#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 scalar_t__ uint64_t;

/* Variables and functions */
scalar_t__ errno;
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char const *const);
int /*<<< orphan*/ stderr;
size_t strlen(char const *const);
scalar_t__ strtoull(char const *const, int /*<<< orphan*/ *, int);
uint64_t get_uint64(const char *const str, size_t *const len) {
  uint64_t val;
  *len = strlen(str);
  errno = 0;
  val = (uint64_t)strtoull(str, NULL, 10);
  if (errno) {
    (void)fprintf(stderr, "Invalid value %s.\n", str);
    exit((1));
  }
  if (*len == 0) {
    (void)fprintf(stderr, "Value %s is an invalid size.\n", str);
    exit((1));
  }
  return val;
}


x86 assembly (clang, -O0):
<get_uint64>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    %rax,%rcx
mov    -0x10(%rbp),%rax
mov    %rcx,(%rax)
mov    0x2e6e(%rip),%rax
movq   $0x0,(%rax)
mov    -0x8(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
mov    $0xa,%edx
call   1040 <strtoull@plt>
mov    %rax,-0x18(%rbp)
mov    0x2e4a(%rip),%rax
cmpq   $0x0,(%rax)
je     11bb <get_uint64+0x7b>
mov    0x2e41(%rip),%rax
mov    (%rax),%edi
mov    -0x8(%rbp),%rdx
lea    0xe54(%rip),%rsi
call   1050 <fprintf@plt>
mov    $0x1,%edi
call   1060 <exit@plt>
mov    -0x10(%rbp),%rax
cmpq   $0x0,(%rax)
jne    11ec <get_uint64+0xac>
mov    0x2e10(%rip),%rax
mov    (%rax),%edi
mov    -0x8(%rbp),%rdx
lea    0xe36(%rip),%rsi
call   1050 <fprintf@plt>
mov    $0x1,%edi
call   1060 <exit@plt>
mov    -0x18(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_uint64>:
push   %r15
push   %r14
push   %rbx
mov    %rsi,%rbx
mov    %rdi,%r14
call   1030 <strlen@plt>
mov    %rax,(%rbx)
mov    0x2e7e(%rip),%r15
movq   $0x0,(%r15)
mov    %r14,%rdi
xor    %esi,%esi
mov    $0xa,%edx
call   1040 <strtoull@plt>
cmpq   $0x0,(%r15)
jne    1182 <get_uint64+0x42>
cmpq   $0x0,(%rbx)
je     1194 <get_uint64+0x54>
pop    %rbx
pop    %r14
pop    %r15
ret
mov    0x2e57(%rip),%rax
mov    (%rax),%edi
lea    0xe6e(%rip),%rsi
jmp    11a4 <get_uint64+0x64>
mov    0x2e45(%rip),%rax
mov    (%rax),%edi
lea    0xe6f(%rip),%rsi
mov    %r14,%rdx
call   1050 <fprintf@plt>
mov    $0x1,%edi
call   1060 <exit@plt>

LLVM IR (-O0):
@errno = global i64 0
@stderr = global i32 0
@.str = [19 x i8] c"Invalid value %s.\0A\00"
@.str.1 = [30 x i8] c"Value %s is an invalid size.\0A\00"
define i64 @get_uint64(i8* %0, i64* %1) {
%3 = alloca i8*
%4 = alloca i64*
%5 = alloca i64
store i8* %0, i8** %3
store i64* %1, i64** %4
%6 = load i8*, i8** %3
%7 = call i64 @strlen(i8* %6)
%8 = load i64*, i64** %4
store i64 %7, i64* %8
store i64 0, i64* @errno
%9 = load i8*, i8** %3
%10 = call i64 @strtoull(i8* %9, i32* null, i32 10)
store i64 %10, i64* %5
%11 = load i64, i64* @errno
%12 = icmp ne i64 %11, 0
br i1 %12, label %13, label %18
13: ; preds = %2
%14 = load i32, i32* @stderr
%15 = load i8*, i8** %3
%16 = call i32 @fprintf(i32 %14, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0), i8* %15)
%17 = call i32 @exit(i32 1)
unreachable
18: ; preds = %2
%19 = load i64*, i64** %4
%20 = load i64, i64* %19
%21 = icmp eq i64 %20, 0
br i1 %21, label %22, label %27
22: ; preds = %18
%23 = load i32, i32* @stderr
%24 = load i8*, i8** %3
%25 = call i32 @fprintf(i32 %23, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.1, i64 0, i64 0), i8* %24)
%26 = call i32 @exit(i32 1)
unreachable
27: ; preds = %18
%28 = load i64, i64* %5
ret i64 %28
}

LLVM IR (-O2):
@errno = global i64 0
@stderr = global i32 0
@.str = [19 x i8] c"Invalid value %s.\0A\00"
@.str.1 = [30 x i8] c"Value %s is an invalid size.\0A\00"
define i64 @get_uint64(i8* %0, i64* nocapture %1) {
%3 = tail call i64 @strlen(i8* dereferenceable(1) %0)
store i64 %3, i64* %1
store i64 0, i64* @errno
%4 = tail call i64 @strtoull(i8* nocapture %0, i32* null, i32 10)
%5 = load i64, i64* @errno
%6 = icmp eq i64 %5, 0
br i1 %6, label %11, label %7
7: ; preds = %2
%8 = load i32, i32* @stderr
%9 = tail call i32 @fprintf(i32 %8, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0), i8* %0)
%10 = tail call i32 @exit(i32 1)
unreachable
11: ; preds = %2
%12 = load i64, i64* %1
%13 = icmp eq i64 %12, 0
br i1 %13, label %14, label %18
14: ; preds = %11
%15 = load i32, i32* @stderr
%16 = tail call i32 @fprintf(i32 %15, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.1, i64 0, i64 0), i8* %0)
%17 = tail call i32 @exit(i32 1)
unreachable
18: ; preds = %11
ret i64 %4
}