#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 */
typedef int /*<<< orphan*/ wchar_t;
typedef int /*<<< orphan*/ mbstate_t;

/* Variables and functions */
int /*<<< orphan*/ free(char *);
scalar_t__ iswspace(int /*<<< orphan*/ const);
char *malloc(size_t);
long double strtold(char *, char **);
size_t wcsrtombs(char *, int /*<<< orphan*/ const **, size_t,
                 int /*<<< orphan*/ *);
long double wcstold(const wchar_t *__restrict nptr,
                    wchar_t **__restrict endptr) {
  static const mbstate_t initial;
  mbstate_t mbs;
  long double val;
  char *buf, *end;
  const wchar_t *wcp;
  size_t len;
  while (iswspace(*nptr))
    nptr++;
  wcp = nptr;
  mbs = initial;
  if ((len = wcsrtombs(NULL, &wcp, 0, &mbs)) == (size_t)-1) {
    if (endptr != NULL)
      *endptr = (wchar_t *)nptr;
    return (0.0);
  }
  if ((buf = malloc(len + 1)) == NULL)
    return (0.0);
  mbs = initial;
  wcsrtombs(buf, &wcp, len + 1, &mbs);
  val = strtold(buf, &end);
  if (endptr != NULL)
    *endptr = (wchar_t *)nptr + (end - buf);
  free(buf);
  return (val);
}


