#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 errno;
float strtof(char *, char **);
float str2float(char *num) {
  float rfloat;
  int p_errno;
  if (num != (char *)NULL) {
    p_errno = errno;
    errno = 0;
    rfloat = strtof(num, (char **)NULL);
    if (errno == 0) {
      errno = p_errno;
      return rfloat;
    }
    return 0.0;
  }
  return 0.0;
}


x86 assembly (clang, -O0):
<str2float>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     118a <str2float+0x7a>
mov    0x2eb2(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x18(%rbp)
mov    0x2ea6(%rip),%rax
movl   $0x0,(%rax)
mov    -0x10(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1030 <strtof@plt>
movss  %xmm0,-0x14(%rbp)
mov    0x2e87(%rip),%rax
cmpl   $0x0,(%rax)
jne    117d <str2float+0x6d>
mov    -0x18(%rbp),%ecx
mov    0x2e74(%rip),%rax
mov    %ecx,(%rax)
movss  -0x14(%rbp),%xmm0
movss  %xmm0,-0x4(%rbp)
jmp    1192 <str2float+0x82>
xorps  %xmm0,%xmm0
movss  %xmm0,-0x4(%rbp)
jmp    1192 <str2float+0x82>
xorps  %xmm0,%xmm0
movss  %xmm0,-0x4(%rbp)
movss  -0x4(%rbp),%xmm0
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<str2float>:
push   %rbp
push   %rbx
push   %rax
xorps  %xmm1,%xmm1
test   %rdi,%rdi
je     113e <str2float+0x2e>
mov    0x2ebe(%rip),%rbx
mov    (%rbx),%ebp
movl   $0x0,(%rbx)
xor    %esi,%esi
call   1030 <strtof@plt>
xorps  %xmm1,%xmm1
cmpl   $0x0,(%rbx)
jne    113e <str2float+0x2e>
mov    %ebp,(%rbx)
movaps %xmm0,%xmm1
movaps %xmm1,%xmm0
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@errno = global i32 0
define float @str2float(i8* %0) {
%2 = alloca float
%3 = alloca i8*
%4 = alloca float
%5 = alloca i32
store i8* %0, i8** %3
%6 = load i8*, i8** %3
%7 = icmp ne i8* %6, null
br i1 %7, label %8, label %18
8: ; preds = %1
%9 = load i32, i32* @errno
store i32 %9, i32* %5
store i32 0, i32* @errno
%10 = load i8*, i8** %3
%11 = call float @strtof(i8* %10, i8** null)
store float %11, float* %4
%12 = load i32, i32* @errno
%13 = icmp eq i32 %12, 0
br i1 %13, label %14, label %17
14: ; preds = %8
%15 = load i32, i32* %5
store i32 %15, i32* @errno
%16 = load float, float* %4
store float %16, float* %2
br label %19
17: ; preds = %8
store float 0.000000e+00, float* %2
br label %19
18: ; preds = %1
store float 0.000000e+00, float* %2
br label %19
19: ; preds = %18, %17, %14
%20 = load float, float* %2
ret float %20
}

LLVM IR (-O2):
@errno = global i32 0
define float @str2float(i8* %0) {
%2 = icmp eq i8* %0, null
br i1 %2, label %9, label %3
3: ; preds = %1
%4 = load i32, i32* @errno
store i32 0, i32* @errno
%5 = tail call float @strtof(i8* nocapture %0, i8** null)
%6 = load i32, i32* @errno
%7 = icmp eq i32 %6, 0
br i1 %7, label %8, label %9
8: ; preds = %3
store i32 %4, i32* @errno
br label %9
9: ; preds = %1, %3, %8
%10 = phi float [ %5, %8 ], [ 0.000000e+00, %3 ], [ 0.000000e+00, %1 ]
ret float %10
}