#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 */
scalar_t__ ERANGE;
scalar_t__ FLT_EPSILON;
float HUGE_VALF;
float HUGE_VALL;
int errno;
scalar_t__ fabs(float);
float strtof(char const *, char **);
int str_to_float(const char *str, float *val) {
  char *endptr;
  errno = 0;
  *val = strtof(str, &endptr);
  if ((errno = ERANGE && (*val == HUGE_VALF || *val == HUGE_VALL)) ||
      (errno != 0 && fabs(*val) < FLT_EPSILON)) {
    return -1;
  }
  if (endptr == str) {
    return -2;
  }
  return 0;
}


x86 assembly (clang, -O0):
<str_to_float>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    0x2e89(%rip),%rax
movl   $0x0,(%rax)
mov    -0x10(%rbp),%rdi
lea    -0x20(%rbp),%rsi
call   1030 <strtof@plt>
mov    -0x18(%rbp),%rax
movss  %xmm0,(%rax)
xor    %eax,%eax
mov    0x2e7d(%rip),%rcx
cmpq   $0x0,(%rcx)
mov    %al,-0x21(%rbp)
je     11b3 <str_to_float+0x93>
mov    -0x18(%rbp),%rax
movss  (%rax),%xmm0
mov    $0x1,%al
mov    0x2e6f(%rip),%rcx
ucomiss (%rcx),%xmm0
mov    %al,-0x22(%rbp)
jne    1190 <str_to_float+0x70>
jp     1190 <str_to_float+0x70>
jmp    11ad <str_to_float+0x8d>
mov    -0x18(%rbp),%rax
movss  (%rax),%xmm0
mov    0x2e51(%rip),%rax
ucomiss (%rax),%xmm0
sete   %al
setnp  %cl
and    %cl,%al
mov    %al,-0x22(%rbp)
mov    -0x22(%rbp),%al
mov    %al,-0x21(%rbp)
mov    -0x21(%rbp),%al
mov    %al,%cl
and    $0x1,%cl
movzbl %cl,%edx
mov    0x2dfb(%rip),%rcx
mov    %edx,(%rcx)
test   $0x1,%al
jne    11fc <str_to_float+0xdc>
mov    0x2dea(%rip),%rax
cmpl   $0x0,(%rax)
je     1208 <str_to_float+0xe8>
mov    -0x18(%rbp),%rax
movss  (%rax),%xmm0
call   1040 <fabs@plt>
mov    0x2dd5(%rip),%rcx
cmp    (%rcx),%rax
jge    1208 <str_to_float+0xe8>
movl   $0xffffffff,-0x4(%rbp)
jmp    1229 <str_to_float+0x109>
mov    -0x20(%rbp),%rax
cmp    -0x10(%rbp),%rax
jne    1222 <str_to_float+0x102>
movl   $0xfffffffe,-0x4(%rbp)
jmp    1229 <str_to_float+0x109>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<str_to_float>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rsi,%rbx
mov    %rdi,%r14
mov    0x2ea2(%rip),%r15
movl   $0x0,(%r15)
lea    0x8(%rsp),%rsi
call   1030 <strtof@plt>
movss  %xmm0,(%rbx)
mov    0x2e96(%rip),%rax
cmpq   $0x0,(%rax)
je     115f <str_to_float+0x4f>
mov    0x2e99(%rip),%rax
ucomiss (%rax),%xmm0
jne    1177 <str_to_float+0x67>
jp     1177 <str_to_float+0x67>
movl   $0x1,(%r15)
jmp    11a5 <str_to_float+0x95>
movl   $0x0,(%r15)
xor    %eax,%eax
cmp    %r14,0x8(%rsp)
setne  %al
add    %eax,%eax
add    $0xfffffffe,%eax
jmp    11aa <str_to_float+0x9a>
mov    0x2e72(%rip),%rax
movss  (%rax),%xmm1
movaps %xmm0,%xmm2
cmpeqss %xmm1,%xmm2
movd   %xmm2,%edx
and    $0x1,%edx
xor    %eax,%eax
cmp    %r14,0x8(%rsp)
setne  %cl
ucomiss %xmm1,%xmm0
mov    %edx,(%r15)
jne    11b4 <str_to_float+0xa4>
jp     11b4 <str_to_float+0xa4>
mov    $0xffffffff,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret
mov    %cl,%al
jmp    1170 <str_to_float+0x60>

