#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*/ fprintf(int /*<<< orphan*/, char *, char *);
int /*<<< orphan*/ stderr;
scalar_t__ strncasecmp(char *, char *, int);
long strtol(char *, char **, int);
int parse_int(char *str) {
  int base = 10;
  long val;
  char *end;
  end = str;
  if (strncasecmp(end, "0x", 2) == 0) {
    base = 16;
    end = end + 2;
  }
  val = strtol(end, &end, base);
  if (*end == 0 && *str != 0)
    return val;
  else {
    fprintf(stderr, "Cannot parse load address \"%s\"\n", str);
    return -1;
  }
}


x86 assembly (clang, -O0):
<parse_int>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
movl   $0xa,-0x14(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rdi
lea    0xeaa(%rip),%rsi
mov    $0x2,%edx
call   1050 <strncasecmp@plt>
cmp    $0x0,%rax
jne    117d <parse_int+0x4d>
movl   $0x10,-0x14(%rbp)
mov    -0x28(%rbp),%rax
add    $0x2,%rax
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rdi
mov    -0x14(%rbp),%edx
lea    -0x28(%rbp),%rsi
call   1040 <strtol@plt>
mov    %rax,-0x20(%rbp)
mov    -0x28(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
jne    11bd <parse_int+0x8d>
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     11bd <parse_int+0x8d>
mov    -0x20(%rbp),%rax
mov    %eax,-0x4(%rbp)
jmp    11dd <parse_int+0xad>
mov    0x2e1c(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rdx
lea    0xe32(%rip),%rsi
call   1030 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<parse_int>:
push   %rbx
sub    $0x10,%rsp
mov    %rdi,%rbx
mov    %rdi,0x8(%rsp)
lea    0xebc(%rip),%rsi
mov    $0x2,%edx
call   1050 <strncasecmp@plt>
mov    $0xa,%edx
mov    %rbx,%rdi
test   %rax,%rax
jne    1169 <parse_int+0x39>
lea    0x2(%rbx),%rdi
mov    %rdi,0x8(%rsp)
mov    $0x10,%edx
lea    0x8(%rsp),%rsi
call   1040 <strtol@plt>
mov    0x8(%rsp),%rcx
cmpb   $0x0,(%rcx)
jne    1182 <parse_int+0x52>
cmpb   $0x0,(%rbx)
jne    119f <parse_int+0x6f>
mov    0x2e57(%rip),%rax
mov    (%rax),%edi
lea    0xe71(%rip),%rsi
mov    %rbx,%rdx
call   1030 <fprintf@plt>
mov    $0xffffffff,%eax
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@.str = [3 x i8] c"0x\00"
@stderr = global i32 0
@.str.1 = [32 x i8] c"Cannot parse load address \22%s\22\0A\00"
define i32 @parse_int(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i64
%6 = alloca i8*
store i8* %0, i8** %3
store i32 10, i32* %4
%7 = load i8*, i8** %3
store i8* %7, i8** %6
%8 = load i8*, i8** %6
%9 = call i64 @strncasecmp(i8* %8, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 2)
%10 = icmp eq i64 %9, 0
br i1 %10, label %11, label %14
11: ; preds = %1
store i32 16, i32* %4
%12 = load i8*, i8** %6
%13 = getelementptr inbounds i8, i8* %12, i64 2
store i8* %13, i8** %6
br label %14
14: ; preds = %11, %1
%15 = load i8*, i8** %6
%16 = load i32, i32* %4
%17 = call i64 @strtol(i8* %15, i8** %6, i32 %16)
store i64 %17, i64* %5
%18 = load i8*, i8** %6
%19 = load i8, i8* %18
%20 = sext i8 %19 to i32
%21 = icmp eq i32 %20, 0
br i1 %21, label %22, label %30
22: ; preds = %14
%23 = load i8*, i8** %3
%24 = load i8, i8* %23
%25 = sext i8 %24 to i32
%26 = icmp ne i32 %25, 0
br i1 %26, label %27, label %30
27: ; preds = %22
%28 = load i64, i64* %5
%29 = trunc i64 %28 to i32
store i32 %29, i32* %2
br label %34
30: ; preds = %22, %14
%31 = load i32, i32* @stderr
%32 = load i8*, i8** %3
%33 = call i32 @fprintf(i32 %31, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.1, i64 0, i64 0), i8* %32)
store i32 -1, i32* %2
br label %34
34: ; preds = %30, %27
%35 = load i32, i32* %2
ret i32 %35
}

LLVM IR (-O2):
@.str = [3 x i8] c"0x\00"
@stderr = global i32 0
@.str.1 = [32 x i8] c"Cannot parse load address \22%s\22\0A\00"
define i32 @parse_int(i8* %0) {
%2 = alloca i8*
%3 = bitcast i8** %2 to i8*
store i8* %0, i8** %2
%4 = tail call i64 @strncasecmp(i8* %0, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 2)
%5 = icmp eq i64 %4, 0
br i1 %5, label %6, label %8
6: ; preds = %1
%7 = getelementptr inbounds i8, i8* %0, i64 2
store i8* %7, i8** %2
br label %8
8: ; preds = %6, %1
%9 = phi i8* [ %7, %6 ], [ %0, %1 ]
%10 = phi i32 [ 16, %6 ], [ 10, %1 ]
%11 = call i64 @strtol(i8* %9, i8** %2, i32 %10)
%12 = load i8*, i8** %2
%13 = load i8, i8* %12
%14 = icmp eq i8 %13, 0
br i1 %14, label %15, label %20
15: ; preds = %8
%16 = load i8, i8* %0
%17 = icmp eq i8 %16, 0
br i1 %17, label %20, label %18
18: ; preds = %15
%19 = trunc i64 %11 to i32
br label %23
20: ; preds = %15, %8
%21 = load i32, i32* @stderr
%22 = tail call i32 @fprintf(i32 %21, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.1, i64 0, i64 0), i8* %0)
br label %23
23: ; preds = %20, %18
%24 = phi i32 [ %19, %18 ], [ -1, %20 ]
ret i32 %24
}