#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 */
typedef int uint16_t;

/* Variables and functions */
char *malloc(int);
int /*<<< orphan*/ strcat(char *, char *);
char *bin(uint16_t x) {
  char *b = malloc(17);
  b[0] = '\0';
  uint16_t z;
  for (z = 1 << 15; z > 0; z >>= 1) {
    strcat(b, (x & z) ? "1" : "0");
  }
  return b;
}


x86 assembly (clang, -O0):
<bin>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    $0x11,%edi
call   1030 <malloc@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
movb   $0x0,(%rax)
movl   $0x8000,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jle    1183 <bin+0x63>
mov    -0x10(%rbp),%rdi
mov    -0x4(%rbp),%ecx
and    -0x14(%rbp),%ecx
lea    0xea0(%rip),%rsi
lea    0xe97(%rip),%rax
cmp    $0x0,%ecx
cmovne %rax,%rsi
call   1040 <strcat@plt>
mov    -0x14(%rbp),%eax
sar    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1147 <bin+0x27>
mov    -0x10(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<bin>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %edi,%r14d
mov    $0x11,%edi
call   1030 <malloc@plt>
mov    %rax,%rbx
movb   $0x0,(%rax)
test   $0x8000,%r14d
lea    0xeba(%rip),%r15
lea    0xeb1(%rip),%rbp
mov    %rbp,%rsi
cmove  %r15,%rsi
mov    %rax,%rdi
call   1040 <strcat@plt>
test   $0x4000,%r14d
mov    %rbp,%rsi
cmove  %r15,%rsi
mov    %rbx,%rdi
call   1040 <strcat@plt>
test   $0x2000,%r14d
mov    %rbp,%rsi
cmove  %r15,%rsi
mov    %rbx,%rdi
call   1040 <strcat@plt>
test   $0x1000,%r14d
mov    %rbp,%rsi
cmove  %r15,%rsi
mov    %rbx,%rdi
call   1040 <strcat@plt>
test   $0x800,%r14d
mov    %rbp,%rsi
cmove  %r15,%rsi
mov    %rbx,%rdi
call   1040 <strcat@plt>
test   $0x400,%r14d
mov    %rbp,%rsi
cmove  %r15,%rsi
mov    %rbx,%rdi
call   1040 <strcat@plt>
test   $0x200,%r14d
mov    %rbp,%rsi
cmove  %r15,%rsi
mov    %rbx,%rdi
call   1040 <strcat@plt>
test   $0x100,%r14d
mov    %rbp,%rsi
cmove  %r15,%rsi
mov    %rbx,%rdi
call   1040 <strcat@plt>
test   $0x80,%r14b
mov    %rbp,%rsi
cmove  %r15,%rsi
mov    %rbx,%rdi
call   1040 <strcat@plt>
test   $0x40,%r14b
mov    %rbp,%rsi
cmove  %r15,%rsi
mov    %rbx,%rdi
call   1040 <strcat@plt>
test   $0x20,%r14b
mov    %rbp,%rsi
cmove  %r15,%rsi
mov    %rbx,%rdi
call   1040 <strcat@plt>
test   $0x10,%r14b
mov    %rbp,%rsi
cmove  %r15,%rsi
mov    %rbx,%rdi
call   1040 <strcat@plt>
test   $0x8,%r14b
mov    %rbp,%rsi
cmove  %r15,%rsi
mov    %rbx,%rdi
call   1040 <strcat@plt>
test   $0x4,%r14b
mov    %rbp,%rsi
cmove  %r15,%rsi
mov    %rbx,%rdi
call   1040 <strcat@plt>
test   $0x2,%r14b
mov    %rbp,%rsi
cmove  %r15,%rsi
mov    %rbx,%rdi
call   1040 <strcat@plt>
test   $0x1,%r14b
cmove  %r15,%rbp
mov    %rbx,%rdi
mov    %rbp,%rsi
call   1040 <strcat@plt>
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
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* @bin(i32 %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i32
store i32 %0, i32* %2
%5 = call i8* @malloc(i32 17)
store i8* %5, i8** %3
%6 = load i8*, i8** %3
%7 = getelementptr inbounds i8, i8* %6, i64 0
store i8 0, i8* %7
store i32 32768, i32* %4
br label %8
8: ; preds = %20, %1
%9 = load i32, i32* %4
%10 = icmp sgt i32 %9, 0
br i1 %10, label %11, label %23
11: ; preds = %8
%12 = load i8*, i8** %3
%13 = load i32, i32* %2
%14 = load i32, i32* %4
%15 = and i32 %13, %14
%16 = icmp ne i32 %15, 0
%17 = zext i1 %16 to i64
%18 = select i1 %16, 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)
%19 = call i32 @strcat(i8* %12, i8* %18)
br label %20
20: ; preds = %11
%21 = load i32, i32* %4
%22 = ashr i32 %21, 1
store i32 %22, i32* %4
br label %8
23: ; preds = %8
%24 = load i8*, i8** %3
ret i8* %24
}

