#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 uint64_t;

/* Variables and functions */
int CHAR_BIT;
char *malloc(size_t);
char *int2bin(uint64_t i) {
  size_t bits = sizeof(uint64_t) * CHAR_BIT;
  char *str = malloc(bits + 1);
  if (!str)
    return NULL;
  str[bits] = 0;
  uint64_t u = *(uint64_t *)&i;
  for (; bits--; u >>= 1)
    str[bits] = u & 1 ? '1' : '0';
  return str;
}


x86 assembly (clang, -O0):
<int2bin>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0xc(%rbp)
mov    0x2ebe(%rip),%rax
movslq (%rax),%rax
shl    $0x2,%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
add    $0x1,%rdi
call   1030 <malloc@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    1156 <int2bin+0x46>
movq   $0x0,-0x8(%rbp)
jmp    11ba <int2bin+0xaa>
mov    -0x20(%rbp),%rax
mov    -0x18(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0xc(%rbp),%eax
mov    %eax,-0x24(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,%rcx
add    $0xffffffffffffffff,%rcx
mov    %rcx,-0x18(%rbp)
cmp    $0x0,%rax
je     11b2 <int2bin+0xa2>
mov    -0x24(%rbp),%edx
and    $0x1,%edx
mov    $0x30,%eax
mov    $0x31,%ecx
cmp    $0x0,%edx
cmovne %ecx,%eax
mov    %al,%dl
mov    -0x20(%rbp),%rax
mov    -0x18(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x24(%rbp),%eax
sar    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    1168 <int2bin+0x58>
mov    -0x20(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<int2bin>:
push   %rbp
push   %rbx
push   %rax
mov    %edi,%ebp
mov    0x2ec4(%rip),%rax
movslq (%rax),%rbx
lea    0x1(,%rbx,4),%rdi
call   1030 <malloc@plt>
test   %rax,%rax
je     1181 <int2bin+0x71>
mov    %ebx,%ecx
shl    $0x2,%rbx
movb   $0x0,(%rax,%rbx,1)
test   %ecx,%ecx
je     1181 <int2bin+0x71>
nop
mov    %ebp,%ecx
and    $0x1,%cl
or     $0x30,%cl
mov    %cl,-0x1(%rax,%rbx,1)
mov    %ebp,%ecx
shr    %cl
and    $0x1,%cl
or     $0x30,%cl
mov    %cl,-0x2(%rax,%rbx,1)
mov    %ebp,%ecx
shr    $0x2,%cl
and    $0x1,%cl
or     $0x30,%cl
mov    %cl,-0x3(%rax,%rbx,1)
mov    %ebp,%ecx
shr    $0x3,%cl
and    $0x1,%cl
or     $0x30,%cl
sar    $0x4,%ebp
mov    %cl,-0x4(%rax,%rbx,1)
add    $0xfffffffffffffffc,%rbx
jne    1140 <int2bin+0x30>
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@CHAR_BIT = global i32 0
define i8* @int2bin(i32 %0) {
%2 = alloca i8*
%3 = alloca i32
%4 = alloca i64
%5 = alloca i8*
%6 = alloca i32
store i32 %0, i32* %3
%7 = load i32, i32* @CHAR_BIT
%8 = sext i32 %7 to i64
%9 = mul i64 4, %8
store i64 %9, i64* %4
%10 = load i64, i64* %4
%11 = add i64 %10, 1
%12 = call i8* @malloc(i64 %11)
store i8* %12, i8** %5
%13 = load i8*, i8** %5
%14 = icmp ne i8* %13, null
br i1 %14, label %16, label %15
15: ; preds = %1
store i8* null, i8** %2
br label %40
16: ; preds = %1
%17 = load i8*, i8** %5
%18 = load i64, i64* %4
%19 = getelementptr inbounds i8, i8* %17, i64 %18
store i8 0, i8* %19
%20 = load i32, i32* %3
store i32 %20, i32* %6
br label %21
21: ; preds = %35, %16
%22 = load i64, i64* %4
%23 = add i64 %22, -1
store i64 %23, i64* %4
%24 = icmp ne i64 %22, 0
br i1 %24, label %25, label %38
25: ; preds = %21
%26 = load i32, i32* %6
%27 = and i32 %26, 1
%28 = icmp ne i32 %27, 0
%29 = zext i1 %28 to i64
%30 = select i1 %28, i32 49, i32 48
%31 = trunc i32 %30 to i8
%32 = load i8*, i8** %5
%33 = load i64, i64* %4
%34 = getelementptr inbounds i8, i8* %32, i64 %33
store i8 %31, i8* %34
br label %35
35: ; preds = %25
%36 = load i32, i32* %6
%37 = ashr i32 %36, 1
store i32 %37, i32* %6
br label %21
38: ; preds = %21
%39 = load i8*, i8** %5
store i8* %39, i8** %2
br label %40
40: ; preds = %38, %15
%41 = load i8*, i8** %2
ret i8* %41
}

LLVM IR (-O2):
@CHAR_BIT = global i32 0
define noalias i8* @int2bin(i32 %0) {
%2 = load i32, i32* @CHAR_BIT
%3 = sext i32 %2 to i64
%4 = shl nsw i64 %3, 2
%5 = or i64 %4, 1
%6 = tail call i8* @malloc(i64 %5)
%7 = icmp eq i8* %6, null
br i1 %7, label %39, label %8
8: ; preds = %1
%9 = getelementptr inbounds i8, i8* %6, i64 %4
store i8 0, i8* %9
%10 = icmp eq i32 %2, 0
br i1 %10, label %39, label %11
11: ; preds = %8, %11
%12 = phi i64 [ %31, %11 ], [ %4, %8 ]
%13 = phi i32 [ %37, %11 ], [ %0, %8 ]
%14 = add i64 %12, -1
%15 = trunc i32 %13 to i8
%16 = and i8 %15, 1
%17 = or i8 %16, 48
%18 = getelementptr inbounds i8, i8* %6, i64 %14
store i8 %17, i8* %18
%19 = add i64 %12, -2
%20 = trunc i32 %13 to i8
%21 = lshr i8 %20, 1
%22 = and i8 %21, 1
%23 = or i8 %22, 48
%24 = getelementptr inbounds i8, i8* %6, i64 %19
store i8 %23, i8* %24
%25 = add i64 %12, -3
%26 = trunc i32 %13 to i8
%27 = lshr i8 %26, 2
%28 = and i8 %27, 1
%29 = or i8 %28, 48
%30 = getelementptr inbounds i8, i8* %6, i64 %25
store i8 %29, i8* %30
%31 = add i64 %12, -4
%32 = trunc i32 %13 to i8
%33 = lshr i8 %32, 3
%34 = and i8 %33, 1
%35 = or i8 %34, 48
%36 = getelementptr inbounds i8, i8* %6, i64 %31
store i8 %35, i8* %36
%37 = ashr i32 %13, 4
%38 = icmp eq i64 %31, 0
br i1 %38, label %39, label %11
39: ; preds = %11, %8, %1
ret i8* %6
}