#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 /*<<< orphan*/ FILE;

/* Variables and functions */
float RAND_MAX;
float SAXPY(int, float, float, float);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, double);
double omp_get_wtime();
scalar_t__ rand();
int /*<<< orphan*/ srand(int /*<<< orphan*/);
int /*<<< orphan*/ time(int /*<<< orphan*/ *);
int main() {
  float x[10000];
  double timer, start, end;
  int i;
  float a, y;
  FILE *file;
  srand(time(NULL));
  a = (float)rand() / RAND_MAX * (float)50.0;
  y = (float)rand() / RAND_MAX * (float)50.0;
  for (i = 0; i < 10000; i++)
    x[i] = (float)rand() / RAND_MAX * (float)100.0;
  file = fopen("/home/user/Labs/Semestr tasks/SAXPY/C/log_float.txt", "w");
  for (i = 0; i < 10000; i += 100) {
    start = omp_get_wtime();
    y = SAXPY(i, a, x[i], y);
    end = omp_get_wtime();
    timer = end - start;
    fprintf(file, "%lf\n", timer);
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x9c80,%rsp
movl   $0x0,-0x4(%rbp)
xor    %eax,%eax
mov    %eax,%edi
call   1060 <time@plt>
mov    %eax,%edi
call   1040 <srand@plt>
mov    $0x0,%al
call   1090 <rand@plt>
cvtsi2ss %rax,%xmm0
mov    0x2e43(%rip),%rax
divss  (%rax),%xmm0
movss  0xe4f(%rip),%xmm1
mulss  %xmm1,%xmm0
movss  %xmm0,-0x9c70(%rbp)
ff
mov    $0x0,%al
call   1090 <rand@plt>
cvtsi2ss %rax,%xmm0
mov    0x2e18(%rip),%rax
divss  (%rax),%xmm0
movss  0xe24(%rip),%xmm1
mulss  %xmm1,%xmm0
movss  %xmm0,-0x9c74(%rbp)
ff
movl   $0x0,-0x9c6c(%rbp)
cmpl   $0x2710,-0x9c6c(%rbp)
jge    1249 <main+0xd9>
mov    $0x0,%al
call   1090 <rand@plt>
cvtsi2ss %rax,%xmm0
mov    0x2dd3(%rip),%rax
divss  (%rax),%xmm0
movss  0xde3(%rip),%xmm1
mulss  %xmm1,%xmm0
movslq -0x9c6c(%rbp),%rax
movss  %xmm0,-0x9c50(%rbp,%rax,4)
ff ff
mov    -0x9c6c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x9c6c(%rbp)
jmp    11f2 <main+0x82>
lea    0xdb8(%rip),%rdi
lea    0xde5(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x9c80(%rbp)
movl   $0x0,-0x9c6c(%rbp)
cmpl   $0x2710,-0x9c6c(%rbp)
jge    1315 <main+0x1a5>
mov    $0x0,%al
call   1030 <omp_get_wtime@plt>
movsd  %xmm0,-0x9c60(%rbp)
ff
mov    -0x9c6c(%rbp),%edi
movss  -0x9c70(%rbp),%xmm0
ff
movslq -0x9c6c(%rbp),%rax
movss  -0x9c50(%rbp,%rax,4),%xmm1
ff ff
movss  -0x9c74(%rbp),%xmm2
ff
call   1080 <SAXPY@plt>
movss  %xmm0,-0x9c74(%rbp)
ff
mov    $0x0,%al
call   1030 <omp_get_wtime@plt>
movsd  %xmm0,-0x9c68(%rbp)
ff
movsd  -0x9c68(%rbp),%xmm0
ff
subsd  -0x9c60(%rbp),%xmm0
ff
movsd  %xmm0,-0x9c58(%rbp)
ff
mov    -0x9c80(%rbp),%rdi
movsd  -0x9c58(%rbp),%xmm0
ff
lea    0xd42(%rip),%rsi
call   1050 <fprintf@plt>
mov    -0x9c6c(%rbp),%eax
add    $0x64,%eax
mov    %eax,-0x9c6c(%rbp)
jmp    126d <main+0xfd>
mov    -0x4(%rbp),%eax
add    $0x9c80,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
sub    $0x9c50,%rsp
xor    %edi,%edi
call   1060 <time@plt>
mov    %eax,%edi
call   1040 <srand@plt>
xor    %eax,%eax
call   1090 <rand@plt>
cvtsi2ss %rax,%xmm0
mov    0x2e4b(%rip),%r14
divss  (%r14),%xmm0
movss  %xmm0,0x4(%rsp)
xor    %eax,%eax
call   1090 <rand@plt>
xorps  %xmm0,%xmm0
cvtsi2ss %rax,%xmm0
divss  (%r14),%xmm0
movss  %xmm0,(%rsp)
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
xor    %eax,%eax
call   1090 <rand@plt>
xorps  %xmm0,%xmm0
cvtsi2ss %rax,%xmm0
divss  (%r14),%xmm0
mulss  0xe14(%rip),%xmm0
movss  %xmm0,0x10(%rsp,%rbx,4)
add    $0x1,%rbx
cmp    $0x2710,%rbx
jne    11d0 <main+0x60>
movss  0xdfd(%rip),%xmm0
movss  0x4(%rsp),%xmm1
mulss  %xmm0,%xmm1
movss  %xmm1,0x4(%rsp)
movss  (%rsp),%xmm1
mulss  %xmm0,%xmm1
movss  %xmm1,(%rsp)
lea    0xddc(%rip),%rdi
lea    0xe09(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,%r15
lea    0xdfc(%rip),%r14
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
xor    %eax,%eax
call   1030 <omp_get_wtime@plt>
movsd  %xmm0,0x8(%rsp)
movss  0x10(%rsp,%rbx,4),%xmm1
mov    %ebx,%edi
movss  0x4(%rsp),%xmm0
movss  (%rsp),%xmm2
call   1080 <SAXPY@plt>
movss  %xmm0,(%rsp)
xor    %eax,%eax
call   1030 <omp_get_wtime@plt>
subsd  0x8(%rsp),%xmm0
mov    %r15,%rdi
mov    %r14,%rsi
call   1050 <fprintf@plt>
lea    0x64(%rbx),%rax
cmp    $0x26ac,%rbx
mov    %rax,%rbx
jb     1250 <main+0xe0>
xor    %eax,%eax
add    $0x9c50,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@RAND_MAX = global float 0.000000e+00
@.str = [52 x i8] c"/home/user/Labs/Semestr tasks/SAXPY/C/log_float.txt\00"
@.str.1 = [2 x i8] c"w\00"
@.str.2 = [5 x i8] c"%lf\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [10000 x float]
%3 = alloca double
%4 = alloca double
%5 = alloca double
%6 = alloca i32
%7 = alloca float
%8 = alloca float
%9 = alloca i32*
store i32 0, i32* %1
%10 = call i32 @time(i32* null)
%11 = call i32 @srand(i32 %10)
%12 = call i64 (...) @rand()
%13 = sitofp i64 %12 to float
%14 = load float, float* @RAND_MAX
%15 = fdiv float %13, %14
%16 = fmul float %15, 5.000000e+01
store float %16, float* %7
%17 = call i64 (...) @rand()
%18 = sitofp i64 %17 to float
%19 = load float, float* @RAND_MAX
%20 = fdiv float %18, %19
%21 = fmul float %20, 5.000000e+01
store float %21, float* %8
store i32 0, i32* %6
br label %22
22: ; preds = %34, %0
%23 = load i32, i32* %6
%24 = icmp slt i32 %23, 10000
br i1 %24, label %25, label %37
25: ; preds = %22
%26 = call i64 (...) @rand()
%27 = sitofp i64 %26 to float
%28 = load float, float* @RAND_MAX
%29 = fdiv float %27, %28
%30 = fmul float %29, 1.000000e+02
%31 = load i32, i32* %6
%32 = sext i32 %31 to i64
%33 = getelementptr inbounds [10000 x float], [10000 x float]* %2, i64 0, i64 %32
store float %30, float* %33
br label %34
34: ; preds = %25
%35 = load i32, i32* %6
%36 = add nsw i32 %35, 1
store i32 %36, i32* %6
br label %22
37: ; preds = %22
%38 = call i32* @fopen(i8* getelementptr inbounds ([52 x i8], [52 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %38, i32** %9
store i32 0, i32* %6
br label %39
39: ; preds = %59, %37
%40 = load i32, i32* %6
%41 = icmp slt i32 %40, 10000
br i1 %41, label %42, label %62
42: ; preds = %39
%43 = call double (...) @omp_get_wtime()
store double %43, double* %4
%44 = load i32, i32* %6
%45 = load float, float* %7
%46 = load i32, i32* %6
%47 = sext i32 %46 to i64
%48 = getelementptr inbounds [10000 x float], [10000 x float]* %2, i64 0, i64 %47
%49 = load float, float* %48
%50 = load float, float* %8
%51 = call float @SAXPY(i32 %44, float %45, float %49, float %50)
store float %51, float* %8
%52 = call double (...) @omp_get_wtime()
store double %52, double* %5
%53 = load double, double* %5
%54 = load double, double* %4
%55 = fsub double %53, %54
store double %55, double* %3
%56 = load i32*, i32** %9
%57 = load double, double* %3
%58 = call i32 @fprintf(i32* %56, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), double %57)
br label %59
59: ; preds = %42
%60 = load i32, i32* %6
%61 = add nsw i32 %60, 100
store i32 %61, i32* %6
br label %39
62: ; preds = %39
%63 = load i32, i32* %1
ret i32 %63
}

LLVM IR (-O2):
@RAND_MAX = global float 0.000000e+00
@.str = [52 x i8] c"/home/user/Labs/Semestr tasks/SAXPY/C/log_float.txt\00"
@.str.1 = [2 x i8] c"w\00"
@.str.2 = [5 x i8] c"%lf\0A\00"
define i32 @main() {
%1 = alloca [10000 x float]
%2 = bitcast [10000 x float]* %1 to i8*
%3 = tail call i32 @time(i32* null)
%4 = tail call i32 @srand(i32 %3)
%5 = tail call i64 (...) @rand()
%6 = sitofp i64 %5 to float
%7 = load float, float* @RAND_MAX
%8 = fdiv float %6, %7
%9 = tail call i64 (...) @rand()
%10 = sitofp i64 %9 to float
%11 = load float, float* @RAND_MAX
%12 = fdiv float %10, %11
br label %13
13: ; preds = %0, %13
%14 = phi i64 [ 0, %0 ], [ %21, %13 ]
%15 = tail call i64 (...) @rand()
%16 = sitofp i64 %15 to float
%17 = load float, float* @RAND_MAX
%18 = fdiv float %16, %17
%19 = fmul float %18, 1.000000e+02
%20 = getelementptr inbounds [10000 x float], [10000 x float]* %1, i64 0, i64 %14
store float %19, float* %20
%21 = add nuw nsw i64 %14, 1
%22 = icmp eq i64 %21, 10000
br i1 %22, label %23, label %13
23: ; preds = %13
%24 = fmul float %8, 5.000000e+01
%25 = fmul float %12, 5.000000e+01
%26 = tail call i32* @fopen(i8* getelementptr inbounds ([52 x i8], [52 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
br label %27
27: ; preds = %23, %27
%28 = phi i64 [ 0, %23 ], [ %38, %27 ]
%29 = phi float [ %25, %23 ], [ %34, %27 ]
%30 = tail call double (...) @omp_get_wtime()
%31 = getelementptr inbounds [10000 x float], [10000 x float]* %1, i64 0, i64 %28
%32 = load float, float* %31
%33 = trunc i64 %28 to i32
%34 = tail call float @SAXPY(i32 %33, float %24, float %32, float %29)
%35 = tail call double (...) @omp_get_wtime()
%36 = fsub double %35, %30
%37 = tail call i32 @fprintf(i32* %26, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), double %36)
%38 = add nuw nsw i64 %28, 100
%39 = icmp ult i64 %28, 9900
br i1 %39, label %27, label %40
40: ; preds = %27
ret i32 0
}