#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*/ eprintf(char *, char const *);
double strtod(char const *, char **);
double estrtod(const char *str) {
  char *ep;
  double d;
  d = strtod(str, &ep);
  if (!d || *ep != '\0' || ep == str)
    eprintf("Invalid number: %s\n", str);
  return d;
}


x86 assembly (clang, -O0):
<estrtod>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
lea    -0x10(%rbp),%rsi
call   1030 <strtod@plt>
movsd  %xmm0,-0x18(%rbp)
movsd  -0x18(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jne    115b <estrtod+0x3b>
jp     115b <estrtod+0x3b>
jmp    1179 <estrtod+0x59>
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
jne    1179 <estrtod+0x59>
mov    -0x10(%rbp),%rax
cmp    -0x8(%rbp),%rax
jne    1189 <estrtod+0x69>
mov    -0x8(%rbp),%rsi
lea    0xe7c(%rip),%rdi
call   1040 <eprintf@plt>
movsd  -0x18(%rbp),%xmm0
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<estrtod>:
push   %rbx
sub    $0x10,%rsp
mov    %rdi,%rbx
lea    0x8(%rsp),%rsi
call   1030 <strtod@plt>
xorpd  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jne    113e <estrtod+0x1e>
jnp    114d <estrtod+0x2d>
mov    0x8(%rsp),%rax
cmp    %rbx,%rax
je     114d <estrtod+0x2d>
cmpb   $0x0,(%rax)
je     1166 <estrtod+0x46>
lea    0xeac(%rip),%rdi
mov    %rbx,%rsi
movsd  %xmm0,(%rsp)
call   1040 <eprintf@plt>
movsd  (%rsp),%xmm0
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@.str = [20 x i8] c"Invalid number: %s\0A\00"
define double @estrtod(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca double
store i8* %0, i8** %2
%5 = load i8*, i8** %2
%6 = call double @strtod(i8* %5, i8** %3)
store double %6, double* %4
%7 = load double, double* %4
%8 = fcmp une double %7, 0.000000e+00
br i1 %8, label %9, label %18
9: ; preds = %1
%10 = load i8*, i8** %3
%11 = load i8, i8* %10
%12 = sext i8 %11 to i32
%13 = icmp ne i32 %12, 0
br i1 %13, label %18, label %14
14: ; preds = %9
%15 = load i8*, i8** %3
%16 = load i8*, i8** %2
%17 = icmp eq i8* %15, %16
br i1 %17, label %18, label %21
18: ; preds = %14, %9, %1
%19 = load i8*, i8** %2
%20 = call i32 @eprintf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0), i8* %19)
br label %21
21: ; preds = %18, %14
%22 = load double, double* %4
ret double %22
}

LLVM IR (-O2):
@.str = [20 x i8] c"Invalid number: %s\0A\00"
define double @estrtod(i8* %0) {
%2 = alloca i8*
%3 = bitcast i8** %2 to i8*
%4 = call double @strtod(i8* %0, i8** %2)
%5 = fcmp une double %4, 0.000000e+00
br i1 %5, label %6, label %12
6: ; preds = %1
%7 = load i8*, i8** %2
%8 = load i8, i8* %7
%9 = icmp ne i8 %8, 0
%10 = icmp eq i8* %7, %0
%11 = or i1 %10, %9
br i1 %11, label %12, label %14
12: ; preds = %6, %1
%13 = tail call i32 @eprintf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0), i8* %0)
br label %14
14: ; preds = %6, %12
ret double %4
}