#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 binary(int x) {
  int tab[8] = {0, 0, 0, 0, 0, 0, 0, 0};
  int i = 0;
  int n = 8;
  while (x != 0) {
    tab[i] = x % 2;
    x = x / 2;
    i++;
  }
  while (n > 0) {
    n--;
    printf("%i", tab[n]);
  }
  printf("\n");
}


x86 assembly (clang, -O0):
<binary>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %edi,-0x4(%rbp)
lea    -0x30(%rbp),%rdi
xor    %esi,%esi
mov    $0x20,%edx
call   1040 <memset@plt>
movl   $0x0,-0x34(%rbp)
movl   $0x8,-0x38(%rbp)
cmpl   $0x0,-0x4(%rbp)
je     1182 <binary+0x62>
mov    -0x4(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
movslq -0x34(%rbp),%rax
mov    %edx,-0x30(%rbp,%rax,4)
mov    -0x4(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,-0x4(%rbp)
mov    -0x34(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x34(%rbp)
jmp    1149 <binary+0x29>
jmp    1187 <binary+0x67>
cmpl   $0x0,-0x38(%rbp)
jle    11b5 <binary+0x95>
mov    -0x38(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x38(%rbp)
movslq -0x38(%rbp),%rax
mov    -0x30(%rbp,%rax,4),%esi
lea    0xe57(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    1187 <binary+0x67>
lea    0xe47(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<binary>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x38,%rsp
xorps  %xmm0,%xmm0
movaps %xmm0,0x20(%rsp)
movaps %xmm0,0x10(%rsp)
test   %edi,%edi
je     119e <binary+0x7e>
lea    0x10(%rsp),%rax
mov    %edi,%ecx
cs nopw 0x0(%rax,%rax,1)
shr    $0x1f,%ecx
add    %edi,%ecx
mov    %ecx,%edx
and    $0xfffffffe,%edx
mov    %edi,%esi
sub    %edx,%esi
mov    %esi,(%rax)
sar    %ecx
add    $0x1,%edi
add    $0x4,%rax
cmp    $0x3,%edi
mov    %ecx,%edi
jae    1150 <binary+0x30>
mov    0x2c(%rsp),%esi
mov    0x28(%rsp),%r15d
mov    0x24(%rsp),%r14d
mov    0x20(%rsp),%ebx
mov    0x1c(%rsp),%r13d
mov    0x18(%rsp),%r12d
mov    0x10(%rsp),%eax
mov    %eax,0xc(%rsp)
mov    0x14(%rsp),%eax
mov    %eax,0x8(%rsp)
jmp    11be <binary+0x9e>
movl   $0x0,0xc(%rsp)
movl   $0x0,0x8(%rsp)
xor    %r12d,%r12d
xor    %r13d,%r13d
xor    %ebx,%ebx
xor    %r14d,%r14d
xor    %r15d,%r15d
xor    %esi,%esi
lea    0xe3b(%rip),%rbp
mov    %rbp,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %rbp,%rdi
mov    %r15d,%esi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %rbp,%rdi
mov    %r14d,%esi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %rbp,%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %rbp,%rdi
mov    %r13d,%esi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %rbp,%rdi
mov    %r12d,%esi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %rbp,%rdi
mov    0x8(%rsp),%esi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %rbp,%rdi
mov    0xc(%rsp),%esi
xor    %eax,%eax
call   1040 <printf@plt>
mov    $0xa,%edi
add    $0x38,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <putchar@plt>

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

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