#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 */
double omp_get_wtime();
int /*<<< orphan*/ printf(char *, double);
void Omp_mat_vect(double A[], double x[], double y[], int m, int n,
                  int thread_count) {
  int i, j;
  double start, finish, elapsed;
  start = omp_get_wtime();
#pragma omp parallel for num_threads(thread_count) default(none) private(i, j) \
    shared(A, x, y, m, n)
  for (i = 0; i < m; i++) {
    y[i] = 0.0;
    for (j = 0; j < n; j++)
      y[i] += A[i * n + j] * x[j];
  }
  finish = omp_get_wtime();
  elapsed = finish - start;
  printf("Elapsed time = %e seconds\n", elapsed);
}


x86 assembly (clang, -O0):
<Omp_mat_vect>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %ecx,-0x1c(%rbp)
mov    %r8d,-0x20(%rbp)
mov    %r9d,-0x24(%rbp)
mov    $0x0,%al
call   1030 <omp_get_wtime@plt>
movsd  %xmm0,-0x38(%rbp)
movl   $0x0,-0x28(%rbp)
mov    -0x28(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jge    11df <Omp_mat_vect+0xbf>
mov    -0x18(%rbp),%rax
movslq -0x28(%rbp),%rcx
xorps  %xmm0,%xmm0
movsd  %xmm0,(%rax,%rcx,8)
movl   $0x0,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
cmp    -0x20(%rbp),%eax
jge    11cc <Omp_mat_vect+0xac>
mov    -0x8(%rbp),%rax
mov    -0x28(%rbp),%ecx
imul   -0x20(%rbp),%ecx
add    -0x2c(%rbp),%ecx
movslq %ecx,%rcx
movsd  (%rax,%rcx,8),%xmm0
mov    -0x10(%rbp),%rax
movslq -0x2c(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm2
mov    -0x18(%rbp),%rax
movslq -0x28(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    1175 <Omp_mat_vect+0x55>
jmp    11d1 <Omp_mat_vect+0xb1>
mov    -0x28(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x28(%rbp)
jmp    1152 <Omp_mat_vect+0x32>
mov    $0x0,%al
call   1030 <omp_get_wtime@plt>
movsd  %xmm0,-0x40(%rbp)
movsd  -0x40(%rbp),%xmm0
subsd  -0x38(%rbp),%xmm0
movsd  %xmm0,-0x48(%rbp)
movsd  -0x48(%rbp),%xmm0
lea    0xdfa(%rip),%rdi
call   1040 <printf@plt>
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<Omp_mat_vect>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x10,%rsp
mov    %r8d,%r14d
mov    %ecx,%r12d
mov    %rdx,%rbx
mov    %rsi,%rbp
mov    %rdi,%r15
xor    %eax,%eax
call   1030 <omp_get_wtime@plt>
movsd  %xmm0,0x8(%rsp)
test   %r12d,%r12d
jle    11fc <Omp_mat_vect+0xdc>
movslq %r14d,%r8
mov    %r12d,%r10d
mov    %r8d,%r9d
mov    %r9d,%esi
and    $0xfffffffe,%esi
lea    0x8(%r15),%rdi
lea    0x0(,%r8,8),%r11
xor    %eax,%eax
jmp    1180 <Omp_mat_vect+0x60>
add    $0x1,%rax
add    %r11,%rdi
cmp    %r10,%rax
je     11fc <Omp_mat_vect+0xdc>
movq   $0x0,(%rbx,%rax,8)
test   %r14d,%r14d
jle    1170 <Omp_mat_vect+0x50>
xorpd  %xmm0,%xmm0
xor    %ecx,%ecx
cmp    $0x1,%r14d
je     11d2 <Omp_mat_vect+0xb2>
nopl   0x0(%rax)
movsd  -0x8(%rdi,%rcx,8),%xmm1
mulsd  0x0(%rbp,%rcx,8),%xmm1
addsd  %xmm0,%xmm1
movsd  %xmm1,(%rbx,%rax,8)
movsd  (%rdi,%rcx,8),%xmm0
mulsd  0x8(%rbp,%rcx,8),%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,(%rbx,%rax,8)
add    $0x2,%rcx
cmp    %rcx,%rsi
jne    11a0 <Omp_mat_vect+0x80>
test   $0x1,%r9b
je     1170 <Omp_mat_vect+0x50>
mov    %rax,%rdx
imul   %r8,%rdx
add    %rcx,%rdx
movsd  (%r15,%rdx,8),%xmm1
mulsd  0x0(%rbp,%rcx,8),%xmm1
addsd  %xmm0,%xmm1
movsd  %xmm1,(%rbx,%rax,8)
jmp    1170 <Omp_mat_vect+0x50>
xor    %eax,%eax
call   1030 <omp_get_wtime@plt>
subsd  0x8(%rsp),%xmm0
lea    0xdf0(%rip),%rdi
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
jmp    1040 <printf@plt>

LLVM IR (-O0):
@.str = [27 x i8] c"Elapsed time = %e seconds\0A\00"
define void @Omp_mat_vect(double* %0, double* %1, double* %2, i32 %3, i32 %4, i32 %5) {
%7 = alloca double*
%8 = alloca double*
%9 = alloca double*
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32
%14 = alloca i32
%15 = alloca double
%16 = alloca double
%17 = alloca double
store double* %0, double** %7
store double* %1, double** %8
store double* %2, double** %9
store i32 %3, i32* %10
store i32 %4, i32* %11
store i32 %5, i32* %12
%18 = call double (...) @omp_get_wtime()
store double %18, double* %15
store i32 0, i32* %13
br label %19
19: ; preds = %57, %6
%20 = load i32, i32* %13
%21 = load i32, i32* %10
%22 = icmp slt i32 %20, %21
br i1 %22, label %23, label %60
23: ; preds = %19
%24 = load double*, double** %9
%25 = load i32, i32* %13
%26 = sext i32 %25 to i64
%27 = getelementptr inbounds double, double* %24, i64 %26
store double 0.000000e+00, double* %27
store i32 0, i32* %14
br label %28
28: ; preds = %53, %23
%29 = load i32, i32* %14
%30 = load i32, i32* %11
%31 = icmp slt i32 %29, %30
br i1 %31, label %32, label %56
32: ; preds = %28
%33 = load double*, double** %7
%34 = load i32, i32* %13
%35 = load i32, i32* %11
%36 = mul nsw i32 %34, %35
%37 = load i32, i32* %14
%38 = add nsw i32 %36, %37
%39 = sext i32 %38 to i64
%40 = getelementptr inbounds double, double* %33, i64 %39
%41 = load double, double* %40
%42 = load double*, double** %8
%43 = load i32, i32* %14
%44 = sext i32 %43 to i64
%45 = getelementptr inbounds double, double* %42, i64 %44
%46 = load double, double* %45
%47 = load double*, double** %9
%48 = load i32, i32* %13
%49 = sext i32 %48 to i64
%50 = getelementptr inbounds double, double* %47, i64 %49
%51 = load double, double* %50
%52 = call double @llvm.fmuladd.f64(double %41, double %46, double %51)
store double %52, double* %50
br label %53
53: ; preds = %32
%54 = load i32, i32* %14
%55 = add nsw i32 %54, 1
store i32 %55, i32* %14
br label %28
56: ; preds = %28
br label %57
57: ; preds = %56
%58 = load i32, i32* %13
%59 = add nsw i32 %58, 1
store i32 %59, i32* %13
br label %19
60: ; preds = %19
%61 = call double (...) @omp_get_wtime()
store double %61, double* %16
%62 = load double, double* %16
%63 = load double, double* %15
%64 = fsub double %62, %63
store double %64, double* %17
%65 = load double, double* %17
%66 = call i32 @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0), double %65)
ret void
}

LLVM IR (-O2):
@.str = [27 x i8] c"Elapsed time = %e seconds\0A\00"
define void @Omp_mat_vect(double* nocapture %0, double* nocapture %1, double* nocapture %2, i32 %3, i32 %4, i32 %5) {
%7 = tail call double (...) @omp_get_wtime()
%8 = icmp sgt i32 %3, 0
br i1 %8, label %9, label %56
9: ; preds = %6
%10 = icmp sgt i32 %4, 0
%11 = sext i32 %4 to i64
%12 = zext i32 %3 to i64
%13 = zext i32 %4 to i64
%14 = and i64 %13, 1
%15 = icmp eq i32 %4, 1
%16 = and i64 %13, 4294967294
%17 = icmp eq i64 %14, 0
br label %18
18: ; preds = %9, %53
%19 = phi i64 [ 0, %9 ], [ %54, %53 ]
%20 = getelementptr inbounds double, double* %2, i64 %19
store double 0.000000e+00, double* %20
br i1 %10, label %21, label %53
21: ; preds = %18
%22 = mul nsw i64 %19, %11
br i1 %15, label %43, label %23
23: ; preds = %21, %23
%24 = phi double [ %39, %23 ], [ 0.000000e+00, %21 ]
%25 = phi i64 [ %40, %23 ], [ 0, %21 ]
%26 = phi i64 [ %41, %23 ], [ 0, %21 ]
%27 = add nsw i64 %25, %22
%28 = getelementptr inbounds double, double* %0, i64 %27
%29 = load double, double* %28
%30 = getelementptr inbounds double, double* %1, i64 %25
%31 = load double, double* %30
%32 = tail call double @llvm.fmuladd.f64(double %29, double %31, double %24)
store double %32, double* %20
%33 = or i64 %25, 1
%34 = add nsw i64 %33, %22
%35 = getelementptr inbounds double, double* %0, i64 %34
%36 = load double, double* %35
%37 = getelementptr inbounds double, double* %1, i64 %33
%38 = load double, double* %37
%39 = tail call double @llvm.fmuladd.f64(double %36, double %38, double %32)
store double %39, double* %20
%40 = add nuw nsw i64 %25, 2
%41 = add i64 %26, 2
%42 = icmp eq i64 %41, %16
br i1 %42, label %43, label %23
43: ; preds = %23, %21
%44 = phi double [ 0.000000e+00, %21 ], [ %39, %23 ]
%45 = phi i64 [ 0, %21 ], [ %40, %23 ]
br i1 %17, label %53, label %46
46: ; preds = %43
%47 = add nsw i64 %45, %22
%48 = getelementptr inbounds double, double* %0, i64 %47
%49 = load double, double* %48
%50 = getelementptr inbounds double, double* %1, i64 %45
%51 = load double, double* %50
%52 = tail call double @llvm.fmuladd.f64(double %49, double %51, double %44)
store double %52, double* %20
br label %53
53: ; preds = %46, %43, %18
%54 = add nuw nsw i64 %19, 1
%55 = icmp eq i64 %54, %12
br i1 %55, label %56, label %18
56: ; preds = %53, %6
%57 = tail call double (...) @omp_get_wtime()
%58 = fsub double %57, %7
%59 = tail call i32 @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0), double %58)
ret void
}