#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 */
double CLOCKS_PER_SEC;
float FastInverseSqrt(float);
scalar_t__ clock();
int /*<<< orphan*/ printf(char *, double);
float rand();
float sqrtf(float);
int /*<<< orphan*/ srand(int /*<<< orphan*/);
int /*<<< orphan*/ time(int /*<<< orphan*/);
int main(int argc, char **argv) {
  static const int num = 2000000;
  float val[num];
  int iternum = 1;
  float x;
  clock_t st, et;
  srand(time(0));
  for (int i = 0; i < num; ++i)
    val[i] = rand() + 100.0f;
  st = clock();
  for (int i = 0; i < num; ++i) {
    x = val[i];
    x = FastInverseSqrt(x);
  }
  et = clock();
  printf("FIS: %lf\n", ((double)et - (double)st) / CLOCKS_PER_SEC);
  st = clock();
  for (int i = 0; i < num; ++i) {
    x = val[i];
    x = 1.0f / sqrtf(x);
  }
  et = clock();
  printf("sqrtf: %lf", ((double)et - (double)st) / CLOCKS_PER_SEC);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x7a1240,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rsp,%rax
mov    %rax,-0x18(%rbp)
movl   $0x1,-0x1c(%rbp)
xor    %edi,%edi
call   1070 <time@plt>
mov    %eax,%edi
call   1060 <srand@plt>
movl   $0x0,-0x34(%rbp)
cmpl   $0x1e8480,-0x34(%rbp)
jge    11e7 <main+0x77>
mov    $0x0,%al
call   1090 <rand@plt>
movss  0xe3c(%rip),%xmm1
addss  %xmm1,%xmm0
movslq -0x34(%rbp),%rax
movss  %xmm0,-0x7a1240(%rbp,%rax,4)
85 ff
mov    -0x34(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x34(%rbp)
jmp    11ac <main+0x3c>
mov    $0x0,%al
call   1030 <clock@plt>
mov    %rax,-0x28(%rbp)
movl   $0x0,-0x38(%rbp)
cmpl   $0x1e8480,-0x38(%rbp)
jge    1235 <main+0xc5>
movslq -0x38(%rbp),%rax
movss  -0x7a1240(%rbp,%rax,4),%xmm0
85 ff
movss  %xmm0,-0x20(%rbp)
movss  -0x20(%rbp),%xmm0
call   1040 <FastInverseSqrt@plt>
movss  %xmm0,-0x20(%rbp)
mov    -0x38(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x38(%rbp)
jmp    11f9 <main+0x89>
mov    $0x0,%al
call   1030 <clock@plt>
mov    %rax,-0x30(%rbp)
cvtsi2sdq -0x30(%rbp),%xmm0
cvtsi2sdq -0x28(%rbp),%xmm1
subsd  %xmm1,%xmm0
mov    0x2d91(%rip),%rax
divsd  (%rax),%xmm0
lea    0xdaa(%rip),%rdi
call   1050 <printf@plt>
mov    $0x0,%al
call   1030 <clock@plt>
mov    %rax,-0x28(%rbp)
movl   $0x0,-0x3c(%rbp)
cmpl   $0x1e8480,-0x3c(%rbp)
jge    12c4 <main+0x154>
movslq -0x3c(%rbp),%rax
movss  -0x7a1240(%rbp,%rax,4),%xmm0
85 ff
movss  %xmm0,-0x20(%rbp)
movss  -0x20(%rbp),%xmm0
call   1080 <sqrtf@plt>
movaps %xmm0,%xmm1
movss  0xd53(%rip),%xmm0
divss  %xmm1,%xmm0
movss  %xmm0,-0x20(%rbp)
mov    -0x3c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x3c(%rbp)
jmp    1279 <main+0x109>
mov    $0x0,%al
call   1030 <clock@plt>
mov    %rax,-0x30(%rbp)
cvtsi2sdq -0x30(%rbp),%xmm0
cvtsi2sdq -0x28(%rbp),%xmm1
subsd  %xmm1,%xmm0
mov    0x2d02(%rip),%rax
divsd  (%rax),%xmm0
lea    0xd25(%rip),%rdi
call   1050 <printf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,%rsp
mov    -0x4(%rbp),%eax
add    $0x7a1240,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
sub    $0x7a1200,%rsp
xor    %edi,%edi
call   1070 <time@plt>
mov    %eax,%edi
call   1060 <srand@plt>
xor    %ebx,%ebx
nopl   0x0(%rax)
xor    %eax,%eax
call   1090 <rand@plt>
addss  0xe61(%rip),%xmm0
movss  %xmm0,(%rsp,%rbx,4)
add    $0x1,%rbx
cmp    $0x1e8480,%rbx
jne    1190 <main+0x20>
xor    %ebx,%ebx
xor    %eax,%eax
call   1030 <clock@plt>
mov    %rax,%r14
nopl   (%rax)
movss  (%rsp,%rbx,4),%xmm0
call   1040 <FastInverseSqrt@plt>
add    $0x1,%rbx
cmp    $0x1e8480,%rbx
jne    11c0 <main+0x50>
xor    %eax,%eax
call   1030 <clock@plt>
xorps  %xmm0,%xmm0
cvtsi2sd %rax,%xmm0
cvtsi2sd %r14,%xmm1
subsd  %xmm1,%xmm0
mov    0x2df2(%rip),%r14
divsd  (%r14),%xmm0
lea    0xe02(%rip),%rdi
call   1050 <printf@plt>
xor    %eax,%eax
call   1030 <clock@plt>
mov    %rax,%r15
mov    $0x3,%ebx
xorpd  %xmm1,%xmm1
nopw   0x0(%rax,%rax,1)
movss  -0xc(%rsp,%rbx,4),%xmm0
ucomiss %xmm0,%xmm1
ja     125a <main+0xea>
movss  -0x8(%rsp,%rbx,4),%xmm0
ucomiss %xmm0,%xmm1
ja     1269 <main+0xf9>
movss  -0x4(%rsp,%rbx,4),%xmm0
ucomiss %xmm0,%xmm1
ja     1278 <main+0x108>
movss  (%rsp,%rbx,4),%xmm0
ucomiss %xmm0,%xmm1
ja     1287 <main+0x117>
add    $0x4,%rbx
cmp    $0x1e8483,%rbx
jne    1220 <main+0xb0>
jmp    1296 <main+0x126>
ucomiss %xmm1,%xmm0
jae    122b <main+0xbb>
call   1080 <sqrtf@plt>
xorps  %xmm1,%xmm1
jmp    122b <main+0xbb>
ucomiss %xmm1,%xmm0
jae    1236 <main+0xc6>
call   1080 <sqrtf@plt>
xorps  %xmm1,%xmm1
jmp    1236 <main+0xc6>
ucomiss %xmm1,%xmm0
jae    1241 <main+0xd1>
call   1080 <sqrtf@plt>
xorps  %xmm1,%xmm1
jmp    1241 <main+0xd1>
ucomiss %xmm1,%xmm0
jae    124b <main+0xdb>
call   1080 <sqrtf@plt>
xorps  %xmm1,%xmm1
jmp    124b <main+0xdb>
xor    %eax,%eax
call   1030 <clock@plt>
xorps  %xmm0,%xmm0
cvtsi2sd %rax,%xmm0
xorps  %xmm1,%xmm1
cvtsi2sd %r15,%xmm1
subsd  %xmm1,%xmm0
divsd  (%r14),%xmm0
lea    0xd51(%rip),%rdi
call   1050 <printf@plt>
xor    %eax,%eax
add    $0x7a1200,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@main.num = internal constant i32 2000000
@.str = [10 x i8] c"FIS: %lf\0A\00"
@CLOCKS_PER_SEC = global double 0.000000e+00
@.str.1 = [11 x i8] c"sqrtf: %lf\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8*
%7 = alloca i32
%8 = alloca float
%9 = alloca i64
%10 = alloca i64
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%14 = call i8* @llvm.stacksave()
store i8* %14, i8** %6
%15 = alloca float, i64 2000000
store i32 1, i32* %7
%16 = call i32 @time(i32 0)
%17 = call i32 @srand(i32 %16)
store i32 0, i32* %11
br label %18
18: ; preds = %27, %2
%19 = load i32, i32* %11
%20 = icmp slt i32 %19, 2000000
br i1 %20, label %21, label %30
21: ; preds = %18
%22 = call float (...) @rand()
%23 = fadd float %22, 1.000000e+02
%24 = load i32, i32* %11
%25 = sext i32 %24 to i64
%26 = getelementptr inbounds float, float* %15, i64 %25
store float %23, float* %26
br label %27
27: ; preds = %21
%28 = load i32, i32* %11
%29 = add nsw i32 %28, 1
store i32 %29, i32* %11
br label %18
30: ; preds = %18
%31 = call i64 (...) @clock()
store i64 %31, i64* %9
store i32 0, i32* %12
br label %32
32: ; preds = %42, %30
%33 = load i32, i32* %12
%34 = icmp slt i32 %33, 2000000
br i1 %34, label %35, label %45
35: ; preds = %32
%36 = load i32, i32* %12
%37 = sext i32 %36 to i64
%38 = getelementptr inbounds float, float* %15, i64 %37
%39 = load float, float* %38
store float %39, float* %8
%40 = load float, float* %8
%41 = call float @FastInverseSqrt(float %40)
store float %41, float* %8
br label %42
42: ; preds = %35
%43 = load i32, i32* %12
%44 = add nsw i32 %43, 1
store i32 %44, i32* %12
br label %32
45: ; preds = %32
%46 = call i64 (...) @clock()
store i64 %46, i64* %10
%47 = load i64, i64* %10
%48 = sitofp i64 %47 to double
%49 = load i64, i64* %9
%50 = sitofp i64 %49 to double
%51 = fsub double %48, %50
%52 = load double, double* @CLOCKS_PER_SEC
%53 = fdiv double %51, %52
%54 = call i32 @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), double %53)
%55 = call i64 (...) @clock()
store i64 %55, i64* %9
store i32 0, i32* %13
br label %56
56: ; preds = %67, %45
%57 = load i32, i32* %13
%58 = icmp slt i32 %57, 2000000
br i1 %58, label %59, label %70
59: ; preds = %56
%60 = load i32, i32* %13
%61 = sext i32 %60 to i64
%62 = getelementptr inbounds float, float* %15, i64 %61
%63 = load float, float* %62
store float %63, float* %8
%64 = load float, float* %8
%65 = call float @sqrtf(float %64)
%66 = fdiv float 1.000000e+00, %65
store float %66, float* %8
br label %67
67: ; preds = %59
%68 = load i32, i32* %13
%69 = add nsw i32 %68, 1
store i32 %69, i32* %13
br label %56
70: ; preds = %56
%71 = call i64 (...) @clock()
store i64 %71, i64* %10
%72 = load i64, i64* %10
%73 = sitofp i64 %72 to double
%74 = load i64, i64* %9
%75 = sitofp i64 %74 to double
%76 = fsub double %73, %75
%77 = load double, double* @CLOCKS_PER_SEC
%78 = fdiv double %76, %77
%79 = call i32 @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0), double %78)
store i32 0, i32* %3
%80 = load i8*, i8** %6
%81 = load i32, i32* %3
ret i32 %81
}

