#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*/ temp;
typedef size_t k;

/* Variables and functions */
double cos(double);
int /*<<< orphan*/ memcpy(double *, double const *, int);
double sin(double);
void cmatrix_mroty(double *mdest, const double *morg, double angle) {
  double temp[3 * 3];
  if (morg == mdest) {
    memcpy(temp, morg, sizeof(temp));
    morg = temp;
  }
  double cosa = cos(angle);
  double sina = sin(angle);
  for (int k = 1; k <= 3; k++) {
    mdest[((((1) - 1) * 3) + ((k)-1))] =
        cosa * morg[((((1) - 1) * 3) + ((k)-1))] +
        sina * morg[((((3) - 1) * 3) + ((k)-1))];
    mdest[((((2) - 1) * 3) + ((k)-1))] = morg[((((2) - 1) * 3) + ((k)-1))];
    mdest[((((3) - 1) * 3) + ((k)-1))] =
        -sina * morg[((((1) - 1) * 3) + ((k)-1))] +
        cosa * morg[((((3) - 1) * 3) + ((k)-1))];
  }
}


x86 assembly (clang, -O0):
<cmatrix_mroty>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movsd  %xmm0,-0x18(%rbp)
mov    -0x10(%rbp),%rax
cmp    -0x8(%rbp),%rax
jne    1170 <cmatrix_mroty+0x40>
lea    -0x60(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    $0x48,%edx
call   1040 <memcpy@plt>
lea    -0x60(%rbp),%rax
mov    %rax,-0x10(%rbp)
movsd  -0x18(%rbp),%xmm0
call   1050 <cos@plt>
movsd  %xmm0,-0x68(%rbp)
movsd  -0x18(%rbp),%xmm0
call   1030 <sin@plt>
movsd  %xmm0,-0x70(%rbp)
movl   $0x1,-0x74(%rbp)
cmpl   $0x3,-0x74(%rbp)
jg     1290 <cmatrix_mroty+0x160>
movsd  -0x68(%rbp),%xmm0
mov    -0x10(%rbp),%rax
mov    -0x74(%rbp),%ecx
sub    $0x1,%ecx
add    $0x0,%ecx
movslq %ecx,%rcx
movsd  (%rax,%rcx,8),%xmm2
movsd  -0x70(%rbp),%xmm1
mov    -0x10(%rbp),%rax
mov    -0x74(%rbp),%ecx
sub    $0x1,%ecx
add    $0x6,%ecx
movslq %ecx,%rcx
mulsd  (%rax,%rcx,8),%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
mov    -0x8(%rbp),%rax
mov    -0x74(%rbp),%ecx
sub    $0x1,%ecx
add    $0x0,%ecx
movslq %ecx,%rcx
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x10(%rbp),%rax
mov    -0x74(%rbp),%ecx
sub    $0x1,%ecx
add    $0x3,%ecx
movslq %ecx,%rcx
movsd  (%rax,%rcx,8),%xmm0
mov    -0x8(%rbp),%rax
mov    -0x74(%rbp),%ecx
sub    $0x1,%ecx
add    $0x3,%ecx
movslq %ecx,%rcx
movsd  %xmm0,(%rax,%rcx,8)
movsd  -0x70(%rbp),%xmm0
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
mov    -0x10(%rbp),%rax
mov    -0x74(%rbp),%ecx
sub    $0x1,%ecx
add    $0x0,%ecx
movslq %ecx,%rcx
movsd  (%rax,%rcx,8),%xmm2
movsd  -0x68(%rbp),%xmm1
mov    -0x10(%rbp),%rax
mov    -0x74(%rbp),%ecx
sub    $0x1,%ecx
add    $0x6,%ecx
movslq %ecx,%rcx
mulsd  (%rax,%rcx,8),%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
mov    -0x8(%rbp),%rax
mov    -0x74(%rbp),%ecx
sub    $0x1,%ecx
add    $0x6,%ecx
movslq %ecx,%rcx
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x74(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x74(%rbp)
jmp    1195 <cmatrix_mroty+0x65>
add    $0x80,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<cmatrix_mroty>:
push   %r15
push   %r14
push   %rbx
sub    $0x60,%rsp
mov    %rsi,%rbx
mov    %rdi,%r14
cmp    %rdi,%rsi
movsd  %xmm0,(%rsp)
jne    1166 <cmatrix_mroty+0x36>
lea    0x10(%rsp),%r15
mov    %r15,%rdi
mov    %rbx,%rsi
mov    $0x48,%edx
call   1040 <memcpy@plt>
movsd  (%rsp),%xmm0
mov    %r15,%rbx
call   1050 <cos@plt>
movsd  %xmm0,0x8(%rsp)
movsd  (%rsp),%xmm0
call   1030 <sin@plt>
movsd  0x30(%rbx),%xmm1
mulsd  %xmm0,%xmm1
movsd  (%rbx),%xmm2
movsd  0x8(%rsp),%xmm3
mulsd  %xmm3,%xmm2
addsd  %xmm1,%xmm2
movsd  %xmm2,(%r14)
movsd  0x18(%rbx),%xmm1
movsd  %xmm1,0x18(%r14)
movsd  0x30(%rbx),%xmm1
mulsd  %xmm3,%xmm1
movsd  (%rbx),%xmm2
mulsd  %xmm0,%xmm2
subsd  %xmm2,%xmm1
movsd  %xmm1,0x30(%r14)
movsd  0x38(%rbx),%xmm1
mulsd  %xmm0,%xmm1
movsd  0x8(%rbx),%xmm2
mulsd  %xmm3,%xmm2
addsd  %xmm1,%xmm2
movsd  %xmm2,0x8(%r14)
movsd  0x20(%rbx),%xmm1
movsd  %xmm1,0x20(%r14)
movsd  0x38(%rbx),%xmm1
mulsd  %xmm3,%xmm1
movsd  0x8(%rbx),%xmm2
mulsd  %xmm0,%xmm2
subsd  %xmm2,%xmm1
movsd  %xmm1,0x38(%r14)
movsd  0x40(%rbx),%xmm1
mulsd  %xmm0,%xmm1
movsd  0x10(%rbx),%xmm2
mulsd  %xmm3,%xmm2
addsd  %xmm1,%xmm2
movsd  %xmm2,0x10(%r14)
movsd  0x28(%rbx),%xmm1
movsd  %xmm1,0x28(%r14)
movapd %xmm3,%xmm1
mulsd  0x40(%rbx),%xmm1
mulsd  0x10(%rbx),%xmm0
subsd  %xmm0,%xmm1
movsd  %xmm1,0x40(%r14)
add    $0x60,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define void @cmatrix_mroty(double* %0, double* %1, double %2) {
%4 = alloca double*
%5 = alloca double*
%6 = alloca double
%7 = alloca [9 x double]
%8 = alloca double
%9 = alloca double
%10 = alloca i32
store double* %0, double** %4
store double* %1, double** %5
store double %2, double* %6
%11 = load double*, double** %5
%12 = load double*, double** %4
%13 = icmp eq double* %11, %12
br i1 %13, label %14, label %19
14: ; preds = %3
%15 = getelementptr inbounds [9 x double], [9 x double]* %7, i64 0, i64 0
%16 = load double*, double** %5
%17 = call i32 @memcpy(double* %15, double* %16, i32 72)
%18 = getelementptr inbounds [9 x double], [9 x double]* %7, i64 0, i64 0
store double* %18, double** %5
br label %19
19: ; preds = %14, %3
%20 = load double, double* %6
%21 = call double @cos(double %20)
store double %21, double* %8
%22 = load double, double* %6
%23 = call double @sin(double %22)
store double %23, double* %9
store i32 1, i32* %10
br label %24
24: ; preds = %90, %19
%25 = load i32, i32* %10
%26 = icmp sle i32 %25, 3
br i1 %26, label %27, label %93
27: ; preds = %24
%28 = load double, double* %8
%29 = load double*, double** %5
%30 = load i32, i32* %10
%31 = sub nsw i32 %30, 1
%32 = add nsw i32 0, %31
%33 = sext i32 %32 to i64
%34 = getelementptr inbounds double, double* %29, i64 %33
%35 = load double, double* %34
%36 = load double, double* %9
%37 = load double*, double** %5
%38 = load i32, i32* %10
%39 = sub nsw i32 %38, 1
%40 = add nsw i32 6, %39
%41 = sext i32 %40 to i64
%42 = getelementptr inbounds double, double* %37, i64 %41
%43 = load double, double* %42
%44 = fmul double %36, %43
%45 = call double @llvm.fmuladd.f64(double %28, double %35, double %44)
%46 = load double*, double** %4
%47 = load i32, i32* %10
%48 = sub nsw i32 %47, 1
%49 = add nsw i32 0, %48
%50 = sext i32 %49 to i64
%51 = getelementptr inbounds double, double* %46, i64 %50
store double %45, double* %51
%52 = load double*, double** %5
%53 = load i32, i32* %10
%54 = sub nsw i32 %53, 1
%55 = add nsw i32 3, %54
%56 = sext i32 %55 to i64
%57 = getelementptr inbounds double, double* %52, i64 %56
%58 = load double, double* %57
%59 = load double*, double** %4
%60 = load i32, i32* %10
%61 = sub nsw i32 %60, 1
%62 = add nsw i32 3, %61
%63 = sext i32 %62 to i64
%64 = getelementptr inbounds double, double* %59, i64 %63
store double %58, double* %64
%65 = load double, double* %9
%66 = fneg double %65
%67 = load double*, double** %5
%68 = load i32, i32* %10
%69 = sub nsw i32 %68, 1
%70 = add nsw i32 0, %69
%71 = sext i32 %70 to i64
%72 = getelementptr inbounds double, double* %67, i64 %71
%73 = load double, double* %72
%74 = load double, double* %8
%75 = load double*, double** %5
%76 = load i32, i32* %10
%77 = sub nsw i32 %76, 1
%78 = add nsw i32 6, %77
%79 = sext i32 %78 to i64
%80 = getelementptr inbounds double, double* %75, i64 %79
%81 = load double, double* %80
%82 = fmul double %74, %81
%83 = call double @llvm.fmuladd.f64(double %66, double %73, double %82)
%84 = load double*, double** %4
%85 = load i32, i32* %10
%86 = sub nsw i32 %85, 1
%87 = add nsw i32 6, %86
%88 = sext i32 %87 to i64
%89 = getelementptr inbounds double, double* %84, i64 %88
store double %83, double* %89
br label %90
90: ; preds = %27
%91 = load i32, i32* %10
%92 = add nsw i32 %91, 1
store i32 %92, i32* %10
br label %24
93: ; preds = %24
ret void
}

LLVM IR (-O2):
define void @cmatrix_mroty(double* writeonly %0, double* %1, double %2) {
%4 = alloca [9 x double]
%5 = bitcast [9 x double]* %4 to i8*
%6 = icmp eq double* %1, %0
br i1 %6, label %7, label %10
7: ; preds = %3
%8 = getelementptr inbounds [9 x double], [9 x double]* %4, i64 0, i64 0
%9 = call i32 @memcpy(double* %8, double* %1, i32 72)
br label %10
10: ; preds = %7, %3
%11 = phi double* [ %8, %7 ], [ %1, %3 ]
%12 = call double @cos(double %2)
%13 = call double @sin(double %2)
%14 = fneg double %13
%15 = load double, double* %11
%16 = getelementptr inbounds double, double* %11, i64 6
%17 = load double, double* %16
%18 = fmul double %13, %17
%19 = call double @llvm.fmuladd.f64(double %12, double %15, double %18)
store double %19, double* %0
%20 = getelementptr inbounds double, double* %11, i64 3
%21 = load double, double* %20
%22 = getelementptr inbounds double, double* %0, i64 3
store double %21, double* %22
%23 = load double, double* %11
%24 = load double, double* %16
%25 = fmul double %12, %24
%26 = call double @llvm.fmuladd.f64(double %14, double %23, double %25)
%27 = getelementptr inbounds double, double* %0, i64 6
store double %26, double* %27
%28 = getelementptr inbounds double, double* %11, i64 1
%29 = load double, double* %28
%30 = getelementptr inbounds double, double* %11, i64 7
%31 = load double, double* %30
%32 = fmul double %13, %31
%33 = call double @llvm.fmuladd.f64(double %12, double %29, double %32)
%34 = getelementptr inbounds double, double* %0, i64 1
store double %33, double* %34
%35 = getelementptr inbounds double, double* %11, i64 4
%36 = load double, double* %35
%37 = getelementptr inbounds double, double* %0, i64 4
store double %36, double* %37
%38 = load double, double* %28
%39 = load double, double* %30
%40 = fmul double %12, %39
%41 = call double @llvm.fmuladd.f64(double %14, double %38, double %40)
%42 = getelementptr inbounds double, double* %0, i64 7
store double %41, double* %42
%43 = getelementptr inbounds double, double* %11, i64 2
%44 = load double, double* %43
%45 = getelementptr inbounds double, double* %11, i64 8
%46 = load double, double* %45
%47 = fmul double %13, %46
%48 = call double @llvm.fmuladd.f64(double %12, double %44, double %47)
%49 = getelementptr inbounds double, double* %0, i64 2
store double %48, double* %49
%50 = getelementptr inbounds double, double* %11, i64 5
%51 = load double, double* %50
%52 = getelementptr inbounds double, double* %0, i64 5
store double %51, double* %52
%53 = load double, double* %43
%54 = load double, double* %45
%55 = fmul double %12, %54
%56 = call double @llvm.fmuladd.f64(double %14, double %53, double %55)
%57 = getelementptr inbounds double, double* %0, i64 8
store double %56, double* %57
ret void
}