#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;
int /*<<< orphan*/ fatal(char *);
int /*<<< orphan*/ snprintf(char *, int, char *, char *);
long strtol(char *, char **, int);
long stringToLong(char *str) {
  char msg[(2048)];
  char *endptr;
  long n;
  n = strtol(str, &endptr, 10);
  if (n < 0 || n == LONG_MAX || *endptr != '\0') {
    snprintf(msg, (2048), "%s: not a valid identifier", str);
    fatal(msg);
  }
  return n;
}


x86 assembly (clang, -O0):
<stringToLong>:
push   %rbp
mov    %rsp,%rbp
sub    $0x820,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
lea    -0x818(%rbp),%rsi
mov    $0xa,%edx
call   1040 <strtol@plt>
mov    %rax,-0x820(%rbp)
cmpq   $0x0,-0x820(%rbp)
jl     1193 <stringToLong+0x63>
mov    -0x820(%rbp),%rax
mov    0x2e69(%rip),%rcx
cmp    (%rcx),%rax
je     1193 <stringToLong+0x63>
mov    -0x818(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     11bb <stringToLong+0x8b>
lea    -0x810(%rbp),%rdi
mov    -0x8(%rbp),%rcx
mov    $0x800,%esi
lea    0xe56(%rip),%rdx
call   1030 <snprintf@plt>
lea    -0x810(%rbp),%rdi
call   1050 <fatal@plt>
mov    -0x820(%rbp),%rax
add    $0x820,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<stringToLong>:
push   %r15
push   %r14
push   %rbx
sub    $0x810,%rsp
mov    %rdi,%r14
lea    0x8(%rsp),%rsi
mov    $0xa,%edx
call   1040 <strtol@plt>
mov    %rax,%rbx
test   %rax,%rax
js     116c <stringToLong+0x3c>
mov    0x2e83(%rip),%rax
cmp    (%rax),%rbx
je     116c <stringToLong+0x3c>
mov    0x8(%rsp),%rax
cmpb   $0x0,(%rax)
je     1190 <stringToLong+0x60>
lea    0xe8d(%rip),%rdx
lea    0x10(%rsp),%r15
mov    %r15,%rdi
mov    $0x800,%esi
mov    %r14,%rcx
call   1030 <snprintf@plt>
mov    %r15,%rdi
call   1050 <fatal@plt>
mov    %rbx,%rax
add    $0x810,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@LONG_MAX = global i64 0
@.str = [27 x i8] c"%s: not a valid identifier\00"
define i64 @stringToLong(i8* %0) {
%2 = alloca i8*
%3 = alloca [2048 x i8]
%4 = alloca i8*
%5 = alloca i64
store i8* %0, i8** %2
%6 = load i8*, i8** %2
%7 = call i64 @strtol(i8* %6, i8** %4, i32 10)
store i64 %7, i64* %5
%8 = load i64, i64* %5
%9 = icmp slt i64 %8, 0
br i1 %9, label %19, label %10
10: ; preds = %1
%11 = load i64, i64* %5
%12 = load i64, i64* @LONG_MAX
%13 = icmp eq i64 %11, %12
br i1 %13, label %19, label %14
14: ; preds = %10
%15 = load i8*, i8** %4
%16 = load i8, i8* %15
%17 = sext i8 %16 to i32
%18 = icmp ne i32 %17, 0
br i1 %18, label %19, label %25
19: ; preds = %14, %10, %1
%20 = getelementptr inbounds [2048 x i8], [2048 x i8]* %3, i64 0, i64 0
%21 = load i8*, i8** %2
%22 = call i32 @snprintf(i8* %20, i32 2048, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0), i8* %21)
%23 = getelementptr inbounds [2048 x i8], [2048 x i8]* %3, i64 0, i64 0
%24 = call i32 @fatal(i8* %23)
br label %25
25: ; preds = %19, %14
%26 = load i64, i64* %5
ret i64 %26
}

LLVM IR (-O2):
@LONG_MAX = global i64 0
@.str = [27 x i8] c"%s: not a valid identifier\00"
define i64 @stringToLong(i8* %0) {
%2 = alloca [2048 x i8]
%3 = alloca i8*
%4 = getelementptr inbounds [2048 x i8], [2048 x i8]* %2, i64 0, i64 0
%5 = bitcast i8** %3 to i8*
%6 = call i64 @strtol(i8* %0, i8** %3, i32 10)
%7 = icmp slt i64 %6, 0
%8 = load i64, i64* @LONG_MAX
%9 = icmp eq i64 %6, %8
%10 = select i1 %7, i1 true, i1 %9
br i1 %10, label %15, label %11
11: ; preds = %1
%12 = load i8*, i8** %3
%13 = load i8, i8* %12
%14 = icmp eq i8 %13, 0
br i1 %14, label %18, label %15
15: ; preds = %11, %1
%16 = call i32 @snprintf(i8* %4, i32 2048, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0), i8* %0)
%17 = call i32 @fatal(i8* %4)
br label %18
18: ; preds = %15, %11
ret i64 %6
}