#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;
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char const *const);
int /*<<< orphan*/ stderr;
size_t strlen(char const *const);
double strtod(char const *const, char **);
double get_double(const char *const str, char **endptr, size_t *const len) {
  double val;
  *len = strlen(str);
  errno = 0;
  val = strtod(str, endptr);
  if (errno) {
    (void)fprintf(stderr, "Invalid value %s.\n", str);
    exit((1));
  }
  if (*len == 0) {
    (void)fprintf(stderr, "Value %s is an invalid size.\n", str);
    exit((1));
  }
  return val;
}


x86 assembly (clang, -O0):
<get_double>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <strlen@plt>
mov    %rax,%rcx
mov    -0x18(%rbp),%rax
mov    %rcx,(%rax)
mov    0x2e6a(%rip),%rax
movq   $0x0,(%rax)
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1030 <strtod@plt>
movsd  %xmm0,-0x20(%rbp)
mov    0x2e4a(%rip),%rax
cmpq   $0x0,(%rax)
je     11bb <get_double+0x7b>
mov    0x2e41(%rip),%rax
mov    (%rax),%edi
mov    -0x8(%rbp),%rdx
lea    0xe54(%rip),%rsi
call   1050 <fprintf@plt>
mov    $0x1,%edi
call   1060 <exit@plt>
mov    -0x18(%rbp),%rax
cmpq   $0x0,(%rax)
jne    11ec <get_double+0xac>
mov    0x2e10(%rip),%rax
mov    (%rax),%edi
mov    -0x8(%rbp),%rdx
lea    0xe36(%rip),%rsi
call   1050 <fprintf@plt>
mov    $0x1,%edi
call   1060 <exit@plt>
movsd  -0x20(%rbp),%xmm0
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_double>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rdx,%rbx
mov    %rsi,%r15
mov    %rdi,%r14
call   1040 <strlen@plt>
mov    %rax,(%rbx)
mov    0x2e78(%rip),%r12
movq   $0x0,(%r12)
mov    %r14,%rdi
mov    %r15,%rsi
call   1030 <strtod@plt>
cmpq   $0x0,(%r12)
jne    118c <get_double+0x4c>
cmpq   $0x0,(%rbx)
je     119e <get_double+0x5e>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret
mov    0x2e4d(%rip),%rax
mov    (%rax),%edi
lea    0xe64(%rip),%rsi
jmp    11ae <get_double+0x6e>
mov    0x2e3b(%rip),%rax
mov    (%rax),%edi
lea    0xe65(%rip),%rsi
mov    %r14,%rdx
call   1050 <fprintf@plt>
mov    $0x1,%edi
call   1060 <exit@plt>

LLVM IR (-O0):
@errno = global i64 0
@stderr = global i32 0
@.str = [19 x i8] c"Invalid value %s.\0A\00"
@.str.1 = [30 x i8] c"Value %s is an invalid size.\0A\00"
define double @get_double(i8* %0, i8** %1, i64* %2) {
%4 = alloca i8*
%5 = alloca i8**
%6 = alloca i64*
%7 = alloca double
store i8* %0, i8** %4
store i8** %1, i8*** %5
store i64* %2, i64** %6
%8 = load i8*, i8** %4
%9 = call i64 @strlen(i8* %8)
%10 = load i64*, i64** %6
store i64 %9, i64* %10
store i64 0, i64* @errno
%11 = load i8*, i8** %4
%12 = load i8**, i8*** %5
%13 = call double @strtod(i8* %11, i8** %12)
store double %13, double* %7
%14 = load i64, i64* @errno
%15 = icmp ne i64 %14, 0
br i1 %15, label %16, label %21
16: ; preds = %3
%17 = load i32, i32* @stderr
%18 = load i8*, i8** %4
%19 = call i32 @fprintf(i32 %17, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0), i8* %18)
%20 = call i32 @exit(i32 1)
unreachable
21: ; preds = %3
%22 = load i64*, i64** %6
%23 = load i64, i64* %22
%24 = icmp eq i64 %23, 0
br i1 %24, label %25, label %30
25: ; preds = %21
%26 = load i32, i32* @stderr
%27 = load i8*, i8** %4
%28 = call i32 @fprintf(i32 %26, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.1, i64 0, i64 0), i8* %27)
%29 = call i32 @exit(i32 1)
unreachable
30: ; preds = %21
%31 = load double, double* %7
ret double %31
}

LLVM IR (-O2):
@errno = global i64 0
@stderr = global i32 0
@.str = [19 x i8] c"Invalid value %s.\0A\00"
@.str.1 = [30 x i8] c"Value %s is an invalid size.\0A\00"
define double @get_double(i8* %0, i8** nocapture %1, i64* nocapture %2) {
%4 = tail call i64 @strlen(i8* dereferenceable(1) %0)
store i64 %4, i64* %2
store i64 0, i64* @errno
%5 = tail call double @strtod(i8* %0, i8** %1)
%6 = load i64, i64* @errno
%7 = icmp eq i64 %6, 0
br i1 %7, label %12, label %8
8: ; preds = %3
%9 = load i32, i32* @stderr
%10 = tail call i32 @fprintf(i32 %9, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0), i8* %0)
%11 = tail call i32 @exit(i32 1)
unreachable
12: ; preds = %3
%13 = load i64, i64* %2
%14 = icmp eq i64 %13, 0
br i1 %14, label %15, label %19
15: ; preds = %12
%16 = load i32, i32* @stderr
%17 = tail call i32 @fprintf(i32 %16, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.1, i64 0, i64 0), i8* %0)
%18 = tail call i32 @exit(i32 1)
unreachable
19: ; preds = %12
ret double %5
}