#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 printBits(unsigned short i) {
  int bits;
  for (bits = (sizeof(short) * 8) - 1; bits >= 0; bits--) {
    if (i & (1 << bits))
      printf("1");
    else
      printf("0");
    if (bits % 4 == 0)
      printf(" ");
  }
  printf("\n");
}


x86 assembly (clang, -O0):
<printBits>:
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 <printBits+0x8b>
movzwl -0x2(%rbp),%eax
mov    -0x8(%rbp),%ecx
mov    $0x1,%edx
shl    %cl,%edx
mov    %edx,%ecx
and    %ecx,%eax
cmp    $0x0,%eax
je     115c <printBits+0x4c>
lea    0xeae(%rip),%rdi
call   1030 <printf@plt>
jmp    1168 <printBits+0x58>
lea    0xe9f(%rip),%rdi
call   1030 <printf@plt>
mov    -0x8(%rbp),%eax
mov    $0x4,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
jne    1188 <printBits+0x78>
lea    0xe81(%rip),%rdi
call   1030 <printf@plt>
jmp    118d <printBits+0x7d>
mov    -0x8(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x8(%rbp)
jmp    1126 <printBits+0x16>
lea    0xe64(%rip),%rdi
call   1030 <printf@plt>
add    $0x10,%rsp
pop    %rbp
ret

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

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