#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 */
unsigned long INT_MAX;
unsigned long strtoul(char const *, char **, int);
int parse_integer(const char *string, int *value_r) {
  unsigned long ul;
  char *ep;
  if (!string[0])
    return -1;
  ul = strtoul(string, &ep, 10);
  if (ul > INT_MAX || *ep != '\0')
    return -1;
  *value_r = ul;
  return 0;
}


x86 assembly (clang, -O0):
<parse_integer>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rax
cmpb   $0x0,(%rax)
jne    1139 <parse_integer+0x29>
movl   $0xffffffff,-0x4(%rbp)
jmp    1192 <parse_integer+0x82>
mov    -0x10(%rbp),%rdi
lea    -0x28(%rbp),%rsi
mov    $0xa,%edx
call   1030 <strtoul@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
mov    0x2e8e(%rip),%rcx
cmp    (%rcx),%rax
ja     1173 <parse_integer+0x63>
mov    -0x28(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     117f <parse_integer+0x6f>
movl   $0xffffffff,-0x4(%rbp)
jmp    1192 <parse_integer+0x82>
mov    -0x20(%rbp),%rax
mov    %eax,%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,(%rax)
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<parse_integer>:
push   %r14
push   %rbx
push   %rax
mov    $0xffffffff,%ebx
cmpb   $0x0,(%rdi)
je     1148 <parse_integer+0x38>
mov    %rsi,%r14
mov    %rsp,%rsi
mov    $0xa,%edx
call   1030 <strtoul@plt>
mov    0x2eb3(%rip),%rcx
cmp    (%rcx),%rax
ja     1148 <parse_integer+0x38>
mov    (%rsp),%rcx
cmpb   $0x0,(%rcx)
jne    1148 <parse_integer+0x38>
mov    %eax,(%r14)
xor    %ebx,%ebx
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@INT_MAX = global i64 0
define i32 @parse_integer(i8* %0, i32* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i32*
%6 = alloca i64
%7 = alloca i8*
store i8* %0, i8** %4
store i32* %1, i32** %5
%8 = load i8*, i8** %4
%9 = getelementptr inbounds i8, i8* %8, i64 0
%10 = load i8, i8* %9
%11 = icmp ne i8 %10, 0
br i1 %11, label %13, label %12
12: ; preds = %2
store i32 -1, i32* %3
br label %29
13: ; preds = %2
%14 = load i8*, i8** %4
%15 = call i64 @strtoul(i8* %14, i8** %7, i32 10)
store i64 %15, i64* %6
%16 = load i64, i64* %6
%17 = load i64, i64* @INT_MAX
%18 = icmp ugt i64 %16, %17
br i1 %18, label %24, label %19
19: ; preds = %13
%20 = load i8*, i8** %7
%21 = load i8, i8* %20
%22 = sext i8 %21 to i32
%23 = icmp ne i32 %22, 0
br i1 %23, label %24, label %25
24: ; preds = %19, %13
store i32 -1, i32* %3
br label %29
25: ; preds = %19
%26 = load i64, i64* %6
%27 = trunc i64 %26 to i32
%28 = load i32*, i32** %5
store i32 %27, i32* %28
store i32 0, i32* %3
br label %29
29: ; preds = %25, %24, %12
%30 = load i32, i32* %3
ret i32 %30
}

LLVM IR (-O2):
@INT_MAX = global i64 0
define i32 @parse_integer(i8* %0, i32* nocapture writeonly %1) {
%3 = alloca i8*
%4 = bitcast i8** %3 to i8*
%5 = load i8, i8* %0
%6 = icmp eq i8 %5, 0
br i1 %6, label %17, label %7
7: ; preds = %2
%8 = call i64 @strtoul(i8* %0, i8** %3, i32 10)
%9 = load i64, i64* @INT_MAX
%10 = icmp ugt i64 %8, %9
br i1 %10, label %17, label %11
11: ; preds = %7
%12 = load i8*, i8** %3
%13 = load i8, i8* %12
%14 = icmp eq i8 %13, 0
br i1 %14, label %15, label %17
15: ; preds = %11
%16 = trunc i64 %8 to i32
store i32 %16, i32* %1
br label %17
17: ; preds = %7, %11, %2, %15
%18 = phi i32 [ 0, %15 ], [ -1, %2 ], [ -1, %11 ], [ -1, %7 ]
ret i32 %18
}