#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 */
typedef int /*<<< orphan*/ uint16_t;

/* Variables and functions */
int /*<<< orphan*/ strtol(char const *, int /*<<< orphan*/ *, int);
uint16_t str_to_int(const char *str) {
  uint16_t ret;
  if (str[0] == '0' && str[1] == 'b') {
    ret = strtol((str + 2), NULL, 2);
  } else if (str[0] == '0' && str[1] == 'x') {
    ret = strtol(str, NULL, 16);
  } else {
    ret = strtol(str, NULL, 10);
  }
  return (uint16_t)ret;
}


x86 assembly (clang, -O0):
<str_to_int>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x30,%eax
jne    115b <str_to_int+0x4b>
mov    -0x8(%rbp),%rax
movsbl 0x1(%rax),%eax
cmp    $0x62,%eax
jne    115b <str_to_int+0x4b>
mov    -0x8(%rbp),%rdi
add    $0x2,%rdi
xor    %eax,%eax
mov    %eax,%esi
mov    $0x2,%edx
call   1030 <strtol@plt>
mov    %eax,-0xc(%rbp)
jmp    11b0 <str_to_int+0xa0>
mov    -0x8(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x30,%eax
jne    1196 <str_to_int+0x86>
mov    -0x8(%rbp),%rax
movsbl 0x1(%rax),%eax
cmp    $0x78,%eax
jne    1196 <str_to_int+0x86>
mov    -0x8(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
mov    $0x10,%edx
call   1030 <strtol@plt>
mov    %eax,-0xc(%rbp)
jmp    11ab <str_to_int+0x9b>
mov    -0x8(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
mov    $0xa,%edx
call   1030 <strtol@plt>
mov    %eax,-0xc(%rbp)
jmp    11b0 <str_to_int+0xa0>
mov    -0xc(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<str_to_int>:
cmpb   $0x30,(%rdi)
jne    1130 <str_to_int+0x20>
mov    0x1(%rdi),%al
cmp    $0x78,%al
je     113c <str_to_int+0x2c>
cmp    $0x62,%al
jne    1130 <str_to_int+0x20>
add    $0x2,%rdi
xor    %esi,%esi
mov    $0x2,%edx
jmp    1030 <strtol@plt>
xor    %esi,%esi
mov    $0xa,%edx
jmp    1030 <strtol@plt>
xor    %esi,%esi
mov    $0x10,%edx
jmp    1030 <strtol@plt>

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

LLVM IR (-O2):
define i32 @str_to_int(i8* nocapture %0) {
%2 = load i8, i8* %0
%3 = icmp eq i8 %2, 48
br i1 %3, label %4, label %12
4: ; preds = %1
%5 = getelementptr inbounds i8, i8* %0, i64 1
%6 = load i8, i8* %5
switch i8 %6, label %12 [
i8 98, label %7
i8 120, label %10
]
7: ; preds = %4
%8 = getelementptr inbounds i8, i8* %0, i64 2
%9 = tail call i32 @strtol(i8* nocapture %8, i32* null, i32 2)
br label %14
10: ; preds = %4
%11 = tail call i32 @strtol(i8* nocapture %0, i32* null, i32 16)
br label %14
12: ; preds = %4, %1
%13 = tail call i32 @strtol(i8* nocapture %0, i32* null, i32 10)
br label %14
14: ; preds = %10, %12, %7
%15 = phi i32 [ %9, %7 ], [ %11, %10 ], [ %13, %12 ]
ret i32 %15
}