#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*/ safe_add(double *, double *, double const);
void mmv(size_t nr, size_t nc, const double m[], const double x[], double y[]) {
  size_t i, j;
  for (i = 0; i < nr; ++i) {
    double s = 0, cs = 0;
    for (j = 0; j < nc; ++j) {
      safe_add(&s, &cs, m[i * nc + j] * x[j]);
    }
    y[i] = s;
  }
}


x86 assembly (clang, -O0):
<mmv>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    %r8,-0x28(%rbp)
movq   $0x0,-0x30(%rbp)
mov    -0x30(%rbp),%rax
cmp    -0x8(%rbp),%rax
jae    11cc <mmv+0xbc>
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x40(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x48(%rbp)
movq   $0x0,-0x38(%rbp)
mov    -0x38(%rbp),%rax
cmp    -0x10(%rbp),%rax
jae    11a9 <mmv+0x99>
mov    -0x18(%rbp),%rax
mov    -0x30(%rbp),%rcx
imul   -0x10(%rbp),%rcx
add    -0x38(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
mov    -0x20(%rbp),%rax
mov    -0x38(%rbp),%rcx
mulsd  (%rax,%rcx,8),%xmm0
lea    -0x40(%rbp),%rdi
lea    -0x48(%rbp),%rsi
call   1030 <safe_add@plt>
mov    -0x38(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x38(%rbp)
jmp    115a <mmv+0x4a>
movsd  -0x40(%rbp),%xmm0
mov    -0x28(%rbp),%rax
mov    -0x30(%rbp),%rcx
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x30(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x30(%rbp)
jmp    1134 <mmv+0x24>
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<mmv>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x38,%rsp
mov    %r8,0x20(%rsp)
mov    %rdi,0x18(%rsp)
test   %rdi,%rdi
je     11cd <mmv+0xbd>
mov    %rcx,%r15
mov    %rdx,%rbx
mov    %rsi,%r12
lea    0x0(,%rsi,8),%rax
mov    %rax,0x10(%rsp)
xor    %ecx,%ecx
lea    0x8(%rsp),%rbp
lea    0x30(%rsp),%r14
jmp    117e <mmv+0x6e>
cs nopw 0x0(%rax,%rax,1)
nop
xorpd  %xmm0,%xmm0
mov    0x20(%rsp),%rax
movsd  %xmm0,(%rax,%rcx,8)
add    $0x1,%rcx
add    0x10(%rsp),%rbx
cmp    0x18(%rsp),%rcx
je     11cd <mmv+0xbd>
movq   $0x0,0x8(%rsp)
movq   $0x0,0x30(%rsp)
test   %r12,%r12
je     1160 <mmv+0x50>
mov    %rcx,0x28(%rsp)
xor    %r13d,%r13d
nopl   (%rax)
movsd  (%rbx,%r13,8),%xmm0
mulsd  (%r15,%r13,8),%xmm0
mov    %rbp,%rdi
mov    %r14,%rsi
call   1030 <safe_add@plt>
add    $0x1,%r13
cmp    %r13,%r12
jne    11a0 <mmv+0x90>
movsd  0x8(%rsp),%xmm0
mov    0x28(%rsp),%rcx
jmp    1164 <mmv+0x54>
add    $0x38,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
define void @mmv(i64 %0, i64 %1, double* nocapture %2, double* nocapture %3, double* nocapture writeonly %4) {
%6 = alloca double
%7 = alloca double
%8 = icmp eq i64 %0, 0
br i1 %8, label %35, label %9
9: ; preds = %5
%10 = bitcast double* %6 to i8*
%11 = bitcast double* %7 to i8*
%12 = icmp eq i64 %1, 0
br label %13
13: ; preds = %9, %30
%14 = phi i64 [ 0, %9 ], [ %33, %30 ]
store double 0.000000e+00, double* %6
store double 0.000000e+00, double* %7
br i1 %12, label %30, label %15
15: ; preds = %13
%16 = mul i64 %14, %1
br label %17
17: ; preds = %15, %17
%18 = phi i64 [ 0, %15 ], [ %26, %17 ]
%19 = add i64 %18, %16
%20 = getelementptr inbounds double, double* %2, i64 %19
%21 = load double, double* %20
%22 = getelementptr inbounds double, double* %3, i64 %18
%23 = load double, double* %22
%24 = fmul double %21, %23
%25 = call i32 @safe_add(double* %6, double* %7, double %24)
%26 = add nuw i64 %18, 1
%27 = icmp eq i64 %26, %1
br i1 %27, label %28, label %17
28: ; preds = %17
%29 = load double, double* %6
br label %30
30: ; preds = %28, %13
%31 = phi double [ %29, %28 ], [ 0.000000e+00, %13 ]
%32 = getelementptr inbounds double, double* %4, i64 %14
store double %31, double* %32
%33 = add nuw i64 %14, 1
%34 = icmp eq i64 %33, %0
br i1 %34, label %35, label %13
35: ; preds = %30, %5
ret void
}