LLVM IR (-O2):
@.str = [10 x i8] c"FIS: %lf\0A\00"
@CLOCKS_PER_SEC = global double 0.000000e+00
@.str.1 = [11 x i8] c"sqrtf: %lf\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca [2000000 x float]
%4 = tail call i32 @time(i32 0)
%5 = tail call i32 @srand(i32 %4)
br label %8
6: ; preds = %8
%7 = tail call i64 (...) @clock()
br label %24
8: ; preds = %2, %8
%9 = phi i64 [ 0, %2 ], [ %13, %8 ]
%10 = tail call float (...) @rand()
%11 = fadd float %10, 1.000000e+02
%12 = getelementptr inbounds [2000000 x float], [2000000 x float]* %3, i64 0, i64 %9
store float %11, float* %12
%13 = add nuw nsw i64 %9, 1
%14 = icmp eq i64 %13, 2000000
br i1 %14, label %6, label %8
15: ; preds = %24
%16 = tail call i64 (...) @clock()
%17 = sitofp i64 %16 to double
%18 = sitofp i64 %7 to double
%19 = fsub double %17, %18
%20 = load double, double* @CLOCKS_PER_SEC
%21 = fdiv double %19, %20
%22 = tail call i32 @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), double %21)
%23 = tail call i64 (...) @clock()
br label %39
24: ; preds = %6, %24
%25 = phi i64 [ 0, %6 ], [ %29, %24 ]
%26 = getelementptr inbounds [2000000 x float], [2000000 x float]* %3, i64 0, i64 %25
%27 = load float, float* %26
%28 = tail call float @FastInverseSqrt(float %27)
%29 = add nuw nsw i64 %25, 1
%30 = icmp eq i64 %29, 2000000
br i1 %30, label %15, label %24
31: ; preds = %67
%32 = tail call i64 (...) @clock()
%33 = sitofp i64 %32 to double
%34 = sitofp i64 %23 to double
%35 = fsub double %33, %34
%36 = load double, double* @CLOCKS_PER_SEC
%37 = fdiv double %35, %36
%38 = tail call i32 @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0), double %37)
ret i32 0
39: ; preds = %67, %15
%40 = phi i64 [ 0, %15 ], [ %68, %67 ]
%41 = getelementptr inbounds [2000000 x float], [2000000 x float]* %3, i64 0, i64 %40
%42 = load float, float* %41
%43 = fcmp olt float %42, 0.000000e+00
br i1 %43, label %44, label %46
44: ; preds = %39
%45 = tail call float @sqrtf(float %42)
br label %46
46: ; preds = %39, %44
%47 = or i64 %40, 1
%48 = getelementptr inbounds [2000000 x float], [2000000 x float]* %3, i64 0, i64 %47
%49 = load float, float* %48
%50 = fcmp olt float %49, 0.000000e+00
br i1 %50, label %51, label %53
51: ; preds = %46
%52 = tail call float @sqrtf(float %49)
br label %53
53: ; preds = %51, %46
%54 = or i64 %40, 2
%55 = getelementptr inbounds [2000000 x float], [2000000 x float]* %3, i64 0, i64 %54
%56 = load float, float* %55
%57 = fcmp olt float %56, 0.000000e+00
br i1 %57, label %58, label %60
58: ; preds = %53
%59 = tail call float @sqrtf(float %56)
br label %60
60: ; preds = %58, %53
%61 = or i64 %40, 3
%62 = getelementptr inbounds [2000000 x float], [2000000 x float]* %3, i64 0, i64 %61
%63 = load float, float* %62
%64 = fcmp olt float %63, 0.000000e+00
br i1 %64, label %65, label %67
65: ; preds = %60
%66 = tail call float @sqrtf(float %63)
br label %67
67: ; preds = %65, %60
%68 = add nuw nsw i64 %40, 4
%69 = icmp eq i64 %68, 2000000
br i1 %69, label %31, label %39
}