#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 INT_MAX;
long INT_MIN;
size_t strlen(char const *);
long strtol(char const *, char **, int);
char parse_entire_int(const char *str, int *result) {
  size_t len = strlen(str);
  char *strtol_last_char_ptr = (char *)str;
  long tmp = strtol(str, &strtol_last_char_ptr, 10);
  if (tmp > INT_MAX || tmp < INT_MIN || strtol_last_char_ptr != str + len) {
    return 0;
  } else {
    *result = (int)tmp;
    return 1;
  }
}


x86 assembly (clang, -O0):
<parse_entire_int>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x10(%rbp),%rdi
lea    -0x28(%rbp),%rsi
mov    $0xa,%edx
call   1040 <strtol@plt>
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rax
mov    0x2e82(%rip),%rcx
cmp    (%rcx),%rax
jg     1198 <parse_entire_int+0x78>
mov    -0x30(%rbp),%rax
mov    0x2e66(%rip),%rcx
cmp    (%rcx),%rax
jl     1198 <parse_entire_int+0x78>
mov    -0x28(%rbp),%rax
mov    -0x10(%rbp),%rcx
add    -0x20(%rbp),%rcx
cmp    %rcx,%rax
je     11a1 <parse_entire_int+0x81>
movb   $0x0,-0x1(%rbp)
jmp    11b1 <parse_entire_int+0x91>
mov    -0x30(%rbp),%rax
mov    %eax,%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,(%rax)
movb   $0x1,-0x1(%rbp)
movsbl -0x1(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<parse_entire_int>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rsi,%r14
mov    %rdi,%rbx
call   1030 <strlen@plt>
mov    %rax,%r15
mov    %rbx,0x8(%rsp)
lea    0x8(%rsp),%rsi
mov    %rbx,%rdi
mov    $0xa,%edx
call   1040 <strtol@plt>
mov    %rax,%rcx
mov    0x2e90(%rip),%rdx
xor    %eax,%eax
cmp    (%rdx),%rcx
jg     117a <parse_entire_int+0x5a>
mov    0x2e7a(%rip),%rdx
cmp    (%rdx),%rcx
jl     117a <parse_entire_int+0x5a>
add    %r15,%rbx
cmp    %rbx,0x8(%rsp)
jne    117a <parse_entire_int+0x5a>
mov    %ecx,(%r14)
mov    $0x1,%al
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

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

LLVM IR (-O2):
@INT_MAX = global i64 0
@INT_MIN = global i64 0
define signext i8 @parse_entire_int(i8* %0, i32* nocapture writeonly %1) {
%3 = alloca i8*
%4 = tail call i64 @strlen(i8* dereferenceable(1) %0)
%5 = bitcast i8** %3 to i8*
store i8* %0, i8** %3
%6 = call i64 @strtol(i8* %0, i8** %3, i32 10)
%7 = load i64, i64* @INT_MAX
%8 = icmp sle i64 %6, %7
%9 = load i64, i64* @INT_MIN
%10 = icmp sge i64 %6, %9
%11 = select i1 %8, i1 %10, i1 false
%12 = load i8*, i8** %3
%13 = getelementptr inbounds i8, i8* %0, i64 %4
%14 = icmp eq i8* %12, %13
%15 = select i1 %11, i1 %14, i1 false
br i1 %15, label %16, label %18
16: ; preds = %2
%17 = trunc i64 %6 to i32
store i32 %17, i32* %1
br label %18
18: ; preds = %2, %16
%19 = phi i8 [ 1, %16 ], [ 0, %2 ]
ret i8 %19
}