#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 */
int /*<<< orphan*/ EXIT_FAILURE;
scalar_t__ errno;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char const *const);
int /*<<< orphan*/ stderr;
size_t strlen(char const *const);
double strtod(char const *const, int /*<<< orphan*/ *);
double get_double(const char *const str, size_t *const len) {
  double val;
  *len = strlen(str);
  errno = 0;
  val = strtod(str, NULL);
  if (errno) {
    (void)fprintf(stderr, "Invalid value %s.\n", str);
    exit(EXIT_FAILURE);
  }
  if (*len == 0) {
    (void)fprintf(stderr, "Value %s is an invalid size.\n", str);
    exit(EXIT_FAILURE);
  }
  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    -0x8(%rbp),%rdi
call   1040 <strlen@plt>
mov    %rax,%rcx
mov    -0x10(%rbp),%rax
mov    %rcx,(%rax)
mov    0x2e6e(%rip),%rax
movq   $0x0,(%rax)
mov    -0x8(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1030 <strtod@plt>
movsd  %xmm0,-0x18(%rbp)
mov    0x2e4e(%rip),%rax
cmpq   $0x0,(%rax)
je     11bb <get_double+0x7b>
mov    0x2e45(%rip),%rax
mov    (%rax),%edi
mov    -0x8(%rbp),%rdx
lea    0xe58(%rip),%rsi
call   1050 <fprintf@plt>
mov    0x2e1c(%rip),%rax
mov    (%rax),%edi
call   1060 <exit@plt>
mov    -0x10(%rbp),%rax
cmpq   $0x0,(%rax)
jne    11f0 <get_double+0xb0>
mov    0x2e10(%rip),%rax
mov    (%rax),%edi
mov    -0x8(%rbp),%rdx
lea    0xe36(%rip),%rsi
call   1050 <fprintf@plt>
mov    0x2de7(%rip),%rax
mov    (%rax),%edi
call   1060 <exit@plt>
movsd  -0x18(%rbp),%xmm0
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_double>:
push   %r15
push   %r14
push   %rbx
mov    %rsi,%rbx
mov    %rdi,%r14
call   1040 <strlen@plt>
mov    %rax,(%rbx)
mov    0x2e7e(%rip),%r15
movq   $0x0,(%r15)
mov    %r14,%rdi
xor    %esi,%esi
call   1030 <strtod@plt>
cmpq   $0x0,(%r15)
jne    117d <get_double+0x3d>
cmpq   $0x0,(%rbx)
je     118f <get_double+0x4f>
pop    %rbx
pop    %r14
pop    %r15
ret
mov    0x2e5c(%rip),%rax
mov    (%rax),%edi
lea    0xe73(%rip),%rsi
jmp    119f <get_double+0x5f>
mov    0x2e4a(%rip),%rax
mov    (%rax),%edi
lea    0xe74(%rip),%rsi
mov    %r14,%rdx
call   1050 <fprintf@plt>
mov    0x2e22(%rip),%rax
mov    (%rax),%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"
@EXIT_FAILURE = global i32 0
@.str.1 = [30 x i8] c"Value %s is an invalid size.\0A\00"
define double @get_double(i8* %0, i64* %1) {
%3 = alloca i8*
%4 = alloca i64*
%5 = alloca double
store i8* %0, i8** %3
store i64* %1, i64** %4
%6 = load i8*, i8** %3
%7 = call i64 @strlen(i8* %6)
%8 = load i64*, i64** %4
store i64 %7, i64* %8
store i64 0, i64* @errno
%9 = load i8*, i8** %3
%10 = call double @strtod(i8* %9, i32* null)
store double %10, double* %5
%11 = load i64, i64* @errno
%12 = icmp ne i64 %11, 0
br i1 %12, label %13, label %19
13: ; preds = %2
%14 = load i32, i32* @stderr
%15 = load i8*, i8** %3
%16 = call i32 @fprintf(i32 %14, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0), i8* %15)
%17 = load i32, i32* @EXIT_FAILURE
%18 = call i32 @exit(i32 %17)
unreachable
19: ; preds = %2
%20 = load i64*, i64** %4
%21 = load i64, i64* %20
%22 = icmp eq i64 %21, 0
br i1 %22, label %23, label %29
23: ; preds = %19
%24 = load i32, i32* @stderr
%25 = load i8*, i8** %3
%26 = call i32 @fprintf(i32 %24, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.1, i64 0, i64 0), i8* %25)
%27 = load i32, i32* @EXIT_FAILURE
%28 = call i32 @exit(i32 %27)
unreachable
29: ; preds = %19
%30 = load double, double* %5
ret double %30
}

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