void *sqlite3HexToBlob(const char *z) {
  char *zBlob;
  int i;
  int n = strlen(z);
  if (n % 2)
    return 0;
  zBlob = (char *)sqlite3Malloc(n / 2, 1);
  if (zBlob) {
    for (i = 0; i < n; i += 2) {
      zBlob[i / 2] = (hexToInt(z[i]) << 4) | hexToInt(z[i + 1]);
    }
  }
  return zBlob;
}


x86 assembly (clang, -O0):
<sqlite3HexToBlob>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0x20(%rbp)
mov    -0x20(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
je     1169 <sqlite3HexToBlob+0x39>
movq   $0x0,-0x8(%rbp)
jmp    121e <sqlite3HexToBlob+0xee>
mov    -0x20(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,%edi
mov    $0x1,%esi
mov    $0x0,%al
call   1050 <sqlite3Malloc@plt>
cltq
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     1216 <sqlite3HexToBlob+0xe6>
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0x20(%rbp),%eax
jge    1211 <sqlite3HexToBlob+0xe1>
mov    -0x10(%rbp),%rax
movslq -0x1c(%rbp),%rcx
movsbl (%rax,%rcx,1),%edi
mov    $0x0,%al
call   1040 <hexToInt@plt>
shl    $0x4,%eax
mov    %eax,-0x30(%rbp)
mov    -0x10(%rbp),%rax
mov    -0x1c(%rbp),%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
movsbl (%rax,%rcx,1),%edi
mov    $0x0,%al
call   1040 <hexToInt@plt>
mov    %eax,%ecx
mov    -0x30(%rbp),%eax
or     %ecx,%eax
mov    %al,-0x29(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x1c(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    -0x29(%rbp),%dl
mov    %eax,%ecx
mov    -0x28(%rbp),%rax
movslq %ecx,%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x1c(%rbp),%eax
add    $0x2,%eax
mov    %eax,-0x1c(%rbp)
jmp    119a <sqlite3HexToBlob+0x6a>
jmp    1216 <sqlite3HexToBlob+0xe6>
mov    -0x18(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sqlite3HexToBlob>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rdi,%r12
call   1030 <strlen@plt>
mov    %rax,%r14
test   $0x1,%r14b
jne    11b4 <sqlite3HexToBlob+0x84>
mov    %r14d,%edi
shr    $0x1f,%edi
add    %r14d,%edi
sar    %edi
mov    $0x1,%esi
xor    %eax,%eax
call   1050 <sqlite3Malloc@plt>
movslq %eax,%r15
test   %r15d,%r15d
je     11b7 <sqlite3HexToBlob+0x87>
test   %r14d,%r14d
jle    11b7 <sqlite3HexToBlob+0x87>
mov    %r15,%rbx
xor    %ebp,%ebp
cs nopw 0x0(%rax,%rax,1)
nop
movsbl (%r12,%rbp,1),%edi
xor    %eax,%eax
call   1040 <hexToInt@plt>
mov    %eax,%r13d
shl    $0x4,%r13d
movsbl 0x1(%r12,%rbp,1),%edi
xor    %eax,%eax
call   1040 <hexToInt@plt>
or     %r13d,%eax
mov    %al,(%rbx)
add    $0x2,%rbp
add    $0x1,%rbx
cmp    %r14d,%ebp
jl     1180 <sqlite3HexToBlob+0x50>
jmp    11b7 <sqlite3HexToBlob+0x87>
xor    %r15d,%r15d
mov    %r15,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i8* @sqlite3HexToBlob(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i32
store i8* %0, i8** %3
%7 = load i8*, i8** %3
%8 = call i64 @strlen(i8* %7)
%9 = trunc i64 %8 to i32
store i32 %9, i32* %6
%10 = load i32, i32* %6
%11 = srem i32 %10, 2
%12 = icmp ne i32 %11, 0
br i1 %12, label %13, label %14
13: ; preds = %1
store i8* null, i8** %2
br label %57
14: ; preds = %1
%15 = load i32, i32* %6
%16 = sdiv i32 %15, 2
%17 = call i32 (i32, i32, ...) bitcast (i32 (...)* @sqlite3Malloc to i32 (i32, i32, ...)*)(i32 %16, i32 1)
%18 = sext i32 %17 to i64
%19 = inttoptr i64 %18 to i8*
store i8* %19, i8** %4
%20 = load i8*, i8** %4
%21 = icmp ne i8* %20, null
br i1 %21, label %22, label %55
22: ; preds = %14
store i32 0, i32* %5
br label %23
23: ; preds = %51, %22
%24 = load i32, i32* %5
%25 = load i32, i32* %6
%26 = icmp slt i32 %24, %25
br i1 %26, label %27, label %54
27: ; preds = %23
%28 = load i8*, i8** %3
%29 = load i32, i32* %5
%30 = sext i32 %29 to i64
%31 = getelementptr inbounds i8, i8* %28, i64 %30
%32 = load i8, i8* %31
%33 = sext i8 %32 to i32
%34 = call i32 (i32, ...) bitcast (i32 (...)* @hexToInt to i32 (i32, ...)*)(i32 %33)
%35 = shl i32 %34, 4
%36 = load i8*, i8** %3
%37 = load i32, i32* %5
%38 = add nsw i32 %37, 1
%39 = sext i32 %38 to i64
%40 = getelementptr inbounds i8, i8* %36, i64 %39
%41 = load i8, i8* %40
%42 = sext i8 %41 to i32
%43 = call i32 (i32, ...) bitcast (i32 (...)* @hexToInt to i32 (i32, ...)*)(i32 %42)
%44 = or i32 %35, %43
%45 = trunc i32 %44 to i8
%46 = load i8*, i8** %4
%47 = load i32, i32* %5
%48 = sdiv i32 %47, 2
%49 = sext i32 %48 to i64
%50 = getelementptr inbounds i8, i8* %46, i64 %49
store i8 %45, i8* %50
br label %51
51: ; preds = %27
%52 = load i32, i32* %5
%53 = add nsw i32 %52, 2
store i32 %53, i32* %5
br label %23
54: ; preds = %23
br label %55
55: ; preds = %54, %14
%56 = load i8*, i8** %4
store i8* %56, i8** %2
br label %57
57: ; preds = %55, %13
%58 = load i8*, i8** %2
ret i8* %58
}

LLVM IR (-O2):
define i8* @sqlite3HexToBlob(i8* nocapture %0) {
%2 = tail call i64 @strlen(i8* dereferenceable(1) %0)
%3 = trunc i64 %2 to i32
%4 = and i32 %3, 1
%5 = icmp eq i32 %4, 0
br i1 %5, label %6, label %33
6: ; preds = %1
%7 = sdiv i32 %3, 2
%8 = tail call i32 (i32, i32, ...) bitcast (i32 (...)* @sqlite3Malloc to i32 (i32, i32, ...)*)(i32 %7, i32 1)
%9 = sext i32 %8 to i64
%10 = inttoptr i64 %9 to i8*
%11 = icmp ne i32 %8, 0
%12 = icmp sgt i32 %3, 0
%13 = select i1 %11, i1 %12, i1 false
br i1 %13, label %14, label %33
14: ; preds = %6, %14
%15 = phi i64 [ %30, %14 ], [ 0, %6 ]
%16 = getelementptr inbounds i8, i8* %0, i64 %15
%17 = load i8, i8* %16
%18 = sext i8 %17 to i32
%19 = tail call i32 (i32, ...) bitcast (i32 (...)* @hexToInt to i32 (i32, ...)*)(i32 %18)
%20 = shl i32 %19, 4
%21 = or i64 %15, 1
%22 = getelementptr inbounds i8, i8* %0, i64 %21
%23 = load i8, i8* %22
%24 = sext i8 %23 to i32
%25 = tail call i32 (i32, ...) bitcast (i32 (...)* @hexToInt to i32 (i32, ...)*)(i32 %24)
%26 = or i32 %25, %20
%27 = trunc i32 %26 to i8
%28 = lshr exact i64 %15, 1
%29 = getelementptr inbounds i8, i8* %10, i64 %28
store i8 %27, i8* %29
%30 = add nuw i64 %15, 2
%31 = trunc i64 %30 to i32
%32 = icmp slt i32 %31, %3
br i1 %32, label %14, label %33
33: ; preds = %14, %6, %1
%34 = phi i8* [ null, %1 ], [ %10, %6 ], [ %10, %14 ]
ret i8* %34
}