#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 */
typedef int /*<<< orphan*/ buf;

/* Variables and functions */
scalar_t__ EINVAL;
scalar_t__ ERANGE;
scalar_t__ LONG_MAX;
scalar_t__ errno;
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char const *, char *);
int /*<<< orphan*/ snprintf(char *, int, char *, unsigned long);
int /*<<< orphan*/ stderr;
long strtol(char const *, char **, int);
int _strtol(char const *progname) {
  char *p;
  char const spaces[] = "      ";
  long l;
  unsigned long lu;
  char buf[32];
  errno = 0;
  strtol(spaces, &p, 0);
  if (p != spaces || errno != ERANGE) {
    fprintf(stderr, "%s: %s: Conversion error (spaces)\n", progname, "strtol");
    return 1;
  }
  lu = (unsigned long)LONG_MAX + 1;
  snprintf(buf, sizeof(buf), "-%lu", lu);
  errno = 0;
  l = strtol(buf, &p, 10);
  if (errno != 0) {
    fprintf(stderr, "%s: %s: Conversion error (-LONG_MAX - 1)\n", progname,
            "strtol");
    return 1;
  }
  lu = (unsigned long)LONG_MAX + 2;
  snprintf(buf, sizeof(buf), "-%lu", lu);
  errno = 0;
  strtol(buf, &p, 10);
  if (errno != ERANGE) {
    fprintf(stderr, "%s: %s: Conversion error (-LONG_MAX - 2)\n", progname,
            "strtol");
    return 1;
  }
  l = strtol("invalid", &p, 0);
  if (l != 0 || errno != EINVAL) {
    fprintf(stderr, "%s: %s: Conversion error (invalid input)\n", progname,
            "strtol");
    return 1;
  }
  return 0;
}


