#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 scalar_t__ clock_t;

/* Variables and functions */
scalar_t__ CLOCKS_PER_SEC;
scalar_t__ clock();
int /*<<< orphan*/ fiolSWriteFloat(char *, float, int);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ sprintf(char *, char *, float);
void benchWriteOneFloat(float val1) {
  unsigned int i;
  char msg[255];
  clock_t start, end;
  printf("\t%f\r\n", val1);
  do {
    start = clock();
  } while (0);
  for (i = 0; i < 400000; i++) {
    fiolSWriteFloat(msg, val1, 4);
  }
  do {
    end = clock();
    printf("\t\t%s: %f\r\n", "fiolSWriteFloat",
           (float)(end - start) / (float)CLOCKS_PER_SEC);
  } while (0);
  do {
    start = clock();
  } while (0);
  for (i = 0; i < 400000; i++) {
    sprintf(msg, "%f", val1);
  }
  do {
    end = clock();
    printf("\t\t%s: %f\r\n", "sscanf",
           (float)(end - start) / (float)CLOCKS_PER_SEC);
  } while (0);
  printf("\r\n");
}


x86 assembly (clang, -O0):
<benchWriteOneFloat>:
push   %rbp
mov    %rsp,%rbp
sub    $0x120,%rsp
movss  %xmm0,-0x4(%rbp)
movss  -0x4(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
lea    0xea0(%rip),%rdi
mov    $0x1,%al
call   1040 <printf@plt>
mov    $0x0,%al
call   1030 <clock@plt>
mov    %rax,-0x118(%rbp)
movl   $0x0,-0x8(%rbp)
cmpl   $0x61a80,-0x8(%rbp)
jae    11ad <benchWriteOneFloat+0x6d>
lea    -0x110(%rbp),%rdi
movss  -0x4(%rbp),%xmm0
mov    $0x4,%esi
call   1050 <fiolSWriteFloat@plt>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    117c <benchWriteOneFloat+0x3c>
jmp    11b2 <benchWriteOneFloat+0x72>
mov    $0x0,%al
call   1030 <clock@plt>
mov    %rax,-0x120(%rbp)
mov    -0x120(%rbp),%rax
sub    -0x118(%rbp),%rax
cvtsi2ss %rax,%xmm0
mov    0x2e0e(%rip),%rax
cvtsi2ssq (%rax),%xmm1
divss  %xmm1,%xmm0
cvtss2sd %xmm0,%xmm0
lea    0xe18(%rip),%rdi
lea    0xe1c(%rip),%rsi
mov    $0x1,%al
call   1040 <printf@plt>
jmp    1201 <benchWriteOneFloat+0xc1>
mov    $0x0,%al
call   1030 <clock@plt>
mov    %rax,-0x118(%rbp)
movl   $0x0,-0x8(%rbp)
cmpl   $0x61a80,-0x8(%rbp)
jae    1249 <benchWriteOneFloat+0x109>
lea    -0x110(%rbp),%rdi
movss  -0x4(%rbp),%xmm0
lea    0xdeb(%rip),%rsi
call   1060 <sprintf@plt>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    1216 <benchWriteOneFloat+0xd6>
jmp    124e <benchWriteOneFloat+0x10e>
mov    $0x0,%al
call   1030 <clock@plt>
mov    %rax,-0x120(%rbp)
mov    -0x120(%rbp),%rax
sub    -0x118(%rbp),%rax
cvtsi2ss %rax,%xmm0
mov    0x2d72(%rip),%rax
cvtsi2ssq (%rax),%xmm1
divss  %xmm1,%xmm0
cvtss2sd %xmm0,%xmm0
lea    0xd7c(%rip),%rdi
lea    0xd93(%rip),%rsi
mov    $0x1,%al
call   1040 <printf@plt>
lea    0xd64(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
add    $0x120,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<benchWriteOneFloat>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x110,%rsp
movss  %xmm0,0xc(%rsp)
cvtss2sd %xmm0,%xmm0
lea    0xe90(%rip),%rdi
mov    $0x1,%al
call   1050 <printf@plt>
xor    %eax,%eax
call   1040 <clock@plt>
mov    %rax,%r14
mov    $0x61a80,%ebp
lea    0x10(%rsp),%rbx
nopl   0x0(%rax,%rax,1)
mov    %rbx,%rdi
movss  0xc(%rsp),%xmm0
mov    $0x4,%esi
call   1060 <fiolSWriteFloat@plt>
add    $0xffffffff,%ebp
jne    1190 <benchWriteOneFloat+0x40>
xor    %eax,%eax
call   1040 <clock@plt>
sub    %r14,%rax
xorps  %xmm0,%xmm0
cvtsi2ss %rax,%xmm0
mov    0x2e27(%rip),%r12
cvtsi2ssq (%r12),%xmm1
divss  %xmm1,%xmm0
cvtss2sd %xmm0,%xmm0
lea    0xe30(%rip),%rdi
lea    0xe34(%rip),%rsi
mov    $0x1,%al
call   1050 <printf@plt>
xor    %eax,%eax
call   1040 <clock@plt>
mov    %rax,%r14
mov    $0x61a80,%ebp
lea    0xe27(%rip),%r15
lea    0x10(%rsp),%rbx
nop
mov    %rbx,%rdi
mov    %r15,%rsi
movss  0xc(%rsp),%xmm0
call   1070 <sprintf@plt>
add    $0xffffffff,%ebp
jne    1200 <benchWriteOneFloat+0xb0>
xor    %eax,%eax
call   1040 <clock@plt>
sub    %r14,%rax
xorps  %xmm0,%xmm0
cvtsi2ss %rax,%xmm0
xorps  %xmm1,%xmm1
cvtsi2ssq (%r12),%xmm1
divss  %xmm1,%xmm0
cvtss2sd %xmm0,%xmm0
lea    0xdc6(%rip),%rdi
lea    0xddd(%rip),%rsi
mov    $0x1,%al
call   1050 <printf@plt>
lea    0xdd6(%rip),%rdi
call   1030 <puts@plt>
add    $0x110,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [6 x i8] c"\09%f\0D\0A\00"
@.str.1 = [11 x i8] c"\09\09%s: %f\0D\0A\00"
@.str.2 = [16 x i8] c"fiolSWriteFloat\00"
@CLOCKS_PER_SEC = global i64 0
@.str.3 = [3 x i8] c"%f\00"
@.str.4 = [7 x i8] c"sscanf\00"
@.str.5 = [3 x i8] c"\0D\0A\00"
define void @benchWriteOneFloat(float %0) {
%2 = alloca float
%3 = alloca i32
%4 = alloca [255 x i8]
%5 = alloca i64
%6 = alloca i64
store float %0, float* %2
%7 = load float, float* %2
%8 = fpext float %7 to double
%9 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), double %8)
br label %10
10: ; preds = %1
%11 = call i64 (...) @clock()
store i64 %11, i64* %5
br label %12
12: ; preds = %10
store i32 0, i32* %3
br label %13
13: ; preds = %20, %12
%14 = load i32, i32* %3
%15 = icmp ult i32 %14, 400000
br i1 %15, label %16, label %23
16: ; preds = %13
%17 = getelementptr inbounds [255 x i8], [255 x i8]* %4, i64 0, i64 0
%18 = load float, float* %2
%19 = call i32 @fiolSWriteFloat(i8* %17, float %18, i32 4)
br label %20
20: ; preds = %16
%21 = load i32, i32* %3
%22 = add i32 %21, 1
store i32 %22, i32* %3
br label %13
23: ; preds = %13
br label %24
24: ; preds = %23
%25 = call i64 (...) @clock()
store i64 %25, i64* %6
%26 = load i64, i64* %6
%27 = load i64, i64* %5
%28 = sub nsw i64 %26, %27
%29 = sitofp i64 %28 to float
%30 = load i64, i64* @CLOCKS_PER_SEC
%31 = sitofp i64 %30 to float
%32 = fdiv float %29, %31
%33 = fpext float %32 to double
%34 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0), double %33)
br label %35
35: ; preds = %24
br label %36
36: ; preds = %35
%37 = call i64 (...) @clock()
store i64 %37, i64* %5
br label %38
38: ; preds = %36
store i32 0, i32* %3
br label %39
39: ; preds = %46, %38
%40 = load i32, i32* %3
%41 = icmp ult i32 %40, 400000
br i1 %41, label %42, label %49
42: ; preds = %39
%43 = getelementptr inbounds [255 x i8], [255 x i8]* %4, i64 0, i64 0
%44 = load float, float* %2
%45 = call i32 @sprintf(i8* %43, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), float %44)
br label %46
46: ; preds = %42
%47 = load i32, i32* %3
%48 = add i32 %47, 1
store i32 %48, i32* %3
br label %39
49: ; preds = %39
br label %50
50: ; preds = %49
%51 = call i64 (...) @clock()
store i64 %51, i64* %6
%52 = load i64, i64* %6
%53 = load i64, i64* %5
%54 = sub nsw i64 %52, %53
%55 = sitofp i64 %54 to float
%56 = load i64, i64* @CLOCKS_PER_SEC
%57 = sitofp i64 %56 to float
%58 = fdiv float %55, %57
%59 = fpext float %58 to double
%60 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.4, i64 0, i64 0), double %59)
br label %61
61: ; preds = %50
%62 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0))
ret void
}

