#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);
scalar_t__ memcmp(char const *, char *, int);
int /*<<< orphan*/ memcpy(char *, char const *, int const);
unsigned long strtoul(char *, char **, int);
int ILibGetULong(const char *TestValue, const int TestValueLength,
                 unsigned 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 = strtoul(TempBuffer, &StopString, 10);
  if (*StopString != '\0') {
    free(TempBuffer);
    free(TempBuffer2);
    return (-1);
  } else {
    free(TempBuffer);
    free(TempBuffer2);
    if (errno != ERANGE) {
      if (memcmp(TestValue, "-", 1) == 0) {
        return (-1);
      }
      return (0);
    } else {
      return (-1);
    }
  }
}


x86 assembly (clang, -O0):
<ILibGetULong>:
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   1070 <strtoul@plt>
mov    %rax,%rcx
mov    -0x20(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x28(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     11ee <ILibGetULong+0x9e>
mov    -0x38(%rbp),%rdi
call   1030 <free@plt>
mov    -0x30(%rbp),%rdi
call   1030 <free@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1258 <ILibGetULong+0x108>
mov    -0x38(%rbp),%rdi
call   1030 <free@plt>
mov    -0x30(%rbp),%rdi
call   1030 <free@plt>
mov    0x2dd1(%rip),%rax
mov    (%rax),%rax
mov    0x2dd7(%rip),%rcx
cmp    (%rcx),%rax
je     1251 <ILibGetULong+0x101>
mov    -0x10(%rbp),%rdi
lea    0xddb(%rip),%rsi
mov    $0x1,%edx
call   1040 <memcmp@plt>
cmp    $0x0,%rax
jne    1245 <ILibGetULong+0xf5>
movl   $0xffffffff,-0x4(%rbp)
jmp    1258 <ILibGetULong+0x108>
movl   $0x0,-0x4(%rbp)
jmp    1258 <ILibGetULong+0x108>
movl   $0xffffffff,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ILibGetULong>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x10,%rsp
mov    %rdx,%r12
mov    %esi,%ebp
mov    %rdi,%r14
mov    $0x14,%edi
call   1060 <malloc@plt>
mov    %rax,%r15
movslq %ebp,%rbp
lea    0x1(%rbp),%edi
call   1060 <malloc@plt>
mov    %rax,%rbx
mov    %rax,%rdi
mov    %r14,%rsi
mov    %ebp,%edx
call   1050 <memcpy@plt>
movb   $0x0,(%rbx,%rbp,1)
lea    0x8(%rsp),%rsi
mov    %rbx,%rdi
mov    $0xa,%edx
call   1070 <strtoul@plt>
mov    %rax,(%r12)
mov    0x8(%rsp),%rax
mov    (%rax),%bpl
mov    %rbx,%rdi
call   1030 <free@plt>
mov    %r15,%rdi
call   1030 <free@plt>
mov    $0xffffffff,%eax
test   %bpl,%bpl
jne    11f8 <ILibGetULong+0xa8>
mov    0x2e09(%rip),%rcx
mov    (%rcx),%rcx
mov    0x2e0f(%rip),%rdx
cmp    (%rdx),%rcx
je     11f8 <ILibGetULong+0xa8>
lea    0xe1b(%rip),%rsi
mov    %r14,%rdi
mov    $0x1,%edx
call   1040 <memcmp@plt>
cmp    $0x1,%rax
sbb    %eax,%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
@.str = [2 x i8] c"-\00"
define i32 @ILibGetULong(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 @strtoul(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 %55
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 %54
48: ; preds = %40
%49 = load i8*, i8** %5
%50 = call i64 @memcmp(i8* %49, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i32 1)
%51 = icmp eq i64 %50, 0
br i1 %51, label %52, label %53
52: ; preds = %48
store i32 -1, i32* %4
br label %55
53: ; preds = %48
store i32 0, i32* %4
br label %55
54: ; preds = %40
store i32 -1, i32* %4
br label %55
55: ; preds = %54, %53, %52, %35
%56 = load i32, i32* %4
ret i32 %56
}

LLVM IR (-O2):
@errno = global i64 0
@ERANGE = global i64 0
@.str = [2 x i8] c"-\00"
define i32 @ILibGetULong(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 @strtoul(i8* %11, i8** %4, i32 10)
store i64 %14, i64* %2
%15 = load i8*, i8** %4
%16 = load i8, i8* %15
%17 = icmp eq i8 %16, 0
%18 = tail call i32 @free(i8* %11)
%19 = tail call i32 @free(i8* %7)
br i1 %17, label %20, label %28
20: ; preds = %3
%21 = load i64, i64* @errno
%22 = load i64, i64* @ERANGE
%23 = icmp eq i64 %21, %22
br i1 %23, label %28, label %24
24: ; preds = %20
%25 = tail call i64 @memcmp(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i32 1)
%26 = icmp eq i64 %25, 0
%27 = sext i1 %26 to i32
br label %28
28: ; preds = %3, %20, %24
%29 = phi i32 [ %27, %24 ], [ -1, %20 ], [ -1, %3 ]
ret i32 %29
}