#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 */
int /*<<< orphan*/ assert(int);
scalar_t__ errno;
unsigned long long strtoull(char const *, char **, int);
unsigned long long xstrtoull(const char *p, char **end) {
  if (*p == '0') {
    *end = (char *)p + 1;
    return 0;
  } else if ('1' <= *p && *p <= '9') {
    unsigned long long val;
    errno = 0;
    val = strtoull(p, end, 10);
    assert(errno == 0);
    return val;
  } else
    assert(0);
}


x86 assembly (clang, -O0):
<xstrtoull>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x30,%eax
jne    115c <xstrtoull+0x3c>
mov    -0x10(%rbp),%rcx
add    $0x1,%rcx
mov    -0x18(%rbp),%rax
mov    %rcx,(%rax)
movq   $0x0,-0x8(%rbp)
jmp    11d5 <xstrtoull+0xb5>
mov    -0x10(%rbp),%rax
movsbl (%rax),%ecx
mov    $0x31,%eax
cmp    %ecx,%eax
jg     11c9 <xstrtoull+0xa9>
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x39,%eax
jg     11c9 <xstrtoull+0xa9>
mov    0x2e59(%rip),%rax
movq   $0x0,(%rax)
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    $0xa,%edx
call   1030 <strtoull@plt>
mov    %rax,-0x20(%rbp)
mov    0x2e35(%rip),%rax
cmpq   $0x0,(%rax)
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1040 <assert@plt>
mov    -0x20(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    11d5 <xstrtoull+0xb5>
xor    %edi,%edi
call   1040 <assert@plt>
jmp    11d5 <xstrtoull+0xb5>
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<xstrtoull>:
push   %r14
push   %rbx
push   %rax
mov    (%rdi),%al
cmp    $0x30,%al
jne    1133 <xstrtoull+0x13>
add    $0x1,%rdi
mov    %rdi,(%rsi)
jmp    116f <xstrtoull+0x4f>
add    $0xcf,%al
cmp    $0x8,%al
ja     1168 <xstrtoull+0x48>
mov    0x2ea0(%rip),%r14
movq   $0x0,(%r14)
mov    $0xa,%edx
call   1030 <strtoull@plt>
mov    %rax,%rbx
xor    %edi,%edi
cmpq   $0x0,(%r14)
sete   %dil
call   1040 <assert@plt>
mov    %rbx,%rax
jmp    1171 <xstrtoull+0x51>
xor    %edi,%edi
call   1040 <assert@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@errno = global i64 0
define i64 @xstrtoull(i8* %0, i8** %1) {
%3 = alloca i64
%4 = alloca i8*
%5 = alloca i8**
%6 = alloca i64
store i8* %0, i8** %4
store i8** %1, i8*** %5
%7 = load i8*, i8** %4
%8 = load i8, i8* %7
%9 = sext i8 %8 to i32
%10 = icmp eq i32 %9, 48
br i1 %10, label %11, label %15
11: ; preds = %2
%12 = load i8*, i8** %4
%13 = getelementptr inbounds i8, i8* %12, i64 1
%14 = load i8**, i8*** %5
store i8* %13, i8** %14
store i64 0, i64* %3
br label %37
15: ; preds = %2
%16 = load i8*, i8** %4
%17 = load i8, i8* %16
%18 = sext i8 %17 to i32
%19 = icmp sle i32 49, %18
br i1 %19, label %20, label %34
20: ; preds = %15
%21 = load i8*, i8** %4
%22 = load i8, i8* %21
%23 = sext i8 %22 to i32
%24 = icmp sle i32 %23, 57
br i1 %24, label %25, label %34
25: ; preds = %20
store i64 0, i64* @errno
%26 = load i8*, i8** %4
%27 = load i8**, i8*** %5
%28 = call i64 @strtoull(i8* %26, i8** %27, i32 10)
store i64 %28, i64* %6
%29 = load i64, i64* @errno
%30 = icmp eq i64 %29, 0
%31 = zext i1 %30 to i32
%32 = call i32 @assert(i32 %31)
%33 = load i64, i64* %6
store i64 %33, i64* %3
br label %37
34: ; preds = %20, %15
%35 = call i32 @assert(i32 0)
br label %36
36: ; preds = %34
br label %37
37: ; preds = %11, %25, %36
%38 = load i64, i64* %3
ret i64 %38
}

LLVM IR (-O2):
@errno = global i64 0
define i64 @xstrtoull(i8* %0, i8** nocapture %1) {
%3 = load i8, i8* %0
%4 = icmp eq i8 %3, 48
br i1 %4, label %5, label %7
5: ; preds = %2
%6 = getelementptr inbounds i8, i8* %0, i64 1
store i8* %6, i8** %1
br label %18
7: ; preds = %2
%8 = add i8 %3, -49
%9 = icmp ult i8 %8, 9
br i1 %9, label %10, label %16
10: ; preds = %7
store i64 0, i64* @errno
%11 = tail call i64 @strtoull(i8* %0, i8** %1, i32 10)
%12 = load i64, i64* @errno
%13 = icmp eq i64 %12, 0
%14 = zext i1 %13 to i32
%15 = tail call i32 @assert(i32 %14)
br label %18
16: ; preds = %7
%17 = tail call i32 @assert(i32 0)
br label %18
18: ; preds = %5, %10, %16
%19 = phi i64 [ 0, %5 ], [ %11, %10 ], [ undef, %16 ]
ret i64 %19
}