#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 strtol(char *, char **, int);
int parse_int(char *s) {
  int i;
  char *e;
  while (*s == ' ')
    s++;
  if (*s == '0' && (*(s + 1) == 'x' || *(s + 1) == 'X')) {
    s += 2;
    i = strtol(s, &e, 16);
    if (*e != '\0')
      return -1;
  } else {
    i = strtol(s, &e, 10);
    if (*e != '\0')
      return -1;
  }
  return i;
}


x86 assembly (clang, -O0):
<parse_int>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x20,%eax
jne    113d <parse_int+0x2d>
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x10(%rbp)
jmp    111c <parse_int+0xc>
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x30,%eax
jne    11b1 <parse_int+0xa1>
mov    -0x10(%rbp),%rax
movsbl 0x1(%rax),%eax
cmp    $0x78,%eax
je     116f <parse_int+0x5f>
mov    -0x10(%rbp),%rax
movsbl 0x1(%rax),%eax
cmp    $0x58,%eax
jne    11b1 <parse_int+0xa1>
mov    -0x10(%rbp),%rax
add    $0x2,%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
lea    -0x20(%rbp),%rsi
mov    $0x10,%edx
call   1030 <strtol@plt>
mov    %eax,-0x14(%rbp)
mov    -0x20(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     11ac <parse_int+0x9c>
movl   $0xffffffff,-0x4(%rbp)
jmp    11ed <parse_int+0xdd>
jmp    11e7 <parse_int+0xd7>
mov    -0x10(%rbp),%rdi
lea    -0x20(%rbp),%rsi
mov    $0xa,%edx
call   1030 <strtol@plt>
mov    %eax,-0x14(%rbp)
mov    -0x20(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     11e2 <parse_int+0xd2>
movl   $0xffffffff,-0x4(%rbp)
jmp    11ed <parse_int+0xdd>
jmp    11e7 <parse_int+0xd7>
mov    -0x14(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<parse_int>:
push   %rax
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
movzbl (%rdi),%eax
cmp    $0x20,%al
jne    112d <parse_int+0x1d>
add    $0x1,%rdi
jmp    1120 <parse_int+0x10>
cmp    $0x30,%al
jne    1148 <parse_int+0x38>
mov    0x1(%rdi),%al
or     $0x20,%al
cmp    $0x78,%al
jne    1148 <parse_int+0x38>
add    $0x2,%rdi
mov    %rsp,%rsi
mov    $0x10,%edx
jmp    1150 <parse_int+0x40>
mov    %rsp,%rsi
mov    $0xa,%edx
call   1030 <strtol@plt>
mov    %eax,%ecx
mov    (%rsp),%rdx
mov    $0xffffffff,%eax
cmpb   $0x0,(%rdx)
je     1167 <parse_int+0x57>
pop    %rcx
ret
mov    %ecx,%eax
pop    %rcx
ret

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

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