#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;
int /*<<< orphan*/ fprint_err(char *, ...);
int /*<<< orphan*/ print_err(char *);
int /*<<< orphan*/ strerror(scalar_t__);
double strtod(char *, char **);
extern int double_value(char *prefix, char *cmd, char *arg, int positive,
                        double *value) {
  char *ptr;
  double val;
  errno = 0;
  val = strtod(arg, &ptr);
  if (errno) {
    print_err("### ");
    if (prefix != NULL)
      fprint_err("%s: ", prefix);
    if (errno == ERANGE && val == 0)
      fprint_err("String cannot be converted to (double) float in %s %s\n", cmd,
                 arg);
    else if (errno == ERANGE && (val == HUGE_VAL || val == -HUGE_VAL))
      fprint_err("Number is too big (overflows) in %s %s\n", cmd, arg);
    else
      fprint_err("Cannot read number in %s %s (%s)\n", cmd, arg,
                 strerror(errno));
    return 1;
  }
  if (ptr[0] != '\0') {
    print_err("### ");
    if (prefix != NULL)
      fprint_err("%s: ", prefix);
    fprint_err("Unexpected characters ('%s') after the %.*s in %s %s\n", ptr,
               (int)(ptr - arg), arg, cmd, arg);
    return 1;
  }
  if (positive && val < 0) {
    print_err("### ");
    if (prefix != NULL)
      fprint_err("%s: ", prefix);
    fprint_err("Value %f (in %s %s) is less than zero\n", val, cmd, arg);
    return 1;
  }
  *value = val;
  return 0;
}


