#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 */
typedef int ssize_t;
typedef int /*<<< orphan*/ fstr;

/* Variables and functions */
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, int);
int /*<<< orphan*/ printf(char *, ...);
int sprintf(char *, char *, int);
int /*<<< orphan*/ strfromf(char *, int, char *, float);
float strtof(char *, int /*<<< orphan*/ *);
int test_strtof(void) {
  char buf[300];
  int cnt;
  int result = 0;
  for (cnt = 0; cnt < 200; ++cnt) {
    ssize_t n;
    float f;
    n = sprintf(buf, "%d", cnt);
    memset(buf + n, '0', cnt);
    sprintf(buf + n + cnt, ".000e-%d", cnt);
    f = strtof(buf, NULL);
    if (f != (float)cnt) {
      char fstr[128];
      char fcntstr[128];
      strfromf(fstr, sizeof(fstr), "%g", f);
      strfromf(fcntstr, sizeof(fstr), "%g", (float)cnt);
      printf("strto"
             "f"
             "(\"%s\") "
             "failed for cnt == %d (%s instead of %s)\n",
             buf, cnt, fstr, fcntstr);
      result = 1;
    } else
      printf("strto"
             "f"
             "() fine for cnt == %d\n",
             cnt);
  }
  return result;
}


x86 assembly (clang, -O0):
<test_strtof>:
push   %rbp
mov    %rsp,%rbp
sub    $0x240,%rsp
movl   $0x0,-0x138(%rbp)
movl   $0x0,-0x134(%rbp)
cmpl   $0xc8,-0x134(%rbp)
jge    12cd <test_strtof+0x17d>
lea    -0x130(%rbp),%rdi
mov    -0x134(%rbp),%edx
lea    0xe73(%rip),%rsi
call   1060 <sprintf@plt>
mov    %eax,-0x13c(%rbp)
lea    -0x130(%rbp),%rdi
movslq -0x13c(%rbp),%rax
add    %rax,%rdi
mov    -0x134(%rbp),%edx
mov    $0x30,%esi
call   1050 <memset@plt>
lea    -0x130(%rbp),%rdi
movslq -0x13c(%rbp),%rax
add    %rax,%rdi
movslq -0x134(%rbp),%rax
add    %rax,%rdi
mov    -0x134(%rbp),%edx
lea    0xe19(%rip),%rsi
call   1060 <sprintf@plt>
lea    -0x130(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1040 <strtof@plt>
movss  %xmm0,-0x140(%rbp)
ff
movss  -0x140(%rbp),%xmm0
ff
cvtsi2ssl -0x134(%rbp),%xmm1
ff
ucomiss %xmm1,%xmm0
jne    1228 <test_strtof+0xd8>
jp     1228 <test_strtof+0xd8>
jmp    12a0 <test_strtof+0x150>
lea    -0x1c0(%rbp),%rdi
movss  -0x140(%rbp),%xmm0
ff
mov    $0x80,%esi
lea    0xdc6(%rip),%rdx
call   1070 <strfromf@plt>
lea    -0x240(%rbp),%rdi
cvtsi2ssl -0x134(%rbp),%xmm0
ff
mov    $0x80,%esi
lea    0xda6(%rip),%rdx
call   1070 <strfromf@plt>
lea    -0x130(%rbp),%rsi
mov    -0x134(%rbp),%edx
lea    -0x1c0(%rbp),%rcx
lea    -0x240(%rbp),%r8
lea    0xd82(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x1,-0x138(%rbp)
jmp    12b4 <test_strtof+0x164>
mov    -0x134(%rbp),%esi
lea    0xd95(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    12b9 <test_strtof+0x169>
mov    -0x134(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x134(%rbp)
jmp    116f <test_strtof+0x1f>
mov    -0x138(%rbp),%eax
add    $0x240,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<test_strtof>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x248,%rsp
lea    0x10(%rsp),%r13
xor    %r14d,%r14d
xor    %r15d,%r15d
jmp    1192 <test_strtof+0x42>
xchg   %ax,%ax
lea    0xecb(%rip),%rdi
mov    %r14d,%esi
xor    %eax,%eax
call   1030 <printf@plt>
add    $0x1,%r14
cmp    $0xc8,%r14
je     1257 <test_strtof+0x107>
mov    %r13,%rdi
lea    0xe6a(%rip),%rsi
mov    %r14d,%edx
call   1060 <sprintf@plt>
movslq %eax,%r12
lea    (%rsp,%r12,1),%rdi
add    $0x10,%rdi
mov    $0x30,%esi
mov    %r14d,%edx
call   1050 <memset@plt>
add    %r14,%r12
lea    (%rsp,%r12,1),%rdi
add    $0x10,%rdi
lea    0xe32(%rip),%rsi
mov    %r14d,%edx
call   1060 <sprintf@plt>
mov    %r13,%rdi
xor    %esi,%esi
call   1040 <strtof@plt>
xorps  %xmm1,%xmm1
cvtsi2ss %r14d,%xmm1
ucomiss %xmm1,%xmm0
jne    11ef <test_strtof+0x9f>
jnp    1170 <test_strtof+0x20>
lea    0x1c0(%rsp),%r15
mov    %r15,%rdi
mov    $0x80,%esi
lea    0xe03(%rip),%rbp
mov    %rbp,%rdx
movss  %xmm1,0xc(%rsp)
call   1070 <strfromf@plt>
lea    0x140(%rsp),%rbx
mov    %rbx,%rdi
mov    $0x80,%esi
mov    %rbp,%rdx
movss  0xc(%rsp),%xmm0
call   1070 <strfromf@plt>
lea    0xdd3(%rip),%rdi
mov    %r13,%rsi
mov    %r14d,%edx
mov    %r15,%rcx
mov    %rbx,%r8
xor    %eax,%eax
call   1030 <printf@plt>
mov    $0x1,%r15d
jmp    1181 <test_strtof+0x31>
mov    %r15d,%eax
add    $0x248,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [3 x i8] c"%d\00"
@.str.1 = [9 x i8] c".000e-%d\00"
@.str.2 = [3 x i8] c"%g\00"
@.str.3 = [54 x i8] c"strtof(\22%s\22) failed for cnt == %d (%s instead of %s)\0A\00"
@.str.4 = [29 x i8] c"strtof() fine for cnt == %d\0A\00"
define i32 @test_strtof() {
%1 = alloca [300 x i8]
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca float
%6 = alloca [128 x i8]
%7 = alloca [128 x i8]
store i32 0, i32* %3
store i32 0, i32* %2
br label %8
8: ; preds = %53, %0
%9 = load i32, i32* %2
%10 = icmp slt i32 %9, 200
br i1 %10, label %11, label %56
11: ; preds = %8
%12 = getelementptr inbounds [300 x i8], [300 x i8]* %1, i64 0, i64 0
%13 = load i32, i32* %2
%14 = call i32 @sprintf(i8* %12, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 %13)
store i32 %14, i32* %4
%15 = getelementptr inbounds [300 x i8], [300 x i8]* %1, i64 0, i64 0
%16 = load i32, i32* %4
%17 = sext i32 %16 to i64
%18 = getelementptr inbounds i8, i8* %15, i64 %17
%19 = load i32, i32* %2
%20 = call i32 @memset(i8* %18, i32 48, i32 %19)
%21 = getelementptr inbounds [300 x i8], [300 x i8]* %1, i64 0, i64 0
%22 = load i32, i32* %4
%23 = sext i32 %22 to i64
%24 = getelementptr inbounds i8, i8* %21, i64 %23
%25 = load i32, i32* %2
%26 = sext i32 %25 to i64
%27 = getelementptr inbounds i8, i8* %24, i64 %26
%28 = load i32, i32* %2
%29 = call i32 @sprintf(i8* %27, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i32 %28)
%30 = getelementptr inbounds [300 x i8], [300 x i8]* %1, i64 0, i64 0
%31 = call float @strtof(i8* %30, i32* null)
store float %31, float* %5
%32 = load float, float* %5
%33 = load i32, i32* %2
%34 = sitofp i32 %33 to float
%35 = fcmp une float %32, %34
br i1 %35, label %36, label %49
36: ; preds = %11
%37 = getelementptr inbounds [128 x i8], [128 x i8]* %6, i64 0, i64 0
%38 = load float, float* %5
%39 = call i32 @strfromf(i8* %37, i32 128, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), float %38)
%40 = getelementptr inbounds [128 x i8], [128 x i8]* %7, i64 0, i64 0
%41 = load i32, i32* %2
%42 = sitofp i32 %41 to float
%43 = call i32 @strfromf(i8* %40, i32 128, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), float %42)
%44 = getelementptr inbounds [300 x i8], [300 x i8]* %1, i64 0, i64 0
%45 = load i32, i32* %2
%46 = getelementptr inbounds [128 x i8], [128 x i8]* %6, i64 0, i64 0
%47 = getelementptr inbounds [128 x i8], [128 x i8]* %7, i64 0, i64 0
%48 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([54 x i8], [54 x i8]* @.str.3, i64 0, i64 0), i8* %44, i32 %45, i8* %46, i8* %47)
store i32 1, i32* %3
br label %52
49: ; preds = %11
%50 = load i32, i32* %2
%51 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.4, i64 0, i64 0), i32 %50)
br label %52
52: ; preds = %49, %36
br label %53
53: ; preds = %52
%54 = load i32, i32* %2
%55 = add nsw i32 %54, 1
store i32 %55, i32* %2
br label %8
56: ; preds = %8
%57 = load i32, i32* %3
ret i32 %57
}

