#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 */
typedef int /*<<< orphan*/ __m128;

/* Variables and functions */
int /*<<< orphan*/ _mm_add_ps(int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ _mm_load_ps(float const *);
int /*<<< orphan*/ _mm_mul_ps(int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ _mm_set1_ps(float const);
int /*<<< orphan*/ _mm_store_ps(float *, int /*<<< orphan*/);
int /*<<< orphan*/ memset(int /*<<< orphan*/ *, char, int);
void multiply_sse(const float *A, const float *B, float *result) {
  const float *a = A;
  const float *b = B;
  float *r = result;
  __m128 a_line, b_line, r_line;
  for (int i = 0; i < 16; i += 4) {
    memset(&r_line, '\0', sizeof(__m128));
    for (int j = 0; j < 4; j++) {
      a_line = _mm_load_ps(&a[j * 4]);
      b_line = _mm_set1_ps(b[i + j]);
      r_line = _mm_add_ps(_mm_mul_ps(a_line, b_line), r_line);
    }
    _mm_store_ps(&r[i], r_line);
  }
}


x86 assembly (clang, -O0):
<multiply_sse>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x30(%rbp)
movl   $0x0,-0x40(%rbp)
cmpl   $0x10,-0x40(%rbp)
jge    123e <multiply_sse+0xde>
lea    -0x3c(%rbp),%rdi
xor    %esi,%esi
mov    $0x4,%edx
call   1040 <memset@plt>
movl   $0x0,-0x44(%rbp)
cmpl   $0x4,-0x44(%rbp)
jge    1219 <multiply_sse+0xb9>
mov    -0x20(%rbp),%rdi
mov    -0x44(%rbp),%eax
shl    $0x2,%eax
cltq
shl    $0x2,%rax
add    %rax,%rdi
call   1030 <_mm_load_ps@plt>
mov    %eax,-0x34(%rbp)
mov    -0x28(%rbp),%rax
mov    -0x40(%rbp),%ecx
add    -0x44(%rbp),%ecx
movslq %ecx,%rcx
movss  (%rax,%rcx,4),%xmm0
call   1070 <_mm_set1_ps@plt>
mov    %eax,-0x38(%rbp)
mov    -0x34(%rbp),%edi
mov    -0x38(%rbp),%esi
call   1050 <_mm_mul_ps@plt>
mov    %eax,%edi
mov    -0x3c(%rbp),%esi
call   1080 <_mm_add_ps@plt>
mov    %eax,-0x3c(%rbp)
mov    -0x44(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x44(%rbp)
jmp    11b4 <multiply_sse+0x54>
mov    -0x30(%rbp),%rdi
movslq -0x40(%rbp),%rax
shl    $0x2,%rax
add    %rax,%rdi
mov    -0x3c(%rbp),%esi
call   1060 <_mm_store_ps@plt>
mov    -0x40(%rbp),%eax
add    $0x4,%eax
mov    %eax,-0x40(%rbp)
jmp    1193 <multiply_sse+0x33>
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<multiply_sse>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
mov    %rdx,%rbx
mov    %rsi,%r14
mov    %rdi,%r15
lea    0x10(%rdi),%rax
mov    %rax,0x20(%rsp)
lea    0x20(%rdi),%rax
mov    %rax,0x18(%rsp)
lea    0x30(%rdi),%rax
mov    %rax,0x10(%rsp)
mov    $0xfffffffffffffffc,%r13
nopl   0x0(%rax)
lea    0xc(%rsp),%rdi
xor    %esi,%esi
mov    $0x4,%edx
call   1040 <memset@plt>
mov    %r15,%rdi
call   1030 <_mm_load_ps@plt>
mov    %eax,%r12d
movss  0x10(%r14,%r13,4),%xmm0
call   1070 <_mm_set1_ps@plt>
mov    %r12d,%edi
mov    %eax,%esi
call   1050 <_mm_mul_ps@plt>
mov    0xc(%rsp),%esi
mov    %eax,%edi
call   1080 <_mm_add_ps@plt>
mov    %eax,0xc(%rsp)
mov    0x20(%rsp),%rdi
call   1030 <_mm_load_ps@plt>
mov    %eax,%ebp
movss  0x14(%r14,%r13,4),%xmm0
call   1070 <_mm_set1_ps@plt>
mov    %ebp,%edi
mov    %eax,%esi
call   1050 <_mm_mul_ps@plt>
mov    0xc(%rsp),%esi
mov    %eax,%edi
call   1080 <_mm_add_ps@plt>
mov    %eax,0xc(%rsp)
mov    0x18(%rsp),%rdi
call   1030 <_mm_load_ps@plt>
mov    %eax,%ebp
movss  0x18(%r14,%r13,4),%xmm0
call   1070 <_mm_set1_ps@plt>
mov    %ebp,%edi
mov    %eax,%esi
call   1050 <_mm_mul_ps@plt>
mov    0xc(%rsp),%esi
mov    %eax,%edi
call   1080 <_mm_add_ps@plt>
mov    %eax,0xc(%rsp)
mov    0x10(%rsp),%rdi
call   1030 <_mm_load_ps@plt>
mov    %eax,%ebp
movss  0x1c(%r14,%r13,4),%xmm0
call   1070 <_mm_set1_ps@plt>
mov    %ebp,%edi
mov    %eax,%esi
call   1050 <_mm_mul_ps@plt>
mov    0xc(%rsp),%esi
mov    %eax,%edi
call   1080 <_mm_add_ps@plt>
mov    %eax,0xc(%rsp)
mov    %rbx,%rdi
mov    %eax,%esi
call   1060 <_mm_store_ps@plt>
add    $0x4,%r13
add    $0x10,%rbx
cmp    $0xc,%r13
jb     11a0 <multiply_sse+0x40>
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
define void @multiply_sse(float* %0, float* nocapture %1, float* %2) {
%4 = alloca i32
%5 = bitcast i32* %4 to i8*
%6 = getelementptr inbounds float, float* %0, i64 4
%7 = getelementptr inbounds float, float* %0, i64 8
%8 = getelementptr inbounds float, float* %0, i64 12
br label %10
9: ; preds = %10
ret void
10: ; preds = %3, %10
%11 = phi i64 [ 0, %3 ], [ %46, %10 ]
%12 = call i32 @memset(i32* %4, i8 signext 0, i32 4)
%13 = call i32 @_mm_load_ps(float* %0)
%14 = getelementptr inbounds float, float* %1, i64 %11
%15 = load float, float* %14
%16 = call i32 @_mm_set1_ps(float %15)
%17 = call i32 @_mm_mul_ps(i32 %13, i32 %16)
%18 = load i32, i32* %4
%19 = call i32 @_mm_add_ps(i32 %17, i32 %18)
store i32 %19, i32* %4
%20 = call i32 @_mm_load_ps(float* %6)
%21 = or i64 %11, 1
%22 = getelementptr inbounds float, float* %1, i64 %21
%23 = load float, float* %22
%24 = call i32 @_mm_set1_ps(float %23)
%25 = call i32 @_mm_mul_ps(i32 %20, i32 %24)
%26 = load i32, i32* %4
%27 = call i32 @_mm_add_ps(i32 %25, i32 %26)
store i32 %27, i32* %4
%28 = call i32 @_mm_load_ps(float* %7)
%29 = or i64 %11, 2
%30 = getelementptr inbounds float, float* %1, i64 %29
%31 = load float, float* %30
%32 = call i32 @_mm_set1_ps(float %31)
%33 = call i32 @_mm_mul_ps(i32 %28, i32 %32)
%34 = load i32, i32* %4
%35 = call i32 @_mm_add_ps(i32 %33, i32 %34)
store i32 %35, i32* %4
%36 = call i32 @_mm_load_ps(float* %8)
%37 = or i64 %11, 3
%38 = getelementptr inbounds float, float* %1, i64 %37
%39 = load float, float* %38
%40 = call i32 @_mm_set1_ps(float %39)
%41 = call i32 @_mm_mul_ps(i32 %36, i32 %40)
%42 = load i32, i32* %4
%43 = call i32 @_mm_add_ps(i32 %41, i32 %42)
store i32 %43, i32* %4
%44 = getelementptr inbounds float, float* %2, i64 %11
%45 = call i32 @_mm_store_ps(float* %44, i32 %43)
%46 = add nuw nsw i64 %11, 4
%47 = icmp ult i64 %11, 12
br i1 %47, label %10, label %9
}