LLVM IR (-O2):
@.str = [2 x i8] c"1\00"
@.str.1 = [2 x i8] c"0\00"
define i8* @bin(i32 %0) {
%2 = tail call dereferenceable_or_null(17) i8* @malloc(i32 17)
store i8 0, i8* %2
%3 = and i32 %0, 32768
%4 = icmp eq i32 %3, 0
%5 = select i1 %4, 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)
%6 = tail call i32 @strcat(i8* %2, i8* %5)
%7 = and i32 %0, 16384
%8 = icmp eq i32 %7, 0
%9 = select i1 %8, 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)
%10 = tail call i32 @strcat(i8* %2, i8* %9)
%11 = and i32 %0, 8192
%12 = icmp eq i32 %11, 0
%13 = select i1 %12, 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)
%14 = tail call i32 @strcat(i8* %2, i8* %13)
%15 = and i32 %0, 4096
%16 = icmp eq i32 %15, 0
%17 = select i1 %16, 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)
%18 = tail call i32 @strcat(i8* %2, i8* %17)
%19 = and i32 %0, 2048
%20 = icmp eq i32 %19, 0
%21 = select i1 %20, 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)
%22 = tail call i32 @strcat(i8* %2, i8* %21)
%23 = and i32 %0, 1024
%24 = icmp eq i32 %23, 0
%25 = select i1 %24, 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)
%26 = tail call i32 @strcat(i8* %2, i8* %25)
%27 = and i32 %0, 512
%28 = icmp eq i32 %27, 0
%29 = select i1 %28, 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)
%30 = tail call i32 @strcat(i8* %2, i8* %29)
%31 = and i32 %0, 256
%32 = icmp eq i32 %31, 0
%33 = select i1 %32, 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)
%34 = tail call i32 @strcat(i8* %2, i8* %33)
%35 = and i32 %0, 128
%36 = icmp eq i32 %35, 0
%37 = select i1 %36, 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)
%38 = tail call i32 @strcat(i8* %2, i8* %37)
%39 = and i32 %0, 64
%40 = icmp eq i32 %39, 0
%41 = select i1 %40, 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)
%42 = tail call i32 @strcat(i8* %2, i8* %41)
%43 = and i32 %0, 32
%44 = icmp eq i32 %43, 0
%45 = select i1 %44, 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)
%46 = tail call i32 @strcat(i8* %2, i8* %45)
%47 = and i32 %0, 16
%48 = icmp eq i32 %47, 0
%49 = select i1 %48, 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)
%50 = tail call i32 @strcat(i8* %2, i8* %49)
%51 = and i32 %0, 8
%52 = icmp eq i32 %51, 0
%53 = select i1 %52, 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)
%54 = tail call i32 @strcat(i8* %2, i8* %53)
%55 = and i32 %0, 4
%56 = icmp eq i32 %55, 0
%57 = select i1 %56, 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)
%58 = tail call i32 @strcat(i8* %2, i8* %57)
%59 = and i32 %0, 2
%60 = icmp eq i32 %59, 0
%61 = select i1 %60, 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)
%62 = tail call i32 @strcat(i8* %2, i8* %61)
%63 = and i32 %0, 1
%64 = icmp eq i32 %63, 0
%65 = select i1 %64, 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)
%66 = tail call i32 @strcat(i8* %2, i8* %65)
ret i8* %2
}