#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 */
typedef int /*<<< orphan*/ buf;

/* Variables and functions */
scalar_t__ ERANGE;
int /*<<< orphan*/ ULLONG_MAX;
scalar_t__ errno;
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char const *, char *);
int /*<<< orphan*/ snprintf(char *, int, char *, int /*<<< orphan*/);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ strtoull(char const *, char **, int);
int _strtoull(char const *progname) {
  char *p;
  char const spaces[] = "      ";
  char buf[32];
  errno = 0;
  strtoull(spaces, &p, 0);
  if (p != spaces || errno != ERANGE) {
    fprintf(stderr, "%s: %s: Conversion error (spaces)\n", progname, "strtoul");
    return 1;
  }
  snprintf(buf, sizeof(buf), "%llu", ULLONG_MAX);
  errno = 0;
  strtoull(buf, &p, 10);
  if (errno != 0 || *p != '\0') {
    fprintf(stderr, "%s: %s: Conversion error (ULLONG_MAX)\n", progname,
            "strtoul");
    return 1;
  }
  return 0;
}


x86 assembly (clang, -O0):
<_strtoull>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    0xebe(%rip),%eax
mov    %eax,-0x1f(%rbp)
mov    0xeb8(%rip),%ax
mov    %ax,-0x1b(%rbp)
mov    0xeb0(%rip),%al
mov    %al,-0x19(%rbp)
mov    0x2e68(%rip),%rax
movq   $0x0,(%rax)
lea    -0x1f(%rbp),%rdi
lea    -0x18(%rbp),%rsi
xor    %edx,%edx
call   1040 <strtoull@plt>
mov    -0x18(%rbp),%rax
lea    -0x1f(%rbp),%rcx
cmp    %rcx,%rax
jne    11a1 <_strtoull+0x71>
mov    0x2e3a(%rip),%rax
mov    (%rax),%rax
mov    0x2e48(%rip),%rcx
cmp    (%rcx),%rax
je     11cd <_strtoull+0x9d>
mov    0x2e28(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rdx
lea    0xe52(%rip),%rsi
lea    0xe6e(%rip),%rcx
call   1050 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    125f <_strtoull+0x12f>
lea    -0x40(%rbp),%rdi
mov    0x2e10(%rip),%rax
mov    (%rax),%ecx
mov    $0x20,%esi
lea    0xe4c(%rip),%rdx
call   1030 <snprintf@plt>
mov    0x2dd6(%rip),%rax
movq   $0x0,(%rax)
lea    -0x40(%rbp),%rdi
lea    -0x18(%rbp),%rsi
mov    $0xa,%edx
call   1040 <strtoull@plt>
mov    0x2db6(%rip),%rax
cmpq   $0x0,(%rax)
jne    122c <_strtoull+0xfc>
mov    -0x18(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     1258 <_strtoull+0x128>
mov    0x2d9d(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rdx
lea    0xdf7(%rip),%rsi
lea    0xde3(%rip),%rcx
call   1050 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    125f <_strtoull+0x12f>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<_strtoull>:
push   %r15
push   %r14
push   %rbx
sub    $0x30,%rsp
mov    %rdi,%r14
movl   $0x202020,0xb(%rsp)
movl   $0x20202020,0x8(%rsp)
20
mov    0x2e75(%rip),%r15
movq   $0x0,(%r15)
lea    0x8(%rsp),%rbx
mov    %rsp,%rsi
mov    %rbx,%rdi
xor    %edx,%edx
call   1040 <strtoull@plt>
lea    0xe94(%rip),%rsi
cmp    %rbx,(%rsp)
jne    11d7 <_strtoull+0xa7>
mov    (%r15),%rax
mov    0x2e5d(%rip),%rcx
cmp    (%rcx),%rax
jne    11d7 <_strtoull+0xa7>
mov    0x2e59(%rip),%rax
mov    (%rax),%ecx
lea    0xe9a(%rip),%rdx
lea    0x10(%rsp),%rbx
mov    %rbx,%rdi
mov    $0x20,%esi
call   1030 <snprintf@plt>
movq   $0x0,(%r15)
mov    %rsp,%rsi
mov    %rbx,%rdi
mov    $0xa,%edx
call   1040 <strtoull@plt>
lea    0xe6f(%rip),%rsi
cmpq   $0x0,(%r15)
jne    11d7 <_strtoull+0xa7>
mov    (%rsp),%rax
cmpb   $0x0,(%rax)
je     11fe <_strtoull+0xce>
mov    0x2df2(%rip),%rax
mov    (%rax),%edi
lea    0xe43(%rip),%rcx
mov    %r14,%rdx
call   1050 <fprintf@plt>
mov    $0x1,%eax
add    $0x30,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret
xor    %eax,%eax
jmp    11f4 <_strtoull+0xc4>

LLVM IR (-O0):
@__const._strtoull.spaces = [7 x i8] c" \00"
@errno = global i64 0
@ERANGE = global i64 0
@stderr = global i32 0
@.str = [35 x i8] c"%s: %s: Conversion error (spaces)\0A\00"
@.str.1 = [8 x i8] c"strtoul\00"
@.str.2 = [5 x i8] c"%llu\00"
@ULLONG_MAX = global i32 0
@.str.3 = [39 x i8] c"%s: %s: Conversion error (ULLONG_MAX)\0A\00"
define i32 @_strtoull(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca [7 x i8]
%6 = alloca [32 x i8]
store i8* %0, i8** %3
%7 = bitcast [7 x i8]* %5 to i8*
store i64 0, i64* @errno
%8 = getelementptr inbounds [7 x i8], [7 x i8]* %5, i64 0, i64 0
%9 = call i32 @strtoull(i8* %8, i8** %4, i32 0)
%10 = load i8*, i8** %4
%11 = getelementptr inbounds [7 x i8], [7 x i8]* %5, i64 0, i64 0
%12 = icmp ne i8* %10, %11
br i1 %12, label %17, label %13
13: ; preds = %1
%14 = load i64, i64* @errno
%15 = load i64, i64* @ERANGE
%16 = icmp ne i64 %14, %15
br i1 %16, label %17, label %21
17: ; preds = %13, %1
%18 = load i32, i32* @stderr
%19 = load i8*, i8** %3
%20 = call i32 @fprintf(i32 %18, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str, i64 0, i64 0), i8* %19, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0))
store i32 1, i32* %2
br label %39
21: ; preds = %13
%22 = getelementptr inbounds [32 x i8], [32 x i8]* %6, i64 0, i64 0
%23 = load i32, i32* @ULLONG_MAX
%24 = call i32 @snprintf(i8* %22, i32 32, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i32 %23)
store i64 0, i64* @errno
%25 = getelementptr inbounds [32 x i8], [32 x i8]* %6, i64 0, i64 0
%26 = call i32 @strtoull(i8* %25, i8** %4, i32 10)
%27 = load i64, i64* @errno
%28 = icmp ne i64 %27, 0
br i1 %28, label %34, label %29
29: ; preds = %21
%30 = load i8*, i8** %4
%31 = load i8, i8* %30
%32 = sext i8 %31 to i32
%33 = icmp ne i32 %32, 0
br i1 %33, label %34, label %38
34: ; preds = %29, %21
%35 = load i32, i32* @stderr
%36 = load i8*, i8** %3
%37 = call i32 @fprintf(i32 %35, i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.3, i64 0, i64 0), i8* %36, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0))
store i32 1, i32* %2
br label %39
38: ; preds = %29
store i32 0, i32* %2
br label %39
39: ; preds = %38, %34, %17
%40 = load i32, i32* %2
ret i32 %40
}

