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


x86 assembly (clang, -O0):
<str2ldoublep>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     11d0 <str2ldoublep+0xa0>
mov    $0x8,%edi
call   1050 <xmalloc@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     11ba <str2ldoublep+0x8a>
mov    0x2e79(%rip),%rax
mov    (%rax),%ecx
mov    %ecx,-0x1c(%rbp)
movl   $0x0,(%rax)
mov    -0x10(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1030 <strtod@plt>
mov    %rax,-0x28(%rbp)
fildll -0x28(%rbp)
mov    -0x18(%rbp),%rax
fstpt  (%rax)
mov    0x2e4d(%rip),%rax
cmpl   $0x0,(%rax)
jne    11b5 <str2ldoublep+0x85>
mov    -0x1c(%rbp),%ecx
mov    0x2e3a(%rip),%rax
mov    %ecx,(%rax)
mov    -0x18(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    11d8 <str2ldoublep+0xa8>
jmp    11ba <str2ldoublep+0x8a>
mov    -0x18(%rbp),%rdi
call   1040 <xfree@plt>
movq   $0x0,-0x8(%rbp)
jmp    11d8 <str2ldoublep+0xa8>
movq   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<str2ldoublep>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
test   %rdi,%rdi
je     1183 <str2ldoublep+0x53>
mov    %rdi,%r14
mov    $0x8,%edi
call   1050 <xmalloc@plt>
mov    %rax,%rbx
test   %rax,%rax
je     117b <str2ldoublep+0x4b>
mov    0x2e88(%rip),%r15
mov    (%r15),%ebp
movl   $0x0,(%r15)
mov    %r14,%rdi
xor    %esi,%esi
call   1030 <strtod@plt>
mov    %rax,(%rsp)
fildll (%rsp)
fstpt  (%rbx)
cmpl   $0x0,(%r15)
je     1193 <str2ldoublep+0x63>
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    1185 <str2ldoublep+0x55>

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

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