#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 /*<<< orphan*/ could_not_parse(char *);
long strtol(char const *, char **, int);
signed long string_to_number(const char *string) {
  signed long result;
  char *end;
  int base = 10;
  if (*string == '%') {
    base = 2;
    ++string;
  } else if (*string == '&') {
    base = 8;
    ++string;
  } else if (*string == '$') {
    base = 16;
    ++string;
  } else if ((*string == '0') && ((string[1] == 'x') || (string[1] == 'X'))) {
    base = 16;
    string += 2;
  }
  result = strtol(string, &end, base);
  if (*end)
    could_not_parse(end);
  return result;
}


x86 assembly (clang, -O0):
<string_to_number>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0xa,-0x1c(%rbp)
mov    -0x8(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x25,%eax
jne    115b <string_to_number+0x3b>
movl   $0x2,-0x1c(%rbp)
mov    -0x8(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x8(%rbp)
jmp    11ff <string_to_number+0xdf>
mov    -0x8(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x26,%eax
jne    1183 <string_to_number+0x63>
movl   $0x8,-0x1c(%rbp)
mov    -0x8(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x8(%rbp)
jmp    11fa <string_to_number+0xda>
mov    -0x8(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x24,%eax
jne    11ab <string_to_number+0x8b>
movl   $0x10,-0x1c(%rbp)
mov    -0x8(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x8(%rbp)
jmp    11f5 <string_to_number+0xd5>
mov    -0x8(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x30,%eax
jne    11f0 <string_to_number+0xd0>
mov    -0x8(%rbp),%rax
movsbl 0x1(%rax),%eax
cmp    $0x78,%eax
je     11dd <string_to_number+0xbd>
mov    -0x8(%rbp),%rax
movsbl 0x1(%rax),%eax
cmp    $0x58,%eax
jne    11f0 <string_to_number+0xd0>
movl   $0x10,-0x1c(%rbp)
mov    -0x8(%rbp),%rax
add    $0x2,%rax
mov    %rax,-0x8(%rbp)
jmp    11f5 <string_to_number+0xd5>
jmp    11fa <string_to_number+0xda>
jmp    11ff <string_to_number+0xdf>
mov    -0x8(%rbp),%rdi
mov    -0x1c(%rbp),%edx
lea    -0x18(%rbp),%rsi
call   1040 <strtol@plt>
mov    %rax,-0x10(%rbp)
mov    -0x18(%rbp),%rax
cmpb   $0x0,(%rax)
je     1229 <string_to_number+0x109>
mov    -0x18(%rbp),%rdi
call   1030 <could_not_parse@plt>
mov    -0x10(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<string_to_number>:
push   %rbx
sub    $0x10,%rsp
mov    (%rdi),%al
mov    $0xa,%edx
add    $0xdc,%al
cmp    $0xc,%al
ja     1173 <string_to_number+0x53>
movzbl %al,%eax
lea    0xec4(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
add    $0x1,%rdi
jmp    116e <string_to_number+0x4e>
add    $0x1,%rdi
mov    $0x2,%edx
jmp    1173 <string_to_number+0x53>
add    $0x1,%rdi
mov    $0x8,%edx
jmp    1173 <string_to_number+0x53>
mov    0x1(%rdi),%al
or     $0x20,%al
cmp    $0x78,%al
jne    1173 <string_to_number+0x53>
add    $0x2,%rdi
mov    $0x10,%edx
lea    0x8(%rsp),%rsi
call   1040 <strtol@plt>
mov    %rax,%rbx
mov    0x8(%rsp),%rdi
cmpb   $0x0,(%rdi)
je     118f <string_to_number+0x6f>
call   1030 <could_not_parse@plt>
mov    %rbx,%rax
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
define i64 @string_to_number(i8* %0) {
%2 = alloca i8*
%3 = alloca i64
%4 = alloca i8*
%5 = alloca i32
store i8* %0, i8** %2
store i32 10, i32* %5
%6 = load i8*, i8** %2
%7 = load i8, i8* %6
%8 = sext i8 %7 to i32
%9 = icmp eq i32 %8, 37
br i1 %9, label %10, label %13
10: ; preds = %1
store i32 2, i32* %5
%11 = load i8*, i8** %2
%12 = getelementptr inbounds i8, i8* %11, i32 1
store i8* %12, i8** %2
br label %52
13: ; preds = %1
%14 = load i8*, i8** %2
%15 = load i8, i8* %14
%16 = sext i8 %15 to i32
%17 = icmp eq i32 %16, 38
br i1 %17, label %18, label %21
18: ; preds = %13
store i32 8, i32* %5
%19 = load i8*, i8** %2
%20 = getelementptr inbounds i8, i8* %19, i32 1
store i8* %20, i8** %2
br label %51
21: ; preds = %13
%22 = load i8*, i8** %2
%23 = load i8, i8* %22
%24 = sext i8 %23 to i32
%25 = icmp eq i32 %24, 36
br i1 %25, label %26, label %29
26: ; preds = %21
store i32 16, i32* %5
%27 = load i8*, i8** %2
%28 = getelementptr inbounds i8, i8* %27, i32 1
store i8* %28, i8** %2
br label %50
29: ; preds = %21
%30 = load i8*, i8** %2
%31 = load i8, i8* %30
%32 = sext i8 %31 to i32
%33 = icmp eq i32 %32, 48
br i1 %33, label %34, label %49
34: ; preds = %29
%35 = load i8*, i8** %2
%36 = getelementptr inbounds i8, i8* %35, i64 1
%37 = load i8, i8* %36
%38 = sext i8 %37 to i32
%39 = icmp eq i32 %38, 120
br i1 %39, label %46, label %40
40: ; preds = %34
%41 = load i8*, i8** %2
%42 = getelementptr inbounds i8, i8* %41, i64 1
%43 = load i8, i8* %42
%44 = sext i8 %43 to i32
%45 = icmp eq i32 %44, 88
br i1 %45, label %46, label %49
46: ; preds = %40, %34
store i32 16, i32* %5
%47 = load i8*, i8** %2
%48 = getelementptr inbounds i8, i8* %47, i64 2
store i8* %48, i8** %2
br label %49
49: ; preds = %46, %40, %29
br label %50
50: ; preds = %49, %26
br label %51
51: ; preds = %50, %18
br label %52
52: ; preds = %51, %10
%53 = load i8*, i8** %2
%54 = load i32, i32* %5
%55 = call i64 @strtol(i8* %53, i8** %4, i32 %54)
store i64 %55, i64* %3
%56 = load i8*, i8** %4
%57 = load i8, i8* %56
%58 = icmp ne i8 %57, 0
br i1 %58, label %59, label %62
59: ; preds = %52
%60 = load i8*, i8** %4
%61 = call i32 @could_not_parse(i8* %60)
br label %62
62: ; preds = %59, %52
%63 = load i64, i64* %3
ret i64 %63
}

LLVM IR (-O2):
define i64 @string_to_number(i8* %0) {
%2 = alloca i8*
%3 = bitcast i8** %2 to i8*
%4 = load i8, i8* %0
switch i8 %4, label %16 [
i8 37, label %5
i8 38, label %7
i8 36, label %9
i8 48, label %11
]
5: ; preds = %1
%6 = getelementptr inbounds i8, i8* %0, i64 1
br label %16
7: ; preds = %1
%8 = getelementptr inbounds i8, i8* %0, i64 1
br label %16
9: ; preds = %1
%10 = getelementptr inbounds i8, i8* %0, i64 1
br label %16
11: ; preds = %1
%12 = getelementptr inbounds i8, i8* %0, i64 1
%13 = load i8, i8* %12
switch i8 %13, label %16 [
i8 120, label %14
i8 88, label %14
]
14: ; preds = %11, %11
%15 = getelementptr inbounds i8, i8* %0, i64 2
br label %16
16: ; preds = %11, %1, %7, %14, %9, %5
%17 = phi i8* [ %6, %5 ], [ %8, %7 ], [ %10, %9 ], [ %15, %14 ], [ %0, %1 ], [ %0, %11 ]
%18 = phi i32 [ 2, %5 ], [ 8, %7 ], [ 16, %9 ], [ 16, %14 ], [ 10, %1 ], [ 10, %11 ]
%19 = call i64 @strtol(i8* %17, i8** %2, i32 %18)
%20 = load i8*, i8** %2
%21 = load i8, i8* %20
%22 = icmp eq i8 %21, 0
br i1 %22, label %25, label %23
23: ; preds = %16
%24 = tail call i32 @could_not_parse(i8* %20)
br label %25
25: ; preds = %23, %16
ret i64 %19
}