#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 */
long const INT_MAX;
long const INT_MIN;
long strtol(char const *, char **, int);
int ParseInt(const char *s, const char **s_end, void *out) {
  const long parsed_value = strtol(s, (char **)s_end, 10);
  if (*s_end == s || !(INT_MIN <= parsed_value && parsed_value <= INT_MAX)) {
    return 0;
  }
  *((int *)out) = (int)parsed_value;
  return 1;
}


x86 assembly (clang, -O0):
<ParseInt>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    $0xa,%edx
call   1030 <strtol@plt>
mov    %rax,-0x28(%rbp)
mov    -0x18(%rbp),%rax
mov    (%rax),%rax
cmp    -0x10(%rbp),%rax
je     1173 <ParseInt+0x63>
mov    0x2e8e(%rip),%rax
mov    (%rax),%rax
cmp    -0x28(%rbp),%rax
jg     1173 <ParseInt+0x63>
mov    -0x28(%rbp),%rax
mov    0x2e7e(%rip),%rcx
cmp    (%rcx),%rax
jle    117f <ParseInt+0x6f>
movl   $0x0,-0x4(%rbp)
jmp    1192 <ParseInt+0x82>
mov    -0x28(%rbp),%rax
mov    %eax,%ecx
mov    -0x20(%rbp),%rax
mov    %ecx,(%rax)
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ParseInt>:
push   %r15
push   %r14
push   %rbx
mov    %rdx,%r14
mov    %rsi,%r15
mov    %rdi,%rbx
mov    $0xa,%edx
call   1030 <strtol@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    %rbx,(%r15)
je     1145 <ParseInt+0x35>
test   %rcx,%rcx
js     1145 <ParseInt+0x35>
jne    1145 <ParseInt+0x35>
movl   $0x0,(%r14)
mov    $0x1,%eax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@INT_MIN = constant i64 0
@INT_MAX = constant i64 0
define i32 @ParseInt(i8* %0, i8** %1, i8* %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i8**
%7 = alloca i8*
%8 = alloca i64
store i8* %0, i8** %5
store i8** %1, i8*** %6
store i8* %2, i8** %7
%9 = load i8*, i8** %5
%10 = load i8**, i8*** %6
%11 = call i64 @strtol(i8* %9, i8** %10, i32 10)
store i64 %11, i64* %8
%12 = load i8**, i8*** %6
%13 = load i8*, i8** %12
%14 = load i8*, i8** %5
%15 = icmp eq i8* %13, %14
br i1 %15, label %24, label %16
16: ; preds = %3
%17 = load i64, i64* @INT_MIN
%18 = load i64, i64* %8
%19 = icmp sle i64 %17, %18
br i1 %19, label %20, label %24
20: ; preds = %16
%21 = load i64, i64* %8
%22 = load i64, i64* @INT_MAX
%23 = icmp sle i64 %21, %22
br i1 %23, label %25, label %24
24: ; preds = %20, %16, %3
store i32 0, i32* %4
br label %30
25: ; preds = %20
%26 = load i64, i64* %8
%27 = trunc i64 %26 to i32
%28 = load i8*, i8** %7
%29 = bitcast i8* %28 to i32*
store i32 %27, i32* %29
store i32 1, i32* %4
br label %30
30: ; preds = %25, %24
%31 = load i32, i32* %4
ret i32 %31
}

LLVM IR (-O2):
@INT_MIN = constant i64 0
@INT_MAX = constant i64 0
define i32 @ParseInt(i8* %0, i8** nocapture %1, i8* nocapture writeonly %2) {
%4 = tail call i64 @strtol(i8* %0, i8** %1, i32 10)
%5 = load i8*, i8** %1
%6 = icmp ne i8* %5, %0
%7 = icmp sgt i64 %4, -1
%8 = select i1 %6, i1 %7, i1 false
%9 = icmp eq i64 %4, 0
%10 = select i1 %8, i1 %9, i1 false
br i1 %10, label %11, label %13
11: ; preds = %3
%12 = bitcast i8* %2 to i32*
store i32 0, i32* %12
br label %13
13: ; preds = %3, %11
%14 = phi i32 [ 1, %11 ], [ 0, %3 ]
ret i32 %14
}