#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 */
scalar_t__ ERANGE;
int /*<<< orphan*/ EXIT_FAILURE;
unsigned int ULONG_MAX;
scalar_t__ errno;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char const *);
int /*<<< orphan*/ stderr;
unsigned int strtoul(char const *, int /*<<< orphan*/ *, int);
unsigned int get_arg_unsigned(const char *arg, const char *name) {
  unsigned int n;
  errno = 0;
  n = strtoul(arg, NULL, 10);
  if (errno == ERANGE && n == ULONG_MAX) {
    fprintf(stderr, "Invalid argument <%s>\n", name);
    exit(EXIT_FAILURE);
  }
  return n;
}


x86 assembly (clang, -O0):
<get_arg_unsigned>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0x2e89(%rip),%rax
movq   $0x0,(%rax)
mov    -0x8(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
mov    $0xa,%edx
call   1040 <strtoul@plt>
mov    %eax,-0x14(%rbp)
mov    0x2e66(%rip),%rax
mov    (%rax),%rax
mov    0x2e74(%rip),%rcx
cmp    (%rcx),%rax
jne    11b6 <get_arg_unsigned+0x86>
mov    -0x14(%rbp),%eax
mov    0x2e31(%rip),%rcx
cmp    (%rcx),%eax
jne    11b6 <get_arg_unsigned+0x86>
mov    0x2e42(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rdx
lea    0xe5d(%rip),%rsi
call   1030 <fprintf@plt>
mov    0x2e19(%rip),%rax
mov    (%rax),%edi
call   1050 <exit@plt>
mov    -0x14(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_arg_unsigned>:
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r14
mov    0x2e92(%rip),%rbx
movq   $0x0,(%rbx)
xor    %esi,%esi
mov    $0xa,%edx
call   1040 <strtoul@plt>
mov    (%rbx),%rcx
mov    0x2e8d(%rip),%rdx
cmp    (%rdx),%rcx
jne    116b <get_arg_unsigned+0x3b>
mov    0x2e51(%rip),%rcx
cmp    (%rcx),%eax
je     1173 <get_arg_unsigned+0x43>
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret
mov    0x2e5e(%rip),%rax
mov    (%rax),%edi
lea    0xe7d(%rip),%rsi
mov    %r14,%rdx
call   1030 <fprintf@plt>
mov    0x2e36(%rip),%rax
mov    (%rax),%edi
call   1050 <exit@plt>

LLVM IR (-O0):
@errno = global i64 0
@ERANGE = global i64 0
@ULONG_MAX = global i32 0
@stderr = global i32 0
@.str = [23 x i8] c"Invalid argument <%s>\0A\00"
@EXIT_FAILURE = global i32 0
define i32 @get_arg_unsigned(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i32
store i8* %0, i8** %3
store i8* %1, i8** %4
store i64 0, i64* @errno
%6 = load i8*, i8** %3
%7 = call i32 @strtoul(i8* %6, i32* null, i32 10)
store i32 %7, i32* %5
%8 = load i64, i64* @errno
%9 = load i64, i64* @ERANGE
%10 = icmp eq i64 %8, %9
br i1 %10, label %11, label %21
11: ; preds = %2
%12 = load i32, i32* %5
%13 = load i32, i32* @ULONG_MAX
%14 = icmp eq i32 %12, %13
br i1 %14, label %15, label %21
15: ; preds = %11
%16 = load i32, i32* @stderr
%17 = load i8*, i8** %4
%18 = call i32 @fprintf(i32 %16, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0), i8* %17)
%19 = load i32, i32* @EXIT_FAILURE
%20 = call i32 @exit(i32 %19)
unreachable
21: ; preds = %11, %2
%22 = load i32, i32* %5
ret i32 %22
}

LLVM IR (-O2):
@errno = global i64 0
@ERANGE = global i64 0
@ULONG_MAX = global i32 0
@stderr = global i32 0
@.str = [23 x i8] c"Invalid argument <%s>\0A\00"
@EXIT_FAILURE = global i32 0
define i32 @get_arg_unsigned(i8* nocapture %0, i8* %1) {
store i64 0, i64* @errno
%3 = tail call i32 @strtoul(i8* nocapture %0, i32* null, i32 10)
%4 = load i64, i64* @errno
%5 = load i64, i64* @ERANGE
%6 = icmp eq i64 %4, %5
%7 = load i32, i32* @ULONG_MAX
%8 = icmp eq i32 %3, %7
%9 = select i1 %6, i1 %8, i1 false
br i1 %9, label %10, label %15
10: ; preds = %2
%11 = load i32, i32* @stderr
%12 = tail call i32 @fprintf(i32 %11, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0), i8* %1)
%13 = load i32, i32* @EXIT_FAILURE
%14 = tail call i32 @exit(i32 %13)
unreachable
15: ; preds = %2
ret i32 %3
}