void *sqlite3HexToBlob(const char *z) {
  char *zBlob;
  int i;
  int n = strlen(z);
  if (n % 2)
    return 0;
  zBlob = (char *)sqlite3Malloc(n / 2);
  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    1209 <sqlite3HexToBlob+0xd9>
mov    -0x20(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,%edi
mov    $0x0,%al
call   1050 <sqlite3Malloc@plt>
cltq
mov    %rax,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0x20(%rbp),%eax
jge    1201 <sqlite3HexToBlob+0xd1>
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    118a <sqlite3HexToBlob+0x5a>
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    11a4 <sqlite3HexToBlob+0x74>
mov    %r14d,%edi
shr    $0x1f,%edi
add    %r14d,%edi
sar    %edi
xor    %eax,%eax
call   1050 <sqlite3Malloc@plt>
movslq %eax,%r15
test   %r14d,%r14d
jle    11a7 <sqlite3HexToBlob+0x77>
mov    %r15,%rbx
xor    %ebp,%ebp
nopl   0x0(%rax,%rax,1)
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     1170 <sqlite3HexToBlob+0x40>
jmp    11a7 <sqlite3HexToBlob+0x77>
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 %53
14: ; preds = %1
%15 = load i32, i32* %6
%16 = sdiv i32 %15, 2
%17 = call i32 (i32, ...) bitcast (i32 (...)* @sqlite3Malloc to i32 (i32, ...)*)(i32 %16)
%18 = sext i32 %17 to i64
%19 = inttoptr i64 %18 to i8*
store i8* %19, i8** %4
store i32 0, i32* %5
br label %20
20: ; preds = %48, %14
%21 = load i32, i32* %5
%22 = load i32, i32* %6
%23 = icmp slt i32 %21, %22
br i1 %23, label %24, label %51
24: ; preds = %20
%25 = load i8*, i8** %3
%26 = load i32, i32* %5
%27 = sext i32 %26 to i64
%28 = getelementptr inbounds i8, i8* %25, i64 %27
%29 = load i8, i8* %28
%30 = sext i8 %29 to i32
%31 = call i32 (i32, ...) bitcast (i32 (...)* @hexToInt to i32 (i32, ...)*)(i32 %30)
%32 = shl i32 %31, 4
%33 = load i8*, i8** %3
%34 = load i32, i32* %5
%35 = add nsw i32 %34, 1
%36 = sext i32 %35 to i64
%37 = getelementptr inbounds i8, i8* %33, i64 %36
%38 = load i8, i8* %37
%39 = sext i8 %38 to i32
%40 = call i32 (i32, ...) bitcast (i32 (...)* @hexToInt to i32 (i32, ...)*)(i32 %39)
%41 = or i32 %32, %40
%42 = trunc i32 %41 to i8
%43 = load i8*, i8** %4
%44 = load i32, i32* %5
%45 = sdiv i32 %44, 2
%46 = sext i32 %45 to i64
%47 = getelementptr inbounds i8, i8* %43, i64 %46
store i8 %42, i8* %47
br label %48
48: ; preds = %24
%49 = load i32, i32* %5
%50 = add nsw i32 %49, 2
store i32 %50, i32* %5
br label %20
51: ; preds = %20
%52 = load i8*, i8** %4
store i8* %52, i8** %2
br label %53
53: ; preds = %51, %13
%54 = load i8*, i8** %2
ret i8* %54
}

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 %31
6: ; preds = %1
%7 = sdiv i32 %3, 2
%8 = tail call i32 (i32, ...) bitcast (i32 (...)* @sqlite3Malloc to i32 (i32, ...)*)(i32 %7)
%9 = sext i32 %8 to i64
%10 = inttoptr i64 %9 to i8*
%11 = icmp sgt i32 %3, 0
br i1 %11, label %12, label %31
12: ; preds = %6, %12
%13 = phi i64 [ %28, %12 ], [ 0, %6 ]
%14 = getelementptr inbounds i8, i8* %0, i64 %13
%15 = load i8, i8* %14
%16 = sext i8 %15 to i32
%17 = tail call i32 (i32, ...) bitcast (i32 (...)* @hexToInt to i32 (i32, ...)*)(i32 %16)
%18 = shl i32 %17, 4
%19 = or i64 %13, 1
%20 = getelementptr inbounds i8, i8* %0, i64 %19
%21 = load i8, i8* %20
%22 = sext i8 %21 to i32
%23 = tail call i32 (i32, ...) bitcast (i32 (...)* @hexToInt to i32 (i32, ...)*)(i32 %22)
%24 = or i32 %23, %18
%25 = trunc i32 %24 to i8
%26 = lshr exact i64 %13, 1
%27 = getelementptr inbounds i8, i8* %10, i64 %26
store i8 %25, i8* %27
%28 = add nuw i64 %13, 2
%29 = trunc i64 %28 to i32
%30 = icmp slt i32 %29, %3
br i1 %30, label %12, label %31
31: ; preds = %12, %6, %1
%32 = phi i8* [ null, %1 ], [ %10, %6 ], [ %10, %12 ]
ret i8* %32
}