#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 /*<<< orphan*/ memcpy(char *, char const *const, int);
int strlen(char const *const);
void uint64_to_binary(uint64_t value, char *binary) {
  static const char *const nibbles_start[] = {
      "",     "1",    "10",   "11",   "100",  "101",  "110",  "111",
      "1000", "1001", "1010", "1011", "1100", "1101", "1110", "1111",
  };
  static const char *const nibbles[] = {
      "0000", "0001", "0010", "0011", "0100", "0101", "0110", "0111",
      "1000", "1001", "1010", "1011", "1100", "1101", "1110", "1111",
  };
  int nibble;
  int nibble_value;
  int nibble_size;
  int zero = 1;
  for (nibble = 0; nibble < (sizeof(uint64_t) * (8 / 4)); nibble++) {
    nibble_value = value >> ((sizeof(uint64_t) * 8) - 4);
    if (zero) {
      if (nibble_value > 0) {
        zero = 0;
        nibble_size = strlen(nibbles_start[nibble_value]);
        memcpy(binary, nibbles_start[nibble_value], nibble_size);
        binary += nibble_size;
      }
    } else {
      memcpy(binary, nibbles[nibble_value], 4);
      binary += 4;
    }
    value <<= 4;
  }
  if (zero) {
    binary[0] = '0';
    binary++;
  }
  binary[0] = '\0';
}


