#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 **);
int /*<<< orphan*/ xfree(double *);
double *xmalloc(int);
double *str2doublep(char *num) {
  double *rdouble;
  int p_errno;
  if (num != (char *)NULL) {
    rdouble = xmalloc(sizeof(double));
    if (rdouble != (double *)NULL) {
      p_errno = errno;
      errno = 0;
      *rdouble = strtod(num, (char **)NULL);
      if (errno == 0) {
        errno = p_errno;
        return rdouble;
      }
    }
    xfree(rdouble);
    return (double *)NULL;
  }
  return (double *)NULL;
}


x86 assembly (clang, -O0):
<str2doublep>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     11d2 <str2doublep+0xa2>
mov    $0x8,%edi
call   1050 <xmalloc@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     11bc <str2doublep+0x8c>
mov    0x2e79(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x1c(%rbp)
mov    0x2e6d(%rip),%rax
movl   $0x0,(%rax)
mov    -0x10(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1030 <strtod@plt>
mov    -0x18(%rbp),%rax
movsd  %xmm0,(%rax)
mov    0x2e4b(%rip),%rax
cmpl   $0x0,(%rax)
jne    11b7 <str2doublep+0x87>
mov    -0x1c(%rbp),%ecx
mov    0x2e38(%rip),%rax
mov    %ecx,(%rax)
mov    -0x18(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    11da <str2doublep+0xaa>
jmp    11bc <str2doublep+0x8c>
mov    -0x18(%rbp),%rdi
call   1040 <xfree@plt>
movq   $0x0,-0x8(%rbp)
jmp    11da <str2doublep+0xaa>
movq   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<str2doublep>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
test   %rdi,%rdi
je     117e <str2doublep+0x4e>
mov    %rdi,%r14
mov    $0x8,%edi
call   1050 <xmalloc@plt>
mov    %rax,%rbx
test   %rax,%rax
je     1176 <str2doublep+0x46>
mov    0x2e88(%rip),%r15
mov    (%r15),%ebp
movl   $0x0,(%r15)
mov    %r14,%rdi
xor    %esi,%esi
call   1030 <strtod@plt>
movsd  %xmm0,(%rbx)
cmpl   $0x0,(%r15)
je     118e <str2doublep+0x5e>
mov    %rbx,%rdi
call   1040 <xfree@plt>
xor    %ebx,%ebx
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
mov    %ebp,(%r15)
jmp    1180 <str2doublep+0x50>

LLVM IR (-O0):
@errno = global i32 0
define double* @str2doublep(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 %26
8: ; preds = %1
%9 = call double* @xmalloc(i32 8)
store double* %9, double** %4
%10 = load double*, double** %4
%11 = icmp ne double* %10, null
br i1 %11, label %12, label %23
12: ; preds = %8
%13 = load i32, i32* @errno
store i32 %13, i32* %5
store i32 0, i32* @errno
%14 = load i8*, i8** %3
%15 = call double @strtod(i8* %14, i8** null)
%16 = load double*, double** %4
store double %15, double* %16
%17 = load i32, i32* @errno
%18 = icmp eq i32 %17, 0
br i1 %18, label %19, label %22
19: ; preds = %12
%20 = load i32, i32* %5
store i32 %20, i32* @errno
%21 = load double*, double** %4
store double* %21, double** %2
br label %27
22: ; preds = %12
br label %23
23: ; preds = %22, %8
%24 = load double*, double** %4
%25 = call i32 @xfree(double* %24)
store double* null, double** %2
br label %27
26: ; preds = %1
store double* null, double** %2
br label %27
27: ; preds = %26, %23, %19
%28 = load double*, double** %2
ret double* %28
}

LLVM IR (-O2):
@errno = global i32 0
define double* @str2doublep(i8* %0) {
%2 = icmp eq i8* %0, null
br i1 %2, label %14, label %3
3: ; preds = %1
%4 = tail call double* @xmalloc(i32 8)
%5 = icmp eq double* %4, null
br i1 %5, label %12, label %6
6: ; preds = %3
%7 = load i32, i32* @errno
store i32 0, i32* @errno
%8 = tail call double @strtod(i8* nocapture %0, i8** null)
store double %8, double* %4
%9 = load i32, i32* @errno
%10 = icmp eq i32 %9, 0
br i1 %10, label %11, label %12
11: ; preds = %6
store i32 %7, i32* @errno
br label %14
12: ; preds = %6, %3
%13 = tail call i32 @xfree(double* %4)
br label %14
14: ; preds = %1, %12, %11
%15 = phi double* [ %4, %11 ], [ null, %12 ], [ null, %1 ]
ret double* %15
}