#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 */
char getBitAt(unsigned int, int);
scalar_t__ malloc(int);
int /*<<< orphan*/ printf(char *, ...);
void printBits(unsigned int bitmap) {
  char *binary = (char *)malloc(sizeof(char *));
  binary = binary + 32;
  int i = 0;
  for (i = 0; i < 32; i++) {
    *binary = '0' + getBitAt(bitmap, i);
    binary--;
  }
  printf("%s\n", ++binary);
  for (i = 31; i >= 0; i--) {
    printf("%d", i % 10);
  }
  printf("\n");
}


x86 assembly (clang, -O0):
<printBits>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    $0x8,%edi
call   1050 <malloc@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
add    $0x20,%rax
mov    %rax,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
movl   $0x0,-0x14(%rbp)
cmpl   $0x20,-0x14(%rbp)
jge    11a0 <printBits+0x70>
mov    -0x4(%rbp),%edi
mov    -0x14(%rbp),%esi
call   1030 <getBitAt@plt>
movsbl %al,%eax
add    $0x30,%eax
mov    %al,%cl
mov    -0x10(%rbp),%rax
mov    %cl,(%rax)
mov    -0x10(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x10(%rbp)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1163 <printBits+0x33>
mov    -0x10(%rbp),%rsi
add    $0x1,%rsi
mov    %rsi,-0x10(%rbp)
lea    0xe4d(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x1f,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jl     11f4 <printBits+0xc4>
mov    -0x14(%rbp),%eax
mov    $0xa,%ecx
cltd
idiv   %ecx
mov    %edx,%esi
lea    0xe25(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x14(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x14(%rbp)
jmp    11c1 <printBits+0x91>
lea    0xe07(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<printBits>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %edi,%r14d
mov    $0x8,%edi
call   1070 <malloc@plt>
mov    %rax,%r15
add    $0x21,%r15
xor    %ebp,%ebp
nopl   (%rax)
mov    %r15,%rbx
add    $0xffffffffffffffff,%r15
mov    %r14d,%edi
mov    %ebp,%esi
call   1050 <getBitAt@plt>
add    $0x30,%al
mov    %al,-0x1(%rbx)
add    $0x1,%ebp
cmp    $0x20,%ebp
jne    1170 <printBits+0x20>
mov    %r15,%rdi
call   1040 <puts@plt>
mov    $0x1f,%ebp
mov    $0xffffffe0,%ebx
mov    $0xcccccccd,%r15d
lea    0xe53(%rip),%r14
nopl   (%rax)
mov    %ebp,%eax
imul   %r15,%rax
shr    $0x23,%rax
add    %eax,%eax
lea    (%rax,%rax,4),%eax
mov    %ebp,%esi
sub    %eax,%esi
mov    %r14,%rdi
xor    %eax,%eax
call   1060 <printf@plt>
add    $0xffffffff,%ebp
inc    %ebx
jne    11b0 <printBits+0x60>
mov    $0xa,%edi
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <putchar@plt>

LLVM IR (-O0):
@.str = [4 x i8] c"%s\0A\00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [2 x i8] c"\0A\00"
define void @printBits(i32 %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i32
store i32 %0, i32* %2
%5 = call i64 @malloc(i32 8)
%6 = inttoptr i64 %5 to i8*
store i8* %6, i8** %3
%7 = load i8*, i8** %3
%8 = getelementptr inbounds i8, i8* %7, i64 32
store i8* %8, i8** %3
store i32 0, i32* %4
store i32 0, i32* %4
br label %9
9: ; preds = %22, %1
%10 = load i32, i32* %4
%11 = icmp slt i32 %10, 32
br i1 %11, label %12, label %25
12: ; preds = %9
%13 = load i32, i32* %2
%14 = load i32, i32* %4
%15 = call signext i8 @getBitAt(i32 %13, i32 %14)
%16 = sext i8 %15 to i32
%17 = add nsw i32 48, %16
%18 = trunc i32 %17 to i8
%19 = load i8*, i8** %3
store i8 %18, i8* %19
%20 = load i8*, i8** %3
%21 = getelementptr inbounds i8, i8* %20, i32 -1
store i8* %21, i8** %3
br label %22
22: ; preds = %12
%23 = load i32, i32* %4
%24 = add nsw i32 %23, 1
store i32 %24, i32* %4
br label %9
25: ; preds = %9
%26 = load i8*, i8** %3
%27 = getelementptr inbounds i8, i8* %26, i32 1
store i8* %27, i8** %3
%28 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* %27)
store i32 31, i32* %4
br label %29
29: ; preds = %36, %25
%30 = load i32, i32* %4
%31 = icmp sge i32 %30, 0
br i1 %31, label %32, label %39
32: ; preds = %29
%33 = load i32, i32* %4
%34 = srem i32 %33, 10
%35 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 %34)
br label %36
36: ; preds = %32
%37 = load i32, i32* %4
%38 = add nsw i32 %37, -1
store i32 %38, i32* %4
br label %29
39: ; preds = %29
%40 = 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.1 = [3 x i8] c"%d\00"
define void @printBits(i32 %0) {
%2 = tail call i64 @malloc(i32 8)
%3 = inttoptr i64 %2 to i8*
%4 = getelementptr inbounds i8, i8* %3, i64 32
br label %5
5: ; preds = %1, %5
%6 = phi i32 [ 0, %1 ], [ %11, %5 ]
%7 = phi i8* [ %4, %1 ], [ %10, %5 ]
%8 = tail call signext i8 @getBitAt(i32 %0, i32 %6)
%9 = add i8 %8, 48
store i8 %9, i8* %7
%10 = getelementptr inbounds i8, i8* %7, i64 -1
%11 = add nuw nsw i32 %6, 1
%12 = icmp eq i32 %11, 32
br i1 %12, label %13, label %5
13: ; preds = %5
%14 = tail call i32 @puts(i8* %7)
br label %15
15: ; preds = %13, %15
%16 = phi i32 [ 31, %13 ], [ %19, %15 ]
%17 = urem i32 %16, 10
%18 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 %17)
%19 = add nsw i32 %16, -1
%20 = icmp eq i32 %16, 0
br i1 %20, label %21, label %15
21: ; preds = %15
%22 = tail call i32 @putchar(i32 10)
ret void
}