#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 = NULL;
  if ((M = (double *)malloc(sizeof(double) * 9)) == NULL) {
    ;
    return NULL;
  }
  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,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
movq   $0x0,-0x30(%rbp)
mov    $0x48,%edi
call   1030 <malloc@plt>
mov    %rax,-0x30(%rbp)
cmp    $0x0,%rax
jne    114d <multiply_matrices+0x3d>
movq   $0x0,-0x8(%rbp)
jmp    1218 <multiply_matrices+0x108>
movl   $0x0,-0x1c(%rbp)
cmpl   $0x3,-0x1c(%rbp)
jge    1210 <multiply_matrices+0x100>
movl   $0x0,-0x20(%rbp)
cmpl   $0x3,-0x20(%rbp)
jge    11fd <multiply_matrices+0xed>
mov    -0x30(%rbp),%rax
imul   $0x3,-0x1c(%rbp),%ecx
add    -0x20(%rbp),%ecx
movslq %ecx,%rcx
xorps  %xmm0,%xmm0
movsd  %xmm0,(%rax,%rcx,8)
movl   $0x0,-0x24(%rbp)
cmpl   $0x3,-0x24(%rbp)
jge    11ea <multiply_matrices+0xda>
mov    -0x10(%rbp),%rax
imul   $0x3,-0x1c(%rbp),%ecx
add    -0x24(%rbp),%ecx
movslq %ecx,%rcx
movsd  (%rax,%rcx,8),%xmm0
mov    -0x18(%rbp),%rax
imul   $0x3,-0x24(%rbp),%ecx
add    -0x20(%rbp),%ecx
movslq %ecx,%rcx
movsd  (%rax,%rcx,8),%xmm2
mov    -0x30(%rbp),%rax
imul   $0x3,-0x1c(%rbp),%ecx
add    -0x20(%rbp),%ecx
movslq %ecx,%rcx
movsd  (%rax,%rcx,8),%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    118c <multiply_matrices+0x7c>
jmp    11ef <multiply_matrices+0xdf>
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    1165 <multiply_matrices+0x55>
jmp    1202 <multiply_matrices+0xf2>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1154 <multiply_matrices+0x44>
mov    -0x30(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%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>
test   %rax,%rax
je     1229 <multiply_matrices+0x119>
mov    $0x10,%ecx
xorpd  %xmm0,%xmm0
cs nopw 0x0(%rax,%rax,1)
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    1140 <multiply_matrices+0x30>
jmp    122b <multiply_matrices+0x11b>
xor    %eax,%eax
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 double*
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca double*
store double* %0, double** %4
store double* %1, double** %5
store double* null, double** %9
%10 = call i64 @malloc(i32 72)
%11 = inttoptr i64 %10 to double*
store double* %11, double** %9
%12 = icmp eq double* %11, null
br i1 %12, label %13, label %14
13: ; preds = %2
store double* null, double** %3
br label %72
14: ; preds = %2
store i32 0, i32* %6
br label %15
15: ; preds = %67, %14
%16 = load i32, i32* %6
%17 = icmp slt i32 %16, 3
br i1 %17, label %18, label %70
18: ; preds = %15
store i32 0, i32* %7
br label %19
19: ; preds = %63, %18
%20 = load i32, i32* %7
%21 = icmp slt i32 %20, 3
br i1 %21, label %22, label %66
22: ; preds = %19
%23 = load double*, double** %9
%24 = load i32, i32* %6
%25 = mul nsw i32 %24, 3
%26 = load i32, i32* %7
%27 = add nsw i32 %25, %26
%28 = sext i32 %27 to i64
%29 = getelementptr inbounds double, double* %23, i64 %28
store double 0.000000e+00, double* %29
store i32 0, i32* %8
br label %30
30: ; preds = %59, %22
%31 = load i32, i32* %8
%32 = icmp slt i32 %31, 3
br i1 %32, label %33, label %62
33: ; preds = %30
%34 = load double*, double** %4
%35 = load i32, i32* %6
%36 = mul nsw i32 %35, 3
%37 = load i32, i32* %8
%38 = add nsw i32 %36, %37
%39 = sext i32 %38 to i64
%40 = getelementptr inbounds double, double* %34, i64 %39
%41 = load double, double* %40
%42 = load double*, double** %5
%43 = load i32, i32* %8
%44 = mul nsw i32 %43, 3
%45 = load i32, i32* %7
%46 = add nsw i32 %44, %45
%47 = sext i32 %46 to i64
%48 = getelementptr inbounds double, double* %42, i64 %47
%49 = load double, double* %48
%50 = load double*, double** %9
%51 = load i32, i32* %6
%52 = mul nsw i32 %51, 3
%53 = load i32, i32* %7
%54 = add nsw i32 %52, %53
%55 = sext i32 %54 to i64
%56 = getelementptr inbounds double, double* %50, i64 %55
%57 = load double, double* %56
%58 = call double @llvm.fmuladd.f64(double %41, double %49, double %57)
store double %58, double* %56
br label %59
59: ; preds = %33
%60 = load i32, i32* %8
%61 = add nsw i32 %60, 1
store i32 %61, i32* %8
br label %30
62: ; preds = %30
br label %63
63: ; preds = %62
%64 = load i32, i32* %7
%65 = add nsw i32 %64, 1
store i32 %65, i32* %7
br label %19
66: ; preds = %19
br label %67
67: ; preds = %66
%68 = load i32, i32* %6
%69 = add nsw i32 %68, 1
store i32 %69, i32* %6
br label %15
70: ; preds = %15
%71 = load double*, double** %9
store double* %71, double** %3
br label %72
72: ; preds = %70, %13
%73 = load double*, double** %3
ret double* %73
}

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