#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 *,
                           scalar_t__);
int /*<<< orphan*/ stderr;
double strtod(char const *, int /*<<< orphan*/ *);
double to_double(const char *s) {
  double val;
  errno = 0;
  val = strtod(s, NULL);
  if (errno != 0) {
    fprintf(stderr,
            "*** Can\'t read string \'%s\' as a double; errno = %d ***\n", s,
            errno);
    errno = 0;
    exit(EXIT_FAILURE);
  }
  return val;
}


x86 assembly (clang, -O0):
<to_double>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
mov    0x2e95(%rip),%rax
movq   $0x0,(%rax)
mov    -0x8(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1030 <strtod@plt>
movsd  %xmm0,-0x10(%rbp)
mov    0x2e75(%rip),%rax
cmpq   $0x0,(%rax)
je     11ac <to_double+0x7c>
mov    0x2e6c(%rip),%rax
mov    (%rax),%edi
mov    -0x8(%rbp),%rdx
mov    0x2e57(%rip),%rax
mov    (%rax),%rcx
lea    0xe75(%rip),%rsi
call   1040 <fprintf@plt>
mov    0x2e41(%rip),%rax
movq   $0x0,(%rax)
mov    0x2e2b(%rip),%rax
mov    (%rax),%edi
call   1050 <exit@plt>
movsd  -0x10(%rbp),%xmm0
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<to_double>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%rbx
mov    0x2e9a(%rip),%r14
movq   $0x0,(%r14)
xor    %esi,%esi
call   1030 <strtod@plt>
mov    (%r14),%rcx
test   %rcx,%rcx
jne    115c <to_double+0x2c>
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret
mov    0x2e7d(%rip),%rax
mov    (%rax),%edi
lea    0xe94(%rip),%rsi
mov    %rbx,%rdx
call   1040 <fprintf@plt>
movq   $0x0,(%r14)
mov    0x2e4e(%rip),%rax
mov    (%rax),%edi
call   1050 <exit@plt>

LLVM IR (-O0):
@errno = global i64 0
@stderr = global i32 0
@.str = [56 x i8] c"*** Can't read string '%s' as a double; errno = %d ***\0A\00"
@EXIT_FAILURE = global i32 0
define double @to_double(i8* %0) {
%2 = alloca i8*
%3 = alloca double
store i8* %0, i8** %2
store i64 0, i64* @errno
%4 = load i8*, i8** %2
%5 = call double @strtod(i8* %4, i32* null)
store double %5, double* %3
%6 = load i64, i64* @errno
%7 = icmp ne i64 %6, 0
br i1 %7, label %8, label %15
8: ; preds = %1
%9 = load i32, i32* @stderr
%10 = load i8*, i8** %2
%11 = load i64, i64* @errno
%12 = call i32 @fprintf(i32 %9, i8* getelementptr inbounds ([56 x i8], [56 x i8]* @.str, i64 0, i64 0), i8* %10, i64 %11)
store i64 0, i64* @errno
%13 = load i32, i32* @EXIT_FAILURE
%14 = call i32 @exit(i32 %13)
unreachable
15: ; preds = %1
%16 = load double, double* %3
ret double %16
}

LLVM IR (-O2):
@errno = global i64 0
@stderr = global i32 0
@.str = [56 x i8] c"*** Can't read string '%s' as a double; errno = %d ***\0A\00"
@EXIT_FAILURE = global i32 0
define double @to_double(i8* %0) {
store i64 0, i64* @errno
%2 = tail call double @strtod(i8* nocapture %0, i32* null)
%3 = load i64, i64* @errno
%4 = icmp eq i64 %3, 0
br i1 %4, label %10, label %5
5: ; preds = %1
%6 = load i32, i32* @stderr
%7 = tail call i32 @fprintf(i32 %6, i8* getelementptr inbounds ([56 x i8], [56 x i8]* @.str, i64 0, i64 0), i8* %0, i64 %3)
store i64 0, i64* @errno
%8 = load i32, i32* @EXIT_FAILURE
%9 = tail call i32 @exit(i32 %8)
unreachable
10: ; preds = %1
ret double %2
}