#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 /*<<< orphan*/);
int parse_int(const char *str, int *i) {
  char *end;
  long l = strtol(str, &end, 0);
  if (*end)
    return 1;
  if (l < INT_MIN || l > INT_MAX)
    return 1;
  *i = (int)l;
  return 0;
}


x86 assembly (clang, -O0):
<parse_int>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
lea    -0x20(%rbp),%rsi
xor    %edx,%edx
call   1030 <strtol@plt>
mov    %rax,-0x28(%rbp)
mov    -0x20(%rbp),%rax
cmpb   $0x0,(%rax)
je     114c <parse_int+0x3c>
movl   $0x1,-0x4(%rbp)
jmp    1193 <parse_int+0x83>
mov    -0x28(%rbp),%rax
mov    0x2e89(%rip),%rcx
cmp    (%rcx),%rax
jl     1174 <parse_int+0x64>
mov    -0x28(%rbp),%rax
mov    0x2e7d(%rip),%rcx
cmp    (%rcx),%rax
jle    1180 <parse_int+0x70>
movl   $0x1,-0x4(%rbp)
jmp    1193 <parse_int+0x83>
mov    -0x28(%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_int>:
push   %rbx
sub    $0x10,%rsp
mov    %rsi,%rbx
lea    0x8(%rsp),%rsi
xor    %edx,%edx
call   1030 <strtol@plt>
mov    %rax,%rcx
mov    0x8(%rsp),%rdx
mov    $0x1,%eax
cmpb   $0x0,(%rdx)
jne    1152 <parse_int+0x42>
mov    0x2ea3(%rip),%rdx
cmp    (%rdx),%rcx
jl     1152 <parse_int+0x42>
mov    0x2e9f(%rip),%rdx
cmp    (%rdx),%rcx
jg     1152 <parse_int+0x42>
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 @parse_int(i8* %0, i32* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i32*
%6 = alloca i8*
%7 = alloca i64
store i8* %0, i8** %4
store i32* %1, i32** %5
%8 = load i8*, i8** %4
%9 = call i64 @strtol(i8* %8, i8** %6, i32 0)
store i64 %9, i64* %7
%10 = load i8*, i8** %6
%11 = load i8, i8* %10
%12 = icmp ne i8 %11, 0
br i1 %12, label %13, label %14
13: ; preds = %2
store i32 1, i32* %3
br label %27
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
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** %5
store i32 %25, i32* %26
store i32 0, i32* %3
br label %27
27: ; preds = %23, %22, %13
%28 = load i32, i32* %3
ret i32 %28
}

LLVM IR (-O2):
@INT_MIN = global i64 0
@INT_MAX = global i64 0
define i32 @parse_int(i8* %0, i32* nocapture writeonly %1) {
%3 = alloca i8*
%4 = bitcast i8** %3 to i8*
%5 = call i64 @strtol(i8* %0, i8** %3, i32 0)
%6 = load i8*, i8** %3
%7 = load i8, i8* %6
%8 = icmp eq i8 %7, 0
br i1 %8, label %9, label %17
9: ; preds = %2
%10 = load i64, i64* @INT_MIN
%11 = icmp slt i64 %5, %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 = %9
%16 = trunc i64 %5 to i32
store i32 %16, i32* %1
br label %17
17: ; preds = %9, %2, %15
%18 = phi i32 [ 0, %15 ], [ 1, %2 ], [ 1, %9 ]
ret i32 %18
}