#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*/ buf;

/* Variables and functions */
int /*<<< orphan*/ assert(int);
double fabs(double const);
double serd_strtod(char *, char **);
int /*<<< orphan*/ snprintf(char *, int, char *, double);
void test_strtod(double dbl, double max_delta) {
  char buf[1024];
  snprintf(buf, sizeof(buf), "%f", dbl);
  char *endptr = NULL;
  const double out = serd_strtod(buf, &endptr);
  const double diff = fabs(out - dbl);
  assert(diff <= max_delta);
}


x86 assembly (clang, -O0):
<test_strtod>:
push   %rbp
mov    %rsp,%rbp
sub    $0x430,%rsp
movsd  %xmm0,-0x8(%rbp)
movsd  %xmm1,-0x10(%rbp)
lea    -0x410(%rbp),%rdi
movsd  -0x8(%rbp),%xmm0
mov    $0x400,%esi
lea    0xeb3(%rip),%rdx
call   1040 <snprintf@plt>
movq   $0x0,-0x418(%rbp)
lea    -0x410(%rbp),%rdi
lea    -0x418(%rbp),%rsi
call   1030 <serd_strtod@plt>
movsd  %xmm0,-0x420(%rbp)
ff
movsd  -0x420(%rbp),%xmm0
ff
subsd  -0x8(%rbp),%xmm0
movaps 0xe64(%rip),%xmm1
pand   %xmm1,%xmm0
movsd  %xmm0,-0x428(%rbp)
ff
movsd  -0x428(%rbp),%xmm1
ff
movsd  -0x10(%rbp),%xmm0
ucomisd %xmm1,%xmm0
setae  %al
and    $0x1,%al
movzbl %al,%edi
call   1050 <assert@plt>
add    $0x430,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<test_strtod>:
push   %rbx
sub    $0x420,%rsp
movsd  %xmm1,0x10(%rsp)
movsd  %xmm0,0x8(%rsp)
lea    0xec5(%rip),%rdx
lea    0x20(%rsp),%rbx
mov    %rbx,%rdi
mov    $0x400,%esi
call   1040 <snprintf@plt>
movq   $0x0,0x18(%rsp)
lea    0x18(%rsp),%rsi
mov    %rbx,%rdi
call   1030 <serd_strtod@plt>
subsd  0x8(%rsp),%xmm0
andpd  0xe7f(%rip),%xmm0
xor    %edi,%edi
movsd  0x10(%rsp),%xmm1
ucomisd %xmm0,%xmm1
setae  %dil
call   1050 <assert@plt>
add    $0x420,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@.str = [3 x i8] c"%f\00"
define void @test_strtod(double %0, double %1) {
%3 = alloca double
%4 = alloca double
%5 = alloca [1024 x i8]
%6 = alloca i8*
%7 = alloca double
%8 = alloca double
store double %0, double* %3
store double %1, double* %4
%9 = getelementptr inbounds [1024 x i8], [1024 x i8]* %5, i64 0, i64 0
%10 = load double, double* %3
%11 = call i32 @snprintf(i8* %9, i32 1024, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), double %10)
store i8* null, i8** %6
%12 = getelementptr inbounds [1024 x i8], [1024 x i8]* %5, i64 0, i64 0
%13 = call double @serd_strtod(i8* %12, i8** %6)
store double %13, double* %7
%14 = load double, double* %7
%15 = load double, double* %3
%16 = fsub double %14, %15
%17 = call double @llvm.fabs.f64(double %16)
store double %17, double* %8
%18 = load double, double* %8
%19 = load double, double* %4
%20 = fcmp ole double %18, %19
%21 = zext i1 %20 to i32
%22 = call i32 @assert(i32 %21)
ret void
}

LLVM IR (-O2):
@.str = [3 x i8] c"%f\00"
define void @test_strtod(double %0, double %1) {
%3 = alloca [1024 x i8]
%4 = alloca i8*
%5 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%6 = call i32 @snprintf(i8* %5, i32 1024, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), double %0)
%7 = bitcast i8** %4 to i8*
store i8* null, i8** %4
%8 = call double @serd_strtod(i8* %5, i8** %4)
%9 = fsub double %8, %0
%10 = call double @llvm.fabs.f64(double %9)
%11 = fcmp ole double %10, %1
%12 = zext i1 %11 to i32
%13 = call i32 @assert(i32 %12)
ret void
}