#define NULL ((void *)0)
typedef unsigned long size_t; // Customize by platform.
typedef long intptr_t;
typedef unsigned long uintptr_t;
typedef long scalar_t__; // Either arithmetic or pointer type.
/* By default, we understand bool (as a convenience). */
typedef int bool;
#define false 0
#define true 1

/* Forward declarations */

/* Type definitions */
struct digest_result {
  int dummy;
};

/* Variables and functions */
int /*<<< orphan*/ free(struct digest_result *);
struct digest_result *malloc_result(int);
int strlen(char const *);
struct digest_result *digest_hex2bin(const char *str, int len) {
  static const char hexval[256] = {
      -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
      -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
      -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 0,  1,  2,  3,  4,  5,
      6,  7,  8,  9,  -1, -1, -1, -1, -1, -1, -1, 10, 11, 12, 13, 14, 15, -1,
      -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
      -1, -1, -1, -1, -1, -1, -1, 10, 11, 12, 13, 14, 15, -1, -1, -1, -1, -1,
      -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
      -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
      -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
      -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
      -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
      -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
      -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
      -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
      -1, -1, -1, -1,
  };
  struct digest_result *resbuf;
  int i;
  if (len < 0)
    len = strlen(str);
  if (len % 2 != 0)
    return NULL;
  resbuf = malloc_result(len / 2);
  for (i = 0; i < len; i += 2) {
    if (hexval[(unsigned char)str[i]] < 0) {
      free(resbuf);
      return NULL;
    }
    if (hexval[(unsigned char)str[i + 1]] < 0) {
      free(resbuf);
      return NULL;
    }
    ((unsigned char *)resbuf + 1)[i / 2] =
        hexval[(unsigned char)str[i]] * 16 + hexval[(unsigned char)str[i + 1]];
  }
  return resbuf;
}


