#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 /*<<< orphan*/ ERANGE;
long double FLT_MAX;
long double FLT_MIN;
float HUGE_VALF;
int /*<<< orphan*/ errno;
long double strtold(char const *, char **);
float strtof(const char *restrict nptr, char **restrict endptr) {
  long double ld = strtold(nptr, endptr);
  if (ld > FLT_MAX) {
    errno = ERANGE;
    return HUGE_VALF;
  } else if (ld < -FLT_MAX) {
    errno = ERANGE;
    return -HUGE_VALF;
  } else if (ld > -FLT_MIN && ld < FLT_MIN) {
    errno = ERANGE;
    return ld < 0 ? -0. : +0.;
  }
  return (float)ld;
}


x86 assembly (clang, -O0):
<strtof>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1030 <strtold@plt>
fstpt  -0x30(%rbp)
fldt   -0x30(%rbp)
mov    0x2e96(%rip),%rax
fldt   (%rax)
fxch   %st(1)
fucomip %st(1),%st
fstp   %st(0)
jbe    1174 <strtof+0x64>
jmp    114d <strtof+0x3d>
mov    0x2e84(%rip),%rax
mov    (%rax),%ecx
mov    0x2e63(%rip),%rax
mov    %ecx,(%rax)
mov    0x2e8a(%rip),%rax
movss  (%rax),%xmm0
movss  %xmm0,-0x4(%rbp)
jmp    126e <strtof+0x15e>
fldt   -0x30(%rbp)
mov    0x2e52(%rip),%rax
fldt   (%rax)
fchs
fucomip %st(1),%st
fstp   %st(0)
jbe    11c5 <strtof+0xb5>
jmp    1191 <strtof+0x81>
mov    0x2e40(%rip),%rax
mov    (%rax),%ecx
mov    0x2e1f(%rip),%rax
mov    %ecx,(%rax)
mov    0x2e46(%rip),%rax
movss  (%rax),%xmm0
movd   %xmm0,%eax
xor    $0x80000000,%eax
movd   %eax,%xmm0
movss  %xmm0,-0x4(%rbp)
jmp    126e <strtof+0x15e>
fldt   -0x30(%rbp)
mov    0x2e11(%rip),%rax
fldt   (%rax)
fchs
fxch   %st(1)
fucomip %st(1),%st
fstp   %st(0)
jbe    1254 <strtof+0x144>
jmp    11e4 <strtof+0xd4>
fldt   -0x30(%rbp)
mov    0x2df2(%rip),%rax
fldt   (%rax)
fucomip %st(1),%st
fstp   %st(0)
jbe    1254 <strtof+0x144>
jmp    11ff <strtof+0xef>
xor    %eax,%eax
mov    0x2dd0(%rip),%rax
mov    (%rax),%ecx
mov    0x2daf(%rip),%rax
mov    %ecx,(%rax)
fldt   -0x30(%rbp)
fldz
fucomip %st(1),%st
fstp   %st(0)
movsd  0xddc(%rip),%xmm0
xorps  %xmm1,%xmm1
movsd  %xmm1,-0x48(%rbp)
movsd  %xmm0,-0x40(%rbp)
ja     1241 <strtof+0x131>
movsd  -0x48(%rbp),%xmm0
movsd  %xmm0,-0x40(%rbp)
movsd  -0x40(%rbp),%xmm0
cvtsd2ss %xmm0,%xmm0
movss  %xmm0,-0x4(%rbp)
jmp    126e <strtof+0x15e>
jmp    1259 <strtof+0x149>
jmp    125e <strtof+0x14e>
fldt   -0x30(%rbp)
fstps  -0x34(%rbp)
movss  -0x34(%rbp),%xmm0
movss  %xmm0,-0x4(%rbp)
movss  -0x4(%rbp),%xmm0
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<strtof>:
push   %rax
call   1030 <strtold@plt>
mov    0x2eb3(%rip),%rax
fldt   (%rax)
fxch   %st(1)
fucomi %st(1),%st
jbe    1148 <strtof+0x38>
fstp   %st(0)
fstp   %st(0)
mov    0x2ea8(%rip),%rax
mov    (%rax),%eax
mov    0x2e87(%rip),%rcx
mov    %eax,(%rcx)
mov    0x2eae(%rip),%rax
movss  (%rax),%xmm0
pop    %rax
ret
fxch   %st(1)
fchs
fucomip %st(1),%st
jbe    1178 <strtof+0x68>
fstp   %st(0)
mov    0x2e7f(%rip),%rax
mov    (%rax),%eax
mov    0x2e5e(%rip),%rcx
mov    %eax,(%rcx)
mov    0x2e85(%rip),%rax
movss  (%rax),%xmm0
xorps  0xe9a(%rip),%xmm0
pop    %rax
ret
mov    0x2e61(%rip),%rax
fldt   (%rax)
fld    %st(0)
fchs
fxch   %st(2)
fucomi %st(2),%st
fstp   %st(2)
jbe    11b4 <strtof+0xa4>
fucomip %st(1),%st
fldz
jbe    11b4 <strtof+0xa4>
fstp   %st(0)
mov    0x2e3c(%rip),%rax
mov    (%rax),%eax
mov    0x2e1b(%rip),%rcx
mov    %eax,(%rcx)
fldz
fucomip %st(1),%st
fstp   %st(0)
ja     11c2 <strtof+0xb2>
xorps  %xmm0,%xmm0
pop    %rax
ret
fstp   %st(0)
fstps  0x4(%rsp)
movss  0x4(%rsp),%xmm0
pop    %rax
ret
movss  0xe36(%rip),%xmm0
pop    %rax
ret

