#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__ EINVAL;
scalar_t__ errno;
double strtod(char const *, char **);
double get_double(const char *s) {
  char *tail;
  double x;
  errno = 0;
  if (!s)
    return 0;
  x = strtod(s, &tail);
  if (errno)
    return 0;
  if (*tail) {
    errno = EINVAL;
    return 0;
  }
  return x;
}


x86 assembly (clang, -O0):
<get_double>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    0x2ebd(%rip),%rax
movq   $0x0,(%rax)
cmpq   $0x0,-0x10(%rbp)
jne    1142 <get_double+0x32>
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    11aa <get_double+0x9a>
mov    -0x10(%rbp),%rdi
lea    -0x18(%rbp),%rsi
call   1030 <strtod@plt>
movsd  %xmm0,-0x20(%rbp)
mov    0x2e85(%rip),%rax
cmpq   $0x0,(%rax)
je     1172 <get_double+0x62>
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    11aa <get_double+0x9a>
mov    -0x18(%rbp),%rax
cmpb   $0x0,(%rax)
je     11a0 <get_double+0x90>
mov    0x2e52(%rip),%rax
mov    (%rax),%rcx
mov    0x2e50(%rip),%rax
mov    %rcx,(%rax)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    11aa <get_double+0x9a>
movsd  -0x20(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
movsd  -0x8(%rbp),%xmm0
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_double>:
push   %rbx
sub    $0x10,%rsp
mov    0x2ec4(%rip),%rbx
movq   $0x0,(%rbx)
xorps  %xmm0,%xmm0
test   %rdi,%rdi
je     1155 <get_double+0x45>
lea    0x8(%rsp),%rsi
call   1030 <strtod@plt>
cmpq   $0x0,(%rbx)
jne    1152 <get_double+0x42>
mov    0x8(%rsp),%rax
cmpb   $0x0,(%rax)
je     1155 <get_double+0x45>
mov    0x2e8c(%rip),%rax
mov    (%rax),%rax
mov    %rax,(%rbx)
xorps  %xmm0,%xmm0
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@errno = global i64 0
@EINVAL = global i64 0
define double @get_double(i8* %0) {
%2 = alloca double
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca double
store i8* %0, i8** %3
store i64 0, i64* @errno
%6 = load i8*, i8** %3
%7 = icmp ne i8* %6, null
br i1 %7, label %9, label %8
8: ; preds = %1
store double 0.000000e+00, double* %2
br label %23
9: ; preds = %1
%10 = load i8*, i8** %3
%11 = call double @strtod(i8* %10, i8** %4)
store double %11, double* %5
%12 = load i64, i64* @errno
%13 = icmp ne i64 %12, 0
br i1 %13, label %14, label %15
14: ; preds = %9
store double 0.000000e+00, double* %2
br label %23
15: ; preds = %9
%16 = load i8*, i8** %4
%17 = load i8, i8* %16
%18 = icmp ne i8 %17, 0
br i1 %18, label %19, label %21
19: ; preds = %15
%20 = load i64, i64* @EINVAL
store i64 %20, i64* @errno
store double 0.000000e+00, double* %2
br label %23
21: ; preds = %15
%22 = load double, double* %5
store double %22, double* %2
br label %23
23: ; preds = %21, %19, %14, %8
%24 = load double, double* %2
ret double %24
}

LLVM IR (-O2):
@errno = global i64 0
@EINVAL = global i64 0
define double @get_double(i8* %0) {
%2 = alloca i8*
%3 = bitcast i8** %2 to i8*
store i64 0, i64* @errno
%4 = icmp eq i8* %0, null
br i1 %4, label %15, label %5
5: ; preds = %1
%6 = call double @strtod(i8* %0, i8** %2)
%7 = load i64, i64* @errno
%8 = icmp eq i64 %7, 0
br i1 %8, label %9, label %15
9: ; preds = %5
%10 = load i8*, i8** %2
%11 = load i8, i8* %10
%12 = icmp eq i8 %11, 0
br i1 %12, label %15, label %13
13: ; preds = %9
%14 = load i64, i64* @EINVAL
store i64 %14, i64* @errno
br label %15
15: ; preds = %9, %5, %1, %13
%16 = phi double [ 0.000000e+00, %13 ], [ 0.000000e+00, %1 ], [ 0.000000e+00, %5 ], [ %6, %9 ]
ret double %16
}