#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 Bool;

/* Variables and functions */
scalar_t__ isspace(char const);
int sscanf(char const *, char const *, unsigned long *);
Bool parse_number(const char *str, unsigned long *val) {
  const char *fmt = "%ld";
  if (*str == '0') {
    str++;
    while (isspace(*str))
      str++;
    fmt = "%lo";
    if (*str == '\0') {
      *val = 0;
      return 1;
    }
    if (*str == 'x' || *str == 'X') {
      str++;
      fmt = "%lx";
    }
  }
  return (sscanf(str, fmt, val) == 1);
}


x86 assembly (clang, -O0):
<parse_number>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
lea    0xec9(%rip),%rax
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x30,%eax
jne    11ec <parse_number+0xcc>
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
movsbl (%rax),%edi
call   1030 <isspace@plt>
cmp    $0x0,%rax
je     117e <parse_number+0x5e>
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x10(%rbp)
jmp    1157 <parse_number+0x37>
lea    0xe7f(%rip),%rax
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
jne    11b0 <parse_number+0x90>
mov    -0x18(%rbp),%rax
movq   $0x0,(%rax)
movl   $0x1,-0x4(%rbp)
jmp    120b <parse_number+0xeb>
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x78,%eax
je     11d0 <parse_number+0xb0>
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x58,%eax
jne    11e7 <parse_number+0xc7>
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x10(%rbp)
lea    0xe25(%rip),%rax
mov    %rax,-0x20(%rbp)
jmp    11ec <parse_number+0xcc>
mov    -0x10(%rbp),%rdi
mov    -0x20(%rbp),%rsi
mov    -0x18(%rbp),%rdx
call   1040 <sscanf@plt>
cmp    $0x1,%eax
sete   %al
and    $0x1,%al
movzbl %al,%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<parse_number>:
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%rbx
cmpb   $0x30,(%rdi)
jne    1169 <parse_number+0x49>
add    $0x1,%rbx
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
movsbl (%rbx),%edi
call   1030 <isspace@plt>
add    $0x1,%rbx
test   %rax,%rax
jne    1140 <parse_number+0x20>
mov    -0x1(%rbx),%al
test   %al,%al
je     118d <parse_number+0x6d>
cmp    $0x58,%al
je     1160 <parse_number+0x40>
cmp    $0x78,%al
jne    119b <parse_number+0x7b>
lea    0xea1(%rip),%rsi
jmp    1170 <parse_number+0x50>
lea    0xe90(%rip),%rsi
mov    %rbx,%rdi
mov    %r14,%rdx
call   1040 <sscanf@plt>
mov    %eax,%ecx
xor    %eax,%eax
cmp    $0x1,%ecx
sete   %al
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret
movq   $0x0,(%r14)
mov    $0x1,%eax
jmp    1185 <parse_number+0x65>
add    $0xffffffffffffffff,%rbx
lea    0xe5e(%rip),%rsi
jmp    1170 <parse_number+0x50>

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

LLVM IR (-O2):
@.str = [4 x i8] c"%ld\00"
@.str.1 = [4 x i8] c"%lo\00"
@.str.2 = [4 x i8] c"%lx\00"
define i32 @parse_number(i8* nocapture %0, i64* %1) {
%3 = load i8, i8* %0
%4 = icmp eq i8 %3, 48
br i1 %4, label %5, label %16
5: ; preds = %2, %5
%6 = phi i8* [ %7, %5 ], [ %0, %2 ]
%7 = getelementptr inbounds i8, i8* %6, i64 1
%8 = load i8, i8* %7
%9 = tail call i64 @isspace(i8 signext %8)
%10 = icmp eq i64 %9, 0
br i1 %10, label %11, label %5
11: ; preds = %5
%12 = load i8, i8* %7
switch i8 %12, label %16 [
i8 0, label %13
i8 120, label %14
i8 88, label %14
]
13: ; preds = %11
store i64 0, i64* %1
br label %22
14: ; preds = %11, %11
%15 = getelementptr inbounds i8, i8* %6, i64 2
br label %16
16: ; preds = %11, %14, %2
%17 = phi i8* [ %15, %14 ], [ %0, %2 ], [ %7, %11 ]
%18 = phi i8* [ getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), %14 ], [ getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), %2 ], [ getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), %11 ]
%19 = tail call i32 @sscanf(i8* %17, i8* %18, i64* %1)
%20 = icmp eq i32 %19, 1
%21 = zext i1 %20 to i32
br label %22
22: ; preds = %16, %13
%23 = phi i32 [ 1, %13 ], [ %21, %16 ]
ret i32 %23
}