#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 */
size_t mpos(int, int);
scalar_t__ mx_multtrmx_tr(int, double *, double *);
void addB(int k, double *B, int M, double **allR) {
  for (int i = 0; i <= k; i++) {
    B[mpos(i, k)] += mx_multtrmx_tr(M, allR[i], allR[k]);
  }
  return;
}


x86 assembly (clang, -O0):
<addB>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    %rcx,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
mov    -0x24(%rbp),%eax
cmp    -0x4(%rbp),%eax
jg     11aa <addB+0x8a>
mov    -0x14(%rbp),%edi
mov    -0x20(%rbp),%rax
movslq -0x24(%rbp),%rcx
mov    (%rax,%rcx,8),%rsi
mov    -0x20(%rbp),%rax
movslq -0x4(%rbp),%rcx
mov    (%rax,%rcx,8),%rdx
call   1040 <mx_multtrmx_tr@plt>
cvtsi2sd %rax,%xmm0
movsd  %xmm0,-0x38(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x24(%rbp),%edi
mov    -0x4(%rbp),%esi
call   1030 <mpos@plt>
movsd  -0x38(%rbp),%xmm0
mov    %rax,%rcx
mov    -0x30(%rbp),%rax
addsd  (%rax,%rcx,8),%xmm0
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    113d <addB+0x1d>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<addB>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
test   %edi,%edi
js     1198 <addB+0x78>
mov    %rcx,%r12
mov    %edx,%r13d
mov    %rsi,%rbp
mov    %edi,%r15d
mov    %edi,%ecx
mov    %rcx,0x8(%rsp)
lea    0x1(%r15),%r14d
xor    %ebx,%ebx
nopl   0x0(%rax,%rax,1)
mov    (%r12,%rbx,8),%rsi
mov    0x8(%rsp),%rcx
mov    (%r12,%rcx,8),%rdx
mov    %r13d,%edi
call   1040 <mx_multtrmx_tr@plt>
xorps  %xmm0,%xmm0
cvtsi2sd %rax,%xmm0
movsd  %xmm0,0x10(%rsp)
mov    %ebx,%edi
mov    %r15d,%esi
call   1030 <mpos@plt>
movsd  0x10(%rsp),%xmm0
addsd  0x0(%rbp,%rax,8),%xmm0
movsd  %xmm0,0x0(%rbp,%rax,8)
add    $0x1,%rbx
cmp    %rbx,%r14
jne    1150 <addB+0x30>
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define void @addB(i32 %0, double* %1, i32 %2, double** %3) {
%5 = alloca i32
%6 = alloca double*
%7 = alloca i32
%8 = alloca double**
%9 = alloca i32
store i32 %0, i32* %5
store double* %1, double** %6
store i32 %2, i32* %7
store double** %3, double*** %8
store i32 0, i32* %9
br label %10
10: ; preds = %35, %4
%11 = load i32, i32* %9
%12 = load i32, i32* %5
%13 = icmp sle i32 %11, %12
br i1 %13, label %14, label %38
14: ; preds = %10
%15 = load i32, i32* %7
%16 = load double**, double*** %8
%17 = load i32, i32* %9
%18 = sext i32 %17 to i64
%19 = getelementptr inbounds double*, double** %16, i64 %18
%20 = load double*, double** %19
%21 = load double**, double*** %8
%22 = load i32, i32* %5
%23 = sext i32 %22 to i64
%24 = getelementptr inbounds double*, double** %21, i64 %23
%25 = load double*, double** %24
%26 = call i64 @mx_multtrmx_tr(i32 %15, double* %20, double* %25)
%27 = sitofp i64 %26 to double
%28 = load double*, double** %6
%29 = load i32, i32* %9
%30 = load i32, i32* %5
%31 = call i64 @mpos(i32 %29, i32 %30)
%32 = getelementptr inbounds double, double* %28, i64 %31
%33 = load double, double* %32
%34 = fadd double %33, %27
store double %34, double* %32
br label %35
35: ; preds = %14
%36 = load i32, i32* %9
%37 = add nsw i32 %36, 1
store i32 %37, i32* %9
br label %10
38: ; preds = %10
ret void
}

LLVM IR (-O2):
define void @addB(i32 %0, double* nocapture %1, i32 %2, double** nocapture %3) {
%5 = icmp slt i32 %0, 0
br i1 %5, label %11, label %6
6: ; preds = %4
%7 = zext i32 %0 to i64
%8 = getelementptr inbounds double*, double** %3, i64 %7
%9 = add nuw i32 %0, 1
%10 = zext i32 %9 to i64
br label %12
11: ; preds = %12, %4
ret void
12: ; preds = %6, %12
%13 = phi i64 [ 0, %6 ], [ %24, %12 ]
%14 = getelementptr inbounds double*, double** %3, i64 %13
%15 = load double*, double** %14
%16 = load double*, double** %8
%17 = tail call i64 @mx_multtrmx_tr(i32 %2, double* %15, double* %16)
%18 = sitofp i64 %17 to double
%19 = trunc i64 %13 to i32
%20 = tail call i64 @mpos(i32 %19, i32 %0)
%21 = getelementptr inbounds double, double* %1, i64 %20
%22 = load double, double* %21
%23 = fadd double %22, %18
store double %23, double* %21
%24 = add nuw nsw i64 %13, 1
%25 = icmp eq i64 %24, %10
br i1 %25, label %11, label %12
}