#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*/ assert(int /*<<< orphan*/);
int sscanf(char const *, char *, int *);
scalar_t__ strncmp(char const *, char *, int);
int load_int(const char *data, int *x) {
  const char *pos = data;
  assert(data != NULL);
  assert(x != NULL);
  *x = 0;
  while (*pos == ' ' || *pos == '\t')
    pos++;
  if (strncmp(pos, "0x", 2) == 0) {
    if (sscanf(pos, "%x", x) != 1)
      return 0;
  } else if (strncmp(pos, "0", 1) == 0) {
    if (sscanf(pos, "%o", x) != 1)
      return 0;
  } else {
    if (sscanf(pos, "%d", x) != 1)
      return 0;
  }
  return 1;
}


x86 assembly (clang, -O0):
<load_int>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x10(%rbp)
setne  %al
and    $0x1,%al
movzbl %al,%edi
call   1040 <assert@plt>
cmpq   $0x0,-0x18(%rbp)
setne  %al
and    $0x1,%al
movzbl %al,%edi
call   1040 <assert@plt>
mov    -0x18(%rbp),%rax
movl   $0x0,(%rax)
mov    -0x20(%rbp),%rax
movsbl (%rax),%ecx
mov    $0x1,%al
cmp    $0x20,%ecx
mov    %al,-0x21(%rbp)
je     119b <load_int+0x6b>
mov    -0x20(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x9,%eax
sete   %al
mov    %al,-0x21(%rbp)
mov    -0x21(%rbp),%al
test   $0x1,%al
jne    11ab <load_int+0x7b>
jmp    11bc <load_int+0x8c>
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
jmp    1176 <load_int+0x46>
mov    -0x20(%rbp),%rdi
lea    0xe39(%rip),%rsi
mov    $0x2,%edx
call   1030 <strncmp@plt>
cmp    $0x0,%rax
jne    1209 <load_int+0xd9>
mov    -0x20(%rbp),%rdi
mov    -0x18(%rbp),%rdx
lea    0xe19(%rip),%rsi
call   1050 <sscanf@plt>
cmp    $0x1,%eax
je     1204 <load_int+0xd4>
movl   $0x0,-0x4(%rbp)
jmp    1290 <load_int+0x160>
jmp    1289 <load_int+0x159>
mov    -0x20(%rbp),%rdi
lea    0xdf2(%rip),%rsi
mov    $0x1,%edx
call   1030 <strncmp@plt>
cmp    $0x0,%rax
jne    1256 <load_int+0x126>
mov    -0x20(%rbp),%rdi
mov    -0x18(%rbp),%rdx
lea    0xdd1(%rip),%rsi
call   1050 <sscanf@plt>
cmp    $0x1,%eax
je     1251 <load_int+0x121>
movl   $0x0,-0x4(%rbp)
jmp    1290 <load_int+0x160>
jmp    1284 <load_int+0x154>
mov    -0x20(%rbp),%rdi
mov    -0x18(%rbp),%rdx
lea    0xda6(%rip),%rsi
call   1050 <sscanf@plt>
cmp    $0x1,%eax
je     127f <load_int+0x14f>
movl   $0x0,-0x4(%rbp)
jmp    1290 <load_int+0x160>
jmp    1284 <load_int+0x154>
jmp    1289 <load_int+0x159>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<load_int>:
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%rbx
xor    %edi,%edi
test   %rbx,%rbx
setne  %dil
call   1040 <assert@plt>
xor    %edi,%edi
test   %r14,%r14
setne  %dil
call   1040 <assert@plt>
movl   $0x0,(%r14)
jmp    1164 <load_int+0x34>
nop
add    $0x1,%rbx
movzbl (%rbx),%eax
cmp    $0x20,%al
je     1160 <load_int+0x30>
cmp    $0x9,%al
je     1160 <load_int+0x30>
lea    0xe8a(%rip),%rsi
mov    %rbx,%rdi
mov    $0x2,%edx
call   1030 <strncmp@plt>
test   %rax,%rax
je     11aa <load_int+0x7a>
lea    0xe77(%rip),%rsi
mov    %rbx,%rdi
mov    $0x1,%edx
call   1030 <strncmp@plt>
test   %rax,%rax
je     11b3 <load_int+0x83>
lea    0xe63(%rip),%rsi
jmp    11ba <load_int+0x8a>
lea    0xe52(%rip),%rsi
jmp    11ba <load_int+0x8a>
lea    0xe4e(%rip),%rsi
mov    %rbx,%rdi
mov    %r14,%rdx
call   1050 <sscanf@plt>
mov    %eax,%ecx
xor    %eax,%eax
cmp    $0x1,%ecx
jne    11d3 <load_int+0xa3>
mov    $0x1,%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"%x\00"
@.str.2 = [2 x i8] c"0\00"
@.str.3 = [3 x i8] c"%o\00"
@.str.4 = [3 x i8] c"%d\00"
define i32 @load_int(i8* %0, i32* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i32*
%6 = alloca i8*
store i8* %0, i8** %4
store i32* %1, i32** %5
%7 = load i8*, i8** %4
store i8* %7, i8** %6
%8 = load i8*, i8** %4
%9 = icmp ne i8* %8, null
%10 = zext i1 %9 to i32
%11 = call i32 @assert(i32 %10)
%12 = load i32*, i32** %5
%13 = icmp ne i32* %12, null
%14 = zext i1 %13 to i32
%15 = call i32 @assert(i32 %14)
%16 = load i32*, i32** %5
store i32 0, i32* %16
br label %17
17: ; preds = %29, %2
%18 = load i8*, i8** %6
%19 = load i8, i8* %18
%20 = sext i8 %19 to i32
%21 = icmp eq i32 %20, 32
br i1 %21, label %27, label %22
22: ; preds = %17
%23 = load i8*, i8** %6
%24 = load i8, i8* %23
%25 = sext i8 %24 to i32
%26 = icmp eq i32 %25, 9
br label %27
27: ; preds = %22, %17
%28 = phi i1 [ true, %17 ], [ %26, %22 ]
br i1 %28, label %29, label %32
29: ; preds = %27
%30 = load i8*, i8** %6
%31 = getelementptr inbounds i8, i8* %30, i32 1
store i8* %31, i8** %6
br label %17
32: ; preds = %27
%33 = load i8*, i8** %6
%34 = call i64 @strncmp(i8* %33, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 2)
%35 = icmp eq i64 %34, 0
br i1 %35, label %36, label %43
36: ; preds = %32
%37 = load i8*, i8** %6
%38 = load i32*, i32** %5
%39 = call i32 @sscanf(i8* %37, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %38)
%40 = icmp ne i32 %39, 1
br i1 %40, label %41, label %42
41: ; preds = %36
store i32 0, i32* %3
br label %63
42: ; preds = %36
br label %62
43: ; preds = %32
%44 = load i8*, i8** %6
%45 = call i64 @strncmp(i8* %44, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0), i32 1)
%46 = icmp eq i64 %45, 0
br i1 %46, label %47, label %54
47: ; preds = %43
%48 = load i8*, i8** %6
%49 = load i32*, i32** %5
%50 = call i32 @sscanf(i8* %48, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32* %49)
%51 = icmp ne i32 %50, 1
br i1 %51, label %52, label %53
52: ; preds = %47
store i32 0, i32* %3
br label %63
53: ; preds = %47
br label %61
54: ; preds = %43
%55 = load i8*, i8** %6
%56 = load i32*, i32** %5
%57 = call i32 @sscanf(i8* %55, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i32* %56)
%58 = icmp ne i32 %57, 1
br i1 %58, label %59, label %60
59: ; preds = %54
store i32 0, i32* %3
br label %63
60: ; preds = %54
br label %61
61: ; preds = %60, %53
br label %62
62: ; preds = %61, %42
store i32 1, i32* %3
br label %63
63: ; preds = %62, %59, %52, %41
%64 = load i32, i32* %3
ret i32 %64
}

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