#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 */
typedef int /*<<< orphan*/ expt_test_nums;

/* Variables and functions */
double const DBL_EPSILON;
int /*<<< orphan*/ assert(int);
double fabs(double const);
double serd_strtod(char const *, int /*<<< orphan*/ *);
int /*<<< orphan*/ test_strtod(double const, double const);
void test_string_to_double(void) {
  const double expt_test_nums[] = {2.0E18, -5e19, +8e20, 2e+24,
                                   -5e-5,  8e0,   9e-0,  2e+0};
  const char *expt_test_strs[] = {"02e18", "-5e019", "+8e20", "2E+24",
                                  "-5E-5", "8E0",    "9e-0",  " 2e+0"};
  for (size_t i = 0; i < sizeof(expt_test_nums) / sizeof(double); ++i) {
    const double num = serd_strtod(expt_test_strs[i], NULL);
    const double delta = fabs(num - expt_test_nums[i]);
    assert(delta <= DBL_EPSILON);
    test_strtod(expt_test_nums[i], DBL_EPSILON);
  }
}


x86 assembly (clang, -O0):
<test_string_to_double>:
push   %rbp
mov    %rsp,%rbp
sub    $0xa0,%rsp
lea    -0x40(%rbp),%rdi
lea    0xeba(%rip),%rsi
mov    $0x40,%edx
call   1060 <memcpy@plt>
lea    -0x80(%rbp),%rdi
lea    0x2c65(%rip),%rsi
mov    $0x40,%edx
call   1060 <memcpy@plt>
movq   $0x0,-0x88(%rbp)
cmpq   $0x8,-0x88(%rbp)
08
jae    122b <test_string_to_double+0xeb>
mov    -0x88(%rbp),%rax
mov    -0x80(%rbp,%rax,8),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1030 <serd_strtod@plt>
movsd  %xmm0,-0x90(%rbp)
ff
movsd  -0x90(%rbp),%xmm0
ff
mov    -0x88(%rbp),%rax
subsd  -0x40(%rbp,%rax,8),%xmm0
movaps 0xe39(%rip),%xmm1
pand   %xmm1,%xmm0
movsd  %xmm0,-0x98(%rbp)
ff
movsd  -0x98(%rbp),%xmm1
ff
mov    0x2dfe(%rip),%rax
movsd  (%rax),%xmm0
ucomisd %xmm1,%xmm0
setae  %al
and    $0x1,%al
movzbl %al,%edi
call   1050 <assert@plt>
mov    -0x88(%rbp),%rax
movsd  -0x40(%rbp,%rax,8),%xmm0
mov    0x2dd5(%rip),%rax
movsd  (%rax),%xmm1
call   1040 <test_strtod@plt>
mov    -0x88(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x88(%rbp)
jmp    1180 <test_string_to_double+0x40>
add    $0xa0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<test_string_to_double>:
push   %rax
lea    0xf50(%rip),%rdi
xor    %esi,%esi
call   1030 <serd_strtod@plt>
addsd  0xeb9(%rip),%xmm0
xorpd  %xmm1,%xmm1
cmpeqsd %xmm1,%xmm0
movq   %xmm0,%rdi
and    $0x1,%edi
call   1050 <assert@plt>
movsd  0xea3(%rip),%xmm0
xorpd  %xmm1,%xmm1
call   1040 <test_strtod@plt>
lea    0xf19(%rip),%rdi
xor    %esi,%esi
call   1030 <serd_strtod@plt>
addsd  0xe8c(%rip),%xmm0
cmpeqsd 0xef3(%rip),%xmm0
movq   %xmm0,%rdi
and    $0x1,%edi
call   1050 <assert@plt>
movsd  0xe76(%rip),%xmm0
xorpd  %xmm1,%xmm1
call   1040 <test_strtod@plt>
lea    0xee3(%rip),%rdi
xor    %esi,%esi
call   1030 <serd_strtod@plt>
addsd  0xe5f(%rip),%xmm0
cmpeqsd 0xeb6(%rip),%xmm0
movq   %xmm0,%rdi
and    $0x1,%edi
call   1050 <assert@plt>
movsd  0xe49(%rip),%xmm0
xorpd  %xmm1,%xmm1
call   1040 <test_strtod@plt>
lea    0xeac(%rip),%rdi
xor    %esi,%esi
call   1030 <serd_strtod@plt>
addsd  0xe32(%rip),%xmm0
cmpeqsd 0xe79(%rip),%xmm0
movq   %xmm0,%rdi
and    $0x1,%edi
call   1050 <assert@plt>
movsd  0xe1c(%rip),%xmm0
xorpd  %xmm1,%xmm1
call   1040 <test_strtod@plt>
lea    0xe75(%rip),%rdi
xor    %esi,%esi
call   1030 <serd_strtod@plt>
addsd  0xe05(%rip),%xmm0
cmpeqsd 0xe3c(%rip),%xmm0
movq   %xmm0,%rdi
and    $0x1,%edi
call   1050 <assert@plt>
movsd  0xdef(%rip),%xmm0
xorpd  %xmm1,%xmm1
call   1040 <test_strtod@plt>
lea    0xe3e(%rip),%rdi
xor    %esi,%esi
call   1030 <serd_strtod@plt>
addsd  0xdd8(%rip),%xmm0
cmpeqsd 0xdff(%rip),%xmm0
movq   %xmm0,%rdi
and    $0x1,%edi
call   1050 <assert@plt>
movsd  0xdc2(%rip),%xmm0
xorpd  %xmm1,%xmm1
call   1040 <test_strtod@plt>
lea    0xe05(%rip),%rdi
xor    %esi,%esi
call   1030 <serd_strtod@plt>
addsd  0xdab(%rip),%xmm0
cmpeqsd 0xdc2(%rip),%xmm0
movq   %xmm0,%rdi
and    $0x1,%edi
call   1050 <assert@plt>
movsd  0xd95(%rip),%xmm0
xorpd  %xmm1,%xmm1
call   1040 <test_strtod@plt>
lea    0xdcd(%rip),%rdi
xor    %esi,%esi
call   1030 <serd_strtod@plt>
addsd  0xd7e(%rip),%xmm0
cmpeqsd 0xd85(%rip),%xmm0
movq   %xmm0,%rdi
and    $0x1,%edi
call   1050 <assert@plt>
movsd  0xd68(%rip),%xmm0
xorpd  %xmm1,%xmm1
pop    %rax
jmp    1040 <test_strtod@plt>

LLVM IR (-O0):
@__const.test_string_to_double.expt_test_nums = [8 x double] [double 2.000000e+18, double -5.000000e+19, double 8.000000e+20, double 2.000000e+24, double -5.000000e-05, double 8.000000e+00, double 9.000000e+00, double 2.000000e+00]
@.str = [6 x i8] c"02e18\00"
@.str.1 = [7 x i8] c"-5e019\00"
@.str.2 = [6 x i8] c"+8e20\00"
@.str.3 = [6 x i8] c"2E+24\00"
@.str.4 = [6 x i8] c"-5E-5\00"
@.str.5 = [4 x i8] c"8E0\00"
@.str.6 = [5 x i8] c"9e-0\00"
@.str.7 = [6 x i8] c" 2e+0\00"
@__const.test_string_to_double.expt_test_strs = [8 x i8*] [i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i32 0, i32 0), i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i32 0, i32 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i32 0, i32 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i32 0, i32 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i32 0, i32 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i32 0, i32 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.6, i32 0, i32 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.7, i32 0, i32 0)]
@DBL_EPSILON = constant double 0.000000e+00
define void @test_string_to_double() {
%1 = alloca [8 x double]
%2 = alloca [8 x i8*]
%3 = alloca i64
%4 = alloca double
%5 = alloca double
%6 = bitcast [8 x double]* %1 to i8*
%7 = bitcast [8 x i8*]* %2 to i8*
store i64 0, i64* %3
br label %8
8: ; preds = %32, %0
%9 = load i64, i64* %3
%10 = icmp ult i64 %9, 8
br i1 %10, label %11, label %35
11: ; preds = %8
%12 = load i64, i64* %3
%13 = getelementptr inbounds [8 x i8*], [8 x i8*]* %2, i64 0, i64 %12
%14 = load i8*, i8** %13
%15 = call double @serd_strtod(i8* %14, i32* null)
store double %15, double* %4
%16 = load double, double* %4
%17 = load i64, i64* %3
%18 = getelementptr inbounds [8 x double], [8 x double]* %1, i64 0, i64 %17
%19 = load double, double* %18
%20 = fsub double %16, %19
%21 = call double @llvm.fabs.f64(double %20)
store double %21, double* %5
%22 = load double, double* %5
%23 = load double, double* @DBL_EPSILON
%24 = fcmp ole double %22, %23
%25 = zext i1 %24 to i32
%26 = call i32 @assert(i32 %25)
%27 = load i64, i64* %3
%28 = getelementptr inbounds [8 x double], [8 x double]* %1, i64 0, i64 %27
%29 = load double, double* %28
%30 = load double, double* @DBL_EPSILON
%31 = call i32 @test_strtod(double %29, double %30)
br label %32
32: ; preds = %11
%33 = load i64, i64* %3
%34 = add i64 %33, 1
store i64 %34, i64* %3
br label %8
35: ; preds = %8
ret void
}

LLVM IR (-O2):
@.str = [6 x i8] c"02e18\00"
@.str.1 = [7 x i8] c"-5e019\00"
@.str.2 = [6 x i8] c"+8e20\00"
@.str.3 = [6 x i8] c"2E+24\00"
@.str.4 = [6 x i8] c"-5E-5\00"
@.str.5 = [4 x i8] c"8E0\00"
@.str.6 = [5 x i8] c"9e-0\00"
@.str.7 = [6 x i8] c" 2e+0\00"
@DBL_EPSILON = constant double 0.000000e+00
define void @test_string_to_double() {
%1 = tail call double @serd_strtod(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i32* null)
%2 = fadd double %1, -2.000000e+18
%3 = fcmp oeq double %2, 0.000000e+00
%4 = zext i1 %3 to i32
%5 = tail call i32 @assert(i32 %4)
%6 = tail call i32 @test_strtod(double 2.000000e+18, double 0.000000e+00)
%7 = tail call double @serd_strtod(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i32* null)
%8 = fadd double %7, 5.000000e+19
%9 = fcmp oeq double %8, 0.000000e+00
%10 = zext i1 %9 to i32
%11 = tail call i32 @assert(i32 %10)
%12 = tail call i32 @test_strtod(double -5.000000e+19, double 0.000000e+00)
%13 = tail call double @serd_strtod(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i32* null)
%14 = fadd double %13, -8.000000e+20
%15 = fcmp oeq double %14, 0.000000e+00
%16 = zext i1 %15 to i32
%17 = tail call i32 @assert(i32 %16)
%18 = tail call i32 @test_strtod(double 8.000000e+20, double 0.000000e+00)
%19 = tail call double @serd_strtod(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0), i32* null)
%20 = fadd double %19, -2.000000e+24
%21 = fcmp oeq double %20, 0.000000e+00
%22 = zext i1 %21 to i32
%23 = tail call i32 @assert(i32 %22)
%24 = tail call i32 @test_strtod(double 2.000000e+24, double 0.000000e+00)
%25 = tail call double @serd_strtod(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0), i32* null)
%26 = fadd double %25, 5.000000e-05
%27 = fcmp oeq double %26, 0.000000e+00
%28 = zext i1 %27 to i32
%29 = tail call i32 @assert(i32 %28)
%30 = tail call i32 @test_strtod(double -5.000000e-05, double 0.000000e+00)
%31 = tail call double @serd_strtod(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i64 0, i64 0), i32* null)
%32 = fadd double %31, -8.000000e+00
%33 = fcmp oeq double %32, 0.000000e+00
%34 = zext i1 %33 to i32
%35 = tail call i32 @assert(i32 %34)
%36 = tail call i32 @test_strtod(double 8.000000e+00, double 0.000000e+00)
%37 = tail call double @serd_strtod(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.6, i64 0, i64 0), i32* null)
%38 = fadd double %37, -9.000000e+00
%39 = fcmp oeq double %38, 0.000000e+00
%40 = zext i1 %39 to i32
%41 = tail call i32 @assert(i32 %40)
%42 = tail call i32 @test_strtod(double 9.000000e+00, double 0.000000e+00)
%43 = tail call double @serd_strtod(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.7, i64 0, i64 0), i32* null)
%44 = fadd double %43, -2.000000e+00
%45 = fcmp oeq double %44, 0.000000e+00
%46 = zext i1 %45 to i32
%47 = tail call i32 @assert(i32 %46)
%48 = tail call i32 @test_strtod(double 2.000000e+00, double 0.000000e+00)
ret void
}