#define NULL ((void *)0)
typedef unsigned long size_t; // Customize by platform.
typedef long intptr_t;
typedef unsigned long uintptr_t;
typedef long scalar_t__; // Either arithmetic or pointer type.
/* By default, we understand bool (as a convenience). */
typedef int bool;
#define false 0
#define true 1

/* Forward declarations */

/* Type definitions */

/* Variables and functions */
int /*<<< orphan*/ printf(char *, ...);
void dec2bin_v1(int num) {
  int rest, i = 0;
  int bin[20], j;
  printf("\n");
  do {
    rest = num % 2;
    num = num / 2;
    bin[i] = rest;
    i++;
  } while (num > 0);
  for (j = i - 1; j >= 0; j--)
    printf("%d", bin[j]);
}


x86 assembly (clang, -O0):
<dec2bin_v1>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
mov    %edi,-0x4(%rbp)
movl   $0x0,-0xc(%rbp)
lea    0xed7(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x4(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %edx,-0x8(%rbp)
mov    -0x4(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,-0x4(%rbp)
mov    -0x8(%rbp),%ecx
movslq -0xc(%rbp),%rax
mov    %ecx,-0x60(%rbp,%rax,4)
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
cmpl   $0x0,-0x4(%rbp)
jg     1130 <dec2bin_v1+0x20>
mov    -0xc(%rbp),%eax
sub    $0x1,%eax
mov    %eax,-0x64(%rbp)
cmpl   $0x0,-0x64(%rbp)
jl     11a1 <dec2bin_v1+0x91>
movslq -0x64(%rbp),%rax
mov    -0x60(%rbp,%rax,4),%esi
lea    0xe76(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x64(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x64(%rbp)
jmp    1173 <dec2bin_v1+0x63>
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<dec2bin_v1>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x58,%rsp
mov    %edi,%ebx
mov    $0xa,%edi
call   1030 <putchar@plt>
xor    %r14d,%r14d
nopw   0x0(%rax,%rax,1)
mov    %ebx,%eax
shr    $0x1f,%eax
add    %ebx,%eax
mov    %eax,%ecx
sar    %ecx
and    $0xfffffffe,%eax
mov    %ebx,%edx
sub    %eax,%edx
mov    %edx,(%rsp,%r14,4)
add    $0x1,%r14
cmp    $0x1,%ebx
mov    %ecx,%ebx
jg     1140 <dec2bin_v1+0x20>
add    $0xffffffffffffffff,%r14
mov    %r14d,%eax
lea    (%rsp,%rax,4),%r12
lea    0xe8d(%rip),%r15
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
nop
mov    (%r12,%rbx,4),%esi
mov    %r15,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
lea    -0x1(%rbx),%rax
add    %r14d,%ebx
test   %ebx,%ebx
mov    %rax,%rbx
jg     1180 <dec2bin_v1+0x60>
add    $0x58,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

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

LLVM IR (-O2):
@.str.1 = [3 x i8] c"%d\00"
define void @dec2bin_v1(i32 %0) {
%2 = alloca [20 x i32]
%3 = bitcast [20 x i32]* %2 to i8*
%4 = tail call i32 @putchar(i32 10)
br label %5
5: ; preds = %5, %1
%6 = phi i64 [ %11, %5 ], [ 0, %1 ]
%7 = phi i32 [ %9, %5 ], [ %0, %1 ]
%8 = srem i32 %7, 2
%9 = sdiv i32 %7, 2
%10 = getelementptr inbounds [20 x i32], [20 x i32]* %2, i64 0, i64 %6
store i32 %8, i32* %10
%11 = add nuw i64 %6, 1
%12 = icmp sgt i32 %7, 1
br i1 %12, label %5, label %13
13: ; preds = %5
%14 = and i64 %6, 4294967295
br label %15
15: ; preds = %13, %15
%16 = phi i64 [ %14, %13 ], [ %20, %15 ]
%17 = getelementptr inbounds [20 x i32], [20 x i32]* %2, i64 0, i64 %16
%18 = load i32, i32* %17
%19 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 %18)
%20 = add nsw i64 %16, -1
%21 = trunc i64 %16 to i32
%22 = icmp sgt i32 %21, 0
br i1 %22, label %15, label %23
23: ; preds = %15
ret void
}