#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*/ _mm256_add_ps(int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ _mm256_loadu_ps(float *);
int /*<<< orphan*/ _mm256_mul_ps(int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ _mm256_set1_ps(float);
int /*<<< orphan*/ _mm256_storeu_ps(float *, int /*<<< orphan*/);
int parallelMatrixMul_AVX_f(float *a, float *b, float *result, int N) {
  int calculation_count = N / 8;
  for (int i = 0; i < N; ++i) {
    int iN = (i * N);
    for (int j = 0; j < calculation_count; ++j) {
      int jAVX = j * 8;
      float *result_address = &result[iN + jAVX];
      for (int k = 0; k < N; ++k) {
        _mm256_storeu_ps(
            result_address,
            _mm256_add_ps(_mm256_mul_ps(_mm256_set1_ps(a[k + iN]),
                                        _mm256_loadu_ps(&b[jAVX + (k * N)])),
                          _mm256_loadu_ps(result_address)));
      }
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<parallelMatrixMul_AVX_f>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %ecx,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
mov    $0x8,%ecx
cltd
idiv   %ecx
mov    %eax,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
mov    -0x24(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jge    1278 <parallelMatrixMul_AVX_f+0x128>
mov    -0x24(%rbp),%eax
imul   -0x1c(%rbp),%eax
mov    %eax,-0x28(%rbp)
movl   $0x0,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
cmp    -0x20(%rbp),%eax
jge    1265 <parallelMatrixMul_AVX_f+0x115>
mov    -0x2c(%rbp),%eax
shl    $0x3,%eax
mov    %eax,-0x30(%rbp)
mov    -0x18(%rbp),%rax
mov    -0x28(%rbp),%ecx
add    -0x30(%rbp),%ecx
movslq %ecx,%rcx
shl    $0x2,%rcx
add    %rcx,%rax
mov    %rax,-0x38(%rbp)
movl   $0x0,-0x3c(%rbp)
mov    -0x3c(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jge    1252 <parallelMatrixMul_AVX_f+0x102>
mov    -0x38(%rbp),%rax
mov    %rax,-0x48(%rbp)
mov    -0x8(%rbp),%rax
mov    -0x3c(%rbp),%ecx
add    -0x28(%rbp),%ecx
movslq %ecx,%rcx
movss  (%rax,%rcx,4),%xmm0
call   1040 <_mm256_set1_ps@plt>
mov    %eax,-0x50(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x30(%rbp),%eax
mov    -0x3c(%rbp),%ecx
imul   -0x1c(%rbp),%ecx
add    %ecx,%eax
cltq
shl    $0x2,%rax
add    %rax,%rdi
call   1030 <_mm256_loadu_ps@plt>
mov    -0x50(%rbp),%edi
mov    %eax,%esi
call   1060 <_mm256_mul_ps@plt>
mov    %eax,-0x4c(%rbp)
mov    -0x38(%rbp),%rdi
call   1030 <_mm256_loadu_ps@plt>
mov    -0x4c(%rbp),%edi
mov    %eax,%esi
call   1070 <_mm256_add_ps@plt>
mov    -0x48(%rbp),%rdi
mov    %eax,%esi
call   1050 <_mm256_storeu_ps@plt>
mov    -0x3c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x3c(%rbp)
jmp    11cd <parallelMatrixMul_AVX_f+0x7d>
jmp    1257 <parallelMatrixMul_AVX_f+0x107>
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    1199 <parallelMatrixMul_AVX_f+0x49>
jmp    126a <parallelMatrixMul_AVX_f+0x11a>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    117c <parallelMatrixMul_AVX_f+0x2c>
xor    %eax,%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<parallelMatrixMul_AVX_f>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x58,%rsp
mov    %rdx,0x28(%rsp)
mov    %rsi,0x18(%rsp)
mov    %rcx,0x10(%rsp)
test   %ecx,%ecx
jle    1287 <parallelMatrixMul_AVX_f+0x137>
mov    0x10(%rsp),%rax
lea    0x7(%rax),%ecx
test   %eax,%eax
cmovns %eax,%ecx
sar    $0x3,%ecx
mov    %rcx,0x20(%rsp)
mov    %eax,%r14d
lea    0x0(,%r14,4),%r13
xor    %eax,%eax
mov    %rax,0x8(%rsp)
jmp    11bd <parallelMatrixMul_AVX_f+0x6d>
xchg   %ax,%ax
mov    0x8(%rsp),%rcx
add    $0x1,%rcx
add    %r13,%rdi
mov    %rcx,%rax
mov    %rcx,0x8(%rsp)
cmp    %r14,%rcx
je     1287 <parallelMatrixMul_AVX_f+0x137>
cmpl   $0x8,0x10(%rsp)
jb     11a0 <parallelMatrixMul_AVX_f+0x50>
mov    0x8(%rsp),%rax
imul   %r14,%rax
mov    %rax,0x30(%rsp)
mov    0x18(%rsp),%rbp
xor    %ecx,%ecx
mov    %rdi,0x48(%rsp)
xchg   %ax,%ax
mov    0x30(%rsp),%rax
mov    %rcx,0x38(%rsp)
lea    (%rax,%rcx,8),%rax
mov    0x28(%rsp),%rcx
lea    (%rcx,%rax,4),%rax
mov    %rax,0x50(%rsp)
mov    %rbp,0x40(%rsp)
xor    %r12d,%r12d
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
movss  (%rdi,%r12,4),%xmm0
call   1040 <_mm256_set1_ps@plt>
mov    %eax,%r15d
mov    %rbp,%rdi
call   1030 <_mm256_loadu_ps@plt>
mov    %r15d,%edi
mov    %eax,%esi
call   1060 <_mm256_mul_ps@plt>
mov    %eax,%r15d
mov    0x50(%rsp),%rbx
mov    %rbx,%rdi
call   1030 <_mm256_loadu_ps@plt>
mov    %r15d,%edi
mov    %eax,%esi
call   1070 <_mm256_add_ps@plt>
mov    %rbx,%rdi
mov    %eax,%esi
call   1050 <_mm256_storeu_ps@plt>
mov    0x48(%rsp),%rdi
add    $0x1,%r12
add    %r13,%rbp
cmp    %r12,%r14
jne    1210 <parallelMatrixMul_AVX_f+0xc0>
mov    0x38(%rsp),%rcx
add    $0x1,%rcx
mov    0x40(%rsp),%rbp
add    $0x20,%rbp
cmp    0x20(%rsp),%rcx
jne    11e0 <parallelMatrixMul_AVX_f+0x90>
jmp    11a0 <parallelMatrixMul_AVX_f+0x50>
xor    %eax,%eax
add    $0x58,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @parallelMatrixMul_AVX_f(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 i32
%12 = alloca i32
%13 = alloca i32
%14 = alloca float*
%15 = alloca i32
store float* %0, float** %5
store float* %1, float** %6
store float* %2, float** %7
store i32 %3, i32* %8
%16 = load i32, i32* %8
%17 = sdiv i32 %16, 8
store i32 %17, i32* %9
store i32 0, i32* %10
br label %18
18: ; preds = %75, %4
%19 = load i32, i32* %10
%20 = load i32, i32* %8
%21 = icmp slt i32 %19, %20
br i1 %21, label %22, label %78
22: ; preds = %18
%23 = load i32, i32* %10
%24 = load i32, i32* %8
%25 = mul nsw i32 %23, %24
store i32 %25, i32* %11
store i32 0, i32* %12
br label %26
26: ; preds = %71, %22
%27 = load i32, i32* %12
%28 = load i32, i32* %9
%29 = icmp slt i32 %27, %28
br i1 %29, label %30, label %74
30: ; preds = %26
%31 = load i32, i32* %12
%32 = mul nsw i32 %31, 8
store i32 %32, i32* %13
%33 = load float*, float** %7
%34 = load i32, i32* %11
%35 = load i32, i32* %13
%36 = add nsw i32 %34, %35
%37 = sext i32 %36 to i64
%38 = getelementptr inbounds float, float* %33, i64 %37
store float* %38, float** %14
store i32 0, i32* %15
br label %39
39: ; preds = %67, %30
%40 = load i32, i32* %15
%41 = load i32, i32* %8
%42 = icmp slt i32 %40, %41
br i1 %42, label %43, label %70
43: ; preds = %39
%44 = load float*, float** %14
%45 = load float*, float** %5
%46 = load i32, i32* %15
%47 = load i32, i32* %11
%48 = add nsw i32 %46, %47
%49 = sext i32 %48 to i64
%50 = getelementptr inbounds float, float* %45, i64 %49
%51 = load float, float* %50
%52 = call i32 @_mm256_set1_ps(float %51)
%53 = load float*, float** %6
%54 = load i32, i32* %13
%55 = load i32, i32* %15
%56 = load i32, i32* %8
%57 = mul nsw i32 %55, %56
%58 = add nsw i32 %54, %57
%59 = sext i32 %58 to i64
%60 = getelementptr inbounds float, float* %53, i64 %59
%61 = call i32 @_mm256_loadu_ps(float* %60)
%62 = call i32 @_mm256_mul_ps(i32 %52, i32 %61)
%63 = load float*, float** %14
%64 = call i32 @_mm256_loadu_ps(float* %63)
%65 = call i32 @_mm256_add_ps(i32 %62, i32 %64)
%66 = call i32 @_mm256_storeu_ps(float* %44, i32 %65)
br label %67
67: ; preds = %43
%68 = load i32, i32* %15
%69 = add nsw i32 %68, 1
store i32 %69, i32* %15
br label %39
70: ; preds = %39
br label %71
71: ; preds = %70
%72 = load i32, i32* %12
%73 = add nsw i32 %72, 1
store i32 %73, i32* %12
br label %26
74: ; preds = %26
br label %75
75: ; preds = %74
%76 = load i32, i32* %10
%77 = add nsw i32 %76, 1
store i32 %77, i32* %10
br label %18
78: ; preds = %18
ret i32 0
}

LLVM IR (-O2):
define i32 @parallelMatrixMul_AVX_f(float* nocapture %0, float* %1, float* %2, i32 %3) {
%5 = icmp sgt i32 %3, 0
br i1 %5, label %6, label %12
6: ; preds = %4
%7 = sdiv i32 %3, 8
%8 = icmp ugt i32 %3, 7
%9 = zext i32 %3 to i64
%10 = zext i32 %3 to i64
%11 = zext i32 %7 to i64
br label %13
12: ; preds = %16, %4
ret i32 0
13: ; preds = %6, %16
%14 = phi i64 [ 0, %6 ], [ %17, %16 ]
%15 = mul nsw i64 %14, %9
br i1 %8, label %19, label %16
16: ; preds = %24, %13
%17 = add nuw nsw i64 %14, 1
%18 = icmp eq i64 %17, %10
br i1 %18, label %12, label %13
19: ; preds = %13, %24
%20 = phi i64 [ %25, %24 ], [ 0, %13 ]
%21 = shl nsw i64 %20, 3
%22 = add nuw nsw i64 %21, %15
%23 = getelementptr inbounds float, float* %2, i64 %22
br label %27
24: ; preds = %27
%25 = add nuw nsw i64 %20, 1
%26 = icmp eq i64 %25, %11
br i1 %26, label %16, label %19
27: ; preds = %19, %27
%28 = phi i64 [ 0, %19 ], [ %41, %27 ]
%29 = add nuw nsw i64 %28, %15
%30 = getelementptr inbounds float, float* %0, i64 %29
%31 = load float, float* %30
%32 = tail call i32 @_mm256_set1_ps(float %31)
%33 = mul nsw i64 %28, %9
%34 = add nuw nsw i64 %33, %21
%35 = getelementptr inbounds float, float* %1, i64 %34
%36 = tail call i32 @_mm256_loadu_ps(float* %35)
%37 = tail call i32 @_mm256_mul_ps(i32 %32, i32 %36)
%38 = tail call i32 @_mm256_loadu_ps(float* %23)
%39 = tail call i32 @_mm256_add_ps(i32 %37, i32 %38)
%40 = tail call i32 @_mm256_storeu_ps(float* %23, i32 %39)
%41 = add nuw nsw i64 %28, 1
%42 = icmp eq i64 %41, %10
br i1 %42, label %24, label %27
}