int dec(x) {
  int i, bin[15];
  for (i = 0; i < 15; i++) {
    bin[i] = x % 2;
    x = x / 2;
  }
  printf("The Binary value is:\n");
  for (i = 14; i >= 0; i--) {
    printf("%d", bin[i]);
  }
}


x86 assembly (clang, -O0):
<dec>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %edi,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
cmpl   $0xf,-0xc(%rbp)
jge    115b <dec+0x4b>
mov    -0x8(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
movslq -0xc(%rbp),%rax
mov    %edx,-0x50(%rbp,%rax,4)
mov    -0x8(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,-0x8(%rbp)
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    1122 <dec+0x12>
lea    0xe9e(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0xe,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
jl     119e <dec+0x8e>
movslq -0xc(%rbp),%rax
mov    -0x50(%rbp,%rax,4),%esi
lea    0xe8d(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0xc(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0xc(%rbp)
jmp    1170 <dec+0x60>
mov    -0x4(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<dec>:
push   %rbx
sub    $0x40,%rsp
mov    $0x1,%eax
nopw   0x0(%rax,%rax,1)
mov    %edi,%ecx
shr    $0x1f,%ecx
add    %edi,%ecx
mov    %ecx,%edx
and    $0xfffffffe,%edx
mov    %edi,%esi
sub    %edx,%esi
mov    %esi,-0x4(%rsp,%rax,4)
cmp    $0xf,%rax
je     116e <dec+0x4e>
sar    %ecx
mov    %ecx,%edx
shr    $0x1f,%edx
add    %ecx,%edx
and    $0xfffffffe,%edx
sub    %edx,%ecx
mov    %ecx,(%rsp,%rax,4)
lea    0x3(%rdi),%ecx
test   %edi,%edi
cmovns %edi,%ecx
sar    $0x2,%ecx
add    $0x2,%rax
mov    %ecx,%edi
jmp    1130 <dec+0x10>
lea    0xe8e(%rip),%rdi
call   1030 <puts@plt>
mov    0x38(%rsp),%esi
lea    0xe7b(%rip),%rbx
mov    %rbx,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x34(%rsp),%esi
mov    %rbx,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x30(%rsp),%esi
mov    %rbx,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x2c(%rsp),%esi
mov    %rbx,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x28(%rsp),%esi
mov    %rbx,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x24(%rsp),%esi
mov    %rbx,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x20(%rsp),%esi
mov    %rbx,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x1c(%rsp),%esi
mov    %rbx,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x18(%rsp),%esi
mov    %rbx,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x14(%rsp),%esi
mov    %rbx,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x10(%rsp),%esi
mov    %rbx,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    0xc(%rsp),%esi
mov    %rbx,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x8(%rsp),%esi
mov    %rbx,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x4(%rsp),%esi
mov    %rbx,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    (%rsp),%esi
mov    %rbx,%rdi
xor    %eax,%eax
add    $0x40,%rsp
pop    %rbx
jmp    1040 <printf@plt>

LLVM IR (-O0):
@.str = [22 x i8] c"The Binary value is:\0A\00"
@.str.1 = [3 x i8] c"%d\00"
define i32 @dec(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca [15 x i32]
store i32 %0, i32* %3
store i32 0, i32* %4
br label %6
6: ; preds = %17, %1
%7 = load i32, i32* %4
%8 = icmp slt i32 %7, 15
br i1 %8, label %9, label %20
9: ; preds = %6
%10 = load i32, i32* %3
%11 = srem i32 %10, 2
%12 = load i32, i32* %4
%13 = sext i32 %12 to i64
%14 = getelementptr inbounds [15 x i32], [15 x i32]* %5, i64 0, i64 %13
store i32 %11, i32* %14
%15 = load i32, i32* %3
%16 = sdiv i32 %15, 2
store i32 %16, i32* %3
br label %17
17: ; preds = %9
%18 = load i32, i32* %4
%19 = add nsw i32 %18, 1
store i32 %19, i32* %4
br label %6
20: ; preds = %6
%21 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0))
store i32 14, i32* %4
br label %22
22: ; preds = %31, %20
%23 = load i32, i32* %4
%24 = icmp sge i32 %23, 0
br i1 %24, label %25, label %34
25: ; preds = %22
%26 = load i32, i32* %4
%27 = sext i32 %26 to i64
%28 = getelementptr inbounds [15 x i32], [15 x i32]* %5, i64 0, i64 %27
%29 = load i32, i32* %28
%30 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 %29)
br label %31
31: ; preds = %25
%32 = load i32, i32* %4
%33 = add nsw i32 %32, -1
store i32 %33, i32* %4
br label %22
34: ; preds = %22
%35 = load i32, i32* %2
ret i32 %35
}

LLVM IR (-O2):
@.str.1 = [3 x i8] c"%d\00"
@str = [21 x i8] c"The Binary value is:\00"
define i32 @dec(i32 %0) {
%2 = alloca [15 x i32]
%3 = bitcast [15 x i32]* %2 to i8*
br label %4
4: ; preds = %12, %1
%5 = phi i64 [ 0, %1 ], [ %16, %12 ]
%6 = phi i32 [ %0, %1 ], [ %15, %12 ]
%7 = srem i32 %6, 2
%8 = sdiv i32 %6, 2
%9 = getelementptr inbounds [15 x i32], [15 x i32]* %2, i64 0, i64 %5
store i32 %7, i32* %9
%10 = or i64 %5, 1
%11 = icmp eq i64 %10, 15
br i1 %11, label %17, label %12
12: ; preds = %4
%13 = srem i32 %8, 2
%14 = getelementptr inbounds [15 x i32], [15 x i32]* %2, i64 0, i64 %10
store i32 %13, i32* %14
%15 = sdiv i32 %6, 4
%16 = add nuw nsw i64 %5, 2
br label %4
17: ; preds = %4
%18 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @str, i64 0, i64 0))
%19 = getelementptr inbounds [15 x i32], [15 x i32]* %2, i64 0, i64 14
%20 = load i32, i32* %19
%21 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 %20)
%22 = getelementptr inbounds [15 x i32], [15 x i32]* %2, i64 0, i64 13
%23 = load i32, i32* %22
%24 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 %23)
%25 = getelementptr inbounds [15 x i32], [15 x i32]* %2, i64 0, i64 12
%26 = load i32, i32* %25
%27 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 %26)
%28 = getelementptr inbounds [15 x i32], [15 x i32]* %2, i64 0, i64 11
%29 = load i32, i32* %28
%30 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 %29)
%31 = getelementptr inbounds [15 x i32], [15 x i32]* %2, i64 0, i64 10
%32 = load i32, i32* %31
%33 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 %32)
%34 = getelementptr inbounds [15 x i32], [15 x i32]* %2, i64 0, i64 9
%35 = load i32, i32* %34
%36 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 %35)
%37 = getelementptr inbounds [15 x i32], [15 x i32]* %2, i64 0, i64 8
%38 = load i32, i32* %37
%39 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 %38)
%40 = getelementptr inbounds [15 x i32], [15 x i32]* %2, i64 0, i64 7
%41 = load i32, i32* %40
%42 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 %41)
%43 = getelementptr inbounds [15 x i32], [15 x i32]* %2, i64 0, i64 6
%44 = load i32, i32* %43
%45 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 %44)
%46 = getelementptr inbounds [15 x i32], [15 x i32]* %2, i64 0, i64 5
%47 = load i32, i32* %46
%48 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 %47)
%49 = getelementptr inbounds [15 x i32], [15 x i32]* %2, i64 0, i64 4
%50 = load i32, i32* %49
%51 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 %50)
%52 = getelementptr inbounds [15 x i32], [15 x i32]* %2, i64 0, i64 3
%53 = load i32, i32* %52
%54 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 %53)
%55 = getelementptr inbounds [15 x i32], [15 x i32]* %2, i64 0, i64 2
%56 = load i32, i32* %55
%57 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 %56)
%58 = getelementptr inbounds [15 x i32], [15 x i32]* %2, i64 0, i64 1
%59 = load i32, i32* %58
%60 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 %59)
%61 = getelementptr inbounds [15 x i32], [15 x i32]* %2, i64 0, i64 0
%62 = load i32, i32* %61
%63 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 %62)
ret i32 undef
}