#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 */
typedef int uint8_t;

/* Variables and functions */
int /*<<< orphan*/ printf(char *, int);
uint8_t hex2int(uint8_t hVal) {
  if (hVal < '0')
    printf("hval wrong: %u\n", hVal);
  if (hVal - '0' < 10)
    return hVal - '0';
  if (hVal - 'A' < 6)
    return hVal - 'A' + 10;
  if (hVal - 'a' < 6)
    return hVal - 'a' + 10;
  return 16;
}


x86 assembly (clang, -O0):
<hex2int>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x8(%rbp)
cmpl   $0x30,-0x8(%rbp)
jge    1134 <hex2int+0x24>
mov    -0x8(%rbp),%esi
lea    0xed1(%rip),%rdi
call   1030 <printf@plt>
mov    -0x8(%rbp),%eax
sub    $0x30,%eax
cmp    $0xa,%eax
jge    1151 <hex2int+0x41>
mov    -0x8(%rbp),%eax
sub    $0x30,%eax
mov    %eax,-0x4(%rbp)
jmp    1198 <hex2int+0x88>
mov    -0x8(%rbp),%eax
sub    $0x41,%eax
cmp    $0x6,%eax
jge    1171 <hex2int+0x61>
mov    -0x8(%rbp),%eax
sub    $0x41,%eax
add    $0xa,%eax
mov    %eax,-0x4(%rbp)
jmp    1198 <hex2int+0x88>
mov    -0x8(%rbp),%eax
sub    $0x61,%eax
cmp    $0x6,%eax
jge    1191 <hex2int+0x81>
mov    -0x8(%rbp),%eax
sub    $0x61,%eax
add    $0xa,%eax
mov    %eax,-0x4(%rbp)
jmp    1198 <hex2int+0x88>
movl   $0x10,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<hex2int>:
push   %rbx
mov    %edi,%ebx
cmp    $0x2f,%edi
jg     112b <hex2int+0x1b>
lea    0xee1(%rip),%rdi
mov    %ebx,%esi
call   1030 <printf@plt>
add    $0xffffffd0,%ebx
jmp    114d <hex2int+0x3d>
cmp    $0x39,%ebx
ja     1135 <hex2int+0x25>
add    $0xffffffd0,%ebx
jmp    114d <hex2int+0x3d>
cmp    $0x46,%ebx
ja     113f <hex2int+0x2f>
add    $0xffffffc9,%ebx
jmp    114d <hex2int+0x3d>
lea    -0x57(%rbx),%eax
cmp    $0x67,%ebx
mov    $0x10,%ebx
cmovb  %eax,%ebx
mov    %ebx,%eax
pop    %rbx
ret

LLVM IR (-O0):
@.str = [16 x i8] c"hval wrong: %u\0A\00"
define i32 @hex2int(i32 %0) {
%2 = alloca i32
%3 = alloca i32
store i32 %0, i32* %3
%4 = load i32, i32* %3
%5 = icmp slt i32 %4, 48
br i1 %5, label %6, label %9
6: ; preds = %1
%7 = load i32, i32* %3
%8 = call i32 @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i32 %7)
br label %9
9: ; preds = %6, %1
%10 = load i32, i32* %3
%11 = sub nsw i32 %10, 48
%12 = icmp slt i32 %11, 10
br i1 %12, label %13, label %16
13: ; preds = %9
%14 = load i32, i32* %3
%15 = sub nsw i32 %14, 48
store i32 %15, i32* %2
br label %33
16: ; preds = %9
%17 = load i32, i32* %3
%18 = sub nsw i32 %17, 65
%19 = icmp slt i32 %18, 6
br i1 %19, label %20, label %24
20: ; preds = %16
%21 = load i32, i32* %3
%22 = sub nsw i32 %21, 65
%23 = add nsw i32 %22, 10
store i32 %23, i32* %2
br label %33
24: ; preds = %16
%25 = load i32, i32* %3
%26 = sub nsw i32 %25, 97
%27 = icmp slt i32 %26, 6
br i1 %27, label %28, label %32
28: ; preds = %24
%29 = load i32, i32* %3
%30 = sub nsw i32 %29, 97
%31 = add nsw i32 %30, 10
store i32 %31, i32* %2
br label %33
32: ; preds = %24
store i32 16, i32* %2
br label %33
33: ; preds = %32, %28, %20, %13
%34 = load i32, i32* %2
ret i32 %34
}

LLVM IR (-O2):
@.str = [16 x i8] c"hval wrong: %u\0A\00"
define i32 @hex2int(i32 %0) {
%2 = icmp slt i32 %0, 48
br i1 %2, label %3, label %5
3: ; preds = %1
%4 = tail call i32 @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i32 %0)
br label %7
5: ; preds = %1
%6 = icmp ult i32 %0, 58
br i1 %6, label %7, label %9
7: ; preds = %3, %5
%8 = add nsw i32 %0, -48
br label %17
9: ; preds = %5
%10 = icmp ult i32 %0, 71
br i1 %10, label %11, label %13
11: ; preds = %9
%12 = add nsw i32 %0, -55
br label %17
13: ; preds = %9
%14 = icmp ult i32 %0, 103
%15 = add nsw i32 %0, -87
%16 = select i1 %14, i32 %15, i32 16
br label %17
17: ; preds = %13, %11, %7
%18 = phi i32 [ %8, %7 ], [ %12, %11 ], [ %16, %13 ]
ret i32 %18
}