#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 /*<<< orphan*/ dot(float *, float *, float *);
float frand(double, double);
int /*<<< orphan*/ initfrand();
int /*<<< orphan*/ printf(char *, float, float, double);
int /*<<< orphan*/ sse_dot(float *, float *, float *);
int main() {
  float v1[4];
  float v2[4];
  float res1, res2;
  int i = 0;
  initfrand();
  for (i = 0; i < 4; i++) {
    v1[i] = frand(-1000.0, 1000.0);
    v2[i] = frand(-1000.0, 1000.0);
  }
  sse_dot(v1, v2, &res2);
  dot(v1, v2, &res1);
  printf("dot=%.3f, sse_dot=%.3f, err=%.3f%%\n", res1, res2,
         100.0 * (1.0 - res1 / res2));
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0x3c(%rbp)
mov    $0x0,%al
call   1050 <initfrand@plt>
movl   $0x0,-0x3c(%rbp)
cmpl   $0x4,-0x3c(%rbp)
jge    11ca <main+0x7a>
movsd  0xe8a(%rip),%xmm0
movsd  0xe8a(%rip),%xmm1
call   1060 <frand@plt>
movslq -0x3c(%rbp),%rax
movss  %xmm0,-0x20(%rbp,%rax,4)
movsd  0xe6b(%rip),%xmm0
movsd  0xe6b(%rip),%xmm1
call   1060 <frand@plt>
movslq -0x3c(%rbp),%rax
movss  %xmm0,-0x30(%rbp,%rax,4)
mov    -0x3c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x3c(%rbp)
jmp    1174 <main+0x24>
lea    -0x20(%rbp),%rdi
lea    -0x30(%rbp),%rsi
lea    -0x38(%rbp),%rdx
call   1070 <sse_dot@plt>
lea    -0x20(%rbp),%rdi
lea    -0x30(%rbp),%rsi
lea    -0x34(%rbp),%rdx
call   1030 <dot@plt>
movss  -0x34(%rbp),%xmm0
movss  -0x38(%rbp),%xmm1
movss  -0x34(%rbp),%xmm2
divss  -0x38(%rbp),%xmm2
cvtss2sd %xmm2,%xmm2
movsd  0xdfc(%rip),%xmm3
subsd  %xmm2,%xmm3
movsd  0xde8(%rip),%xmm2
mulsd  %xmm3,%xmm2
lea    0xdfd(%rip),%rdi
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
sub    $0x38,%rsp
xor    %eax,%eax
call   1050 <initfrand@plt>
movsd  0xe9a(%rip),%xmm0
movsd  0xe9a(%rip),%xmm1
call   1060 <frand@plt>
movss  %xmm0,0x20(%rsp)
movsd  0xe7f(%rip),%xmm0
movsd  0xe7f(%rip),%xmm1
call   1060 <frand@plt>
movss  %xmm0,0x10(%rsp)
movsd  0xe64(%rip),%xmm0
movsd  0xe64(%rip),%xmm1
call   1060 <frand@plt>
movss  %xmm0,0x24(%rsp)
movsd  0xe49(%rip),%xmm0
movsd  0xe49(%rip),%xmm1
call   1060 <frand@plt>
movss  %xmm0,0x14(%rsp)
movsd  0xe2e(%rip),%xmm0
movsd  0xe2e(%rip),%xmm1
call   1060 <frand@plt>
movss  %xmm0,0x28(%rsp)
movsd  0xe13(%rip),%xmm0
movsd  0xe13(%rip),%xmm1
call   1060 <frand@plt>
movss  %xmm0,0x18(%rsp)
movsd  0xdf8(%rip),%xmm0
movsd  0xdf8(%rip),%xmm1
call   1060 <frand@plt>
movss  %xmm0,0x2c(%rsp)
movsd  0xddd(%rip),%xmm0
movsd  0xddd(%rip),%xmm1
call   1060 <frand@plt>
movss  %xmm0,0x1c(%rsp)
lea    0x20(%rsp),%rbx
lea    0x10(%rsp),%r14
lea    0x8(%rsp),%rdx
mov    %rbx,%rdi
mov    %r14,%rsi
call   1070 <sse_dot@plt>
lea    0xc(%rsp),%rdx
mov    %rbx,%rdi
mov    %r14,%rsi
call   1030 <dot@plt>
movss  0xc(%rsp),%xmm0
movss  0x8(%rsp),%xmm1
movaps %xmm0,%xmm2
divss  %xmm1,%xmm2
cvtss2sd %xmm2,%xmm3
movsd  0xd91(%rip),%xmm2
subsd  %xmm3,%xmm2
mulsd  0xd8d(%rip),%xmm2
lea    0xd8e(%rip),%rdi
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x38,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [36 x i8] c"dot=%.3f, sse_dot=%.3f, err=%.3f%%\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [4 x float]
%3 = alloca [4 x float]
%4 = alloca float
%5 = alloca float
%6 = alloca i32
store i32 0, i32* %1
store i32 0, i32* %6
%7 = call i32 (...) @initfrand()
store i32 0, i32* %6
br label %8
8: ; preds = %20, %0
%9 = load i32, i32* %6
%10 = icmp slt i32 %9, 4
br i1 %10, label %11, label %23
11: ; preds = %8
%12 = call float @frand(double -1.000000e+03, double 1.000000e+03)
%13 = load i32, i32* %6
%14 = sext i32 %13 to i64
%15 = getelementptr inbounds [4 x float], [4 x float]* %2, i64 0, i64 %14
store float %12, float* %15
%16 = call float @frand(double -1.000000e+03, double 1.000000e+03)
%17 = load i32, i32* %6
%18 = sext i32 %17 to i64
%19 = getelementptr inbounds [4 x float], [4 x float]* %3, i64 0, i64 %18
store float %16, float* %19
br label %20
20: ; preds = %11
%21 = load i32, i32* %6
%22 = add nsw i32 %21, 1
store i32 %22, i32* %6
br label %8
23: ; preds = %8
%24 = getelementptr inbounds [4 x float], [4 x float]* %2, i64 0, i64 0
%25 = getelementptr inbounds [4 x float], [4 x float]* %3, i64 0, i64 0
%26 = call i32 @sse_dot(float* %24, float* %25, float* %5)
%27 = getelementptr inbounds [4 x float], [4 x float]* %2, i64 0, i64 0
%28 = getelementptr inbounds [4 x float], [4 x float]* %3, i64 0, i64 0
%29 = call i32 @dot(float* %27, float* %28, float* %4)
%30 = load float, float* %4
%31 = load float, float* %5
%32 = load float, float* %4
%33 = load float, float* %5
%34 = fdiv float %32, %33
%35 = fpext float %34 to double
%36 = fsub double 1.000000e+00, %35
%37 = fmul double 1.000000e+02, %36
%38 = call i32 @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str, i64 0, i64 0), float %30, float %31, double %37)
ret i32 0
}

LLVM IR (-O2):
@.str = [36 x i8] c"dot=%.3f, sse_dot=%.3f, err=%.3f%%\0A\00"
define i32 @main() {
%1 = alloca [4 x float]
%2 = alloca [4 x float]
%3 = alloca float
%4 = alloca float
%5 = bitcast [4 x float]* %1 to i8*
%6 = bitcast [4 x float]* %2 to i8*
%7 = bitcast float* %3 to i8*
%8 = bitcast float* %4 to i8*
%9 = tail call i32 (...) @initfrand()
%10 = tail call float @frand(double -1.000000e+03, double 1.000000e+03)
%11 = getelementptr inbounds [4 x float], [4 x float]* %1, i64 0, i64 0
store float %10, float* %11
%12 = tail call float @frand(double -1.000000e+03, double 1.000000e+03)
%13 = getelementptr inbounds [4 x float], [4 x float]* %2, i64 0, i64 0
store float %12, float* %13
%14 = tail call float @frand(double -1.000000e+03, double 1.000000e+03)
%15 = getelementptr inbounds [4 x float], [4 x float]* %1, i64 0, i64 1
store float %14, float* %15
%16 = tail call float @frand(double -1.000000e+03, double 1.000000e+03)
%17 = getelementptr inbounds [4 x float], [4 x float]* %2, i64 0, i64 1
store float %16, float* %17
%18 = tail call float @frand(double -1.000000e+03, double 1.000000e+03)
%19 = getelementptr inbounds [4 x float], [4 x float]* %1, i64 0, i64 2
store float %18, float* %19
%20 = tail call float @frand(double -1.000000e+03, double 1.000000e+03)
%21 = getelementptr inbounds [4 x float], [4 x float]* %2, i64 0, i64 2
store float %20, float* %21
%22 = tail call float @frand(double -1.000000e+03, double 1.000000e+03)
%23 = getelementptr inbounds [4 x float], [4 x float]* %1, i64 0, i64 3
store float %22, float* %23
%24 = tail call float @frand(double -1.000000e+03, double 1.000000e+03)
%25 = getelementptr inbounds [4 x float], [4 x float]* %2, i64 0, i64 3
store float %24, float* %25
%26 = call i32 @sse_dot(float* %11, float* %13, float* %4)
%27 = call i32 @dot(float* %11, float* %13, float* %3)
%28 = load float, float* %3
%29 = load float, float* %4
%30 = fdiv float %28, %29
%31 = fpext float %30 to double
%32 = fsub double 1.000000e+00, %31
%33 = fmul double %32, 1.000000e+02
%34 = call i32 @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str, i64 0, i64 0), float %28, float %29, double %33)
ret i32 0
}