#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;
long strtol(char const *, char **, int);
int read_int(int *out, const char *in) {
  char *end;
  long l = strtol(in, &end, 10);
  if (*end || l < INT_MIN || l > INT_MAX)
    return 1;
  *out = l;
  return 0;
}


x86 assembly (clang, -O0):
<read_int>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
lea    -0x20(%rbp),%rsi
mov    $0xa,%edx
call   1030 <strtol@plt>
mov    %rax,-0x28(%rbp)
mov    -0x20(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
jne    116e <read_int+0x5e>
mov    -0x28(%rbp),%rax
mov    0x2e8f(%rip),%rcx
cmp    (%rcx),%rax
jl     116e <read_int+0x5e>
mov    -0x28(%rbp),%rax
mov    0x2e83(%rip),%rcx
cmp    (%rcx),%rax
jle    117a <read_int+0x6a>
movl   $0x1,-0x4(%rbp)
jmp    118d <read_int+0x7d>
mov    -0x28(%rbp),%rax
mov    %eax,%ecx
mov    -0x10(%rbp),%rax
mov    %ecx,(%rax)
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<read_int>:
push   %rbx
sub    $0x10,%rsp
mov    %rsi,%rax
mov    %rdi,%rbx
lea    0x8(%rsp),%rsi
mov    %rax,%rdi
mov    $0xa,%edx
call   1030 <strtol@plt>
mov    %rax,%rcx
mov    0x8(%rsp),%rax
cmpb   $0x0,(%rax)
mov    $0x1,%eax
jne    115b <read_int+0x4b>
mov    0x2e9a(%rip),%rdx
cmp    (%rdx),%rcx
jl     115b <read_int+0x4b>
mov    0x2e96(%rip),%rdx
cmp    (%rdx),%rcx
jg     115b <read_int+0x4b>
mov    %ecx,(%rbx)
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
ret

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

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