#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);
float strtof(char *, char **);
size_t wcsrtombs(char *, int /*<<< orphan*/ const **, size_t,
                 int /*<<< orphan*/ *);
float wcstof(const wchar_t *__restrict nptr, wchar_t **__restrict endptr) {
  static const mbstate_t initial;
  mbstate_t mbs;
  float 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 = strtof(buf, &end);
  if (endptr != NULL)
    *endptr = (wchar_t *)nptr + (end - buf);
  free(buf);
  return (val);
}


x86 assembly (clang, -O0):
<wcstof>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%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 <wcstof+0x36>
mov    -0x10(%rbp),%rax
add    $0x4,%rax
mov    %rax,-0x10(%rbp)
jmp    1160 <wcstof+0x10>
mov    -0x10(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    0xe6c(%rip),%eax
mov    %eax,-0x1c(%rbp)
xor    %eax,%eax
mov    %eax,%edx
lea    -0x38(%rbp),%rsi
lea    -0x1c(%rbp),%rcx
mov    %rdx,%rdi
call   1040 <wcsrtombs@plt>
mov    %rax,-0x40(%rbp)
cmp    $0xffffffffffffffff,%rax
jne    11dc <wcstof+0x8c>
cmpq   $0x0,-0x18(%rbp)
je     11cf <wcstof+0x7f>
mov    -0x10(%rbp),%rcx
mov    -0x18(%rbp),%rax
mov    %rcx,(%rax)
xorps  %xmm0,%xmm0
movss  %xmm0,-0x4(%rbp)
jmp    1273 <wcstof+0x123>
mov    -0x40(%rbp),%rdi
add    $0x1,%rdi
call   1060 <malloc@plt>
mov    %rax,-0x28(%rbp)
cmp    $0x0,%rax
jne    1204 <wcstof+0xb4>
xorps  %xmm0,%xmm0
movss  %xmm0,-0x4(%rbp)
jmp    1273 <wcstof+0x123>
mov    0xdf6(%rip),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x28(%rbp),%rdi
mov    -0x40(%rbp),%rdx
add    $0x1,%rdx
lea    -0x38(%rbp),%rsi
lea    -0x1c(%rbp),%rcx
call   1040 <wcsrtombs@plt>
mov    -0x28(%rbp),%rdi
lea    -0x30(%rbp),%rsi
call   1050 <strtof@plt>
movss  %xmm0,-0x20(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     1260 <wcstof+0x110>
mov    -0x10(%rbp),%rcx
mov    -0x30(%rbp),%rax
mov    -0x28(%rbp),%rdx
sub    %rdx,%rax
shl    $0x2,%rax
add    %rax,%rcx
mov    -0x18(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
movss  -0x20(%rbp),%xmm0
movss  %xmm0,-0x4(%rbp)
movss  -0x4(%rbp),%xmm0
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<wcstof>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x18,%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 <wcstof+0x20>
mov    %rbx,0x8(%rsp)
movl   $0x0,(%rsp)
lea    0x8(%rsp),%rsi
mov    %rsp,%rcx
xor    %edi,%edi
xor    %edx,%edx
call   1040 <wcsrtombs@plt>
cmp    $0xffffffffffffffff,%rax
je     1216 <wcstof+0xc6>
mov    %rax,%r12
add    $0x1,%r12
mov    %r12,%rdi
call   1060 <malloc@plt>
test   %rax,%rax
je     1223 <wcstof+0xd3>
mov    %rax,%r15
movl   $0x0,(%rsp)
lea    0x8(%rsp),%rsi
mov    %rsp,%rcx
mov    %rax,%rdi
mov    %r12,%rdx
call   1040 <wcsrtombs@plt>
lea    0x10(%rsp),%rsi
mov    %r15,%rdi
call   1050 <strtof@plt>
movss  %xmm0,0x4(%rsp)
test   %r14,%r14
je     1206 <wcstof+0xb6>
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>
movss  0x4(%rsp),%xmm0
jmp    1226 <wcstof+0xd6>
xorps  %xmm0,%xmm0
test   %r14,%r14
je     1226 <wcstof+0xd6>
mov    %rbx,(%r14)
jmp    1226 <wcstof+0xd6>
xorps  %xmm0,%xmm0
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@wcstof.initial = internal constant i32 0
define float @wcstof(i32* noalias %0, i32** noalias %1) {
%3 = alloca float
%4 = alloca i32*
%5 = alloca i32**
%6 = alloca i32
%7 = alloca float
%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* @wcstof.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 float 0.000000e+00, float* %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 float 0.000000e+00, float* %3
br label %61
38: ; preds = %32
%39 = load i32, i32* @wcstof.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 float @strtof(i8* %44, i8** %9)
store float %45, float* %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 float, float* %7
store float %60, float* %3
br label %61
61: ; preds = %57, %37, %31
%62 = load float, float* %3
ret float %62
}

LLVM IR (-O2):
define float @wcstof(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 float @strtof(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 float [ %27, %35 ], [ 0.000000e+00, %20 ], [ 0.000000e+00, %18 ], [ 0.000000e+00, %21 ]
ret float %38
}