#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__ errno;
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char const *);
int /*<<< orphan*/ stderr;
long strtol(char const *, char **, int);
long parse_integer(const char *arg) {
  char *endptr = NULL;
  errno = 0;
  long value = strtol(arg, &endptr, 10);
  if (*arg == '\0' || *endptr != '\0') {
    fprintf(stderr, "Argument is not a valid decimal number: '%s'\n", arg);
    exit(1);
  }
  if (errno) {
    fprintf(stderr, "Argument parse error: '%s': %m\n", arg);
    exit(1);
  }
  return value;
}


x86 assembly (clang, -O0):
<parse_integer>:
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 <strtol@plt>
mov    %rax,-0x18(%rbp)
mov    -0x8(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     1188 <parse_integer+0x58>
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     11ab <parse_integer+0x7b>
mov    0x2e51(%rip),%rax
mov    (%rax),%edi
mov    -0x8(%rbp),%rdx
lea    0xe64(%rip),%rsi
call   1030 <fprintf@plt>
mov    $0x1,%edi
call   1050 <exit@plt>
mov    0x2e26(%rip),%rax
cmpq   $0x0,(%rax)
je     11df <parse_integer+0xaf>
mov    0x2e1d(%rip),%rax
mov    (%rax),%edi
mov    -0x8(%rbp),%rdx
lea    0xe5e(%rip),%rsi
call   1030 <fprintf@plt>
mov    $0x1,%edi
call   1050 <exit@plt>
mov    -0x18(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<parse_integer>:
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 <strtol@plt>
cmpb   $0x0,(%rbx)
je     1176 <parse_integer+0x46>
mov    (%rsp),%rcx
cmpb   $0x0,(%rcx)
jne    1176 <parse_integer+0x46>
cmpq   $0x0,(%r14)
jne    1188 <parse_integer+0x58>
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret
mov    0x2e63(%rip),%rax
mov    (%rax),%edi
lea    0xe7a(%rip),%rsi
jmp    1198 <parse_integer+0x68>
mov    0x2e51(%rip),%rax
mov    (%rax),%edi
lea    0xe96(%rip),%rsi
mov    %rbx,%rdx
call   1030 <fprintf@plt>
mov    $0x1,%edi
call   1050 <exit@plt>

LLVM IR (-O0):
@errno = global i64 0
@stderr = global i32 0
@.str = [46 x i8] c"Argument is not a valid decimal number: '%s'\0A\00"
@.str.1 = [32 x i8] c"Argument parse error: '%s': %m\0A\00"
define i64 @parse_integer(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 @strtol(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 %21
16: ; preds = %11, %1
%17 = load i32, i32* @stderr
%18 = load i8*, i8** %2
%19 = call i32 @fprintf(i32 %17, i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str, i64 0, i64 0), i8* %18)
%20 = call i32 @exit(i32 1)
unreachable
21: ; preds = %11
%22 = load i64, i64* @errno
%23 = icmp ne i64 %22, 0
br i1 %23, label %24, label %29
24: ; preds = %21
%25 = load i32, i32* @stderr
%26 = load i8*, i8** %2
%27 = call i32 @fprintf(i32 %25, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.1, i64 0, i64 0), i8* %26)
%28 = call i32 @exit(i32 1)
unreachable
29: ; preds = %21
%30 = load i64, i64* %4
ret i64 %30
}

LLVM IR (-O2):
@errno = global i64 0
@stderr = global i32 0
@.str = [46 x i8] c"Argument is not a valid decimal number: '%s'\0A\00"
@.str.1 = [32 x i8] c"Argument parse error: '%s': %m\0A\00"
define i64 @parse_integer(i8* %0) {
%2 = alloca i8*
%3 = bitcast i8** %2 to i8*
store i8* null, i8** %2
store i64 0, i64* @errno
%4 = call i64 @strtol(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 %15, label %11
11: ; preds = %7, %1
%12 = load i32, i32* @stderr
%13 = tail call i32 @fprintf(i32 %12, i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str, i64 0, i64 0), i8* %0)
%14 = tail call i32 @exit(i32 1)
unreachable
15: ; preds = %7
%16 = load i64, i64* @errno
%17 = icmp eq i64 %16, 0
br i1 %17, label %22, label %18
18: ; preds = %15
%19 = load i32, i32* @stderr
%20 = tail call i32 @fprintf(i32 %19, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.1, i64 0, i64 0), i8* %0)
%21 = tail call i32 @exit(i32 1)
unreachable
22: ; preds = %15
ret i64 %4
}