#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*/ uint64_t;

/* Variables and functions */
scalar_t__ errno;
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char const *, int, ...);
int /*<<< orphan*/ stderr;
char *strerror(scalar_t__);
int /*<<< orphan*/ strtoull(char const *, int /*<<< orphan*/, int);
int test(const char *str, uint64_t want, int base) {
  uint64_t val;
  errno = 0;
  val = strtoull(str, 0, base);
  if (errno != 0) {
    fprintf(stderr, "strtoull(\"%s\", 0, %d): %s\n", str, base,
            strerror(errno));
    return 1;
  }
  if (val == want)
    return 0;
  fprintf(stderr, "%llu != %llu\n", val, want);
  return 1;
}


x86 assembly (clang, -O0):
<test>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %edx,-0x18(%rbp)
mov    0x2e8f(%rip),%rax
movq   $0x0,(%rax)
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%edx
xor    %esi,%esi
call   1030 <strtoull@plt>
mov    %eax,-0x1c(%rbp)
mov    0x2e70(%rip),%rax
cmpq   $0x0,(%rax)
je     11c2 <test+0x92>
mov    0x2e67(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x2c(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x18(%rbp),%eax
mov    %eax,-0x20(%rbp)
mov    0x2e45(%rip),%rax
mov    (%rax),%rdi
call   1050 <strerror@plt>
mov    -0x2c(%rbp),%edi
mov    -0x28(%rbp),%rdx
mov    -0x20(%rbp),%ecx
mov    %rax,%r8
lea    0xe51(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    11ff <test+0xcf>
mov    -0x1c(%rbp),%eax
cmp    -0x14(%rbp),%eax
jne    11da <test+0xaa>
movl   $0x0,-0x4(%rbp)
jmp    11ff <test+0xcf>
mov    0x2dff(%rip),%rax
mov    (%rax),%edi
movslq -0x1c(%rbp),%rdx
mov    -0x14(%rbp),%ecx
lea    0xe2a(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<test>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %edx,%r15d
mov    %esi,%r14d
mov    %rdi,%rbx
mov    0x2e90(%rip),%r12
movq   $0x0,(%r12)
xor    %ebp,%ebp
xor    %esi,%esi
call   1030 <strtoull@plt>
mov    (%r12),%rdi
test   %rdi,%rdi
je     118b <test+0x5b>
mov    0x2e77(%rip),%rax
mov    (%rax),%ebp
call   1050 <strerror@plt>
lea    0xe89(%rip),%rsi
mov    %ebp,%edi
mov    %rbx,%rdx
mov    %r15d,%ecx
mov    %rax,%r8
xor    %eax,%eax
call   1040 <fprintf@plt>
jmp    11ad <test+0x7d>
cmp    %r14d,%eax
je     11b2 <test+0x82>
mov    0x2e49(%rip),%rcx
mov    (%rcx),%edi
movslq %eax,%rdx
lea    0xe78(%rip),%rsi
mov    %r14d,%ecx
xor    %eax,%eax
call   1040 <fprintf@plt>
mov    $0x1,%ebp
mov    %ebp,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@errno = global i64 0
@stderr = global i32 0
@.str = [27 x i8] c"strtoull(\22%s\22, 0, %d): %s\0A\00"
@.str.1 = [14 x i8] c"%llu != %llu\0A\00"
define i32 @test(i8* %0, i32 %1, i32 %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
store i8* %0, i8** %5
store i32 %1, i32* %6
store i32 %2, i32* %7
store i64 0, i64* @errno
%9 = load i8*, i8** %5
%10 = load i32, i32* %7
%11 = call i32 @strtoull(i8* %9, i32 0, i32 %10)
store i32 %11, i32* %8
%12 = load i64, i64* @errno
%13 = icmp ne i64 %12, 0
br i1 %13, label %14, label %21
14: ; preds = %3
%15 = load i32, i32* @stderr
%16 = load i8*, i8** %5
%17 = load i32, i32* %7
%18 = load i64, i64* @errno
%19 = call i8* @strerror(i64 %18)
%20 = call i32 (i32, i8*, i8*, i32, ...) @fprintf(i32 %15, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0), i8* %16, i32 %17, i8* %19)
store i32 1, i32* %4
br label %33
21: ; preds = %3
%22 = load i32, i32* %8
%23 = load i32, i32* %6
%24 = icmp eq i32 %22, %23
br i1 %24, label %25, label %26
25: ; preds = %21
store i32 0, i32* %4
br label %33
26: ; preds = %21
%27 = load i32, i32* @stderr
%28 = load i32, i32* %8
%29 = sext i32 %28 to i64
%30 = inttoptr i64 %29 to i8*
%31 = load i32, i32* %6
%32 = call i32 (i32, i8*, i8*, i32, ...) @fprintf(i32 %27, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0), i8* %30, i32 %31)
store i32 1, i32* %4
br label %33
33: ; preds = %26, %25, %14
%34 = load i32, i32* %4
ret i32 %34
}

LLVM IR (-O2):
@errno = global i64 0
@stderr = global i32 0
@.str = [27 x i8] c"strtoull(\22%s\22, 0, %d): %s\0A\00"
@.str.1 = [14 x i8] c"%llu != %llu\0A\00"
define i32 @test(i8* %0, i32 %1, i32 %2) {
store i64 0, i64* @errno
%4 = tail call i32 @strtoull(i8* %0, i32 0, i32 %2)
%5 = load i64, i64* @errno
%6 = icmp eq i64 %5, 0
br i1 %6, label %11, label %7
7: ; preds = %3
%8 = load i32, i32* @stderr
%9 = tail call i8* @strerror(i64 %5)
%10 = tail call i32 (i32, i8*, i8*, i32, ...) @fprintf(i32 %8, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0), i8* %0, i32 %2, i8* %9)
br label %18
11: ; preds = %3
%12 = icmp eq i32 %4, %1
br i1 %12, label %18, label %13
13: ; preds = %11
%14 = load i32, i32* @stderr
%15 = sext i32 %4 to i64
%16 = inttoptr i64 %15 to i8*
%17 = tail call i32 (i32, i8*, i8*, i32, ...) @fprintf(i32 %14, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0), i8* %16, i32 %1)
br label %18
18: ; preds = %11, %13, %7
%19 = phi i32 [ 1, %7 ], [ 1, %13 ], [ 0, %11 ]
ret i32 %19
}