#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;
unsigned long strtoll(char const *, char **, int);
int sasutil_get_uint(const char *str, unsigned long *value, int base) {
  char *endptr;
  unsigned long ret = strtoll(str, &endptr, base);
  if ((*endptr != '\0') || (errno == ERANGE)) {
    return -1;
  }
  *value = ret;
  return 0;
}


x86 assembly (clang, -O0):
<sasutil_get_uint>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x1c(%rbp),%edx
lea    -0x28(%rbp),%rsi
call   1030 <strtoll@plt>
mov    %rax,-0x30(%rbp)
mov    -0x28(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
jne    1161 <sasutil_get_uint+0x51>
mov    0x2e8a(%rip),%rax
mov    (%rax),%rax
mov    0x2e90(%rip),%rcx
cmp    (%rcx),%rax
jne    116d <sasutil_get_uint+0x5d>
movl   $0xffffffff,-0x4(%rbp)
jmp    117f <sasutil_get_uint+0x6f>
mov    -0x30(%rbp),%rcx
mov    -0x18(%rbp),%rax
mov    %rcx,(%rax)
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sasutil_get_uint>:
push   %rbx
sub    $0x10,%rsp
mov    %rsi,%rbx
lea    0x8(%rsp),%rsi
call   1030 <strtoll@plt>
mov    %rax,%rcx
mov    0x8(%rsp),%rdx
mov    $0xffffffff,%eax
cmpb   $0x0,(%rdx)
jne    114f <sasutil_get_uint+0x3f>
mov    0x2e9d(%rip),%rdx
mov    (%rdx),%rdx
mov    0x2ea3(%rip),%rsi
cmp    (%rsi),%rdx
je     114f <sasutil_get_uint+0x3f>
mov    %rcx,(%rbx)
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@errno = global i64 0
@ERANGE = global i64 0
define i32 @sasutil_get_uint(i8* %0, i64* %1, i32 %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i64*
%7 = alloca i32
%8 = alloca i8*
%9 = alloca i64
store i8* %0, i8** %5
store i64* %1, i64** %6
store i32 %2, i32* %7
%10 = load i8*, i8** %5
%11 = load i32, i32* %7
%12 = call i64 @strtoll(i8* %10, i8** %8, i32 %11)
store i64 %12, i64* %9
%13 = load i8*, i8** %8
%14 = load i8, i8* %13
%15 = sext i8 %14 to i32
%16 = icmp ne i32 %15, 0
br i1 %16, label %21, label %17
17: ; preds = %3
%18 = load i64, i64* @errno
%19 = load i64, i64* @ERANGE
%20 = icmp eq i64 %18, %19
br i1 %20, label %21, label %22
21: ; preds = %17, %3
store i32 -1, i32* %4
br label %25
22: ; preds = %17
%23 = load i64, i64* %9
%24 = load i64*, i64** %6
store i64 %23, i64* %24
store i32 0, i32* %4
br label %25
25: ; preds = %22, %21
%26 = load i32, i32* %4
ret i32 %26
}

LLVM IR (-O2):
@errno = global i64 0
@ERANGE = global i64 0
define i32 @sasutil_get_uint(i8* %0, i64* nocapture writeonly %1, i32 %2) {
%4 = alloca i8*
%5 = bitcast i8** %4 to i8*
%6 = call i64 @strtoll(i8* %0, i8** %4, i32 %2)
%7 = load i8*, i8** %4
%8 = load i8, i8* %7
%9 = icmp eq i8 %8, 0
br i1 %9, label %10, label %15
10: ; preds = %3
%11 = load i64, i64* @errno
%12 = load i64, i64* @ERANGE
%13 = icmp eq i64 %11, %12
br i1 %13, label %15, label %14
14: ; preds = %10
store i64 %6, i64* %1
br label %15
15: ; preds = %3, %10, %14
%16 = phi i32 [ 0, %14 ], [ -1, %10 ], [ -1, %3 ]
ret i32 %16
}