#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 long INT_MAX;
long long INT_MIN;
scalar_t__ parse_ll(char *, long long *);
int parse_int(char *tok, int *rval) {
  long long ll;
  if (parse_ll(tok, &ll) != 0) {
    return -1;
  }
  if (ll > INT_MAX || ll < INT_MIN) {
    return -1;
  }
  *rval = (int)ll;
  return 0;
}


x86 assembly (clang, -O0):
<parse_int>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
lea    -0x20(%rbp),%rsi
call   1030 <parse_ll@plt>
cmp    $0x0,%rax
je     1143 <parse_int+0x33>
movl   $0xffffffff,-0x4(%rbp)
jmp    118a <parse_int+0x7a>
mov    -0x20(%rbp),%rax
mov    0x2e9a(%rip),%rcx
cmp    (%rcx),%rax
jg     116b <parse_int+0x5b>
mov    -0x20(%rbp),%rax
mov    0x2e7e(%rip),%rcx
cmp    (%rcx),%rax
jge    1177 <parse_int+0x67>
movl   $0xffffffff,-0x4(%rbp)
jmp    118a <parse_int+0x7a>
mov    -0x20(%rbp),%rax
mov    %eax,%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,(%rax)
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<parse_int>:
push   %rbx
sub    $0x10,%rsp
mov    %rsi,%rbx
lea    0x8(%rsp),%rsi
call   1030 <parse_ll@plt>
mov    %rax,%rcx
mov    $0xffffffff,%eax
test   %rcx,%rcx
jne    1150 <parse_int+0x40>
mov    0x8(%rsp),%rcx
mov    0x2ead(%rip),%rdx
cmp    (%rdx),%rcx
jg     1150 <parse_int+0x40>
mov    0x2e99(%rip),%rdx
cmp    (%rdx),%rcx
jl     1150 <parse_int+0x40>
mov    %ecx,(%rbx)
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
ret

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

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