#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 errno;
double strtod(char *, char **);
double str2double(char *num) {
  double rdouble;
  int p_errno;
  if (num != (char *)NULL) {
    p_errno = errno;
    errno = 0;
    rdouble = strtod(num, (char **)NULL);
    if (errno == 0) {
      errno = p_errno;
      return rdouble;
    }
    return 0.0;
  }
  return 0.0;
}


x86 assembly (clang, -O0):
<str2double>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     118a <str2double+0x7a>
mov    0x2eb2(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x1c(%rbp)
mov    0x2ea6(%rip),%rax
movl   $0x0,(%rax)
mov    -0x10(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1030 <strtod@plt>
movsd  %xmm0,-0x18(%rbp)
mov    0x2e87(%rip),%rax
cmpl   $0x0,(%rax)
jne    117d <str2double+0x6d>
mov    -0x1c(%rbp),%ecx
mov    0x2e74(%rip),%rax
mov    %ecx,(%rax)
movsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    1192 <str2double+0x82>
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    1192 <str2double+0x82>
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x8(%rbp)
movsd  -0x8(%rbp),%xmm0
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<str2double>:
push   %rbp
push   %rbx
push   %rax
xorps  %xmm1,%xmm1
test   %rdi,%rdi
je     113e <str2double+0x2e>
mov    0x2ebe(%rip),%rbx
mov    (%rbx),%ebp
movl   $0x0,(%rbx)
xor    %esi,%esi
call   1030 <strtod@plt>
xorps  %xmm1,%xmm1
cmpl   $0x0,(%rbx)
jne    113e <str2double+0x2e>
mov    %ebp,(%rbx)
movaps %xmm0,%xmm1
movaps %xmm1,%xmm0
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

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

LLVM IR (-O2):
@errno = global i32 0
define double @str2double(i8* %0) {
%2 = icmp eq i8* %0, null
br i1 %2, label %9, label %3
3: ; preds = %1
%4 = load i32, i32* @errno
store i32 0, i32* @errno
%5 = tail call double @strtod(i8* nocapture %0, i8** null)
%6 = load i32, i32* @errno
%7 = icmp eq i32 %6, 0
br i1 %7, label %8, label %9
8: ; preds = %3
store i32 %4, i32* @errno
br label %9
9: ; preds = %1, %3, %8
%10 = phi double [ %5, %8 ], [ 0.000000e+00, %3 ], [ 0.000000e+00, %1 ]
ret double %10
}