#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 getSize(int);
int /*<<< orphan*/ printf(char *, ...);
void printBits(int x) {
  int i = 0;
  int size = getSize(x);
  char bytes[size];
  for (i = 0; i < size; i++)
    bytes[i] = '0';
  for (i = 0; x; x >>= 1, i++)
    bytes[i] = ('0' + (char)(x & 1));
  for (i = size - 1; i >= 0; i--) {
    printf("%c", bytes[i]);
    if (i % 8 == 0)
      printf(" ");
  }
}


x86 assembly (clang, -O0):
<printBits>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
movl   $0x0,-0x8(%rbp)
mov    -0x4(%rbp),%edi
call   1040 <getSize@plt>
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%eax
mov    %rsp,%rcx
mov    %rcx,-0x18(%rbp)
mov    %rax,%rdx
add    $0xf,%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x28(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x20(%rbp)
movl   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    1190 <printBits+0x70>
mov    -0x28(%rbp),%rax
movslq -0x8(%rbp),%rcx
movb   $0x30,(%rax,%rcx,1)
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    116a <printBits+0x4a>
movl   $0x0,-0x8(%rbp)
cmpl   $0x0,-0x4(%rbp)
je     11d1 <printBits+0xb1>
mov    -0x28(%rbp),%rax
mov    -0x4(%rbp),%ecx
and    $0x1,%ecx
movsbl %cl,%ecx
add    $0x30,%ecx
mov    %cl,%dl
movslq -0x8(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x4(%rbp),%eax
sar    $0x1,%eax
mov    %eax,-0x4(%rbp)
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    1197 <printBits+0x77>
mov    -0xc(%rbp),%eax
sub    $0x1,%eax
mov    %eax,-0x8(%rbp)
cmpl   $0x0,-0x8(%rbp)
jl     1233 <printBits+0x113>
mov    -0x28(%rbp),%rax
movslq -0x8(%rbp),%rcx
movsbl (%rax,%rcx,1),%esi
lea    0xe09(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x8(%rbp),%eax
mov    $0x8,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
jne    1220 <printBits+0x100>
lea    0xdea(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    1225 <printBits+0x105>
mov    -0x8(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x8(%rbp)
jmp    11da <printBits+0xba>
mov    -0x18(%rbp),%rax
mov    %rax,%rsp
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<printBits>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %edi,%r15d
call   1050 <getSize@plt>
mov    %eax,%r12d
mov    %rsp,%r14
lea    0xf(%r12),%rcx
and    $0xfffffffffffffff0,%rcx
sub    %rcx,%r14
mov    %r14,%rsp
test   %eax,%eax
jle    116c <printBits+0x3c>
mov    %r14,%rdi
mov    $0x30,%esi
mov    %r12,%rdx
call   1040 <memset@plt>
test   %r15d,%r15d
je     119a <printBits+0x6a>
mov    %r14,%rax
mov    %r15d,%ecx
nopw   0x0(%rax,%rax,1)
mov    %r15d,%edx
and    $0x1,%dl
or     $0x30,%dl
mov    %dl,(%rax)
sar    %ecx
add    $0x1,%rax
cmp    $0x2,%r15d
mov    %ecx,%r15d
jae    1180 <printBits+0x50>
test   %r12d,%r12d
jle    11dc <printBits+0xac>
add    $0x1,%r12
jmp    11ba <printBits+0x8a>
cs nopw 0x0(%rax,%rax,1)
nop
add    $0xffffffffffffffff,%r12
cmp    $0x1,%r12
jle    11dc <printBits+0xac>
lea    -0x2(%r12),%rbx
mov    %ebx,%eax
movsbl (%r14,%rax,1),%edi
call   1030 <putchar@plt>
test   $0x7,%bl
jne    11b0 <printBits+0x80>
mov    $0x20,%edi
call   1030 <putchar@plt>
jmp    11b0 <printBits+0x80>
lea    -0x20(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
define void @printBits(i32 %0) {
%2 = tail call i32 @getSize(i32 %0)
%3 = zext i32 %2 to i64
%4 = alloca i8, i64 %3
%5 = icmp sgt i32 %2, 0
br i1 %5, label %6, label %7
6: ; preds = %1
br label %7
7: ; preds = %6, %1
%8 = icmp eq i32 %0, 0
br i1 %8, label %9, label %10
9: ; preds = %10, %7
br i1 %5, label %20, label %34
10: ; preds = %7, %10
%11 = phi i64 [ %18, %10 ], [ 0, %7 ]
%12 = phi i32 [ %17, %10 ], [ %0, %7 ]
%13 = trunc i32 %12 to i8
%14 = and i8 %13, 1
%15 = or i8 %14, 48
%16 = getelementptr inbounds i8, i8* %4, i64 %11
store i8 %15, i8* %16
%17 = ashr i32 %12, 1
%18 = add nuw i64 %11, 1
%19 = icmp ult i32 %12, 2
br i1 %19, label %9, label %10
20: ; preds = %9, %32
%21 = phi i64 [ %22, %32 ], [ %3, %9 ]
%22 = add nsw i64 %21, -1
%23 = and i64 %22, 4294967295
%24 = getelementptr inbounds i8, i8* %4, i64 %23
%25 = load i8, i8* %24
%26 = sext i8 %25 to i32
%27 = tail call i32 @putchar(i32 %26)
%28 = and i64 %22, 7
%29 = icmp eq i64 %28, 0
br i1 %29, label %30, label %32
30: ; preds = %20
%31 = tail call i32 @putchar(i32 32)
br label %32
32: ; preds = %20, %30
%33 = icmp sgt i64 %21, 1
br i1 %33, label %20, label %34
34: ; preds = %32, %9
ret void
}