LLVM IR (-O2):
@.str = [6 x i8] c"\09%f\0D\0A\00"
@.str.1 = [11 x i8] c"\09\09%s: %f\0D\0A\00"
@.str.2 = [16 x i8] c"fiolSWriteFloat\00"
@CLOCKS_PER_SEC = global i64 0
@.str.3 = [3 x i8] c"%f\00"
@.str.4 = [7 x i8] c"sscanf\00"
@str = [2 x i8] c"\0D\00"
define void @benchWriteOneFloat(float %0) {
%2 = alloca [255 x i8]
%3 = getelementptr inbounds [255 x i8], [255 x i8]* %2, i64 0, i64 0
%4 = fpext float %0 to double
%5 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), double %4)
%6 = tail call i64 (...) @clock()
br label %7
7: ; preds = %1, %7
%8 = phi i32 [ 0, %1 ], [ %10, %7 ]
%9 = call i32 @fiolSWriteFloat(i8* %3, float %0, i32 4)
%10 = add nuw nsw i32 %8, 1
%11 = icmp eq i32 %10, 400000
br i1 %11, label %12, label %7
12: ; preds = %7
%13 = call i64 (...) @clock()
%14 = sub nsw i64 %13, %6
%15 = sitofp i64 %14 to float
%16 = load i64, i64* @CLOCKS_PER_SEC
%17 = sitofp i64 %16 to float
%18 = fdiv float %15, %17
%19 = fpext float %18 to double
%20 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0), double %19)
%21 = call i64 (...) @clock()
br label %22
22: ; preds = %12, %22
%23 = phi i32 [ 0, %12 ], [ %25, %22 ]
%24 = call i32 @sprintf(i8* %3, i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), float %0)
%25 = add nuw nsw i32 %23, 1
%26 = icmp eq i32 %25, 400000
br i1 %26, label %27, label %22
27: ; preds = %22
%28 = call i64 (...) @clock()
%29 = sub nsw i64 %28, %21
%30 = sitofp i64 %29 to float
%31 = load i64, i64* @CLOCKS_PER_SEC
%32 = sitofp i64 %31 to float
%33 = fdiv float %30, %32
%34 = fpext float %33 to double
%35 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.4, i64 0, i64 0), double %34)
%36 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([2 x i8], [2 x i8]* @str, i64 0, i64 0))
ret void
}