#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 printBinary(unsigned int i, unsigned int bits) {
  int x;
  for (x = bits - 1; x >= 0; x--) {
    printf("%d", (i & (1 << x)) ? 1 : 0);
    if (x % 16 == 0 && x > 0) {
      printf(" ");
    } else if (x % 4 == 0 && x > 0) {
      printf(":");
    }
  }
}


x86 assembly (clang, -O0):
<printBinary>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    -0x8(%rbp),%eax
sub    $0x1,%eax
mov    %eax,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
jl     11d6 <printBinary+0xc6>
mov    -0x4(%rbp),%eax
mov    %eax,-0x10(%rbp)
mov    -0xc(%rbp),%ecx
mov    $0x1,%eax
shl    %cl,%eax
mov    -0x10(%rbp),%ecx
and    %eax,%ecx
xor    %esi,%esi
mov    $0x1,%eax
cmp    $0x0,%ecx
cmovne %eax,%esi
lea    0xea6(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0xc(%rbp),%eax
mov    $0x10,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
jne    1192 <printBinary+0x82>
cmpl   $0x0,-0xc(%rbp)
jle    1192 <printBinary+0x82>
lea    0xe7d(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    11c3 <printBinary+0xb3>
mov    -0xc(%rbp),%eax
mov    $0x4,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
jne    11be <printBinary+0xae>
cmpl   $0x0,-0xc(%rbp)
jle    11be <printBinary+0xae>
lea    0xe4e(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    11c3 <printBinary+0xb3>
jmp    11c8 <printBinary+0xb8>
mov    -0xc(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0xc(%rbp)
jmp    1127 <printBinary+0x17>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<printBinary>:
push   %rbp
push   %r14
push   %rbx
mov    %esi,%ebx
add    $0xffffffff,%ebx
js     117f <printBinary+0x5f>
mov    %edi,%ebp
lea    0xecc(%rip),%r14
jmp    114a <printBinary+0x2a>
cs nopw 0x0(%rax,%rax,1)
call   1030 <putchar@plt>
add    $0xffffffff,%ebx
js     117f <printBinary+0x5f>
mov    %ebp,%esi
mov    %ebx,%ecx
shr    %cl,%esi
and    $0x1,%esi
mov    %r14,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
test   %ebx,%ebx
je     116d <printBinary+0x4d>
mov    %ebx,%eax
mov    $0x20,%edi
and    $0xf,%eax
je     1140 <printBinary+0x20>
test   %ebx,%ebx
je     1145 <printBinary+0x25>
mov    %ebx,%eax
mov    $0x3a,%edi
and    $0x3,%eax
je     1140 <printBinary+0x20>
jmp    1145 <printBinary+0x25>
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [3 x i8] c"%d\00"
@.str.1 = [2 x i8] c" \00"
@.str.2 = [2 x i8] c":\00"
define void @printBinary(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
store i32 %0, i32* %3
store i32 %1, i32* %4
%6 = load i32, i32* %4
%7 = sub i32 %6, 1
store i32 %7, i32* %5
br label %8
8: ; preds = %39, %2
%9 = load i32, i32* %5
%10 = icmp sge i32 %9, 0
br i1 %10, label %11, label %42
11: ; preds = %8
%12 = load i32, i32* %3
%13 = load i32, i32* %5
%14 = shl i32 1, %13
%15 = and i32 %12, %14
%16 = icmp ne i32 %15, 0
%17 = zext i1 %16 to i64
%18 = select i1 %16, i32 1, i32 0
%19 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 %18)
%20 = load i32, i32* %5
%21 = srem i32 %20, 16
%22 = icmp eq i32 %21, 0
br i1 %22, label %23, label %28
23: ; preds = %11
%24 = load i32, i32* %5
%25 = icmp sgt i32 %24, 0
br i1 %25, label %26, label %28
26: ; preds = %23
%27 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
br label %38
28: ; preds = %23, %11
%29 = load i32, i32* %5
%30 = srem i32 %29, 4
%31 = icmp eq i32 %30, 0
br i1 %31, label %32, label %37
32: ; preds = %28
%33 = load i32, i32* %5
%34 = icmp sgt i32 %33, 0
br i1 %34, label %35, label %37
35: ; preds = %32
%36 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
br label %37
37: ; preds = %35, %32, %28
br label %38
38: ; preds = %37, %26
br label %39
39: ; preds = %38
%40 = load i32, i32* %5
%41 = add nsw i32 %40, -1
store i32 %41, i32* %5
br label %8
42: ; preds = %8
ret void
}

LLVM IR (-O2):
@.str = [3 x i8] c"%d\00"
define void @printBinary(i32 %0, i32 %1) {
%3 = add i32 %1, -1
%4 = icmp sgt i32 %3, -1
br i1 %4, label %5, label %24
5: ; preds = %2, %21
%6 = phi i32 [ %22, %21 ], [ %3, %2 ]
%7 = lshr i32 %0, %6
%8 = and i32 %7, 1
%9 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 %8)
%10 = and i32 %6, 15
%11 = icmp eq i32 %10, 0
%12 = icmp ne i32 %6, 0
%13 = and i1 %12, %11
br i1 %13, label %18, label %14
14: ; preds = %5
%15 = and i32 %6, 3
%16 = icmp eq i32 %15, 0
%17 = and i1 %12, %16
br i1 %17, label %18, label %21
18: ; preds = %14, %5
%19 = phi i32 [ 32, %5 ], [ 58, %14 ]
%20 = tail call i32 @putchar(i32 %19)
br label %21
21: ; preds = %18, %14
%22 = add i32 %6, -1
%23 = icmp sgt i32 %22, -1
br i1 %23, label %5, label %24
24: ; preds = %21, %2
ret void
}