#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 */
double RAND_MAX;
double SAXPY(int, double, double, double);
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() {
  double x[10000];
  double timer, start, end;
  int i;
  double a, y;
  FILE *file;
  srand(time(NULL));
  a = (double)rand() / RAND_MAX * (double)50.0;
  y = (double)rand() / RAND_MAX * (double)50.0;
  for (i = 0; i < 10000; i++)
    x[i] = (double)rand() / RAND_MAX * (double)100.0;
  file = fopen("/home/user/Labs/Semestr tasks/SAXPY/C/log_double.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    $0x138d0,%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>
cvtsi2sd %rax,%xmm0
mov    0x2e43(%rip),%rax
divsd  (%rax),%xmm0
movsd  0xe4f(%rip),%xmm1
mulsd  %xmm1,%xmm0
movsd  %xmm0,-0x138b8(%rbp)
ff
mov    $0x0,%al
call   1090 <rand@plt>
cvtsi2sd %rax,%xmm0
mov    0x2e18(%rip),%rax
divsd  (%rax),%xmm0
movsd  0xe24(%rip),%xmm1
mulsd  %xmm1,%xmm0
movsd  %xmm0,-0x138c0(%rbp)
ff
movl   $0x0,-0x138ac(%rbp)
cmpl   $0x2710,-0x138ac(%rbp)
jge    1249 <main+0xd9>
mov    $0x0,%al
call   1090 <rand@plt>
cvtsi2sd %rax,%xmm0
mov    0x2dd3(%rip),%rax
divsd  (%rax),%xmm0
movsd  0xde7(%rip),%xmm1
mulsd  %xmm1,%xmm0
movslq -0x138ac(%rbp),%rax
movsd  %xmm0,-0x13890(%rbp,%rax,8)
fe ff
mov    -0x138ac(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x138ac(%rbp)
jmp    11f2 <main+0x82>
lea    0xdc0(%rip),%rdi
lea    0xdee(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x138c8(%rbp)
movl   $0x0,-0x138ac(%rbp)
cmpl   $0x2710,-0x138ac(%rbp)
jge    1315 <main+0x1a5>
mov    $0x0,%al
call   1030 <omp_get_wtime@plt>
movsd  %xmm0,-0x138a0(%rbp)
ff
mov    -0x138ac(%rbp),%edi
movsd  -0x138b8(%rbp),%xmm0
ff
movslq -0x138ac(%rbp),%rax
movsd  -0x13890(%rbp,%rax,8),%xmm1
fe ff
movsd  -0x138c0(%rbp),%xmm2
ff
call   1080 <SAXPY@plt>
movsd  %xmm0,-0x138c0(%rbp)
ff
mov    $0x0,%al
call   1030 <omp_get_wtime@plt>
movsd  %xmm0,-0x138a8(%rbp)
ff
movsd  -0x138a8(%rbp),%xmm0
ff
subsd  -0x138a0(%rbp),%xmm0
ff
movsd  %xmm0,-0x13898(%rbp)
ff
mov    -0x138c8(%rbp),%rdi
movsd  -0x13898(%rbp),%xmm0
ff
lea    0xd4b(%rip),%rsi
call   1050 <fprintf@plt>
mov    -0x138ac(%rbp),%eax
add    $0x64,%eax
mov    %eax,-0x138ac(%rbp)
jmp    126d <main+0xfd>
mov    -0x4(%rbp),%eax
add    $0x138d0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
sub    $0x138a0,%rsp
xor    %edi,%edi
call   1060 <time@plt>
mov    %eax,%edi
call   1040 <srand@plt>
xor    %eax,%eax
call   1090 <rand@plt>
cvtsi2sd %rax,%xmm0
mov    0x2e4b(%rip),%r14
divsd  (%r14),%xmm0
movsd  %xmm0,0x10(%rsp)
xor    %eax,%eax
call   1090 <rand@plt>
xorps  %xmm0,%xmm0
cvtsi2sd %rax,%xmm0
divsd  (%r14),%xmm0
movsd  %xmm0,0x8(%rsp)
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
xor    %eax,%eax
call   1090 <rand@plt>
xorps  %xmm0,%xmm0
cvtsi2sd %rax,%xmm0
divsd  (%r14),%xmm0
mulsd  0xe14(%rip),%xmm0
movsd  %xmm0,0x20(%rsp,%rbx,8)
add    $0x1,%rbx
cmp    $0x2710,%rbx
jne    11d0 <main+0x60>
movsd  0xe01(%rip),%xmm0
movsd  0x10(%rsp),%xmm1
mulsd  %xmm0,%xmm1
movsd  %xmm1,0x10(%rsp)
movsd  0x8(%rsp),%xmm1
mulsd  %xmm0,%xmm1
movsd  %xmm1,0x8(%rsp)
lea    0xde2(%rip),%rdi
lea    0xe10(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,%r15
lea    0xe03(%rip),%r14
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
xor    %eax,%eax
call   1030 <omp_get_wtime@plt>
movsd  %xmm0,0x18(%rsp)
movsd  0x20(%rsp,%rbx,8),%xmm1
mov    %ebx,%edi
movsd  0x10(%rsp),%xmm0
movsd  0x8(%rsp),%xmm2
call   1080 <SAXPY@plt>
movsd  %xmm0,0x8(%rsp)
xor    %eax,%eax
call   1030 <omp_get_wtime@plt>
subsd  0x18(%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    $0x138a0,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@RAND_MAX = global double 0.000000e+00
@.str = [53 x i8] c"/home/user/Labs/Semestr tasks/SAXPY/C/log_double.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 double]
%3 = alloca double
%4 = alloca double
%5 = alloca double
%6 = alloca i32
%7 = alloca double
%8 = alloca double
%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 double
%14 = load double, double* @RAND_MAX
%15 = fdiv double %13, %14
%16 = fmul double %15, 5.000000e+01
store double %16, double* %7
%17 = call i64 (...) @rand()
%18 = sitofp i64 %17 to double
%19 = load double, double* @RAND_MAX
%20 = fdiv double %18, %19
%21 = fmul double %20, 5.000000e+01
store double %21, double* %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 double
%28 = load double, double* @RAND_MAX
%29 = fdiv double %27, %28
%30 = fmul double %29, 1.000000e+02
%31 = load i32, i32* %6
%32 = sext i32 %31 to i64
%33 = getelementptr inbounds [10000 x double], [10000 x double]* %2, i64 0, i64 %32
store double %30, double* %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 ([53 x i8], [53 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 double, double* %7
%46 = load i32, i32* %6
%47 = sext i32 %46 to i64
%48 = getelementptr inbounds [10000 x double], [10000 x double]* %2, i64 0, i64 %47
%49 = load double, double* %48
%50 = load double, double* %8
%51 = call double @SAXPY(i32 %44, double %45, double %49, double %50)
store double %51, double* %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 double 0.000000e+00
@.str = [53 x i8] c"/home/user/Labs/Semestr tasks/SAXPY/C/log_double.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 double]
%2 = bitcast [10000 x double]* %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 double
%7 = load double, double* @RAND_MAX
%8 = fdiv double %6, %7
%9 = tail call i64 (...) @rand()
%10 = sitofp i64 %9 to double
%11 = load double, double* @RAND_MAX
%12 = fdiv double %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 double
%17 = load double, double* @RAND_MAX
%18 = fdiv double %16, %17
%19 = fmul double %18, 1.000000e+02
%20 = getelementptr inbounds [10000 x double], [10000 x double]* %1, i64 0, i64 %14
store double %19, double* %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 double %8, 5.000000e+01
%25 = fmul double %12, 5.000000e+01
%26 = tail call i32* @fopen(i8* getelementptr inbounds ([53 x i8], [53 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 double [ %25, %23 ], [ %34, %27 ]
%30 = tail call double (...) @omp_get_wtime()
%31 = getelementptr inbounds [10000 x double], [10000 x double]* %1, i64 0, i64 %28
%32 = load double, double* %31
%33 = trunc i64 %28 to i32
%34 = tail call double @SAXPY(i32 %33, double %24, double %32, double %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
}