#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 /*<<< orphan*/);
int parseLong(const char *str, int *ret) {
  errno = 0;
  char *temp;
  long val = strtol(str, &temp, 0);
  if (temp == str || *temp != '\0' ||
      ((val == LONG_MIN || val == LONG_MAX) && errno == ERANGE))
    return 1;
  *ret = (int)val;
  return 0;
}


x86 assembly (clang, -O0):
<parseLong>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    0x2ea1(%rip),%rax
movq   $0x0,(%rax)
mov    -0x10(%rbp),%rdi
lea    -0x20(%rbp),%rsi
xor    %edx,%edx
call   1030 <strtol@plt>
mov    %rax,-0x28(%rbp)
mov    -0x20(%rbp),%rax
cmp    -0x10(%rbp),%rax
je     11a1 <parseLong+0x91>
mov    -0x20(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
jne    11a1 <parseLong+0x91>
mov    -0x28(%rbp),%rax
mov    0x2e7e(%rip),%rcx
cmp    (%rcx),%rax
je     1187 <parseLong+0x77>
mov    -0x28(%rbp),%rax
mov    0x2e52(%rip),%rcx
cmp    (%rcx),%rax
jne    11ad <parseLong+0x9d>
mov    0x2e3a(%rip),%rax
mov    (%rax),%rax
mov    0x2e48(%rip),%rcx
cmp    (%rcx),%rax
jne    11ad <parseLong+0x9d>
movl   $0x1,-0x4(%rbp)
jmp    11c0 <parseLong+0xb0>
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):
<parseLong>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rsi,%r14
mov    %rdi,%rbx
mov    0x2ea2(%rip),%r15
movq   $0x0,(%r15)
lea    0x8(%rsp),%rsi
xor    %edx,%edx
call   1030 <strtol@plt>
mov    %rax,%rcx
mov    0x8(%rsp),%rdx
mov    $0x1,%eax
cmp    %rbx,%rdx
je     117c <parseLong+0x6c>
cmpb   $0x0,(%rdx)
jne    117c <parseLong+0x6c>
mov    0x2e91(%rip),%rdx
cmp    (%rdx),%rcx
je     1168 <parseLong+0x58>
mov    0x2e6d(%rip),%rdx
cmp    (%rdx),%rcx
jne    1177 <parseLong+0x67>
mov    (%r15),%rdx
mov    0x2e6e(%rip),%rsi
cmp    (%rsi),%rdx
je     117c <parseLong+0x6c>
mov    %ecx,(%r14)
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@errno = global i64 0
@LONG_MIN = global i64 0
@LONG_MAX = global i64 0
@ERANGE = global i64 0
define i32 @parseLong(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
store i64 0, i64* @errno
%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** %4
%12 = icmp eq i8* %10, %11
br i1 %12, label %30, label %13
13: ; preds = %2
%14 = load i8*, i8** %6
%15 = load i8, i8* %14
%16 = sext i8 %15 to i32
%17 = icmp ne i32 %16, 0
br i1 %17, label %30, label %18
18: ; preds = %13
%19 = load i64, i64* %7
%20 = load i64, i64* @LONG_MIN
%21 = icmp eq i64 %19, %20
br i1 %21, label %26, label %22
22: ; preds = %18
%23 = load i64, i64* %7
%24 = load i64, i64* @LONG_MAX
%25 = icmp eq i64 %23, %24
br i1 %25, label %26, label %31
26: ; preds = %22, %18
%27 = load i64, i64* @errno
%28 = load i64, i64* @ERANGE
%29 = icmp eq i64 %27, %28
br i1 %29, label %30, label %31
30: ; preds = %26, %13, %2
store i32 1, i32* %3
br label %35
31: ; preds = %26, %22
%32 = load i64, i64* %7
%33 = trunc i64 %32 to i32
%34 = load i32*, i32** %5
store i32 %33, i32* %34
store i32 0, i32* %3
br label %35
35: ; preds = %31, %30
%36 = load i32, i32* %3
ret i32 %36
}

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