#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__ ERANGE;
int /*<<< orphan*/ err(int, char *, char const *);
scalar_t__ errno;
int /*<<< orphan*/ errx(int, char *, char const *);
double strtod(char const *, char **);
double e_atof(const char *num) {
  char *endp;
  double dbl;
  errno = 0;
  dbl = strtod(num, &endp);
  if (errno == ERANGE)
    err(2, "%s", num);
  else if (*endp != '\0')
    errx(2, "invalid floating point argument: %s", num);
  if (dbl == -0.0)
    dbl = 0;
  return (dbl);
}


x86 assembly (clang, -O0):
<e_atof>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    0x2e95(%rip),%rax
movq   $0x0,(%rax)
mov    -0x8(%rbp),%rdi
lea    -0x10(%rbp),%rsi
call   1030 <strtod@plt>
movsd  %xmm0,-0x18(%rbp)
mov    0x2e75(%rip),%rax
mov    (%rax),%rax
mov    0x2e7b(%rip),%rcx
cmp    (%rcx),%rax
jne    1190 <e_atof+0x60>
mov    -0x8(%rbp),%rdx
mov    $0x2,%edi
lea    0xea3(%rip),%rsi
call   1050 <err@plt>
jmp    11ba <e_atof+0x8a>
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     11b5 <e_atof+0x85>
mov    -0x8(%rbp),%rdx
mov    $0x2,%edi
lea    0xe58(%rip),%rsi
call   1040 <errx@plt>
jmp    11ba <e_atof+0x8a>
movsd  -0x18(%rbp),%xmm0
movsd  0xe39(%rip),%xmm1
ucomisd %xmm1,%xmm0
jne    11df <e_atof+0xaf>
jp     11df <e_atof+0xaf>
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x18(%rbp)
movsd  -0x18(%rbp),%xmm0
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<e_atof>:
push   %r14
push   %rbx
sub    $0x18,%rsp
mov    %rdi,%rbx
mov    0x2e97(%rip),%r14
movq   $0x0,(%r14)
lea    0x10(%rsp),%rsi
call   1030 <strtod@plt>
movapd %xmm0,%xmm2
mov    (%r14),%rax
mov    0x2e88(%rip),%rcx
cmp    (%rcx),%rax
jne    1180 <e_atof+0x50>
lea    0xeb5(%rip),%rsi
mov    $0x2,%edi
mov    %rbx,%rdx
movapd %xmm2,(%rsp)
call   1050 <err@plt>
jmp    11a3 <e_atof+0x73>
mov    0x10(%rsp),%rax
cmpb   $0x0,(%rax)
je     11a8 <e_atof+0x78>
lea    0xe6f(%rip),%rsi
mov    $0x2,%edi
mov    %rbx,%rdx
movapd %xmm2,(%rsp)
call   1040 <errx@plt>
movapd (%rsp),%xmm2
xorpd  %xmm1,%xmm1
movapd %xmm2,%xmm0
cmpeqsd %xmm1,%xmm0
andnpd %xmm2,%xmm0
add    $0x18,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@errno = global i64 0
@ERANGE = global i64 0
@.str = [3 x i8] c"%s\00"
@.str.1 = [36 x i8] c"invalid floating point argument: %s\00"
define double @e_atof(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca double
store i8* %0, i8** %2
store i64 0, i64* @errno
%5 = load i8*, i8** %2
%6 = call double @strtod(i8* %5, i8** %3)
store double %6, double* %4
%7 = load i64, i64* @errno
%8 = load i64, i64* @ERANGE
%9 = icmp eq i64 %7, %8
br i1 %9, label %10, label %13
10: ; preds = %1
%11 = load i8*, i8** %2
%12 = call i32 @err(i32 2, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %11)
br label %22
13: ; preds = %1
%14 = load i8*, i8** %3
%15 = load i8, i8* %14
%16 = sext i8 %15 to i32
%17 = icmp ne i32 %16, 0
br i1 %17, label %18, label %21
18: ; preds = %13
%19 = load i8*, i8** %2
%20 = call i32 @errx(i32 2, i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.1, i64 0, i64 0), i8* %19)
br label %21
21: ; preds = %18, %13
br label %22
22: ; preds = %21, %10
%23 = load double, double* %4
%24 = fcmp oeq double %23, -0.000000e+00
br i1 %24, label %25, label %26
25: ; preds = %22
store double 0.000000e+00, double* %4
br label %26
26: ; preds = %25, %22
%27 = load double, double* %4
ret double %27
}

LLVM IR (-O2):
@errno = global i64 0
@ERANGE = global i64 0
@.str = [3 x i8] c"%s\00"
@.str.1 = [36 x i8] c"invalid floating point argument: %s\00"
define double @e_atof(i8* %0) {
%2 = alloca i8*
%3 = bitcast i8** %2 to i8*
store i64 0, i64* @errno
%4 = call double @strtod(i8* %0, i8** %2)
%5 = load i64, i64* @errno
%6 = load i64, i64* @ERANGE
%7 = icmp eq i64 %5, %6
br i1 %7, label %8, label %10
8: ; preds = %1
%9 = tail call i32 @err(i32 2, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %0)
br label %16
10: ; preds = %1
%11 = load i8*, i8** %2
%12 = load i8, i8* %11
%13 = icmp eq i8 %12, 0
br i1 %13, label %16, label %14
14: ; preds = %10
%15 = tail call i32 @errx(i32 2, i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.1, i64 0, i64 0), i8* %0)
br label %16
16: ; preds = %10, %14, %8
%17 = fcmp oeq double %4, 0.000000e+00
%18 = select i1 %17, double 0.000000e+00, double %4
ret double %18
}