#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 *);
int /*<<< orphan*/ putchar(char);
void printbin(unsigned int n, unsigned int i, unsigned int length) {
  if (n == 0) {
    if (i <= length) {
      for (int j = 0; j < length - i; j++) {
        printf("0");
        if (j % 4 == 3) {
          putchar(' ');
        }
      }
    }
    return;
  } else {
    i++;
    if (n & 1) {
      n >>= 1;
      printbin(n, i, length);
      putchar('1');
    } else {
      n >>= 1;
      printbin(n, i, length);
      putchar('0');
    }
    if (i % 4 == 1) {
      putchar(' ');
    }
  }
}


x86 assembly (clang, -O0):
<printbin>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %edx,-0xc(%rbp)
cmpl   $0x0,-0x4(%rbp)
jne    11b6 <printbin+0x86>
mov    -0x8(%rbp),%eax
cmp    -0xc(%rbp),%eax
ja     11b1 <printbin+0x81>
movl   $0x0,-0x10(%rbp)
mov    -0x10(%rbp),%eax
mov    -0xc(%rbp),%ecx
sub    -0x8(%rbp),%ecx
cmp    %ecx,%eax
jae    11ac <printbin+0x7c>
lea    0xe8a(%rip),%rdi
call   1040 <printf@plt>
mov    -0x10(%rbp),%eax
mov    $0x4,%ecx
cltd
idiv   %ecx
cmp    $0x3,%edx
jne    1199 <printbin+0x69>
mov    $0x20,%edi
call   1030 <putchar@plt>
jmp    119e <printbin+0x6e>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    115e <printbin+0x2e>
jmp    11b1 <printbin+0x81>
jmp    1233 <printbin+0x103>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
mov    -0x4(%rbp),%eax
and    $0x1,%eax
cmp    $0x0,%eax
je     11f4 <printbin+0xc4>
mov    -0x4(%rbp),%eax
shr    $0x1,%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%edi
mov    -0x8(%rbp),%esi
mov    -0xc(%rbp),%edx
call   1050 <printbin@plt>
mov    $0x31,%edi
call   1030 <putchar@plt>
jmp    1215 <printbin+0xe5>
mov    -0x4(%rbp),%eax
shr    $0x1,%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%edi
mov    -0x8(%rbp),%esi
mov    -0xc(%rbp),%edx
call   1050 <printbin@plt>
mov    $0x30,%edi
call   1030 <putchar@plt>
mov    -0x8(%rbp),%eax
and    $0x3,%eax
cmp    $0x1,%eax
jne    122e <printbin+0xfe>
mov    $0x20,%edi
call   1030 <putchar@plt>
jmp    1233 <printbin+0x103>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<printbin>:
push   %rbp
push   %r14
push   %rbx
mov    %edx,%r14d
mov    %esi,%ebp
test   %edi,%edi
je     1161 <printbin+0x41>
add    $0x1,%ebp
mov    %edi,%ebx
and    $0x1,%ebx
shr    %edi
mov    %ebp,%esi
mov    %r14d,%edx
call   1040 <printbin@plt>
or     $0x30,%ebx
mov    %ebx,%edi
call   1030 <putchar@plt>
and    $0x3,%ebp
cmp    $0x1,%ebp
jne    1196 <printbin+0x76>
mov    $0x20,%edi
pop    %rbx
pop    %r14
pop    %rbp
jmp    1030 <putchar@plt>
sub    %ebp,%r14d
jb     1196 <printbin+0x76>
je     1196 <printbin+0x76>
xor    %ebx,%ebx
jmp    1178 <printbin+0x58>
nopl   0x0(%rax)
add    $0x1,%ebx
cmp    %ebx,%r14d
je     1196 <printbin+0x76>
mov    $0x30,%edi
call   1030 <putchar@plt>
mov    %ebx,%eax
not    %eax
test   $0x3,%al
jne    1170 <printbin+0x50>
mov    $0x20,%edi
call   1030 <putchar@plt>
jmp    1170 <printbin+0x50>
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [2 x i8] c"0\00"
define void @printbin(i32 %0, i32 %1, i32 %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
store i32 %0, i32* %4
store i32 %1, i32* %5
store i32 %2, i32* %6
%8 = load i32, i32* %4
%9 = icmp eq i32 %8, 0
br i1 %9, label %10, label %34
10: ; preds = %3
%11 = load i32, i32* %5
%12 = load i32, i32* %6
%13 = icmp ule i32 %11, %12
br i1 %13, label %14, label %33
14: ; preds = %10
store i32 0, i32* %7
br label %15
15: ; preds = %29, %14
%16 = load i32, i32* %7
%17 = load i32, i32* %6
%18 = load i32, i32* %5
%19 = sub i32 %17, %18
%20 = icmp ult i32 %16, %19
br i1 %20, label %21, label %32
21: ; preds = %15
%22 = call i32 @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%23 = load i32, i32* %7
%24 = srem i32 %23, 4
%25 = icmp eq i32 %24, 3
br i1 %25, label %26, label %28
26: ; preds = %21
%27 = call i32 @putchar(i8 signext 32)
br label %28
28: ; preds = %26, %21
br label %29
29: ; preds = %28
%30 = load i32, i32* %7
%31 = add nsw i32 %30, 1
store i32 %31, i32* %7
br label %15
32: ; preds = %15
br label %33
33: ; preds = %32, %10
br label %61
34: ; preds = %3
%35 = load i32, i32* %5
%36 = add i32 %35, 1
store i32 %36, i32* %5
%37 = load i32, i32* %4
%38 = and i32 %37, 1
%39 = icmp ne i32 %38, 0
br i1 %39, label %40, label %47
40: ; preds = %34
%41 = load i32, i32* %4
%42 = lshr i32 %41, 1
store i32 %42, i32* %4
%43 = load i32, i32* %4
%44 = load i32, i32* %5
%45 = load i32, i32* %6
%46 = call i32 @putchar(i8 signext 49)
br label %54
47: ; preds = %34
%48 = load i32, i32* %4
%49 = lshr i32 %48, 1
store i32 %49, i32* %4
%50 = load i32, i32* %4
%51 = load i32, i32* %5
%52 = load i32, i32* %6
%53 = call i32 @putchar(i8 signext 48)
br label %54
54: ; preds = %47, %40
%55 = load i32, i32* %5
%56 = urem i32 %55, 4
%57 = icmp eq i32 %56, 1
br i1 %57, label %58, label %60
58: ; preds = %54
%59 = call i32 @putchar(i8 signext 32)
br label %60
60: ; preds = %58, %54
br label %61
61: ; preds = %33, %60
ret void
}

