#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__ errno;
unsigned long long handle_errors(unsigned long long, char **, char *);
int /*<<< orphan*/ isalnum(char const);
unsigned long long ret_ERANGE();
unsigned long long strtoull(char const *, char **, int);
unsigned long long bb_strtoull(const char *arg, char **endp, int base) {
  unsigned long long v;
  char *endptr;
  if (!isalnum(arg[0]))
    return ret_ERANGE();
  errno = 0;
  v = strtoull(arg, &endptr, base);
  return handle_errors(v, endp, endptr);
}


x86 assembly (clang, -O0):
<bb_strtoull>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
mov    -0x10(%rbp),%rax
movsbl (%rax),%edi
call   1040 <isalnum@plt>
cmp    $0x0,%eax
jne    1178 <bb_strtoull+0x38>
mov    $0x0,%al
call   1030 <ret_ERANGE@plt>
mov    %rax,-0x8(%rbp)
jmp    11af <bb_strtoull+0x6f>
mov    0x2e61(%rip),%rax
movq   $0x0,(%rax)
mov    -0x10(%rbp),%rdi
mov    -0x1c(%rbp),%edx
lea    -0x30(%rbp),%rsi
call   1050 <strtoull@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x30(%rbp),%rdx
call   1060 <handle_errors@plt>
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<bb_strtoull>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %edx,%ebp
mov    %rsi,%r14
mov    %rdi,%rbx
movsbl (%rdi),%edi
call   1040 <isalnum@plt>
test   %eax,%eax
je     1191 <bb_strtoull+0x51>
mov    0x2e7d(%rip),%rax
movq   $0x0,(%rax)
lea    0x8(%rsp),%rsi
mov    %rbx,%rdi
mov    %ebp,%edx
call   1050 <strtoull@plt>
mov    0x8(%rsp),%rdx
mov    %rax,%rdi
mov    %r14,%rsi
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
jmp    1060 <handle_errors@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
jmp    1030 <ret_ERANGE@plt>

LLVM IR (-O0):
@errno = global i64 0
define i64 @bb_strtoull(i8* %0, i8** %1, i32 %2) {
%4 = alloca i64
%5 = alloca i8*
%6 = alloca i8**
%7 = alloca i32
%8 = alloca i64
%9 = alloca i8*
store i8* %0, i8** %5
store i8** %1, i8*** %6
store i32 %2, i32* %7
%10 = load i8*, i8** %5
%11 = getelementptr inbounds i8, i8* %10, i64 0
%12 = load i8, i8* %11
%13 = call i32 @isalnum(i8 signext %12)
%14 = icmp ne i32 %13, 0
br i1 %14, label %17, label %15
15: ; preds = %3
%16 = call i64 (...) @ret_ERANGE()
store i64 %16, i64* %4
br label %25
17: ; preds = %3
store i64 0, i64* @errno
%18 = load i8*, i8** %5
%19 = load i32, i32* %7
%20 = call i64 @strtoull(i8* %18, i8** %9, i32 %19)
store i64 %20, i64* %8
%21 = load i64, i64* %8
%22 = load i8**, i8*** %6
%23 = load i8*, i8** %9
%24 = call i64 @handle_errors(i64 %21, i8** %22, i8* %23)
store i64 %24, i64* %4
br label %25
25: ; preds = %17, %15
%26 = load i64, i64* %4
ret i64 %26
}

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