#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*/ cg_daxpy0(double *, double *, double, int);
double cg_dot0(double *, double *, int);
int /*<<< orphan*/ cg_scale0(double *, double *, double, int);
void cg_matvec(double *y, double *A, double *x, int n, long int m, int w) {
  long int j, l;
  l = 0;
  if (w) {
    cg_scale0(y, A, x[0], (int)m);
    for (j = 1; j < n; j++) {
      l += m;
      cg_daxpy0(y, A + l, x[j], (int)m);
    }
  } else {
    for (j = 0; j < n; j++) {
      y[j] = cg_dot0(A + l, x, (int)m);
      l += m;
    }
  }
  return;
}


x86 assembly (clang, -O0):
<cg_matvec>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %ecx,-0x1c(%rbp)
mov    %r8,-0x28(%rbp)
mov    %r9d,-0x2c(%rbp)
movq   $0x0,-0x40(%rbp)
cmpl   $0x0,-0x2c(%rbp)
je     11e2 <cg_matvec+0xb2>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rax
movsd  (%rax),%xmm0
mov    -0x28(%rbp),%rax
mov    %eax,%edx
call   1050 <cg_scale0@plt>
movq   $0x1,-0x38(%rbp)
mov    -0x38(%rbp),%rax
movslq -0x1c(%rbp),%rcx
cmp    %rcx,%rax
jge    11dd <cg_matvec+0xad>
mov    -0x28(%rbp),%rax
add    -0x40(%rbp),%rax
mov    %rax,-0x40(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x40(%rbp),%rax
shl    $0x3,%rax
add    %rax,%rsi
mov    -0x18(%rbp),%rax
mov    -0x38(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
mov    -0x28(%rbp),%rax
mov    %eax,%edx
call   1030 <cg_daxpy0@plt>
mov    -0x38(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x38(%rbp)
jmp    1184 <cg_matvec+0x54>
jmp    1248 <cg_matvec+0x118>
movq   $0x0,-0x38(%rbp)
mov    -0x38(%rbp),%rax
movslq -0x1c(%rbp),%rcx
cmp    %rcx,%rax
jge    1243 <cg_matvec+0x113>
mov    -0x10(%rbp),%rdi
mov    -0x40(%rbp),%rax
shl    $0x3,%rax
add    %rax,%rdi
mov    -0x18(%rbp),%rsi
mov    -0x28(%rbp),%rax
mov    %eax,%edx
call   1040 <cg_dot0@plt>
mov    -0x8(%rbp),%rax
mov    -0x38(%rbp),%rcx
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x28(%rbp),%rax
add    -0x40(%rbp),%rax
mov    %rax,-0x40(%rbp)
mov    -0x38(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x38(%rbp)
jmp    11ea <cg_matvec+0xba>
jmp    1248 <cg_matvec+0x118>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<cg_matvec>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %r8,%r12
mov    %ecx,%ebp
mov    %rsi,%rbx
mov    %rdi,%r15
test   %r9d,%r9d
je     11a6 <cg_matvec+0x76>
movsd  (%rdx),%xmm0
mov    %r15,%rdi
mov    %rbx,%rsi
mov    %rdx,(%rsp)
mov    %r12d,%edx
call   1050 <cg_scale0@plt>
cmp    $0x2,%ebp
jl     11e1 <cg_matvec+0xb1>
movslq %ebp,%r13
lea    (%rbx,%r12,8),%rbx
mov    %r12,%rbp
shl    $0x3,%rbp
mov    $0x1,%r14d
nopw   0x0(%rax,%rax,1)
mov    (%rsp),%rax
movsd  (%rax,%r14,8),%xmm0
mov    %r15,%rdi
mov    %rbx,%rsi
mov    %r12d,%edx
call   1030 <cg_daxpy0@plt>
add    $0x1,%r14
add    %rbp,%rbx
cmp    %r14,%r13
jne    1180 <cg_matvec+0x50>
jmp    11e1 <cg_matvec+0xb1>
test   %ebp,%ebp
jle    11e1 <cg_matvec+0xb1>
mov    %rdx,%r14
movslq %ebp,%rax
mov    %rax,(%rsp)
mov    %r12,%rbp
shl    $0x3,%rbp
xor    %r13d,%r13d
xchg   %ax,%ax
mov    %rbx,%rdi
mov    %r14,%rsi
mov    %r12d,%edx
call   1040 <cg_dot0@plt>
movsd  %xmm0,(%r15,%r13,8)
add    $0x1,%r13
add    %rbp,%rbx
cmp    %r13,(%rsp)
jne    11c0 <cg_matvec+0x90>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define void @cg_matvec(double* %0, double* %1, double* %2, i32 %3, i64 %4, i32 %5) {
%7 = alloca double*
%8 = alloca double*
%9 = alloca double*
%10 = alloca i32
%11 = alloca i64
%12 = alloca i32
%13 = alloca i64
%14 = alloca i64
store double* %0, double** %7
store double* %1, double** %8
store double* %2, double** %9
store i32 %3, i32* %10
store i64 %4, i64* %11
store i32 %5, i32* %12
store i64 0, i64* %14
%15 = load i32, i32* %12
%16 = icmp ne i32 %15, 0
br i1 %16, label %17, label %50
17: ; preds = %6
%18 = load double*, double** %7
%19 = load double*, double** %8
%20 = load double*, double** %9
%21 = getelementptr inbounds double, double* %20, i64 0
%22 = load double, double* %21
%23 = load i64, i64* %11
%24 = trunc i64 %23 to i32
%25 = call i32 @cg_scale0(double* %18, double* %19, double %22, i32 %24)
store i64 1, i64* %13
br label %26
26: ; preds = %46, %17
%27 = load i64, i64* %13
%28 = load i32, i32* %10
%29 = sext i32 %28 to i64
%30 = icmp slt i64 %27, %29
br i1 %30, label %31, label %49
31: ; preds = %26
%32 = load i64, i64* %11
%33 = load i64, i64* %14
%34 = add nsw i64 %33, %32
store i64 %34, i64* %14
%35 = load double*, double** %7
%36 = load double*, double** %8
%37 = load i64, i64* %14
%38 = getelementptr inbounds double, double* %36, i64 %37
%39 = load double*, double** %9
%40 = load i64, i64* %13
%41 = getelementptr inbounds double, double* %39, i64 %40
%42 = load double, double* %41
%43 = load i64, i64* %11
%44 = trunc i64 %43 to i32
%45 = call i32 @cg_daxpy0(double* %35, double* %38, double %42, i32 %44)
br label %46
46: ; preds = %31
%47 = load i64, i64* %13
%48 = add nsw i64 %47, 1
store i64 %48, i64* %13
br label %26
49: ; preds = %26
br label %74
50: ; preds = %6
store i64 0, i64* %13
br label %51
51: ; preds = %70, %50
%52 = load i64, i64* %13
%53 = load i32, i32* %10
%54 = sext i32 %53 to i64
%55 = icmp slt i64 %52, %54
br i1 %55, label %56, label %73
56: ; preds = %51
%57 = load double*, double** %8
%58 = load i64, i64* %14
%59 = getelementptr inbounds double, double* %57, i64 %58
%60 = load double*, double** %9
%61 = load i64, i64* %11
%62 = trunc i64 %61 to i32
%63 = call double @cg_dot0(double* %59, double* %60, i32 %62)
%64 = load double*, double** %7
%65 = load i64, i64* %13
%66 = getelementptr inbounds double, double* %64, i64 %65
store double %63, double* %66
%67 = load i64, i64* %11
%68 = load i64, i64* %14
%69 = add nsw i64 %68, %67
store i64 %69, i64* %14
br label %70
70: ; preds = %56
%71 = load i64, i64* %13
%72 = add nsw i64 %71, 1
store i64 %72, i64* %13
br label %51
73: ; preds = %51
br label %74
74: ; preds = %73, %49
ret void
}

LLVM IR (-O2):
define void @cg_matvec(double* %0, double* %1, double* %2, i32 %3, i64 %4, i32 %5) {
%7 = icmp eq i32 %5, 0
br i1 %7, label %8, label %13
8: ; preds = %6
%9 = sext i32 %3 to i64
%10 = icmp sgt i32 %3, 0
br i1 %10, label %11, label %38
11: ; preds = %8
%12 = trunc i64 %4 to i32
br label %29
13: ; preds = %6
%14 = load double, double* %2
%15 = trunc i64 %4 to i32
%16 = tail call i32 @cg_scale0(double* %0, double* %1, double %14, i32 %15)
%17 = sext i32 %3 to i64
%18 = icmp sgt i32 %3, 1
br i1 %18, label %19, label %38
19: ; preds = %13, %19
%20 = phi i64 [ %22, %19 ], [ 0, %13 ]
%21 = phi i64 [ %27, %19 ], [ 1, %13 ]
%22 = add nsw i64 %20, %4
%23 = getelementptr inbounds double, double* %1, i64 %22
%24 = getelementptr inbounds double, double* %2, i64 %21
%25 = load double, double* %24
%26 = tail call i32 @cg_daxpy0(double* %0, double* %23, double %25, i32 %15)
%27 = add nuw nsw i64 %21, 1
%28 = icmp eq i64 %27, %17
br i1 %28, label %38, label %19
29: ; preds = %11, %29
%30 = phi i64 [ 0, %11 ], [ %35, %29 ]
%31 = phi i64 [ 0, %11 ], [ %36, %29 ]
%32 = getelementptr inbounds double, double* %1, i64 %30
%33 = tail call double @cg_dot0(double* %32, double* %2, i32 %12)
%34 = getelementptr inbounds double, double* %0, i64 %31
store double %33, double* %34
%35 = add nsw i64 %30, %4
%36 = add nuw nsw i64 %31, 1
%37 = icmp eq i64 %36, %9
br i1 %37, label %38, label %29
38: ; preds = %19, %29, %13, %8
ret void
}