#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__ errno;
double strtod(char const *, char **);
double str2double(const char *str, double min, double max, bool *ok) {
  double value;
  char *endptr;
  errno = 0;
  value = strtod(str, &endptr);
  if (errno != 0 || value < min || value > max || endptr == str ||
      *endptr != '\0') {
    if (ok) {
      *ok = false;
    }
    return 0;
  }
  if (ok) {
    *ok = true;
  }
  return value;
}


x86 assembly (clang, -O0):
<str2double>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
movsd  %xmm0,-0x18(%rbp)
movsd  %xmm1,-0x20(%rbp)
mov    %rsi,-0x28(%rbp)
mov    0x2eaf(%rip),%rax
movq   $0x0,(%rax)
mov    -0x10(%rbp),%rdi
lea    -0x38(%rbp),%rsi
call   1030 <strtod@plt>
movsd  %xmm0,-0x30(%rbp)
mov    0x2e8f(%rip),%rax
cmpq   $0x0,(%rax)
jne    119d <str2double+0x8d>
movsd  -0x30(%rbp),%xmm1
movsd  -0x18(%rbp),%xmm0
ucomisd %xmm1,%xmm0
ja     119d <str2double+0x8d>
movsd  -0x30(%rbp),%xmm0
ucomisd -0x20(%rbp),%xmm0
ja     119d <str2double+0x8d>
mov    -0x38(%rbp),%rax
cmp    -0x10(%rbp),%rax
je     119d <str2double+0x8d>
mov    -0x38(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     11bf <str2double+0xaf>
cmpq   $0x0,-0x28(%rbp)
je     11b2 <str2double+0xa2>
mov    -0x28(%rbp),%rax
movl   $0x0,(%rax)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    11de <str2double+0xce>
cmpq   $0x0,-0x28(%rbp)
je     11d4 <str2double+0xc4>
mov    -0x28(%rbp),%rax
movl   $0x1,(%rax)
movsd  -0x30(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
movsd  -0x8(%rbp),%xmm0
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<str2double>:
push   %r15
push   %r14
push   %rbx
sub    $0x20,%rsp
mov    %rsi,%r14
movsd  %xmm1,0x8(%rsp)
movsd  %xmm0,0x10(%rsp)
mov    %rdi,%rbx
mov    0x2eae(%rip),%r15
movq   $0x0,(%r15)
lea    0x18(%rsp),%rsi
call   1030 <strtod@plt>
cmpq   $0x0,(%r15)
jne    116c <str2double+0x5c>
movsd  0x10(%rsp),%xmm1
ucomisd %xmm0,%xmm1
ja     116c <str2double+0x5c>
ucomisd 0x8(%rsp),%xmm0
ja     116c <str2double+0x5c>
mov    0x18(%rsp),%rax
cmp    %rbx,%rax
je     116c <str2double+0x5c>
cmpb   $0x0,(%rax)
je     1184 <str2double+0x74>
xor    %eax,%eax
xorpd  %xmm0,%xmm0
test   %r14,%r14
je     117a <str2double+0x6a>
mov    %eax,(%r14)
add    $0x20,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret
mov    $0x1,%eax
test   %r14,%r14
jne    1177 <str2double+0x67>
jmp    117a <str2double+0x6a>

LLVM IR (-O0):
@errno = global i64 0
define double @str2double(i8* %0, double %1, double %2, i32* %3) {
%5 = alloca double
%6 = alloca i8*
%7 = alloca double
%8 = alloca double
%9 = alloca i32*
%10 = alloca double
%11 = alloca i8*
store i8* %0, i8** %6
store double %1, double* %7
store double %2, double* %8
store i32* %3, i32** %9
store i64 0, i64* @errno
%12 = load i8*, i8** %6
%13 = call double @strtod(i8* %12, i8** %11)
store double %13, double* %10
%14 = load i64, i64* @errno
%15 = icmp ne i64 %14, 0
br i1 %15, label %33, label %16
16: ; preds = %4
%17 = load double, double* %10
%18 = load double, double* %7
%19 = fcmp olt double %17, %18
br i1 %19, label %33, label %20
20: ; preds = %16
%21 = load double, double* %10
%22 = load double, double* %8
%23 = fcmp ogt double %21, %22
br i1 %23, label %33, label %24
24: ; preds = %20
%25 = load i8*, i8** %11
%26 = load i8*, i8** %6
%27 = icmp eq i8* %25, %26
br i1 %27, label %33, label %28
28: ; preds = %24
%29 = load i8*, i8** %11
%30 = load i8, i8* %29
%31 = sext i8 %30 to i32
%32 = icmp ne i32 %31, 0
br i1 %32, label %33, label %39
33: ; preds = %28, %24, %20, %16, %4
%34 = load i32*, i32** %9
%35 = icmp ne i32* %34, null
br i1 %35, label %36, label %38
36: ; preds = %33
%37 = load i32*, i32** %9
store i32 0, i32* %37
br label %38
38: ; preds = %36, %33
store double 0.000000e+00, double* %5
br label %46
39: ; preds = %28
%40 = load i32*, i32** %9
%41 = icmp ne i32* %40, null
br i1 %41, label %42, label %44
42: ; preds = %39
%43 = load i32*, i32** %9
store i32 1, i32* %43
br label %44
44: ; preds = %42, %39
%45 = load double, double* %10
store double %45, double* %5
br label %46
46: ; preds = %44, %38
%47 = load double, double* %5
ret double %47
}

LLVM IR (-O2):
@errno = global i64 0
define double @str2double(i8* %0, double %1, double %2, i32* writeonly %3) {
%5 = alloca i8*
%6 = bitcast i8** %5 to i8*
store i64 0, i64* @errno
%7 = call double @strtod(i8* %0, i8** %5)
%8 = load i64, i64* @errno
%9 = icmp ne i64 %8, 0
%10 = fcmp olt double %7, %1
%11 = select i1 %9, i1 true, i1 %10
%12 = fcmp ogt double %7, %2
%13 = select i1 %11, i1 true, i1 %12
br i1 %13, label %20, label %14
14: ; preds = %4
%15 = load i8*, i8** %5
%16 = icmp eq i8* %15, %0
br i1 %16, label %20, label %17
17: ; preds = %14
%18 = load i8, i8* %15
%19 = icmp eq i8 %18, 0
br i1 %19, label %22, label %20
20: ; preds = %17, %14, %4
%21 = icmp eq i32* %3, null
br i1 %21, label %27, label %24
22: ; preds = %17
%23 = icmp eq i32* %3, null
br i1 %23, label %27, label %24
24: ; preds = %22, %20
%25 = phi i32 [ 0, %20 ], [ 1, %22 ]
%26 = phi double [ 0.000000e+00, %20 ], [ %7, %22 ]
store i32 %25, i32* %3
br label %27
27: ; preds = %24, %22, %20
%28 = phi double [ 0.000000e+00, %20 ], [ %7, %22 ], [ %26, %24 ]
ret double %28
}