#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 *ExpToBin(int exp, int prec) {
  int i, max;
  char *bin;
  if (prec == 1) {
    max = 8;
  }
  if (prec == 2) {
    max = 11;
  }
  bin = malloc(sizeof(char) * (max + 1));
  for (i = 0; i < max; i++) {
    if (exp % 2)
      strcat(bin, "1");
    else
      strcat(bin, "0");
    exp = exp / 2;
  }
  strcpy(bin, InvString(bin));
  return bin;
}


x86 assembly (clang, -O0):
<ExpToBin>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
cmpl   $0x1,-0x8(%rbp)
jne    115f <ExpToBin+0x1f>
movl   $0x8,-0x10(%rbp)
cmpl   $0x2,-0x8(%rbp)
jne    1170 <ExpToBin+0x30>
movl   $0xb,-0x10(%rbp)
mov    -0x10(%rbp),%eax
add    $0x1,%eax
cltq
shl    $0x0,%rax
mov    %eax,%edi
call   1050 <malloc@plt>
mov    %rax,-0x18(%rbp)
movl   $0x0,-0xc(%rbp)
mov    -0xc(%rbp),%eax
cmp    -0x10(%rbp),%eax
jge    11ef <ExpToBin+0xaf>
mov    -0x4(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
je     11c3 <ExpToBin+0x83>
mov    -0x18(%rbp),%rdi
lea    0xe47(%rip),%rsi
call   1060 <strcat@plt>
jmp    11d3 <ExpToBin+0x93>
mov    -0x18(%rbp),%rdi
lea    0xe34(%rip),%rsi
call   1060 <strcat@plt>
mov    -0x4(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,-0x4(%rbp)
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    118e <ExpToBin+0x4e>
mov    -0x18(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x18(%rbp),%rdi
call   1040 <InvString@plt>
mov    -0x20(%rbp),%rdi
mov    %eax,%esi
call   1030 <strcpy@plt>
mov    -0x18(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ExpToBin>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %edi,%r13d
xor    %eax,%eax
cmp    $0x2,%esi
sete   %al
lea    (%rax,%rax,2),%ebx
or     $0x8,%ebx
lea    (%rax,%rax,2),%edi
add    $0x9,%edi
call   1050 <malloc@plt>
mov    %rax,%r14
lea    0xe91(%rip),%r15
lea    0xe88(%rip),%r12
mov    %r13d,%ebp
nopl   0x0(%rax,%rax,1)
test   $0x1,%r13b
mov    %r12,%rsi
cmove  %r15,%rsi
mov    %r14,%rdi
call   1060 <strcat@plt>
shr    $0x1f,%ebp
add    %r13d,%ebp
sar    %ebp
mov    %ebp,%r13d
add    $0xffffffff,%ebx
jne    1180 <ExpToBin+0x40>
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"1\00"
@.str.1 = [2 x i8] c"0\00"
define i8* @ExpToBin(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i8*
store i32 %0, i32* %3
store i32 %1, i32* %4
%8 = load i32, i32* %4
%9 = icmp eq i32 %8, 1
br i1 %9, label %10, label %11
10: ; preds = %2
store i32 8, i32* %6
br label %11
11: ; preds = %10, %2
%12 = load i32, i32* %4
%13 = icmp eq i32 %12, 2
br i1 %13, label %14, label %15
14: ; preds = %11
store i32 11, i32* %6
br label %15
15: ; preds = %14, %11
%16 = load i32, i32* %6
%17 = add nsw i32 %16, 1
%18 = sext i32 %17 to i64
%19 = mul i64 1, %18
%20 = trunc i64 %19 to i32
%21 = call i8* @malloc(i32 %20)
store i8* %21, i8** %7
store i32 0, i32* %5
br label %22
22: ; preds = %39, %15
%23 = load i32, i32* %5
%24 = load i32, i32* %6
%25 = icmp slt i32 %23, %24
br i1 %25, label %26, label %42
26: ; preds = %22
%27 = load i32, i32* %3
%28 = srem i32 %27, 2
%29 = icmp ne i32 %28, 0
br i1 %29, label %30, label %33
30: ; preds = %26
%31 = load i8*, i8** %7
%32 = call i32 @strcat(i8* %31, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
br label %36
33: ; preds = %26
%34 = load i8*, i8** %7
%35 = call i32 @strcat(i8* %34, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
br label %36
36: ; preds = %33, %30
%37 = load i32, i32* %3
%38 = sdiv i32 %37, 2
store i32 %38, i32* %3
br label %39
39: ; preds = %36
%40 = load i32, i32* %5
%41 = add nsw i32 %40, 1
store i32 %41, i32* %5
br label %22
42: ; preds = %22
%43 = load i8*, i8** %7
%44 = load i8*, i8** %7
%45 = call i32 @InvString(i8* %44)
%46 = call i32 @strcpy(i8* %43, i32 %45)
%47 = load i8*, i8** %7
ret i8* %47
}

LLVM IR (-O2):
@.str = [2 x i8] c"1\00"
@.str.1 = [2 x i8] c"0\00"
define i8* @ExpToBin(i32 %0, i32 %1) {
%3 = icmp eq i32 %1, 2
%4 = select i1 %3, i32 11, i32 8
%5 = add nuw nsw i32 %4, 1
%6 = tail call i8* @malloc(i32 %5)
br label %7
7: ; preds = %2, %7
%8 = phi i32 [ %0, %2 ], [ %14, %7 ]
%9 = phi i32 [ 0, %2 ], [ %15, %7 ]
%10 = and i32 %8, 1
%11 = icmp eq i32 %10, 0
%12 = select i1 %11, 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)
%13 = tail call i32 @strcat(i8* %6, i8* %12)
%14 = sdiv i32 %8, 2
%15 = add nuw nsw i32 %9, 1
%16 = icmp eq i32 %15, %4
br i1 %16, label %17, label %7
17: ; preds = %7
%18 = tail call i32 @InvString(i8* %6)
%19 = tail call i32 @strcpy(i8* %6, i32 %18)
ret i8* %6
}