Skip to content

Instantly share code, notes, and snippets.

@luqmana
Created August 3, 2013 13:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save luqmana/6146443 to your computer and use it in GitHub Desktop.
Save luqmana/6146443 to your computer and use it in GitHub Desktop.
fn main() {
let b = test_nd_dr(8, 3);
assert_eq!(b, 2);
}
fn test_nd_dr(n: i8, d: i8) -> i8 {
let separate_div_rem = (n / d, n % d);
let combined_div_rem = n.div_rem(&d);
let (_, b) = separate_div_rem;
b
}
; Function Attrs: uwtable
define i8 @"_ZN10test_nd_dr17_c28bae5793b43ea27_0$x2e0E"({ i64, %tydesc*, i8*, i8*, i8 }*, i8, i8) #1 {
"function top level":
%__make_return_pointer = alloca i8
%__arg = alloca i8
%__arg1 = alloca i8
%separate_div_rem = alloca { i8, i8 }
%__trans_ret_slot = alloca {}
%__trans_ret_slot4 = alloca {}
%combined_div_rem = alloca { i8, i8 }
%b = alloca i8
store i8 %1, i8* %__arg
store i8 %2, i8* %__arg1
%3 = getelementptr inbounds { i8, i8 }* %separate_div_rem, i32 0, i32 0
%4 = load i8* %__arg
%5 = load i8* %__arg1
%6 = icmp eq i8 %5, 0
br i1 %6, label %cond, label %next
next: ; preds = %"function top level"
%7 = sdiv i8 %4, %5
store i8 %7, i8* %3
%8 = getelementptr inbounds { i8, i8 }* %separate_div_rem, i32 0, i32 1
%9 = load i8* %__arg
%10 = load i8* %__arg1
%11 = icmp eq i8 %10, 0
br i1 %11, label %cond3, label %next2
cond: ; preds = %"function top level"
call void @"_ZN8unstable4lang5fail_16_89e154cd091567114_0$x2e8$x2dpreE"({}* %__trans_ret_slot, { i64, %tydesc*, i8*, i8*, i8 }* undef, i8* getelementptr inbounds ([28 x i8]* @str3881, i32 0, i32 0), i8* getelementptr inbounds ([6 x i8]* @str3880, i32 0, i32 0), i64 7)
unreachable
next2: ; preds = %next
%12 = srem i8 %9, %10
store i8 %12, i8* %8
%13 = bitcast i8* %__arg to { i64, %tydesc*, i8*, i8*, i8 }*
call void @"_ZN2i89generated14__extensions__9meth_38847div_rem17_40ddfece17c6da617_0$x2e0E"({ i8, i8 }* %combined_div_rem, { i64, %tydesc*, i8*, i8*, i8 }* %13, i8* %__arg1)
%14 = getelementptr inbounds { i8, i8 }* %separate_div_rem, i32 0, i32 0
%15 = getelementptr inbounds { i8, i8 }* %separate_div_rem, i32 0, i32 1
%16 = load i8* %15
store i8 %16, i8* %b
%17 = load i8* %b
store i8 %17, i8* %__make_return_pointer
%18 = load i8* %__make_return_pointer
ret i8 %18
cond3: ; preds = %next
call void @"_ZN8unstable4lang5fail_16_89e154cd091567114_0$x2e8$x2dpreE"({}* %__trans_ret_slot4, { i64, %tydesc*, i8*, i8*, i8 }* undef, i8* getelementptr inbounds ([43 x i8]* @str3882, i32 0, i32 0), i8* getelementptr inbounds ([6 x i8]* @str3880, i32 0, i32 0), i64 7)
unreachable
}
.globl _ZN10test_nd_dr17_c28bae5793b43ea27_0$x2e0E
.align 16, 0x90
.type _ZN10test_nd_dr17_c28bae5793b43ea27_0$x2e0E,@function
_ZN10test_nd_dr17_c28bae5793b43ea27_0$x2e0E:
.cfi_startproc
cmpq %fs:112, %rsp
ja .LBB3_0
movabsq $104, %r10
movabsq $0, %r11
callq __morestack
ret
.LBB3_0:
pushq %rbp
.Ltmp29:
.cfi_def_cfa_offset 16
.Ltmp30:
.cfi_offset %rbp, -16
movq %rsp, %rbp
.Ltmp31:
.cfi_def_cfa_register %rbp
subq $96, %rsp
movb %dl, %al
movb %sil, %cl
leaq -8(%rbp), %rdi
movb %cl, -2(%rbp)
movb %al, -3(%rbp)
movb -2(%rbp), %al
movb -3(%rbp), %cl
cmpb $0, %cl
movq %rdi, -48(%rbp)
movb %al, -49(%rbp)
movb %cl, -50(%rbp)
je .LBB3_2
leaq -8(%rbp), %rax
movb -49(%rbp), %cl
movq %rax, -64(%rbp)
movsbw %cl, %ax
movb -50(%rbp), %dl
idivb %dl
movq -48(%rbp), %rsi
movb %al, (%rsi)
movq -64(%rbp), %rdi
addq $1, %rdi
movb -2(%rbp), %al
movb -3(%rbp), %r8b
cmpb $0, %r8b
movq %rdi, -72(%rbp)
movb %al, -73(%rbp)
movb %r8b, -74(%rbp)
je .LBB3_4
jmp .LBB3_3
.LBB3_2:
leaq -16(%rbp), %rdi
leaq str3881(%rip), %rdx
leaq str3880(%rip), %rcx
movabsq $7, %r8
callq _ZN8unstable4lang5fail_16_89e154cd091567114_0$x2e8$x2dpreE@PLT
.LBB3_3:
leaq -32(%rbp), %rdi
leaq -3(%rbp), %rdx
leaq -2(%rbp), %rax
movb -73(%rbp), %cl
movq %rax, -88(%rbp)
movsbw %cl, %ax
movb -74(%rbp), %sil
idivb %sil
movq -72(%rbp), %r8
movb %ah, (%r8)
movq -88(%rbp), %r9
movq %r9, %rsi
callq _ZN2i89generated14__extensions__9meth_38847div_rem17_40ddfece17c6da617_0$x2e0E
movb -7(%rbp), %cl
movb %cl, -33(%rbp)
movb -33(%rbp), %cl
movb %cl, -1(%rbp)
movb -1(%rbp), %al
addq $96, %rsp
popq %rbp
ret
.LBB3_4:
leaq -24(%rbp), %rdi
leaq str3882(%rip), %rdx
leaq str3880(%rip), %rcx
movabsq $7, %r8
callq _ZN8unstable4lang5fail_16_89e154cd091567114_0$x2e8$x2dpreE@PLT
.Ltmp32:
.size _ZN10test_nd_dr17_c28bae5793b43ea27_0$x2e0E, .Ltmp32-_ZN10test_nd_dr17_c28bae5793b43ea27_0$x2e0E
.cfi_endproc
0000000000403c70 <_ZN10test_nd_dr17_c28bae5793b43ea27_0$x2e0E>:
403c70: 64 48 3b 24 25 70 00 cmp %fs:0x70,%rsp
403c77: 00 00
403c79: 77 1a ja 403c95 <_ZN10test_nd_dr17_c28bae5793b43ea27_0$x2e0E+0x25>
403c7b: 49 ba 68 00 00 00 00 movabs $0x68,%r10
403c82: 00 00 00
403c85: 49 bb 00 00 00 00 00 movabs $0x0,%r11
403c8c: 00 00 00
403c8f: e8 a0 56 00 00 callq 409334 <__morestack>
403c94: c3 retq
403c95: 55 push %rbp
403c96: 48 89 e5 mov %rsp,%rbp
403c99: 48 83 ec 60 sub $0x60,%rsp
403c9d: 88 d0 mov %dl,%al
403c9f: 40 88 f1 mov %sil,%cl
403ca2: 48 8d 7d f8 lea -0x8(%rbp),%rdi
403ca6: 88 4d fe mov %cl,-0x2(%rbp)
403ca9: 88 45 fd mov %al,-0x3(%rbp)
403cac: 8a 45 fe mov -0x2(%rbp),%al
403caf: 8a 4d fd mov -0x3(%rbp),%cl
403cb2: 80 f9 00 cmp $0x0,%cl
403cb5: 48 89 7d d0 mov %rdi,-0x30(%rbp)
403cb9: 88 45 cf mov %al,-0x31(%rbp)
403cbc: 88 4d ce mov %cl,-0x32(%rbp)
403cbf: 74 3f je 403d00 <_ZN10test_nd_dr17_c28bae5793b43ea27_0$x2e0E+0x90>
403cc1: 48 8d 45 f8 lea -0x8(%rbp),%rax
403cc5: 8a 4d cf mov -0x31(%rbp),%cl
403cc8: 48 89 45 c0 mov %rax,-0x40(%rbp)
403ccc: 66 0f be c1 movsbw %cl,%ax
403cd0: 8a 55 ce mov -0x32(%rbp),%dl
403cd3: f6 fa idiv %dl
403cd5: 48 8b 75 d0 mov -0x30(%rbp),%rsi
403cd9: 88 06 mov %al,(%rsi)
403cdb: 48 8b 7d c0 mov -0x40(%rbp),%rdi
403cdf: 48 81 c7 01 00 00 00 add $0x1,%rdi
403ce6: 8a 45 fe mov -0x2(%rbp),%al
403ce9: 44 8a 45 fd mov -0x3(%rbp),%r8b
403ced: 41 80 f8 00 cmp $0x0,%r8b
403cf1: 48 89 7d b8 mov %rdi,-0x48(%rbp)
403cf5: 88 45 b7 mov %al,-0x49(%rbp)
403cf8: 44 88 45 b6 mov %r8b,-0x4a(%rbp)
403cfc: 74 69 je 403d67 <_ZN10test_nd_dr17_c28bae5793b43ea27_0$x2e0E+0xf7>
403cfe: eb 21 jmp 403d21 <_ZN10test_nd_dr17_c28bae5793b43ea27_0$x2e0E+0xb1>
403d00: 48 8d 7d f0 lea -0x10(%rbp),%rdi
403d04: 48 8d 15 f5 57 00 00 lea 0x57f5(%rip),%rdx # 409500 <str3881>
403d0b: 48 8d 0d e5 57 00 00 lea 0x57e5(%rip),%rcx # 4094f7 <str3880>
403d12: 49 b8 07 00 00 00 00 movabs $0x7,%r8
403d19: 00 00 00
403d1c: e8 ff f6 ff ff callq 403420 <_ZN8unstable4lang5fail_16_89e154cd091567114_0$x2e8$x2dpreE@plt>
403d21: 48 8d 7d e0 lea -0x20(%rbp),%rdi
403d25: 48 8d 55 fd lea -0x3(%rbp),%rdx
403d29: 48 8d 45 fe lea -0x2(%rbp),%rax
403d2d: 8a 4d b7 mov -0x49(%rbp),%cl
403d30: 48 89 45 a8 mov %rax,-0x58(%rbp)
403d34: 66 0f be c1 movsbw %cl,%ax
403d38: 40 8a 75 b6 mov -0x4a(%rbp),%sil
403d3c: 40 f6 fe idiv %sil
403d3f: 4c 8b 45 b8 mov -0x48(%rbp),%r8
403d43: 41 88 20 mov %spl,(%r8)
403d46: 4c 8b 4d a8 mov -0x58(%rbp),%r9
403d4a: 4c 89 ce mov %r9,%rsi
403d4d: e8 fe 54 00 00 callq 409250 <_ZN2i89generated14__extensions__9meth_38847div_rem17_40ddfece17c6da617_0$x2e0E>
403d52: 8a 4d f9 mov -0x7(%rbp),%cl
403d55: 88 4d df mov %cl,-0x21(%rbp)
403d58: 8a 4d df mov -0x21(%rbp),%cl
403d5b: 88 4d ff mov %cl,-0x1(%rbp)
403d5e: 8a 45 ff mov -0x1(%rbp),%al
403d61: 48 83 c4 60 add $0x60,%rsp
403d65: 5d pop %rbp
403d66: c3 retq
403d67: 48 8d 7d e8 lea -0x18(%rbp),%rdi
403d6b: 48 8d 15 ae 57 00 00 lea 0x57ae(%rip),%rdx # 409520 <str3882>
403d72: 48 8d 0d 7e 57 00 00 lea 0x577e(%rip),%rcx # 4094f7 <str3880>
403d79: 49 b8 07 00 00 00 00 movabs $0x7,%r8
403d80: 00 00 00
403d83: e8 98 f6 ff ff callq 403420 <_ZN8unstable4lang5fail_16_89e154cd091567114_0$x2e8$x2dpreE@plt>
403d88: 90 nop
403d89: 90 nop
403d8a: 90 nop
403d8b: 90 nop
403d8c: 90 nop
403d8d: 90 nop
403d8e: 90 nop
403d8f: 90 nop
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment