#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;
double strtod(char const *, char **);
double xatof(const char *nptr) {
  if (*nptr == '\0') {
    fputs("an empty string is not a valid number!\n", stderr);
    exit(1);
  }
  char *end;
  double val = strtod(nptr, &end);
  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):
<xatof>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
jne    117b <xatof+0x3b>
mov    0x2e7d(%rip),%rax
mov    (%rax),%esi
lea    0xe94(%rip),%rdi
call   1040 <fputs@plt>
mov    $0x1,%edi
call   1060 <exit@plt>
mov    -0x8(%rbp),%rdi
lea    -0x10(%rbp),%rsi
call   1030 <strtod@plt>
movsd  %xmm0,-0x18(%rbp)
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     11dd <xatof+0x9d>
mov    0x2e3c(%rip),%rax
mov    (%rax),%edi
mov    -0x8(%rbp),%rcx
mov    -0x10(%rbp),%rsi
lea    0xe8f(%rip),%rdx
lea    0xe76(%rip),%rax
cmp    %rsi,%rcx
cmove  %rax,%rdx
mov    -0x8(%rbp),%rcx
lea    0xe5a(%rip),%rsi
call   1050 <fprintf@plt>
mov    $0x1,%edi
call   1060 <exit@plt>
movsd  -0x18(%rbp),%xmm0
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<xatof>:
push   %rbx
sub    $0x10,%rsp
cmpb   $0x0,(%rdi)
je     1167 <xatof+0x27>
mov    %rdi,%rbx
lea    0x8(%rsp),%rsi
call   1030 <strtod@plt>
mov    0x8(%rsp),%rax
cmpb   $0x0,(%rax)
jne    1186 <xatof+0x46>
add    $0x10,%rsp
pop    %rbx
ret
mov    0x2e72(%rip),%rax
mov    (%rax),%esi
lea    0xe89(%rip),%rdi
call   1040 <fputs@plt>
mov    $0x1,%edi
call   1060 <exit@plt>
mov    0x2e53(%rip),%rcx
mov    (%rcx),%edi
cmp    %rbx,%rax
lea    0xe99(%rip),%rax
lea    0xea4(%rip),%rdx
cmove  %rax,%rdx
lea    0xe7d(%rip),%rsi
mov    %rbx,%rcx
call   1050 <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 double @xatof(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca double
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 double @strtod(i8* %14, i8** %3)
store double %15, double* %4
%16 = load i8*, i8** %3
%17 = load i8, i8* %16
%18 = sext i8 %17 to i32
%19 = icmp ne i32 %18, 0
br i1 %19, label %20, label %30
20: ; preds = %13
%21 = load i32, i32* @stderr
%22 = load i8*, i8** %2
%23 = load i8*, i8** %3
%24 = icmp eq i8* %22, %23
%25 = zext i1 %24 to i64
%26 = select i1 %24, 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)
%27 = load i8*, i8** %2
%28 = call i32 @fprintf(i32 %21, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), i8* %26, i8* %27)
%29 = call i32 @exit(i32 1)
unreachable
30: ; preds = %13
%31 = load double, double* %4
ret double %31
}

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 double @xatof(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 double @strtod(i8* %0, i8** %2)
%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
ret double %11
}