#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__ ERANGE;
double HUGE_VAL;
scalar_t__ errno;
double strtod(char const *, char **);
void read_double_arg(const char *arg, double *result, const char **error) {
  char *endptr;
  errno = 0;
  double d = strtod(arg, &endptr);
  if (*arg == '\0' || *endptr != '\0') {
    *error = "is not a number";
    return;
  }
  if ((errno == ERANGE && d == HUGE_VAL) || d >= 1) {
    *error = "too high";
    return;
  }
  if ((errno == ERANGE && d == -HUGE_VAL) || d <= 0) {
    *error = "too low";
    return;
  }
  *result = d;
}


x86 assembly (clang, -O0):
<read_double_arg>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    0x2ea5(%rip),%rax
movq   $0x0,(%rax)
mov    -0x8(%rbp),%rdi
lea    -0x20(%rbp),%rsi
call   1030 <strtod@plt>
movsd  %xmm0,-0x28(%rbp)
mov    -0x8(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     1164 <read_double_arg+0x54>
mov    -0x20(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     1177 <read_double_arg+0x67>
mov    -0x18(%rbp),%rax
lea    0xe99(%rip),%rcx
mov    %rcx,(%rax)
jmp    1260 <read_double_arg+0x150>
mov    0x2e52(%rip),%rax
mov    (%rax),%rax
mov    0x2e58(%rip),%rcx
cmp    (%rcx),%rax
jne    11b2 <read_double_arg+0xa2>
movsd  -0x28(%rbp),%xmm0
mov    0x2e4b(%rip),%rax
ucomisd (%rax),%xmm0
jne    11b2 <read_double_arg+0xa2>
jp     11b2 <read_double_arg+0xa2>
jmp    11c9 <read_double_arg+0xb9>
movsd  -0x28(%rbp),%xmm0
movsd  0xe41(%rip),%xmm1
ucomisd %xmm1,%xmm0
jb     11dc <read_double_arg+0xcc>
mov    -0x18(%rbp),%rax
lea    0xe44(%rip),%rcx
mov    %rcx,(%rax)
jmp    1260 <read_double_arg+0x150>
mov    0x2ded(%rip),%rax
mov    (%rax),%rax
mov    0x2df3(%rip),%rcx
cmp    (%rcx),%rax
jne    1232 <read_double_arg+0x122>
movsd  -0x28(%rbp),%xmm0
mov    0x2de6(%rip),%rax
movsd  (%rax),%xmm1
movq   %xmm1,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm1
ucomisd %xmm1,%xmm0
jne    1232 <read_double_arg+0x122>
jp     1232 <read_double_arg+0x122>
jmp    1240 <read_double_arg+0x130>
xorps  %xmm0,%xmm0
ucomisd -0x28(%rbp),%xmm0
jb     1253 <read_double_arg+0x143>
mov    -0x18(%rbp),%rax
lea    0xdd6(%rip),%rcx
mov    %rcx,(%rax)
jmp    1260 <read_double_arg+0x150>
movsd  -0x28(%rbp),%xmm0
mov    -0x10(%rbp),%rax
movsd  %xmm0,(%rax)
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<read_double_arg>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rdx,%r15
mov    %rsi,%r14
mov    %rdi,%rbx
mov    0x2ea8(%rip),%r12
movq   $0x0,(%r12)
mov    %rsp,%rsi
call   1030 <strtod@plt>
cmpb   $0x0,(%rbx)
je     1146 <read_double_arg+0x36>
mov    (%rsp),%rax
cmpb   $0x0,(%rax)
je     115c <read_double_arg+0x4c>
lea    0xed3(%rip),%rax
mov    %rax,(%r15)
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret
mov    (%r12),%rax
mov    0x2e79(%rip),%rcx
cmp    (%rcx),%rax
jne    11aa <read_double_arg+0x9a>
ucomisd 0xe8c(%rip),%xmm0
jae    11c7 <read_double_arg+0xb7>
mov    0x2e6b(%rip),%rax
movsd  (%rax),%xmm1
ucomisd %xmm1,%xmm0
jne    1189 <read_double_arg+0x79>
jnp    11c7 <read_double_arg+0xb7>
xorpd  %xmm2,%xmm2
ucomisd %xmm0,%xmm2
jae    11be <read_double_arg+0xae>
xorpd  0xe75(%rip),%xmm1
ucomisd %xmm1,%xmm0
jne    11a3 <read_double_arg+0x93>
jnp    11be <read_double_arg+0xae>
movsd  %xmm0,(%r14)
jmp    1150 <read_double_arg+0x40>
ucomisd 0xe4e(%rip),%xmm0
jae    11c7 <read_double_arg+0xb7>
xorpd  %xmm1,%xmm1
ucomisd %xmm0,%xmm1
jb     11a3 <read_double_arg+0x93>
lea    0xe74(%rip),%rax
jmp    114d <read_double_arg+0x3d>
lea    0xe62(%rip),%rax
jmp    114d <read_double_arg+0x3d>

LLVM IR (-O0):
@errno = global i64 0
@.str = [16 x i8] c"is not a number\00"
@ERANGE = global i64 0
@HUGE_VAL = global double 0.000000e+00
@.str.1 = [9 x i8] c"too high\00"
@.str.2 = [8 x i8] c"too low\00"
define void @read_double_arg(i8* %0, double* %1, i8** %2) {
%4 = alloca i8*
%5 = alloca double*
%6 = alloca i8**
%7 = alloca i8*
%8 = alloca double
store i8* %0, i8** %4
store double* %1, double** %5
store i8** %2, i8*** %6
store i64 0, i64* @errno
%9 = load i8*, i8** %4
%10 = call double @strtod(i8* %9, i8** %7)
store double %10, double* %8
%11 = load i8*, i8** %4
%12 = load i8, i8* %11
%13 = sext i8 %12 to i32
%14 = icmp eq i32 %13, 0
br i1 %14, label %20, label %15
15: ; preds = %3
%16 = load i8*, i8** %7
%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, %3
%21 = load i8**, i8*** %6
store i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i8** %21
br label %52
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 %30
26: ; preds = %22
%27 = load double, double* %8
%28 = load double, double* @HUGE_VAL
%29 = fcmp oeq double %27, %28
br i1 %29, label %33, label %30
30: ; preds = %26, %22
%31 = load double, double* %8
%32 = fcmp oge double %31, 1.000000e+00
br i1 %32, label %33, label %35
33: ; preds = %30, %26
%34 = load i8**, i8*** %6
store i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i8** %34
br label %52
35: ; preds = %30
%36 = load i64, i64* @errno
%37 = load i64, i64* @ERANGE
%38 = icmp eq i64 %36, %37
br i1 %38, label %39, label %44
39: ; preds = %35
%40 = load double, double* %8
%41 = load double, double* @HUGE_VAL
%42 = fneg double %41
%43 = fcmp oeq double %40, %42
br i1 %43, label %47, label %44
44: ; preds = %39, %35
%45 = load double, double* %8
%46 = fcmp ole double %45, 0.000000e+00
br i1 %46, label %47, label %49
47: ; preds = %44, %39
%48 = load i8**, i8*** %6
store i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0), i8** %48
br label %52
49: ; preds = %44
%50 = load double, double* %8
%51 = load double*, double** %5
store double %50, double* %51
br label %52
52: ; preds = %49, %47, %33, %20
ret void
}

LLVM IR (-O2):
@errno = global i64 0
@.str = [16 x i8] c"is not a number\00"
@ERANGE = global i64 0
@HUGE_VAL = global double 0.000000e+00
@.str.1 = [9 x i8] c"too high\00"
@.str.2 = [8 x i8] c"too low\00"
define void @read_double_arg(i8* %0, double* nocapture writeonly %1, i8** nocapture writeonly %2) {
%4 = alloca i8*
%5 = bitcast i8** %4 to i8*
store i64 0, i64* @errno
%6 = call double @strtod(i8* %0, i8** %4)
%7 = load i8, i8* %0
%8 = icmp eq i8 %7, 0
br i1 %8, label %13, label %9
9: ; preds = %3
%10 = load i8*, i8** %4
%11 = load i8, i8* %10
%12 = icmp eq i8 %11, 0
br i1 %12, label %14, label %13
13: ; preds = %9, %3
store i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i8** %2
br label %35
14: ; preds = %9
%15 = load i64, i64* @errno
%16 = load i64, i64* @ERANGE
%17 = icmp eq i64 %15, %16
br i1 %17, label %18, label %23
18: ; preds = %14
%19 = load double, double* @HUGE_VAL
%20 = fcmp oeq double %6, %19
%21 = fcmp oge double %6, 1.000000e+00
%22 = or i1 %21, %20
br i1 %22, label %25, label %26
23: ; preds = %14
%24 = fcmp ult double %6, 1.000000e+00
br i1 %24, label %31, label %25
25: ; preds = %23, %18
store i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i8** %2
br label %35
26: ; preds = %18
%27 = fneg double %19
%28 = fcmp oeq double %6, %27
%29 = fcmp ole double %6, 0.000000e+00
%30 = or i1 %29, %28
br i1 %30, label %33, label %34
31: ; preds = %23
%32 = fcmp ugt double %6, 0.000000e+00
br i1 %32, label %34, label %33
33: ; preds = %31, %26
store i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0), i8** %2
br label %35
34: ; preds = %26, %31
store double %6, double* %1
br label %35
35: ; preds = %34, %33, %25, %13
ret void
}