#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);
int htoi(char ch) {
  ch = toupper(ch);
  if (ch < '0')
    return (0);
  else if (ch <= '9')
    return ((int)(ch - '0'));
  else if (ch < 'A')
    return (0);
  else if (ch <= 'F')
    return ((int)(ch - 'A' + 10));
  return (0);
}


x86 assembly (clang, -O0):
<htoi>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %dil,%al
mov    %al,-0x5(%rbp)
movsbl -0x5(%rbp),%edi
call   1030 <toupper@plt>
mov    %al,-0x5(%rbp)
movsbl -0x5(%rbp),%eax
cmp    $0x30,%eax
jge    1143 <htoi+0x33>
movl   $0x0,-0x4(%rbp)
jmp    11ad <htoi+0x9d>
movsbl -0x5(%rbp),%eax
cmp    $0x39,%eax
jg     115f <htoi+0x4f>
movsbl -0x5(%rbp),%eax
sub    $0x30,%eax
mov    %eax,-0x4(%rbp)
jmp    11ad <htoi+0x9d>
movsbl -0x5(%rbp),%eax
cmp    $0x41,%eax
jge    1178 <htoi+0x68>
movl   $0x0,-0x4(%rbp)
jmp    11ad <htoi+0x9d>
movsbl -0x5(%rbp),%eax
cmp    $0x46,%eax
jg     1197 <htoi+0x87>
movsbl -0x5(%rbp),%eax
sub    $0x41,%eax
add    $0xa,%eax
mov    %eax,-0x4(%rbp)
jmp    11ad <htoi+0x9d>
jmp    119c <htoi+0x8c>
jmp    11a1 <htoi+0x91>
jmp    11a6 <htoi+0x96>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<htoi>:
push   %rax
call   1030 <toupper@plt>
mov    %eax,%ecx
xor    %eax,%eax
cmp    $0x30,%cl
jl     113a <htoi+0x2a>
movsbl %cl,%eax
cmp    $0x39,%cl
ja     112c <htoi+0x1c>
add    $0xffffffd0,%eax
pop    %rcx
ret
add    $0xbf,%cl
add    $0xffffffc9,%eax
xor    %edx,%edx
cmp    $0x6,%cl
cmovae %edx,%eax
pop    %rcx
ret

LLVM IR (-O0):
define i32 @htoi(i8 signext %0) {
%2 = alloca i32
%3 = alloca i8
store i8 %0, i8* %3
%4 = load i8, i8* %3
%5 = call signext i8 @toupper(i8 signext %4)
store i8 %5, i8* %3
%6 = load i8, i8* %3
%7 = sext i8 %6 to i32
%8 = icmp slt i32 %7, 48
br i1 %8, label %9, label %10
9: ; preds = %1
store i32 0, i32* %2
br label %36
10: ; preds = %1
%11 = load i8, i8* %3
%12 = sext i8 %11 to i32
%13 = icmp sle i32 %12, 57
br i1 %13, label %14, label %18
14: ; preds = %10
%15 = load i8, i8* %3
%16 = sext i8 %15 to i32
%17 = sub nsw i32 %16, 48
store i32 %17, i32* %2
br label %36
18: ; preds = %10
%19 = load i8, i8* %3
%20 = sext i8 %19 to i32
%21 = icmp slt i32 %20, 65
br i1 %21, label %22, label %23
22: ; preds = %18
store i32 0, i32* %2
br label %36
23: ; preds = %18
%24 = load i8, i8* %3
%25 = sext i8 %24 to i32
%26 = icmp sle i32 %25, 70
br i1 %26, label %27, label %32
27: ; preds = %23
%28 = load i8, i8* %3
%29 = sext i8 %28 to i32
%30 = sub nsw i32 %29, 65
%31 = add nsw i32 %30, 10
store i32 %31, i32* %2
br label %36
32: ; preds = %23
br label %33
33: ; preds = %32
br label %34
34: ; preds = %33
br label %35
35: ; preds = %34
store i32 0, i32* %2
br label %36
36: ; preds = %35, %27, %22, %14, %9
%37 = load i32, i32* %2
ret i32 %37
}

LLVM IR (-O2):
define i32 @htoi(i8 signext %0) {
%2 = tail call signext i8 @toupper(i8 signext %0)
%3 = sext i8 %2 to i32
%4 = icmp slt i8 %2, 48
br i1 %4, label %14, label %5
5: ; preds = %1
%6 = icmp ult i8 %2, 58
br i1 %6, label %7, label %9
7: ; preds = %5
%8 = add nsw i32 %3, -48
br label %14
9: ; preds = %5
%10 = add nsw i8 %2, -65
%11 = icmp ult i8 %10, 6
%12 = add nsw i32 %3, -55
%13 = select i1 %11, i32 %12, i32 0
br label %14
14: ; preds = %9, %1, %7
%15 = phi i32 [ %8, %7 ], [ 0, %1 ], [ %13, %9 ]
ret i32 %15
}