#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__ hex(char);
int htoi(char *hnbr) {
  unsigned int n = 0;
  while (hex(*hnbr)) {
    n *= 16;
    n += *hnbr <= '9' ? *hnbr - '0' : *hnbr - 'A' + 10;
    hnbr++;
  }
  return n;
}


x86 assembly (clang, -O0):
<htoi>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
mov    -0x8(%rbp),%rax
movsbl (%rax),%edi
call   1030 <hex@plt>
cmp    $0x0,%rax
je     118e <htoi+0x7e>
mov    -0xc(%rbp),%eax
shl    $0x4,%eax
mov    %eax,-0xc(%rbp)
mov    -0x8(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x39,%eax
jg     1164 <htoi+0x54>
mov    -0x8(%rbp),%rax
movsbl (%rax),%eax
sub    $0x30,%eax
mov    %eax,-0x10(%rbp)
jmp    1174 <htoi+0x64>
mov    -0x8(%rbp),%rax
movsbl (%rax),%eax
sub    $0x41,%eax
add    $0xa,%eax
mov    %eax,-0x10(%rbp)
mov    -0x10(%rbp),%eax
add    -0xc(%rbp),%eax
mov    %eax,-0xc(%rbp)
mov    -0x8(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x8(%rbp)
jmp    1123 <htoi+0x13>
mov    -0xc(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<htoi>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%r14
movsbl (%rdi),%edi
call   1030 <hex@plt>
test   %rax,%rax
je     115a <htoi+0x4a>
add    $0x1,%r14
xor    %ebx,%ebx
nopw   0x0(%rax,%rax,1)
shl    $0x4,%ebx
movsbl -0x1(%r14),%eax
cmp    $0x3a,%eax
lea    -0x30(%rbx,%rax,1),%ecx
lea    -0x37(%rbx,%rax,1),%ebx
cmovl  %ecx,%ebx
movsbl (%r14),%edi
call   1030 <hex@plt>
add    $0x1,%r14
test   %rax,%rax
jne    1130 <htoi+0x20>
jmp    115c <htoi+0x4c>
xor    %ebx,%ebx
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

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

LLVM IR (-O2):
define i32 @htoi(i8* nocapture %0) {
%2 = load i8, i8* %0
%3 = tail call i64 @hex(i8 signext %2)
%4 = icmp eq i64 %3, 0
br i1 %4, label %19, label %5
5: ; preds = %1, %5
%6 = phi i32 [ %14, %5 ], [ 0, %1 ]
%7 = phi i8* [ %15, %5 ], [ %0, %1 ]
%8 = shl i32 %6, 4
%9 = load i8, i8* %7
%10 = sext i8 %9 to i32
%11 = icmp slt i8 %9, 58
%12 = select i1 %11, i32 -48, i32 -55
%13 = add i32 %8, %10
%14 = add i32 %13, %12
%15 = getelementptr inbounds i8, i8* %7, i64 1
%16 = load i8, i8* %15
%17 = tail call i64 @hex(i8 signext %16)
%18 = icmp eq i64 %17, 0
br i1 %18, label %19, label %5
19: ; preds = %5, %1
%20 = phi i32 [ 0, %1 ], [ %14, %5 ]
ret i32 %20
}