LLVM IR (-O2):
@__const._strtoull.spaces = [7 x i8] c" \00"
@errno = global i64 0
@ERANGE = global i64 0
@stderr = global i32 0
@.str = [35 x i8] c"%s: %s: Conversion error (spaces)\0A\00"
@.str.1 = [8 x i8] c"strtoul\00"
@.str.2 = [5 x i8] c"%llu\00"
@ULLONG_MAX = global i32 0
@.str.3 = [39 x i8] c"%s: %s: Conversion error (ULLONG_MAX)\0A\00"
define i32 @_strtoull(i8* %0) {
%2 = alloca i8*
%3 = alloca [7 x i8]
%4 = alloca [32 x i8]
%5 = bitcast i8** %2 to i8*
%6 = getelementptr inbounds [7 x i8], [7 x i8]* %3, i64 0, i64 0
%7 = getelementptr inbounds [32 x i8], [32 x i8]* %4, i64 0, i64 0
store i64 0, i64* @errno
%8 = call i32 @strtoull(i8* %6, i8** %2, i32 0)
%9 = load i8*, i8** %2
%10 = icmp eq i8* %9, %6
br i1 %10, label %11, label %25
11: ; preds = %1
%12 = load i64, i64* @errno
%13 = load i64, i64* @ERANGE
%14 = icmp eq i64 %12, %13
br i1 %14, label %15, label %25
15: ; preds = %11
%16 = load i32, i32* @ULLONG_MAX
%17 = call i32 @snprintf(i8* %7, i32 32, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i32 %16)
store i64 0, i64* @errno
%18 = call i32 @strtoull(i8* %7, i8** %2, i32 10)
%19 = load i64, i64* @errno
%20 = icmp eq i64 %19, 0
br i1 %20, label %21, label %25
21: ; preds = %15
%22 = load i8*, i8** %2
%23 = load i8, i8* %22
%24 = icmp eq i8 %23, 0
br i1 %24, label %29, label %25
25: ; preds = %15, %21, %1, %11
%26 = phi i8* [ getelementptr inbounds ([35 x i8], [35 x i8]* @.str, i64 0, i64 0), %11 ], [ getelementptr inbounds ([35 x i8], [35 x i8]* @.str, i64 0, i64 0), %1 ], [ getelementptr inbounds ([39 x i8], [39 x i8]* @.str.3, i64 0, i64 0), %21 ], [ getelementptr inbounds ([39 x i8], [39 x i8]* @.str.3, i64 0, i64 0), %15 ]
%27 = load i32, i32* @stderr
%28 = call i32 @fprintf(i32 %27, i8* %26, i8* %0, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0))
br label %29
29: ; preds = %25, %21
%30 = phi i32 [ 0, %21 ], [ 1, %25 ]
ret i32 %30
}