#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 */
int sscanf(char const *, char *, unsigned long *);
Bool parse_number(const char *str, unsigned long *val) {
  char *fmt = "%ld";
  if (*str == '0') {
    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    0xed9(%rip),%rax
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x30,%eax
jne    11b5 <parse_number+0xa5>
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x10(%rbp)
lea    0xeb6(%rip),%rax
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
jne    1179 <parse_number+0x69>
mov    -0x18(%rbp),%rax
movq   $0x0,(%rax)
movl   $0x1,-0x4(%rbp)
jmp    11d4 <parse_number+0xc4>
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x78,%eax
je     1199 <parse_number+0x89>
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x58,%eax
jne    11b0 <parse_number+0xa0>
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x10(%rbp)
lea    0xe5c(%rip),%rax
mov    %rax,-0x20(%rbp)
jmp    11b5 <parse_number+0xa5>
mov    -0x10(%rbp),%rdi
mov    -0x20(%rbp),%rsi
mov    -0x18(%rbp),%rdx
call   1030 <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   %rax
mov    %rsi,%rdx
cmpb   $0x30,(%rdi)
jne    1136 <parse_number+0x26>
mov    0x1(%rdi),%al
cmp    $0x78,%al
je     113f <parse_number+0x2f>
cmp    $0x58,%al
je     113f <parse_number+0x2f>
test   %al,%al
jne    114c <parse_number+0x3c>
movq   $0x0,(%rdx)
mov    $0x1,%eax
pop    %rcx
ret
lea    0xec3(%rip),%rsi
jmp    1157 <parse_number+0x47>
add    $0x2,%rdi
lea    0xebe(%rip),%rsi
jmp    1157 <parse_number+0x47>
add    $0x1,%rdi
lea    0xead(%rip),%rsi
call   1030 <sscanf@plt>
mov    %eax,%ecx
xor    %eax,%eax
cmp    $0x1,%ecx
sete   %al
pop    %rcx
ret

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 %34
11: ; preds = %2
%12 = load i8*, i8** %4
%13 = getelementptr inbounds i8, i8* %12, i32 1
store i8* %13, i8** %4
store i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i8** %6
%14 = load i8*, i8** %4
%15 = load i8, i8* %14
%16 = sext i8 %15 to i32
%17 = icmp eq i32 %16, 0
br i1 %17, label %18, label %20
18: ; preds = %11
%19 = load i64*, i64** %5
store i64 0, i64* %19
store i32 1, i32* %3
br label %41
20: ; preds = %11
%21 = load i8*, i8** %4
%22 = load i8, i8* %21
%23 = sext i8 %22 to i32
%24 = icmp eq i32 %23, 120
br i1 %24, label %30, label %25
25: ; preds = %20
%26 = load i8*, i8** %4
%27 = load i8, i8* %26
%28 = sext i8 %27 to i32
%29 = icmp eq i32 %28, 88
br i1 %29, label %30, label %33
30: ; preds = %25, %20
%31 = load i8*, i8** %4
%32 = getelementptr inbounds i8, i8* %31, i32 1
store i8* %32, i8** %4
store i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i8** %6
br label %33
33: ; preds = %30, %25
br label %34
34: ; preds = %33, %2
%35 = load i8*, i8** %4
%36 = load i8*, i8** %6
%37 = load i64*, i64** %5
%38 = call i32 @sscanf(i8* %35, i8* %36, i64* %37)
%39 = icmp eq i32 %38, 1
%40 = zext i1 %39 to i32
store i32 %40, i32* %3
br label %41
41: ; preds = %34, %18
%42 = load i32, i32* %3
ret i32 %42
}

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 %11
5: ; preds = %2
%6 = getelementptr inbounds i8, i8* %0, i64 1
%7 = load i8, i8* %6
switch i8 %7, label %11 [
i8 0, label %8
i8 120, label %9
i8 88, label %9
]
8: ; preds = %5
store i64 0, i64* %1
br label %17
9: ; preds = %5, %5
%10 = getelementptr inbounds i8, i8* %0, i64 2
br label %11
11: ; preds = %5, %9, %2
%12 = phi i8* [ %10, %9 ], [ %0, %2 ], [ %6, %5 ]
%13 = phi i8* [ getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), %9 ], [ 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), %5 ]
%14 = tail call i32 @sscanf(i8* %12, i8* %13, i64* %1)
%15 = icmp eq i32 %14, 1
%16 = zext i1 %15 to i32
br label %17
17: ; preds = %11, %8
%18 = phi i32 [ 1, %8 ], [ %16, %11 ]
ret i32 %18
}