#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 */
unsigned long long ULLONG_MAX;
scalar_t__ errno;
int muggle_str_lstrip_idx(char *);
unsigned long long strtoull(char const *, char **, int);
int muggle_str_toull(const char *str, unsigned long long *pval, int base) {
  char *endptr;
  if (str == NULL || pval == NULL) {
    return 0;
  }
  errno = 0;
  *pval = strtoull(str, &endptr, base);
  if (endptr == str) {
    return 0;
  } else if (*endptr != '\0') {
    if (muggle_str_lstrip_idx(endptr) != -1) {
      return 0;
    }
  }
  if (*pval == ULLONG_MAX) {
    return 0;
  }
  return 1;
}


x86 assembly (clang, -O0):
<muggle_str_toull>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     1149 <muggle_str_toull+0x29>
cmpq   $0x0,-0x18(%rbp)
jne    1155 <muggle_str_toull+0x35>
movl   $0x0,-0x4(%rbp)
jmp    11f9 <muggle_str_toull+0xd9>
mov    0x2e7c(%rip),%rax
movq   $0x0,(%rax)
mov    -0x10(%rbp),%rdi
mov    -0x1c(%rbp),%edx
lea    -0x28(%rbp),%rsi
call   1040 <strtoull@plt>
mov    %rax,%rcx
mov    -0x18(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x28(%rbp),%rax
cmp    -0x10(%rbp),%rax
jne    1197 <muggle_str_toull+0x77>
movl   $0x0,-0x4(%rbp)
jmp    11f9 <muggle_str_toull+0xd9>
mov    -0x28(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     11ca <muggle_str_toull+0xaa>
mov    -0x28(%rbp),%rdi
call   1030 <muggle_str_lstrip_idx@plt>
cmp    $0xffffffff,%eax
je     11c5 <muggle_str_toull+0xa5>
movl   $0x0,-0x4(%rbp)
jmp    11f9 <muggle_str_toull+0xd9>
jmp    11ca <muggle_str_toull+0xaa>
jmp    11cf <muggle_str_toull+0xaf>
mov    -0x18(%rbp),%rax
mov    (%rax),%rax
mov    0x2e0b(%rip),%rcx
cmp    (%rcx),%rax
jne    11f2 <muggle_str_toull+0xd2>
movl   $0x0,-0x4(%rbp)
jmp    11f9 <muggle_str_toull+0xd9>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<muggle_str_toull>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
xor    %r14d,%r14d
test   %rdi,%rdi
je     1183 <muggle_str_toull+0x63>
mov    %rsi,%rbx
test   %rsi,%rsi
je     1183 <muggle_str_toull+0x63>
mov    %rdi,%rbp
mov    0x2e96(%rip),%rax
movq   $0x0,(%rax)
lea    0x8(%rsp),%rsi
call   1040 <strtoull@plt>
mov    %rax,(%rbx)
mov    0x8(%rsp),%rdi
cmp    %rbp,%rdi
je     1183 <muggle_str_toull+0x63>
cmpb   $0x0,(%rdi)
je     1172 <muggle_str_toull+0x52>
call   1030 <muggle_str_lstrip_idx@plt>
cmp    $0xffffffff,%eax
jne    1183 <muggle_str_toull+0x63>
mov    (%rbx),%rax
mov    0x2e6f(%rip),%rcx
xor    %r14d,%r14d
cmp    (%rcx),%rax
setne  %r14b
mov    %r14d,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@errno = global i64 0
@ULLONG_MAX = global i64 0
define i32 @muggle_str_toull(i8* %0, i64* %1, i32 %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i64*
%7 = alloca i32
%8 = alloca i8*
store i8* %0, i8** %5
store i64* %1, i64** %6
store i32 %2, i32* %7
%9 = load i8*, i8** %5
%10 = icmp eq i8* %9, null
br i1 %10, label %14, label %11
11: ; preds = %3
%12 = load i64*, i64** %6
%13 = icmp eq i64* %12, null
br i1 %13, label %14, label %15
14: ; preds = %11, %3
store i32 0, i32* %4
br label %43
15: ; preds = %11
store i64 0, i64* @errno
%16 = load i8*, i8** %5
%17 = load i32, i32* %7
%18 = call i64 @strtoull(i8* %16, i8** %8, i32 %17)
%19 = load i64*, i64** %6
store i64 %18, i64* %19
%20 = load i8*, i8** %8
%21 = load i8*, i8** %5
%22 = icmp eq i8* %20, %21
br i1 %22, label %23, label %24
23: ; preds = %15
store i32 0, i32* %4
br label %43
24: ; preds = %15
%25 = load i8*, i8** %8
%26 = load i8, i8* %25
%27 = sext i8 %26 to i32
%28 = icmp ne i32 %27, 0
br i1 %28, label %29, label %35
29: ; preds = %24
%30 = load i8*, i8** %8
%31 = call i32 @muggle_str_lstrip_idx(i8* %30)
%32 = icmp ne i32 %31, -1
br i1 %32, label %33, label %34
33: ; preds = %29
store i32 0, i32* %4
br label %43
34: ; preds = %29
br label %35
35: ; preds = %34, %24
br label %36
36: ; preds = %35
%37 = load i64*, i64** %6
%38 = load i64, i64* %37
%39 = load i64, i64* @ULLONG_MAX
%40 = icmp eq i64 %38, %39
br i1 %40, label %41, label %42
41: ; preds = %36
store i32 0, i32* %4
br label %43
42: ; preds = %36
store i32 1, i32* %4
br label %43
43: ; preds = %42, %41, %33, %23, %14
%44 = load i32, i32* %4
ret i32 %44
}

LLVM IR (-O2):
@errno = global i64 0
@ULLONG_MAX = global i64 0
define i32 @muggle_str_toull(i8* %0, i64* %1, i32 %2) {
%4 = alloca i8*
%5 = bitcast i8** %4 to i8*
%6 = icmp eq i8* %0, null
%7 = icmp eq i64* %1, null
%8 = or i1 %6, %7
br i1 %8, label %26, label %9
9: ; preds = %3
store i64 0, i64* @errno
%10 = call i64 @strtoull(i8* %0, i8** %4, i32 %2)
store i64 %10, i64* %1
%11 = load i8*, i8** %4
%12 = icmp eq i8* %11, %0
br i1 %12, label %26, label %13
13: ; preds = %9
%14 = load i8, i8* %11
%15 = icmp eq i8 %14, 0
br i1 %15, label %21, label %16
16: ; preds = %13
%17 = tail call i32 @muggle_str_lstrip_idx(i8* %11)
%18 = icmp eq i32 %17, -1
br i1 %18, label %19, label %26
19: ; preds = %16
%20 = load i64, i64* %1
br label %21
21: ; preds = %19, %13
%22 = phi i64 [ %20, %19 ], [ %10, %13 ]
%23 = load i64, i64* @ULLONG_MAX
%24 = icmp ne i64 %22, %23
%25 = zext i1 %24 to i32
br label %26
26: ; preds = %21, %16, %9, %3
%27 = phi i32 [ 0, %3 ], [ 0, %9 ], [ 0, %16 ], [ %25, %21 ]
ret i32 %27
}