#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 printAsBinary(short numToPrint) {
  for (int i = 15; i >= 0; i--) {
    int j = numToPrint >> i;
    if (j & 1) {
      printf("1");
    } else {
      printf("0");
    }
    if (i % 4 == 0) {
      printf(" ");
    }
  }
}


x86 assembly (clang, -O0):
<printAsBinary>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %di,%ax
mov    %ax,-0x2(%rbp)
movl   $0xf,-0x8(%rbp)
cmpl   $0x0,-0x8(%rbp)
jl     119b <printAsBinary+0x8b>
movswl -0x2(%rbp),%eax
mov    -0x8(%rbp),%ecx
sar    %cl,%eax
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%eax
and    $0x1,%eax
cmp    $0x0,%eax
je     115c <printAsBinary+0x4c>
lea    0xeae(%rip),%rdi
call   1030 <printf@plt>
jmp    1168 <printAsBinary+0x58>
lea    0xe9f(%rip),%rdi
call   1030 <printf@plt>
mov    -0x8(%rbp),%eax
mov    $0x4,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
jne    1188 <printAsBinary+0x78>
lea    0xe81(%rip),%rdi
call   1030 <printf@plt>
jmp    118d <printAsBinary+0x7d>
mov    -0x8(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x8(%rbp)
jmp    1126 <printAsBinary+0x16>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<printAsBinary>:
push   %rbp
push   %rbx
push   %rax
mov    %edi,%ebx
mov    $0xf,%ebp
jmp    1125 <printAsBinary+0x15>
nopl   0x0(%rax)
add    $0xffffffff,%ebp
jae    1147 <printAsBinary+0x37>
bt     %ebp,%ebx
mov    $0x31,%edi
adc    $0xffffffff,%edi
call   1030 <putchar@plt>
test   $0x3,%bpl
jne    1120 <printAsBinary+0x10>
mov    $0x20,%edi
call   1030 <putchar@plt>
jmp    1120 <printAsBinary+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"
@.str.2 = [2 x i8] c" \00"
define void @printAsBinary(i16 signext %0) {
%2 = alloca i16
%3 = alloca i32
%4 = alloca i32
store i16 %0, i16* %2
store i32 15, i32* %3
br label %5
5: ; preds = %27, %1
%6 = load i32, i32* %3
%7 = icmp sge i32 %6, 0
br i1 %7, label %8, label %30
8: ; preds = %5
%9 = load i16, i16* %2
%10 = sext i16 %9 to i32
%11 = load i32, i32* %3
%12 = ashr i32 %10, %11
store i32 %12, i32* %4
%13 = load i32, i32* %4
%14 = and i32 %13, 1
%15 = icmp ne i32 %14, 0
br i1 %15, label %16, label %18
16: ; preds = %8
%17 = call i32 @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
br label %20
18: ; preds = %8
%19 = call i32 @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
br label %20
20: ; preds = %18, %16
%21 = load i32, i32* %3
%22 = srem i32 %21, 4
%23 = icmp eq i32 %22, 0
br i1 %23, label %24, label %26
24: ; preds = %20
%25 = call i32 @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
br label %26
26: ; preds = %24, %20
br label %27
27: ; preds = %26
%28 = load i32, i32* %3
%29 = add nsw i32 %28, -1
store i32 %29, i32* %3
br label %5
30: ; preds = %5
ret void
}

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