#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 */
float const mat_get(float const *, int, int, int);
void mat_transform(const float *m, const float *v, float *r, int n) {
  int i, j;
  for (i = 0; i < n; i++) {
    float sum = 0.0f;
    for (j = 0; j < n; j++) {
      sum += v[j] * mat_get(m, i, j, n);
    }
    r[i] = sum;
  }
}


x86 assembly (clang, -O0):
<mat_transform>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %ecx,-0x1c(%rbp)
movl   $0x0,-0x20(%rbp)
mov    -0x20(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jge    11c1 <mat_transform+0xb1>
xorps  %xmm0,%xmm0
movss  %xmm0,-0x28(%rbp)
movl   $0x0,-0x24(%rbp)
mov    -0x24(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jge    11a1 <mat_transform+0x91>
mov    -0x10(%rbp),%rax
movslq -0x24(%rbp),%rcx
movss  (%rax,%rcx,4),%xmm0
movss  %xmm0,-0x2c(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x20(%rbp),%esi
mov    -0x24(%rbp),%edx
mov    -0x1c(%rbp),%ecx
call   1030 <mat_get@plt>
movaps %xmm0,%xmm2
movss  -0x2c(%rbp),%xmm0
movss  -0x28(%rbp),%xmm1
mulss  %xmm2,%xmm0
addss  %xmm1,%xmm0
movss  %xmm0,-0x28(%rbp)
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    1149 <mat_transform+0x39>
movss  -0x28(%rbp),%xmm0
mov    -0x18(%rbp),%rax
movslq -0x20(%rbp),%rcx
movss  %xmm0,(%rax,%rcx,4)
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    112e <mat_transform+0x1e>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<mat_transform>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
test   %ecx,%ecx
jle    1191 <mat_transform+0x81>
mov    %rdx,%r14
mov    %rsi,%r15
mov    %rdi,%r12
mov    %ecx,%ebx
xor    %r13d,%r13d
nopl   (%rax)
xorps  %xmm0,%xmm0
xor    %ebp,%ebp
cs nopw 0x0(%rax,%rax,1)
nop
movss  %xmm0,(%rsp)
movss  (%r15,%rbp,4),%xmm0
movss  %xmm0,0x4(%rsp)
mov    %r12,%rdi
mov    %r13d,%esi
mov    %ebp,%edx
mov    %ebx,%ecx
call   1030 <mat_get@plt>
mulss  0x4(%rsp),%xmm0
movss  (%rsp),%xmm1
addss  %xmm0,%xmm1
movss  %xmm1,(%rsp)
movss  (%rsp),%xmm0
add    $0x1,%rbp
cmp    %rbp,%rbx
jne    1140 <mat_transform+0x30>
movss  %xmm0,(%r14,%r13,4)
add    $0x1,%r13
cmp    %rbx,%r13
jne    1130 <mat_transform+0x20>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

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