#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*/ strcat(char *, char *);
char *tobinary(int x) {
  static char b[33];
  b[0] = '\0';
  long unsigned int z;
  for (z = 0x80000000; z > 0; z >>= 1) {
    strcat(b, ((x & z) == z) ? "1" : "0");
  }
  return b;
}


x86 assembly (clang, -O0):
<tobinary>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
movb   $0x0,0x2f1e(%rip)
mov    $0x80000000,%eax
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jbe    1174 <tobinary+0x64>
movslq -0x4(%rbp),%rcx
and    -0x10(%rbp),%rcx
mov    -0x10(%rbp),%rdx
lea    0xeb9(%rip),%rsi
lea    0xeb0(%rip),%rax
cmp    %rdx,%rcx
cmove  %rax,%rsi
lea    0x2ee2(%rip),%rdi
call   1030 <strcat@plt>
mov    -0x10(%rbp),%rax
shr    $0x1,%rax
mov    %rax,-0x10(%rbp)
jmp    112b <tobinary+0x1b>
lea    0x2ec5(%rip),%rax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<tobinary>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
movb   $0x0,0x2f1e(%rip)
mov    %edi,%r15d
mov    $0x80000000,%ebx
not    %r15
lea    0xecc(%rip),%r12
lea    0xec7(%rip),%r13
lea    0x2efe(%rip),%r14
mov    $0x80000000,%ebp
nopw   0x0(%rax,%rax,1)
test   %r15,%rbx
mov    %r13,%rsi
cmove  %r12,%rsi
mov    %r14,%rdi
call   1030 <strcat@plt>
shr    %rbp
cmp    $0x1,%rbx
mov    %rbp,%rbx
ja     1150 <tobinary+0x40>
lea    0x2ecb(%rip),%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@tobinary.b = internal global [33 x i8] zeroinitializer
@.str = [2 x i8] c"1\00"
@.str.1 = [2 x i8] c"0\00"
define i8* @tobinary(i32 %0) {
%2 = alloca i32
%3 = alloca i64
store i32 %0, i32* %2
store i8 0, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @tobinary.b, i64 0, i64 0)
store i64 2147483648, i64* %3
br label %4
4: ; preds = %17, %1
%5 = load i64, i64* %3
%6 = icmp ugt i64 %5, 0
br i1 %6, label %7, label %20
7: ; preds = %4
%8 = load i32, i32* %2
%9 = sext i32 %8 to i64
%10 = load i64, i64* %3
%11 = and i64 %9, %10
%12 = load i64, i64* %3
%13 = icmp eq i64 %11, %12
%14 = zext i1 %13 to i64
%15 = 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)
%16 = call i32 @strcat(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @tobinary.b, i64 0, i64 0), i8* %15)
br label %17
17: ; preds = %7
%18 = load i64, i64* %3
%19 = lshr i64 %18, 1
store i64 %19, i64* %3
br label %4
20: ; preds = %4
ret i8* getelementptr inbounds ([33 x i8], [33 x i8]* @tobinary.b, i64 0, i64 0)
}

LLVM IR (-O2):
@tobinary.b = internal global [33 x i8] zeroinitializer
@.str = [2 x i8] c"1\00"
@.str.1 = [2 x i8] c"0\00"
define i8* @tobinary(i32 %0) {
store i8 0, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @tobinary.b, i64 0, i64 0)
%2 = zext i32 %0 to i64
br label %3
3: ; preds = %1, %3
%4 = phi i64 [ 2147483648, %1 ], [ %9, %3 ]
%5 = and i64 %4, %2
%6 = icmp eq i64 %5, %4
%7 = select i1 %6, 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)
%8 = tail call i32 @strcat(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @tobinary.b, i64 0, i64 0), i8* %7)
%9 = lshr i64 %4, 1
%10 = icmp ult i64 %4, 2
br i1 %10, label %11, label %3
11: ; preds = %3
ret i8* getelementptr inbounds ([33 x i8], [33 x i8]* @tobinary.b, i64 0, i64 0)
}