#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 fb_hStrRadix2Int(char *, int, int);
char *fb_hStrSkipChar(char *, int, int);
int strtoul(char *, int /*<<< orphan*/, int);
int fb_hStr2Int(char *src, int len) {
  char *p;
  int radix;
  int skip;
  p = fb_hStrSkipChar(src, len, 32);
  len -= (int)(p - src);
  if (len < 1)
    return 0;
  else if ((len >= 2) && (p[0] == '&')) {
    radix = 0;
    skip = 2;
    switch (p[1]) {
    case 'h':
    case 'H':
      radix = 16;
      break;
    case 'o':
    case 'O':
      radix = 8;
      break;
    case 'b':
    case 'B':
      radix = 2;
      break;
    default:
      radix = 8;
      skip = 1;
      break;
    }
    if (radix != 0)
      return fb_hStrRadix2Int(&p[skip], len - skip, radix);
  }
  return strtoul(p, 0, 10);
}


x86 assembly (clang, -O0):
<fb_hStr2Int>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
mov    $0x20,%edx
call   1040 <fb_hStrSkipChar@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
mov    -0x10(%rbp),%rcx
sub    %rcx,%rax
mov    %eax,%ecx
mov    -0x14(%rbp),%eax
sub    %ecx,%eax
mov    %eax,-0x14(%rbp)
cmpl   $0x1,-0x14(%rbp)
jge    117f <fb_hStr2Int+0x4f>
movl   $0x0,-0x4(%rbp)
jmp    128f <fb_hStr2Int+0x15f>
cmpl   $0x2,-0x14(%rbp)
jl     1277 <fb_hStr2Int+0x147>
mov    -0x20(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x26,%eax
jne    1277 <fb_hStr2Int+0x147>
movl   $0x0,-0x24(%rbp)
movl   $0x2,-0x28(%rbp)
mov    -0x20(%rbp),%rax
movsbl 0x1(%rax),%eax
mov    %eax,-0x2c(%rbp)
sub    $0x42,%eax
je     122d <fb_hStr2Int+0xfd>
jmp    11c0 <fb_hStr2Int+0x90>
mov    -0x2c(%rbp),%eax
sub    $0x48,%eax
je     1215 <fb_hStr2Int+0xe5>
jmp    11d1 <fb_hStr2Int+0xa1>
mov    -0x2c(%rbp),%eax
sub    $0x4f,%eax
je     1221 <fb_hStr2Int+0xf1>
jmp    11e2 <fb_hStr2Int+0xb2>
mov    -0x2c(%rbp),%eax
sub    $0x62,%eax
je     122d <fb_hStr2Int+0xfd>
jmp    11f3 <fb_hStr2Int+0xc3>
mov    -0x2c(%rbp),%eax
sub    $0x68,%eax
je     1215 <fb_hStr2Int+0xe5>
jmp    1204 <fb_hStr2Int+0xd4>
mov    -0x2c(%rbp),%eax
sub    $0x6f,%eax
je     1221 <fb_hStr2Int+0xf1>
jmp    1239 <fb_hStr2Int+0x109>
movl   $0x10,-0x24(%rbp)
jmp    1247 <fb_hStr2Int+0x117>
movl   $0x8,-0x24(%rbp)
jmp    1247 <fb_hStr2Int+0x117>
movl   $0x2,-0x24(%rbp)
jmp    1247 <fb_hStr2Int+0x117>
movl   $0x8,-0x24(%rbp)
movl   $0x1,-0x28(%rbp)
cmpl   $0x0,-0x24(%rbp)
je     1272 <fb_hStr2Int+0x142>
mov    -0x20(%rbp),%rdi
movslq -0x28(%rbp),%rax
add    %rax,%rdi
mov    -0x14(%rbp),%esi
sub    -0x28(%rbp),%esi
mov    -0x24(%rbp),%edx
call   1030 <fb_hStrRadix2Int@plt>
mov    %eax,-0x4(%rbp)
jmp    128f <fb_hStr2Int+0x15f>
jmp    1277 <fb_hStr2Int+0x147>
jmp    127c <fb_hStr2Int+0x14c>
mov    -0x20(%rbp),%rdi
xor    %esi,%esi
mov    $0xa,%edx
call   1050 <strtoul@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<fb_hStr2Int>:
push   %rbp
push   %rbx
push   %rax
mov    %esi,%ebp
mov    %rdi,%rbx
mov    $0x20,%edx
call   1040 <fb_hStrSkipChar@plt>
sub    %eax,%ebx
add    %ebp,%ebx
test   %ebx,%ebx
jle    11bb <fb_hStr2Int+0x8b>
cmp    $0x1,%ebx
je     11a6 <fb_hStr2Int+0x76>
cmpb   $0x26,(%rax)
jne    11a6 <fb_hStr2Int+0x76>
movsbl 0x1(%rax),%esi
add    $0xffffffbe,%esi
cmp    $0x2d,%esi
ja     119a <fb_hStr2Int+0x6a>
movabs $0x100000001,%rcx
bt     %rsi,%rcx
jb     11c4 <fb_hStr2Int+0x94>
mov    $0x2,%ecx
mov    $0x10,%edx
movabs $0x4000000040,%rdi
bt     %rsi,%rdi
jb     11ce <fb_hStr2Int+0x9e>
movabs $0x200000002000,%rdx
bt     %rsi,%rdx
jb     119f <fb_hStr2Int+0x6f>
mov    $0x1,%ecx
mov    $0x8,%edx
jmp    11ce <fb_hStr2Int+0x9e>
mov    %rax,%rdi
xor    %esi,%esi
mov    $0xa,%edx
add    $0x8,%rsp
pop    %rbx
pop    %rbp
jmp    1050 <strtoul@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret
mov    $0x2,%edx
mov    $0x2,%ecx
mov    %ecx,%esi
add    %rsi,%rax
sub    %ecx,%ebx
mov    %rax,%rdi
mov    %ebx,%esi
add    $0x8,%rsp
pop    %rbx
pop    %rbp
jmp    1030 <fb_hStrRadix2Int@plt>

LLVM IR (-O0):
define i32 @fb_hStr2Int(i8* %0, i32 %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i32
store i8* %0, i8** %4
store i32 %1, i32* %5
%9 = load i8*, i8** %4
%10 = load i32, i32* %5
%11 = call i8* @fb_hStrSkipChar(i8* %9, i32 %10, i32 32)
store i8* %11, i8** %6
%12 = load i8*, i8** %6
%13 = load i8*, i8** %4
%14 = ptrtoint i8* %12 to i64
%15 = ptrtoint i8* %13 to i64
%16 = sub i64 %14, %15
%17 = trunc i64 %16 to i32
%18 = load i32, i32* %5
%19 = sub nsw i32 %18, %17
store i32 %19, i32* %5
%20 = load i32, i32* %5
%21 = icmp slt i32 %20, 1
br i1 %21, label %22, label %23
22: ; preds = %2
store i32 0, i32* %3
br label %59
23: ; preds = %2
%24 = load i32, i32* %5
%25 = icmp sge i32 %24, 2
br i1 %25, label %26, label %55
26: ; preds = %23
%27 = load i8*, i8** %6
%28 = getelementptr inbounds i8, i8* %27, i64 0
%29 = load i8, i8* %28
%30 = sext i8 %29 to i32
%31 = icmp eq i32 %30, 38
br i1 %31, label %32, label %55
32: ; preds = %26
store i32 0, i32* %7
store i32 2, i32* %8
%33 = load i8*, i8** %6
%34 = getelementptr inbounds i8, i8* %33, i64 1
%35 = load i8, i8* %34
%36 = sext i8 %35 to i32
switch i32 %36, label %40 [
i32 104, label %37
i32 72, label %37
i32 111, label %38
i32 79, label %38
i32 98, label %39
i32 66, label %39
]
37: ; preds = %32, %32
store i32 16, i32* %7
br label %41
38: ; preds = %32, %32
store i32 8, i32* %7
br label %41
39: ; preds = %32, %32
store i32 2, i32* %7
br label %41
40: ; preds = %32
store i32 8, i32* %7
store i32 1, i32* %8
br label %41
41: ; preds = %40, %39, %38, %37
%42 = load i32, i32* %7
%43 = icmp ne i32 %42, 0
br i1 %43, label %44, label %54
44: ; preds = %41
%45 = load i8*, i8** %6
%46 = load i32, i32* %8
%47 = sext i32 %46 to i64
%48 = getelementptr inbounds i8, i8* %45, i64 %47
%49 = load i32, i32* %5
%50 = load i32, i32* %8
%51 = sub nsw i32 %49, %50
%52 = load i32, i32* %7
%53 = call i32 @fb_hStrRadix2Int(i8* %48, i32 %51, i32 %52)
store i32 %53, i32* %3
br label %59
54: ; preds = %41
br label %55
55: ; preds = %54, %26, %23
br label %56
56: ; preds = %55
%57 = load i8*, i8** %6
%58 = call i32 @strtoul(i8* %57, i32 0, i32 10)
store i32 %58, i32* %3
br label %59
59: ; preds = %56, %44, %22
%60 = load i32, i32* %3
ret i32 %60
}

LLVM IR (-O2):
define i32 @fb_hStr2Int(i8* %0, i32 %1) {
%3 = tail call i8* @fb_hStrSkipChar(i8* %0, i32 %1, i32 32)
%4 = ptrtoint i8* %3 to i64
%5 = ptrtoint i8* %0 to i64
%6 = sub i64 %5, %4
%7 = trunc i64 %6 to i32
%8 = add i32 %7, %1
%9 = icmp slt i32 %8, 1
br i1 %9, label %31, label %10
10: ; preds = %2
%11 = icmp eq i32 %8, 1
br i1 %11, label %29, label %12
12: ; preds = %10
%13 = load i8, i8* %3
%14 = icmp eq i8 %13, 38
br i1 %14, label %15, label %29
15: ; preds = %12
%16 = getelementptr inbounds i8, i8* %3, i64 1
%17 = load i8, i8* %16
%18 = sext i8 %17 to i32
switch i32 %18, label %21 [
i32 104, label %22
i32 72, label %22
i32 111, label %19
i32 79, label %19
i32 98, label %20
i32 66, label %20
]
19: ; preds = %15, %15
br label %22
20: ; preds = %15, %15
br label %22
21: ; preds = %15
br label %22
22: ; preds = %19, %20, %21, %15, %15
%23 = phi i32 [ 8, %21 ], [ 2, %20 ], [ 8, %19 ], [ 16, %15 ], [ 16, %15 ]
%24 = phi i32 [ 1, %21 ], [ 2, %20 ], [ 2, %19 ], [ 2, %15 ], [ 2, %15 ]
%25 = zext i32 %24 to i64
%26 = getelementptr inbounds i8, i8* %3, i64 %25
%27 = sub nuw nsw i32 %8, %24
%28 = tail call i32 @fb_hStrRadix2Int(i8* %26, i32 %27, i32 %23)
br label %31
29: ; preds = %10, %12
%30 = tail call i32 @strtoul(i8* %3, i32 0, i32 10)
br label %31
31: ; preds = %2, %29, %22
%32 = phi i32 [ %28, %22 ], [ %30, %29 ], [ 0, %2 ]
ret i32 %32
}