#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 */
scalar_t__ ERANGE;
long LONG_MAX;
long LONG_MIN;
scalar_t__ errno;
long strtol(char const *, char **, int);
int get_long(const char *in, long *var) {
  char *e;
  *var = strtol(in, &e, 10);
  if (e == in)
    return 0;
  if ((errno == ERANGE) && ((*var == LONG_MIN) || (*var == LONG_MAX)))
    return 0;
  return 1;
}


x86 assembly (clang, -O0):
<get_long>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
lea    -0x20(%rbp),%rsi
mov    $0xa,%edx
call   1030 <strtol@plt>
mov    %rax,%rcx
mov    -0x18(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x20(%rbp),%rax
cmp    -0x10(%rbp),%rax
jne    1156 <get_long+0x46>
movl   $0x0,-0x4(%rbp)
jmp    11b1 <get_long+0xa1>
mov    0x2e6b(%rip),%rax
mov    (%rax),%rax
mov    0x2e79(%rip),%rcx
cmp    (%rcx),%rax
jne    11aa <get_long+0x9a>
mov    -0x18(%rbp),%rax
mov    (%rax),%rax
mov    0x2e6a(%rip),%rcx
cmp    (%rcx),%rax
je     119e <get_long+0x8e>
mov    -0x18(%rbp),%rax
mov    (%rax),%rax
mov    0x2e3b(%rip),%rcx
cmp    (%rcx),%rax
jne    11aa <get_long+0x9a>
movl   $0x0,-0x4(%rbp)
jmp    11b1 <get_long+0xa1>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_long>:
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%rbx
mov    %rsp,%rsi
mov    $0xa,%edx
call   1030 <strtol@plt>
mov    %rax,%rcx
mov    %rax,(%r14)
xor    %eax,%eax
cmp    %rbx,(%rsp)
je     1168 <get_long+0x58>
mov    0x2e8c(%rip),%rdx
mov    (%rdx),%rdx
mov    0x2e9a(%rip),%rsi
cmp    (%rsi),%rdx
jne    1163 <get_long+0x53>
mov    0x2e96(%rip),%rdx
cmp    (%rdx),%rcx
je     1168 <get_long+0x58>
mov    0x2e72(%rip),%rdx
cmp    (%rdx),%rcx
je     1168 <get_long+0x58>
mov    $0x1,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

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

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