x86 assembly (clang, -O0):
<digest_hex2bin>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jge    1155 <digest_hex2bin+0x25>
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
je     1176 <digest_hex2bin+0x46>
movq   $0x0,-0x8(%rbp)
jmp    128c <digest_hex2bin+0x15c>
mov    -0x14(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,%edi
call   1050 <malloc_result@plt>
mov    %rax,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
mov    -0x24(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    1284 <digest_hex2bin+0x154>
mov    -0x10(%rbp),%rax
movslq -0x24(%rbp),%rcx
movzbl (%rax,%rcx,1),%eax
mov    %eax,%ecx
lea    0xe4c(%rip),%rax
movsbl (%rax,%rcx,1),%eax
cmp    $0x0,%eax
jge    11d7 <digest_hex2bin+0xa7>
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
movq   $0x0,-0x8(%rbp)
jmp    128c <digest_hex2bin+0x15c>
mov    -0x10(%rbp),%rax
mov    -0x24(%rbp),%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
movzbl (%rax,%rcx,1),%eax
mov    %eax,%ecx
lea    0xe0f(%rip),%rax
movsbl (%rax,%rcx,1),%eax
cmp    $0x0,%eax
jge    1214 <digest_hex2bin+0xe4>
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
movq   $0x0,-0x8(%rbp)
jmp    128c <digest_hex2bin+0x15c>
mov    -0x10(%rbp),%rax
movslq -0x24(%rbp),%rcx
movzbl (%rax,%rcx,1),%eax
mov    %eax,%ecx
lea    0xdd7(%rip),%rax
movsbl (%rax,%rcx,1),%eax
shl    $0x4,%eax
mov    -0x10(%rbp),%rcx
mov    -0x24(%rbp),%edx
add    $0x1,%edx
movslq %edx,%rdx
movzbl (%rcx,%rdx,1),%ecx
mov    %ecx,%edx
lea    0xdb6(%rip),%rcx
movsbl (%rcx,%rdx,1),%ecx
add    %ecx,%eax
mov    %al,-0x31(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x24(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    -0x31(%rbp),%dl
mov    %eax,%ecx
mov    -0x30(%rbp),%rax
movslq %ecx,%rcx
mov    %dl,0x1(%rax,%rcx,1)
mov    -0x24(%rbp),%eax
add    $0x2,%eax
mov    %eax,-0x24(%rbp)
jmp    1193 <digest_hex2bin+0x63>
mov    -0x20(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<digest_hex2bin>:
push   %rbp
push   %r14
push   %rbx
mov    %esi,%ebp
mov    %rdi,%r14
test   %esi,%esi
js     1145 <digest_hex2bin+0x15>
test   $0x1,%bpl
je     1155 <digest_hex2bin+0x25>
jmp    11b8 <digest_hex2bin+0x88>
mov    %r14,%rdi
call   1040 <strlen@plt>
mov    %eax,%ebp
test   $0x1,%bpl
jne    11b8 <digest_hex2bin+0x88>
mov    %ebp,%edi
shr    $0x1f,%edi
add    %ebp,%edi
sar    %edi
call   1050 <malloc_result@plt>
test   %ebp,%ebp
jle    11ba <digest_hex2bin+0x8a>
mov    %rax,%rdi
add    $0x1,%rdi
xor    %edx,%edx
lea    0xe89(%rip),%rsi
nopw   0x0(%rax,%rax,1)
movzbl (%r14,%rdx,1),%ecx
movzbl (%rcx,%rsi,1),%ebx
test   %bl,%bl
js     11b0 <digest_hex2bin+0x80>
movzbl 0x1(%r14,%rdx,1),%ecx
movzbl (%rcx,%rsi,1),%ecx
test   %cl,%cl
js     11b0 <digest_hex2bin+0x80>
shl    $0x4,%bl
add    %bl,%cl
mov    %cl,(%rdi)
add    $0x2,%rdx
add    $0x1,%rdi
cmp    %edx,%ebp
jg     1180 <digest_hex2bin+0x50>
jmp    11ba <digest_hex2bin+0x8a>
mov    %rax,%rdi
call   1030 <free@plt>
xor    %eax,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
%struct.digest_result = type { i32 }
@digest_hex2bin.hexval = internal constant [256 x i8] c"\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\00\01\02\03\04\05\06\07\08\09\FF\FF\FF\FF\FF\FF\FF\0A\0B\0C\0D\0E\0F\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\0A\0B\0C\0D\0E\0F\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF"
define %struct.digest_result* @digest_hex2bin(i8* %0, i32 %1) {
%3 = alloca %struct.digest_result*
%4 = alloca i8*
%5 = alloca i32
%6 = alloca %struct.digest_result*
%7 = alloca i32
store i8* %0, i8** %4
store i32 %1, i32* %5
%8 = load i32, i32* %5
%9 = icmp slt i32 %8, 0
br i1 %9, label %10, label %13
10: ; preds = %2
%11 = load i8*, i8** %4
%12 = call i32 @strlen(i8* %11)
store i32 %12, i32* %5
br label %13
13: ; preds = %10, %2
%14 = load i32, i32* %5
%15 = srem i32 %14, 2
%16 = icmp ne i32 %15, 0
br i1 %16, label %17, label %18
17: ; preds = %13
store %struct.digest_result* null, %struct.digest_result** %3
br label %90
18: ; preds = %13
%19 = load i32, i32* %5
%20 = sdiv i32 %19, 2
%21 = call %struct.digest_result* @malloc_result(i32 %20)
store %struct.digest_result* %21, %struct.digest_result** %6
store i32 0, i32* %7
br label %22
22: ; preds = %85, %18
%23 = load i32, i32* %7
%24 = load i32, i32* %5
%25 = icmp slt i32 %23, %24
br i1 %25, label %26, label %88
26: ; preds = %22
%27 = load i8*, i8** %4
%28 = load i32, i32* %7
%29 = sext i32 %28 to i64
%30 = getelementptr inbounds i8, i8* %27, i64 %29
%31 = load i8, i8* %30
%32 = zext i8 %31 to i64
%33 = getelementptr inbounds [256 x i8], [256 x i8]* @digest_hex2bin.hexval, i64 0, i64 %32
%34 = load i8, i8* %33
%35 = sext i8 %34 to i32
%36 = icmp slt i32 %35, 0
br i1 %36, label %37, label %40
37: ; preds = %26
%38 = load %struct.digest_result*, %struct.digest_result** %6
%39 = call i32 @free(%struct.digest_result* %38)
store %struct.digest_result* null, %struct.digest_result** %3
br label %90
40: ; preds = %26
%41 = load i8*, i8** %4
%42 = load i32, i32* %7
%43 = add nsw i32 %42, 1
%44 = sext i32 %43 to i64
%45 = getelementptr inbounds i8, i8* %41, i64 %44
%46 = load i8, i8* %45
%47 = zext i8 %46 to i64
%48 = getelementptr inbounds [256 x i8], [256 x i8]* @digest_hex2bin.hexval, i64 0, i64 %47
%49 = load i8, i8* %48
%50 = sext i8 %49 to i32
%51 = icmp slt i32 %50, 0
br i1 %51, label %52, label %55
52: ; preds = %40
%53 = load %struct.digest_result*, %struct.digest_result** %6
%54 = call i32 @free(%struct.digest_result* %53)
store %struct.digest_result* null, %struct.digest_result** %3
br label %90
55: ; preds = %40
%56 = load i8*, i8** %4
%57 = load i32, i32* %7
%58 = sext i32 %57 to i64
%59 = getelementptr inbounds i8, i8* %56, i64 %58
%60 = load i8, i8* %59
%61 = zext i8 %60 to i64
%62 = getelementptr inbounds [256 x i8], [256 x i8]* @digest_hex2bin.hexval, i64 0, i64 %61
%63 = load i8, i8* %62
%64 = sext i8 %63 to i32
%65 = mul nsw i32 %64, 16
%66 = load i8*, i8** %4
%67 = load i32, i32* %7
%68 = add nsw i32 %67, 1
%69 = sext i32 %68 to i64
%70 = getelementptr inbounds i8, i8* %66, i64 %69
%71 = load i8, i8* %70
%72 = zext i8 %71 to i64
%73 = getelementptr inbounds [256 x i8], [256 x i8]* @digest_hex2bin.hexval, i64 0, i64 %72
%74 = load i8, i8* %73
%75 = sext i8 %74 to i32
%76 = add nsw i32 %65, %75
%77 = trunc i32 %76 to i8
%78 = load %struct.digest_result*, %struct.digest_result** %6
%79 = bitcast %struct.digest_result* %78 to i8*
%80 = getelementptr inbounds i8, i8* %79, i64 1
%81 = load i32, i32* %7
%82 = sdiv i32 %81, 2
%83 = sext i32 %82 to i64
%84 = getelementptr inbounds i8, i8* %80, i64 %83
store i8 %77, i8* %84
br label %85
85: ; preds = %55
%86 = load i32, i32* %7
%87 = add nsw i32 %86, 2
store i32 %87, i32* %7
br label %22
88: ; preds = %22
%89 = load %struct.digest_result*, %struct.digest_result** %6
store %struct.digest_result* %89, %struct.digest_result** %3
br label %90
90: ; preds = %88, %52, %37, %17
%91 = load %struct.digest_result*, %struct.digest_result** %3
ret %struct.digest_result* %91
}

LLVM IR (-O2):
%struct.digest_result = type { i32 }
@digest_hex2bin.hexval = internal unnamed_addr constant [256 x i8] c"\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\00\01\02\03\04\05\06\07\08\09\FF\FF\FF\FF\FF\FF\FF\0A\0B\0C\0D\0E\0F\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\0A\0B\0C\0D\0E\0F\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF"
define %struct.digest_result* @digest_hex2bin(i8* %0, i32 %1) {
%3 = icmp slt i32 %1, 0
br i1 %3, label %4, label %6
4: ; preds = %2
%5 = tail call i32 @strlen(i8* %0)
br label %6
6: ; preds = %4, %2
%7 = phi i32 [ %5, %4 ], [ %1, %2 ]
%8 = and i32 %7, 1
%9 = icmp eq i32 %8, 0
br i1 %9, label %10, label %43
10: ; preds = %6
%11 = sdiv i32 %7, 2
%12 = tail call %struct.digest_result* @malloc_result(i32 %11)
%13 = icmp sgt i32 %7, 0
br i1 %13, label %14, label %43
14: ; preds = %10
%15 = bitcast %struct.digest_result* %12 to i8*
%16 = getelementptr inbounds i8, i8* %15, i64 1
br label %17
17: ; preds = %14, %33
%18 = phi i64 [ 0, %14 ], [ %38, %33 ]
%19 = getelementptr inbounds i8, i8* %0, i64 %18
%20 = load i8, i8* %19
%21 = zext i8 %20 to i64
%22 = getelementptr inbounds [256 x i8], [256 x i8]* @digest_hex2bin.hexval, i64 0, i64 %21
%23 = load i8, i8* %22
%24 = icmp slt i8 %23, 0
br i1 %24, label %41, label %25
25: ; preds = %17
%26 = or i64 %18, 1
%27 = getelementptr inbounds i8, i8* %0, i64 %26
%28 = load i8, i8* %27
%29 = zext i8 %28 to i64
%30 = getelementptr inbounds [256 x i8], [256 x i8]* @digest_hex2bin.hexval, i64 0, i64 %29
%31 = load i8, i8* %30
%32 = icmp slt i8 %31, 0
br i1 %32, label %41, label %33
33: ; preds = %25
%34 = shl i8 %23, 4
%35 = add i8 %31, %34
%36 = lshr exact i64 %18, 1
%37 = getelementptr inbounds i8, i8* %16, i64 %36
store i8 %35, i8* %37
%38 = add nuw i64 %18, 2
%39 = trunc i64 %38 to i32
%40 = icmp sgt i32 %7, %39
br i1 %40, label %17, label %43
41: ; preds = %25, %17
%42 = tail call i32 @free(%struct.digest_result* %12)
br label %43
43: ; preds = %33, %41, %10, %6
%44 = phi %struct.digest_result* [ null, %6 ], [ %12, %10 ], [ null, %41 ], [ %12, %33 ]
ret %struct.digest_result* %44
}