#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 */
float HUGE_VAL;
float HUGE_VALF;
float HUGE_VALL;
scalar_t__ errno;
int muggle_str_lstrip_idx(char *);
float strtof(char const *, char **);
int muggle_str_tof(const char *str, float *pval) {
  char *endptr;
  if (str == NULL || pval == NULL) {
    return 0;
  }
  errno = 0;
  *pval = strtof(str, &endptr);
  if (endptr == str) {
    return 0;
  } else if (*endptr != '\0') {
    if (muggle_str_lstrip_idx(endptr) != -1) {
      return 0;
    }
  }
  if (*pval == HUGE_VAL || *pval == HUGE_VALF || *pval == HUGE_VALL) {
    return 0;
  }
  return 1;
}


x86 assembly (clang, -O0):
<muggle_str_tof>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     1146 <muggle_str_tof+0x26>
cmpq   $0x0,-0x18(%rbp)
jne    1152 <muggle_str_tof+0x32>
movl   $0x0,-0x4(%rbp)
jmp    123e <muggle_str_tof+0x11e>
mov    0x2e6f(%rip),%rax
movq   $0x0,(%rax)
mov    -0x10(%rbp),%rdi
lea    -0x20(%rbp),%rsi
call   1040 <strtof@plt>
mov    -0x18(%rbp),%rax
movss  %xmm0,(%rax)
mov    -0x20(%rbp),%rax
cmp    -0x10(%rbp),%rax
jne    118f <muggle_str_tof+0x6f>
movl   $0x0,-0x4(%rbp)
jmp    123e <muggle_str_tof+0x11e>
mov    -0x20(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     11c2 <muggle_str_tof+0xa2>
mov    -0x20(%rbp),%rdi
call   1030 <muggle_str_lstrip_idx@plt>
cmp    $0xffffffff,%eax
je     11bd <muggle_str_tof+0x9d>
movl   $0x0,-0x4(%rbp)
jmp    123e <muggle_str_tof+0x11e>
jmp    11c2 <muggle_str_tof+0xa2>
jmp    11c7 <muggle_str_tof+0xa7>
mov    -0x18(%rbp),%rax
movss  (%rax),%xmm0
mov    0x2e02(%rip),%rax
ucomiss (%rax),%xmm0
jne    11ea <muggle_str_tof+0xca>
jp     11ea <muggle_str_tof+0xca>
jmp    122b <muggle_str_tof+0x10b>
mov    -0x18(%rbp),%rax
movss  (%rax),%xmm0
mov    0x2def(%rip),%rax
ucomiss (%rax),%xmm0
jne    120d <muggle_str_tof+0xed>
jp     120d <muggle_str_tof+0xed>
jmp    122b <muggle_str_tof+0x10b>
mov    -0x18(%rbp),%rax
movss  (%rax),%xmm0
mov    0x2dd4(%rip),%rax
ucomiss (%rax),%xmm0
jne    1237 <muggle_str_tof+0x117>
jp     1237 <muggle_str_tof+0x117>
movl   $0x0,-0x4(%rbp)
jmp    123e <muggle_str_tof+0x11e>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<muggle_str_tof>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
xor    %r14d,%r14d
test   %rdi,%rdi
je     11b6 <muggle_str_tof+0x96>
mov    %rsi,%rbx
test   %rsi,%rsi
je     11b6 <muggle_str_tof+0x96>
mov    %rdi,%rbp
mov    0x2e82(%rip),%rax
movq   $0x0,(%rax)
lea    0x8(%rsp),%rsi
call   1040 <strtof@plt>
movss  %xmm0,(%rbx)
mov    0x8(%rsp),%rdi
cmp    %rbp,%rdi
je     11b6 <muggle_str_tof+0x96>
cmpb   $0x0,(%rdi)
je     1178 <muggle_str_tof+0x58>
call   1030 <muggle_str_lstrip_idx@plt>
cmp    $0xffffffff,%eax
jne    11b6 <muggle_str_tof+0x96>
movss  (%rbx),%xmm0
mov    0x2e59(%rip),%rax
ucomiss (%rax),%xmm0
setp   %al
setne  %cl
or     %al,%cl
mov    0x2e57(%rip),%rax
ucomiss (%rax),%xmm0
setp   %al
setne  %dl
or     %al,%dl
and    %cl,%dl
mov    0x2e4b(%rip),%rax
ucomiss (%rax),%xmm0
setp   %al
setne  %cl
or     %al,%cl
and    %dl,%cl
movzbl %cl,%r14d
mov    %r14d,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@errno = global i64 0
@HUGE_VAL = global float 0.000000e+00
@HUGE_VALF = global float 0.000000e+00
@HUGE_VALL = global float 0.000000e+00
define i32 @muggle_str_tof(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
%7 = load i8*, i8** %4
%8 = icmp eq i8* %7, null
br i1 %8, label %12, label %9
9: ; preds = %2
%10 = load float*, float** %5
%11 = icmp eq float* %10, null
br i1 %11, label %12, label %13
12: ; preds = %9, %2
store i32 0, i32* %3
br label %50
13: ; preds = %9
store i64 0, i64* @errno
%14 = load i8*, i8** %4
%15 = call float @strtof(i8* %14, i8** %6)
%16 = load float*, float** %5
store float %15, float* %16
%17 = load i8*, i8** %6
%18 = load i8*, i8** %4
%19 = icmp eq i8* %17, %18
br i1 %19, label %20, label %21
20: ; preds = %13
store i32 0, i32* %3
br label %50
21: ; preds = %13
%22 = load i8*, i8** %6
%23 = load i8, i8* %22
%24 = sext i8 %23 to i32
%25 = icmp ne i32 %24, 0
br i1 %25, label %26, label %32
26: ; preds = %21
%27 = load i8*, i8** %6
%28 = call i32 @muggle_str_lstrip_idx(i8* %27)
%29 = icmp ne i32 %28, -1
br i1 %29, label %30, label %31
30: ; preds = %26
store i32 0, i32* %3
br label %50
31: ; preds = %26
br label %32
32: ; preds = %31, %21
br label %33
33: ; preds = %32
%34 = load float*, float** %5
%35 = load float, float* %34
%36 = load float, float* @HUGE_VAL
%37 = fcmp oeq float %35, %36
br i1 %37, label %48, label %38
38: ; preds = %33
%39 = load float*, float** %5
%40 = load float, float* %39
%41 = load float, float* @HUGE_VALF
%42 = fcmp oeq float %40, %41
br i1 %42, label %48, label %43
43: ; preds = %38
%44 = load float*, float** %5
%45 = load float, float* %44
%46 = load float, float* @HUGE_VALL
%47 = fcmp oeq float %45, %46
br i1 %47, label %48, label %49
48: ; preds = %43, %38, %33
store i32 0, i32* %3
br label %50
49: ; preds = %43
store i32 1, i32* %3
br label %50
50: ; preds = %49, %48, %30, %20, %12
%51 = load i32, i32* %3
ret i32 %51
}

LLVM IR (-O2):
@errno = global i64 0
@HUGE_VAL = global float 0.000000e+00
@HUGE_VALF = global float 0.000000e+00
@HUGE_VALL = global float 0.000000e+00
define i32 @muggle_str_tof(i8* %0, float* %1) {
%3 = alloca i8*
%4 = bitcast i8** %3 to i8*
%5 = icmp eq i8* %0, null
%6 = icmp eq float* %1, null
%7 = or i1 %5, %6
br i1 %7, label %31, label %8
8: ; preds = %2
store i64 0, i64* @errno
%9 = call float @strtof(i8* %0, i8** %3)
store float %9, float* %1
%10 = load i8*, i8** %3
%11 = icmp eq i8* %10, %0
br i1 %11, label %31, label %12
12: ; preds = %8
%13 = load i8, i8* %10
%14 = icmp eq i8 %13, 0
br i1 %14, label %20, label %15
15: ; preds = %12
%16 = tail call i32 @muggle_str_lstrip_idx(i8* %10)
%17 = icmp eq i32 %16, -1
br i1 %17, label %18, label %31
18: ; preds = %15
%19 = load float, float* %1
br label %20
20: ; preds = %18, %12
%21 = phi float [ %19, %18 ], [ %9, %12 ]
%22 = load float, float* @HUGE_VAL
%23 = fcmp une float %21, %22
%24 = load float, float* @HUGE_VALF
%25 = fcmp une float %21, %24
%26 = select i1 %23, i1 %25, i1 false
%27 = load float, float* @HUGE_VALL
%28 = fcmp une float %21, %27
%29 = select i1 %26, i1 %28, i1 false
%30 = zext i1 %29 to i32
br label %31
31: ; preds = %20, %15, %8, %2
%32 = phi i32 [ 0, %2 ], [ 0, %8 ], [ 0, %15 ], [ %30, %20 ]
ret i32 %32
}