x86 assembly (clang, -O0):
<_strtol>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x10(%rbp)
mov    0xebe(%rip),%eax
mov    %eax,-0x1f(%rbp)
mov    0xeb8(%rip),%ax
mov    %ax,-0x1b(%rbp)
mov    0xeb0(%rip),%al
mov    %al,-0x19(%rbp)
mov    0x2e68(%rip),%rax
movq   $0x0,(%rax)
lea    -0x1f(%rbp),%rdi
lea    -0x18(%rbp),%rsi
xor    %edx,%edx
call   1050 <strtol@plt>
mov    -0x18(%rbp),%rax
lea    -0x1f(%rbp),%rcx
cmp    %rcx,%rax
jne    11a1 <_strtol+0x71>
mov    0x2e3a(%rip),%rax
mov    (%rax),%rax
mov    0x2e50(%rip),%rcx
cmp    (%rcx),%rax
je     11cd <_strtol+0x9d>
mov    0x2e30(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rdx
lea    0xe52(%rip),%rsi
lea    0xe6e(%rip),%rcx
call   1040 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1358 <_strtol+0x228>
mov    0x2dfc(%rip),%rax
mov    (%rax),%rax
add    $0x1,%rax
mov    %rax,-0x30(%rbp)
lea    -0x50(%rbp),%rdi
mov    -0x30(%rbp),%rcx
mov    $0x20,%esi
lea    0xe3e(%rip),%rdx
call   1030 <snprintf@plt>
mov    0x2dc9(%rip),%rax
movq   $0x0,(%rax)
lea    -0x50(%rbp),%rdi
lea    -0x18(%rbp),%rsi
mov    $0xa,%edx
call   1050 <strtol@plt>
mov    %rax,-0x28(%rbp)
mov    0x2da5(%rip),%rax
cmpq   $0x0,(%rax)
je     1259 <_strtol+0x129>
mov    0x2da4(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rdx
lea    0xdf5(%rip),%rsi
lea    0xde2(%rip),%rcx
call   1040 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1358 <_strtol+0x228>
mov    0x2d70(%rip),%rax
mov    (%rax),%rax
add    $0x2,%rax
mov    %rax,-0x30(%rbp)
lea    -0x50(%rbp),%rdi
mov    -0x30(%rbp),%rcx
mov    $0x20,%esi
lea    0xdb2(%rip),%rdx
call   1030 <snprintf@plt>
mov    0x2d3d(%rip),%rax
movq   $0x0,(%rax)
lea    -0x50(%rbp),%rdi
lea    -0x18(%rbp),%rsi
mov    $0xa,%edx
call   1050 <strtol@plt>
mov    0x2d1d(%rip),%rax
mov    (%rax),%rax
mov    0x2d33(%rip),%rcx
cmp    (%rcx),%rax
je     12ea <_strtol+0x1ba>
mov    0x2d13(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rdx
lea    0xd8e(%rip),%rsi
lea    0xd51(%rip),%rcx
call   1040 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1358 <_strtol+0x228>
lea    0xd99(%rip),%rdi
lea    -0x18(%rbp),%rsi
xor    %edx,%edx
call   1050 <strtol@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    1325 <_strtol+0x1f5>
mov    0x2cb6(%rip),%rax
mov    (%rax),%rax
mov    0x2ca4(%rip),%rcx
cmp    (%rcx),%rax
je     1351 <_strtol+0x221>
mov    0x2cac(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rdx
lea    0xd59(%rip),%rsi
lea    0xcea(%rip),%rcx
call   1040 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1358 <_strtol+0x228>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<_strtol>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x30,%rsp
mov    %rdi,%rbx
movl   $0x202020,0xb(%rsp)
movl   $0x20202020,0x8(%rsp)
20
mov    0x2e72(%rip),%r14
movq   $0x0,(%r14)
lea    0x8(%rsp),%rbp
mov    %rsp,%rsi
mov    %rbp,%rdi
xor    %edx,%edx
call   1050 <strtol@plt>
lea    0xe91(%rip),%rsi
cmp    %rbp,(%rsp)
jne    1258 <_strtol+0x128>
mov    (%r14),%rax
mov    0x2e5e(%rip),%r15
cmp    (%r15),%rax
jne    1258 <_strtol+0x128>
mov    0x2e36(%rip),%r12
mov    (%r12),%rcx
add    $0x1,%rcx
lea    0xe88(%rip),%rdx
lea    0x10(%rsp),%rbp
mov    %rbp,%rdi
mov    $0x20,%esi
call   1030 <snprintf@plt>
movq   $0x0,(%r14)
mov    %rsp,%rsi
mov    %rbp,%rdi
mov    $0xa,%edx
call   1050 <strtol@plt>
cmpq   $0x0,(%r14)
je     11e1 <_strtol+0xb1>
lea    0xe57(%rip),%rsi
jmp    1258 <_strtol+0x128>
mov    (%r12),%rcx
add    $0x2,%rcx
lea    0xe41(%rip),%rdx
lea    0x10(%rsp),%rbp
mov    %rbp,%rdi
mov    $0x20,%esi
call   1030 <snprintf@plt>
movq   $0x0,(%r14)
mov    %rsp,%rsi
mov    %rbp,%rdi
mov    $0xa,%edx
call   1050 <strtol@plt>
mov    (%r14),%rax
cmp    (%r15),%rax
jne    1251 <_strtol+0x121>
lea    0xe62(%rip),%rdi
mov    %rsp,%rsi
xor    %ebp,%ebp
xor    %edx,%edx
call   1050 <strtol@plt>
lea    0xe57(%rip),%rsi
test   %rax,%rax
jne    1258 <_strtol+0x128>
mov    (%r14),%rax
mov    0x2d76(%rip),%rcx
cmp    (%rcx),%rax
jne    1258 <_strtol+0x128>
jmp    1275 <_strtol+0x145>
lea    0xe08(%rip),%rsi
mov    0x2d79(%rip),%rax
mov    (%rax),%edi
lea    0xdc2(%rip),%rcx
mov    %rbx,%rdx
call   1040 <fprintf@plt>
mov    $0x1,%ebp
mov    %ebp,%eax
add    $0x30,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@__const._strtol.spaces = [7 x i8] c" \00"
@errno = global i64 0
@ERANGE = global i64 0
@stderr = global i32 0
@.str = [35 x i8] c"%s: %s: Conversion error (spaces)\0A\00"
@.str.1 = [7 x i8] c"strtol\00"
@LONG_MAX = global i64 0
@.str.2 = [5 x i8] c"-%lu\00"
@.str.3 = [42 x i8] c"%s: %s: Conversion error (-LONG_MAX - 1)\0A\00"
@.str.4 = [42 x i8] c"%s: %s: Conversion error (-LONG_MAX - 2)\0A\00"
@.str.5 = [8 x i8] c"invalid\00"
@EINVAL = global i64 0
@.str.6 = [42 x i8] c"%s: %s: Conversion error (invalid input)\0A\00"
define i32 @_strtol(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca [7 x i8]
%6 = alloca i64
%7 = alloca i64
%8 = alloca [32 x i8]
store i8* %0, i8** %3
%9 = bitcast [7 x i8]* %5 to i8*
store i64 0, i64* @errno
%10 = getelementptr inbounds [7 x i8], [7 x i8]* %5, i64 0, i64 0
%11 = call i64 @strtol(i8* %10, i8** %4, i32 0)
%12 = load i8*, i8** %4
%13 = getelementptr inbounds [7 x i8], [7 x i8]* %5, i64 0, i64 0
%14 = icmp ne i8* %12, %13
br i1 %14, label %19, label %15
15: ; preds = %1
%16 = load i64, i64* @errno
%17 = load i64, i64* @ERANGE
%18 = icmp ne i64 %16, %17
br i1 %18, label %19, label %23
19: ; preds = %15, %1
%20 = load i32, i32* @stderr
%21 = load i8*, i8** %3
%22 = call i32 @fprintf(i32 %20, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str, i64 0, i64 0), i8* %21, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
store i32 1, i32* %2
br label %65
23: ; preds = %15
%24 = load i64, i64* @LONG_MAX
%25 = add i64 %24, 1
store i64 %25, i64* %7
%26 = getelementptr inbounds [32 x i8], [32 x i8]* %8, i64 0, i64 0
%27 = load i64, i64* %7
%28 = call i32 @snprintf(i8* %26, i32 32, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i64 %27)
store i64 0, i64* @errno
%29 = getelementptr inbounds [32 x i8], [32 x i8]* %8, i64 0, i64 0
%30 = call i64 @strtol(i8* %29, i8** %4, i32 10)
store i64 %30, i64* %6
%31 = load i64, i64* @errno
%32 = icmp ne i64 %31, 0
br i1 %32, label %33, label %37
33: ; preds = %23
%34 = load i32, i32* @stderr
%35 = load i8*, i8** %3
%36 = call i32 @fprintf(i32 %34, i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.3, i64 0, i64 0), i8* %35, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
store i32 1, i32* %2
br label %65
37: ; preds = %23
%38 = load i64, i64* @LONG_MAX
%39 = add i64 %38, 2
store i64 %39, i64* %7
%40 = getelementptr inbounds [32 x i8], [32 x i8]* %8, i64 0, i64 0
%41 = load i64, i64* %7
%42 = call i32 @snprintf(i8* %40, i32 32, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i64 %41)
store i64 0, i64* @errno
%43 = getelementptr inbounds [32 x i8], [32 x i8]* %8, i64 0, i64 0
%44 = call i64 @strtol(i8* %43, i8** %4, i32 10)
%45 = load i64, i64* @errno
%46 = load i64, i64* @ERANGE
%47 = icmp ne i64 %45, %46
br i1 %47, label %48, label %52
48: ; preds = %37
%49 = load i32, i32* @stderr
%50 = load i8*, i8** %3
%51 = call i32 @fprintf(i32 %49, i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.4, i64 0, i64 0), i8* %50, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
store i32 1, i32* %2
br label %65
52: ; preds = %37
%53 = call i64 @strtol(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.5, i64 0, i64 0), i8** %4, i32 0)
store i64 %53, i64* %6
%54 = load i64, i64* %6
%55 = icmp ne i64 %54, 0
br i1 %55, label %60, label %56
56: ; preds = %52
%57 = load i64, i64* @errno
%58 = load i64, i64* @EINVAL
%59 = icmp ne i64 %57, %58
br i1 %59, label %60, label %64
60: ; preds = %56, %52
%61 = load i32, i32* @stderr
%62 = load i8*, i8** %3
%63 = call i32 @fprintf(i32 %61, i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.6, i64 0, i64 0), i8* %62, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
store i32 1, i32* %2
br label %65
64: ; preds = %56
store i32 0, i32* %2
br label %65
65: ; preds = %64, %60, %48, %33, %19
%66 = load i32, i32* %2
ret i32 %66
}

LLVM IR (-O2):
@__const._strtol.spaces = [7 x i8] c" \00"
@errno = global i64 0
@ERANGE = global i64 0
@stderr = global i32 0
@.str = [35 x i8] c"%s: %s: Conversion error (spaces)\0A\00"
@.str.1 = [7 x i8] c"strtol\00"
@LONG_MAX = global i64 0
@.str.2 = [5 x i8] c"-%lu\00"
@.str.3 = [42 x i8] c"%s: %s: Conversion error (-LONG_MAX - 1)\0A\00"
@.str.4 = [42 x i8] c"%s: %s: Conversion error (-LONG_MAX - 2)\0A\00"
@.str.5 = [8 x i8] c"invalid\00"
@EINVAL = global i64 0
@.str.6 = [42 x i8] c"%s: %s: Conversion error (invalid input)\0A\00"
define i32 @_strtol(i8* %0) {
%2 = alloca i8*
%3 = alloca [7 x i8]
%4 = alloca [32 x i8]
%5 = bitcast i8** %2 to i8*
%6 = getelementptr inbounds [7 x i8], [7 x i8]* %3, i64 0, i64 0
%7 = getelementptr inbounds [32 x i8], [32 x i8]* %4, i64 0, i64 0
store i64 0, i64* @errno
%8 = call i64 @strtol(i8* %6, i8** %2, i32 0)
%9 = load i8*, i8** %2
%10 = icmp eq i8* %9, %6
br i1 %10, label %11, label %37
11: ; preds = %1
%12 = load i64, i64* @errno
%13 = load i64, i64* @ERANGE
%14 = icmp eq i64 %12, %13
br i1 %14, label %15, label %37
15: ; preds = %11
%16 = load i64, i64* @LONG_MAX
%17 = add i64 %16, 1
%18 = call i32 @snprintf(i8* %7, i32 32, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i64 %17)
store i64 0, i64* @errno
%19 = call i64 @strtol(i8* %7, i8** %2, i32 10)
%20 = load i64, i64* @errno
%21 = icmp eq i64 %20, 0
br i1 %21, label %22, label %37
22: ; preds = %15
%23 = load i64, i64* @LONG_MAX
%24 = add i64 %23, 2
%25 = call i32 @snprintf(i8* %7, i32 32, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i64 %24)
store i64 0, i64* @errno
%26 = call i64 @strtol(i8* %7, i8** %2, i32 10)
%27 = load i64, i64* @errno
%28 = load i64, i64* @ERANGE
%29 = icmp eq i64 %27, %28
br i1 %29, label %30, label %37
30: ; preds = %22
%31 = call i64 @strtol(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.5, i64 0, i64 0), i8** %2, i32 0)
%32 = icmp eq i64 %31, 0
br i1 %32, label %33, label %37
33: ; preds = %30
%34 = load i64, i64* @errno
%35 = load i64, i64* @EINVAL
%36 = icmp eq i64 %34, %35
br i1 %36, label %41, label %37
37: ; preds = %30, %33, %22, %15, %1, %11
%38 = phi i8* [ getelementptr inbounds ([35 x i8], [35 x i8]* @.str, i64 0, i64 0), %11 ], [ getelementptr inbounds ([35 x i8], [35 x i8]* @.str, i64 0, i64 0), %1 ], [ getelementptr inbounds ([42 x i8], [42 x i8]* @.str.3, i64 0, i64 0), %15 ], [ getelementptr inbounds ([42 x i8], [42 x i8]* @.str.4, i64 0, i64 0), %22 ], [ getelementptr inbounds ([42 x i8], [42 x i8]* @.str.6, i64 0, i64 0), %33 ], [ getelementptr inbounds ([42 x i8], [42 x i8]* @.str.6, i64 0, i64 0), %30 ]
%39 = load i32, i32* @stderr
%40 = call i32 @fprintf(i32 %39, i8* %38, i8* %0, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
br label %41
41: ; preds = %37, %33
%42 = phi i32 [ 0, %33 ], [ 1, %37 ]
ret i32 %42
}