#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 */
long pow(int, int);
int /*<<< orphan*/ printf(char *, char *);
void binary(int digit) {
  int bits = sizeof(int) * 8;
  char output[bits];
  output[bits] = '\0';
  for (int i = bits; i >= 0; i--) {
    long tmp = pow(2, i);
    if (digit >= tmp) {
      digit -= tmp;
      output[bits - i] = '1';
    } else {
      output[bits - i] = '0';
    }
  }
  printf("%s\n", output);
}


x86 assembly (clang, -O0):
<binary>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
movl   $0x20,-0x8(%rbp)
mov    -0x8(%rbp),%eax
mov    %eax,%ecx
mov    %rsp,%rax
mov    %rax,-0x10(%rbp)
mov    %rcx,%rdx
add    $0xf,%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rax
sub    %rdx,%rax
mov    %rax,-0x30(%rbp)
mov    %rax,%rsp
mov    %rcx,-0x18(%rbp)
movslq -0x8(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x8(%rbp),%eax
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jl     11d9 <binary+0xb9>
mov    -0x1c(%rbp),%esi
mov    $0x2,%edi
call   1040 <pow@plt>
mov    %rax,-0x28(%rbp)
movslq -0x4(%rbp),%rax
cmp    -0x28(%rbp),%rax
jl     11b5 <binary+0x95>
mov    -0x30(%rbp),%rax
mov    -0x28(%rbp),%rdx
movslq -0x4(%rbp),%rcx
sub    %rdx,%rcx
mov    %ecx,-0x4(%rbp)
mov    -0x8(%rbp),%ecx
sub    -0x1c(%rbp),%ecx
movslq %ecx,%rcx
movb   $0x31,(%rax,%rcx,1)
jmp    11c6 <binary+0xa6>
mov    -0x30(%rbp),%rax
mov    -0x8(%rbp),%ecx
sub    -0x1c(%rbp),%ecx
movslq %ecx,%rcx
movb   $0x30,(%rax,%rcx,1)
jmp    11cb <binary+0xab>
mov    -0x1c(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x1c(%rbp)
jmp    1168 <binary+0x48>
mov    -0x30(%rbp),%rsi
lea    0xe1c(%rip),%rdi
call   1030 <printf@plt>
mov    -0x10(%rbp),%rax
mov    %rax,%rsp
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<binary>:
push   %r15
push   %r14
push   %rbx
sub    $0x20,%rsp
mov    %edi,%ebx
movb   $0x0,0x20(%rsp)
mov    $0x1f,%r14d
xor    %r15d,%r15d
jmp    1152 <binary+0x32>
nopl   0x0(%rax,%rax,1)
xor    $0x31,%cl
sub    %edx,%ebx
mov    %cl,0x1(%rsp,%r15,1)
add    $0xfffffffe,%r14d
add    $0x2,%r15
lea    0x1(%r14),%esi
mov    $0x2,%edi
call   1040 <pow@plt>
movslq %ebx,%rdx
mov    $0x0,%ecx
cmp    %rdx,%rax
setg   %dl
jg     1172 <binary+0x52>
mov    %eax,%ecx
xor    $0x31,%dl
mov    %dl,(%rsp,%r15,1)
cmp    $0x20,%r15
je     119f <binary+0x7f>
sub    %ecx,%ebx
mov    $0x2,%edi
mov    %r14d,%esi
call   1040 <pow@plt>
movslq %ebx,%rcx
xor    %edx,%edx
cmp    %rcx,%rax
setg   %cl
jg     1140 <binary+0x20>
mov    %eax,%edx
jmp    1140 <binary+0x20>
lea    0xe5a(%rip),%rdi
mov    %rsp,%rsi
call   1030 <printf@plt>
add    $0x20,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

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

LLVM IR (-O2):
@.str = [4 x i8] c"%s\0A\00"
define void @binary(i32 %0) {
%2 = alloca [32 x i8]
%3 = getelementptr inbounds [32 x i8], [32 x i8]* %2, i64 0, i64 32
store i8 0, i8* %3
br label %7
4: ; preds = %7
%5 = getelementptr inbounds [32 x i8], [32 x i8]* %2, i64 0, i64 0
%6 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* %5)
ret void
7: ; preds = %21, %1
%8 = phi i64 [ 32, %1 ], [ %33, %21 ]
%9 = phi i32 [ %0, %1 ], [ %30, %21 ]
%10 = trunc i64 %8 to i32
%11 = tail call i64 @pow(i32 2, i32 %10)
%12 = sext i32 %9 to i64
%13 = icmp sgt i64 %11, %12
%14 = trunc i64 %11 to i32
%15 = select i1 %13, i8 48, i8 49
%16 = select i1 %13, i32 0, i32 %14
%17 = sub i32 %9, %16
%18 = sub nuw nsw i64 32, %8
%19 = getelementptr inbounds [32 x i8], [32 x i8]* %2, i64 0, i64 %18
store i8 %15, i8* %19
%20 = icmp eq i64 %8, 0
br i1 %20, label %4, label %21
21: ; preds = %7
%22 = trunc i64 %8 to i32
%23 = add i32 %22, -1
%24 = tail call i64 @pow(i32 2, i32 %23)
%25 = sext i32 %17 to i64
%26 = icmp sgt i64 %24, %25
%27 = trunc i64 %24 to i32
%28 = select i1 %26, i8 48, i8 49
%29 = select i1 %26, i32 0, i32 %27
%30 = sub i32 %17, %29
%31 = sub i64 33, %8
%32 = getelementptr inbounds [32 x i8], [32 x i8]* %2, i64 0, i64 %31
store i8 %28, i8* %32
%33 = add nsw i64 %8, -2
br label %7
}