#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 printbin(int dec) {
  int bin = 1;
  while (bin <= dec) {
    bin *= 2;
  }
  while (1) {
    bin /= 2;
    if (dec == 0 && bin == 0) {
      break;
    }
    if (dec >= bin) {
      printf("1");
      dec -= bin;
    } else {
      printf("0");
    }
  }
  printf("\n");
}


x86 assembly (clang, -O0):
<printbin>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
movl   $0x1,-0x8(%rbp)
mov    -0x8(%rbp),%eax
cmp    -0x4(%rbp),%eax
jg     113c <printbin+0x2c>
mov    -0x8(%rbp),%eax
shl    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    1122 <printbin+0x12>
jmp    1141 <printbin+0x31>
mov    -0x8(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,-0x8(%rbp)
cmpl   $0x0,-0x4(%rbp)
jne    1168 <printbin+0x58>
cmpl   $0x0,-0x8(%rbp)
jne    1168 <printbin+0x58>
jmp    11a1 <printbin+0x91>
mov    -0x4(%rbp),%eax
cmp    -0x8(%rbp),%eax
jl     1190 <printbin+0x80>
lea    0xe85(%rip),%rdi
call   1030 <printf@plt>
mov    -0x8(%rbp),%ecx
mov    -0x4(%rbp),%eax
sub    %ecx,%eax
mov    %eax,-0x4(%rbp)
jmp    119c <printbin+0x8c>
lea    0xe6b(%rip),%rdi
call   1030 <printf@plt>
jmp    1141 <printbin+0x31>
lea    0xe5c(%rip),%rdi
call   1030 <printf@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<printbin>:
push   %rbp
push   %r14
push   %rbx
mov    %edi,%r14d
mov    $0x1,%eax
nopl   0x0(%rax)
mov    %eax,%ebx
lea    (%rbx,%rbx,1),%eax
cmp    %r14d,%ebx
jle    1120 <printbin+0x10>
test   %r14d,%r14d
jne    1140 <printbin+0x30>
cmp    $0x2,%ebx
jb     117a <printbin+0x6a>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    %ebx,%eax
shr    $0x1f,%eax
add    %eax,%ebx
sar    %ebx
mov    %r14d,%ebp
sub    %ebx,%ebp
jge    1160 <printbin+0x50>
mov    $0x30,%edi
call   1030 <putchar@plt>
jmp    116d <printbin+0x5d>
nopl   0x0(%rax)
mov    $0x31,%edi
call   1030 <putchar@plt>
mov    %ebp,%r14d
lea    0x1(%rbx),%eax
test   %r14d,%r14d
jne    1140 <printbin+0x30>
cmp    $0x2,%eax
ja     1140 <printbin+0x30>
mov    $0xa,%edi
pop    %rbx
pop    %r14
pop    %rbp
jmp    1030 <putchar@plt>

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

LLVM IR (-O2):
define void @printbin(i32 %0) {
br label %2
2: ; preds = %2, %1
%3 = phi i32 [ 1, %1 ], [ %5, %2 ]
%4 = icmp sgt i32 %3, %0
%5 = shl nsw i32 %3, 1
br i1 %4, label %6, label %2
6: ; preds = %2
%7 = icmp eq i32 %0, 0
%8 = icmp ult i32 %3, 2
%9 = select i1 %7, i1 %8, i1 false
br i1 %9, label %26, label %10
10: ; preds = %6, %20
%11 = phi i32 [ %13, %20 ], [ %3, %6 ]
%12 = phi i32 [ %21, %20 ], [ %0, %6 ]
%13 = sdiv i32 %11, 2
%14 = icmp slt i32 %12, %13
br i1 %14, label %18, label %15
15: ; preds = %10
%16 = tail call i32 @putchar(i32 49)
%17 = sub nsw i32 %12, %13
br label %20
18: ; preds = %10
%19 = tail call i32 @putchar(i32 48)
br label %20
20: ; preds = %18, %15
%21 = phi i32 [ %17, %15 ], [ %12, %18 ]
%22 = icmp eq i32 %21, 0
%23 = add nsw i32 %13, 1
%24 = icmp ult i32 %23, 3
%25 = select i1 %22, i1 %24, i1 false
br i1 %25, label %26, label %10
26: ; preds = %20, %6
%27 = tail call i32 @putchar(i32 10)
ret void
}