#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 */
int SAXPY(int, int, int, int);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, double);
double omp_get_wtime();
int rand();
int /*<<< orphan*/ srand(int /*<<< orphan*/);
int /*<<< orphan*/ time(int /*<<< orphan*/ *);
int main() {
  int x[10000];
  double timer, start, end;
  int i, a, y;
  FILE *file;
  srand(time(NULL));
  a = rand() / 100;
  y = rand() / 100;
  for (i = 0; i < 10000; i++)
    x[i] = rand() % 100;
  file = fopen("/home/user/Labs/Semestr tasks/SAXPY/C/log_int.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>
mov    $0x64,%ecx
cltd
idiv   %ecx
mov    %eax,-0x9c70(%rbp)
mov    $0x0,%al
call   1090 <rand@plt>
mov    $0x64,%ecx
cltd
idiv   %ecx
mov    %eax,-0x9c74(%rbp)
movl   $0x0,-0x9c6c(%rbp)
cmpl   $0x2710,-0x9c6c(%rbp)
jge    1207 <main+0x97>
mov    $0x0,%al
call   1090 <rand@plt>
mov    $0x64,%ecx
cltd
idiv   %ecx
movslq -0x9c6c(%rbp),%rax
mov    %edx,-0x9c50(%rbp,%rax,4)
mov    -0x9c6c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x9c6c(%rbp)
jmp    11c6 <main+0x56>
lea    0xdf2(%rip),%rdi
lea    0xe1d(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x9c80(%rbp)
movl   $0x0,-0x9c6c(%rbp)
cmpl   $0x2710,-0x9c6c(%rbp)
jge    12cb <main+0x15b>
mov    $0x0,%al
call   1030 <omp_get_wtime@plt>
movsd  %xmm0,-0x9c60(%rbp)
ff
mov    -0x9c6c(%rbp),%edi
mov    -0x9c70(%rbp),%esi
movslq -0x9c6c(%rbp),%rax
mov    -0x9c50(%rbp,%rax,4),%edx
mov    -0x9c74(%rbp),%ecx
call   1080 <SAXPY@plt>
mov    %eax,-0x9c74(%rbp)
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    0xd82(%rip),%rsi
call   1050 <fprintf@plt>
mov    -0x9c6c(%rbp),%eax
add    $0x64,%eax
mov    %eax,-0x9c6c(%rbp)
jmp    122b <main+0xbb>
mov    -0x4(%rbp),%eax
add    $0x9c80,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x9c58,%rsp
xor    %edi,%edi
call   1060 <time@plt>
mov    %eax,%edi
call   1040 <srand@plt>
xor    %eax,%eax
call   1090 <rand@plt>
mov    %eax,%ebp
xor    %eax,%eax
call   1090 <rand@plt>
mov    %eax,%r15d
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
xor    %eax,%eax
call   1090 <rand@plt>
cltq
imul   $0x51eb851f,%rax,%rcx
mov    %rcx,%rdx
shr    $0x3f,%rdx
sar    $0x25,%rcx
add    %edx,%ecx
imul   $0x64,%ecx,%ecx
sub    %ecx,%eax
mov    %eax,0x10(%rsp,%rbx,4)
add    $0x1,%rbx
cmp    $0x2710,%rbx
jne    11b0 <main+0x40>
movslq %ebp,%rax
imul   $0x51eb851f,%rax,%r14
mov    %r14,%rax
shr    $0x3f,%rax
sar    $0x25,%r14
add    %eax,%r14d
movslq %r15d,%rax
imul   $0x51eb851f,%rax,%r13
mov    %r13,%rax
shr    $0x3f,%rax
sar    $0x25,%r13
add    %eax,%r13d
lea    0xde6(%rip),%rdi
lea    0xe11(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,%r15
lea    0xe04(%rip),%r12
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
xor    %eax,%eax
call   1030 <omp_get_wtime@plt>
movsd  %xmm0,0x8(%rsp)
mov    0x10(%rsp,%rbx,4),%edx
mov    %ebx,%edi
mov    %r14d,%esi
mov    %r13d,%ecx
call   1080 <SAXPY@plt>
mov    %eax,%r13d
xor    %eax,%eax
call   1030 <omp_get_wtime@plt>
subsd  0x8(%rsp),%xmm0
mov    %r15,%rdi
mov    %r12,%rsi
call   1050 <fprintf@plt>
lea    0x64(%rbx),%rax
cmp    $0x26ac,%rbx
mov    %rax,%rbx
jb     1240 <main+0xd0>
xor    %eax,%eax
add    $0x9c58,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [50 x i8] c"/home/user/Labs/Semestr tasks/SAXPY/C/log_int.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 i32]
%3 = alloca double
%4 = alloca double
%5 = alloca double
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32*
store i32 0, i32* %1
%10 = call i32 @time(i32* null)
%11 = call i32 @srand(i32 %10)
%12 = call i32 (...) @rand()
%13 = sdiv i32 %12, 100
store i32 %13, i32* %7
%14 = call i32 (...) @rand()
%15 = sdiv i32 %14, 100
store i32 %15, i32* %8
store i32 0, i32* %6
br label %16
16: ; preds = %25, %0
%17 = load i32, i32* %6
%18 = icmp slt i32 %17, 10000
br i1 %18, label %19, label %28
19: ; preds = %16
%20 = call i32 (...) @rand()
%21 = srem i32 %20, 100
%22 = load i32, i32* %6
%23 = sext i32 %22 to i64
%24 = getelementptr inbounds [10000 x i32], [10000 x i32]* %2, i64 0, i64 %23
store i32 %21, i32* %24
br label %25
25: ; preds = %19
%26 = load i32, i32* %6
%27 = add nsw i32 %26, 1
store i32 %27, i32* %6
br label %16
28: ; preds = %16
%29 = call i32* @fopen(i8* getelementptr inbounds ([50 x i8], [50 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %29, i32** %9
store i32 0, i32* %6
br label %30
30: ; preds = %50, %28
%31 = load i32, i32* %6
%32 = icmp slt i32 %31, 10000
br i1 %32, label %33, label %53
33: ; preds = %30
%34 = call double (...) @omp_get_wtime()
store double %34, double* %4
%35 = load i32, i32* %6
%36 = load i32, i32* %7
%37 = load i32, i32* %6
%38 = sext i32 %37 to i64
%39 = getelementptr inbounds [10000 x i32], [10000 x i32]* %2, i64 0, i64 %38
%40 = load i32, i32* %39
%41 = load i32, i32* %8
%42 = call i32 @SAXPY(i32 %35, i32 %36, i32 %40, i32 %41)
store i32 %42, i32* %8
%43 = call double (...) @omp_get_wtime()
store double %43, double* %5
%44 = load double, double* %5
%45 = load double, double* %4
%46 = fsub double %44, %45
store double %46, double* %3
%47 = load i32*, i32** %9
%48 = load double, double* %3
%49 = call i32 @fprintf(i32* %47, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), double %48)
br label %50
50: ; preds = %33
%51 = load i32, i32* %6
%52 = add nsw i32 %51, 100
store i32 %52, i32* %6
br label %30
53: ; preds = %30
%54 = load i32, i32* %1
ret i32 %54
}

LLVM IR (-O2):
@.str = [50 x i8] c"/home/user/Labs/Semestr tasks/SAXPY/C/log_int.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 i32]
%2 = bitcast [10000 x i32]* %1 to i8*
%3 = tail call i32 @time(i32* null)
%4 = tail call i32 @srand(i32 %3)
%5 = tail call i32 (...) @rand()
%6 = tail call i32 (...) @rand()
br label %7
7: ; preds = %0, %7
%8 = phi i64 [ 0, %0 ], [ %12, %7 ]
%9 = tail call i32 (...) @rand()
%10 = srem i32 %9, 100
%11 = getelementptr inbounds [10000 x i32], [10000 x i32]* %1, i64 0, i64 %8
store i32 %10, i32* %11
%12 = add nuw nsw i64 %8, 1
%13 = icmp eq i64 %12, 10000
br i1 %13, label %14, label %7
14: ; preds = %7
%15 = sdiv i32 %5, 100
%16 = sdiv i32 %6, 100
%17 = tail call i32* @fopen(i8* getelementptr inbounds ([50 x i8], [50 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
br label %18
18: ; preds = %14, %18
%19 = phi i64 [ 0, %14 ], [ %29, %18 ]
%20 = phi i32 [ %16, %14 ], [ %25, %18 ]
%21 = tail call double (...) @omp_get_wtime()
%22 = getelementptr inbounds [10000 x i32], [10000 x i32]* %1, i64 0, i64 %19
%23 = load i32, i32* %22
%24 = trunc i64 %19 to i32
%25 = tail call i32 @SAXPY(i32 %24, i32 %15, i32 %23, i32 %20)
%26 = tail call double (...) @omp_get_wtime()
%27 = fsub double %26, %21
%28 = tail call i32 @fprintf(i32* %17, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), double %27)
%29 = add nuw nsw i64 %19, 100
%30 = icmp ult i64 %19, 9900
br i1 %30, label %18, label %31
31: ; preds = %18
ret i32 0
}