#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;
int /*<<< orphan*/ Log(char *, char const *, char const *);
scalar_t__ errno;
char *getenv(char const *);
double strtod(char const *, char **);
double GetDoubleSetting(const char *name, double def) {
  const char *value = getenv(name);
  if (value == NULL || value[0] == 0) {
    return def;
  }
  char *endptr = NULL;
  errno = 0;
  double number = strtod(value, &endptr);
  if (errno == ERANGE) {
    Log("Ignoring out-of-range value of %s: %s", name, value);
    return def;
  }
  if ((endptr != NULL && *endptr != 0)) {
    Log("Ignoring non-numeric value of %s: %s", name, value);
    return def;
  }
  return number;
}


x86 assembly (clang, -O0):
<GetDoubleSetting>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
movsd  %xmm0,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <getenv@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
je     1169 <GetDoubleSetting+0x39>
mov    -0x20(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
jne    1178 <GetDoubleSetting+0x48>
movsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    1225 <GetDoubleSetting+0xf5>
movq   $0x0,-0x28(%rbp)
mov    0x2e51(%rip),%rax
movq   $0x0,(%rax)
mov    -0x20(%rbp),%rdi
lea    -0x28(%rbp),%rsi
call   1040 <strtod@plt>
movsd  %xmm0,-0x30(%rbp)
mov    0x2e31(%rip),%rax
mov    (%rax),%rax
mov    0x2e37(%rip),%rcx
cmp    (%rcx),%rax
jne    11dd <GetDoubleSetting+0xad>
mov    -0x10(%rbp),%rsi
mov    -0x20(%rbp),%rdx
lea    0xe37(%rip),%rdi
call   1050 <Log@plt>
movsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    1225 <GetDoubleSetting+0xf5>
cmpq   $0x0,-0x28(%rbp)
je     121b <GetDoubleSetting+0xeb>
mov    -0x28(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     121b <GetDoubleSetting+0xeb>
mov    -0x10(%rbp),%rsi
mov    -0x20(%rbp),%rdx
lea    0xe1f(%rip),%rdi
call   1050 <Log@plt>
movsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    1225 <GetDoubleSetting+0xf5>
movsd  -0x30(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
movsd  -0x8(%rbp),%xmm0
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<GetDoubleSetting>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
movsd  %xmm0,(%rsp)
mov    %rdi,%r14
call   1030 <getenv@plt>
test   %rax,%rax
je     11b0 <GetDoubleSetting+0x80>
mov    %rax,%rbx
cmpb   $0x0,(%rax)
je     11b0 <GetDoubleSetting+0x80>
movq   $0x0,0x8(%rsp)
mov    0x2e75(%rip),%r15
movq   $0x0,(%r15)
lea    0x8(%rsp),%rsi
mov    %rbx,%rdi
call   1040 <strtod@plt>
mov    (%r15),%rax
mov    0x2e67(%rip),%rcx
cmp    (%rcx),%rax
jne    118f <GetDoubleSetting+0x5f>
lea    0xe73(%rip),%rdi
jmp    11a5 <GetDoubleSetting+0x75>
mov    0x8(%rsp),%rax
test   %rax,%rax
je     11b5 <GetDoubleSetting+0x85>
cmpb   $0x0,(%rax)
je     11b5 <GetDoubleSetting+0x85>
lea    0xe81(%rip),%rdi
mov    %r14,%rsi
mov    %rbx,%rdx
call   1050 <Log@plt>
movsd  (%rsp),%xmm0
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@errno = global i64 0
@ERANGE = global i64 0
@.str = [38 x i8] c"Ignoring out-of-range value of %s: %s\00"
@.str.1 = [37 x i8] c"Ignoring non-numeric value of %s: %s\00"
define double @GetDoubleSetting(i8* %0, double %1) {
%3 = alloca double
%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
%9 = load i8*, i8** %4
%10 = call i8* @getenv(i8* %9)
store i8* %10, i8** %6
%11 = load i8*, i8** %6
%12 = icmp eq i8* %11, null
br i1 %12, label %19, label %13
13: ; preds = %2
%14 = load i8*, i8** %6
%15 = getelementptr inbounds i8, i8* %14, i64 0
%16 = load i8, i8* %15
%17 = sext i8 %16 to i32
%18 = icmp eq i32 %17, 0
br i1 %18, label %19, label %21
19: ; preds = %13, %2
%20 = load double, double* %5
store double %20, double* %3
br label %47
21: ; preds = %13
store i8* null, i8** %7
store i64 0, i64* @errno
%22 = load i8*, i8** %6
%23 = call double @strtod(i8* %22, i8** %7)
store double %23, double* %8
%24 = load i64, i64* @errno
%25 = load i64, i64* @ERANGE
%26 = icmp eq i64 %24, %25
br i1 %26, label %27, label %32
27: ; preds = %21
%28 = load i8*, i8** %4
%29 = load i8*, i8** %6
%30 = call i32 @Log(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str, i64 0, i64 0), i8* %28, i8* %29)
%31 = load double, double* %5
store double %31, double* %3
br label %47
32: ; preds = %21
%33 = load i8*, i8** %7
%34 = icmp ne i8* %33, null
br i1 %34, label %35, label %45
35: ; preds = %32
%36 = load i8*, i8** %7
%37 = load i8, i8* %36
%38 = sext i8 %37 to i32
%39 = icmp ne i32 %38, 0
br i1 %39, label %40, label %45
40: ; preds = %35
%41 = load i8*, i8** %4
%42 = load i8*, i8** %6
%43 = call i32 @Log(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.1, i64 0, i64 0), i8* %41, i8* %42)
%44 = load double, double* %5
store double %44, double* %3
br label %47
45: ; preds = %35, %32
%46 = load double, double* %8
store double %46, double* %3
br label %47
47: ; preds = %45, %40, %27, %19
%48 = load double, double* %3
ret double %48
}

LLVM IR (-O2):
@errno = global i64 0
@ERANGE = global i64 0
@.str = [38 x i8] c"Ignoring out-of-range value of %s: %s\00"
@.str.1 = [37 x i8] c"Ignoring non-numeric value of %s: %s\00"
define double @GetDoubleSetting(i8* %0, double %1) {
%3 = alloca i8*
%4 = tail call i8* @getenv(i8* %0)
%5 = icmp eq i8* %4, null
br i1 %5, label %26, label %6
6: ; preds = %2
%7 = load i8, i8* %4
%8 = icmp eq i8 %7, 0
br i1 %8, label %26, label %9
9: ; preds = %6
%10 = bitcast i8** %3 to i8*
store i8* null, i8** %3
store i64 0, i64* @errno
%11 = call double @strtod(i8* %4, i8** %3)
%12 = load i64, i64* @errno
%13 = load i64, i64* @ERANGE
%14 = icmp eq i64 %12, %13
br i1 %14, label %21, label %15
15: ; preds = %9
%16 = load i8*, i8** %3
%17 = icmp eq i8* %16, null
br i1 %17, label %24, label %18
18: ; preds = %15
%19 = load i8, i8* %16
%20 = icmp eq i8 %19, 0
br i1 %20, label %24, label %21
21: ; preds = %18, %9
%22 = phi i8* [ getelementptr inbounds ([38 x i8], [38 x i8]* @.str, i64 0, i64 0), %9 ], [ getelementptr inbounds ([37 x i8], [37 x i8]* @.str.1, i64 0, i64 0), %18 ]
%23 = tail call i32 @Log(i8* %22, i8* %0, i8* %4)
br label %24
24: ; preds = %21, %15, %18
%25 = phi double [ %11, %18 ], [ %11, %15 ], [ %1, %21 ]
br label %26
26: ; preds = %2, %6, %24
%27 = phi double [ %25, %24 ], [ %1, %6 ], [ %1, %2 ]
ret double %27
}