#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 */
int /*<<< orphan*/ EXIT_FAILURE;
scalar_t__ errno;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ strtoull(char *, char **, int);
uint64_t parse_arg(char *str) {
  char *endptr = NULL;
  uint64_t val;
  errno = 0;
  val = strtoull(str, &endptr, 10);
  if (errno != 0 || endptr == str || *endptr != '\0') {
    perror("Failed to parse command line argument.");
    exit(EXIT_FAILURE);
  }
  return val;
}


x86 assembly (clang, -O0):
<parse_arg>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
movq   $0x0,-0x10(%rbp)
mov    0x2e95(%rip),%rax
movq   $0x0,(%rax)
mov    -0x8(%rbp),%rdi
lea    -0x10(%rbp),%rsi
mov    $0xa,%edx
call   1030 <strtoull@plt>
mov    %eax,-0x14(%rbp)
mov    0x2e72(%rip),%rax
cmpq   $0x0,(%rax)
jne    1196 <parse_arg+0x66>
mov    -0x10(%rbp),%rax
cmp    -0x8(%rbp),%rax
je     1196 <parse_arg+0x66>
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     11b0 <parse_arg+0x80>
lea    0xe63(%rip),%rdi
call   1040 <perror@plt>
mov    0x2e2f(%rip),%rax
mov    (%rax),%edi
call   1050 <exit@plt>
mov    -0x14(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<parse_arg>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%rbx
movq   $0x0,(%rsp)
mov    0x2e9a(%rip),%r14
movq   $0x0,(%r14)
mov    %rsp,%rsi
mov    $0xa,%edx
call   1030 <strtoull@plt>
cmpq   $0x0,(%r14)
jne    1176 <parse_arg+0x46>
mov    (%rsp),%rcx
cmp    %rbx,%rcx
je     1176 <parse_arg+0x46>
cmpb   $0x0,(%rcx)
jne    1176 <parse_arg+0x46>
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret
lea    0xe83(%rip),%rdi
call   1040 <perror@plt>
mov    0x2e4f(%rip),%rax
mov    (%rax),%edi
call   1050 <exit@plt>

LLVM IR (-O0):
@errno = global i64 0
@.str = [39 x i8] c"Failed to parse command line argument.\00"
@EXIT_FAILURE = global i32 0
define i32 @parse_arg(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i32
store i8* %0, i8** %2
store i8* null, i8** %3
store i64 0, i64* @errno
%5 = load i8*, i8** %2
%6 = call i32 @strtoull(i8* %5, i8** %3, i32 10)
store i32 %6, i32* %4
%7 = load i64, i64* @errno
%8 = icmp ne i64 %7, 0
br i1 %8, label %18, label %9
9: ; preds = %1
%10 = load i8*, i8** %3
%11 = load i8*, i8** %2
%12 = icmp eq i8* %10, %11
br i1 %12, label %18, label %13
13: ; preds = %9
%14 = load i8*, i8** %3
%15 = load i8, i8* %14
%16 = sext i8 %15 to i32
%17 = icmp ne i32 %16, 0
br i1 %17, label %18, label %22
18: ; preds = %13, %9, %1
%19 = call i32 @perror(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str, i64 0, i64 0))
%20 = load i32, i32* @EXIT_FAILURE
%21 = call i32 @exit(i32 %20)
unreachable
22: ; preds = %13
%23 = load i32, i32* %4
ret i32 %23
}

LLVM IR (-O2):
@errno = global i64 0
@.str = [39 x i8] c"Failed to parse command line argument.\00"
@EXIT_FAILURE = global i32 0
define i32 @parse_arg(i8* %0) {
%2 = alloca i8*
%3 = bitcast i8** %2 to i8*
store i8* null, i8** %2
store i64 0, i64* @errno
%4 = call i32 @strtoull(i8* %0, i8** %2, i32 10)
%5 = load i64, i64* @errno
%6 = icmp eq i64 %5, 0
br i1 %6, label %7, label %13
7: ; preds = %1
%8 = load i8*, i8** %2
%9 = icmp eq i8* %8, %0
br i1 %9, label %13, label %10
10: ; preds = %7
%11 = load i8, i8* %8
%12 = icmp eq i8 %11, 0
br i1 %12, label %17, label %13
13: ; preds = %10, %7, %1
%14 = tail call i32 @perror(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str, i64 0, i64 0))
%15 = load i32, i32* @EXIT_FAILURE
%16 = tail call i32 @exit(i32 %15)
unreachable
17: ; preds = %10
ret i32 %4
}