#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 */
scalar_t__ malloc(int);
double *multiply_matrices(const double *L, const double *R) {
  int i, j, k;
  double *M;
  M = (double *)malloc(sizeof(double) * 9);
  for (i = 0; i < 3; i++) {
    for (j = 0; j < 3; j++) {
      M[i * 3 + j] = 0;
      for (k = 0; k < 3; k++) {
        M[i * 3 + j] += L[i * 3 + k] * R[k * 3 + j];
      }
    }
  }
  return M;
}


x86 assembly (clang, -O0):
<multiply_matrices>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    $0x48,%edi
call   1030 <malloc@plt>
mov    %rax,-0x28(%rbp)
movl   $0x0,-0x14(%rbp)
cmpl   $0x3,-0x14(%rbp)
jge    11f1 <multiply_matrices+0xe1>
movl   $0x0,-0x18(%rbp)
cmpl   $0x3,-0x18(%rbp)
jge    11de <multiply_matrices+0xce>
mov    -0x28(%rbp),%rax
imul   $0x3,-0x14(%rbp),%ecx
add    -0x18(%rbp),%ecx
movslq %ecx,%rcx
xorps  %xmm0,%xmm0
movsd  %xmm0,(%rax,%rcx,8)
movl   $0x0,-0x1c(%rbp)
cmpl   $0x3,-0x1c(%rbp)
jge    11cb <multiply_matrices+0xbb>
mov    -0x8(%rbp),%rax
imul   $0x3,-0x14(%rbp),%ecx
add    -0x1c(%rbp),%ecx
movslq %ecx,%rcx
movsd  (%rax,%rcx,8),%xmm0
mov    -0x10(%rbp),%rax
imul   $0x3,-0x1c(%rbp),%ecx
add    -0x18(%rbp),%ecx
movslq %ecx,%rcx
movsd  (%rax,%rcx,8),%xmm2
mov    -0x28(%rbp),%rax
imul   $0x3,-0x14(%rbp),%ecx
add    -0x18(%rbp),%ecx
movslq %ecx,%rcx
movsd  (%rax,%rcx,8),%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    116d <multiply_matrices+0x5d>
jmp    11d0 <multiply_matrices+0xc0>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    1146 <multiply_matrices+0x36>
jmp    11e3 <multiply_matrices+0xd3>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1135 <multiply_matrices+0x25>
mov    -0x28(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<multiply_matrices>:
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%rbx
mov    $0x48,%edi
call   1030 <malloc@plt>
mov    $0x10,%ecx
xorpd  %xmm0,%xmm0
nopl   (%rax)
movq   $0x0,-0x10(%rax,%rcx,1)
movsd  -0x10(%rbx,%rcx,1),%xmm1
mulsd  (%r14),%xmm1
addsd  %xmm0,%xmm1
movsd  %xmm1,-0x10(%rax,%rcx,1)
movsd  -0x8(%rbx,%rcx,1),%xmm2
mulsd  0x18(%r14),%xmm2
addsd  %xmm1,%xmm2
movsd  %xmm2,-0x10(%rax,%rcx,1)
movsd  (%rbx,%rcx,1),%xmm1
mulsd  0x30(%r14),%xmm1
addsd  %xmm2,%xmm1
movsd  %xmm1,-0x10(%rax,%rcx,1)
movq   $0x0,-0x8(%rax,%rcx,1)
movsd  -0x10(%rbx,%rcx,1),%xmm1
mulsd  0x8(%r14),%xmm1
addsd  %xmm0,%xmm1
movsd  %xmm1,-0x8(%rax,%rcx,1)
movsd  -0x8(%rbx,%rcx,1),%xmm2
mulsd  0x20(%r14),%xmm2
addsd  %xmm1,%xmm2
movsd  %xmm2,-0x8(%rax,%rcx,1)
movsd  (%rbx,%rcx,1),%xmm1
mulsd  0x38(%r14),%xmm1
addsd  %xmm2,%xmm1
movsd  %xmm1,-0x8(%rax,%rcx,1)
movq   $0x0,(%rax,%rcx,1)
movsd  -0x10(%rbx,%rcx,1),%xmm1
mulsd  0x10(%r14),%xmm1
addsd  %xmm0,%xmm1
movsd  %xmm1,(%rax,%rcx,1)
movsd  -0x8(%rbx,%rcx,1),%xmm2
mulsd  0x28(%r14),%xmm2
addsd  %xmm1,%xmm2
movsd  %xmm2,(%rax,%rcx,1)
movsd  (%rbx,%rcx,1),%xmm1
mulsd  0x40(%r14),%xmm1
addsd  %xmm2,%xmm1
movsd  %xmm1,(%rax,%rcx,1)
add    $0x18,%rcx
cmp    $0x58,%rcx
jne    1130 <multiply_matrices+0x20>
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

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

LLVM IR (-O2):
define double* @multiply_matrices(double* nocapture %0, double* nocapture %1) {
%3 = tail call i64 @malloc(i32 72)
%4 = inttoptr i64 %3 to double*
%5 = getelementptr inbounds double, double* %1, i64 3
%6 = getelementptr inbounds double, double* %1, i64 6
%7 = getelementptr inbounds double, double* %1, i64 1
%8 = getelementptr inbounds double, double* %1, i64 4
%9 = getelementptr inbounds double, double* %1, i64 7
%10 = getelementptr inbounds double, double* %1, i64 2
%11 = getelementptr inbounds double, double* %1, i64 5
%12 = getelementptr inbounds double, double* %1, i64 8
br label %13
13: ; preds = %2, %13
%14 = phi i64 [ 0, %2 ], [ %51, %13 ]
%15 = mul nuw nsw i64 %14, 3
%16 = getelementptr inbounds double, double* %0, i64 %15
%17 = getelementptr inbounds double, double* %4, i64 %15
store double 0.000000e+00, double* %17
%18 = load double, double* %16
%19 = load double, double* %1
%20 = tail call double @llvm.fmuladd.f64(double %18, double %19, double 0.000000e+00)
store double %20, double* %17
%21 = add nuw nsw i64 %15, 1
%22 = getelementptr inbounds double, double* %0, i64 %21
%23 = load double, double* %22
%24 = load double, double* %5
%25 = tail call double @llvm.fmuladd.f64(double %23, double %24, double %20)
store double %25, double* %17
%26 = add nuw nsw i64 %15, 2
%27 = getelementptr inbounds double, double* %0, i64 %26
%28 = load double, double* %27
%29 = load double, double* %6
%30 = tail call double @llvm.fmuladd.f64(double %28, double %29, double %25)
store double %30, double* %17
%31 = getelementptr inbounds double, double* %4, i64 %21
store double 0.000000e+00, double* %31
%32 = load double, double* %16
%33 = load double, double* %7
%34 = tail call double @llvm.fmuladd.f64(double %32, double %33, double 0.000000e+00)
store double %34, double* %31
%35 = load double, double* %22
%36 = load double, double* %8
%37 = tail call double @llvm.fmuladd.f64(double %35, double %36, double %34)
store double %37, double* %31
%38 = load double, double* %27
%39 = load double, double* %9
%40 = tail call double @llvm.fmuladd.f64(double %38, double %39, double %37)
store double %40, double* %31
%41 = getelementptr inbounds double, double* %4, i64 %26
store double 0.000000e+00, double* %41
%42 = load double, double* %16
%43 = load double, double* %10
%44 = tail call double @llvm.fmuladd.f64(double %42, double %43, double 0.000000e+00)
store double %44, double* %41
%45 = load double, double* %22
%46 = load double, double* %11
%47 = tail call double @llvm.fmuladd.f64(double %45, double %46, double %44)
store double %47, double* %41
%48 = load double, double* %27
%49 = load double, double* %12
%50 = tail call double @llvm.fmuladd.f64(double %48, double %49, double %47)
store double %50, double* %41
%51 = add nuw nsw i64 %14, 1
%52 = icmp eq i64 %51, 3
br i1 %52, label %53, label %13
53: ; preds = %13
ret double* %4
}