#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*/ InvString(char *);
char *malloc(int);
int /*<<< orphan*/ strcat(char *, char *);
int /*<<< orphan*/ strcpy(char *, int /*<<< orphan*/);
char *IntToBin(long int real, int prec) {
  int sign;
  if (prec == 1)
    sign = 23;
  else
    sign = 52;
  char *bin = malloc(sizeof(char) * (sign + 1 + 1));
  int i;
  long int deci;
  deci = real;
  if (deci == 0)
    strcat(bin, "0");
  for (i = 0; i < sign + 2; i++) {
    if (deci == 0)
      break;
    if (deci % 2)
      strcat(bin, "1");
    else
      strcat(bin, "0");
    deci = deci / 2;
  }
  strcpy(bin, InvString(bin));
  return bin;
}


x86 assembly (clang, -O0):
<IntToBin>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
cmpl   $0x1,-0xc(%rbp)
jne    1165 <IntToBin+0x25>
movl   $0x17,-0x10(%rbp)
jmp    116c <IntToBin+0x2c>
movl   $0x34,-0x10(%rbp)
mov    -0x10(%rbp),%eax
add    $0x1,%eax
add    $0x1,%eax
cltq
shl    $0x0,%rax
mov    %eax,%edi
call   1050 <malloc@plt>
mov    %rax,-0x18(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    11a9 <IntToBin+0x69>
mov    -0x18(%rbp),%rdi
lea    0xe5c(%rip),%rsi
call   1060 <strcat@plt>
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
mov    -0x10(%rbp),%ecx
add    $0x2,%ecx
cmp    %ecx,%eax
jge    122e <IntToBin+0xee>
cmpq   $0x0,-0x28(%rbp)
jne    11d1 <IntToBin+0x91>
jmp    122e <IntToBin+0xee>
mov    -0x28(%rbp),%rax
mov    $0x2,%ecx
cqto
idiv   %rcx
cmp    $0x0,%rdx
je     11fe <IntToBin+0xbe>
mov    -0x18(%rbp),%rdi
lea    0xe0e(%rip),%rsi
call   1060 <strcat@plt>
jmp    120e <IntToBin+0xce>
mov    -0x18(%rbp),%rdi
lea    0xdf7(%rip),%rsi
call   1060 <strcat@plt>
mov    -0x28(%rbp),%rax
mov    $0x2,%ecx
cqto
idiv   %rcx
mov    %rax,-0x28(%rbp)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    11b0 <IntToBin+0x70>
mov    -0x18(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x18(%rbp),%rdi
call   1040 <InvString@plt>
mov    -0x30(%rbp),%rdi
mov    %eax,%esi
call   1030 <strcpy@plt>
mov    -0x18(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<IntToBin>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rdi,%rbx
cmp    $0x1,%esi
mov    $0x19,%eax
mov    $0x36,%r15d
cmove  %eax,%r15d
mov    %r15d,%edi
call   1050 <malloc@plt>
mov    %rax,%r14
test   %rbx,%rbx
je     11c6 <IntToBin+0x86>
mov    $0x1,%ebp
lea    0xe84(%rip),%r12
lea    0xe7f(%rip),%r13
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
test   $0x1,%bl
mov    %r13,%rsi
cmove  %r12,%rsi
mov    %r14,%rdi
call   1060 <strcat@plt>
cmp    %r15d,%ebp
jae    11d5 <IntToBin+0x95>
mov    %rbx,%rax
shr    $0x3f,%rax
add    %rbx,%rax
sar    %rax
add    $0x1,%rbx
add    $0x1,%ebp
cmp    $0x2,%rbx
mov    %rax,%rbx
ja     1190 <IntToBin+0x50>
jmp    11d5 <IntToBin+0x95>
lea    0xe33(%rip),%rsi
mov    %r14,%rdi
call   1060 <strcat@plt>
mov    %r14,%rdi
call   1040 <InvString@plt>
mov    %r14,%rdi
mov    %eax,%esi
call   1030 <strcpy@plt>
mov    %r14,%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"0\00"
@.str.1 = [2 x i8] c"1\00"
define i8* @IntToBin(i64 %0, i32 %1) {
%3 = alloca i64
%4 = alloca i32
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i64
store i64 %0, i64* %3
store i32 %1, i32* %4
%9 = load i32, i32* %4
%10 = icmp eq i32 %9, 1
br i1 %10, label %11, label %12
11: ; preds = %2
store i32 23, i32* %5
br label %13
12: ; preds = %2
store i32 52, i32* %5
br label %13
13: ; preds = %12, %11
%14 = load i32, i32* %5
%15 = add nsw i32 %14, 1
%16 = add nsw i32 %15, 1
%17 = sext i32 %16 to i64
%18 = mul i64 1, %17
%19 = trunc i64 %18 to i32
%20 = call i8* @malloc(i32 %19)
store i8* %20, i8** %6
%21 = load i64, i64* %3
store i64 %21, i64* %8
%22 = load i64, i64* %8
%23 = icmp eq i64 %22, 0
br i1 %23, label %24, label %27
24: ; preds = %13
%25 = load i8*, i8** %6
%26 = call i32 @strcat(i8* %25, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
br label %27
27: ; preds = %24, %13
store i32 0, i32* %7
br label %28
28: ; preds = %50, %27
%29 = load i32, i32* %7
%30 = load i32, i32* %5
%31 = add nsw i32 %30, 2
%32 = icmp slt i32 %29, %31
br i1 %32, label %33, label %53
33: ; preds = %28
%34 = load i64, i64* %8
%35 = icmp eq i64 %34, 0
br i1 %35, label %36, label %37
36: ; preds = %33
br label %53
37: ; preds = %33
%38 = load i64, i64* %8
%39 = srem i64 %38, 2
%40 = icmp ne i64 %39, 0
br i1 %40, label %41, label %44
41: ; preds = %37
%42 = load i8*, i8** %6
%43 = call i32 @strcat(i8* %42, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
br label %47
44: ; preds = %37
%45 = load i8*, i8** %6
%46 = call i32 @strcat(i8* %45, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
br label %47
47: ; preds = %44, %41
%48 = load i64, i64* %8
%49 = sdiv i64 %48, 2
store i64 %49, i64* %8
br label %50
50: ; preds = %47
%51 = load i32, i32* %7
%52 = add nsw i32 %51, 1
store i32 %52, i32* %7
br label %28
53: ; preds = %36, %28
%54 = load i8*, i8** %6
%55 = load i8*, i8** %6
%56 = call i32 @InvString(i8* %55)
%57 = call i32 @strcpy(i8* %54, i32 %56)
%58 = load i8*, i8** %6
ret i8* %58
}

LLVM IR (-O2):
@.str = [2 x i8] c"0\00"
@.str.1 = [2 x i8] c"1\00"
define i8* @IntToBin(i64 %0, i32 %1) {
%3 = icmp eq i32 %1, 1
%4 = select i1 %3, i32 25, i32 54
%5 = tail call i8* @malloc(i32 %4)
%6 = icmp eq i64 %0, 0
br i1 %6, label %7, label %9
7: ; preds = %2
%8 = tail call i32 @strcat(i8* %5, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
br label %22
9: ; preds = %2, %9
%10 = phi i64 [ %16, %9 ], [ %0, %2 ]
%11 = phi i32 [ %17, %9 ], [ 0, %2 ]
%12 = and i64 %10, 1
%13 = icmp eq i64 %12, 0
%14 = select i1 %13, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0)
%15 = tail call i32 @strcat(i8* %5, i8* %14)
%16 = sdiv i64 %10, 2
%17 = add nuw nsw i32 %11, 1
%18 = icmp uge i32 %17, %4
%19 = add i64 %10, 1
%20 = icmp ult i64 %19, 3
%21 = select i1 %18, i1 true, i1 %20
br i1 %21, label %22, label %9
22: ; preds = %9, %7
%23 = tail call i32 @InvString(i8* %5)
%24 = tail call i32 @strcpy(i8* %5, i32 %23)
ret i8* %5
}