#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 *fb_hStrSkipChar(char *, int, int);
unsigned int strtoul(char *, int /*<<< orphan*/, int);
unsigned int fb_hStr2UInt(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;
  radix = 10;
  if ((len >= 2) && (p[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 != 10)
      p += skip;
  }
  return strtoul(p, 0, radix);
}


x86 assembly (clang, -O0):
<fb_hStr2UInt>:
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   1030 <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    116f <fb_hStr2UInt+0x4f>
movl   $0x0,-0x4(%rbp)
jmp    1268 <fb_hStr2UInt+0x148>
movl   $0xa,-0x24(%rbp)
cmpl   $0x2,-0x14(%rbp)
jl     1257 <fb_hStr2UInt+0x137>
mov    -0x20(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x26,%eax
jne    1257 <fb_hStr2UInt+0x137>
movl   $0x2,-0x28(%rbp)
mov    -0x20(%rbp),%rax
movsbl 0x1(%rax),%eax
mov    %eax,-0x2c(%rbp)
sub    $0x42,%eax
je     121d <fb_hStr2UInt+0xfd>
jmp    11b0 <fb_hStr2UInt+0x90>
mov    -0x2c(%rbp),%eax
sub    $0x48,%eax
je     1205 <fb_hStr2UInt+0xe5>
jmp    11c1 <fb_hStr2UInt+0xa1>
mov    -0x2c(%rbp),%eax
sub    $0x4f,%eax
je     1211 <fb_hStr2UInt+0xf1>
jmp    11d2 <fb_hStr2UInt+0xb2>
mov    -0x2c(%rbp),%eax
sub    $0x62,%eax
je     121d <fb_hStr2UInt+0xfd>
jmp    11e3 <fb_hStr2UInt+0xc3>
mov    -0x2c(%rbp),%eax
sub    $0x68,%eax
je     1205 <fb_hStr2UInt+0xe5>
jmp    11f4 <fb_hStr2UInt+0xd4>
mov    -0x2c(%rbp),%eax
sub    $0x6f,%eax
je     1211 <fb_hStr2UInt+0xf1>
jmp    1229 <fb_hStr2UInt+0x109>
movl   $0x10,-0x24(%rbp)
jmp    1237 <fb_hStr2UInt+0x117>
movl   $0x8,-0x24(%rbp)
jmp    1237 <fb_hStr2UInt+0x117>
movl   $0x2,-0x24(%rbp)
jmp    1237 <fb_hStr2UInt+0x117>
movl   $0x8,-0x24(%rbp)
movl   $0x1,-0x28(%rbp)
cmpl   $0xa,-0x24(%rbp)
je     1252 <fb_hStr2UInt+0x132>
mov    -0x28(%rbp),%ecx
mov    -0x20(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x20(%rbp)
jmp    1257 <fb_hStr2UInt+0x137>
mov    -0x20(%rbp),%rdi
mov    -0x24(%rbp),%edx
xor    %esi,%esi
call   1040 <strtoul@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<fb_hStr2UInt>:
push   %rbp
push   %rbx
push   %rax
mov    %esi,%ebp
mov    %rdi,%rbx
mov    $0x20,%edx
call   1030 <fb_hStrSkipChar@plt>
sub    %eax,%ebx
add    %ebp,%ebx
test   %ebx,%ebx
jle    119b <fb_hStr2UInt+0x7b>
mov    $0xa,%edx
cmp    $0x1,%ebx
je     11ac <fb_hStr2UInt+0x8c>
cmpb   $0x26,(%rax)
jne    11ac <fb_hStr2UInt+0x8c>
movsbl 0x1(%rax),%esi
add    $0xffffffbe,%esi
cmp    $0x2d,%esi
ja     118f <fb_hStr2UInt+0x6f>
mov    $0x2,%ecx
movabs $0x100000001,%rdx
bt     %rsi,%rdx
jb     11a4 <fb_hStr2UInt+0x84>
mov    $0x10,%edx
movabs $0x4000000040,%rdi
bt     %rsi,%rdi
jb     11a9 <fb_hStr2UInt+0x89>
movabs $0x200000002000,%rdx
bt     %rsi,%rdx
jb     1194 <fb_hStr2UInt+0x74>
mov    $0x1,%ecx
mov    $0x8,%edx
jmp    11a9 <fb_hStr2UInt+0x89>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret
mov    $0x2,%edx
add    %rcx,%rax
mov    %rax,%rdi
xor    %esi,%esi
add    $0x8,%rsp
pop    %rbx
pop    %rbp
jmp    1040 <strtoul@plt>

LLVM IR (-O0):
define i32 @fb_hStr2UInt(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 %54
23: ; preds = %2
store i32 10, i32* %7
%24 = load i32, i32* %5
%25 = icmp sge i32 %24, 2
br i1 %25, label %26, label %50
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 %50
32: ; preds = %26
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, 10
br i1 %43, label %44, label %49
44: ; preds = %41
%45 = load i32, i32* %8
%46 = load i8*, i8** %6
%47 = sext i32 %45 to i64
%48 = getelementptr inbounds i8, i8* %46, i64 %47
store i8* %48, i8** %6
br label %49
49: ; preds = %44, %41
br label %50
50: ; preds = %49, %26, %23
%51 = load i8*, i8** %6
%52 = load i32, i32* %7
%53 = call i32 @strtoul(i8* %51, i32 0, i32 %52)
store i32 %53, i32* %3
br label %54
54: ; preds = %50, %22
%55 = load i32, i32* %3
ret i32 %55
}

LLVM IR (-O2):
define i32 @fb_hStr2UInt(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 %30, label %10
10: ; preds = %2
%11 = icmp eq i32 %8, 1
br i1 %11, label %26, label %12
12: ; preds = %10
%13 = load i8, i8* %3
%14 = icmp eq i8 %13, 38
br i1 %14, label %15, label %26
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 i64 [ 1, %21 ], [ 2, %20 ], [ 2, %19 ], [ 2, %15 ], [ 2, %15 ]
%25 = getelementptr inbounds i8, i8* %3, i64 %24
br label %26
26: ; preds = %22, %12, %10
%27 = phi i8* [ %25, %22 ], [ %3, %12 ], [ %3, %10 ]
%28 = phi i32 [ %23, %22 ], [ 10, %12 ], [ 10, %10 ]
%29 = tail call i32 @strtoul(i8* %27, i32 0, i32 %28)
br label %30
30: ; preds = %2, %26
%31 = phi i32 [ %29, %26 ], [ 0, %2 ]
ret i32 %31
}