#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 bin, int size) {
  int bit, mask;
  for (bit = 0; bit < size; bit++) {
    mask = (1 << (size - 1 - bit));
    if (bin & mask)
      printf("1");
    else
      printf("0");
  }
}


x86 assembly (clang, -O0):
<printbin>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
mov    -0xc(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    1183 <printbin+0x73>
mov    -0x8(%rbp),%ecx
sub    $0x1,%ecx
sub    -0xc(%rbp),%ecx
mov    $0x1,%eax
shl    %cl,%eax
mov    %eax,-0x10(%rbp)
mov    -0x4(%rbp),%eax
and    -0x10(%rbp),%eax
cmp    $0x0,%eax
je     1164 <printbin+0x54>
lea    0xea6(%rip),%rdi
call   1030 <printf@plt>
jmp    1170 <printbin+0x60>
lea    0xe97(%rip),%rdi
call   1030 <printf@plt>
jmp    1175 <printbin+0x65>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    1125 <printbin+0x15>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<printbin>:
push   %rbp
push   %rbx
push   %rax
test   %esi,%esi
jle    1135 <printbin+0x25>
mov    %esi,%ebx
mov    %edi,%ebp
add    $0xffffffff,%ebx
xchg   %ax,%ax
bt     %ebx,%ebp
mov    $0x31,%edi
adc    $0xffffffff,%edi
call   1030 <putchar@plt>
add    $0xffffffff,%ebx
jb     1120 <printbin+0x10>
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

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

LLVM IR (-O2):
define void @printbin(i32 %0, i32 %1) {
%3 = icmp sgt i32 %1, 0
br i1 %3, label %4, label %15
4: ; preds = %2, %4
%5 = phi i32 [ %13, %4 ], [ 0, %2 ]
%6 = xor i32 %5, -1
%7 = add i32 %6, %1
%8 = shl nuw i32 1, %7
%9 = and i32 %8, %0
%10 = icmp eq i32 %9, 0
%11 = select i1 %10, i32 48, i32 49
%12 = tail call i32 @putchar(i32 %11)
%13 = add nuw nsw i32 %5, 1
%14 = icmp eq i32 %13, %1
br i1 %14, label %15, label %4
15: ; preds = %4, %2
ret void
}