#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 printbin(int num) {
  int binary[32] = {0};
  int index = 0;
  while (num > 0) {
    binary[index++] = num % 2;
    num /= 2;
  }
  while ((index + 1) % 4 != 0)
    index++;
  int i;
  for (i = index; i >= 0; i--) {
    if (i % 4 == 0)
      printf("%d ", binary[i]);
    else
      printf("%d", binary[i]);
  }
  printf("\n");
}


x86 assembly (clang, -O0):
<printbin>:
push   %rbp
mov    %rsp,%rbp
sub    $0xa0,%rsp
mov    %edi,-0x4(%rbp)
lea    -0x90(%rbp),%rdi
xor    %esi,%esi
mov    $0x80,%edx
call   1040 <memset@plt>
movl   $0x0,-0x94(%rbp)
cmpl   $0x0,-0x4(%rbp)
jle    118d <printbin+0x6d>
mov    -0x4(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    -0x94(%rbp),%eax
mov    %eax,%ecx
add    $0x1,%ecx
mov    %ecx,-0x94(%rbp)
cltq
mov    %edx,-0x90(%rbp,%rax,4)
mov    -0x4(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,-0x4(%rbp)
jmp    114b <printbin+0x2b>
jmp    1192 <printbin+0x72>
mov    -0x94(%rbp),%eax
add    $0x1,%eax
mov    $0x4,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
je     11c0 <printbin+0xa0>
mov    -0x94(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x94(%rbp)
jmp    1192 <printbin+0x72>
mov    -0x94(%rbp),%eax
mov    %eax,-0x98(%rbp)
cmpl   $0x0,-0x98(%rbp)
jl     1246 <printbin+0x126>
mov    -0x98(%rbp),%eax
mov    $0x4,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
jne    1211 <printbin+0xf1>
movslq -0x98(%rbp),%rax
mov    -0x90(%rbp,%rax,4),%esi
lea    0xdfb(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    122d <printbin+0x10d>
movslq -0x98(%rbp),%rax
mov    -0x90(%rbp,%rax,4),%esi
lea    0xdde(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    1232 <printbin+0x112>
mov    -0x98(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x98(%rbp)
jmp    11cc <printbin+0xac>
lea    0xdba(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
add    $0xa0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<printbin>:
push   %r15
push   %r14
push   %rbx
sub    $0x80,%rsp
xorps  %xmm0,%xmm0
movaps %xmm0,0x70(%rsp)
movaps %xmm0,0x60(%rsp)
movaps %xmm0,0x50(%rsp)
movaps %xmm0,0x40(%rsp)
movaps %xmm0,0x30(%rsp)
movaps %xmm0,0x20(%rsp)
movaps %xmm0,0x10(%rsp)
movaps %xmm0,(%rsp)
xor    %eax,%eax
test   %edi,%edi
jle    1175 <printbin+0x55>
mov    %edi,%ecx
xchg   %ax,%ax
mov    %edi,%edx
and    $0x1,%edx
mov    %edx,(%rsp,%rax,4)
add    $0x1,%rax
shr    %ecx
cmp    $0x2,%edi
mov    %ecx,%edi
jae    1160 <printbin+0x40>
mov    %eax,%ecx
not    %ecx
and    $0x3,%ecx
add    %eax,%ecx
js     11b0 <printbin+0x90>
mov    %ecx,%ebx
lea    0xe77(%rip),%r14
lea    0xe74(%rip),%r15
test   $0x3,%bl
mov    (%rsp,%rbx,4),%esi
mov    %r15,%rdi
cmove  %r14,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
lea    -0x1(%rbx),%rax
test   %rbx,%rbx
mov    %rax,%rbx
jg     1190 <printbin+0x70>
mov    $0xa,%edi
add    $0x80,%rsp
pop    %rbx
pop    %r14
pop    %r15
jmp    1030 <putchar@plt>

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

LLVM IR (-O2):
@.str = [4 x i8] c"%d \00"
@.str.1 = [3 x i8] c"%d\00"
define void @printbin(i32 %0) {
%2 = alloca [32 x i32]
%3 = bitcast [32 x i32]* %2 to i8*
%4 = icmp sgt i32 %0, 0
br i1 %4, label %13, label %7
5: ; preds = %13
%6 = trunc i64 %17 to i32
br label %7
7: ; preds = %5, %1
%8 = phi i32 [ 0, %1 ], [ %6, %5 ]
%9 = and i32 %8, 3
%10 = xor i32 %9, 3
%11 = add i32 %8, %10
%12 = icmp sgt i32 %11, -1
br i1 %12, label %21, label %33
13: ; preds = %1, %13
%14 = phi i64 [ %17, %13 ], [ 0, %1 ]
%15 = phi i32 [ %19, %13 ], [ %0, %1 ]
%16 = and i32 %15, 1
%17 = add nuw nsw i64 %14, 1
%18 = getelementptr inbounds [32 x i32], [32 x i32]* %2, i64 0, i64 %14
store i32 %16, i32* %18
%19 = lshr i32 %15, 1
%20 = icmp ult i32 %15, 2
br i1 %20, label %5, label %13
21: ; preds = %7
%22 = zext i32 %11 to i64
br label %23
23: ; preds = %21, %23
%24 = phi i64 [ %22, %21 ], [ %31, %23 ]
%25 = and i64 %24, 3
%26 = icmp eq i64 %25, 0
%27 = getelementptr inbounds [32 x i32], [32 x i32]* %2, i64 0, i64 %24
%28 = load i32, i32* %27
%29 = select i1 %26, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0)
%30 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) %29, i32 %28)
%31 = add nsw i64 %24, -1
%32 = icmp sgt i64 %24, 0
br i1 %32, label %23, label %33
33: ; preds = %23, %7
%34 = tail call i32 @putchar(i32 10)
ret void
}