#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*/ EXIT_FAILURE;
scalar_t__ errno;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char const *);
int /*<<< orphan*/ stderr;
unsigned long strtoul(char const *, char **, int);
unsigned long strtoul_or_die(const char *arg) {
  char *endptr = NULL;
  errno = 0;
  unsigned long val = strtoul(arg, &endptr, 10);
  if (*arg == '\0' || *endptr != '\0') {
    do {
      fprintf(stderr,
              "Argument is not a valid non-negative decimal number: '%s'"
              "\n",
              arg);
      exit(EXIT_FAILURE);
    } while (0);
  }
  if (errno) {
    do {
      fprintf(stderr,
              "Argument parse error: '%s': %m"
              "\n",
              arg);
      exit(EXIT_FAILURE);
    } while (0);
  }
  return val;
}


x86 assembly (clang, -O0):
<strtoul_or_die>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
movq   $0x0,-0x10(%rbp)
mov    0x2e8d(%rip),%rax
movq   $0x0,(%rax)
mov    -0x8(%rbp),%rdi
lea    -0x10(%rbp),%rsi
mov    $0xa,%edx
call   1040 <strtoul@plt>
mov    %rax,-0x18(%rbp)
mov    -0x8(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     1188 <strtoul_or_die+0x58>
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     11b4 <strtoul_or_die+0x84>
jmp    118d <strtoul_or_die+0x5d>
mov    0x2e4c(%rip),%rax
mov    (%rax),%edi
mov    -0x8(%rbp),%rdx
lea    0xe5f(%rip),%rsi
call   1030 <fprintf@plt>
mov    0x2e23(%rip),%rax
mov    (%rax),%edi
call   1050 <exit@plt>
mov    0x2e1d(%rip),%rax
cmpq   $0x0,(%rax)
je     11f1 <strtoul_or_die+0xc1>
jmp    11ca <strtoul_or_die+0x9a>
mov    0x2e0f(%rip),%rax
mov    (%rax),%edi
mov    -0x8(%rbp),%rdx
lea    0xe5d(%rip),%rsi
call   1030 <fprintf@plt>
mov    0x2de6(%rip),%rax
mov    (%rax),%edi
call   1050 <exit@plt>
mov    -0x18(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<strtoul_or_die>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%rbx
movq   $0x0,(%rsp)
mov    0x2e92(%rip),%r14
movq   $0x0,(%r14)
mov    %rsp,%rsi
mov    $0xa,%edx
call   1040 <strtoul@plt>
cmpb   $0x0,(%rbx)
je     1176 <strtoul_or_die+0x46>
mov    (%rsp),%rcx
cmpb   $0x0,(%rcx)
jne    1176 <strtoul_or_die+0x46>
cmpq   $0x0,(%r14)
jne    1188 <strtoul_or_die+0x58>
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret
mov    0x2e63(%rip),%rax
mov    (%rax),%edi
lea    0xe7a(%rip),%rsi
jmp    1198 <strtoul_or_die+0x68>
mov    0x2e51(%rip),%rax
mov    (%rax),%edi
lea    0xea3(%rip),%rsi
mov    %rbx,%rdx
call   1030 <fprintf@plt>
mov    0x2e29(%rip),%rax
mov    (%rax),%edi
call   1050 <exit@plt>

LLVM IR (-O0):
@errno = global i64 0
@stderr = global i32 0
@.str = [59 x i8] c"Argument is not a valid non-negative decimal number: '%s'\0A\00"
@EXIT_FAILURE = global i32 0
@.str.1 = [32 x i8] c"Argument parse error: '%s': %m\0A\00"
define i64 @strtoul_or_die(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i64
store i8* %0, i8** %2
store i8* null, i8** %3
store i64 0, i64* @errno
%5 = load i8*, i8** %2
%6 = call i64 @strtoul(i8* %5, i8** %3, i32 10)
store i64 %6, i64* %4
%7 = load i8*, i8** %2
%8 = load i8, i8* %7
%9 = sext i8 %8 to i32
%10 = icmp eq i32 %9, 0
br i1 %10, label %16, label %11
11: ; preds = %1
%12 = load i8*, i8** %3
%13 = load i8, i8* %12
%14 = sext i8 %13 to i32
%15 = icmp ne i32 %14, 0
br i1 %15, label %16, label %24
16: ; preds = %11, %1
br label %17
17: ; preds = %16
%18 = load i32, i32* @stderr
%19 = load i8*, i8** %2
%20 = call i32 @fprintf(i32 %18, i8* getelementptr inbounds ([59 x i8], [59 x i8]* @.str, i64 0, i64 0), i8* %19)
%21 = load i32, i32* @EXIT_FAILURE
%22 = call i32 @exit(i32 %21)
unreachable
23: ; No predecessors!
br label %24
24: ; preds = %23, %11
%25 = load i64, i64* @errno
%26 = icmp ne i64 %25, 0
br i1 %26, label %27, label %35
27: ; preds = %24
br label %28
28: ; preds = %27
%29 = load i32, i32* @stderr
%30 = load i8*, i8** %2
%31 = call i32 @fprintf(i32 %29, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.1, i64 0, i64 0), i8* %30)
%32 = load i32, i32* @EXIT_FAILURE
%33 = call i32 @exit(i32 %32)
unreachable
34: ; No predecessors!
br label %35
35: ; preds = %34, %24
%36 = load i64, i64* %4
ret i64 %36
}

LLVM IR (-O2):
@errno = global i64 0
@stderr = global i32 0
@.str = [59 x i8] c"Argument is not a valid non-negative decimal number: '%s'\0A\00"
@EXIT_FAILURE = global i32 0
@.str.1 = [32 x i8] c"Argument parse error: '%s': %m\0A\00"
define i64 @strtoul_or_die(i8* %0) {
%2 = alloca i8*
%3 = bitcast i8** %2 to i8*
store i8* null, i8** %2
store i64 0, i64* @errno
%4 = call i64 @strtoul(i8* %0, i8** %2, i32 10)
%5 = load i8, i8* %0
%6 = icmp eq i8 %5, 0
br i1 %6, label %11, label %7
7: ; preds = %1
%8 = load i8*, i8** %2
%9 = load i8, i8* %8
%10 = icmp eq i8 %9, 0
br i1 %10, label %16, label %11
11: ; preds = %1, %7
%12 = load i32, i32* @stderr
%13 = tail call i32 @fprintf(i32 %12, i8* getelementptr inbounds ([59 x i8], [59 x i8]* @.str, i64 0, i64 0), i8* %0)
%14 = load i32, i32* @EXIT_FAILURE
%15 = tail call i32 @exit(i32 %14)
unreachable
16: ; preds = %7
%17 = load i64, i64* @errno
%18 = icmp eq i64 %17, 0
br i1 %18, label %24, label %19
19: ; preds = %16
%20 = load i32, i32* @stderr
%21 = tail call i32 @fprintf(i32 %20, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.1, i64 0, i64 0), i8* %0)
%22 = load i32, i32* @EXIT_FAILURE
%23 = tail call i32 @exit(i32 %22)
unreachable
24: ; preds = %16
ret i64 %4
}