LLVM IR (-O2):
@.str = [3 x i8] c"%d\00"
@.str.1 = [9 x i8] c".000e-%d\00"
@.str.2 = [3 x i8] c"%g\00"
@.str.3 = [54 x i8] c"strtof(\22%s\22) failed for cnt == %d (%s instead of %s)\0A\00"
@.str.4 = [29 x i8] c"strtof() fine for cnt == %d\0A\00"
define i32 @test_strtof() {
%1 = alloca [300 x i8]
%2 = alloca [128 x i8]
%3 = alloca [128 x i8]
%4 = getelementptr inbounds [300 x i8], [300 x i8]* %1, i64 0, i64 0
%5 = getelementptr inbounds [128 x i8], [128 x i8]* %2, i64 0, i64 0
%6 = getelementptr inbounds [128 x i8], [128 x i8]* %3, i64 0, i64 0
br label %7
7: ; preds = %0, %26
%8 = phi i64 [ 0, %0 ], [ %28, %26 ]
%9 = phi i32 [ 0, %0 ], [ %27, %26 ]
%10 = trunc i64 %8 to i32
%11 = call i32 @sprintf(i8* %4, i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 %10)
%12 = sext i32 %11 to i64
%13 = getelementptr inbounds [300 x i8], [300 x i8]* %1, i64 0, i64 %12
%14 = call i32 @memset(i8* %13, i32 48, i32 %10)
%15 = getelementptr inbounds i8, i8* %13, i64 %8
%16 = call i32 @sprintf(i8* %15, i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i32 %10)
%17 = call float @strtof(i8* nocapture %4, i32* null)
%18 = sitofp i32 %10 to float
%19 = fcmp une float %17, %18
br i1 %19, label %20, label %24
20: ; preds = %7
%21 = call i32 @strfromf(i8* %5, i32 128, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), float %17)
%22 = call i32 @strfromf(i8* %6, i32 128, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), float %18)
%23 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([54 x i8], [54 x i8]* @.str.3, i64 0, i64 0), i8* %4, i32 %10, i8* %5, i8* %6)
br label %26
24: ; preds = %7
%25 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([29 x i8], [29 x i8]* @.str.4, i64 0, i64 0), i32 %10)
br label %26
26: ; preds = %24, %20
%27 = phi i32 [ 1, %20 ], [ %9, %24 ]
%28 = add nuw nsw i64 %8, 1
%29 = icmp eq i64 %28, 200
br i1 %29, label %30, label %7
30: ; preds = %26
ret i32 %27
}