x86 assembly (clang, -O0):
<uint64_to_binary>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x1,-0x20(%rbp)
movl   $0x0,-0x14(%rbp)
movslq -0x14(%rbp),%rax
cmp    $0x8,%rax
jae    11f7 <uint64_to_binary+0xd7>
mov    -0x4(%rbp),%eax
sar    $0x1c,%eax
mov    %eax,-0x18(%rbp)
cmpl   $0x0,-0x20(%rbp)
je     11b7 <uint64_to_binary+0x97>
cmpl   $0x0,-0x18(%rbp)
jle    11b2 <uint64_to_binary+0x92>
movl   $0x0,-0x20(%rbp)
movslq -0x18(%rbp),%rcx
lea    0x2ba6(%rip),%rax
mov    (%rax,%rcx,8),%rdi
call   1030 <strlen@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x10(%rbp),%rdi
movslq -0x18(%rbp),%rcx
lea    0x2b8b(%rip),%rax
mov    (%rax,%rcx,8),%rsi
mov    -0x1c(%rbp),%edx
call   1040 <memcpy@plt>
mov    -0x1c(%rbp),%ecx
mov    -0x10(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x10(%rbp)
jmp    11e0 <uint64_to_binary+0xc0>
mov    -0x10(%rbp),%rdi
movslq -0x18(%rbp),%rcx
lea    0x2bda(%rip),%rax
mov    (%rax,%rcx,8),%rsi
mov    $0x4,%edx
call   1040 <memcpy@plt>
mov    -0x10(%rbp),%rax
add    $0x4,%rax
mov    %rax,-0x10(%rbp)
mov    -0x4(%rbp),%eax
shl    $0x4,%eax
mov    %eax,-0x4(%rbp)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    113d <uint64_to_binary+0x1d>
cmpl   $0x0,-0x20(%rbp)
je     1214 <uint64_to_binary+0xf4>
mov    -0x10(%rbp),%rax
movb   $0x30,(%rax)
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
movb   $0x0,(%rax)
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<uint64_to_binary>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r12
mov    %edi,%ebp
xor    %ebx,%ebx
mov    $0x1,%eax
lea    0xf12(%rip),%r13
add    $0x1,%ebx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
test   %eax,%eax
je     1170 <uint64_to_binary+0x50>
cmp    $0x10000000,%ebp
jge    11a0 <uint64_to_binary+0x80>
shl    $0x4,%ebp
add    $0x1,%ebx
mov    $0x1,%eax
cmp    $0x9,%ebx
jne    1150 <uint64_to_binary+0x30>
jmp    11e0 <uint64_to_binary+0xc0>
xchg   %ax,%ax
mov    %ebp,%eax
sar    $0x1c,%eax
cltq
movslq 0x0(%r13,%rax,4),%rsi
add    %r13,%rsi
mov    %r12,%rdi
mov    $0x4,%edx
call   1040 <memcpy@plt>
mov    $0x4,%eax
jmp    11cd <uint64_to_binary+0xad>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    %ebp,%eax
sar    $0x1c,%eax
cltq
lea    0x2bf2(%rip),%rcx
mov    (%rcx,%rax,8),%r14
mov    %r14,%rdi
call   1030 <strlen@plt>
mov    %eax,%r15d
mov    %r12,%rdi
mov    %r14,%rsi
mov    %eax,%edx
call   1040 <memcpy@plt>
movslq %r15d,%rax
add    %rax,%r12
shl    $0x4,%ebp
xor    %eax,%eax
cmp    $0x8,%ebx
jne    113e <uint64_to_binary+0x1e>
jmp    11e9 <uint64_to_binary+0xc9>
movb   $0x30,(%r12)
add    $0x1,%r12
movb   $0x0,(%r12)
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@uint64_to_binary.nibbles_start = internal constant [16 x i8*] [i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i32 0, i32 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i32 0, i32 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i32 0, i32 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i32 0, i32 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i32 0, i32 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.6, i32 0, i32 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.7, i32 0, i32 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.8, i32 0, i32 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.9, i32 0, i32 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.10, i32 0, i32 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.11, i32 0, i32 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.12, i32 0, i32 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.13, i32 0, i32 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.14, i32 0, i32 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.15, i32 0, i32 0)]
@.str = [1 x i8] zeroinitializer
@.str.1 = [2 x i8] c"1\00"
@.str.2 = [3 x i8] c"10\00"
@.str.3 = [3 x i8] c"11\00"
@.str.4 = [4 x i8] c"100\00"
@.str.5 = [4 x i8] c"101\00"
@.str.6 = [4 x i8] c"110\00"
@.str.7 = [4 x i8] c"111\00"
@.str.8 = [5 x i8] c"1000\00"
@.str.9 = [5 x i8] c"1001\00"
@.str.10 = [5 x i8] c"1010\00"
@.str.11 = [5 x i8] c"1011\00"
@.str.12 = [5 x i8] c"1100\00"
@.str.13 = [5 x i8] c"1101\00"
@.str.14 = [5 x i8] c"1110\00"
@.str.15 = [5 x i8] c"1111\00"
@uint64_to_binary.nibbles = internal constant [16 x i8*] [i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.16, i32 0, i32 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.17, i32 0, i32 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.18, i32 0, i32 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.19, i32 0, i32 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.20, i32 0, i32 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.21, i32 0, i32 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.22, i32 0, i32 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.23, i32 0, i32 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.8, i32 0, i32 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.9, i32 0, i32 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.10, i32 0, i32 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.11, i32 0, i32 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.12, i32 0, i32 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.13, i32 0, i32 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.14, i32 0, i32 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.15, i32 0, i32 0)]
@.str.16 = [5 x i8] c"0000\00"
@.str.17 = [5 x i8] c"0001\00"
@.str.18 = [5 x i8] c"0010\00"
@.str.19 = [5 x i8] c"0011\00"
@.str.20 = [5 x i8] c"0100\00"
@.str.21 = [5 x i8] c"0101\00"
@.str.22 = [5 x i8] c"0110\00"
@.str.23 = [5 x i8] c"0111\00"
define void @uint64_to_binary(i32 %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
store i32 %0, i32* %3
store i8* %1, i8** %4
store i32 1, i32* %8
store i32 0, i32* %5
br label %9
9: ; preds = %51, %2
%10 = load i32, i32* %5
%11 = sext i32 %10 to i64
%12 = icmp ult i64 %11, 8
br i1 %12, label %13, label %54
13: ; preds = %9
%14 = load i32, i32* %3
%15 = ashr i32 %14, 28
store i32 %15, i32* %6
%16 = load i32, i32* %8
%17 = icmp ne i32 %16, 0
br i1 %17, label %18, label %39
18: ; preds = %13
%19 = load i32, i32* %6
%20 = icmp sgt i32 %19, 0
br i1 %20, label %21, label %38
21: ; preds = %18
store i32 0, i32* %8
%22 = load i32, i32* %6
%23 = sext i32 %22 to i64
%24 = getelementptr inbounds [16 x i8*], [16 x i8*]* @uint64_to_binary.nibbles_start, i64 0, i64 %23
%25 = load i8*, i8** %24
%26 = call i32 @strlen(i8* %25)
store i32 %26, i32* %7
%27 = load i8*, i8** %4
%28 = load i32, i32* %6
%29 = sext i32 %28 to i64
%30 = getelementptr inbounds [16 x i8*], [16 x i8*]* @uint64_to_binary.nibbles_start, i64 0, i64 %29
%31 = load i8*, i8** %30
%32 = load i32, i32* %7
%33 = call i32 @memcpy(i8* %27, i8* %31, i32 %32)
%34 = load i32, i32* %7
%35 = load i8*, i8** %4
%36 = sext i32 %34 to i64
%37 = getelementptr inbounds i8, i8* %35, i64 %36
store i8* %37, i8** %4
br label %38
38: ; preds = %21, %18
br label %48
39: ; preds = %13
%40 = load i8*, i8** %4
%41 = load i32, i32* %6
%42 = sext i32 %41 to i64
%43 = getelementptr inbounds [16 x i8*], [16 x i8*]* @uint64_to_binary.nibbles, i64 0, i64 %42
%44 = load i8*, i8** %43
%45 = call i32 @memcpy(i8* %40, i8* %44, i32 4)
%46 = load i8*, i8** %4
%47 = getelementptr inbounds i8, i8* %46, i64 4
store i8* %47, i8** %4
br label %48
48: ; preds = %39, %38
%49 = load i32, i32* %3
%50 = shl i32 %49, 4
store i32 %50, i32* %3
br label %51
51: ; preds = %48
%52 = load i32, i32* %5
%53 = add nsw i32 %52, 1
store i32 %53, i32* %5
br label %9
54: ; preds = %9
%55 = load i32, i32* %8
%56 = icmp ne i32 %55, 0
br i1 %56, label %57, label %62
57: ; preds = %54
%58 = load i8*, i8** %4
%59 = getelementptr inbounds i8, i8* %58, i64 0
store i8 48, i8* %59
%60 = load i8*, i8** %4
%61 = getelementptr inbounds i8, i8* %60, i32 1
store i8* %61, i8** %4
br label %62
62: ; preds = %57, %54
%63 = load i8*, i8** %4
%64 = getelementptr inbounds i8, i8* %63, i64 0
store i8 0, i8* %64
ret void
}

