#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*/);
void matrix4x4_mult_vect(float *r, const float *a, const float *b) {
  __m128 a_line, b_line, r_line;
  int i, j;
  for (i = 0; i < 16; i += 4) {
    b_line = _mm_load_ps(b);
    a_line = _mm_set1_ps(a[i]);
    r_line = _mm_mul_ps(a_line, b_line);
    for (j = 1; j < 4; j++) {
      b_line = _mm_load_ps(&b[j * 4]);
      a_line = _mm_set1_ps(a[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):
<matrix4x4_mult_vect>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
movl   $0x0,-0x28(%rbp)
cmpl   $0x10,-0x28(%rbp)
jge    1235 <matrix4x4_mult_vect+0xe5>
mov    -0x18(%rbp),%rdi
call   1030 <_mm_load_ps@plt>
mov    %eax,-0x20(%rbp)
mov    -0x10(%rbp),%rax
movslq -0x28(%rbp),%rcx
movss  (%rax,%rcx,4),%xmm0
call   1060 <_mm_set1_ps@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%edi
mov    -0x20(%rbp),%esi
call   1040 <_mm_mul_ps@plt>
mov    %eax,-0x24(%rbp)
movl   $0x1,-0x2c(%rbp)
cmpl   $0x4,-0x2c(%rbp)
jge    1210 <matrix4x4_mult_vect+0xc0>
mov    -0x18(%rbp),%rdi
mov    -0x2c(%rbp),%eax
shl    $0x2,%eax
cltq
shl    $0x2,%rax
add    %rax,%rdi
call   1030 <_mm_load_ps@plt>
mov    %eax,-0x20(%rbp)
mov    -0x10(%rbp),%rax
mov    -0x28(%rbp),%ecx
add    -0x2c(%rbp),%ecx
movslq %ecx,%rcx
movss  (%rax,%rcx,4),%xmm0
call   1060 <_mm_set1_ps@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%edi
mov    -0x20(%rbp),%esi
call   1040 <_mm_mul_ps@plt>
mov    %eax,%edi
mov    -0x24(%rbp),%esi
call   1070 <_mm_add_ps@plt>
mov    %eax,-0x24(%rbp)
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    11ab <matrix4x4_mult_vect+0x5b>
mov    -0x8(%rbp),%rdi
movslq -0x28(%rbp),%rax
shl    $0x2,%rax
add    %rax,%rdi
mov    -0x24(%rbp),%esi
call   1050 <_mm_store_ps@plt>
mov    -0x28(%rbp),%eax
add    $0x4,%eax
mov    %eax,-0x28(%rbp)
jmp    116b <matrix4x4_mult_vect+0x1b>
add    $0x30,%rsp
pop    %rbp
ret

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

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

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