LLVM IR (-O0):
@FLT_MAX = global x86_fp80 0xK00000000000000000000
@ERANGE = global i32 0
@errno = global i32 0
@HUGE_VALF = global float 0.000000e+00
@FLT_MIN = global x86_fp80 0xK00000000000000000000
define float @strtof(i8* noalias %0, i8** noalias %1) {
%3 = alloca float
%4 = alloca i8*
%5 = alloca i8**
%6 = alloca x86_fp80
store i8* %0, i8** %4
store i8** %1, i8*** %5
%7 = load i8*, i8** %4
%8 = load i8**, i8*** %5
%9 = call x86_fp80 @strtold(i8* %7, i8** %8)
store x86_fp80 %9, x86_fp80* %6
%10 = load x86_fp80, x86_fp80* %6
%11 = load x86_fp80, x86_fp80* @FLT_MAX
%12 = fcmp ogt x86_fp80 %10, %11
br i1 %12, label %13, label %16
13: ; preds = %2
%14 = load i32, i32* @ERANGE
store i32 %14, i32* @errno
%15 = load float, float* @HUGE_VALF
store float %15, float* %3
br label %46
16: ; preds = %2
%17 = load x86_fp80, x86_fp80* %6
%18 = load x86_fp80, x86_fp80* @FLT_MAX
%19 = fneg x86_fp80 %18
%20 = fcmp olt x86_fp80 %17, %19
br i1 %20, label %21, label %25
21: ; preds = %16
%22 = load i32, i32* @ERANGE
store i32 %22, i32* @errno
%23 = load float, float* @HUGE_VALF
%24 = fneg float %23
store float %24, float* %3
br label %46
25: ; preds = %16
%26 = load x86_fp80, x86_fp80* %6
%27 = load x86_fp80, x86_fp80* @FLT_MIN
%28 = fneg x86_fp80 %27
%29 = fcmp ogt x86_fp80 %26, %28
br i1 %29, label %30, label %41
30: ; preds = %25
%31 = load x86_fp80, x86_fp80* %6
%32 = load x86_fp80, x86_fp80* @FLT_MIN
%33 = fcmp olt x86_fp80 %31, %32
br i1 %33, label %34, label %41
34: ; preds = %30
%35 = load i32, i32* @ERANGE
store i32 %35, i32* @errno
%36 = load x86_fp80, x86_fp80* %6
%37 = fcmp olt x86_fp80 %36, 0xK00000000000000000000
%38 = zext i1 %37 to i64
%39 = select i1 %37, double -0.000000e+00, double 0.000000e+00
%40 = fptrunc double %39 to float
store float %40, float* %3
br label %46
41: ; preds = %30, %25
br label %42
42: ; preds = %41
br label %43
43: ; preds = %42
%44 = load x86_fp80, x86_fp80* %6
%45 = fptrunc x86_fp80 %44 to float
store float %45, float* %3
br label %46
46: ; preds = %43, %34, %21, %13
%47 = load float, float* %3
ret float %47
}

LLVM IR (-O2):
@FLT_MAX = global x86_fp80 0xK00000000000000000000
@ERANGE = global i32 0
@errno = global i32 0
@HUGE_VALF = global float 0.000000e+00
@FLT_MIN = global x86_fp80 0xK00000000000000000000
define float @strtof(i8* noalias %0, i8** noalias nocapture %1) {
%3 = tail call x86_fp80 @strtold(i8* %0, i8** %1)
%4 = load x86_fp80, x86_fp80* @FLT_MAX
%5 = fcmp ogt x86_fp80 %3, %4
br i1 %5, label %6, label %9
6: ; preds = %2
%7 = load i32, i32* @ERANGE
store i32 %7, i32* @errno
%8 = load float, float* @HUGE_VALF
br label %28
9: ; preds = %2
%10 = fneg x86_fp80 %4
%11 = fcmp olt x86_fp80 %3, %10
br i1 %11, label %12, label %16
12: ; preds = %9
%13 = load i32, i32* @ERANGE
store i32 %13, i32* @errno
%14 = load float, float* @HUGE_VALF
%15 = fneg float %14
br label %28
16: ; preds = %9
%17 = load x86_fp80, x86_fp80* @FLT_MIN
%18 = fneg x86_fp80 %17
%19 = fcmp ogt x86_fp80 %3, %18
%20 = fcmp olt x86_fp80 %3, %17
%21 = and i1 %19, %20
br i1 %21, label %22, label %26
22: ; preds = %16
%23 = load i32, i32* @ERANGE
store i32 %23, i32* @errno
%24 = fcmp olt x86_fp80 %3, 0xK00000000000000000000
%25 = select i1 %24, float -0.000000e+00, float 0.000000e+00
br label %28
26: ; preds = %16
%27 = fptrunc x86_fp80 %3 to float
br label %28
28: ; preds = %26, %22, %12, %6
%29 = phi float [ %8, %6 ], [ %15, %12 ], [ %25, %22 ], [ %27, %26 ]
ret float %29
}