LLVM IR (-O2):
@uint64_to_binary.nibbles_start = internal unnamed_addr constant [16 x i8*] [i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i32 0, i32 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i32 0, i32 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i32 0, i32 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i32 0, i32 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i32 0, i32 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.6, i32 0, i32 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.7, i32 0, i32 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.8, i32 0, i32 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.9, i32 0, i32 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.10, i32 0, i32 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.11, i32 0, i32 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.12, i32 0, i32 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.13, i32 0, i32 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.14, i32 0, i32 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.15, i32 0, i32 0)]
@.str = [1 x i8] zeroinitializer
@.str.1 = [2 x i8] c"1\00"
@.str.2 = [3 x i8] c"10\00"
@.str.3 = [3 x i8] c"11\00"
@.str.4 = [4 x i8] c"100\00"
@.str.5 = [4 x i8] c"101\00"
@.str.6 = [4 x i8] c"110\00"
@.str.7 = [4 x i8] c"111\00"
@.str.8 = [5 x i8] c"1000\00"
@.str.9 = [5 x i8] c"1001\00"
@.str.10 = [5 x i8] c"1010\00"
@.str.11 = [5 x i8] c"1011\00"
@.str.12 = [5 x i8] c"1100\00"
@.str.13 = [5 x i8] c"1101\00"
@.str.14 = [5 x i8] c"1110\00"
@.str.15 = [5 x i8] c"1111\00"
@reltable.uint64_to_binary = internal unnamed_addr constant [16 x i32] [i32 trunc (i64 sub (i64 ptrtoint ([5 x i8]* @.str.16 to i64), i64 ptrtoint ([16 x i32]* @reltable.uint64_to_binary to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([5 x i8]* @.str.17 to i64), i64 ptrtoint ([16 x i32]* @reltable.uint64_to_binary to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([5 x i8]* @.str.18 to i64), i64 ptrtoint ([16 x i32]* @reltable.uint64_to_binary to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([5 x i8]* @.str.19 to i64), i64 ptrtoint ([16 x i32]* @reltable.uint64_to_binary to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([5 x i8]* @.str.20 to i64), i64 ptrtoint ([16 x i32]* @reltable.uint64_to_binary to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([5 x i8]* @.str.21 to i64), i64 ptrtoint ([16 x i32]* @reltable.uint64_to_binary to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([5 x i8]* @.str.22 to i64), i64 ptrtoint ([16 x i32]* @reltable.uint64_to_binary to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([5 x i8]* @.str.23 to i64), i64 ptrtoint ([16 x i32]* @reltable.uint64_to_binary to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([5 x i8]* @.str.8 to i64), i64 ptrtoint ([16 x i32]* @reltable.uint64_to_binary to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([5 x i8]* @.str.9 to i64), i64 ptrtoint ([16 x i32]* @reltable.uint64_to_binary to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([5 x i8]* @.str.10 to i64), i64 ptrtoint ([16 x i32]* @reltable.uint64_to_binary to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([5 x i8]* @.str.11 to i64), i64 ptrtoint ([16 x i32]* @reltable.uint64_to_binary to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([5 x i8]* @.str.12 to i64), i64 ptrtoint ([16 x i32]* @reltable.uint64_to_binary to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([5 x i8]* @.str.13 to i64), i64 ptrtoint ([16 x i32]* @reltable.uint64_to_binary to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([5 x i8]* @.str.14 to i64), i64 ptrtoint ([16 x i32]* @reltable.uint64_to_binary to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([5 x i8]* @.str.15 to i64), i64 ptrtoint ([16 x i32]* @reltable.uint64_to_binary to i64)) to i32)]
@.str.16 = [5 x i8] c"0000\00"
@.str.17 = [5 x i8] c"0001\00"
@.str.18 = [5 x i8] c"0010\00"
@.str.19 = [5 x i8] c"0011\00"
@.str.20 = [5 x i8] c"0100\00"
@.str.21 = [5 x i8] c"0101\00"
@.str.22 = [5 x i8] c"0110\00"
@.str.23 = [5 x i8] c"0111\00"
define void @uint64_to_binary(i32 %0, i8* %1) {
br label %3
3: ; preds = %29, %2
%4 = phi i32 [ 0, %29 ], [ 1, %2 ]
%5 = phi i32 [ %32, %29 ], [ %0, %2 ]
%6 = phi i8* [ %31, %29 ], [ %1, %2 ]
%7 = phi i32 [ %33, %29 ], [ 0, %2 ]
br label %8
8: ; preds = %3, %35
%9 = phi i32 [ 1, %35 ], [ %4, %3 ]
%10 = phi i32 [ %36, %35 ], [ %5, %3 ]
%11 = phi i32 [ %37, %35 ], [ %7, %3 ]
%12 = icmp eq i32 %9, 0
br i1 %12, label %23, label %13
13: ; preds = %8
%14 = icmp sgt i32 %10, 268435455
br i1 %14, label %15, label %35
15: ; preds = %13
%16 = ashr i32 %10, 28
%17 = sext i32 %16 to i64
%18 = getelementptr inbounds [16 x i8*], [16 x i8*]* @uint64_to_binary.nibbles_start, i64 0, i64 %17
%19 = load i8*, i8** %18
%20 = tail call i32 @strlen(i8* %19)
%21 = tail call i32 @memcpy(i8* %6, i8* %19, i32 %20)
%22 = sext i32 %20 to i64
br label %29
23: ; preds = %8
%24 = ashr i32 %10, 28
%25 = sext i32 %24 to i64
%26 = shl i64 %25, 2
%27 = call i8* @llvm.load.relative.i64(i8* bitcast ([16 x i32]* @reltable.uint64_to_binary to i8*), i64 %26)
%28 = tail call i32 @memcpy(i8* %6, i8* %27, i32 4)
br label %29
29: ; preds = %15, %23
%30 = phi i64 [ %22, %15 ], [ 4, %23 ]
%31 = getelementptr inbounds i8, i8* %6, i64 %30
%32 = shl i32 %10, 4
%33 = add nuw nsw i32 %11, 1
%34 = icmp eq i32 %33, 8
br i1 %34, label %41, label %3
35: ; preds = %13
%36 = shl i32 %10, 4
%37 = add nuw nsw i32 %11, 1
%38 = icmp eq i32 %37, 8
br i1 %38, label %39, label %8
39: ; preds = %35
store i8 48, i8* %6
%40 = getelementptr inbounds i8, i8* %6, i64 1
br label %41
41: ; preds = %29, %39
%42 = phi i8* [ %40, %39 ], [ %31, %29 ]
store i8 0, i8* %42
ret void
}