#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;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int /*<<< orphan*/ stderr;
long long strtoll(char *, char **, int /*<<< orphan*/);
unsigned long parse_int(char *str) {
  long long result;
  char *endptr;
  result = strtoll(str, &endptr, 0);
  if (*str == '\0' || *endptr != '\0') {
    fprintf(stderr, "\"%s\" is not a valid number\n", str);
    exit(EXIT_FAILURE);
  }
  return (unsigned long)result;
}


x86 assembly (clang, -O0):
<parse_int>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
lea    -0x18(%rbp),%rsi
xor    %edx,%edx
call   1030 <strtoll@plt>
mov    %rax,-0x10(%rbp)
mov    -0x8(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     116f <parse_int+0x3f>
mov    -0x18(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     1196 <parse_int+0x66>
mov    0x2e6a(%rip),%rax
mov    (%rax),%edi
mov    -0x8(%rbp),%rdx
lea    0xe7d(%rip),%rsi
call   1040 <fprintf@plt>
mov    0x2e49(%rip),%rax
mov    (%rax),%edi
call   1050 <exit@plt>
mov    -0x10(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<parse_int>:
push   %rbx
sub    $0x10,%rsp
mov    %rdi,%rbx
lea    0x8(%rsp),%rsi
xor    %edx,%edx
call   1030 <strtoll@plt>
cmpb   $0x0,(%rbx)
je     1159 <parse_int+0x29>
mov    0x8(%rsp),%rcx
cmpb   $0x0,(%rcx)
jne    1159 <parse_int+0x29>
add    $0x10,%rsp
pop    %rbx
ret
mov    0x2e80(%rip),%rax
mov    (%rax),%edi
lea    0xe97(%rip),%rsi
mov    %rbx,%rdx
call   1040 <fprintf@plt>
mov    0x2e60(%rip),%rax
mov    (%rax),%edi
call   1050 <exit@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [28 x i8] c"\22%s\22 is not a valid number\0A\00"
@EXIT_FAILURE = global i32 0
define i64 @parse_int(i8* %0) {
%2 = alloca i8*
%3 = alloca i64
%4 = alloca i8*
store i8* %0, i8** %2
%5 = load i8*, i8** %2
%6 = call i64 @strtoll(i8* %5, i8** %4, i32 0)
store i64 %6, i64* %3
%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** %4
%13 = load i8, i8* %12
%14 = sext i8 %13 to i32
%15 = icmp ne i32 %14, 0
br i1 %15, label %16, label %22
16: ; preds = %11, %1
%17 = load i32, i32* @stderr
%18 = load i8*, i8** %2
%19 = call i32 @fprintf(i32 %17, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str, i64 0, i64 0), i8* %18)
%20 = load i32, i32* @EXIT_FAILURE
%21 = call i32 @exit(i32 %20)
unreachable
22: ; preds = %11
%23 = load i64, i64* %3
ret i64 %23
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [28 x i8] c"\22%s\22 is not a valid number\0A\00"
@EXIT_FAILURE = global i32 0
define i64 @parse_int(i8* %0) {
%2 = alloca i8*
%3 = bitcast i8** %2 to i8*
%4 = call i64 @strtoll(i8* %0, i8** %2, i32 0)
%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 = %7, %1
%12 = load i32, i32* @stderr
%13 = tail call i32 @fprintf(i32 %12, i8* getelementptr inbounds ([28 x i8], [28 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
ret i64 %4
}