#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 */
unsigned short powerOf2(int);
int /*<<< orphan*/ printf(char *);
void printBin(unsigned short bin, int bitNum) {
  int ii;
  for (ii = (bitNum - 1); ii >= 0; ii--) {
    if ((bin & powerOf2(ii)) > 0)
      printf("1");
    else
      printf("0");
  }
}


x86 assembly (clang, -O0):
<printBin>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %di,%ax
mov    %ax,-0x2(%rbp)
mov    %esi,-0x8(%rbp)
mov    -0x8(%rbp),%eax
sub    $0x1,%eax
mov    %eax,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
jl     1198 <printBin+0x78>
movzwl -0x2(%rbp),%eax
mov    %eax,-0x10(%rbp)
mov    -0xc(%rbp),%edi
call   1040 <powerOf2@plt>
mov    %ax,%cx
mov    -0x10(%rbp),%eax
movzwl %cx,%ecx
and    %ecx,%eax
cmp    $0x0,%eax
jle    1179 <printBin+0x59>
lea    0xe91(%rip),%rdi
call   1030 <printf@plt>
jmp    1185 <printBin+0x65>
lea    0xe82(%rip),%rdi
call   1030 <printf@plt>
jmp    118a <printBin+0x6a>
mov    -0xc(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0xc(%rbp)
jmp    113b <printBin+0x1b>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<printBin>:
push   %rbp
push   %rbx
push   %rax
test   %esi,%esi
jle    1153 <printBin+0x33>
mov    %esi,%ebx
mov    %edi,%ebp
add    $0x1,%ebx
xchg   %ax,%ax
lea    -0x2(%rbx),%edi
call   1040 <powerOf2@plt>
and    %ebp,%eax
cmp    $0x1,%ax
mov    $0x31,%edi
sbb    $0x0,%edi
call   1030 <putchar@plt>
add    $0xffffffff,%ebx
cmp    $0x1,%ebx
ja     1130 <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(i16 zeroext %0, i32 %1) {
%3 = alloca i16
%4 = alloca i32
%5 = alloca i32
store i16 %0, i16* %3
store i32 %1, i32* %4
%6 = load i32, i32* %4
%7 = sub nsw i32 %6, 1
store i32 %7, i32* %5
br label %8
8: ; preds = %24, %2
%9 = load i32, i32* %5
%10 = icmp sge i32 %9, 0
br i1 %10, label %11, label %27
11: ; preds = %8
%12 = load i16, i16* %3
%13 = zext i16 %12 to i32
%14 = load i32, i32* %5
%15 = call zeroext i16 @powerOf2(i32 %14)
%16 = zext i16 %15 to i32
%17 = and i32 %13, %16
%18 = icmp sgt i32 %17, 0
br i1 %18, label %19, label %21
19: ; preds = %11
%20 = call i32 @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
br label %23
21: ; preds = %11
%22 = call i32 @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
br label %23
23: ; preds = %21, %19
br label %24
24: ; preds = %23
%25 = load i32, i32* %5
%26 = add nsw i32 %25, -1
store i32 %26, i32* %5
br label %8
27: ; preds = %8
ret void
}

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