#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 */
int lower(char);
int htoi(char c) {
  int hexmap[16] = {'0', '1', '2', '3', '4', '5', '6', '7',
                    '8', '9', 'a', 'b', 'c', 'd', 'e', 'f'};
  int e;
  for (e = 0; lower(c) != hexmap[e] && e < 16; ++e)
    ;
  return e;
}


x86 assembly (clang, -O0):
<htoi>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %dil,%al
mov    %al,-0x1(%rbp)
lea    -0x50(%rbp),%rdi
lea    0xec7(%rip),%rsi
mov    $0x40,%edx
call   1030 <memcpy@plt>
movl   $0x0,-0x54(%rbp)
movsbl -0x1(%rbp),%edi
call   1040 <lower@plt>
mov    %eax,%ecx
movslq -0x54(%rbp),%rdx
xor    %eax,%eax
cmp    -0x50(%rbp,%rdx,4),%ecx
mov    %al,-0x55(%rbp)
je     1172 <htoi+0x52>
cmpl   $0x10,-0x54(%rbp)
setl   %al
mov    %al,-0x55(%rbp)
mov    -0x55(%rbp),%al
test   $0x1,%al
jne    1182 <htoi+0x62>
jmp    1195 <htoi+0x75>
jmp    1187 <htoi+0x67>
mov    -0x54(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x54(%rbp)
jmp    114a <htoi+0x2a>
mov    -0x54(%rbp),%eax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<htoi>:
push   %rbp
push   %r14
push   %rbx
lea    0xee5(%rip),%rbx
xor    %ebp,%ebp
movsbl %dil,%r14d
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    %r14d,%edi
call   1030 <lower@plt>
mov    %eax,%ecx
lea    0x1(%rbp),%rax
cmp    (%rbx),%ecx
je     114f <htoi+0x3f>
add    $0x4,%rbx
cmp    $0x10,%rbp
mov    %rax,%rbp
jb     1130 <htoi+0x20>
add    $0xffffffff,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@__const.htoi.hexmap = [16 x i32] [i32 48, i32 49, i32 50, i32 51, i32 52, i32 53, i32 54, i32 55, i32 56, i32 57, i32 97, i32 98, i32 99, i32 100, i32 101, i32 102]
define i32 @htoi(i8 signext %0) {
%2 = alloca i8
%3 = alloca [16 x i32]
%4 = alloca i32
store i8 %0, i8* %2
%5 = bitcast [16 x i32]* %3 to i8*
store i32 0, i32* %4
br label %6
6: ; preds = %20, %1
%7 = load i8, i8* %2
%8 = call i32 @lower(i8 signext %7)
%9 = load i32, i32* %4
%10 = sext i32 %9 to i64
%11 = getelementptr inbounds [16 x i32], [16 x i32]* %3, i64 0, i64 %10
%12 = load i32, i32* %11
%13 = icmp ne i32 %8, %12
br i1 %13, label %14, label %17
14: ; preds = %6
%15 = load i32, i32* %4
%16 = icmp slt i32 %15, 16
br label %17
17: ; preds = %14, %6
%18 = phi i1 [ false, %6 ], [ %16, %14 ]
br i1 %18, label %19, label %23
19: ; preds = %17
br label %20
20: ; preds = %19
%21 = load i32, i32* %4
%22 = add nsw i32 %21, 1
store i32 %22, i32* %4
br label %6
23: ; preds = %17
%24 = load i32, i32* %4
ret i32 %24
}

LLVM IR (-O2):
@__const.htoi.hexmap = [16 x i32] [i32 48, i32 49, i32 50, i32 51, i32 52, i32 53, i32 54, i32 55, i32 56, i32 57, i32 97, i32 98, i32 99, i32 100, i32 101, i32 102]
define i32 @htoi(i8 signext %0) {
br label %2
2: ; preds = %2, %1
%3 = phi i64 [ %10, %2 ], [ 0, %1 ]
%4 = tail call i32 @lower(i8 signext %0)
%5 = getelementptr inbounds [16 x i32], [16 x i32]* @__const.htoi.hexmap, i64 0, i64 %3
%6 = load i32, i32* %5
%7 = icmp ne i32 %4, %6
%8 = icmp ult i64 %3, 16
%9 = select i1 %7, i1 %8, i1 false
%10 = add nuw nsw i64 %3, 1
br i1 %9, label %2, label %11
11: ; preds = %2
%12 = trunc i64 %3 to i32
ret i32 %12
}