#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_MAX;
long LONG_MIN;
char *chl_get(char *);
long strtol(char *, char **, int);
int chl_geti(char *name) {
  char *val, *err;
  long int ret;
  if (!(val = chl_get(name)))
    return -1;
  ret = strtol(val, &err, 10);
  if ((val == err) || (ret == LONG_MIN) || (ret == LONG_MAX))
    return -1;
  return (int)ret;
}


x86 assembly (clang, -O0):
<chl_geti>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <chl_get@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
jne    114f <chl_geti+0x2f>
movl   $0xffffffff,-0x4(%rbp)
jmp    11ae <chl_geti+0x8e>
mov    -0x18(%rbp),%rdi
lea    -0x20(%rbp),%rsi
mov    $0xa,%edx
call   1040 <strtol@plt>
mov    %rax,-0x28(%rbp)
mov    -0x18(%rbp),%rax
cmp    -0x20(%rbp),%rax
je     119b <chl_geti+0x7b>
mov    -0x28(%rbp),%rax
mov    0x2e6a(%rip),%rcx
cmp    (%rcx),%rax
je     119b <chl_geti+0x7b>
mov    -0x28(%rbp),%rax
mov    0x2e46(%rip),%rcx
cmp    (%rcx),%rax
jne    11a7 <chl_geti+0x87>
movl   $0xffffffff,-0x4(%rbp)
jmp    11ae <chl_geti+0x8e>
mov    -0x28(%rbp),%rax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<chl_geti>:
push   %rbx
sub    $0x10,%rsp
call   1030 <chl_get@plt>
test   %rax,%rax
je     1172 <chl_geti+0x52>
mov    %rax,%rbx
lea    0x8(%rsp),%rsi
mov    %rax,%rdi
mov    $0xa,%edx
call   1040 <strtol@plt>
mov    %rax,%rcx
mov    0x2e8a(%rip),%rax
cmp    (%rax),%rcx
mov    0x2e90(%rip),%rdx
mov    $0xffffffff,%esi
mov    %ecx,%eax
cmove  %esi,%eax
cmp    (%rdx),%rcx
cmove  %esi,%eax
cmp    0x8(%rsp),%rbx
cmove  %esi,%eax
jmp    1177 <chl_geti+0x57>
mov    $0xffffffff,%eax
add    $0x10,%rsp
pop    %rbx
ret

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

LLVM IR (-O2):
@LONG_MIN = global i64 0
@LONG_MAX = global i64 0
define i32 @chl_geti(i8* %0) {
%2 = alloca i8*
%3 = bitcast i8** %2 to i8*
%4 = tail call i8* @chl_get(i8* %0)
%5 = icmp eq i8* %4, null
br i1 %5, label %18, label %6
6: ; preds = %1
%7 = call i64 @strtol(i8* %4, i8** %2, i32 10)
%8 = load i8*, i8** %2
%9 = icmp eq i8* %4, %8
%10 = load i64, i64* @LONG_MIN
%11 = icmp eq i64 %7, %10
%12 = select i1 %9, i1 true, i1 %11
%13 = load i64, i64* @LONG_MAX
%14 = icmp eq i64 %7, %13
%15 = select i1 %12, i1 true, i1 %14
%16 = trunc i64 %7 to i32
%17 = select i1 %15, i32 -1, i32 %16
br label %18
18: ; preds = %6, %1
%19 = phi i32 [ -1, %1 ], [ %17, %6 ]
ret i32 %19
}