#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 */
char toupper(char const);
unsigned char stmHexToChar(const char *hex) {
  char hex1, hex2;
  unsigned char nibble1, nibble2;
  hex1 = toupper(hex[0]);
  hex2 = toupper(hex[1]);
  if (hex1 < 65)
    nibble1 = hex1 - 48;
  else
    nibble1 = hex1 - 55;
  if (hex2 < 65)
    nibble2 = hex2 - 48;
  else
    nibble2 = hex2 - 55;
  return (nibble1 << 4 | nibble2);
}


x86 assembly (clang, -O0):
<stmHexToChar>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rax
movsbl (%rax),%edi
call   1030 <toupper@plt>
mov    %al,-0x9(%rbp)
mov    -0x8(%rbp),%rax
movsbl 0x1(%rax),%edi
call   1030 <toupper@plt>
mov    %al,-0xa(%rbp)
movsbl -0x9(%rbp),%eax
cmp    $0x41,%eax
jge    1157 <stmHexToChar+0x47>
movsbl -0x9(%rbp),%eax
sub    $0x30,%eax
mov    %al,-0xb(%rbp)
jmp    1161 <stmHexToChar+0x51>
movsbl -0x9(%rbp),%eax
sub    $0x37,%eax
mov    %al,-0xb(%rbp)
movsbl -0xa(%rbp),%eax
cmp    $0x41,%eax
jge    117d <stmHexToChar+0x6d>
movsbl -0xa(%rbp),%eax
sub    $0x30,%eax
mov    %al,-0xc(%rbp)
jmp    1187 <stmHexToChar+0x77>
movsbl -0xa(%rbp),%eax
sub    $0x37,%eax
mov    %al,-0xc(%rbp)
movzbl -0xb(%rbp),%eax
shl    $0x4,%eax
movzbl -0xc(%rbp),%ecx
or     %ecx,%eax
movzbl %al,%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<stmHexToChar>:
push   %rbp
push   %rbx
push   %rax
mov    %rdi,%rbx
movsbl (%rdi),%edi
call   1030 <toupper@plt>
mov    %eax,%ebp
movsbl 0x1(%rbx),%edi
call   1030 <toupper@plt>
xor    %ecx,%ecx
cmp    $0x41,%bpl
setge  %cl
lea    (%rcx,%rcx,8),%ecx
add    %bpl,%cl
cmp    $0x41,%al
mov    $0xd0,%edx
mov    $0xc9,%esi
cmovl  %edx,%esi
add    %sil,%al
shl    $0x4,%cl
or     %cl,%al
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

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

LLVM IR (-O2):
define zeroext i8 @stmHexToChar(i8* nocapture %0) {
%2 = load i8, i8* %0
%3 = tail call signext i8 @toupper(i8 signext %2)
%4 = getelementptr inbounds i8, i8* %0, i64 1
%5 = load i8, i8* %4
%6 = tail call signext i8 @toupper(i8 signext %5)
%7 = icmp slt i8 %3, 65
%8 = select i1 %7, i8 0, i8 9
%9 = add i8 %8, %3
%10 = icmp slt i8 %6, 65
%11 = select i1 %10, i8 -48, i8 -55
%12 = add i8 %11, %6
%13 = shl i8 %9, 4
%14 = or i8 %12, %13
ret i8 %14
}