LLVM IR (-O0):
@errno = global i32 0
@ERANGE = global i64 0
@HUGE_VALF = global float 0.000000e+00
@HUGE_VALL = global float 0.000000e+00
@FLT_EPSILON = global i64 0
define i32 @str_to_float(i8* %0, float* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca float*
%6 = alloca i8*
store i8* %0, i8** %4
store float* %1, float** %5
store i32 0, i32* @errno
%7 = load i8*, i8** %4
%8 = call float @strtof(i8* %7, i8** %6)
%9 = load float*, float** %5
store float %8, float* %9
%10 = load i64, i64* @ERANGE
%11 = icmp ne i64 %10, 0
br i1 %11, label %12, label %24
12: ; preds = %2
%13 = load float*, float** %5
%14 = load float, float* %13
%15 = load float, float* @HUGE_VALF
%16 = fcmp oeq float %14, %15
br i1 %16, label %22, label %17
17: ; preds = %12
%18 = load float*, float** %5
%19 = load float, float* %18
%20 = load float, float* @HUGE_VALL
%21 = fcmp oeq float %19, %20
br label %22
22: ; preds = %17, %12
%23 = phi i1 [ true, %12 ], [ %21, %17 ]
br label %24
24: ; preds = %22, %2
%25 = phi i1 [ false, %2 ], [ %23, %22 ]
%26 = zext i1 %25 to i32
store i32 %26, i32* @errno
br i1 %25, label %36, label %27
27: ; preds = %24
%28 = load i32, i32* @errno
%29 = icmp ne i32 %28, 0
br i1 %29, label %30, label %37
30: ; preds = %27
%31 = load float*, float** %5
%32 = load float, float* %31
%33 = call i64 @fabs(float %32)
%34 = load i64, i64* @FLT_EPSILON
%35 = icmp slt i64 %33, %34
br i1 %35, label %36, label %37
36: ; preds = %30, %24
store i32 -1, i32* %3
br label %43
37: ; preds = %30, %27
%38 = load i8*, i8** %6
%39 = load i8*, i8** %4
%40 = icmp eq i8* %38, %39
br i1 %40, label %41, label %42
41: ; preds = %37
store i32 -2, i32* %3
br label %43
42: ; preds = %37
store i32 0, i32* %3
br label %43
43: ; preds = %42, %41, %36
%44 = load i32, i32* %3
ret i32 %44
}

LLVM IR (-O2):
@errno = global i32 0
@ERANGE = global i64 0
@HUGE_VALF = global float 0.000000e+00
@HUGE_VALL = global float 0.000000e+00
@FLT_EPSILON = global i64 0
define i32 @str_to_float(i8* %0, float* nocapture writeonly %1) {
%3 = alloca i8*
%4 = bitcast i8** %3 to i8*
store i32 0, i32* @errno
%5 = call float @strtof(i8* %0, i8** %3)
store float %5, float* %1
%6 = load i64, i64* @ERANGE
%7 = icmp eq i64 %6, 0
br i1 %7, label %8, label %12
8: ; preds = %2
store i32 0, i32* @errno
%9 = load i8*, i8** %3
%10 = icmp eq i8* %9, %0
%11 = select i1 %10, i32 -2, i32 0
br label %24
12: ; preds = %2
%13 = load float, float* @HUGE_VALF
%14 = fcmp oeq float %5, %13
br i1 %14, label %15, label %16
15: ; preds = %12
store i32 1, i32* @errno
br label %23
16: ; preds = %12
%17 = load float, float* @HUGE_VALL
%18 = fcmp oeq float %5, %17
%19 = zext i1 %18 to i32
store i32 %19, i32* @errno
%20 = load i8*, i8** %3
%21 = icmp eq i8* %20, %0
%22 = select i1 %21, i32 -2, i32 0
br i1 %18, label %23, label %24
23: ; preds = %15, %16
br label %24
24: ; preds = %8, %16, %23
%25 = phi i32 [ -1, %23 ], [ %22, %16 ], [ %11, %8 ]
ret i32 %25
}