#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 */

/* Variables and functions */
scalar_t__ isdigit(unsigned char);
char toupper(char);
int hextochr(char *str) {
  return ((isdigit((unsigned char)(str[0])) ? str[0] - '0'
                                            : toupper(str[0]) - 'A' + 10)
          << 4) +
         (isdigit((unsigned char)(str[1])) ? str[1] - '0'
                                           : toupper(str[1]) - 'A' + 10);
}


x86 assembly (clang, -O0):
<hextochr>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rax
movzbl (%rax),%edi
call   1030 <isdigit@plt>
cmp    $0x0,%rax
je     1154 <hextochr+0x34>
mov    -0x8(%rbp),%rax
movsbl (%rax),%eax
sub    $0x30,%eax
mov    %eax,-0xc(%rbp)
jmp    116c <hextochr+0x4c>
mov    -0x8(%rbp),%rax
movsbl (%rax),%edi
call   1040 <toupper@plt>
movsbl %al,%eax
sub    $0x41,%eax
add    $0xa,%eax
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%eax
shl    $0x4,%eax
mov    %eax,-0x10(%rbp)
mov    -0x8(%rbp),%rax
movzbl 0x1(%rax),%edi
call   1030 <isdigit@plt>
cmp    $0x0,%rax
je     119f <hextochr+0x7f>
mov    -0x8(%rbp),%rax
movsbl 0x1(%rax),%eax
sub    $0x30,%eax
mov    %eax,-0x14(%rbp)
jmp    11b8 <hextochr+0x98>
mov    -0x8(%rbp),%rax
movsbl 0x1(%rax),%edi
call   1040 <toupper@plt>
movsbl %al,%eax
sub    $0x41,%eax
add    $0xa,%eax
mov    %eax,-0x14(%rbp)
mov    -0x10(%rbp),%eax
mov    -0x14(%rbp),%ecx
add    %ecx,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<hextochr>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rdi,%rbp
movzbl (%rdi),%edi
call   1030 <isdigit@plt>
mov    0x0(%rbp),%r14b
mov    $0xffffffd0,%r15d
test   %rax,%rax
je     1148 <hextochr+0x28>
mov    $0xffffffd0,%ebx
jmp    1159 <hextochr+0x39>
movsbl %r14b,%edi
call   1040 <toupper@plt>
mov    %eax,%r14d
mov    $0xffffffc9,%ebx
movzbl 0x1(%rbp),%edi
call   1030 <isdigit@plt>
mov    %rax,%rcx
mov    0x1(%rbp),%al
test   %rcx,%rcx
jne    117b <hextochr+0x5b>
movsbl %al,%edi
call   1040 <toupper@plt>
mov    $0xffffffc9,%r15d
movsbl %r14b,%ecx
add    %ecx,%ebx
movsbl %al,%eax
add    %r15d,%eax
shl    $0x4,%ebx
add    %eax,%ebx
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @hextochr(i8* %0) {
%2 = alloca i8*
store i8* %0, i8** %2
%3 = load i8*, i8** %2
%4 = getelementptr inbounds i8, i8* %3, i64 0
%5 = load i8, i8* %4
%6 = call i64 @isdigit(i8 zeroext %5)
%7 = icmp ne i64 %6, 0
br i1 %7, label %8, label %14
8: ; preds = %1
%9 = load i8*, i8** %2
%10 = getelementptr inbounds i8, i8* %9, i64 0
%11 = load i8, i8* %10
%12 = sext i8 %11 to i32
%13 = sub nsw i32 %12, 48
br label %22
14: ; preds = %1
%15 = load i8*, i8** %2
%16 = getelementptr inbounds i8, i8* %15, i64 0
%17 = load i8, i8* %16
%18 = call signext i8 @toupper(i8 signext %17)
%19 = sext i8 %18 to i32
%20 = sub nsw i32 %19, 65
%21 = add nsw i32 %20, 10
br label %22
22: ; preds = %14, %8
%23 = phi i32 [ %13, %8 ], [ %21, %14 ]
%24 = shl i32 %23, 4
%25 = load i8*, i8** %2
%26 = getelementptr inbounds i8, i8* %25, i64 1
%27 = load i8, i8* %26
%28 = call i64 @isdigit(i8 zeroext %27)
%29 = icmp ne i64 %28, 0
br i1 %29, label %30, label %36
30: ; preds = %22
%31 = load i8*, i8** %2
%32 = getelementptr inbounds i8, i8* %31, i64 1
%33 = load i8, i8* %32
%34 = sext i8 %33 to i32
%35 = sub nsw i32 %34, 48
br label %44
36: ; preds = %22
%37 = load i8*, i8** %2
%38 = getelementptr inbounds i8, i8* %37, i64 1
%39 = load i8, i8* %38
%40 = call signext i8 @toupper(i8 signext %39)
%41 = sext i8 %40 to i32
%42 = sub nsw i32 %41, 65
%43 = add nsw i32 %42, 10
br label %44
44: ; preds = %36, %30
%45 = phi i32 [ %35, %30 ], [ %43, %36 ]
%46 = add nsw i32 %24, %45
ret i32 %46
}

LLVM IR (-O2):
define i32 @hextochr(i8* nocapture %0) {
%2 = load i8, i8* %0
%3 = tail call i64 @isdigit(i8 zeroext %2)
%4 = icmp eq i64 %3, 0
%5 = load i8, i8* %0
br i1 %4, label %6, label %8
6: ; preds = %1
%7 = tail call signext i8 @toupper(i8 signext %5)
br label %8
8: ; preds = %1, %6
%9 = phi i8 [ %7, %6 ], [ %5, %1 ]
%10 = phi i32 [ -55, %6 ], [ -48, %1 ]
%11 = getelementptr inbounds i8, i8* %0, i64 1
%12 = load i8, i8* %11
%13 = tail call i64 @isdigit(i8 zeroext %12)
%14 = icmp eq i64 %13, 0
%15 = load i8, i8* %11
br i1 %14, label %16, label %18
16: ; preds = %8
%17 = tail call signext i8 @toupper(i8 signext %15)
br label %18
18: ; preds = %8, %16
%19 = phi i8 [ %17, %16 ], [ %15, %8 ]
%20 = phi i32 [ -55, %16 ], [ -48, %8 ]
%21 = sext i8 %9 to i32
%22 = add nsw i32 %10, %21
%23 = sext i8 %19 to i32
%24 = add nsw i32 %20, %23
%25 = shl nsw i32 %22, 4
%26 = add nsw i32 %24, %25
ret i32 %26
}