char hexToChar(int len, char *h) {
  char res = 0x00;
  int i = 0;
  for (; i < len; i++) {
    res |= (h[i] << (8 - 1 - i));
  }
  return res;
}


x86 assembly (clang, -O0):
<hexToChar>:
push   %rbp
mov    %rsp,%rbp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
movb   $0x0,-0x11(%rbp)
movl   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%eax
cmp    -0x4(%rbp),%eax
jge    1151 <hexToChar+0x51>
mov    -0x10(%rbp),%rax
movslq -0x18(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
mov    $0x7,%ecx
sub    -0x18(%rbp),%ecx
shl    %cl,%eax
mov    %eax,%ecx
movsbl -0x11(%rbp),%eax
or     %ecx,%eax
mov    %al,-0x11(%rbp)
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    1116 <hexToChar+0x16>
movsbl -0x11(%rbp),%eax
pop    %rbp
ret

x86 assembly (clang, -O2):
<hexToChar>:
test   %edi,%edi
jle    1115 <hexToChar+0x15>
mov    %edi,%r9d
cmp    $0x10,%edi
jae    1118 <hexToChar+0x18>
xor    %edi,%edi
xor    %eax,%eax
jmp    1607 <hexToChar+0x507>
xor    %eax,%eax
ret
mov    %r9d,%edi
and    $0xfffffff0,%edi
lea    -0x10(%rdi),%rax
mov    %rax,%r8
shr    $0x4,%r8
add    $0x1,%r8
test   %rax,%rax
je     1625 <hexToChar+0x525>
mov    %r8,%rax
and    $0xfffffffffffffffe,%rax
movdqa 0xefb(%rip),%xmm1
movdqa 0xf02(%rip),%xmm15
movdqa 0xf0a(%rip),%xmm4
movdqa 0xf11(%rip),%xmm14
xor    %ecx,%ecx
pxor   %xmm0,%xmm0
movdqa 0xf22(%rip),%xmm12
xchg   %ax,%ax
movdqa %xmm4,-0x28(%rsp)
movdqa %xmm15,-0x18(%rsp)
movdqa %xmm1,-0x48(%rsp)
movdqa %xmm1,%xmm13
movdqa %xmm15,-0x38(%rsp)
movdqa %xmm4,%xmm10
movdqa %xmm14,%xmm11
movdqu (%rsi,%rcx,1),%xmm5
movdqa %xmm5,%xmm7
pxor   %xmm9,%xmm9
punpcklbw %xmm9,%xmm7
movdqa %xmm7,%xmm8
punpcklwd %xmm9,%xmm8
punpckhwd %xmm9,%xmm7
punpckhbw %xmm9,%xmm5
movdqa %xmm5,%xmm1
punpcklwd %xmm9,%xmm1
punpckhwd %xmm9,%xmm5
movdqa 0xeaa(%rip),%xmm4
movdqa %xmm4,%xmm6
psubd  %xmm13,%xmm6
pslld  $0x17,%xmm6
paddd  %xmm12,%xmm6
cvttps2dq %xmm6,%xmm6
pshufd $0xf5,%xmm5,%xmm2
pmuludq %xmm6,%xmm5
pshufd $0xf5,%xmm6,%xmm3
pmuludq %xmm2,%xmm3
movdqa %xmm4,%xmm2
psubd  %xmm15,%xmm2
pshufd $0xe8,%xmm5,%xmm6
pshufd $0xe8,%xmm3,%xmm3
punpckldq %xmm3,%xmm6
pslld  $0x17,%xmm2
paddd  %xmm12,%xmm2
cvttps2dq %xmm2,%xmm2
pshufd $0xf5,%xmm1,%xmm3
pmuludq %xmm2,%xmm1
pshufd $0xf5,%xmm2,%xmm2
pmuludq %xmm3,%xmm2
movdqa %xmm4,%xmm3
psubd  %xmm10,%xmm3
movdqa %xmm10,%xmm15
pshufd $0xe8,%xmm1,%xmm10
pshufd $0xe8,%xmm2,%xmm1
punpckldq %xmm1,%xmm10
pslld  $0x17,%xmm3
paddd  %xmm12,%xmm3
cvttps2dq %xmm3,%xmm1
pshufd $0xf5,%xmm7,%xmm2
pmuludq %xmm1,%xmm7
pshufd $0xf5,%xmm1,%xmm1
pmuludq %xmm2,%xmm1
movdqa %xmm4,%xmm2
psubd  %xmm14,%xmm2
pshufd $0xe8,%xmm7,%xmm3
pshufd $0xe8,%xmm1,%xmm1
punpckldq %xmm1,%xmm3
pslld  $0x17,%xmm2
paddd  %xmm12,%xmm2
cvttps2dq %xmm2,%xmm1
pshufd $0xf5,%xmm8,%xmm2
pmuludq %xmm1,%xmm8
pshufd $0xf5,%xmm1,%xmm1
pmuludq %xmm2,%xmm1
movdqu 0x10(%rsi,%rcx,1),%xmm5
pshufd $0xe8,%xmm8,%xmm7
pshufd $0xe8,%xmm1,%xmm1
punpckldq %xmm1,%xmm7
movdqa 0xdd5(%rip),%xmm8
pand   %xmm8,%xmm7
pand   %xmm8,%xmm3
packuswb %xmm3,%xmm7
pand   %xmm8,%xmm10
pand   %xmm8,%xmm6
packuswb %xmm6,%xmm10
packuswb %xmm10,%xmm7
movdqa %xmm13,%xmm10
por    %xmm0,%xmm7
movdqa %xmm5,%xmm0
punpcklbw %xmm9,%xmm0
movdqa %xmm0,%xmm6
punpcklwd %xmm9,%xmm6
punpckhwd %xmm9,%xmm0
punpckhbw %xmm9,%xmm5
movdqa %xmm5,%xmm1
punpcklwd %xmm9,%xmm1
punpckhwd %xmm9,%xmm5
movdqa 0xd88(%rip),%xmm4
movdqa %xmm4,%xmm2
psubd  %xmm13,%xmm2
pslld  $0x17,%xmm2
paddd  %xmm12,%xmm2
cvttps2dq %xmm2,%xmm2
pshufd $0xf5,%xmm5,%xmm3
pmuludq %xmm2,%xmm5
pshufd $0xf5,%xmm2,%xmm2
pmuludq %xmm3,%xmm2
movdqa %xmm4,%xmm3
psubd  -0x38(%rsp),%xmm3
pshufd $0xe8,%xmm5,%xmm5
pshufd $0xe8,%xmm2,%xmm2
punpckldq %xmm2,%xmm5
pslld  $0x17,%xmm3
paddd  %xmm12,%xmm3
cvttps2dq %xmm3,%xmm2
pshufd $0xf5,%xmm1,%xmm3
pmuludq %xmm2,%xmm1
pshufd $0xf5,%xmm2,%xmm2
pmuludq %xmm3,%xmm2
movdqa %xmm4,%xmm3
movdqa %xmm15,%xmm13
movdqa %xmm15,%xmm9
psubd  %xmm15,%xmm3
pshufd $0xe8,%xmm1,%xmm1
pshufd $0xe8,%xmm2,%xmm2
punpckldq %xmm2,%xmm1
pslld  $0x17,%xmm3
paddd  %xmm12,%xmm3
cvttps2dq %xmm3,%xmm2
pshufd $0xf5,%xmm0,%xmm3
pmuludq %xmm2,%xmm0
pshufd $0xf5,%xmm2,%xmm2
pmuludq %xmm3,%xmm2
movdqa %xmm4,%xmm3
movdqa %xmm14,%xmm13
psubd  %xmm14,%xmm3
pshufd $0xe8,%xmm0,%xmm4
pshufd $0xe8,%xmm2,%xmm0
punpckldq %xmm0,%xmm4
pslld  $0x17,%xmm3
paddd  %xmm12,%xmm3
cvttps2dq %xmm3,%xmm0
pshufd $0xf5,%xmm6,%xmm2
pmuludq %xmm0,%xmm6
pshufd $0xf5,%xmm0,%xmm3
pmuludq %xmm2,%xmm3
pshufd $0xe8,%xmm6,%xmm0
pshufd $0xe8,%xmm3,%xmm2
movdqa -0x18(%rsp),%xmm15
punpckldq %xmm2,%xmm0
pand   %xmm8,%xmm0
pand   %xmm8,%xmm4
packuswb %xmm4,%xmm0
movdqa -0x28(%rsp),%xmm4
pand   %xmm8,%xmm1
pand   %xmm8,%xmm5
packuswb %xmm5,%xmm1
packuswb %xmm1,%xmm0
por    %xmm7,%xmm0
add    $0x20,%rcx
movdqa 0xc6f(%rip),%xmm1
paddd  %xmm1,%xmm14
paddd  %xmm1,%xmm4
paddd  %xmm1,%xmm15
movdqa -0x48(%rsp),%xmm2
paddd  %xmm1,%xmm2
movdqa %xmm2,-0x48(%rsp)
movdqa -0x48(%rsp),%xmm1
add    $0xfffffffffffffffe,%rax
jne    1170 <hexToChar+0x70>
movdqa 0xc49(%rip),%xmm5
movdqa %xmm5,%xmm12
psubd  %xmm13,%xmm12
movdqa %xmm5,%xmm2
psubd  %xmm9,%xmm2
movdqa %xmm5,%xmm3
psubd  -0x38(%rsp),%xmm3
psubd  %xmm10,%xmm5
test   $0x1,%r8b
je     15d2 <hexToChar+0x4d2>
movdqu (%rsi,%rcx,1),%xmm6
pxor   %xmm1,%xmm1
movdqa %xmm6,%xmm4
punpcklbw %xmm1,%xmm4
movdqa %xmm4,%xmm10
punpcklwd %xmm1,%xmm10
punpckhwd %xmm1,%xmm4
punpckhbw %xmm1,%xmm6
movdqa %xmm6,%xmm7
punpcklwd %xmm1,%xmm7
punpckhwd %xmm1,%xmm6
pslld  $0x17,%xmm5
movdqa 0xba0(%rip),%xmm8
paddd  %xmm8,%xmm5
cvttps2dq %xmm5,%xmm1
pshufd $0xf5,%xmm6,%xmm11
pmuludq %xmm1,%xmm6
pshufd $0xe8,%xmm6,%xmm5
pshufd $0xf5,%xmm1,%xmm1
pmuludq %xmm11,%xmm1
pshufd $0xe8,%xmm1,%xmm1
punpckldq %xmm1,%xmm5
pslld  $0x17,%xmm3
paddd  %xmm8,%xmm3
cvttps2dq %xmm3,%xmm1
pshufd $0xf5,%xmm7,%xmm6
pmuludq %xmm1,%xmm7
pshufd $0xe8,%xmm7,%xmm3
pshufd $0xf5,%xmm1,%xmm1
pmuludq %xmm6,%xmm1
pshufd $0xe8,%xmm1,%xmm1
punpckldq %xmm1,%xmm3
pslld  $0x17,%xmm2
paddd  %xmm8,%xmm2
cvttps2dq %xmm2,%xmm1
pshufd $0xf5,%xmm4,%xmm2
pmuludq %xmm1,%xmm4
pshufd $0xe8,%xmm4,%xmm4
pshufd $0xf5,%xmm1,%xmm1
pmuludq %xmm2,%xmm1
pshufd $0xe8,%xmm1,%xmm1
punpckldq %xmm1,%xmm4
pslld  $0x17,%xmm12
paddd  %xmm8,%xmm12
cvttps2dq %xmm12,%xmm1
pshufd $0xf5,%xmm10,%xmm2
pmuludq %xmm1,%xmm10
pshufd $0xe8,%xmm10,%xmm6
pshufd $0xf5,%xmm1,%xmm1
pmuludq %xmm2,%xmm1
pshufd $0xe8,%xmm1,%xmm1
punpckldq %xmm1,%xmm6
movdqa 0xaee(%rip),%xmm1
pand   %xmm1,%xmm6
pand   %xmm1,%xmm4
packuswb %xmm4,%xmm6
pand   %xmm1,%xmm3
pand   %xmm1,%xmm5
packuswb %xmm5,%xmm3
packuswb %xmm3,%xmm6
por    %xmm6,%xmm0
pshufd $0xee,%xmm0,%xmm1
por    %xmm0,%xmm1
pshufd $0x55,%xmm1,%xmm0
por    %xmm1,%xmm0
movdqa %xmm0,%xmm1
psrld  $0x10,%xmm1
por    %xmm0,%xmm1
movdqa %xmm1,%xmm0
psrlw  $0x8,%xmm0
por    %xmm1,%xmm0
movd   %xmm0,%eax
cmp    %r9,%rdi
je     1624 <hexToChar+0x524>
mov    $0x7,%ecx
sub    %edi,%ecx
xchg   %ax,%ax
movzbl (%rsi,%rdi,1),%edx
shl    %cl,%edx
or     %dl,%al
add    $0x1,%rdi
add    $0xffffffff,%ecx
cmp    %rdi,%r9
jne    1610 <hexToChar+0x510>
ret
movdqa 0x9d3(%rip),%xmm5
movdqa 0x9db(%rip),%xmm3
movdqa 0x9e3(%rip),%xmm2
movdqa 0x9ea(%rip),%xmm12
pxor   %xmm0,%xmm0
xor    %ecx,%ecx
test   $0x1,%r8b
jne    14b3 <hexToChar+0x3b3>
jmp    15d2 <hexToChar+0x4d2>

LLVM IR (-O0):
define signext i8 @hexToChar(i32 %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i8
%6 = alloca i32
store i32 %0, i32* %3
store i8* %1, i8** %4
store i8 0, i8* %5
store i32 0, i32* %6
br label %7
7: ; preds = %25, %2
%8 = load i32, i32* %6
%9 = load i32, i32* %3
%10 = icmp slt i32 %8, %9
br i1 %10, label %11, label %28
11: ; preds = %7
%12 = load i8*, i8** %4
%13 = load i32, i32* %6
%14 = sext i32 %13 to i64
%15 = getelementptr inbounds i8, i8* %12, i64 %14
%16 = load i8, i8* %15
%17 = sext i8 %16 to i32
%18 = load i32, i32* %6
%19 = sub nsw i32 7, %18
%20 = shl i32 %17, %19
%21 = load i8, i8* %5
%22 = sext i8 %21 to i32
%23 = or i32 %22, %20
%24 = trunc i32 %23 to i8
store i8 %24, i8* %5
br label %25
25: ; preds = %11
%26 = load i32, i32* %6
%27 = add nsw i32 %26, 1
store i32 %27, i32* %6
br label %7
28: ; preds = %7
%29 = load i8, i8* %5
ret i8 %29
}

LLVM IR (-O2):
define signext i8 @hexToChar(i32 %0, i8* nocapture %1) {
%3 = icmp sgt i32 %0, 0
br i1 %3, label %4, label %78
4: ; preds = %2
%5 = zext i32 %0 to i64
%6 = icmp ult i32 %0, 16
br i1 %6, label %62, label %7
7: ; preds = %4
%8 = and i64 %5, 4294967280
%9 = add nsw i64 %8, -16
%10 = lshr exact i64 %9, 4
%11 = add nuw nsw i64 %10, 1
%12 = and i64 %11, 1
%13 = icmp eq i64 %9, 0
br i1 %13, label %44, label %14
14: ; preds = %7
%15 = and i64 %11, 2305843009213693950
br label %16
16: ; preds = %16, %14
%17 = phi i64 [ 0, %14 ], [ %38, %16 ]
%18 = phi <16 x i8> [ zeroinitializer, %14 ], [ %37, %16 ]
%19 = phi <16 x i32> [ <i32 0, i32 1, i32 2, i32 3, i32 4, i32 5, i32 6, i32 7, i32 8, i32 9, i32 10, i32 11, i32 12, i32 13, i32 14, i32 15>, %14 ], [ %39, %16 ]
%20 = phi i64 [ 0, %14 ], [ %40, %16 ]
%21 = getelementptr inbounds i8, i8* %1, i64 %17
%22 = bitcast i8* %21 to <16 x i8>*
%23 = load <16 x i8>, <16 x i8>* %22
%24 = zext <16 x i8> %23 to <16 x i32>
%25 = sub <16 x i32> <i32 7, i32 7, i32 7, i32 7, i32 7, i32 7, i32 7, i32 7, i32 7, i32 7, i32 7, i32 7, i32 7, i32 7, i32 7, i32 7>, %19
%26 = shl <16 x i32> %24, %25
%27 = trunc <16 x i32> %26 to <16 x i8>
%28 = or <16 x i8> %18, %27
%29 = or i64 %17, 16
%30 = getelementptr inbounds i8, i8* %1, i64 %29
%31 = bitcast i8* %30 to <16 x i8>*
%32 = load <16 x i8>, <16 x i8>* %31
%33 = zext <16 x i8> %32 to <16 x i32>
%34 = sub <16 x i32> <i32 -9, i32 -9, i32 -9, i32 -9, i32 -9, i32 -9, i32 -9, i32 -9, i32 -9, i32 -9, i32 -9, i32 -9, i32 -9, i32 -9, i32 -9, i32 -9>, %19
%35 = shl <16 x i32> %33, %34
%36 = trunc <16 x i32> %35 to <16 x i8>
%37 = or <16 x i8> %28, %36
%38 = add nuw i64 %17, 32
%39 = add <16 x i32> %19, <i32 32, i32 32, i32 32, i32 32, i32 32, i32 32, i32 32, i32 32, i32 32, i32 32, i32 32, i32 32, i32 32, i32 32, i32 32, i32 32>
%40 = add i64 %20, 2
%41 = icmp eq i64 %40, %15
br i1 %41, label %42, label %16
42: ; preds = %16
%43 = sub <16 x i32> <i32 -25, i32 -25, i32 -25, i32 -25, i32 -25, i32 -25, i32 -25, i32 -25, i32 -25, i32 -25, i32 -25, i32 -25, i32 -25, i32 -25, i32 -25, i32 -25>, %19
br label %44
44: ; preds = %42, %7
%45 = phi <16 x i8> [ undef, %7 ], [ %37, %42 ]
%46 = phi i64 [ 0, %7 ], [ %38, %42 ]
%47 = phi <16 x i8> [ zeroinitializer, %7 ], [ %37, %42 ]
%48 = phi <16 x i32> [ <i32 7, i32 6, i32 5, i32 4, i32 3, i32 2, i32 1, i32 0, i32 -1, i32 -2, i32 -3, i32 -4, i32 -5, i32 -6, i32 -7, i32 -8>, %7 ], [ %43, %42 ]
%49 = icmp eq i64 %12, 0
br i1 %49, label %58, label %50
50: ; preds = %44
%51 = getelementptr inbounds i8, i8* %1, i64 %46
%52 = bitcast i8* %51 to <16 x i8>*
%53 = load <16 x i8>, <16 x i8>* %52
%54 = zext <16 x i8> %53 to <16 x i32>
%55 = shl <16 x i32> %54, %48
%56 = trunc <16 x i32> %55 to <16 x i8>
%57 = or <16 x i8> %47, %56
br label %58
58: ; preds = %44, %50
%59 = phi <16 x i8> [ %45, %44 ], [ %57, %50 ]
%60 = call i8 @llvm.vector.reduce.or.v16i8(<16 x i8> %59)
%61 = icmp eq i64 %8, %5
br i1 %61, label %78, label %62
62: ; preds = %4, %58
%63 = phi i64 [ 0, %4 ], [ %8, %58 ]
%64 = phi i8 [ 0, %4 ], [ %60, %58 ]
br label %65
65: ; preds = %62, %65
%66 = phi i64 [ %76, %65 ], [ %63, %62 ]
%67 = phi i8 [ %75, %65 ], [ %64, %62 ]
%68 = getelementptr inbounds i8, i8* %1, i64 %66
%69 = load i8, i8* %68
%70 = zext i8 %69 to i32
%71 = trunc i64 %66 to i32
%72 = sub i32 7, %71
%73 = shl i32 %70, %72
%74 = trunc i32 %73 to i8
%75 = or i8 %67, %74
%76 = add nuw nsw i64 %66, 1
%77 = icmp eq i64 %76, %5
br i1 %77, label %78, label %65
78: ; preds = %65, %58, %2
%79 = phi i8 [ 0, %2 ], [ %60, %58 ], [ %75, %65 ]
ret i8 %79
}