LLVM IR (-O2):
define void @printbin(i32 %0, i32 %1, i32 %2) {
%4 = icmp eq i32 %0, 0
br i1 %4, label %5, label %20
5: ; preds = %3
%6 = icmp ult i32 %2, %1
br i1 %6, label %31, label %7
7: ; preds = %5
%8 = sub i32 %2, %1
%9 = icmp eq i32 %8, 0
br i1 %9, label %31, label %10
10: ; preds = %7, %17
%11 = phi i32 [ %18, %17 ], [ 0, %7 ]
%12 = tail call i32 bitcast (i32 (i8)* @putchar to i32 (i32)*)(i32 48)
%13 = and i32 %11, 3
%14 = icmp eq i32 %13, 3
br i1 %14, label %15, label %17
15: ; preds = %10
%16 = tail call i32 @putchar(i8 signext 32)
br label %17
17: ; preds = %10, %15
%18 = add nuw i32 %11, 1
%19 = icmp eq i32 %18, %8
br i1 %19, label %31, label %10
20: ; preds = %3
%21 = add i32 %1, 1
%22 = and i32 %0, 1
%23 = icmp eq i32 %22, 0
%24 = lshr i32 %0, 1
tail call void @printbin(i32 %24, i32 %21, i32 %2)
%25 = select i1 %23, i8 48, i8 49
%26 = tail call i32 @putchar(i8 signext %25)
%27 = and i32 %21, 3
%28 = icmp eq i32 %27, 1
br i1 %28, label %29, label %31
29: ; preds = %20
%30 = tail call i32 @putchar(i8 signext 32)
br label %31
31: ; preds = %17, %7, %20, %29, %5
ret void
}