#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*/ sscanf(char *, char *, int *);
scalar_t__ strncmp(char *, char *, int);
int atonum(char *s) {
  int n;
  while (*s == ' ')
    s++;
  if (strncmp(s, "0x", 2) == 0 || strncmp(s, "0X", 2) == 0)
    sscanf(s + 2, "%x", &n);
  else if (s[0] == '0' && s[1])
    sscanf(s + 1, "%o", &n);
  else
    sscanf(s, "%d", &n);
  return n;
}


x86 assembly (clang, -O0):
<atonum>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x20,%eax
jne    114d <atonum+0x2d>
mov    -0x8(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x8(%rbp)
jmp    112c <atonum+0xc>
mov    -0x8(%rbp),%rdi
lea    0xea8(%rip),%rsi
mov    $0x2,%edx
call   1030 <strncmp@plt>
cmp    $0x0,%rax
je     118b <atonum+0x6b>
mov    -0x8(%rbp),%rdi
lea    0xe8c(%rip),%rsi
mov    $0x2,%edx
call   1030 <strncmp@plt>
cmp    $0x0,%rax
jne    11a8 <atonum+0x88>
mov    -0x8(%rbp),%rdi
add    $0x2,%rdi
lea    0xe6c(%rip),%rsi
lea    -0xc(%rbp),%rdx
call   1040 <sscanf@plt>
jmp    11ff <atonum+0xdf>
mov    -0x8(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x30,%eax
jne    11e6 <atonum+0xc6>
mov    -0x8(%rbp),%rax
movsbl 0x1(%rax),%eax
cmp    $0x0,%eax
je     11e6 <atonum+0xc6>
mov    -0x8(%rbp),%rdi
add    $0x1,%rdi
lea    0xe31(%rip),%rsi
lea    -0xc(%rbp),%rdx
call   1040 <sscanf@plt>
jmp    11fa <atonum+0xda>
mov    -0x8(%rbp),%rdi
lea    0xe1b(%rip),%rsi
lea    -0xc(%rbp),%rdx
call   1040 <sscanf@plt>
jmp    11ff <atonum+0xdf>
mov    -0xc(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<atonum>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%rbx
nopw   0x0(%rax,%rax,1)
cmpb   $0x20,(%rbx)
lea    0x1(%rbx),%rbx
je     1130 <atonum+0x10>
lea    -0x1(%rbx),%r14
lea    0xebc(%rip),%rsi
mov    %r14,%rdi
mov    $0x2,%edx
call   1030 <strncmp@plt>
test   %rax,%rax
je     1183 <atonum+0x63>
lea    0xea6(%rip),%rsi
mov    %r14,%rdi
mov    $0x2,%edx
call   1030 <strncmp@plt>
test   %rax,%rax
je     1183 <atonum+0x63>
cmpb   $0x30,(%r14)
jne    1198 <atonum+0x78>
cmpb   $0x0,(%rbx)
je     1198 <atonum+0x78>
lea    0xe88(%rip),%rsi
jmp    118e <atonum+0x6e>
add    $0x1,%rbx
lea    0xe78(%rip),%rsi
lea    0x4(%rsp),%rdx
mov    %rbx,%rdi
jmp    11a7 <atonum+0x87>
lea    0xe6d(%rip),%rsi
lea    0x4(%rsp),%rdx
mov    %r14,%rdi
call   1040 <sscanf@plt>
mov    0x4(%rsp),%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [3 x i8] c"0x\00"
@.str.1 = [3 x i8] c"0X\00"
@.str.2 = [3 x i8] c"%x\00"
@.str.3 = [3 x i8] c"%o\00"
@.str.4 = [3 x i8] c"%d\00"
define i32 @atonum(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
store i8* %0, i8** %2
br label %4
4: ; preds = %9, %1
%5 = load i8*, i8** %2
%6 = load i8, i8* %5
%7 = sext i8 %6 to i32
%8 = icmp eq i32 %7, 32
br i1 %8, label %9, label %12
9: ; preds = %4
%10 = load i8*, i8** %2
%11 = getelementptr inbounds i8, i8* %10, i32 1
store i8* %11, i8** %2
br label %4
12: ; preds = %4
%13 = load i8*, i8** %2
%14 = call i64 @strncmp(i8* %13, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 2)
%15 = icmp eq i64 %14, 0
br i1 %15, label %20, label %16
16: ; preds = %12
%17 = load i8*, i8** %2
%18 = call i64 @strncmp(i8* %17, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 2)
%19 = icmp eq i64 %18, 0
br i1 %19, label %20, label %24
20: ; preds = %16, %12
%21 = load i8*, i8** %2
%22 = getelementptr inbounds i8, i8* %21, i64 2
%23 = call i32 @sscanf(i8* %22, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %3)
br label %44
24: ; preds = %16
%25 = load i8*, i8** %2
%26 = getelementptr inbounds i8, i8* %25, i64 0
%27 = load i8, i8* %26
%28 = sext i8 %27 to i32
%29 = icmp eq i32 %28, 48
br i1 %29, label %30, label %40
30: ; preds = %24
%31 = load i8*, i8** %2
%32 = getelementptr inbounds i8, i8* %31, i64 1
%33 = load i8, i8* %32
%34 = sext i8 %33 to i32
%35 = icmp ne i32 %34, 0
br i1 %35, label %36, label %40
36: ; preds = %30
%37 = load i8*, i8** %2
%38 = getelementptr inbounds i8, i8* %37, i64 1
%39 = call i32 @sscanf(i8* %38, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32* %3)
br label %43
40: ; preds = %30, %24
%41 = load i8*, i8** %2
%42 = call i32 @sscanf(i8* %41, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i32* %3)
br label %43
43: ; preds = %40, %36
br label %44
44: ; preds = %43, %20
%45 = load i32, i32* %3
ret i32 %45
}

LLVM IR (-O2):
@.str = [3 x i8] c"0x\00"
@.str.1 = [3 x i8] c"0X\00"
@.str.2 = [3 x i8] c"%x\00"
@.str.3 = [3 x i8] c"%o\00"
@.str.4 = [3 x i8] c"%d\00"
define i32 @atonum(i8* %0) {
%2 = alloca i32
%3 = bitcast i32* %2 to i8*
br label %4
4: ; preds = %4, %1
%5 = phi i8* [ %0, %1 ], [ %8, %4 ]
%6 = load i8, i8* %5
%7 = icmp eq i8 %6, 32
%8 = getelementptr inbounds i8, i8* %5, i64 1
br i1 %7, label %4, label %9
9: ; preds = %4
%10 = tail call i64 @strncmp(i8* %5, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 2)
%11 = icmp eq i64 %10, 0
br i1 %11, label %15, label %12
12: ; preds = %9
%13 = tail call i64 @strncmp(i8* %5, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 2)
%14 = icmp eq i64 %13, 0
br i1 %14, label %15, label %18
15: ; preds = %12, %9
%16 = getelementptr inbounds i8, i8* %5, i64 2
%17 = call i32 @sscanf(i8* %16, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %2)
br label %28
18: ; preds = %12
%19 = load i8, i8* %5
%20 = icmp eq i8 %19, 48
br i1 %20, label %21, label %26
21: ; preds = %18
%22 = load i8, i8* %8
%23 = icmp eq i8 %22, 0
br i1 %23, label %26, label %24
24: ; preds = %21
%25 = call i32 @sscanf(i8* %8, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32* %2)
br label %28
26: ; preds = %21, %18
%27 = call i32 @sscanf(i8* %5, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i32* %2)
br label %28
28: ; preds = %24, %26, %15
%29 = load i32, i32* %2
ret i32 %29
}