#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(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *, char const *);
int /*<<< orphan*/ fputs(char *, int /*<<< orphan*/);
int /*<<< orphan*/ stderr;
scalar_t__ strtol(char const *, char **, int);
int xatoi(const char *nptr) {
  if (*nptr == '\0') {
    fputs("an empty string is not a valid number!\n", stderr);
    exit(1);
  }
  char *end;
  int val = (int)strtol(nptr, &end, 10);
  if (*end != '\0') {
    fprintf(stderr, "%s: \"%s\"\n",
            (nptr == end) ? "unreadable number" : "can't parse whole number",
            nptr);
    exit(1);
  }
  return val;
}


x86 assembly (clang, -O0):
<xatoi>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
jne    117b <xatoi+0x3b>
mov    0x2e7d(%rip),%rax
mov    (%rax),%esi
lea    0xe94(%rip),%rdi
call   1030 <fputs@plt>
mov    $0x1,%edi
call   1060 <exit@plt>
mov    -0x8(%rbp),%rdi
lea    -0x10(%rbp),%rsi
mov    $0xa,%edx
call   1050 <strtol@plt>
mov    %eax,-0x14(%rbp)
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     11e0 <xatoi+0xa0>
mov    0x2e39(%rip),%rax
mov    (%rax),%edi
mov    -0x8(%rbp),%rcx
mov    -0x10(%rbp),%rsi
lea    0xe8c(%rip),%rdx
lea    0xe73(%rip),%rax
cmp    %rsi,%rcx
cmove  %rax,%rdx
mov    -0x8(%rbp),%rcx
lea    0xe57(%rip),%rsi
call   1040 <fprintf@plt>
mov    $0x1,%edi
call   1060 <exit@plt>
mov    -0x14(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<xatoi>:
push   %rbx
sub    $0x10,%rsp
cmpb   $0x0,(%rdi)
je     116c <xatoi+0x2c>
mov    %rdi,%rbx
lea    0x8(%rsp),%rsi
mov    $0xa,%edx
call   1050 <strtol@plt>
mov    0x8(%rsp),%rcx
cmpb   $0x0,(%rcx)
jne    118b <xatoi+0x4b>
add    $0x10,%rsp
pop    %rbx
ret
mov    0x2e6d(%rip),%rax
mov    (%rax),%esi
lea    0xe84(%rip),%rdi
call   1030 <fputs@plt>
mov    $0x1,%edi
call   1060 <exit@plt>
mov    0x2e4e(%rip),%rax
mov    (%rax),%edi
cmp    %rbx,%rcx
lea    0xe94(%rip),%rax
lea    0xe9f(%rip),%rdx
cmove  %rax,%rdx
lea    0xe78(%rip),%rsi
mov    %rbx,%rcx
call   1040 <fprintf@plt>
mov    $0x1,%edi
call   1060 <exit@plt>

LLVM IR (-O0):
@.str = [40 x i8] c"an empty string is not a valid number!\0A\00"
@stderr = global i32 0
@.str.1 = [10 x i8] c"%s: \22%s\22\0A\00"
@.str.2 = [18 x i8] c"unreadable number\00"
@.str.3 = [25 x i8] c"can't parse whole number\00"
define i32 @xatoi(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i32
store i8* %0, i8** %2
%5 = load i8*, i8** %2
%6 = load i8, i8* %5
%7 = sext i8 %6 to i32
%8 = icmp eq i32 %7, 0
br i1 %8, label %9, label %13
9: ; preds = %1
%10 = load i32, i32* @stderr
%11 = call i32 @fputs(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str, i64 0, i64 0), i32 %10)
%12 = call i32 @exit(i32 1)
unreachable
13: ; preds = %1
%14 = load i8*, i8** %2
%15 = call i64 @strtol(i8* %14, i8** %3, i32 10)
%16 = trunc i64 %15 to i32
store i32 %16, i32* %4
%17 = load i8*, i8** %3
%18 = load i8, i8* %17
%19 = sext i8 %18 to i32
%20 = icmp ne i32 %19, 0
br i1 %20, label %21, label %31
21: ; preds = %13
%22 = load i32, i32* @stderr
%23 = load i8*, i8** %2
%24 = load i8*, i8** %3
%25 = icmp eq i8* %23, %24
%26 = zext i1 %25 to i64
%27 = select i1 %25, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.3, i64 0, i64 0)
%28 = load i8*, i8** %2
%29 = call i32 @fprintf(i32 %22, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), i8* %27, i8* %28)
%30 = call i32 @exit(i32 1)
unreachable
31: ; preds = %13
%32 = load i32, i32* %4
ret i32 %32
}

LLVM IR (-O2):
@.str = [40 x i8] c"an empty string is not a valid number!\0A\00"
@stderr = global i32 0
@.str.1 = [10 x i8] c"%s: \22%s\22\0A\00"
@.str.2 = [18 x i8] c"unreadable number\00"
@.str.3 = [25 x i8] c"can't parse whole number\00"
define i32 @xatoi(i8* %0) {
%2 = alloca i8*
%3 = load i8, i8* %0
%4 = icmp eq i8 %3, 0
br i1 %4, label %5, label %9
5: ; preds = %1
%6 = load i32, i32* @stderr
%7 = tail call i32 @fputs(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str, i64 0, i64 0), i32 %6)
%8 = tail call i32 @exit(i32 1)
unreachable
9: ; preds = %1
%10 = bitcast i8** %2 to i8*
%11 = call i64 @strtol(i8* %0, i8** %2, i32 10)
%12 = load i8*, i8** %2
%13 = load i8, i8* %12
%14 = icmp eq i8 %13, 0
br i1 %14, label %21, label %15
15: ; preds = %9
%16 = load i32, i32* @stderr
%17 = icmp eq i8* %12, %0
%18 = select i1 %17, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.3, i64 0, i64 0)
%19 = tail call i32 @fprintf(i32 %16, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), i8* %18, i8* %0)
%20 = tail call i32 @exit(i32 1)
unreachable
21: ; preds = %9
%22 = trunc i64 %11 to i32
ret i32 %22
}