#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 */
typedef int ssize_t;

/* Variables and functions */
long LONG_MAX;
long LONG_MIN;
long strtol(char const *, char **, int);
ssize_t parse_integer(const char *buffer, const char **error) {
  long part;
  char *end;
  part = strtol(buffer, &end, 10);
  if ((part == LONG_MIN) || (part == LONG_MAX)) {
    *error = "Integer value is out of bounds";
    return 0;
  }
  if (*end) {
    *error = "Unexpected text after decimal integer";
    return 0;
  }
  return 1;
}


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),%rdi
lea    -0x28(%rbp),%rsi
mov    $0xa,%edx
call   1030 <strtol@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
mov    0x2ea7(%rip),%rcx
cmp    (%rcx),%rax
je     115e <parse_integer+0x4e>
mov    -0x20(%rbp),%rax
mov    0x2e83(%rip),%rcx
cmp    (%rcx),%rax
jne    1178 <parse_integer+0x68>
mov    -0x18(%rbp),%rax
lea    0xe97(%rip),%rcx
mov    %rcx,(%rax)
movl   $0x0,-0x4(%rbp)
jmp    11a6 <parse_integer+0x96>
mov    -0x28(%rbp),%rax
cmpb   $0x0,(%rax)
je     119f <parse_integer+0x8f>
mov    -0x18(%rbp),%rax
lea    0xe8f(%rip),%rcx
mov    %rcx,(%rax)
movl   $0x0,-0x4(%rbp)
jmp    11a6 <parse_integer+0x96>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<parse_integer>:
push   %rbx
sub    $0x10,%rsp
mov    %rsi,%rbx
lea    0x8(%rsp),%rsi
mov    $0xa,%edx
call   1030 <strtol@plt>
mov    0x2eba(%rip),%rdx
lea    0xecb(%rip),%rcx
cmp    (%rdx),%rax
je     1157 <parse_integer+0x47>
mov    0x2e97(%rip),%rdx
cmp    (%rdx),%rax
je     1157 <parse_integer+0x47>
mov    0x8(%rsp),%rax
cmpb   $0x0,(%rax)
je     1162 <parse_integer+0x52>
lea    0xec8(%rip),%rcx
mov    %rcx,(%rbx)
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
ret
mov    $0x1,%eax
jmp    115c <parse_integer+0x4c>

LLVM IR (-O0):
@LONG_MIN = global i64 0
@LONG_MAX = global i64 0
@.str = [31 x i8] c"Integer value is out of bounds\00"
@.str.1 = [38 x i8] c"Unexpected text after decimal integer\00"
define i32 @parse_integer(i8* %0, i8** %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i8**
%6 = alloca i64
%7 = alloca i8*
store i8* %0, i8** %4
store i8** %1, i8*** %5
%8 = load i8*, i8** %4
%9 = call i64 @strtol(i8* %8, i8** %7, i32 10)
store i64 %9, i64* %6
%10 = load i64, i64* %6
%11 = load i64, i64* @LONG_MIN
%12 = icmp eq i64 %10, %11
br i1 %12, label %17, label %13
13: ; preds = %2
%14 = load i64, i64* %6
%15 = load i64, i64* @LONG_MAX
%16 = icmp eq i64 %14, %15
br i1 %16, label %17, label %19
17: ; preds = %13, %2
%18 = load i8**, i8*** %5
store i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str, i64 0, i64 0), i8** %18
store i32 0, i32* %3
br label %26
19: ; preds = %13
%20 = load i8*, i8** %7
%21 = load i8, i8* %20
%22 = icmp ne i8 %21, 0
br i1 %22, label %23, label %25
23: ; preds = %19
%24 = load i8**, i8*** %5
store i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.1, i64 0, i64 0), i8** %24
store i32 0, i32* %3
br label %26
25: ; preds = %19
store i32 1, i32* %3
br label %26
26: ; preds = %25, %23, %17
%27 = load i32, i32* %3
ret i32 %27
}

LLVM IR (-O2):
@LONG_MIN = global i64 0
@LONG_MAX = global i64 0
@.str = [31 x i8] c"Integer value is out of bounds\00"
@.str.1 = [38 x i8] c"Unexpected text after decimal integer\00"
define i32 @parse_integer(i8* %0, i8** nocapture writeonly %1) {
%3 = alloca i8*
%4 = bitcast i8** %3 to i8*
%5 = call i64 @strtol(i8* %0, i8** %3, i32 10)
%6 = load i64, i64* @LONG_MIN
%7 = icmp eq i64 %5, %6
%8 = load i64, i64* @LONG_MAX
%9 = icmp eq i64 %5, %8
%10 = select i1 %7, i1 true, i1 %9
br i1 %10, label %15, label %11
11: ; preds = %2
%12 = load i8*, i8** %3
%13 = load i8, i8* %12
%14 = icmp eq i8 %13, 0
br i1 %14, label %17, label %15
15: ; preds = %11, %2
%16 = phi i8* [ getelementptr inbounds ([31 x i8], [31 x i8]* @.str, i64 0, i64 0), %2 ], [ getelementptr inbounds ([38 x i8], [38 x i8]* @.str.1, i64 0, i64 0), %11 ]
store i8* %16, i8** %1
br label %17
17: ; preds = %15, %11
%18 = phi i32 [ 1, %11 ], [ 0, %15 ]
ret i32 %18
}