#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 */
float __internal_str_to_float(char const *, unsigned int, unsigned int);
unsigned int __internal_str_to_int(char const *, unsigned int, unsigned int,
                                   int);
int str_first_pos(char const *, unsigned int, unsigned int, char);
scalar_t__ str_starts_with(char *, char const *, unsigned int, unsigned int);
int str_to_int(const char *str, unsigned f_char, unsigned l_char) {
  unsigned res = -1;
  if (str_starts_with("0x", str, f_char, l_char))
    res = __internal_str_to_int(str, f_char + 2, l_char, 16);
  else if (str_starts_with("0b", str, f_char, l_char))
    res = __internal_str_to_int(str, f_char + 2, l_char, 2);
  else if (str_first_pos(str, f_char, l_char, '.') == -1)
    res = __internal_str_to_int(str, f_char, l_char, 10);
  else {
    float f = __internal_str_to_float(str, f_char, l_char);
    res = *((int *)&f);
  }
  return res;
}


x86 assembly (clang, -O0):
<str_to_int>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
movl   $0xffffffff,-0x14(%rbp)
mov    -0x8(%rbp),%rsi
mov    -0xc(%rbp),%edx
mov    -0x10(%rbp),%ecx
lea    0xe96(%rip),%rdi
call   1040 <str_starts_with@plt>
cmp    $0x0,%rax
je     1198 <str_to_int+0x58>
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
add    $0x2,%esi
mov    -0x10(%rbp),%edx
mov    $0x10,%ecx
call   1050 <__internal_str_to_int@plt>
mov    %eax,-0x14(%rbp)
jmp    1234 <str_to_int+0xf4>
mov    -0x8(%rbp),%rsi
mov    -0xc(%rbp),%edx
mov    -0x10(%rbp),%ecx
lea    0xe5a(%rip),%rdi
call   1040 <str_starts_with@plt>
cmp    $0x0,%rax
je     11d7 <str_to_int+0x97>
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
add    $0x2,%esi
mov    -0x10(%rbp),%edx
mov    $0x2,%ecx
call   1050 <__internal_str_to_int@plt>
mov    %eax,-0x14(%rbp)
jmp    122f <str_to_int+0xef>
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
mov    -0x10(%rbp),%edx
mov    $0x2e,%ecx
call   1030 <str_first_pos@plt>
cmp    $0xffffffff,%eax
jne    1210 <str_to_int+0xd0>
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
mov    -0x10(%rbp),%edx
mov    $0xa,%ecx
call   1050 <__internal_str_to_int@plt>
mov    %eax,-0x14(%rbp)
jmp    122a <str_to_int+0xea>
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
mov    -0x10(%rbp),%edx
call   1060 <__internal_str_to_float@plt>
movss  %xmm0,-0x18(%rbp)
mov    -0x18(%rbp),%eax
mov    %eax,-0x14(%rbp)
jmp    122f <str_to_int+0xef>
jmp    1234 <str_to_int+0xf4>
mov    -0x14(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<str_to_int>:
push   %rbp
push   %r14
push   %rbx
mov    %edx,%r14d
mov    %esi,%ebp
mov    %rdi,%rbx
lea    0xead(%rip),%rdi
mov    %rbx,%rsi
mov    %ebp,%edx
mov    %r14d,%ecx
call   1040 <str_starts_with@plt>
test   %rax,%rax
je     1177 <str_to_int+0x37>
add    $0x2,%ebp
mov    %rbx,%rdi
mov    %ebp,%esi
mov    %r14d,%edx
mov    $0x10,%ecx
jmp    11a0 <str_to_int+0x60>
lea    0xe85(%rip),%rdi
mov    %rbx,%rsi
mov    %ebp,%edx
mov    %r14d,%ecx
call   1040 <str_starts_with@plt>
test   %rax,%rax
je     11a9 <str_to_int+0x69>
add    $0x2,%ebp
mov    %rbx,%rdi
mov    %ebp,%esi
mov    %r14d,%edx
mov    $0x2,%ecx
pop    %rbx
pop    %r14
pop    %rbp
jmp    1050 <__internal_str_to_int@plt>
mov    %rbx,%rdi
mov    %ebp,%esi
mov    %r14d,%edx
mov    $0x2e,%ecx
call   1030 <str_first_pos@plt>
mov    %rbx,%rdi
mov    %ebp,%esi
mov    %r14d,%edx
cmp    $0xffffffff,%eax
je     11d6 <str_to_int+0x96>
call   1060 <__internal_str_to_float@plt>
movd   %xmm0,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret
mov    $0xa,%ecx
jmp    11a0 <str_to_int+0x60>

LLVM IR (-O0):
@.str = [3 x i8] c"0x\00"
@.str.1 = [3 x i8] c"0b\00"
define i32 @str_to_int(i8* %0, i32 %1, i32 %2) {
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca float
store i8* %0, i8** %4
store i32 %1, i32* %5
store i32 %2, i32* %6
store i32 -1, i32* %7
%9 = load i8*, i8** %4
%10 = load i32, i32* %5
%11 = load i32, i32* %6
%12 = call i64 @str_starts_with(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %9, i32 %10, i32 %11)
%13 = icmp ne i64 %12, 0
br i1 %13, label %14, label %20
14: ; preds = %3
%15 = load i8*, i8** %4
%16 = load i32, i32* %5
%17 = add i32 %16, 2
%18 = load i32, i32* %6
%19 = call i32 @__internal_str_to_int(i8* %15, i32 %17, i32 %18, i32 16)
store i32 %19, i32* %7
br label %52
20: ; preds = %3
%21 = load i8*, i8** %4
%22 = load i32, i32* %5
%23 = load i32, i32* %6
%24 = call i64 @str_starts_with(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %21, i32 %22, i32 %23)
%25 = icmp ne i64 %24, 0
br i1 %25, label %26, label %32
26: ; preds = %20
%27 = load i8*, i8** %4
%28 = load i32, i32* %5
%29 = add i32 %28, 2
%30 = load i32, i32* %6
%31 = call i32 @__internal_str_to_int(i8* %27, i32 %29, i32 %30, i32 2)
store i32 %31, i32* %7
br label %51
32: ; preds = %20
%33 = load i8*, i8** %4
%34 = load i32, i32* %5
%35 = load i32, i32* %6
%36 = call i32 @str_first_pos(i8* %33, i32 %34, i32 %35, i8 signext 46)
%37 = icmp eq i32 %36, -1
br i1 %37, label %38, label %43
38: ; preds = %32
%39 = load i8*, i8** %4
%40 = load i32, i32* %5
%41 = load i32, i32* %6
%42 = call i32 @__internal_str_to_int(i8* %39, i32 %40, i32 %41, i32 10)
store i32 %42, i32* %7
br label %50
43: ; preds = %32
%44 = load i8*, i8** %4
%45 = load i32, i32* %5
%46 = load i32, i32* %6
%47 = call float @__internal_str_to_float(i8* %44, i32 %45, i32 %46)
store float %47, float* %8
%48 = bitcast float* %8 to i32*
%49 = load i32, i32* %48
store i32 %49, i32* %7
br label %50
50: ; preds = %43, %38
br label %51
51: ; preds = %50, %26
br label %52
52: ; preds = %51, %14
%53 = load i32, i32* %7
ret i32 %53
}

LLVM IR (-O2):
@.str = [3 x i8] c"0x\00"
@.str.1 = [3 x i8] c"0b\00"
define i32 @str_to_int(i8* %0, i32 %1, i32 %2) {
%4 = tail call i64 @str_starts_with(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %0, i32 %1, i32 %2)
%5 = icmp eq i64 %4, 0
br i1 %5, label %9, label %6
6: ; preds = %3
%7 = add i32 %1, 2
%8 = tail call i32 @__internal_str_to_int(i8* %0, i32 %7, i32 %2, i32 16)
br label %23
9: ; preds = %3
%10 = tail call i64 @str_starts_with(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %0, i32 %1, i32 %2)
%11 = icmp eq i64 %10, 0
br i1 %11, label %15, label %12
12: ; preds = %9
%13 = add i32 %1, 2
%14 = tail call i32 @__internal_str_to_int(i8* %0, i32 %13, i32 %2, i32 2)
br label %23
15: ; preds = %9
%16 = tail call i32 @str_first_pos(i8* %0, i32 %1, i32 %2, i8 signext 46)
%17 = icmp eq i32 %16, -1
br i1 %17, label %18, label %20
18: ; preds = %15
%19 = tail call i32 @__internal_str_to_int(i8* %0, i32 %1, i32 %2, i32 10)
br label %23
20: ; preds = %15
%21 = tail call float @__internal_str_to_float(i8* %0, i32 %1, i32 %2)
%22 = bitcast float %21 to i32
br label %23
23: ; preds = %12, %20, %18, %6
%24 = phi i32 [ %8, %6 ], [ %14, %12 ], [ %19, %18 ], [ %22, %20 ]
ret i32 %24
}