#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 print3(int a) {
  int b[512];
  int i = 0;
  while (a) {
    if (a % 2)
      b[i++] = 1;
    else
      b[i++] = 0;
    a >>= 1;
  }
  while (i)
    printf("%d", b[--i]);
  printf("\n");
}


x86 assembly (clang, -O0):
<print3>:
push   %rbp
mov    %rsp,%rbp
sub    $0x820,%rsp
mov    %edi,-0x4(%rbp)
movl   $0x0,-0x814(%rbp)
cmpl   $0x0,-0x4(%rbp)
je     1195 <print3+0x85>
mov    -0x4(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
je     1169 <print3+0x59>
mov    -0x814(%rbp),%eax
mov    %eax,%ecx
add    $0x1,%ecx
mov    %ecx,-0x814(%rbp)
cltq
movl   $0x1,-0x810(%rbp,%rax,4)
jmp    1187 <print3+0x77>
mov    -0x814(%rbp),%eax
mov    %eax,%ecx
add    $0x1,%ecx
mov    %ecx,-0x814(%rbp)
cltq
movl   $0x0,-0x810(%rbp,%rax,4)
mov    -0x4(%rbp),%eax
sar    $0x1,%eax
mov    %eax,-0x4(%rbp)
jmp    1128 <print3+0x18>
jmp    119a <print3+0x8a>
cmpl   $0x0,-0x814(%rbp)
je     11d2 <print3+0xc2>
mov    -0x814(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x814(%rbp)
cltq
mov    -0x810(%rbp,%rax,4),%esi
lea    0xe3a(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    119a <print3+0x8a>
lea    0xe2a(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
add    $0x820,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<print3>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x808,%rsp
test   %edi,%edi
je     118d <print3+0x6d>
xor    %r12d,%r12d
mov    %edi,%eax
nopw   0x0(%rax,%rax,1)
mov    %edi,%ecx
and    $0x1,%ecx
mov    %ecx,(%rsp,%r12,4)
add    $0x1,%r12
sar    %eax
cmp    $0x2,%edi
mov    %eax,%edi
jae    1140 <print3+0x20>
test   %r12d,%r12d
je     118d <print3+0x6d>
movslq %r12d,%rax
lea    (%rsp,%rax,4),%r15
add    $0xfffffffffffffffc,%r15
lea    0xe93(%rip),%r14
xor    %ebx,%ebx
nop
mov    (%r15,%rbx,4),%esi
mov    %r14,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
lea    -0x1(%rbx),%rax
add    %r12d,%ebx
cmp    $0x1,%ebx
mov    %rax,%rbx
jne    1170 <print3+0x50>
mov    $0xa,%edi
add    $0x808,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
jmp    1030 <putchar@plt>

LLVM IR (-O0):
@.str = [3 x i8] c"%d\00"
@.str.1 = [2 x i8] c"\0A\00"
define void @print3(i32 %0) {
%2 = alloca i32
%3 = alloca [512 x i32]
%4 = alloca i32
store i32 %0, i32* %2
store i32 0, i32* %4
br label %5
5: ; preds = %22, %1
%6 = load i32, i32* %2
%7 = icmp ne i32 %6, 0
br i1 %7, label %8, label %25
8: ; preds = %5
%9 = load i32, i32* %2
%10 = srem i32 %9, 2
%11 = icmp ne i32 %10, 0
br i1 %11, label %12, label %17
12: ; preds = %8
%13 = load i32, i32* %4
%14 = add nsw i32 %13, 1
store i32 %14, i32* %4
%15 = sext i32 %13 to i64
%16 = getelementptr inbounds [512 x i32], [512 x i32]* %3, i64 0, i64 %15
store i32 1, i32* %16
br label %22
17: ; preds = %8
%18 = load i32, i32* %4
%19 = add nsw i32 %18, 1
store i32 %19, i32* %4
%20 = sext i32 %18 to i64
%21 = getelementptr inbounds [512 x i32], [512 x i32]* %3, i64 0, i64 %20
store i32 0, i32* %21
br label %22
22: ; preds = %17, %12
%23 = load i32, i32* %2
%24 = ashr i32 %23, 1
store i32 %24, i32* %2
br label %5
25: ; preds = %5
br label %26
26: ; preds = %29, %25
%27 = load i32, i32* %4
%28 = icmp ne i32 %27, 0
br i1 %28, label %29, label %36
29: ; preds = %26
%30 = load i32, i32* %4
%31 = add nsw i32 %30, -1
store i32 %31, i32* %4
%32 = sext i32 %31 to i64
%33 = getelementptr inbounds [512 x i32], [512 x i32]* %3, i64 0, i64 %32
%34 = load i32, i32* %33
%35 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 %34)
br label %26
36: ; preds = %26
%37 = 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"%d\00"
define void @print3(i32 %0) {
%2 = alloca [512 x i32]
%3 = bitcast [512 x i32]* %2 to i8*
%4 = icmp eq i32 %0, 0
br i1 %4, label %27, label %11
5: ; preds = %11
%6 = trunc i64 %16 to i32
%7 = icmp eq i32 %6, 0
br i1 %7, label %27, label %8
8: ; preds = %5
%9 = shl i64 %16, 32
%10 = ashr exact i64 %9, 32
br label %19
11: ; preds = %1, %11
%12 = phi i64 [ %16, %11 ], [ 0, %1 ]
%13 = phi i32 [ %17, %11 ], [ %0, %1 ]
%14 = and i32 %13, 1
%15 = getelementptr inbounds [512 x i32], [512 x i32]* %2, i64 0, i64 %12
store i32 %14, i32* %15
%16 = add nuw i64 %12, 1
%17 = ashr i32 %13, 1
%18 = icmp ult i32 %13, 2
br i1 %18, label %5, label %11
19: ; preds = %8, %19
%20 = phi i64 [ %10, %8 ], [ %21, %19 ]
%21 = add nsw i64 %20, -1
%22 = getelementptr inbounds [512 x i32], [512 x i32]* %2, i64 0, i64 %21
%23 = load i32, i32* %22
%24 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 %23)
%25 = trunc i64 %21 to i32
%26 = icmp eq i32 %25, 0
br i1 %26, label %27, label %19
27: ; preds = %19, %1, %5
%28 = tail call i32 @putchar(i32 10)
ret void
}