x86 assembly (clang, -O0):
<wcstold>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %rdi,-0x18(%rbp)
mov    %rsi,-0x20(%rbp)
mov    -0x18(%rbp),%rax
mov    (%rax),%edi
call   1060 <iswspace@plt>
cmp    $0x0,%rax
je     1186 <wcstold+0x36>
mov    -0x18(%rbp),%rax
add    $0x4,%rax
mov    %rax,-0x18(%rbp)
jmp    1160 <wcstold+0x10>
mov    -0x18(%rbp),%rax
mov    %rax,-0x58(%rbp)
mov    0xe6c(%rip),%eax
mov    %eax,-0x24(%rbp)
xor    %eax,%eax
mov    %eax,%edx
lea    -0x58(%rbp),%rsi
lea    -0x24(%rbp),%rcx
mov    %rdx,%rdi
call   1040 <wcsrtombs@plt>
mov    %rax,-0x60(%rbp)
cmp    $0xffffffffffffffff,%rax
jne    11d9 <wcstold+0x89>
cmpq   $0x0,-0x20(%rbp)
je     11cf <wcstold+0x7f>
mov    -0x18(%rbp),%rcx
mov    -0x20(%rbp),%rax
mov    %rcx,(%rax)
fldz
fstpt  -0x10(%rbp)
jmp    1267 <wcstold+0x117>
mov    -0x60(%rbp),%rdi
add    $0x1,%rdi
call   1050 <malloc@plt>
mov    %rax,-0x48(%rbp)
cmp    $0x0,%rax
jne    11fe <wcstold+0xae>
fldz
fstpt  -0x10(%rbp)
jmp    1267 <wcstold+0x117>
mov    0xdfc(%rip),%eax
mov    %eax,-0x24(%rbp)
mov    -0x48(%rbp),%rdi
mov    -0x60(%rbp),%rdx
add    $0x1,%rdx
lea    -0x58(%rbp),%rsi
lea    -0x24(%rbp),%rcx
call   1040 <wcsrtombs@plt>
mov    -0x48(%rbp),%rdi
lea    -0x50(%rbp),%rsi
call   1070 <strtold@plt>
fstpt  -0x40(%rbp)
cmpq   $0x0,-0x20(%rbp)
je     1258 <wcstold+0x108>
mov    -0x18(%rbp),%rcx
mov    -0x50(%rbp),%rax
mov    -0x48(%rbp),%rdx
sub    %rdx,%rax
shl    $0x2,%rax
add    %rax,%rcx
mov    -0x20(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x48(%rbp),%rdi
call   1030 <free@plt>
fldt   -0x40(%rbp)
fstpt  -0x10(%rbp)
fldt   -0x10(%rbp)
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<wcstold>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x28,%rsp
mov    %rsi,%r14
mov    %rdi,%rbx
add    $0xfffffffffffffffc,%rbx
cs nopw 0x0(%rax,%rax,1)
nop
mov    0x4(%rbx),%edi
add    $0x4,%rbx
call   1060 <iswspace@plt>
test   %rax,%rax
jne    1170 <wcstold+0x20>
mov    %rbx,0x8(%rsp)
movl   $0x0,0x4(%rsp)
lea    0x8(%rsp),%rsi
lea    0x4(%rsp),%rcx
xor    %edi,%edi
xor    %edx,%edx
call   1040 <wcsrtombs@plt>
cmp    $0xffffffffffffffff,%rax
je     121c <wcstold+0xcc>
mov    %rax,%r12
add    $0x1,%r12
mov    %r12,%rdi
call   1050 <malloc@plt>
fldz
test   %rax,%rax
je     1226 <wcstold+0xd6>
mov    %rax,%r15
fstp   %st(0)
movl   $0x0,0x4(%rsp)
lea    0x8(%rsp),%rsi
lea    0x4(%rsp),%rcx
mov    %rax,%rdi
mov    %r12,%rdx
call   1040 <wcsrtombs@plt>
lea    0x10(%rsp),%rsi
mov    %r15,%rdi
call   1070 <strtold@plt>
fstpt  0x1c(%rsp)
test   %r14,%r14
je     120e <wcstold+0xbe>
mov    0x10(%rsp),%rax
shl    $0x2,%rax
mov    %r15,%rcx
shl    $0x2,%rcx
sub    %rcx,%rax
add    %rax,%rbx
mov    %rbx,(%r14)
mov    %r15,%rdi
call   1030 <free@plt>
fldt   0x1c(%rsp)
jmp    1226 <wcstold+0xd6>
fldz
test   %r14,%r14
je     1226 <wcstold+0xd6>
mov    %rbx,(%r14)
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@wcstold.initial = internal constant i32 0
define x86_fp80 @wcstold(i32* noalias %0, i32** noalias %1) {
%3 = alloca x86_fp80
%4 = alloca i32*
%5 = alloca i32**
%6 = alloca i32
%7 = alloca x86_fp80
%8 = alloca i8*
%9 = alloca i8*
%10 = alloca i32*
%11 = alloca i64
store i32* %0, i32** %4
store i32** %1, i32*** %5
br label %12
12: ; preds = %17, %2
%13 = load i32*, i32** %4
%14 = load i32, i32* %13
%15 = call i64 @iswspace(i32 %14)
%16 = icmp ne i64 %15, 0
br i1 %16, label %17, label %20
17: ; preds = %12
%18 = load i32*, i32** %4
%19 = getelementptr inbounds i32, i32* %18, i32 1
store i32* %19, i32** %4
br label %12
20: ; preds = %12
%21 = load i32*, i32** %4
store i32* %21, i32** %10
%22 = load i32, i32* @wcstold.initial
store i32 %22, i32* %6
%23 = call i64 @wcsrtombs(i8* null, i32** %10, i64 0, i32* %6)
store i64 %23, i64* %11
%24 = icmp eq i64 %23, -1
br i1 %24, label %25, label %32
25: ; preds = %20
%26 = load i32**, i32*** %5
%27 = icmp ne i32** %26, null
br i1 %27, label %28, label %31
28: ; preds = %25
%29 = load i32*, i32** %4
%30 = load i32**, i32*** %5
store i32* %29, i32** %30
br label %31
31: ; preds = %28, %25
store x86_fp80 0xK00000000000000000000, x86_fp80* %3
br label %61
32: ; preds = %20
%33 = load i64, i64* %11
%34 = add i64 %33, 1
%35 = call i8* @malloc(i64 %34)
store i8* %35, i8** %8
%36 = icmp eq i8* %35, null
br i1 %36, label %37, label %38
37: ; preds = %32
store x86_fp80 0xK00000000000000000000, x86_fp80* %3
br label %61
38: ; preds = %32
%39 = load i32, i32* @wcstold.initial
store i32 %39, i32* %6
%40 = load i8*, i8** %8
%41 = load i64, i64* %11
%42 = add i64 %41, 1
%43 = call i64 @wcsrtombs(i8* %40, i32** %10, i64 %42, i32* %6)
%44 = load i8*, i8** %8
%45 = call x86_fp80 @strtold(i8* %44, i8** %9)
store x86_fp80 %45, x86_fp80* %7
%46 = load i32**, i32*** %5
%47 = icmp ne i32** %46, null
br i1 %47, label %48, label %57
48: ; preds = %38
%49 = load i32*, i32** %4
%50 = load i8*, i8** %9
%51 = load i8*, i8** %8
%52 = ptrtoint i8* %50 to i64
%53 = ptrtoint i8* %51 to i64
%54 = sub i64 %52, %53
%55 = getelementptr inbounds i32, i32* %49, i64 %54
%56 = load i32**, i32*** %5
store i32* %55, i32** %56
br label %57
57: ; preds = %48, %38
%58 = load i8*, i8** %8
%59 = call i32 @free(i8* %58)
%60 = load x86_fp80, x86_fp80* %7
store x86_fp80 %60, x86_fp80* %3
br label %61
61: ; preds = %57, %37, %31
%62 = load x86_fp80, x86_fp80* %3
ret x86_fp80 %62
}

LLVM IR (-O2):
define x86_fp80 @wcstold(i32* noalias %0, i32** noalias writeonly %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i32*
%6 = bitcast i32* %3 to i8*
%7 = bitcast i8** %4 to i8*
%8 = bitcast i32** %5 to i8*
br label %9
9: ; preds = %9, %2
%10 = phi i32* [ %0, %2 ], [ %14, %9 ]
%11 = load i32, i32* %10
%12 = tail call i64 @iswspace(i32 %11)
%13 = icmp eq i64 %12, 0
%14 = getelementptr inbounds i32, i32* %10, i64 1
br i1 %13, label %15, label %9
15: ; preds = %9
store i32* %10, i32** %5
store i32 0, i32* %3
%16 = call i64 @wcsrtombs(i8* null, i32** %5, i64 0, i32* %3)
%17 = icmp eq i64 %16, -1
br i1 %17, label %18, label %21
18: ; preds = %15
%19 = icmp eq i32** %1, null
br i1 %19, label %37, label %20
20: ; preds = %18
store i32* %10, i32** %1
br label %37
21: ; preds = %15
%22 = add nuw i64 %16, 1
%23 = call i8* @malloc(i64 %22)
%24 = icmp eq i8* %23, null
br i1 %24, label %37, label %25
25: ; preds = %21
store i32 0, i32* %3
%26 = call i64 @wcsrtombs(i8* %23, i32** %5, i64 %22, i32* %3)
%27 = call x86_fp80 @strtold(i8* %23, i8** %4)
%28 = icmp eq i32** %1, null
br i1 %28, label %35, label %29
29: ; preds = %25
%30 = load i8*, i8** %4
%31 = ptrtoint i8* %30 to i64
%32 = ptrtoint i8* %23 to i64
%33 = sub i64 %31, %32
%34 = getelementptr inbounds i32, i32* %10, i64 %33
store i32* %34, i32** %1
br label %35
35: ; preds = %29, %25
%36 = call i32 @free(i8* %23)
br label %37
37: ; preds = %21, %18, %20, %35
%38 = phi x86_fp80 [ %27, %35 ], [ 0xK00000000000000000000, %20 ], [ 0xK00000000000000000000, %18 ], [ 0xK00000000000000000000, %21 ]
ret x86_fp80 %38
}