#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 *apped_char(char *, char);
char *to_binary(int a) {
  if (a == 0)
    return "0";
  else if (a == 1)
    return "1";
  else if (a % 2 == 0)
    return apped_char(to_binary(a / 2), '0');
  else
    return apped_char(to_binary(a / 2), '1');
}


x86 assembly (clang, -O0):
<to_binary>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
jne    1145 <to_binary+0x25>
lea    0xec4(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    11be <to_binary+0x9e>
cmpl   $0x1,-0xc(%rbp)
jne    115f <to_binary+0x3f>
lea    0xeac(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    11be <to_binary+0x9e>
mov    -0xc(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
jne    119b <to_binary+0x7b>
mov    -0xc(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,%edi
call   1030 <to_binary@plt>
mov    %rax,%rdi
mov    $0x30,%esi
call   1040 <apped_char@plt>
mov    %rax,-0x8(%rbp)
jmp    11be <to_binary+0x9e>
mov    -0xc(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,%edi
call   1030 <to_binary@plt>
mov    %rax,%rdi
mov    $0x31,%esi
call   1040 <apped_char@plt>
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<to_binary>:
push   %rbx
test   %edi,%edi
je     1135 <to_binary+0x15>
mov    %edi,%ebx
cmp    $0x1,%edi
jne    113e <to_binary+0x1e>
lea    0xecf(%rip),%rax
pop    %rbx
ret
lea    0xec4(%rip),%rax
pop    %rbx
ret
mov    %ebx,%edi
shr    $0x1f,%edi
add    %ebx,%edi
sar    %edi
call   1030 <to_binary@plt>
mov    %rax,%rdi
test   $0x1,%bl
jne    115f <to_binary+0x3f>
mov    $0x30,%esi
pop    %rbx
jmp    1040 <apped_char@plt>
mov    $0x31,%esi
pop    %rbx
jmp    1040 <apped_char@plt>

LLVM IR (-O0):
@.str = [2 x i8] c"0\00"
@.str.1 = [2 x i8] c"1\00"
define i8* @to_binary(i32 %0) {
%2 = alloca i8*
%3 = alloca i32
store i32 %0, i32* %3
%4 = load i32, i32* %3
%5 = icmp eq i32 %4, 0
br i1 %5, label %6, label %7
6: ; preds = %1
store i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i8** %2
br label %25
7: ; preds = %1
%8 = load i32, i32* %3
%9 = icmp eq i32 %8, 1
br i1 %9, label %10, label %11
10: ; preds = %7
store i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0), i8** %2
br label %25
11: ; preds = %7
%12 = load i32, i32* %3
%13 = srem i32 %12, 2
%14 = icmp eq i32 %13, 0
br i1 %14, label %15, label %20
15: ; preds = %11
%16 = load i32, i32* %3
%17 = sdiv i32 %16, 2
%18 = call i8* @to_binary(i32 %17)
%19 = call i8* @apped_char(i8* %18, i8 signext 48)
store i8* %19, i8** %2
br label %25
20: ; preds = %11
%21 = load i32, i32* %3
%22 = sdiv i32 %21, 2
%23 = call i8* @to_binary(i32 %22)
%24 = call i8* @apped_char(i8* %23, i8 signext 49)
store i8* %24, i8** %2
br label %25
25: ; preds = %20, %15, %10, %6
%26 = load i8*, i8** %2
ret i8* %26
}

LLVM IR (-O2):
@.str = [2 x i8] c"0\00"
@.str.1 = [2 x i8] c"1\00"
define i8* @to_binary(i32 %0) {
switch i32 %0, label %3 [
i32 0, label %8
i32 1, label %2
]
2: ; preds = %1
br label %8
3: ; preds = %1
%4 = and i32 %0, 1
%5 = icmp eq i32 %4, 0
%6 = sdiv i32 %0, 2
%7 = tail call i8* @to_binary(i32 %6)
br i1 %5, label %10, label %12
8: ; preds = %2, %1, %12, %10
%9 = phi i8* [ %11, %10 ], [ %13, %12 ], [ getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0), %2 ], [ getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), %1 ]
ret i8* %9
10: ; preds = %3
%11 = tail call i8* @apped_char(i8* %7, i8 signext 48)
br label %8
12: ; preds = %3
%13 = tail call i8* @apped_char(i8* %7, i8 signext 49)
br label %8
}