#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__ EINVAL;
scalar_t__ ERANGE;
double HUGE_VAL;
double INFINITY;
double NAN;
scalar_t__ errno;
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int /*<<< orphan*/ stderr;
char *strerror(scalar_t__);
double strtod(char *, int /*<<< orphan*/ *);
double stringtod(char *string) {
  errno = 0;
  double result = strtod(string, NULL);
  if (errno != 0) {
    if (ERANGE == errno) {
      if (HUGE_VAL >= result) {
        result = INFINITY;
        fprintf(stderr, "%s", strerror(errno));
        ;
      } else if (-HUGE_VAL <= result) {
        result = -INFINITY;
        fprintf(stderr, "%s", strerror(errno));
        ;
      } else
        fprintf(stderr, "%s", strerror(errno));
      ;
    } else if (errno == EINVAL) {
      result = NAN;
      fprintf(stderr, "%s", strerror(errno));
      ;
    } else
      fprintf(stderr, "%s", strerror(errno));
    ;
  }
  return result;
}


x86 assembly (clang, -O0):
<stringtod>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    0x2e75(%rip),%rax
movq   $0x0,(%rax)
mov    -0x8(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1030 <strtod@plt>
movsd  %xmm0,-0x10(%rbp)
mov    0x2e55(%rip),%rax
cmpq   $0x0,(%rax)
je     1333 <stringtod+0x203>
mov    0x2e5c(%rip),%rax
mov    (%rax),%rax
mov    0x2e3a(%rip),%rcx
cmp    (%rcx),%rax
jne    12a0 <stringtod+0x170>
mov    0x2e4a(%rip),%rax
movsd  (%rax),%xmm0
ucomisd -0x10(%rbp),%xmm0
jb     11df <stringtod+0xaf>
mov    0x2e3c(%rip),%rax
movsd  (%rax),%xmm0
movsd  %xmm0,-0x10(%rbp)
mov    0x2e0c(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x14(%rbp)
mov    0x2df8(%rip),%rax
mov    (%rax),%rdi
call   1050 <strerror@plt>
mov    -0x14(%rbp),%edi
mov    %rax,%rdx
lea    0xe2b(%rip),%rsi
call   1040 <fprintf@plt>
jmp    129b <stringtod+0x16b>
mov    0x2df2(%rip),%rax
movsd  (%rax),%xmm0
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm1
movsd  -0x10(%rbp),%xmm0
ucomisd %xmm1,%xmm0
jb     1269 <stringtod+0x139>
mov    0x2dc9(%rip),%rax
movsd  (%rax),%xmm0
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
movsd  %xmm0,-0x10(%rbp)
mov    0x2d82(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x18(%rbp)
mov    0x2d6e(%rip),%rax
mov    (%rax),%rdi
call   1050 <strerror@plt>
mov    -0x18(%rbp),%edi
mov    %rax,%rdx
lea    0xda1(%rip),%rsi
call   1040 <fprintf@plt>
jmp    1296 <stringtod+0x166>
mov    0x2d50(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x1c(%rbp)
mov    0x2d3c(%rip),%rax
mov    (%rax),%rdi
call   1050 <strerror@plt>
mov    -0x1c(%rbp),%edi
mov    %rax,%rdx
lea    0xd6f(%rip),%rsi
call   1040 <fprintf@plt>
jmp    129b <stringtod+0x16b>
jmp    132e <stringtod+0x1fe>
mov    0x2d11(%rip),%rax
mov    (%rax),%rax
mov    0x2cff(%rip),%rcx
cmp    (%rcx),%rax
jne    12fc <stringtod+0x1cc>
mov    0x2d37(%rip),%rax
movsd  (%rax),%xmm0
movsd  %xmm0,-0x10(%rbp)
mov    0x2cef(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x20(%rbp)
mov    0x2cdb(%rip),%rax
mov    (%rax),%rdi
call   1050 <strerror@plt>
mov    -0x20(%rbp),%edi
mov    %rax,%rdx
lea    0xd0e(%rip),%rsi
call   1040 <fprintf@plt>
jmp    1329 <stringtod+0x1f9>
mov    0x2cbd(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x24(%rbp)
mov    0x2ca9(%rip),%rax
mov    (%rax),%rdi
call   1050 <strerror@plt>
mov    -0x24(%rbp),%edi
mov    %rax,%rdx
lea    0xcdc(%rip),%rsi
call   1040 <fprintf@plt>
jmp    132e <stringtod+0x1fe>
jmp    1333 <stringtod+0x203>
movsd  -0x10(%rbp),%xmm0
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<stringtod>:
push   %rbx
sub    $0x10,%rsp
mov    0x2e7c(%rip),%rbx
movq   $0x0,(%rbx)
xor    %esi,%esi
call   1030 <strtod@plt>
mov    (%rbx),%rdi
test   %rdi,%rdi
je     11de <stringtod+0xae>
mov    0x2e73(%rip),%rax
cmp    %rdi,(%rax)
jne    1196 <stringtod+0x66>
mov    0x2e6f(%rip),%rax
movsd  (%rax),%xmm1
ucomisd %xmm0,%xmm1
jae    11ab <stringtod+0x7b>
xorpd  0xe85(%rip),%xmm1
ucomisd %xmm1,%xmm0
jb     11b6 <stringtod+0x86>
mov    0x2e58(%rip),%rax
movsd  (%rax),%xmm0
xorpd  0xe6c(%rip),%xmm0
jmp    11b6 <stringtod+0x86>
mov    0x2e13(%rip),%rax
cmp    (%rax),%rdi
jne    11b6 <stringtod+0x86>
mov    0x2e4f(%rip),%rax
jmp    11b2 <stringtod+0x82>
mov    0x2e2e(%rip),%rax
movsd  (%rax),%xmm0
movapd %xmm0,(%rsp)
mov    0x2dfe(%rip),%rax
mov    (%rax),%ebx
call   1050 <strerror@plt>
lea    0xe40(%rip),%rsi
mov    %ebx,%edi
mov    %rax,%rdx
call   1040 <fprintf@plt>
movaps (%rsp),%xmm0
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@errno = global i64 0
@ERANGE = global i64 0
@HUGE_VAL = global double 0.000000e+00
@INFINITY = global double 0.000000e+00
@stderr = global i32 0
@.str = [3 x i8] c"%s\00"
@EINVAL = global i64 0
@NAN = global double 0.000000e+00
define double @stringtod(i8* %0) {
%2 = alloca i8*
%3 = alloca double
store i8* %0, i8** %2
store i64 0, i64* @errno
%4 = load i8*, i8** %2
%5 = call double @strtod(i8* %4, i32* null)
store double %5, double* %3
%6 = load i64, i64* @errno
%7 = icmp ne i64 %6, 0
br i1 %7, label %8, label %58
8: ; preds = %1
%9 = load i64, i64* @ERANGE
%10 = load i64, i64* @errno
%11 = icmp eq i64 %9, %10
br i1 %11, label %12, label %41
12: ; preds = %8
%13 = load double, double* @HUGE_VAL
%14 = load double, double* %3
%15 = fcmp oge double %13, %14
br i1 %15, label %16, label %22
16: ; preds = %12
%17 = load double, double* @INFINITY
store double %17, double* %3
%18 = load i32, i32* @stderr
%19 = load i64, i64* @errno
%20 = call i8* @strerror(i64 %19)
%21 = call i32 @fprintf(i32 %18, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %20)
br label %40
22: ; preds = %12
%23 = load double, double* @HUGE_VAL
%24 = fneg double %23
%25 = load double, double* %3
%26 = fcmp ole double %24, %25
br i1 %26, label %27, label %34
27: ; preds = %22
%28 = load double, double* @INFINITY
%29 = fneg double %28
store double %29, double* %3
%30 = load i32, i32* @stderr
%31 = load i64, i64* @errno
%32 = call i8* @strerror(i64 %31)
%33 = call i32 @fprintf(i32 %30, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %32)
br label %39
34: ; preds = %22
%35 = load i32, i32* @stderr
%36 = load i64, i64* @errno
%37 = call i8* @strerror(i64 %36)
%38 = call i32 @fprintf(i32 %35, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %37)
br label %39
39: ; preds = %34, %27
br label %40
40: ; preds = %39, %16
br label %57
41: ; preds = %8
%42 = load i64, i64* @errno
%43 = load i64, i64* @EINVAL
%44 = icmp eq i64 %42, %43
br i1 %44, label %45, label %51
45: ; preds = %41
%46 = load double, double* @NAN
store double %46, double* %3
%47 = load i32, i32* @stderr
%48 = load i64, i64* @errno
%49 = call i8* @strerror(i64 %48)
%50 = call i32 @fprintf(i32 %47, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %49)
br label %56
51: ; preds = %41
%52 = load i32, i32* @stderr
%53 = load i64, i64* @errno
%54 = call i8* @strerror(i64 %53)
%55 = call i32 @fprintf(i32 %52, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %54)
br label %56
56: ; preds = %51, %45
br label %57
57: ; preds = %56, %40
br label %58
58: ; preds = %57, %1
%59 = load double, double* %3
ret double %59
}

LLVM IR (-O2):
@errno = global i64 0
@ERANGE = global i64 0
@HUGE_VAL = global double 0.000000e+00
@INFINITY = global double 0.000000e+00
@stderr = global i32 0
@.str = [3 x i8] c"%s\00"
@EINVAL = global i64 0
@NAN = global double 0.000000e+00
define double @stringtod(i8* nocapture %0) {
store i64 0, i64* @errno
%2 = tail call double @strtod(i8* nocapture %0, i32* null)
%3 = load i64, i64* @errno
%4 = icmp eq i64 %3, 0
br i1 %4, label %29, label %5
5: ; preds = %1
%6 = load i64, i64* @ERANGE
%7 = icmp eq i64 %6, %3
br i1 %7, label %8, label %19
8: ; preds = %5
%9 = load double, double* @HUGE_VAL
%10 = fcmp ult double %9, %2
br i1 %10, label %13, label %11
11: ; preds = %8
%12 = load double, double* @INFINITY
br label %24
13: ; preds = %8
%14 = fneg double %9
%15 = fcmp ult double %2, %14
br i1 %15, label %24, label %16
16: ; preds = %13
%17 = load double, double* @INFINITY
%18 = fneg double %17
br label %24
19: ; preds = %5
%20 = load i64, i64* @EINVAL
%21 = icmp eq i64 %3, %20
%22 = load double, double* @NAN
%23 = select i1 %21, double %22, double %2
br label %24
24: ; preds = %19, %13, %11, %16
%25 = phi double [ %18, %16 ], [ %12, %11 ], [ %2, %13 ], [ %23, %19 ]
%26 = load i32, i32* @stderr
%27 = tail call i8* @strerror(i64 %3)
%28 = tail call i32 @fprintf(i32 %26, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %27)
br label %29
29: ; preds = %24, %1
%30 = phi double [ %2, %1 ], [ %25, %24 ]
ret double %30
}