const char *binary(int value) {
  static const char binnums[16][5] = {
      "0000", "0001", "0010", "0011", "0100", "0101", "0110", "0111",
      "1000", "1001", "1010", "1011", "1100", "1101", "1110", "1111"};
  static const char *hexnums = "0123456789abcdef";
  static char inbuffer[16], outbuffer[4 * 16];
  const char *i;
  sprintf(inbuffer, "%x", value);
  for (i = inbuffer; *i != 0; ++i) {
    int d = strchr(hexnums, *i) - hexnums;
    char *o = outbuffer + (i - inbuffer) * 4;
    sprintf(o, "%s", binnums[d]);
  }
  return strchr(outbuffer, '1');
}


x86 assembly (clang, -O0):
<binary>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    -0x4(%rbp),%edx
lea    0x2f1b(%rip),%rdi
lea    0xf25(%rip),%rsi
mov    $0x0,%al
call   1040 <sprintf@plt>
lea    0x2f06(%rip),%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     11d3 <binary+0xb3>
mov    0x2ecb(%rip),%rdi
mov    -0x10(%rbp),%rax
movsbl (%rax),%esi
call   1030 <strchr@plt>
mov    0x2eb8(%rip),%rcx
sub    %rcx,%rax
mov    %eax,-0x14(%rbp)
mov    -0x10(%rbp),%rcx
lea    0x2ec7(%rip),%rax
sub    %rax,%rcx
shl    $0x2,%rcx
lea    0x2ec9(%rip),%rax
add    %rcx,%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
movslq -0x14(%rbp),%rax
lea    0xe53(%rip),%rdx
imul   $0x5,%rax,%rax
add    %rax,%rdx
lea    0xea9(%rip),%rsi
mov    $0x0,%al
call   1040 <sprintf@plt>
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x10(%rbp)
jmp    114e <binary+0x2e>
lea    0x2e86(%rip),%rdi
mov    $0x31,%esi
call   1030 <strchr@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<binary>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %edi,%edx
lea    0x2eff(%rip),%rdi
lea    0xf09(%rip),%rsi
xor    %eax,%eax
call   1060 <sprintf@plt>
mov    0x2eeb(%rip),%al
test   %al,%al
je     11c3 <binary+0x83>
lea    0x2ef0(%rip),%r15
lea    0x2eda(%rip),%rbx
lea    0xed2(%rip),%r14
lea    0xe7b(%rip),%r12
cs nopw 0x0(%rax,%rax,1)
nop
movsbl %al,%esi
mov    $0x11,%edx
mov    %r14,%rdi
call   1050 <memchr@plt>
sub    %r14d,%eax
cltq
lea    (%rax,%rax,4),%rsi
add    %r12,%rsi
mov    %r15,%rdi
call   1030 <strcpy@plt>
movzbl (%rbx),%eax
add    $0x4,%r15
add    $0x1,%rbx
test   %al,%al
jne    1190 <binary+0x50>
lea    0x2e96(%rip),%rdi
mov    $0x31,%esi
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
jmp    1040 <strchr@plt>

