#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__ errno;
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *, ...);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ stderr;
float strtof(char *, char **);
float str_to_float(char *str, char *argname) {
  char *endptr;
  float val = 0.;
  errno = 0;
  val = strtof(str, &endptr);
  if (errno != 0) {
    fprintf(stderr, "Error when parsing option %s: ", argname);
    perror("strtof");
  }
  if (endptr == str) {
    fprintf(stderr, "No digits were found when parsing option %s\n", argname);
  }
  if (*endptr != '\0') {
    fprintf(stderr, "Excess characters after float argument of option %s: %s\n",
            argname, endptr);
  }
  return val;
}


x86 assembly (clang, -O0):
<str_to_float>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
xorps  %xmm0,%xmm0
movss  %xmm0,-0x1c(%rbp)
mov    0x2e89(%rip),%rax
movq   $0x0,(%rax)
mov    -0x8(%rbp),%rdi
lea    -0x18(%rbp),%rsi
call   1030 <strtof@plt>
movss  %xmm0,-0x1c(%rbp)
mov    0x2e69(%rip),%rax
cmpq   $0x0,(%rax)
je     11a0 <str_to_float+0x70>
mov    0x2e60(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rdx
lea    0xe73(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
lea    0xe84(%rip),%rdi
call   1050 <perror@plt>
mov    -0x18(%rbp),%rax
cmp    -0x8(%rbp),%rax
jne    11c9 <str_to_float+0x99>
mov    0x2e2b(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rdx
lea    0xe64(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
mov    -0x18(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     11f8 <str_to_float+0xc8>
mov    0x2e00(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rdx
mov    -0x18(%rbp),%rcx
lea    0xe62(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
movss  -0x1c(%rbp),%xmm0
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<str_to_float>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rsi,%r14
mov    %rdi,%r15
mov    0x2e92(%rip),%rbx
movq   $0x0,(%rbx)
lea    0x8(%rsp),%rsi
call   1030 <strtof@plt>
movss  %xmm0,0x4(%rsp)
cmpq   $0x0,(%rbx)
jne    11c0 <str_to_float+0x90>
mov    0x8(%rsp),%rbx
cmp    %r15,%rbx
je     119f <str_to_float+0x6f>
cmpb   $0x0,(%rbx)
je     118f <str_to_float+0x5f>
mov    0x2e67(%rip),%rax
mov    (%rax),%edi
lea    0xed1(%rip),%rsi
mov    %r14,%rdx
mov    %rbx,%rcx
xor    %eax,%eax
call   1040 <fprintf@plt>
movss  0x4(%rsp),%xmm0
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret
mov    0x2e3a(%rip),%rax
mov    (%rax),%edi
lea    0xe77(%rip),%rsi
mov    %r14,%rdx
xor    %eax,%eax
call   1040 <fprintf@plt>
cmpb   $0x0,(%rbx)
jne    1172 <str_to_float+0x42>
jmp    118f <str_to_float+0x5f>
mov    0x2e19(%rip),%rax
mov    (%rax),%edi
lea    0xe30(%rip),%rsi
mov    %r14,%rdx
xor    %eax,%eax
call   1040 <fprintf@plt>
lea    0xe3e(%rip),%rdi
call   1050 <perror@plt>
jmp    1163 <str_to_float+0x33>

LLVM IR (-O0):
@errno = global i64 0
@stderr = global i32 0
@.str = [31 x i8] c"Error when parsing option %s: \00"
@.str.1 = [7 x i8] c"strtof\00"
@.str.2 = [45 x i8] c"No digits were found when parsing option %s\0A\00"
@.str.3 = [57 x i8] c"Excess characters after float argument of option %s: %s\0A\00"
define float @str_to_float(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca float
store i8* %0, i8** %3
store i8* %1, i8** %4
store float 0.000000e+00, float* %6
store i64 0, i64* @errno
%7 = load i8*, i8** %3
%8 = call float @strtof(i8* %7, i8** %5)
store float %8, float* %6
%9 = load i64, i64* @errno
%10 = icmp ne i64 %9, 0
br i1 %10, label %11, label %16
11: ; preds = %2
%12 = load i32, i32* @stderr
%13 = load i8*, i8** %4
%14 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %12, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str, i64 0, i64 0), i8* %13)
%15 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
br label %16
16: ; preds = %11, %2
%17 = load i8*, i8** %5
%18 = load i8*, i8** %3
%19 = icmp eq i8* %17, %18
br i1 %19, label %20, label %24
20: ; preds = %16
%21 = load i32, i32* @stderr
%22 = load i8*, i8** %4
%23 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %21, i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str.2, i64 0, i64 0), i8* %22)
br label %24
24: ; preds = %20, %16
%25 = load i8*, i8** %5
%26 = load i8, i8* %25
%27 = sext i8 %26 to i32
%28 = icmp ne i32 %27, 0
br i1 %28, label %29, label %34
29: ; preds = %24
%30 = load i32, i32* @stderr
%31 = load i8*, i8** %4
%32 = load i8*, i8** %5
%33 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %30, i8* getelementptr inbounds ([57 x i8], [57 x i8]* @.str.3, i64 0, i64 0), i8* %31, i8* %32)
br label %34
34: ; preds = %29, %24
%35 = load float, float* %6
ret float %35
}

LLVM IR (-O2):
@errno = global i64 0
@stderr = global i32 0
@.str = [31 x i8] c"Error when parsing option %s: \00"
@.str.1 = [7 x i8] c"strtof\00"
@.str.2 = [45 x i8] c"No digits were found when parsing option %s\0A\00"
@.str.3 = [57 x i8] c"Excess characters after float argument of option %s: %s\0A\00"
define float @str_to_float(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = bitcast i8** %3 to i8*
store i64 0, i64* @errno
%5 = call float @strtof(i8* %0, i8** %3)
%6 = load i64, i64* @errno
%7 = icmp eq i64 %6, 0
br i1 %7, label %12, label %8
8: ; preds = %2
%9 = load i32, i32* @stderr
%10 = tail call i32 (i32, i8*, i8*, ...) @fprintf(i32 %9, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str, i64 0, i64 0), i8* %1)
%11 = tail call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
br label %12
12: ; preds = %8, %2
%13 = load i8*, i8** %3
%14 = icmp eq i8* %13, %0
br i1 %14, label %15, label %18
15: ; preds = %12
%16 = load i32, i32* @stderr
%17 = tail call i32 (i32, i8*, i8*, ...) @fprintf(i32 %16, i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str.2, i64 0, i64 0), i8* %1)
br label %18
18: ; preds = %15, %12
%19 = load i8, i8* %13
%20 = icmp eq i8 %19, 0
br i1 %20, label %24, label %21
21: ; preds = %18
%22 = load i32, i32* @stderr
%23 = tail call i32 (i32, i8*, i8*, ...) @fprintf(i32 %22, i8* getelementptr inbounds ([57 x i8], [57 x i8]* @.str.3, i64 0, i64 0), i8* %1, i8* %13)
br label %24
24: ; preds = %21, %18
ret float %5
}