#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 *);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ stderr;
size_t strtoul(char *, char **, int /*<<< orphan*/);
size_t parse_number(char *str, char *name) {
  size_t result;
  char *err;
  errno = 0;
  result = strtoul(str, &err, 0);
  if (errno)
    perror(name);
  else if (*err != '\0') {
    fprintf(stderr, "%s: invalid number\n", name);
    exit(EXIT_FAILURE);
  }
  return result;
}


x86 assembly (clang, -O0):
<parse_number>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0x2e81(%rip),%rax
movq   $0x0,(%rax)
mov    -0x8(%rbp),%rdi
lea    -0x20(%rbp),%rsi
xor    %edx,%edx
call   1050 <strtoul@plt>
mov    %rax,-0x18(%rbp)
mov    0x2e60(%rip),%rax
cmpq   $0x0,(%rax)
je     1190 <parse_number+0x50>
mov    -0x10(%rbp),%rdi
call   1040 <perror@plt>
jmp    11cc <parse_number+0x8c>
mov    -0x20(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     11c7 <parse_number+0x87>
mov    0x2e39(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rdx
lea    0xe4c(%rip),%rsi
call   1030 <fprintf@plt>
mov    0x2e10(%rip),%rax
mov    (%rax),%edi
call   1060 <exit@plt>
jmp    11cc <parse_number+0x8c>
mov    -0x18(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<parse_number>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rsi,%r14
mov    0x2e85(%rip),%r15
movq   $0x0,(%r15)
lea    0x8(%rsp),%rsi
xor    %edx,%edx
call   1050 <strtoul@plt>
mov    %rax,%rbx
cmpq   $0x0,(%r15)
jne    1186 <parse_number+0x46>
mov    0x8(%rsp),%rax
cmpb   $0x0,(%rax)
jne    1190 <parse_number+0x50>
mov    %rbx,%rax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret
mov    %r14,%rdi
call   1040 <perror@plt>
jmp    1179 <parse_number+0x39>
mov    0x2e49(%rip),%rax
mov    (%rax),%edi
lea    0xe60(%rip),%rsi
mov    %r14,%rdx
call   1030 <fprintf@plt>
mov    0x2e21(%rip),%rax
mov    (%rax),%edi
call   1060 <exit@plt>

LLVM IR (-O0):
@errno = global i64 0
@stderr = global i32 0
@.str = [20 x i8] c"%s: invalid number\0A\00"
@EXIT_FAILURE = global i32 0
define i64 @parse_number(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i64
%6 = alloca i8*
store i8* %0, i8** %3
store i8* %1, i8** %4
store i64 0, i64* @errno
%7 = load i8*, i8** %3
%8 = call i64 @strtoul(i8* %7, i8** %6, i32 0)
store i64 %8, i64* %5
%9 = load i64, i64* @errno
%10 = icmp ne i64 %9, 0
br i1 %10, label %11, label %14
11: ; preds = %2
%12 = load i8*, i8** %4
%13 = call i32 @perror(i8* %12)
br label %26
14: ; preds = %2
%15 = load i8*, i8** %6
%16 = load i8, i8* %15
%17 = sext i8 %16 to i32
%18 = icmp ne i32 %17, 0
br i1 %18, label %19, label %25
19: ; preds = %14
%20 = load i32, i32* @stderr
%21 = load i8*, i8** %4
%22 = call i32 @fprintf(i32 %20, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0), i8* %21)
%23 = load i32, i32* @EXIT_FAILURE
%24 = call i32 @exit(i32 %23)
unreachable
25: ; preds = %14
br label %26
26: ; preds = %25, %11
%27 = load i64, i64* %5
ret i64 %27
}

LLVM IR (-O2):
@errno = global i64 0
@stderr = global i32 0
@.str = [20 x i8] c"%s: invalid number\0A\00"
@EXIT_FAILURE = global i32 0
define i64 @parse_number(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = bitcast i8** %3 to i8*
store i64 0, i64* @errno
%5 = call i64 @strtoul(i8* %0, i8** %3, i32 0)
%6 = load i64, i64* @errno
%7 = icmp eq i64 %6, 0
br i1 %7, label %10, label %8
8: ; preds = %2
%9 = tail call i32 @perror(i8* %1)
br label %19
10: ; preds = %2
%11 = load i8*, i8** %3
%12 = load i8, i8* %11
%13 = icmp eq i8 %12, 0
br i1 %13, label %19, label %14
14: ; preds = %10
%15 = load i32, i32* @stderr
%16 = tail call i32 @fprintf(i32 %15, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0), i8* %1)
%17 = load i32, i32* @EXIT_FAILURE
%18 = tail call i32 @exit(i32 %17)
unreachable
19: ; preds = %10, %8
ret i64 %5
}