LLVM IR (-O0):
@binary.binnums = internal constant [16 x [5 x i8]] [[5 x i8] c"0000\00", [5 x i8] c"0001\00", [5 x i8] c"0010\00", [5 x i8] c"0011\00", [5 x i8] c"0100\00", [5 x i8] c"0101\00", [5 x i8] c"0110\00", [5 x i8] c"0111\00", [5 x i8] c"1000\00", [5 x i8] c"1001\00", [5 x i8] c"1010\00", [5 x i8] c"1011\00", [5 x i8] c"1100\00", [5 x i8] c"1101\00", [5 x i8] c"1110\00", [5 x i8] c"1111\00"]
@binary.hexnums = internal global i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i32 0, i32 0)
@.str = [17 x i8] c"0123456789abcdef\00"
@binary.inbuffer = internal global [16 x i8] zeroinitializer
@binary.outbuffer = internal global [64 x i8] zeroinitializer
@.str.1 = [3 x i8] c"%x\00"
@.str.2 = [3 x i8] c"%s\00"
define i8* @binary(i32 %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i8*
store i32 %0, i32* %2
%6 = load i32, i32* %2
%7 = call i32 (i8*, i8*, ...) @sprintf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @binary.inbuffer, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 %6)
store i8* getelementptr inbounds ([16 x i8], [16 x i8]* @binary.inbuffer, i64 0, i64 0), i8** %3
br label %8
8: ; preds = %35, %1
%9 = load i8*, i8** %3
%10 = load i8, i8* %9
%11 = sext i8 %10 to i32
%12 = icmp ne i32 %11, 0
br i1 %12, label %13, label %38
13: ; preds = %8
%14 = load i8*, i8** @binary.hexnums
%15 = load i8*, i8** %3
%16 = load i8, i8* %15
%17 = sext i8 %16 to i32
%18 = call i8* @strchr(i8* %14, i32 %17)
%19 = load i8*, i8** @binary.hexnums
%20 = ptrtoint i8* %18 to i64
%21 = ptrtoint i8* %19 to i64
%22 = sub i64 %20, %21
%23 = trunc i64 %22 to i32
store i32 %23, i32* %4
%24 = load i8*, i8** %3
%25 = ptrtoint i8* %24 to i64
%26 = sub i64 %25, ptrtoint ([16 x i8]* @binary.inbuffer to i64)
%27 = mul nsw i64 %26, 4
%28 = getelementptr inbounds i8, i8* getelementptr inbounds ([64 x i8], [64 x i8]* @binary.outbuffer, i64 0, i64 0), i64 %27
store i8* %28, i8** %5
%29 = load i8*, i8** %5
%30 = load i32, i32* %4
%31 = sext i32 %30 to i64
%32 = getelementptr inbounds [16 x [5 x i8]], [16 x [5 x i8]]* @binary.binnums, i64 0, i64 %31
%33 = getelementptr inbounds [5 x i8], [5 x i8]* %32, i64 0, i64 0
%34 = call i32 (i8*, i8*, ...) @sprintf(i8* %29, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8* %33)
br label %35
35: ; preds = %13
%36 = load i8*, i8** %3
%37 = getelementptr inbounds i8, i8* %36, i32 1
store i8* %37, i8** %3
br label %8
38: ; preds = %8
%39 = call i8* @strchr(i8* getelementptr inbounds ([64 x i8], [64 x i8]* @binary.outbuffer, i64 0, i64 0), i32 49)
ret i8* %39
}

LLVM IR (-O2):
@binary.binnums = internal constant [16 x [5 x i8]] [[5 x i8] c"0000\00", [5 x i8] c"0001\00", [5 x i8] c"0010\00", [5 x i8] c"0011\00", [5 x i8] c"0100\00", [5 x i8] c"0101\00", [5 x i8] c"0110\00", [5 x i8] c"0111\00", [5 x i8] c"1000\00", [5 x i8] c"1001\00", [5 x i8] c"1010\00", [5 x i8] c"1011\00", [5 x i8] c"1100\00", [5 x i8] c"1101\00", [5 x i8] c"1110\00", [5 x i8] c"1111\00"]
@.str = [17 x i8] c"0123456789abcdef\00"
@binary.inbuffer = internal global [16 x i8] zeroinitializer
@binary.outbuffer = internal global [64 x i8] zeroinitializer
@.str.1 = [3 x i8] c"%x\00"
define i8* @binary(i32 %0) {
%2 = tail call i32 (i8*, i8*, ...) @sprintf(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @binary.inbuffer, i64 0, i64 0), i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 %0)
%3 = load i8, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @binary.inbuffer, i64 0, i64 0)
%4 = icmp eq i8 %3, 0
br i1 %4, label %23, label %5
5: ; preds = %1, %5
%6 = phi i8 [ %21, %5 ], [ %3, %1 ]
%7 = phi i8* [ %20, %5 ], [ getelementptr inbounds ([16 x i8], [16 x i8]* @binary.inbuffer, i64 0, i64 0), %1 ]
%8 = sext i8 %6 to i32
%9 = tail call i8* @memchr(i8* dereferenceable(17) getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), i32 %8, i64 17)
%10 = ptrtoint i8* %9 to i64
%11 = sub i64 %10, sext (i32 ptrtoint ([17 x i8]* @.str to i32) to i64)
%12 = ptrtoint i8* %7 to i64
%13 = sub i64 %12, ptrtoint ([16 x i8]* @binary.inbuffer to i64)
%14 = shl nsw i64 %13, 2
%15 = getelementptr inbounds [64 x i8], [64 x i8]* @binary.outbuffer, i64 0, i64 %14
%16 = shl i64 %11, 32
%17 = ashr exact i64 %16, 32
%18 = getelementptr inbounds [16 x [5 x i8]], [16 x [5 x i8]]* @binary.binnums, i64 0, i64 %17, i64 0
%19 = tail call i8* @strcpy(i8* %15, i8* %18)
%20 = getelementptr inbounds i8, i8* %7, i64 1
%21 = load i8, i8* %20
%22 = icmp eq i8 %21, 0
br i1 %22, label %23, label %5
23: ; preds = %5, %1
%24 = tail call i8* @strchr(i8* dereferenceable(1) getelementptr inbounds ([64 x i8], [64 x i8]* @binary.outbuffer, i64 0, i64 0), i32 49)
ret i8* %24
}