#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 long UINT_MAX;
scalar_t__ errno;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int /*<<< orphan*/ stderr;
char *strerror(scalar_t__);
unsigned long strtol(char const *, char **, int);
size_t parse_size_t(const char *arg) {
  char *endptr;
  unsigned long val;
  val = strtol(arg, &endptr, 10);
  if (errno == ERANGE)
    fprintf(stderr, "Error converting argument \"%s\": %s\n", arg,
            strerror(errno));
  else if (endptr == arg)
    fprintf(stderr, "No digits found in value: %s\n", arg);
  else if (*endptr != '\0')
    fprintf(stderr, "Invalid characters after number: %s\n", endptr);
  else if (val > UINT_MAX)
    fprintf(stderr, "Number is too big: %lu\n", val);
  else
    return val;
  exit(EXIT_FAILURE);
}


x86 assembly (clang, -O0):
<parse_size_t>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
lea    -0x10(%rbp),%rsi
mov    $0xa,%edx
call   1040 <strtol@plt>
mov    %rax,-0x18(%rbp)
mov    0x2e5f(%rip),%rax
mov    (%rax),%rax
mov    0x2e6d(%rip),%rcx
cmp    (%rcx),%rax
jne    11bc <parse_size_t+0x7c>
mov    0x2e4d(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x24(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    0x2e31(%rip),%rax
mov    (%rax),%rdi
call   1060 <strerror@plt>
mov    -0x24(%rbp),%edi
mov    -0x20(%rbp),%rdx
mov    %rax,%rcx
lea    0xe50(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
jmp    1267 <parse_size_t+0x127>
mov    -0x10(%rbp),%rax
cmp    -0x8(%rbp),%rax
jne    11ea <parse_size_t+0xaa>
mov    0x2dff(%rip),%rax
mov    (%rax),%edi
mov    -0x8(%rbp),%rdx
lea    0xe46(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
jmp    1262 <parse_size_t+0x122>
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     121a <parse_size_t+0xda>
mov    0x2dcf(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rdx
lea    0xe34(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
jmp    125d <parse_size_t+0x11d>
mov    -0x18(%rbp),%rax
mov    0x2dc3(%rip),%rcx
cmp    (%rcx),%rax
jbe    124e <parse_size_t+0x10e>
mov    0x2d9b(%rip),%rax
mov    (%rax),%edi
mov    -0x18(%rbp),%rdx
lea    0xe25(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
jmp    1258 <parse_size_t+0x118>
mov    -0x18(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret
jmp    125d <parse_size_t+0x11d>
jmp    1262 <parse_size_t+0x122>
jmp    1267 <parse_size_t+0x127>
mov    0x2d52(%rip),%rax
mov    (%rax),%edi
call   1050 <exit@plt>

x86 assembly (clang, -O2):
<parse_size_t>:
push   %rbp
push   %rbx
push   %rax
mov    %rdi,%rbx
mov    %rsp,%rsi
mov    $0xa,%edx
call   1040 <strtol@plt>
mov    0x2e6e(%rip),%rcx
mov    (%rcx),%rdi
mov    0x2e7c(%rip),%rcx
cmp    (%rcx),%rdi
je     118a <parse_size_t+0x4a>
mov    (%rsp),%rdx
cmp    %rbx,%rdx
je     11b0 <parse_size_t+0x70>
cmpb   $0x0,(%rdx)
jne    11c5 <parse_size_t+0x85>
mov    0x2e6a(%rip),%rcx
cmp    (%rcx),%rax
ja     11d7 <parse_size_t+0x97>
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret
mov    0x2e3f(%rip),%rax
mov    (%rax),%ebp
call   1060 <strerror@plt>
lea    0xe61(%rip),%rsi
mov    %ebp,%edi
mov    %rbx,%rdx
mov    %rax,%rcx
xor    %eax,%eax
call   1030 <fprintf@plt>
jmp    11f1 <parse_size_t+0xb1>
mov    0x2e19(%rip),%rax
mov    (%rax),%edi
lea    0xe64(%rip),%rsi
mov    %rbx,%rdx
jmp    11ea <parse_size_t+0xaa>
mov    0x2e04(%rip),%rax
mov    (%rax),%edi
lea    0xe6d(%rip),%rsi
jmp    11ea <parse_size_t+0xaa>
mov    0x2df2(%rip),%rcx
mov    (%rcx),%edi
lea    0xe80(%rip),%rsi
mov    %rax,%rdx
xor    %eax,%eax
call   1030 <fprintf@plt>
mov    0x2dc8(%rip),%rax
mov    (%rax),%edi
call   1050 <exit@plt>

LLVM IR (-O0):
@errno = global i64 0
@ERANGE = global i64 0
@stderr = global i32 0
@.str = [36 x i8] c"Error converting argument \22%s\22: %s\0A\00"
@.str.1 = [30 x i8] c"No digits found in value: %s\0A\00"
@.str.2 = [37 x i8] c"Invalid characters after number: %s\0A\00"
@UINT_MAX = global i64 0
@.str.3 = [24 x i8] c"Number is too big: %lu\0A\00"
@EXIT_FAILURE = global i32 0
define i64 @parse_size_t(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i64
store i8* %0, i8** %2
%5 = load i8*, i8** %2
%6 = call i64 @strtol(i8* %5, i8** %3, i32 10)
store i64 %6, i64* %4
%7 = load i64, i64* @errno
%8 = load i64, i64* @ERANGE
%9 = icmp eq i64 %7, %8
br i1 %9, label %10, label %16
10: ; preds = %1
%11 = load i32, i32* @stderr
%12 = load i8*, i8** %2
%13 = load i64, i64* @errno
%14 = call i8* @strerror(i64 %13)
%15 = call i32 (i32, i8*, ...) @fprintf(i32 %11, i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str, i64 0, i64 0), i8* %12, i8* %14)
br label %46
16: ; preds = %1
%17 = load i8*, i8** %3
%18 = load i8*, i8** %2
%19 = icmp eq i8* %17, %18
br i1 %19, label %20, label %24
20: ; preds = %16
%21 = load i32, i32* @stderr
%22 = load i8*, i8** %2
%23 = call i32 (i32, i8*, ...) @fprintf(i32 %21, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.1, i64 0, i64 0), i8* %22)
br label %45
24: ; preds = %16
%25 = load i8*, i8** %3
%26 = load i8, i8* %25
%27 = sext i8 %26 to i32
%28 = icmp ne i32 %27, 0
br i1 %28, label %29, label %33
29: ; preds = %24
%30 = load i32, i32* @stderr
%31 = load i8*, i8** %3
%32 = call i32 (i32, i8*, ...) @fprintf(i32 %30, i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.2, i64 0, i64 0), i8* %31)
br label %44
33: ; preds = %24
%34 = load i64, i64* %4
%35 = load i64, i64* @UINT_MAX
%36 = icmp ugt i64 %34, %35
br i1 %36, label %37, label %41
37: ; preds = %33
%38 = load i32, i32* @stderr
%39 = load i64, i64* %4
%40 = call i32 (i32, i8*, ...) @fprintf(i32 %38, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.3, i64 0, i64 0), i64 %39)
br label %43
41: ; preds = %33
%42 = load i64, i64* %4
ret i64 %42
43: ; preds = %37
br label %44
44: ; preds = %43, %29
br label %45
45: ; preds = %44, %20
br label %46
46: ; preds = %45, %10
%47 = load i32, i32* @EXIT_FAILURE
%48 = call i32 @exit(i32 %47)
unreachable
}

LLVM IR (-O2):
@errno = global i64 0
@ERANGE = global i64 0
@stderr = global i32 0
@.str = [36 x i8] c"Error converting argument \22%s\22: %s\0A\00"
@.str.1 = [30 x i8] c"No digits found in value: %s\0A\00"
@.str.2 = [37 x i8] c"Invalid characters after number: %s\0A\00"
@UINT_MAX = global i64 0
@.str.3 = [24 x i8] c"Number is too big: %lu\0A\00"
@EXIT_FAILURE = global i32 0
define i64 @parse_size_t(i8* %0) {
%2 = alloca i8*
%3 = bitcast i8** %2 to i8*
%4 = call i64 @strtol(i8* %0, i8** %2, i32 10)
%5 = load i64, i64* @errno
%6 = load i64, i64* @ERANGE
%7 = icmp eq i64 %5, %6
br i1 %7, label %8, label %12
8: ; preds = %1
%9 = load i32, i32* @stderr
%10 = tail call i8* @strerror(i64 %5)
%11 = tail call i32 (i32, i8*, ...) @fprintf(i32 %9, i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str, i64 0, i64 0), i8* %0, i8* %10)
br label %31
12: ; preds = %1
%13 = load i8*, i8** %2
%14 = icmp eq i8* %13, %0
br i1 %14, label %15, label %18
15: ; preds = %12
%16 = load i32, i32* @stderr
%17 = tail call i32 (i32, i8*, ...) @fprintf(i32 %16, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.1, i64 0, i64 0), i8* %0)
br label %31
18: ; preds = %12
%19 = load i8, i8* %13
%20 = icmp eq i8 %19, 0
br i1 %20, label %24, label %21
21: ; preds = %18
%22 = load i32, i32* @stderr
%23 = tail call i32 (i32, i8*, ...) @fprintf(i32 %22, i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.2, i64 0, i64 0), i8* %13)
br label %31
24: ; preds = %18
%25 = load i64, i64* @UINT_MAX
%26 = icmp ugt i64 %4, %25
br i1 %26, label %27, label %30
27: ; preds = %24
%28 = load i32, i32* @stderr
%29 = tail call i32 (i32, i8*, ...) @fprintf(i32 %28, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.3, i64 0, i64 0), i64 %4)
br label %31
30: ; preds = %24
ret i64 %4
31: ; preds = %15, %27, %21, %8
%32 = load i32, i32* @EXIT_FAILURE
%33 = tail call i32 @exit(i32 %32)
unreachable
}