void bintohex(char binaryNumber[32], char hex[2]) {
  int i = 0, j = 0, k = 0, l = 0, m = 0, h[] = {0, 0};
  char bit[0], dechex[16] = {"0123456789ABCDEF"}, val;
  for (j = 0; j <= 3; j++) {
    h[j] = 0;
    l = 0;
    for (i = 0; i <= 3; i++) {
      k = j * 4 + i;
      strncpy(bit, binaryNumber + k, 1);
      m = 0;
      if (bit[0] == '1')
        m = 1;
      l = (l * 2) + m;
      val = dechex[l];
    }
    hex[j] = val;
  }
}


x86 assembly (clang, -O0):
<bintohex>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
movl   $0x0,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
lea    -0x2c(%rbp),%rdi
xor    %esi,%esi
mov    $0x8,%edx
call   1040 <memset@plt>
mov    0xe96(%rip),%rax
mov    %rax,-0x40(%rbp)
mov    0xe93(%rip),%rax
mov    %rax,-0x38(%rbp)
movl   $0x0,-0x18(%rbp)
cmpl   $0x3,-0x18(%rbp)
jg     122f <bintohex+0x10f>
movslq -0x18(%rbp),%rax
movl   $0x0,-0x2c(%rbp,%rax,4)
movl   $0x0,-0x20(%rbp)
movl   $0x0,-0x14(%rbp)
cmpl   $0x3,-0x14(%rbp)
jg     1213 <bintohex+0xf3>
mov    -0x18(%rbp),%eax
shl    $0x2,%eax
add    -0x14(%rbp),%eax
mov    %eax,-0x1c(%rbp)
lea    -0x2d(%rbp),%rdi
mov    -0x8(%rbp),%rsi
movslq -0x1c(%rbp),%rax
add    %rax,%rsi
mov    $0x1,%edx
call   1030 <strncpy@plt>
movl   $0x0,-0x24(%rbp)
movsbl -0x2d(%rbp),%eax
cmp    $0x31,%eax
jne    11ee <bintohex+0xce>
movl   $0x1,-0x24(%rbp)
mov    -0x20(%rbp),%eax
shl    $0x1,%eax
add    -0x24(%rbp),%eax
mov    %eax,-0x20(%rbp)
movslq -0x20(%rbp),%rax
mov    -0x40(%rbp,%rax,1),%al
mov    %al,-0x41(%rbp)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    11a4 <bintohex+0x84>
mov    -0x41(%rbp),%dl
mov    -0x10(%rbp),%rax
movslq -0x18(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    1180 <bintohex+0x60>
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<bintohex>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%rbx
xor    %r12d,%r12d
lea    0x7(%rsp),%r15
nopl   0x0(%rax)
mov    $0x1,%edx
mov    %r15,%rdi
mov    %rbx,%rsi
call   1030 <strncpy@plt>
xor    %ebp,%ebp
cmpb   $0x31,0x7(%rsp)
sete   %bpl
lea    0x1(%rbx),%rsi
mov    $0x1,%edx
mov    %r15,%rdi
call   1030 <strncpy@plt>
xor    %eax,%eax
cmpb   $0x31,0x7(%rsp)
sete   %al
lea    (%rax,%rbp,2),%rbp
lea    0x2(%rbx),%rsi
mov    $0x1,%edx
mov    %r15,%rdi
call   1030 <strncpy@plt>
xor    %r13d,%r13d
cmpb   $0x31,0x7(%rsp)
sete   %r13b
lea    0x3(%rbx),%rsi
mov    $0x1,%edx
mov    %r15,%rdi
call   1030 <strncpy@plt>
xor    %eax,%eax
cmpb   $0x31,0x7(%rsp)
sete   %al
add    %r13,%r13
lea    0x0(,%rbp,4),%rcx
add    %r13,%rcx
or     %rax,%rcx
lea    0xe46(%rip),%rax
movzbl (%rax,%rcx,1),%eax
mov    %al,(%r14,%r12,1)
add    $0x1,%r12
add    $0x4,%rbx
cmp    $0x4,%r12
jne    1130 <bintohex+0x20>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@__const.bintohex.dechex = [16 x i8] c"0123456789ABCDEF"
define void @bintohex(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca [2 x i32]
%11 = alloca [0 x i8]
%12 = alloca [16 x i8]
%13 = alloca i8
store i8* %0, i8** %3
store i8* %1, i8** %4
store i32 0, i32* %5
store i32 0, i32* %6
store i32 0, i32* %7
store i32 0, i32* %8
store i32 0, i32* %9
%14 = bitcast [2 x i32]* %10 to i8*
%15 = bitcast [16 x i8]* %12 to i8*
store i32 0, i32* %6
br label %16
16: ; preds = %60, %2
%17 = load i32, i32* %6
%18 = icmp sle i32 %17, 3
br i1 %18, label %19, label %63
19: ; preds = %16
%20 = load i32, i32* %6
%21 = sext i32 %20 to i64
%22 = getelementptr inbounds [2 x i32], [2 x i32]* %10, i64 0, i64 %21
store i32 0, i32* %22
store i32 0, i32* %8
store i32 0, i32* %5
br label %23
23: ; preds = %51, %19
%24 = load i32, i32* %5
%25 = icmp sle i32 %24, 3
br i1 %25, label %26, label %54
26: ; preds = %23
%27 = load i32, i32* %6
%28 = mul nsw i32 %27, 4
%29 = load i32, i32* %5
%30 = add nsw i32 %28, %29
store i32 %30, i32* %7
%31 = getelementptr inbounds [0 x i8], [0 x i8]* %11, i64 0, i64 0
%32 = load i8*, i8** %3
%33 = load i32, i32* %7
%34 = sext i32 %33 to i64
%35 = getelementptr inbounds i8, i8* %32, i64 %34
%36 = call i8* @strncpy(i8* %31, i8* %35, i64 1)
store i32 0, i32* %9
%37 = getelementptr inbounds [0 x i8], [0 x i8]* %11, i64 0, i64 0
%38 = load i8, i8* %37
%39 = sext i8 %38 to i32
%40 = icmp eq i32 %39, 49
br i1 %40, label %41, label %42
41: ; preds = %26
store i32 1, i32* %9
br label %42
42: ; preds = %41, %26
%43 = load i32, i32* %8
%44 = mul nsw i32 %43, 2
%45 = load i32, i32* %9
%46 = add nsw i32 %44, %45
store i32 %46, i32* %8
%47 = load i32, i32* %8
%48 = sext i32 %47 to i64
%49 = getelementptr inbounds [16 x i8], [16 x i8]* %12, i64 0, i64 %48
%50 = load i8, i8* %49
store i8 %50, i8* %13
br label %51
51: ; preds = %42
%52 = load i32, i32* %5
%53 = add nsw i32 %52, 1
store i32 %53, i32* %5
br label %23
54: ; preds = %23
%55 = load i8, i8* %13
%56 = load i8*, i8** %4
%57 = load i32, i32* %6
%58 = sext i32 %57 to i64
%59 = getelementptr inbounds i8, i8* %56, i64 %58
store i8 %55, i8* %59
br label %60
60: ; preds = %54
%61 = load i32, i32* %6
%62 = add nsw i32 %61, 1
store i32 %62, i32* %6
br label %16
63: ; preds = %16
ret void
}

LLVM IR (-O2):
@__const.bintohex.dechex = [16 x i8] c"0123456789ABCDEF"
define void @bintohex(i8* nocapture %0, i8* nocapture writeonly %1) {
%3 = alloca [0 x i8]
%4 = getelementptr inbounds [0 x i8], [0 x i8]* %3, i64 0, i64 0
br label %5
5: ; preds = %2, %5
%6 = phi i64 [ 0, %2 ], [ %38, %5 ]
%7 = shl nsw i64 %6, 2
%8 = getelementptr inbounds i8, i8* %0, i64 %7
%9 = call i8* @strncpy(i8* %4, i8* dereferenceable(1) %8, i64 1)
%10 = load i8, i8* %4
%11 = icmp eq i8 %10, 49
%12 = or i64 %7, 1
%13 = getelementptr inbounds i8, i8* %0, i64 %12
%14 = call i8* @strncpy(i8* %4, i8* dereferenceable(1) %13, i64 1)
%15 = load i8, i8* %4
%16 = icmp eq i8 %15, 49
%17 = zext i1 %16 to i64
%18 = select i1 %11, i64 2, i64 0
%19 = or i64 %18, %17
%20 = or i64 %7, 2
%21 = getelementptr inbounds i8, i8* %0, i64 %20
%22 = call i8* @strncpy(i8* %4, i8* dereferenceable(1) %21, i64 1)
%23 = load i8, i8* %4
%24 = icmp eq i8 %23, 49
%25 = or i64 %7, 3
%26 = getelementptr inbounds i8, i8* %0, i64 %25
%27 = call i8* @strncpy(i8* %4, i8* dereferenceable(1) %26, i64 1)
%28 = load i8, i8* %4
%29 = icmp eq i8 %28, 49
%30 = zext i1 %29 to i64
%31 = shl nuw nsw i64 %19, 2
%32 = select i1 %24, i64 2, i64 0
%33 = or i64 %31, %32
%34 = or i64 %33, %30
%35 = getelementptr inbounds [16 x i8], [16 x i8]* @__const.bintohex.dechex, i64 0, i64 %34
%36 = load i8, i8* %35
%37 = getelementptr inbounds i8, i8* %1, i64 %6
store i8 %36, i8* %37
%38 = add nuw nsw i64 %6, 1
%39 = icmp eq i64 %38, 4
br i1 %39, label %40, label %5
40: ; preds = %5
ret void
}