x86 assembly (clang, -O0):
<double_value>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %ecx,-0x24(%rbp)
mov    %r8,-0x30(%rbp)
mov    0x2e6e(%rip),%rax
movq   $0x0,(%rax)
mov    -0x20(%rbp),%rdi
lea    -0x38(%rbp),%rsi
call   1050 <strtod@plt>
movsd  %xmm0,-0x40(%rbp)
mov    0x2e4e(%rip),%rax
cmpq   $0x0,(%rax)
je     12d7 <double_value+0x197>
lea    0xe6d(%rip),%rdi
call   1040 <print_err@plt>
cmpq   $0x0,-0x10(%rbp)
je     11b5 <double_value+0x75>
mov    -0x10(%rbp),%rsi
lea    0xe57(%rip),%rdi
mov    $0x0,%al
call   1030 <fprint_err@plt>
mov    0x2e14(%rip),%rax
mov    (%rax),%rax
mov    0x2e1a(%rip),%rcx
cmp    (%rcx),%rax
jne    1202 <double_value+0xc2>
movsd  -0x40(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jne    1202 <double_value+0xc2>
jp     1202 <double_value+0xc2>
mov    -0x18(%rbp),%rsi
mov    -0x20(%rbp),%rdx
lea    0xe14(%rip),%rdi
mov    $0x0,%al
call   1030 <fprint_err@plt>
jmp    12cb <double_value+0x18b>
mov    0x2dc7(%rip),%rax
mov    (%rax),%rax
mov    0x2dcd(%rip),%rcx
cmp    (%rcx),%rax
jne    128f <double_value+0x14f>
movsd  -0x40(%rbp),%xmm0
mov    0x2dc0(%rip),%rax
ucomisd (%rax),%xmm0
jne    123d <double_value+0xfd>
jp     123d <double_value+0xfd>
jmp    1274 <double_value+0x134>
movsd  -0x40(%rbp),%xmm0
mov    0x2d9f(%rip),%rax
movsd  (%rax),%xmm1
movq   %xmm1,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm1
ucomisd %xmm1,%xmm0
jne    128f <double_value+0x14f>
jp     128f <double_value+0x14f>
mov    -0x18(%rbp),%rsi
mov    -0x20(%rbp),%rdx
lea    0xdbe(%rip),%rdi
mov    $0x0,%al
call   1030 <fprint_err@plt>
jmp    12c6 <double_value+0x186>
mov    -0x18(%rbp),%rax
mov    %rax,-0x50(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,-0x48(%rbp)
mov    0x2d2a(%rip),%rax
mov    (%rax),%rdi
call   1060 <strerror@plt>
mov    -0x50(%rbp),%rsi
mov    -0x48(%rbp),%rdx
mov    %eax,%ecx
lea    0xdaa(%rip),%rdi
mov    $0x0,%al
call   1030 <fprint_err@plt>
jmp    12cb <double_value+0x18b>
movl   $0x1,-0x4(%rbp)
jmp    13c3 <double_value+0x283>
mov    -0x38(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     1347 <double_value+0x207>
lea    0xd12(%rip),%rdi
call   1040 <print_err@plt>
cmpq   $0x0,-0x10(%rbp)
je     1310 <double_value+0x1d0>
mov    -0x10(%rbp),%rsi
lea    0xcfc(%rip),%rdi
mov    $0x0,%al
call   1030 <fprint_err@plt>
mov    -0x38(%rbp),%rsi
mov    -0x38(%rbp),%rax
mov    -0x20(%rbp),%rcx
sub    %rcx,%rax
mov    %eax,%edx
mov    -0x20(%rbp),%rcx
mov    -0x18(%rbp),%r8
mov    -0x20(%rbp),%r9
lea    0xd57(%rip),%rdi
mov    $0x0,%al
call   1030 <fprint_err@plt>
movl   $0x1,-0x4(%rbp)
jmp    13c3 <double_value+0x283>
cmpl   $0x0,-0x24(%rbp)
je     13af <double_value+0x26f>
xorps  %xmm0,%xmm0
ucomisd -0x40(%rbp),%xmm0
jbe    13af <double_value+0x26f>
lea    0xc9a(%rip),%rdi
call   1040 <print_err@plt>
cmpq   $0x0,-0x10(%rbp)
je     1388 <double_value+0x248>
mov    -0x10(%rbp),%rsi
lea    0xc84(%rip),%rdi
mov    $0x0,%al
call   1030 <fprint_err@plt>
movsd  -0x40(%rbp),%xmm0
mov    -0x18(%rbp),%rsi
mov    -0x20(%rbp),%rdx
lea    0xd25(%rip),%rdi
mov    $0x1,%al
call   1030 <fprint_err@plt>
movl   $0x1,-0x4(%rbp)
jmp    13c3 <double_value+0x283>
movsd  -0x40(%rbp),%xmm0
mov    -0x30(%rbp),%rax
movsd  %xmm0,(%rax)
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<double_value>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %r8,%r13
mov    %ecx,%r14d
mov    %rdx,%r15
mov    %rsi,%r12
mov    %rdi,%rbx
mov    0x2e6c(%rip),%rbp
movq   $0x0,0x0(%rbp)
lea    0x10(%rsp),%rsi
mov    %rdx,%rdi
call   1050 <strtod@plt>
cmpq   $0x0,0x0(%rbp)
je     11d9 <double_value+0x99>
movsd  %xmm0,0x8(%rsp)
lea    0xe83(%rip),%rdi
call   1040 <print_err@plt>
test   %rbx,%rbx
je     11a8 <double_value+0x68>
lea    0xe77(%rip),%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1030 <fprint_err@plt>
mov    0x0(%rbp),%rdi
mov    0x2e2d(%rip),%rax
mov    (%rax),%rax
cmp    %rax,%rdi
movsd  0x8(%rsp),%xmm1
jne    1233 <double_value+0xf3>
xorpd  %xmm0,%xmm0
ucomisd %xmm0,%xmm1
jne    1233 <double_value+0xf3>
jp     1233 <double_value+0xf3>
lea    0xe46(%rip),%rdi
jmp    12d6 <double_value+0x196>
mov    %r12,%rbp
mov    0x10(%rsp),%r12
cmpb   $0x0,(%r12)
je     127c <double_value+0x13c>
lea    0xe1d(%rip),%rdi
call   1040 <print_err@plt>
test   %rbx,%rbx
je     120e <double_value+0xce>
lea    0xe11(%rip),%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1030 <fprint_err@plt>
mov    %r12d,%edx
sub    %r15d,%edx
lea    0xe80(%rip),%rdi
mov    %r12,%rsi
mov    %r15,%rcx
mov    %rbp,%r8
mov    %r15,%r9
xor    %eax,%eax
call   1030 <fprint_err@plt>
jmp    12e3 <double_value+0x1a3>
cmp    %rax,%rdi
jne    125f <double_value+0x11f>
mov    0x2da9(%rip),%rax
movsd  (%rax),%xmm0
ucomisd %xmm0,%xmm1
jne    124f <double_value+0x10f>
jnp    12cf <double_value+0x18f>
xorpd  0xda9(%rip),%xmm0
ucomisd %xmm0,%xmm1
jne    125f <double_value+0x11f>
jnp    12cf <double_value+0x18f>
call   1060 <strerror@plt>
lea    0xe0e(%rip),%rdi
mov    %r12,%rsi
mov    %r15,%rdx
mov    %eax,%ecx
xor    %eax,%eax
call   1030 <fprint_err@plt>
jmp    12e3 <double_value+0x1a3>
test   %r14d,%r14d
je     12f7 <double_value+0x1b7>
xorpd  %xmm1,%xmm1
ucomisd %xmm0,%xmm1
jbe    12f7 <double_value+0x1b7>
movsd  %xmm0,0x8(%rsp)
lea    0xd78(%rip),%rdi
call   1040 <print_err@plt>
test   %rbx,%rbx
je     12b3 <double_value+0x173>
lea    0xd6c(%rip),%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1030 <fprint_err@plt>
lea    0xe17(%rip),%rdi
movsd  0x8(%rsp),%xmm0
mov    %rbp,%rsi
mov    %r15,%rdx
mov    $0x1,%al
call   1030 <fprint_err@plt>
jmp    12e3 <double_value+0x1a3>
lea    0xd7b(%rip),%rdi
mov    %r12,%rsi
mov    %r15,%rdx
xor    %eax,%eax
call   1030 <fprint_err@plt>
mov    $0x1,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
movsd  %xmm0,0x0(%r13)
xor    %eax,%eax
jmp    12e8 <double_value+0x1a8>

LLVM IR (-O0):
@errno = global i64 0
@.str = [5 x i8] c"### \00"
@.str.1 = [5 x i8] c"%s: \00"
@ERANGE = global i64 0
@.str.2 = [55 x i8] c"String cannot be converted to (double) float in %s %s\0A\00"
@HUGE_VAL = global double 0.000000e+00
@.str.3 = [40 x i8] c"Number is too big (overflows) in %s %s\0A\00"
@.str.4 = [34 x i8] c"Cannot read number in %s %s (%s)\0A\00"
@.str.5 = [54 x i8] c"Unexpected characters ('%s') after the %.*s in %s %s\0A\00"
@.str.6 = [39 x i8] c"Value %f (in %s %s) is less than zero\0A\00"
define i32 @double_value(i8* %0, i8* %1, i8* %2, i32 %3, double* %4) {
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i8*
%10 = alloca i32
%11 = alloca double*
%12 = alloca i8*
%13 = alloca double
store i8* %0, i8** %7
store i8* %1, i8** %8
store i8* %2, i8** %9
store i32 %3, i32* %10
store double* %4, double** %11
store i64 0, i64* @errno
%14 = load i8*, i8** %9
%15 = call double @strtod(i8* %14, i8** %12)
store double %15, double* %13
%16 = load i64, i64* @errno
%17 = icmp ne i64 %16, 0
br i1 %17, label %18, label %61
18: ; preds = %5
%19 = call i32 @print_err(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%20 = load i8*, i8** %7
%21 = icmp ne i8* %20, null
br i1 %21, label %22, label %25
22: ; preds = %18
%23 = load i8*, i8** %7
%24 = call i32 (i8*, ...) @fprint_err(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i8* %23)
br label %25
25: ; preds = %22, %18
%26 = load i64, i64* @errno
%27 = load i64, i64* @ERANGE
%28 = icmp eq i64 %26, %27
br i1 %28, label %29, label %36
29: ; preds = %25
%30 = load double, double* %13
%31 = fcmp oeq double %30, 0.000000e+00
br i1 %31, label %32, label %36
32: ; preds = %29
%33 = load i8*, i8** %8
%34 = load i8*, i8** %9
%35 = call i32 (i8*, ...) @fprint_err(i8* getelementptr inbounds ([55 x i8], [55 x i8]* @.str.2, i64 0, i64 0), i8* %33, i8* %34)
br label %60
36: ; preds = %29, %25
%37 = load i64, i64* @errno
%38 = load i64, i64* @ERANGE
%39 = icmp eq i64 %37, %38
br i1 %39, label %40, label %53
40: ; preds = %36
%41 = load double, double* %13
%42 = load double, double* @HUGE_VAL
%43 = fcmp oeq double %41, %42
br i1 %43, label %49, label %44
44: ; preds = %40
%45 = load double, double* %13
%46 = load double, double* @HUGE_VAL
%47 = fneg double %46
%48 = fcmp oeq double %45, %47
br i1 %48, label %49, label %53
49: ; preds = %44, %40
%50 = load i8*, i8** %8
%51 = load i8*, i8** %9
%52 = call i32 (i8*, ...) @fprint_err(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.3, i64 0, i64 0), i8* %50, i8* %51)
br label %59
53: ; preds = %44, %36
%54 = load i8*, i8** %8
%55 = load i8*, i8** %9
%56 = load i64, i64* @errno
%57 = call i32 @strerror(i64 %56)
%58 = call i32 (i8*, ...) @fprint_err(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.4, i64 0, i64 0), i8* %54, i8* %55, i32 %57)
br label %59
59: ; preds = %53, %49
br label %60
60: ; preds = %59, %32
store i32 1, i32* %6
br label %107
61: ; preds = %5
%62 = load i8*, i8** %12
%63 = getelementptr inbounds i8, i8* %62, i64 0
%64 = load i8, i8* %63
%65 = sext i8 %64 to i32
%66 = icmp ne i32 %65, 0
br i1 %66, label %67, label %86
67: ; preds = %61
%68 = call i32 @print_err(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%69 = load i8*, i8** %7
%70 = icmp ne i8* %69, null
br i1 %70, label %71, label %74
71: ; preds = %67
%72 = load i8*, i8** %7
%73 = call i32 (i8*, ...) @fprint_err(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i8* %72)
br label %74
74: ; preds = %71, %67
%75 = load i8*, i8** %12
%76 = load i8*, i8** %12
%77 = load i8*, i8** %9
%78 = ptrtoint i8* %76 to i64
%79 = ptrtoint i8* %77 to i64
%80 = sub i64 %78, %79
%81 = trunc i64 %80 to i32
%82 = load i8*, i8** %9
%83 = load i8*, i8** %8
%84 = load i8*, i8** %9
%85 = call i32 (i8*, ...) @fprint_err(i8* getelementptr inbounds ([54 x i8], [54 x i8]* @.str.5, i64 0, i64 0), i8* %75, i32 %81, i8* %82, i8* %83, i8* %84)
store i32 1, i32* %6
br label %107
86: ; preds = %61
%87 = load i32, i32* %10
%88 = icmp ne i32 %87, 0
br i1 %88, label %89, label %104
89: ; preds = %86
%90 = load double, double* %13
%91 = fcmp olt double %90, 0.000000e+00
br i1 %91, label %92, label %104
92: ; preds = %89
%93 = call i32 @print_err(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%94 = load i8*, i8** %7
%95 = icmp ne i8* %94, null
br i1 %95, label %96, label %99
96: ; preds = %92
%97 = load i8*, i8** %7
%98 = call i32 (i8*, ...) @fprint_err(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i8* %97)
br label %99
99: ; preds = %96, %92
%100 = load double, double* %13
%101 = load i8*, i8** %8
%102 = load i8*, i8** %9
%103 = call i32 (i8*, ...) @fprint_err(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.6, i64 0, i64 0), double %100, i8* %101, i8* %102)
store i32 1, i32* %6
br label %107
104: ; preds = %89, %86
%105 = load double, double* %13
%106 = load double*, double** %11
store double %105, double* %106
store i32 0, i32* %6
br label %107
107: ; preds = %104, %99, %74, %60
%108 = load i32, i32* %6
ret i32 %108
}

LLVM IR (-O2):
@errno = global i64 0
@.str = [5 x i8] c"### \00"
@.str.1 = [5 x i8] c"%s: \00"
@ERANGE = global i64 0
@.str.2 = [55 x i8] c"String cannot be converted to (double) float in %s %s\0A\00"
@HUGE_VAL = global double 0.000000e+00
@.str.3 = [40 x i8] c"Number is too big (overflows) in %s %s\0A\00"
@.str.4 = [34 x i8] c"Cannot read number in %s %s (%s)\0A\00"
@.str.5 = [54 x i8] c"Unexpected characters ('%s') after the %.*s in %s %s\0A\00"
@.str.6 = [39 x i8] c"Value %f (in %s %s) is less than zero\0A\00"
define i32 @double_value(i8* %0, i8* %1, i8* %2, i32 %3, double* nocapture writeonly %4) {
%6 = alloca i8*
%7 = bitcast i8** %6 to i8*
store i64 0, i64* @errno
%8 = call double @strtod(i8* %2, i8** %6)
%9 = load i64, i64* @errno
%10 = icmp eq i64 %9, 0
br i1 %10, label %36, label %11
11: ; preds = %5
%12 = tail call i32 @print_err(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%13 = icmp eq i8* %0, null
br i1 %13, label %16, label %14
14: ; preds = %11
%15 = tail call i32 (i8*, ...) @fprint_err(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i8* %0)
br label %16
16: ; preds = %14, %11
%17 = load i64, i64* @errno
%18 = load i64, i64* @ERANGE
%19 = icmp eq i64 %17, %18
%20 = fcmp oeq double %8, 0.000000e+00
%21 = select i1 %19, i1 %20, i1 false
br i1 %21, label %22, label %24
22: ; preds = %16
%23 = tail call i32 (i8*, ...) @fprint_err(i8* getelementptr inbounds ([55 x i8], [55 x i8]* @.str.2, i64 0, i64 0), i8* %1, i8* %2)
br label %63
24: ; preds = %16
br i1 %19, label %25, label %33
25: ; preds = %24
%26 = load double, double* @HUGE_VAL
%27 = fcmp oeq double %8, %26
%28 = fneg double %26
%29 = fcmp oeq double %8, %28
%30 = or i1 %27, %29
br i1 %30, label %31, label %33
31: ; preds = %25
%32 = tail call i32 (i8*, ...) @fprint_err(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.3, i64 0, i64 0), i8* %1, i8* %2)
br label %63
33: ; preds = %25, %24
%34 = tail call i32 @strerror(i64 %17)
%35 = tail call i32 (i8*, ...) @fprint_err(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.4, i64 0, i64 0), i8* %1, i8* %2, i32 %34)
br label %63
36: ; preds = %5
%37 = load i8*, i8** %6
%38 = load i8, i8* %37
%39 = icmp eq i8 %38, 0
br i1 %39, label %51, label %40
40: ; preds = %36
%41 = tail call i32 @print_err(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%42 = icmp eq i8* %0, null
br i1 %42, label %45, label %43
43: ; preds = %40
%44 = tail call i32 (i8*, ...) @fprint_err(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i8* %0)
br label %45
45: ; preds = %43, %40
%46 = ptrtoint i8* %37 to i64
%47 = ptrtoint i8* %2 to i64
%48 = sub i64 %46, %47
%49 = trunc i64 %48 to i32
%50 = tail call i32 (i8*, ...) @fprint_err(i8* getelementptr inbounds ([54 x i8], [54 x i8]* @.str.5, i64 0, i64 0), i8* %37, i32 %49, i8* %2, i8* %1, i8* %2)
br label %63
51: ; preds = %36
%52 = icmp ne i32 %3, 0
%53 = fcmp olt double %8, 0.000000e+00
%54 = select i1 %52, i1 %53, i1 false
br i1 %54, label %55, label %62
55: ; preds = %51
%56 = tail call i32 @print_err(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%57 = icmp eq i8* %0, null
br i1 %57, label %60, label %58
58: ; preds = %55
%59 = tail call i32 (i8*, ...) @fprint_err(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i8* %0)
br label %60
60: ; preds = %58, %55
%61 = tail call i32 (i8*, ...) @fprint_err(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.6, i64 0, i64 0), double %8, i8* %1, i8* %2)
br label %63
62: ; preds = %51
store double %8, double* %4
br label %63
63: ; preds = %22, %33, %31, %62, %60, %45
%64 = phi i32 [ 1, %45 ], [ 1, %60 ], [ 0, %62 ], [ 1, %31 ], [ 1, %33 ], [ 1, %22 ]
ret i32 %64
}