#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 printDecimalAsBinary(int dec) {
  int pos = 1;
  while (pos <= dec)
    pos *= 2;
  pos /= 2;
  while (pos > 1) {
    if (dec >= pos) {
      printf("%d", (dec / pos));
      dec -= pos;
    } else
      printf("0");
    pos /= 2;
  }
  printf("%d", dec);
}


x86 assembly (clang, -O0):
<printDecimalAsBinary>:
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 <printDecimalAsBinary+0x2c>
mov    -0x8(%rbp),%eax
shl    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    1122 <printDecimalAsBinary+0x12>
mov    -0x8(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,-0x8(%rbp)
cmpl   $0x1,-0x8(%rbp)
jle    11a8 <printDecimalAsBinary+0x98>
mov    -0x4(%rbp),%eax
cmp    -0x8(%rbp),%eax
jl     1187 <printDecimalAsBinary+0x77>
mov    -0x4(%rbp),%eax
cltd
idivl  -0x8(%rbp)
mov    %eax,%esi
lea    0xe90(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x8(%rbp),%ecx
mov    -0x4(%rbp),%eax
sub    %ecx,%eax
mov    %eax,-0x4(%rbp)
jmp    1195 <printDecimalAsBinary+0x85>
lea    0xe75(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x8(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,-0x8(%rbp)
jmp    114a <printDecimalAsBinary+0x3a>
mov    -0x4(%rbp),%esi
lea    0xe4e(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<printDecimalAsBinary>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %edi,%r15d
mov    $0x1,%eax
nop
mov    %eax,%ebx
lea    (%rbx,%rbx,1),%eax
cmp    %r15d,%ebx
jle    1130 <printDecimalAsBinary+0x10>
cmp    $0x4,%ebx
jb     118b <printDecimalAsBinary+0x6b>
shr    %ebx
lea    0xeb8(%rip),%r14
jmp    116d <printDecimalAsBinary+0x4d>
nopw   0x0(%rax,%rax,1)
mov    $0x30,%edi
call   1030 <putchar@plt>
mov    %r15d,%ebp
mov    %ebx,%eax
shr    $0x1f,%eax
add    %ebx,%eax
sar    %eax
cmp    $0x3,%ebx
mov    %eax,%ebx
jle    118e <printDecimalAsBinary+0x6e>
mov    %r15d,%ebp
sub    %ebx,%ebp
jl     1150 <printDecimalAsBinary+0x30>
mov    %r15d,%eax
cltd
idiv   %ebx
mov    %r14,%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %ebp,%r15d
jmp    115d <printDecimalAsBinary+0x3d>
mov    %r15d,%ebp
lea    0xe6b(%rip),%rdi
mov    %ebp,%esi
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
jmp    1040 <printf@plt>

LLVM IR (-O0):
@.str = [3 x i8] c"%d\00"
@.str.1 = [2 x i8] c"0\00"
define void @printDecimalAsBinary(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
%12 = load i32, i32* %3
%13 = sdiv i32 %12, 2
store i32 %13, i32* %3
br label %14
14: ; preds = %31, %11
%15 = load i32, i32* %3
%16 = icmp sgt i32 %15, 1
br i1 %16, label %17, label %34
17: ; preds = %14
%18 = load i32, i32* %2
%19 = load i32, i32* %3
%20 = icmp sge i32 %18, %19
br i1 %20, label %21, label %29
21: ; preds = %17
%22 = load i32, i32* %2
%23 = load i32, i32* %3
%24 = sdiv i32 %22, %23
%25 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 %24)
%26 = load i32, i32* %3
%27 = load i32, i32* %2
%28 = sub nsw i32 %27, %26
store i32 %28, i32* %2
br label %31
29: ; preds = %17
%30 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
br label %31
31: ; preds = %29, %21
%32 = load i32, i32* %3
%33 = sdiv i32 %32, 2
store i32 %33, i32* %3
br label %14
34: ; preds = %14
%35 = load i32, i32* %2
%36 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 %35)
ret void
}

LLVM IR (-O2):
@.str = [3 x i8] c"%d\00"
define void @printDecimalAsBinary(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 ugt i32 %3, 3
br i1 %7, label %8, label %24
8: ; preds = %6
%9 = lshr i32 %3, 1
br label %10
10: ; preds = %8, %20
%11 = phi i32 [ %22, %20 ], [ %9, %8 ]
%12 = phi i32 [ %21, %20 ], [ %0, %8 ]
%13 = icmp slt i32 %12, %11
br i1 %13, label %18, label %14
14: ; preds = %10
%15 = sdiv i32 %12, %11
%16 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 %15)
%17 = sub nsw i32 %12, %11
br label %20
18: ; preds = %10
%19 = tail call i32 @putchar(i32 48)
br label %20
20: ; preds = %18, %14
%21 = phi i32 [ %17, %14 ], [ %12, %18 ]
%22 = sdiv i32 %11, 2
%23 = icmp sgt i32 %11, 3
br i1 %23, label %10, label %24
24: ; preds = %20, %6
%25 = phi i32 [ %0, %6 ], [ %21, %20 ]
%26 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 %25)
ret void
}