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


x86 assembly (clang, -O0):
<str2ldouble>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     1181 <str2ldouble+0x71>
mov    0x2eb2(%rip),%rax
mov    (%rax),%ecx
mov    %ecx,-0x34(%rbp)
movl   $0x0,(%rax)
mov    -0x18(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1030 <strtod@plt>
mov    %rax,-0x40(%rbp)
fildll -0x40(%rbp)
fstpt  -0x30(%rbp)
mov    0x2e89(%rip),%rax
cmpl   $0x0,(%rax)
jne    1177 <str2ldouble+0x67>
mov    -0x34(%rbp),%ecx
mov    0x2e76(%rip),%rax
mov    %ecx,(%rax)
fldt   -0x30(%rbp)
fstpt  -0x10(%rbp)
jmp    1186 <str2ldouble+0x76>
fldz
fstpt  -0x10(%rbp)
jmp    1186 <str2ldouble+0x76>
fldz
fstpt  -0x10(%rbp)
fldt   -0x10(%rbp)
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<str2ldouble>:
push   %rbp
push   %rbx
sub    $0x18,%rsp
fldz
test   %rdi,%rdi
je     114b <str2ldouble+0x3b>
mov    0x2ebc(%rip),%rbx
mov    (%rbx),%ebp
movl   $0x0,(%rbx)
xor    %esi,%esi
fstpt  0xc(%rsp)
call   1030 <strtod@plt>
fldt   0xc(%rsp)
cmpl   $0x0,(%rbx)
jne    114b <str2ldouble+0x3b>
fstp   %st(0)
mov    %rax,(%rsp)
fildll (%rsp)
mov    %ebp,(%rbx)
add    $0x18,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@errno = global i32 0
define x86_fp80 @str2ldouble(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 %19
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 i64 @strtod(i8* %10, i8** null)
%12 = sitofp i64 %11 to x86_fp80
store x86_fp80 %12, x86_fp80* %4
%13 = load i32, i32* @errno
%14 = icmp eq i32 %13, 0
br i1 %14, label %15, label %18
15: ; preds = %8
%16 = load i32, i32* %5
store i32 %16, i32* @errno
%17 = load x86_fp80, x86_fp80* %4
store x86_fp80 %17, x86_fp80* %2
br label %20
18: ; preds = %8
store x86_fp80 0xK00000000000000000000, x86_fp80* %2
br label %20
19: ; preds = %1
store x86_fp80 0xK00000000000000000000, x86_fp80* %2
br label %20
20: ; preds = %19, %18, %15
%21 = load x86_fp80, x86_fp80* %2
ret x86_fp80 %21
}

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