#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 print_binary(int decimal) {
  int i = 0;
  int bin_values[80];
  while (decimal != 0) {
    bin_values[i++] = decimal % 2;
    decimal = decimal / 2;
  }
  bin_values[i] = '\0';
  int j = i;
  while (j % 4 != 0) {
    printf("0");
    j++;
  }
  for (j = i - 1; j >= 0; j--) {
    printf("%d", bin_values[j]);
  }
}


x86 assembly (clang, -O0):
<print_binary>:
push   %rbp
mov    %rsp,%rbp
sub    $0x160,%rsp
mov    %edi,-0x4(%rbp)
movl   $0x0,-0x8(%rbp)
cmpl   $0x0,-0x4(%rbp)
je     1161 <print_binary+0x51>
mov    -0x4(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    -0x8(%rbp),%eax
mov    %eax,%ecx
add    $0x1,%ecx
mov    %ecx,-0x8(%rbp)
cltq
mov    %edx,-0x150(%rbp,%rax,4)
mov    -0x4(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,-0x4(%rbp)
jmp    1125 <print_binary+0x15>
movslq -0x8(%rbp),%rax
movl   $0x0,-0x150(%rbp,%rax,4)
mov    -0x8(%rbp),%eax
mov    %eax,-0x154(%rbp)
mov    -0x154(%rbp),%eax
mov    $0x4,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
je     11b2 <print_binary+0xa2>
lea    0xe69(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x154(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x154(%rbp)
jmp    1179 <print_binary+0x69>
mov    -0x8(%rbp),%eax
sub    $0x1,%eax
mov    %eax,-0x154(%rbp)
cmpl   $0x0,-0x154(%rbp)
jl     11fb <print_binary+0xeb>
movslq -0x154(%rbp),%rax
mov    -0x150(%rbp,%rax,4),%esi
lea    0xe22(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x154(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x154(%rbp)
jmp    11be <print_binary+0xae>
add    $0x160,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<print_binary>:
push   %rbp
push   %r14
push   %rbx
sub    $0x140,%rsp
test   %edi,%edi
je     11ca <print_binary+0xaa>
xor    %ebx,%ebx
mov    %edi,%eax
nopw   0x0(%rax,%rax,1)
shr    $0x1f,%eax
add    %edi,%eax
mov    %eax,%ecx
and    $0xfffffffe,%ecx
mov    %edi,%edx
sub    %ecx,%edx
mov    %edx,(%rsp,%rbx,4)
add    $0x1,%rbx
sar    %eax
add    $0x1,%edi
cmp    $0x2,%edi
mov    %eax,%edi
ja     1140 <print_binary+0x20>
mov    %ebx,%eax
movl   $0x0,(%rsp,%rax,4)
test   $0x3,%bl
je     1196 <print_binary+0x76>
lea    0x1(%rbx),%r14
mov    %r14d,%ebp
cs nopw 0x0(%rax,%rax,1)
mov    $0x30,%edi
call   1030 <putchar@plt>
add    $0x1,%ebp
test   $0x3,%r14b
mov    %ebp,%r14d
jne    1180 <print_binary+0x60>
test   %ebx,%ebx
jle    11ca <print_binary+0xaa>
mov    %ebx,%ebx
add    $0x1,%rbx
lea    0xe59(%rip),%r14
nopw   0x0(%rax,%rax,1)
lea    -0x2(%rbx),%eax
mov    (%rsp,%rax,4),%esi
mov    %r14,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
add    $0xffffffffffffffff,%rbx
cmp    $0x1,%rbx
jg     11b0 <print_binary+0x90>
add    $0x140,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

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

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