#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 */
scalar_t__ realloc(char *, int);
int /*<<< orphan*/ strcat(char *, char *);
char *toBin(int n, char **buffer, int bits_per_component) {
  *buffer = (char *)realloc(*buffer, sizeof(int) * 8 + 1 + 1);
  *buffer[0] = 0;
  for (int c = sizeof(int) * 8 - 1; c >= 0; c--) {
    if ((n >> c) & 1)
      strcat(*buffer, "1");
    else
      strcat(*buffer, "0");
    if (c == bits_per_component)
      strcat(*buffer, " ");
  }
  return *buffer;
}


x86 assembly (clang, -O0):
<toBin>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
mov    $0x22,%esi
call   1030 <realloc@plt>
mov    %rax,%rcx
mov    -0x10(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
movb   $0x0,(%rax)
movl   $0x1f,-0x18(%rbp)
cmpl   $0x0,-0x18(%rbp)
jl     11d9 <toBin+0xb9>
mov    -0x4(%rbp),%eax
mov    -0x18(%rbp),%ecx
sar    %cl,%eax
and    $0x1,%eax
cmp    $0x0,%eax
je     1194 <toBin+0x74>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
lea    0xe76(%rip),%rsi
call   1040 <strcat@plt>
jmp    11a7 <toBin+0x87>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
lea    0xe60(%rip),%rsi
call   1040 <strcat@plt>
mov    -0x18(%rbp),%eax
cmp    -0x14(%rbp),%eax
jne    11c6 <toBin+0xa6>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
lea    0xe43(%rip),%rsi
call   1040 <strcat@plt>
jmp    11cb <toBin+0xab>
mov    -0x18(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x18(%rbp)
jmp    115e <toBin+0x3e>
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<toBin>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %edx,%r14d
mov    %rsi,%rbx
mov    %edi,%r12d
mov    (%rsi),%rdi
mov    $0x22,%esi
call   1030 <realloc@plt>
mov    %rax,(%rbx)
movb   $0x0,(%rax)
mov    $0x1f,%ebp
lea    0xeaf(%rip),%r13
lea    0xea6(%rip),%r15
jmp    1165 <toBin+0x45>
nopl   0x0(%rax)
add    $0xffffffff,%ebp
jae    118e <toBin+0x6e>
bt     %ebp,%r12d
mov    (%rbx),%rdi
mov    %r15,%rsi
cmovae %r13,%rsi
call   1040 <strcat@plt>
cmp    %ebp,%r14d
jne    1160 <toBin+0x40>
mov    (%rbx),%rdi
lea    0xe7d(%rip),%rsi
call   1040 <strcat@plt>
jmp    1160 <toBin+0x40>
mov    (%rbx),%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
@.str = [2 x i8] c"1\00"
@.str.1 = [2 x i8] c"0\00"
@.str.2 = [2 x i8] c" \00"
define i8* @toBin(i32 %0, i8** nocapture %1, i32 %2) {
%4 = load i8*, i8** %1
%5 = tail call i64 @realloc(i8* %4, i32 34)
%6 = inttoptr i64 %5 to i8*
store i8* %6, i8** %1
store i8 0, i8* %6
br label %9
7: ; preds = %21
%8 = load i8*, i8** %1
ret i8* %8
9: ; preds = %3, %21
%10 = phi i32 [ 31, %3 ], [ %22, %21 ]
%11 = shl nuw i32 1, %10
%12 = and i32 %11, %0
%13 = icmp eq i32 %12, 0
%14 = load i8*, i8** %1
%15 = select i1 %13, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0)
%16 = tail call i32 @strcat(i8* %14, i8* %15)
%17 = icmp eq i32 %10, %2
br i1 %17, label %18, label %21
18: ; preds = %9
%19 = load i8*, i8** %1
%20 = tail call i32 @strcat(i8* %19, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
br label %21
21: ; preds = %9, %18
%22 = add nsw i32 %10, -1
%23 = icmp eq i32 %10, 0
br i1 %23, label %7, label %9
}