#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;
scalar_t__ errno;
int /*<<< orphan*/ free(char *);
scalar_t__ malloc(int);
int /*<<< orphan*/ memcpy(char *, char *, int);
long strtol(char *, char **, int);
int ILibGetLong(char *TestValue, int TestValueLength, long *NumericValue) {
  char *StopString;
  char *TempBuffer2 = (char *)malloc(1 + sizeof(char) * 19);
  char *TempBuffer = (char *)malloc(1 + sizeof(char) * TestValueLength);
  memcpy(TempBuffer, TestValue, TestValueLength);
  TempBuffer[TestValueLength] = '\0';
  *NumericValue = strtol(TempBuffer, &StopString, 10);
  if (*StopString != '\0') {
    free(TempBuffer);
    free(TempBuffer2);
    return (-1);
  } else {
    free(TempBuffer);
    free(TempBuffer2);
    if (errno != ERANGE) {
      return (0);
    } else {
      return (-1);
    }
  }
}


x86 assembly (clang, -O0):
<ILibGetLong>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %rdx,-0x20(%rbp)
mov    $0x14,%edi
call   1060 <malloc@plt>
mov    %rax,-0x30(%rbp)
movslq -0x14(%rbp),%rax
shl    $0x0,%rax
add    $0x1,%rax
mov    %eax,%edi
call   1060 <malloc@plt>
mov    %rax,-0x38(%rbp)
mov    -0x38(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x14(%rbp),%edx
call   1050 <memcpy@plt>
mov    -0x38(%rbp),%rax
movslq -0x14(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x38(%rbp),%rdi
lea    -0x28(%rbp),%rsi
mov    $0xa,%edx
call   1040 <strtol@plt>
mov    %rax,%rcx
mov    -0x20(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x28(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     11de <ILibGetLong+0x9e>
mov    -0x38(%rbp),%rdi
call   1030 <free@plt>
mov    -0x30(%rbp),%rdi
call   1030 <free@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    121d <ILibGetLong+0xdd>
mov    -0x38(%rbp),%rdi
call   1030 <free@plt>
mov    -0x30(%rbp),%rdi
call   1030 <free@plt>
mov    0x2de1(%rip),%rax
mov    (%rax),%rax
mov    0x2de7(%rip),%rcx
cmp    (%rcx),%rax
je     1216 <ILibGetLong+0xd6>
movl   $0x0,-0x4(%rbp)
jmp    121d <ILibGetLong+0xdd>
movl   $0xffffffff,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ILibGetLong>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x10,%rsp
mov    %rdx,%r15
mov    %esi,%ebp
mov    %rdi,%r12
mov    $0x14,%edi
call   1060 <malloc@plt>
mov    %rax,%r14
movslq %ebp,%rbp
lea    0x1(%rbp),%edi
call   1060 <malloc@plt>
mov    %rax,%rbx
mov    %rax,%rdi
mov    %r12,%rsi
mov    %ebp,%edx
call   1050 <memcpy@plt>
movb   $0x0,(%rbx,%rbp,1)
lea    0x8(%rsp),%rsi
mov    %rbx,%rdi
mov    $0xa,%edx
call   1040 <strtol@plt>
mov    %rax,(%r15)
mov    0x8(%rsp),%rax
cmpb   $0x0,(%rax)
setne  %bpl
mov    %rbx,%rdi
call   1030 <free@plt>
mov    %r14,%rdi
call   1030 <free@plt>
mov    0x2e20(%rip),%rax
mov    (%rax),%rax
mov    0x2e26(%rip),%rcx
cmp    (%rcx),%rax
sete   %al
or     %bpl,%al
movzbl %al,%eax
neg    %eax
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@errno = global i64 0
@ERANGE = global i64 0
define i32 @ILibGetLong(i8* %0, i32 %1, i64* %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i64*
%8 = alloca i8*
%9 = alloca i8*
%10 = alloca i8*
store i8* %0, i8** %5
store i32 %1, i32* %6
store i64* %2, i64** %7
%11 = call i64 @malloc(i32 20)
%12 = inttoptr i64 %11 to i8*
store i8* %12, i8** %9
%13 = load i32, i32* %6
%14 = sext i32 %13 to i64
%15 = mul i64 1, %14
%16 = add i64 1, %15
%17 = trunc i64 %16 to i32
%18 = call i64 @malloc(i32 %17)
%19 = inttoptr i64 %18 to i8*
store i8* %19, i8** %10
%20 = load i8*, i8** %10
%21 = load i8*, i8** %5
%22 = load i32, i32* %6
%23 = call i32 @memcpy(i8* %20, i8* %21, i32 %22)
%24 = load i8*, i8** %10
%25 = load i32, i32* %6
%26 = sext i32 %25 to i64
%27 = getelementptr inbounds i8, i8* %24, i64 %26
store i8 0, i8* %27
%28 = load i8*, i8** %10
%29 = call i64 @strtol(i8* %28, i8** %8, i32 10)
%30 = load i64*, i64** %7
store i64 %29, i64* %30
%31 = load i8*, i8** %8
%32 = load i8, i8* %31
%33 = sext i8 %32 to i32
%34 = icmp ne i32 %33, 0
br i1 %34, label %35, label %40
35: ; preds = %3
%36 = load i8*, i8** %10
%37 = call i32 @free(i8* %36)
%38 = load i8*, i8** %9
%39 = call i32 @free(i8* %38)
store i32 -1, i32* %4
br label %50
40: ; preds = %3
%41 = load i8*, i8** %10
%42 = call i32 @free(i8* %41)
%43 = load i8*, i8** %9
%44 = call i32 @free(i8* %43)
%45 = load i64, i64* @errno
%46 = load i64, i64* @ERANGE
%47 = icmp ne i64 %45, %46
br i1 %47, label %48, label %49
48: ; preds = %40
store i32 0, i32* %4
br label %50
49: ; preds = %40
store i32 -1, i32* %4
br label %50
50: ; preds = %49, %48, %35
%51 = load i32, i32* %4
ret i32 %51
}

LLVM IR (-O2):
@errno = global i64 0
@ERANGE = global i64 0
define i32 @ILibGetLong(i8* %0, i32 %1, i64* nocapture writeonly %2) {
%4 = alloca i8*
%5 = bitcast i8** %4 to i8*
%6 = tail call i64 @malloc(i32 20)
%7 = inttoptr i64 %6 to i8*
%8 = sext i32 %1 to i64
%9 = add i32 %1, 1
%10 = tail call i64 @malloc(i32 %9)
%11 = inttoptr i64 %10 to i8*
%12 = tail call i32 @memcpy(i8* %11, i8* %0, i32 %1)
%13 = getelementptr inbounds i8, i8* %11, i64 %8
store i8 0, i8* %13
%14 = call i64 @strtol(i8* %11, i8** %4, i32 10)
store i64 %14, i64* %2
%15 = load i8*, i8** %4
%16 = load i8, i8* %15
%17 = icmp ne i8 %16, 0
%18 = tail call i32 @free(i8* %11)
%19 = tail call i32 @free(i8* %7)
%20 = load i64, i64* @errno
%21 = load i64, i64* @ERANGE
%22 = icmp eq i64 %20, %21
%23 = select i1 %17, i1 true, i1 %22
%24 = sext i1 %23 to i32
ret i32 %24
}