#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);
double strtod(char *, char **);
size_t wcsrtombs(char *, int /*<<< orphan*/ const **, size_t,
                 int /*<<< orphan*/ *);
double wcstod(const wchar_t *__restrict nptr, wchar_t **__restrict endptr) {
  static const mbstate_t initial;
  mbstate_t state;
  double val;
  char *buf, *end;
  const wchar_t *wcp;
  size_t clen, len;
  while (iswspace(*nptr))
    nptr++;
  state = initial;
  wcp = nptr;
  if ((len = wcsrtombs(NULL, &wcp, 0, &state)) == (size_t)-1) {
    if (endptr != NULL)
      *endptr = (wchar_t *)nptr;
    return (0.0);
  }
  if ((buf = malloc(len + 1)) == NULL)
    return (0.0);
  state = initial;
  wcsrtombs(buf, &wcp, len + 1, &state);
  val = strtod(buf, &end);
  if (endptr != NULL) {
    *endptr = (wchar_t *)nptr + (end - buf);
    (void)clen;
  }
  free(buf);
  return (val);
}


x86 assembly (clang, -O0):
<wcstod>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%edi
call   1070 <iswspace@plt>
cmp    $0x0,%rax
je     1186 <wcstod+0x36>
mov    -0x10(%rbp),%rax
add    $0x4,%rax
mov    %rax,-0x10(%rbp)
jmp    1160 <wcstod+0x10>
mov    0xe74(%rip),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x40(%rbp)
xor    %eax,%eax
mov    %eax,%edx
lea    -0x40(%rbp),%rsi
lea    -0x1c(%rbp),%rcx
mov    %rdx,%rdi
call   1050 <wcsrtombs@plt>
mov    %rax,-0x50(%rbp)
cmp    $0xffffffffffffffff,%rax
jne    11dc <wcstod+0x8c>
cmpq   $0x0,-0x18(%rbp)
je     11cf <wcstod+0x7f>
mov    -0x10(%rbp),%rcx
mov    -0x18(%rbp),%rax
mov    %rcx,(%rax)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    1273 <wcstod+0x123>
mov    -0x50(%rbp),%rdi
add    $0x1,%rdi
call   1060 <malloc@plt>
mov    %rax,-0x30(%rbp)
cmp    $0x0,%rax
jne    1204 <wcstod+0xb4>
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    1273 <wcstod+0x123>
mov    0xdf6(%rip),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x30(%rbp),%rdi
mov    -0x50(%rbp),%rdx
add    $0x1,%rdx
lea    -0x40(%rbp),%rsi
lea    -0x1c(%rbp),%rcx
call   1050 <wcsrtombs@plt>
mov    -0x30(%rbp),%rdi
lea    -0x38(%rbp),%rsi
call   1040 <strtod@plt>
movsd  %xmm0,-0x28(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     1260 <wcstod+0x110>
mov    -0x10(%rbp),%rcx
mov    -0x38(%rbp),%rax
mov    -0x30(%rbp),%rdx
sub    %rdx,%rax
shl    $0x2,%rax
add    %rax,%rcx
mov    -0x18(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x30(%rbp),%rdi
call   1030 <free@plt>
movsd  -0x28(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
movsd  -0x8(%rbp),%xmm0
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<wcstod>:
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   1070 <iswspace@plt>
test   %rax,%rax
jne    1170 <wcstod+0x20>
movl   $0x0,0xc(%rsp)
mov    %rbx,0x10(%rsp)
lea    0x10(%rsp),%rsi
lea    0xc(%rsp),%rcx
xor    %edi,%edi
xor    %edx,%edx
call   1050 <wcsrtombs@plt>
cmp    $0xffffffffffffffff,%rax
je     121c <wcstod+0xcc>
mov    %rax,%r12
add    $0x1,%r12
mov    %r12,%rdi
call   1060 <malloc@plt>
test   %rax,%rax
je     1229 <wcstod+0xd9>
mov    %rax,%r15
movl   $0x0,0xc(%rsp)
lea    0x10(%rsp),%rsi
lea    0xc(%rsp),%rcx
mov    %rax,%rdi
mov    %r12,%rdx
call   1050 <wcsrtombs@plt>
lea    0x20(%rsp),%rsi
mov    %r15,%rdi
call   1040 <strtod@plt>
movsd  %xmm0,0x18(%rsp)
test   %r14,%r14
je     120c <wcstod+0xbc>
mov    0x20(%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>
movsd  0x18(%rsp),%xmm0
jmp    122c <wcstod+0xdc>
xorps  %xmm0,%xmm0
test   %r14,%r14
je     122c <wcstod+0xdc>
mov    %rbx,(%r14)
jmp    122c <wcstod+0xdc>
xorps  %xmm0,%xmm0
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

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

LLVM IR (-O2):
define double @wcstod(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 0, i32* %3
store i32* %10, i32** %5
%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 double @strtod(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 double [ %27, %35 ], [ 0.000000e+00, %20 ], [ 0.000000e+00, %18 ], [ 0.000000e+00, %21 ]
ret double %38
}