#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 *malloc(int);
char *binToStr(int value) {
  int i;
  char *output = malloc(11 * sizeof(char));
  output[10] = '\0';
  for (i = 9; i >= 0; --i, value >>= 1) {
    output[i] = (value & 1) + '0';
  }
  return output;
}


x86 assembly (clang, -O0):
<binToStr>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
mov    $0xb,%edi
call   1030 <malloc@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
movb   $0x0,0xa(%rax)
movl   $0x9,-0x8(%rbp)
cmpl   $0x0,-0x8(%rbp)
jl     116f <binToStr+0x5f>
mov    -0x4(%rbp),%eax
and    $0x1,%eax
add    $0x30,%eax
mov    %al,%dl
mov    -0x10(%rbp),%rax
movslq -0x8(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x8(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x8(%rbp)
mov    -0x4(%rbp),%eax
sar    $0x1,%eax
mov    %eax,-0x4(%rbp)
jmp    1138 <binToStr+0x28>
mov    -0x10(%rbp),%rax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<binToStr>:
push   %rbx
mov    %edi,%ebx
mov    $0xb,%edi
call   1030 <malloc@plt>
movb   $0x0,0xa(%rax)
mov    %ebx,%ecx
and    $0x1,%cl
or     $0x30,%cl
mov    %cl,0x9(%rax)
mov    %ebx,%ecx
shr    %cl
and    $0x1,%cl
or     $0x30,%cl
mov    %cl,0x8(%rax)
mov    %ebx,%ecx
shr    $0x2,%cl
and    $0x1,%cl
or     $0x30,%cl
mov    %cl,0x7(%rax)
mov    %ebx,%ecx
shr    $0x3,%cl
and    $0x1,%cl
or     $0x30,%cl
mov    %cl,0x6(%rax)
mov    %ebx,%ecx
shr    $0x4,%cl
and    $0x1,%cl
or     $0x30,%cl
mov    %cl,0x5(%rax)
mov    %ebx,%ecx
shr    $0x5,%cl
and    $0x1,%cl
or     $0x30,%cl
mov    %cl,0x4(%rax)
mov    %ebx,%ecx
shr    $0x6,%cl
and    $0x1,%cl
or     $0x30,%cl
mov    %cl,0x3(%rax)
mov    %ebx,%ecx
shr    $0x7,%cl
or     $0x30,%cl
mov    %cl,0x2(%rax)
mov    %ebx,%ecx
shr    $0x8,%ecx
and    $0x1,%cl
or     $0x30,%cl
mov    %cl,0x1(%rax)
shr    $0x9,%ebx
and    $0x1,%bl
or     $0x30,%bl
mov    %bl,(%rax)
pop    %rbx
ret

LLVM IR (-O0):
define i8* @binToStr(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i8*
store i32 %0, i32* %2
%5 = call i8* @malloc(i32 11)
store i8* %5, i8** %4
%6 = load i8*, i8** %4
%7 = getelementptr inbounds i8, i8* %6, i64 10
store i8 0, i8* %7
store i32 9, i32* %3
br label %8
8: ; preds = %20, %1
%9 = load i32, i32* %3
%10 = icmp sge i32 %9, 0
br i1 %10, label %11, label %25
11: ; preds = %8
%12 = load i32, i32* %2
%13 = and i32 %12, 1
%14 = add nsw i32 %13, 48
%15 = trunc i32 %14 to i8
%16 = load i8*, i8** %4
%17 = load i32, i32* %3
%18 = sext i32 %17 to i64
%19 = getelementptr inbounds i8, i8* %16, i64 %18
store i8 %15, i8* %19
br label %20
20: ; preds = %11
%21 = load i32, i32* %3
%22 = add nsw i32 %21, -1
store i32 %22, i32* %3
%23 = load i32, i32* %2
%24 = ashr i32 %23, 1
store i32 %24, i32* %2
br label %8
25: ; preds = %8
%26 = load i8*, i8** %4
ret i8* %26
}

LLVM IR (-O2):
define noalias i8* @binToStr(i32 %0) {
%2 = tail call dereferenceable_or_null(11) i8* @malloc(i32 11)
%3 = getelementptr inbounds i8, i8* %2, i64 10
store i8 0, i8* %3
%4 = trunc i32 %0 to i8
%5 = and i8 %4, 1
%6 = or i8 %5, 48
%7 = getelementptr inbounds i8, i8* %2, i64 9
store i8 %6, i8* %7
%8 = trunc i32 %0 to i8
%9 = lshr i8 %8, 1
%10 = and i8 %9, 1
%11 = or i8 %10, 48
%12 = getelementptr inbounds i8, i8* %2, i64 8
store i8 %11, i8* %12
%13 = trunc i32 %0 to i8
%14 = lshr i8 %13, 2
%15 = and i8 %14, 1
%16 = or i8 %15, 48
%17 = getelementptr inbounds i8, i8* %2, i64 7
store i8 %16, i8* %17
%18 = trunc i32 %0 to i8
%19 = lshr i8 %18, 3
%20 = and i8 %19, 1
%21 = or i8 %20, 48
%22 = getelementptr inbounds i8, i8* %2, i64 6
store i8 %21, i8* %22
%23 = trunc i32 %0 to i8
%24 = lshr i8 %23, 4
%25 = and i8 %24, 1
%26 = or i8 %25, 48
%27 = getelementptr inbounds i8, i8* %2, i64 5
store i8 %26, i8* %27
%28 = trunc i32 %0 to i8
%29 = lshr i8 %28, 5
%30 = and i8 %29, 1
%31 = or i8 %30, 48
%32 = getelementptr inbounds i8, i8* %2, i64 4
store i8 %31, i8* %32
%33 = trunc i32 %0 to i8
%34 = lshr i8 %33, 6
%35 = and i8 %34, 1
%36 = or i8 %35, 48
%37 = getelementptr inbounds i8, i8* %2, i64 3
store i8 %36, i8* %37
%38 = trunc i32 %0 to i8
%39 = lshr i8 %38, 7
%40 = or i8 %39, 48
%41 = getelementptr inbounds i8, i8* %2, i64 2
store i8 %40, i8* %41
%42 = lshr i32 %0, 8
%43 = trunc i32 %42 to i8
%44 = and i8 %43, 1
%45 = or i8 %44, 48
%46 = getelementptr inbounds i8, i8* %2, i64 1
store i8 %45, i8* %46
%47 = lshr i32 %0, 9
%48 = trunc i32 %47 to i8
%49 = and i8 %48, 1
%50 = or i8 %49, 48
store i8 %50, i8* %2
ret i8* %2
}