#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 index_symm_matrix(double **, int, int);
extern void multiply_symm_matrix_vector(double **A, double *x, int n,
                                        double *b) {
  for (int i = 0; i < n; i++) {
    double sum = 0;
    for (int j = 0; j < n; j++) {
      sum += index_symm_matrix(A, i, j) * x[j];
    }
    b[i] = sum;
  }
}


x86 assembly (clang, -O0):
<multiply_symm_matrix_vector>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    %rcx,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
mov    -0x24(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    11b1 <multiply_symm_matrix_vector+0xa1>
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x30(%rbp)
movl   $0x0,-0x34(%rbp)
mov    -0x34(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    1191 <multiply_symm_matrix_vector+0x81>
mov    -0x8(%rbp),%rdi
mov    -0x24(%rbp),%esi
mov    -0x34(%rbp),%edx
call   1030 <index_symm_matrix@plt>
mov    -0x10(%rbp),%rax
movslq -0x34(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm2
movsd  -0x30(%rbp),%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x30(%rbp)
mov    -0x34(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x34(%rbp)
jmp    1149 <multiply_symm_matrix_vector+0x39>
movsd  -0x30(%rbp),%xmm0
mov    -0x20(%rbp),%rax
movslq -0x24(%rbp),%rcx
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    112e <multiply_symm_matrix_vector+0x1e>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<multiply_symm_matrix_vector>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
test   %edx,%edx
jle    1183 <multiply_symm_matrix_vector+0x73>
mov    %rcx,%r14
mov    %rsi,%r15
mov    %rdi,%r12
mov    %edx,%ebp
xor    %r13d,%r13d
nopl   (%rax)
xorpd  %xmm0,%xmm0
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
movsd  %xmm0,(%rsp)
mov    %r12,%rdi
mov    %r13d,%esi
mov    %ebx,%edx
call   1030 <index_symm_matrix@plt>
mulsd  (%r15,%rbx,8),%xmm0
movsd  (%rsp),%xmm1
addsd  %xmm0,%xmm1
movsd  %xmm1,(%rsp)
movsd  (%rsp),%xmm0
add    $0x1,%rbx
cmp    %rbx,%rbp
jne    1140 <multiply_symm_matrix_vector+0x30>
movsd  %xmm0,(%r14,%r13,8)
add    $0x1,%r13
cmp    %rbp,%r13
jne    1130 <multiply_symm_matrix_vector+0x20>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define void @multiply_symm_matrix_vector(double** %0, double* %1, i32 %2, double* %3) {
%5 = alloca double**
%6 = alloca double*
%7 = alloca i32
%8 = alloca double*
%9 = alloca i32
%10 = alloca double
%11 = alloca i32
store double** %0, double*** %5
store double* %1, double** %6
store i32 %2, i32* %7
store double* %3, double** %8
store i32 0, i32* %9
br label %12
12: ; preds = %42, %4
%13 = load i32, i32* %9
%14 = load i32, i32* %7
%15 = icmp slt i32 %13, %14
br i1 %15, label %16, label %45
16: ; preds = %12
store double 0.000000e+00, double* %10
store i32 0, i32* %11
br label %17
17: ; preds = %33, %16
%18 = load i32, i32* %11
%19 = load i32, i32* %7
%20 = icmp slt i32 %18, %19
br i1 %20, label %21, label %36
21: ; preds = %17
%22 = load double**, double*** %5
%23 = load i32, i32* %9
%24 = load i32, i32* %11
%25 = call double @index_symm_matrix(double** %22, i32 %23, i32 %24)
%26 = load double*, double** %6
%27 = load i32, i32* %11
%28 = sext i32 %27 to i64
%29 = getelementptr inbounds double, double* %26, i64 %28
%30 = load double, double* %29
%31 = load double, double* %10
%32 = call double @llvm.fmuladd.f64(double %25, double %30, double %31)
store double %32, double* %10
br label %33
33: ; preds = %21
%34 = load i32, i32* %11
%35 = add nsw i32 %34, 1
store i32 %35, i32* %11
br label %17
36: ; preds = %17
%37 = load double, double* %10
%38 = load double*, double** %8
%39 = load i32, i32* %9
%40 = sext i32 %39 to i64
%41 = getelementptr inbounds double, double* %38, i64 %40
store double %37, double* %41
br label %42
42: ; preds = %36
%43 = load i32, i32* %9
%44 = add nsw i32 %43, 1
store i32 %44, i32* %9
br label %12
45: ; preds = %12
ret void
}

LLVM IR (-O2):
define void @multiply_symm_matrix_vector(double** %0, double* nocapture %1, i32 %2, double* nocapture writeonly %3) {
%5 = icmp sgt i32 %2, 0
br i1 %5, label %6, label %11
6: ; preds = %4
%7 = zext i32 %2 to i64
br label %8
8: ; preds = %12, %6
%9 = phi i64 [ 0, %6 ], [ %14, %12 ]
%10 = trunc i64 %9 to i32
br label %16
11: ; preds = %12, %4
ret void
12: ; preds = %16
%13 = getelementptr inbounds double, double* %3, i64 %9
store double %23, double* %13
%14 = add nuw nsw i64 %9, 1
%15 = icmp eq i64 %14, %7
br i1 %15, label %11, label %8
16: ; preds = %8, %16
%17 = phi i64 [ 0, %8 ], [ %24, %16 ]
%18 = phi double [ 0.000000e+00, %8 ], [ %23, %16 ]
%19 = trunc i64 %17 to i32
%20 = tail call double @index_symm_matrix(double** %0, i32 %10, i32 %19)
%21 = getelementptr inbounds double, double* %1, i64 %17
%22 = load double, double* %21
%23 = tail call double @llvm.fmuladd.f64(double %20, double %22, double %18)
%24 = add nuw nsw i64 %17, 1
%25 = icmp eq i64 %24, %7
br i1 %25, label %12, label %16
}