#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 square_symm_matrix(double **A, double **B, int n) {
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n - i; j++) {
      double sum = 0;
      for (int k = 0; k < n; k++) {
        sum += index_symm_matrix(A, i, k) * index_symm_matrix(A, k, j + i);
      }
      B[i][j] = sum;
    }
  }
}


x86 assembly (clang, -O0):
<square_symm_matrix>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    11f2 <square_symm_matrix+0xe2>
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
mov    -0x14(%rbp),%ecx
sub    -0x18(%rbp),%ecx
cmp    %ecx,%eax
jge    11df <square_symm_matrix+0xcf>
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x28(%rbp)
movl   $0x0,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    11b7 <square_symm_matrix+0xa7>
mov    -0x8(%rbp),%rdi
mov    -0x18(%rbp),%esi
mov    -0x2c(%rbp),%edx
call   1030 <index_symm_matrix@plt>
movsd  %xmm0,-0x38(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x2c(%rbp),%esi
mov    -0x1c(%rbp),%edx
add    -0x18(%rbp),%edx
call   1030 <index_symm_matrix@plt>
movaps %xmm0,%xmm2
movsd  -0x38(%rbp),%xmm0
movsd  -0x28(%rbp),%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x28(%rbp)
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    115d <square_symm_matrix+0x4d>
movsd  -0x28(%rbp),%xmm0
mov    -0x10(%rbp),%rax
movslq -0x18(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
movslq -0x1c(%rbp),%rcx
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    113d <square_symm_matrix+0x2d>
jmp    11e4 <square_symm_matrix+0xd4>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    112a <square_symm_matrix+0x1a>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<square_symm_matrix>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x38,%rsp
mov    %rsi,0x20(%rsp)
test   %edx,%edx
jle    11f9 <square_symm_matrix+0xe9>
mov    %edx,%r15d
mov    %rdi,%rbx
mov    %edx,%eax
mov    %rax,0x18(%rsp)
xor    %r12d,%r12d
mov    %edx,0xc(%rsp)
jmp    1164 <square_symm_matrix+0x54>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
add    $0x1,%r12
addl   $0xffffffff,0xc(%rsp)
cmp    0x18(%rsp),%r12
je     11f9 <square_symm_matrix+0xe9>
cmp    %r15d,%r12d
jge    1150 <square_symm_matrix+0x40>
mov    0xc(%rsp),%eax
mov    %rax,0x28(%rsp)
xor    %r14d,%r14d
cs nopw 0x0(%rax,%rax,1)
nop
lea    (%r14,%r12,1),%r13d
xorpd  %xmm0,%xmm0
xor    %ebp,%ebp
nopw   0x0(%rax,%rax,1)
movsd  %xmm0,0x10(%rsp)
mov    %rbx,%rdi
mov    %r12d,%esi
mov    %ebp,%edx
call   1030 <index_symm_matrix@plt>
movsd  %xmm0,0x30(%rsp)
mov    %rbx,%rdi
mov    %ebp,%esi
mov    %r13d,%edx
call   1030 <index_symm_matrix@plt>
mulsd  0x30(%rsp),%xmm0
movsd  0x10(%rsp),%xmm1
addsd  %xmm0,%xmm1
movsd  %xmm1,0x10(%rsp)
movsd  0x10(%rsp),%xmm0
add    $0x1,%ebp
cmp    %ebp,%r15d
jne    1190 <square_symm_matrix+0x80>
mov    0x20(%rsp),%rax
mov    (%rax,%r12,8),%rax
movsd  %xmm0,(%rax,%r14,8)
add    $0x1,%r14
cmp    0x28(%rsp),%r14
jne    1180 <square_symm_matrix+0x70>
jmp    1150 <square_symm_matrix+0x40>
add    $0x38,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

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