#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 tolower(int /*<<< orphan*/);
int h2toi(char *s) {
  int tmp;
  int ch;
  tmp = tolower(*s++);
  if (tmp > '9')
    tmp -= ('a' - 10);
  else
    tmp -= '0';
  ch = 16 * tmp;
  tmp = tolower(*s++);
  if (tmp > '9')
    tmp -= ('a' - 10);
  else
    tmp -= '0';
  ch += tmp;
  return ch;
}


x86 assembly (clang, -O0):
<h2toi>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x8(%rbp)
movsbl (%rax),%edi
call   1030 <tolower@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0x39,-0xc(%rbp)
jle    114e <h2toi+0x3e>
mov    -0xc(%rbp),%eax
sub    $0x57,%eax
mov    %eax,-0xc(%rbp)
jmp    1157 <h2toi+0x47>
mov    -0xc(%rbp),%eax
sub    $0x30,%eax
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%eax
shl    $0x4,%eax
mov    %eax,-0x10(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x8(%rbp)
movsbl (%rax),%edi
call   1030 <tolower@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0x39,-0xc(%rbp)
jle    1192 <h2toi+0x82>
mov    -0xc(%rbp),%eax
sub    $0x57,%eax
mov    %eax,-0xc(%rbp)
jmp    119b <h2toi+0x8b>
mov    -0xc(%rbp),%eax
sub    $0x30,%eax
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%eax
add    -0x10(%rbp),%eax
mov    %eax,-0x10(%rbp)
mov    -0x10(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<h2toi>:
push   %rbp
push   %rbx
push   %rax
mov    %rdi,%rbx
movsbl (%rdi),%edi
call   1030 <tolower@plt>
lea    -0x30(%rax),%ecx
lea    -0x57(%rax),%ebp
cmp    $0x3a,%eax
cmovl  %ecx,%ebp
movsbl 0x1(%rbx),%edi
call   1030 <tolower@plt>
lea    -0x30(%rax),%ecx
lea    -0x57(%rax),%edx
cmp    $0x3a,%eax
cmovl  %ecx,%edx
shl    $0x4,%ebp
add    %edx,%ebp
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

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

LLVM IR (-O2):
define i32 @h2toi(i8* nocapture %0) {
%2 = getelementptr inbounds i8, i8* %0, i64 1
%3 = load i8, i8* %0
%4 = sext i8 %3 to i32
%5 = tail call i32 @tolower(i32 %4)
%6 = icmp sgt i32 %5, 57
%7 = select i1 %6, i32 -87, i32 -48
%8 = add nsw i32 %7, %5
%9 = load i8, i8* %2
%10 = sext i8 %9 to i32
%11 = tail call i32 @tolower(i32 %10)
%12 = icmp sgt i32 %11, 57
%13 = select i1 %12, i32 -87, i32 -48
%14 = add nsw i32 %13, %11
%15 = shl nsw i32 %8, 4
%16 = add nsw i32 %14, %15
ret i32 %16
}