#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 */
double DBL_MAX;
scalar_t__ DBL_MIN;
scalar_t__ ERANGE;
scalar_t__ errno;
scalar_t__ fabs(double);
double strtod(char *, char **);
double cdouble(char *s, long int *nerr) {
  double v;
  char *endptr;
  *nerr = 0;
  v = strtod(s, &endptr);
  if (endptr == s) {
    *nerr = 4005;
  } else if (*endptr != '\0') {
    *nerr = 4006;
  } else if (errno == ERANGE) {
    if (v > 0 && v >= DBL_MAX) {
      *nerr = 4003;
    }
    if (fabs(v) >= 0 && fabs(v) <= DBL_MIN) {
      *nerr = 4008;
    }
    if (v < 0 && v <= -DBL_MAX) {
      *nerr = 4004;
    }
  }
  errno = 0;
  return v;
}


x86 assembly (clang, -O0):
<cdouble>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
movq   $0x0,(%rax)
mov    -0x8(%rbp),%rdi
lea    -0x20(%rbp),%rsi
call   1030 <strtod@plt>
movsd  %xmm0,-0x18(%rbp)
mov    -0x20(%rbp),%rax
cmp    -0x8(%rbp),%rax
jne    116b <cdouble+0x4b>
mov    -0x10(%rbp),%rax
movq   $0xfa5,(%rax)
jmp    126a <cdouble+0x14a>
mov    -0x20(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     118b <cdouble+0x6b>
mov    -0x10(%rbp),%rax
movq   $0xfa6,(%rax)
jmp    1265 <cdouble+0x145>
mov    0x2e46(%rip),%rax
mov    (%rax),%rax
mov    0x2e4c(%rip),%rcx
cmp    (%rcx),%rax
jne    1260 <cdouble+0x140>
movsd  -0x18(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jbe    11d8 <cdouble+0xb8>
movsd  -0x18(%rbp),%xmm0
mov    0x2e0d(%rip),%rax
ucomisd (%rax),%xmm0
jb     11d8 <cdouble+0xb8>
mov    -0x10(%rbp),%rax
movq   $0xfa3,(%rax)
movsd  -0x18(%rbp),%xmm0
call   1040 <fabs@plt>
cmp    $0x0,%rax
jl     1211 <cdouble+0xf1>
movsd  -0x18(%rbp),%xmm0
call   1040 <fabs@plt>
mov    0x2dcb(%rip),%rcx
cmp    (%rcx),%rax
jg     1211 <cdouble+0xf1>
mov    -0x10(%rbp),%rax
movq   $0xfa8,(%rax)
xorps  %xmm0,%xmm0
ucomisd -0x18(%rbp),%xmm0
jbe    125b <cdouble+0x13b>
movsd  -0x18(%rbp),%xmm1
mov    0x2da5(%rip),%rax
movsd  (%rax),%xmm0
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
ucomisd %xmm1,%xmm0
jb     125b <cdouble+0x13b>
mov    -0x10(%rbp),%rax
movq   $0xfa4,(%rax)
jmp    1260 <cdouble+0x140>
jmp    1265 <cdouble+0x145>
jmp    126a <cdouble+0x14a>
mov    0x2d67(%rip),%rax
movq   $0x0,(%rax)
movsd  -0x18(%rbp),%xmm0
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<cdouble>:
push   %r14
push   %rbx
sub    $0x18,%rsp
mov    %rsi,%r14
mov    %rdi,%rbx
movq   $0x0,(%rsi)
lea    0x10(%rsp),%rsi
call   1030 <strtod@plt>
mov    0x10(%rsp),%rcx
cmp    %rbx,%rcx
je     11ed <cdouble+0xcd>
mov    $0xfa6,%eax
cmpb   $0x0,(%rcx)
jne    11f2 <cdouble+0xd2>
mov    0x2e77(%rip),%rax
mov    (%rax),%rax
mov    0x2e7d(%rip),%rcx
cmp    (%rcx),%rax
jne    11f5 <cdouble+0xd5>
xorpd  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
mov    0x2e4d(%rip),%rbx
jbe    1192 <cdouble+0x72>
ucomisd (%rbx),%xmm0
jb     1192 <cdouble+0x72>
movq   $0xfa3,(%r14)
movsd  %xmm0,0x8(%rsp)
call   1040 <fabs@plt>
test   %rax,%rax
js     11c0 <cdouble+0xa0>
movsd  0x8(%rsp),%xmm0
call   1040 <fabs@plt>
mov    0x2e14(%rip),%rcx
cmp    (%rcx),%rax
jg     11c0 <cdouble+0xa0>
movq   $0xfa8,(%r14)
xorpd  %xmm0,%xmm0
movsd  0x8(%rsp),%xmm1
ucomisd %xmm1,%xmm0
movapd %xmm1,%xmm0
jbe    11f5 <cdouble+0xd5>
movsd  (%rbx),%xmm1
xorpd  0xe20(%rip),%xmm1
mov    $0xfa4,%eax
ucomisd %xmm0,%xmm1
jae    11f2 <cdouble+0xd2>
jmp    11f5 <cdouble+0xd5>
mov    $0xfa5,%eax
mov    %rax,(%r14)
mov    0x2ddc(%rip),%rax
movq   $0x0,(%rax)
add    $0x18,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@errno = global i64 0
@ERANGE = global i64 0
@DBL_MAX = global double 0.000000e+00
@DBL_MIN = global i64 0
define double @cdouble(i8* %0, i64* %1) {
%3 = alloca i8*
%4 = alloca i64*
%5 = alloca double
%6 = alloca i8*
store i8* %0, i8** %3
store i64* %1, i64** %4
%7 = load i64*, i64** %4
store i64 0, i64* %7
%8 = load i8*, i8** %3
%9 = call double @strtod(i8* %8, i8** %6)
store double %9, double* %5
%10 = load i8*, i8** %6
%11 = load i8*, i8** %3
%12 = icmp eq i8* %10, %11
br i1 %12, label %13, label %15
13: ; preds = %2
%14 = load i64*, i64** %4
store i64 4005, i64* %14
br label %59
15: ; preds = %2
%16 = load i8*, i8** %6
%17 = load i8, i8* %16
%18 = sext i8 %17 to i32
%19 = icmp ne i32 %18, 0
br i1 %19, label %20, label %22
20: ; preds = %15
%21 = load i64*, i64** %4
store i64 4006, i64* %21
br label %58
22: ; preds = %15
%23 = load i64, i64* @errno
%24 = load i64, i64* @ERANGE
%25 = icmp eq i64 %23, %24
br i1 %25, label %26, label %57
26: ; preds = %22
%27 = load double, double* %5
%28 = fcmp ogt double %27, 0.000000e+00
br i1 %28, label %29, label %35
29: ; preds = %26
%30 = load double, double* %5
%31 = load double, double* @DBL_MAX
%32 = fcmp oge double %30, %31
br i1 %32, label %33, label %35
33: ; preds = %29
%34 = load i64*, i64** %4
store i64 4003, i64* %34
br label %35
35: ; preds = %33, %29, %26
%36 = load double, double* %5
%37 = call i64 @fabs(double %36)
%38 = icmp sge i64 %37, 0
br i1 %38, label %39, label %46
39: ; preds = %35
%40 = load double, double* %5
%41 = call i64 @fabs(double %40)
%42 = load i64, i64* @DBL_MIN
%43 = icmp sle i64 %41, %42
br i1 %43, label %44, label %46
44: ; preds = %39
%45 = load i64*, i64** %4
store i64 4008, i64* %45
br label %46
46: ; preds = %44, %39, %35
%47 = load double, double* %5
%48 = fcmp olt double %47, 0.000000e+00
br i1 %48, label %49, label %56
49: ; preds = %46
%50 = load double, double* %5
%51 = load double, double* @DBL_MAX
%52 = fneg double %51
%53 = fcmp ole double %50, %52
br i1 %53, label %54, label %56
54: ; preds = %49
%55 = load i64*, i64** %4
store i64 4004, i64* %55
br label %56
56: ; preds = %54, %49, %46
br label %57
57: ; preds = %56, %22
br label %58
58: ; preds = %57, %20
br label %59
59: ; preds = %58, %13
store i64 0, i64* @errno
%60 = load double, double* %5
ret double %60
}

LLVM IR (-O2):
@errno = global i64 0
@ERANGE = global i64 0
@DBL_MAX = global double 0.000000e+00
@DBL_MIN = global i64 0
define double @cdouble(i8* %0, i64* nocapture writeonly %1) {
%3 = alloca i8*
%4 = bitcast i8** %3 to i8*
store i64 0, i64* %1
%5 = call double @strtod(i8* %0, i8** %3)
%6 = load i8*, i8** %3
%7 = icmp eq i8* %6, %0
br i1 %7, label %35, label %8
8: ; preds = %2
%9 = load i8, i8* %6
%10 = icmp eq i8 %9, 0
br i1 %10, label %11, label %35
11: ; preds = %8
%12 = load i64, i64* @errno
%13 = load i64, i64* @ERANGE
%14 = icmp eq i64 %12, %13
br i1 %14, label %15, label %37
15: ; preds = %11
%16 = fcmp ule double %5, 0.000000e+00
%17 = load double, double* @DBL_MAX
%18 = fcmp ult double %5, %17
%19 = select i1 %16, i1 true, i1 %18
br i1 %19, label %21, label %20
20: ; preds = %15
store i64 4003, i64* %1
br label %21
21: ; preds = %20, %15
%22 = tail call i64 @fabs(double %5)
%23 = icmp sgt i64 %22, -1
br i1 %23, label %24, label %29
24: ; preds = %21
%25 = tail call i64 @fabs(double %5)
%26 = load i64, i64* @DBL_MIN
%27 = icmp sgt i64 %25, %26
br i1 %27, label %29, label %28
28: ; preds = %24
store i64 4008, i64* %1
br label %29
29: ; preds = %28, %24, %21
%30 = fcmp olt double %5, 0.000000e+00
br i1 %30, label %31, label %37
31: ; preds = %29
%32 = load double, double* @DBL_MAX
%33 = fneg double %32
%34 = fcmp ugt double %5, %33
br i1 %34, label %37, label %35
35: ; preds = %31, %8, %2
%36 = phi i64 [ 4005, %2 ], [ 4006, %8 ], [ 4004, %31 ]
store i64 %36, i64* %1
br label %37
37: ; preds = %35, %29, %31, %11
store i64 0, i64* @errno
ret double %5
}