#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 */
double cos(double);
int /*<<< orphan*/ mat3_mul(double **, double **, double **);
int /*<<< orphan*/ memset(double **, int /*<<< orphan*/, int);
double sin(double);
void test_mat_rot(double R[3][3], double a1, double a2, double a3) {
  double R1[3][3], R2[3][3], R3[3][3];
  double c1, s1, c2, s2, c3, s3;
  s1 = sin(a1);
  s2 = sin(a2);
  s3 = sin(a3);
  c1 = cos(a1);
  c2 = cos(a2);
  c3 = cos(a3);
  memset(R1, 0, sizeof(double) * 3 * 3);
  memset(R2, 0, sizeof(double) * 3 * 3);
  memset(R3, 0, sizeof(double) * 3 * 3);
  R1[0][0] = 1.;
  R1[1][1] = c1;
  R1[1][2] = -s1;
  R1[2][1] = s1;
  R1[2][2] = c1;
  R2[0][0] = c2;
  R2[0][2] = s2;
  R2[1][1] = 1.;
  R2[2][0] = -s2;
  R2[2][2] = c2;
  R3[0][0] = c3;
  R3[0][1] = -s3;
  R3[1][0] = s3;
  R3[1][1] = c3;
  R3[2][2] = 1.;
  mat3_mul(R, R1, R2);
  mat3_mul(R, R, R3);
}


x86 assembly (clang, -O0):
<test_mat_rot>:
push   %rbp
mov    %rsp,%rbp
sub    $0x140,%rsp
mov    %rdi,-0x8(%rbp)
movsd  %xmm0,-0x10(%rbp)
movsd  %xmm1,-0x18(%rbp)
movsd  %xmm2,-0x20(%rbp)
movsd  -0x10(%rbp),%xmm0
call   1050 <sin@plt>
movsd  %xmm0,-0x120(%rbp)
ff
movsd  -0x18(%rbp),%xmm0
call   1050 <sin@plt>
movsd  %xmm0,-0x130(%rbp)
ff
movsd  -0x20(%rbp),%xmm0
call   1050 <sin@plt>
movsd  %xmm0,-0x140(%rbp)
ff
movsd  -0x10(%rbp),%xmm0
call   1060 <cos@plt>
movsd  %xmm0,-0x118(%rbp)
ff
movsd  -0x18(%rbp),%xmm0
call   1060 <cos@plt>
movsd  %xmm0,-0x128(%rbp)
ff
movsd  -0x20(%rbp),%xmm0
call   1060 <cos@plt>
movsd  %xmm0,-0x138(%rbp)
ff
lea    -0x70(%rbp),%rdi
xor    %esi,%esi
mov    $0x48,%edx
call   1040 <memset@plt>
lea    -0xc0(%rbp),%rdi
xor    %esi,%esi
mov    $0x48,%edx
call   1040 <memset@plt>
lea    -0x110(%rbp),%rdi
xor    %esi,%esi
mov    $0x48,%edx
call   1040 <memset@plt>
movsd  0xdf8(%rip),%xmm0
movsd  %xmm0,-0x70(%rbp)
movsd  -0x118(%rbp),%xmm0
ff
movsd  %xmm0,-0x50(%rbp)
movsd  -0x120(%rbp),%xmm0
ff
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
movsd  %xmm0,-0x48(%rbp)
movsd  -0x120(%rbp),%xmm0
ff
movsd  %xmm0,-0x38(%rbp)
movsd  -0x118(%rbp),%xmm0
ff
movsd  %xmm0,-0x30(%rbp)
movsd  -0x128(%rbp),%xmm0
ff
movsd  %xmm0,-0xc0(%rbp)
ff
movsd  -0x130(%rbp),%xmm0
ff
movsd  %xmm0,-0xb0(%rbp)
ff
movsd  0xd80(%rip),%xmm0
movsd  %xmm0,-0xa0(%rbp)
ff
movsd  -0x130(%rbp),%xmm0
ff
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
movsd  %xmm0,-0x90(%rbp)
ff
movsd  -0x128(%rbp),%xmm0
ff
movsd  %xmm0,-0x80(%rbp)
movsd  -0x138(%rbp),%xmm0
ff
movsd  %xmm0,-0x110(%rbp)
ff
movsd  -0x140(%rbp),%xmm0
ff
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
movsd  %xmm0,-0x108(%rbp)
ff
movsd  -0x140(%rbp),%xmm0
ff
movsd  %xmm0,-0xf8(%rbp)
ff
movsd  -0x138(%rbp),%xmm0
ff
movsd  %xmm0,-0xf0(%rbp)
ff
movsd  0xce5(%rip),%xmm0
movsd  %xmm0,-0xd0(%rbp)
ff
mov    -0x8(%rbp),%rdi
lea    -0x70(%rbp),%rsi
lea    -0xc0(%rbp),%rdx
call   1030 <mat3_mul@plt>
mov    -0x8(%rbp),%rdi
mov    -0x8(%rbp),%rsi
lea    -0x110(%rbp),%rdx
call   1030 <mat3_mul@plt>
add    $0x140,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<test_mat_rot>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x138,%rsp
movsd  %xmm2,0x10(%rsp)
movsd  %xmm1,0x8(%rsp)
movsd  %xmm0,0x18(%rsp)
mov    %rdi,%rbx
call   1050 <sin@plt>
movaps %xmm0,0x20(%rsp)
movsd  0x8(%rsp),%xmm0
call   1050 <sin@plt>
movaps %xmm0,0x30(%rsp)
movsd  0x10(%rsp),%xmm0
call   1050 <sin@plt>
movaps %xmm0,0x40(%rsp)
movsd  0x18(%rsp),%xmm0
call   1060 <cos@plt>
movsd  %xmm0,0x18(%rsp)
movsd  0x8(%rsp),%xmm0
call   1060 <cos@plt>
movsd  %xmm0,0x8(%rsp)
movsd  0x10(%rsp),%xmm0
call   1060 <cos@plt>
movsd  %xmm0,0x10(%rsp)
lea    0xf0(%rsp),%r14
mov    %r14,%rdi
xor    %esi,%esi
mov    $0x48,%edx
call   1040 <memset@plt>
lea    0xa0(%rsp),%r15
mov    %r15,%rdi
xor    %esi,%esi
mov    $0x48,%edx
call   1040 <memset@plt>
lea    0x50(%rsp),%r12
mov    %r12,%rdi
xor    %esi,%esi
mov    $0x48,%edx
call   1040 <memset@plt>
movabs $0x3ff0000000000000,%rax
mov    %rax,0xf0(%rsp)
movsd  0x18(%rsp),%xmm3
movsd  %xmm3,0x110(%rsp)
movaps 0xdd6(%rip),%xmm0
movaps 0x20(%rsp),%xmm2
movaps %xmm2,%xmm1
xorps  %xmm0,%xmm1
movlps %xmm1,0x118(%rsp)
movsd  %xmm2,0x128(%rsp)
movsd  %xmm3,0x130(%rsp)
movsd  0x8(%rsp),%xmm2
movsd  %xmm2,0xa0(%rsp)
movaps 0x30(%rsp),%xmm1
movsd  %xmm1,0xb0(%rsp)
mov    %rax,0xc0(%rsp)
xorps  %xmm0,%xmm1
movlps %xmm1,0xd0(%rsp)
movsd  %xmm2,0xe0(%rsp)
movsd  0x10(%rsp),%xmm2
movsd  %xmm2,0x50(%rsp)
movaps 0x40(%rsp),%xmm1
xorps  %xmm1,%xmm0
movlps %xmm0,0x58(%rsp)
movsd  %xmm1,0x68(%rsp)
movsd  %xmm2,0x70(%rsp)
mov    %rax,0x90(%rsp)
mov    %rbx,%rdi
mov    %r14,%rsi
mov    %r15,%rdx
call   1030 <mat3_mul@plt>
mov    %rbx,%rdi
mov    %rbx,%rsi
mov    %r12,%rdx
call   1030 <mat3_mul@plt>
add    $0x138,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define void @test_mat_rot([3 x double]* %0, double %1, double %2, double %3) {
%5 = alloca [3 x double]*
%6 = alloca double
%7 = alloca double
%8 = alloca double
%9 = alloca [3 x [3 x double]]
%10 = alloca [3 x [3 x double]]
%11 = alloca [3 x [3 x double]]
%12 = alloca double
%13 = alloca double
%14 = alloca double
%15 = alloca double
%16 = alloca double
%17 = alloca double
store [3 x double]* %0, [3 x double]** %5
store double %1, double* %6
store double %2, double* %7
store double %3, double* %8
%18 = load double, double* %6
%19 = call double @sin(double %18)
store double %19, double* %13
%20 = load double, double* %7
%21 = call double @sin(double %20)
store double %21, double* %15
%22 = load double, double* %8
%23 = call double @sin(double %22)
store double %23, double* %17
%24 = load double, double* %6
%25 = call double @cos(double %24)
store double %25, double* %12
%26 = load double, double* %7
%27 = call double @cos(double %26)
store double %27, double* %14
%28 = load double, double* %8
%29 = call double @cos(double %28)
store double %29, double* %16
%30 = getelementptr inbounds [3 x [3 x double]], [3 x [3 x double]]* %9, i64 0, i64 0
%31 = bitcast [3 x double]* %30 to double**
%32 = call i32 @memset(double** %31, i32 0, i32 72)
%33 = getelementptr inbounds [3 x [3 x double]], [3 x [3 x double]]* %10, i64 0, i64 0
%34 = bitcast [3 x double]* %33 to double**
%35 = call i32 @memset(double** %34, i32 0, i32 72)
%36 = getelementptr inbounds [3 x [3 x double]], [3 x [3 x double]]* %11, i64 0, i64 0
%37 = bitcast [3 x double]* %36 to double**
%38 = call i32 @memset(double** %37, i32 0, i32 72)
%39 = getelementptr inbounds [3 x [3 x double]], [3 x [3 x double]]* %9, i64 0, i64 0
%40 = getelementptr inbounds [3 x double], [3 x double]* %39, i64 0, i64 0
store double 1.000000e+00, double* %40
%41 = load double, double* %12
%42 = getelementptr inbounds [3 x [3 x double]], [3 x [3 x double]]* %9, i64 0, i64 1
%43 = getelementptr inbounds [3 x double], [3 x double]* %42, i64 0, i64 1
store double %41, double* %43
%44 = load double, double* %13
%45 = fneg double %44
%46 = getelementptr inbounds [3 x [3 x double]], [3 x [3 x double]]* %9, i64 0, i64 1
%47 = getelementptr inbounds [3 x double], [3 x double]* %46, i64 0, i64 2
store double %45, double* %47
%48 = load double, double* %13
%49 = getelementptr inbounds [3 x [3 x double]], [3 x [3 x double]]* %9, i64 0, i64 2
%50 = getelementptr inbounds [3 x double], [3 x double]* %49, i64 0, i64 1
store double %48, double* %50
%51 = load double, double* %12
%52 = getelementptr inbounds [3 x [3 x double]], [3 x [3 x double]]* %9, i64 0, i64 2
%53 = getelementptr inbounds [3 x double], [3 x double]* %52, i64 0, i64 2
store double %51, double* %53
%54 = load double, double* %14
%55 = getelementptr inbounds [3 x [3 x double]], [3 x [3 x double]]* %10, i64 0, i64 0
%56 = getelementptr inbounds [3 x double], [3 x double]* %55, i64 0, i64 0
store double %54, double* %56
%57 = load double, double* %15
%58 = getelementptr inbounds [3 x [3 x double]], [3 x [3 x double]]* %10, i64 0, i64 0
%59 = getelementptr inbounds [3 x double], [3 x double]* %58, i64 0, i64 2
store double %57, double* %59
%60 = getelementptr inbounds [3 x [3 x double]], [3 x [3 x double]]* %10, i64 0, i64 1
%61 = getelementptr inbounds [3 x double], [3 x double]* %60, i64 0, i64 1
store double 1.000000e+00, double* %61
%62 = load double, double* %15
%63 = fneg double %62
%64 = getelementptr inbounds [3 x [3 x double]], [3 x [3 x double]]* %10, i64 0, i64 2
%65 = getelementptr inbounds [3 x double], [3 x double]* %64, i64 0, i64 0
store double %63, double* %65
%66 = load double, double* %14
%67 = getelementptr inbounds [3 x [3 x double]], [3 x [3 x double]]* %10, i64 0, i64 2
%68 = getelementptr inbounds [3 x double], [3 x double]* %67, i64 0, i64 2
store double %66, double* %68
%69 = load double, double* %16
%70 = getelementptr inbounds [3 x [3 x double]], [3 x [3 x double]]* %11, i64 0, i64 0
%71 = getelementptr inbounds [3 x double], [3 x double]* %70, i64 0, i64 0
store double %69, double* %71
%72 = load double, double* %17
%73 = fneg double %72
%74 = getelementptr inbounds [3 x [3 x double]], [3 x [3 x double]]* %11, i64 0, i64 0
%75 = getelementptr inbounds [3 x double], [3 x double]* %74, i64 0, i64 1
store double %73, double* %75
%76 = load double, double* %17
%77 = getelementptr inbounds [3 x [3 x double]], [3 x [3 x double]]* %11, i64 0, i64 1
%78 = getelementptr inbounds [3 x double], [3 x double]* %77, i64 0, i64 0
store double %76, double* %78
%79 = load double, double* %16
%80 = getelementptr inbounds [3 x [3 x double]], [3 x [3 x double]]* %11, i64 0, i64 1
%81 = getelementptr inbounds [3 x double], [3 x double]* %80, i64 0, i64 1
store double %79, double* %81
%82 = getelementptr inbounds [3 x [3 x double]], [3 x [3 x double]]* %11, i64 0, i64 2
%83 = getelementptr inbounds [3 x double], [3 x double]* %82, i64 0, i64 2
store double 1.000000e+00, double* %83
%84 = load [3 x double]*, [3 x double]** %5
%85 = bitcast [3 x double]* %84 to double**
%86 = getelementptr inbounds [3 x [3 x double]], [3 x [3 x double]]* %9, i64 0, i64 0
%87 = bitcast [3 x double]* %86 to double**
%88 = getelementptr inbounds [3 x [3 x double]], [3 x [3 x double]]* %10, i64 0, i64 0
%89 = bitcast [3 x double]* %88 to double**
%90 = call i32 @mat3_mul(double** %85, double** %87, double** %89)
%91 = load [3 x double]*, [3 x double]** %5
%92 = bitcast [3 x double]* %91 to double**
%93 = load [3 x double]*, [3 x double]** %5
%94 = bitcast [3 x double]* %93 to double**
%95 = getelementptr inbounds [3 x [3 x double]], [3 x [3 x double]]* %11, i64 0, i64 0
%96 = bitcast [3 x double]* %95 to double**
%97 = call i32 @mat3_mul(double** %92, double** %94, double** %96)
ret void
}

LLVM IR (-O2):
define void @test_mat_rot([3 x double]* %0, double %1, double %2, double %3) {
%5 = alloca [3 x [3 x double]]
%6 = alloca [3 x [3 x double]]
%7 = alloca [3 x [3 x double]]
%8 = bitcast [3 x [3 x double]]* %5 to i8*
%9 = bitcast [3 x [3 x double]]* %6 to i8*
%10 = bitcast [3 x [3 x double]]* %7 to i8*
%11 = tail call double @sin(double %1)
%12 = tail call double @sin(double %2)
%13 = tail call double @sin(double %3)
%14 = tail call double @cos(double %1)
%15 = tail call double @cos(double %2)
%16 = tail call double @cos(double %3)
%17 = bitcast [3 x [3 x double]]* %5 to double**
%18 = call i32 @memset(double** %17, i32 0, i32 72)
%19 = bitcast [3 x [3 x double]]* %6 to double**
%20 = call i32 @memset(double** %19, i32 0, i32 72)
%21 = bitcast [3 x [3 x double]]* %7 to double**
%22 = call i32 @memset(double** %21, i32 0, i32 72)
%23 = getelementptr inbounds [3 x [3 x double]], [3 x [3 x double]]* %5, i64 0, i64 0, i64 0
store double 1.000000e+00, double* %23
%24 = getelementptr inbounds [3 x [3 x double]], [3 x [3 x double]]* %5, i64 0, i64 1, i64 1
store double %14, double* %24
%25 = fneg double %11
%26 = getelementptr inbounds [3 x [3 x double]], [3 x [3 x double]]* %5, i64 0, i64 1, i64 2
store double %25, double* %26
%27 = getelementptr inbounds [3 x [3 x double]], [3 x [3 x double]]* %5, i64 0, i64 2, i64 1
store double %11, double* %27
%28 = getelementptr inbounds [3 x [3 x double]], [3 x [3 x double]]* %5, i64 0, i64 2, i64 2
store double %14, double* %28
%29 = getelementptr inbounds [3 x [3 x double]], [3 x [3 x double]]* %6, i64 0, i64 0, i64 0
store double %15, double* %29
%30 = getelementptr inbounds [3 x [3 x double]], [3 x [3 x double]]* %6, i64 0, i64 0, i64 2
store double %12, double* %30
%31 = getelementptr inbounds [3 x [3 x double]], [3 x [3 x double]]* %6, i64 0, i64 1, i64 1
store double 1.000000e+00, double* %31
%32 = fneg double %12
%33 = getelementptr inbounds [3 x [3 x double]], [3 x [3 x double]]* %6, i64 0, i64 2, i64 0
store double %32, double* %33
%34 = getelementptr inbounds [3 x [3 x double]], [3 x [3 x double]]* %6, i64 0, i64 2, i64 2
store double %15, double* %34
%35 = getelementptr inbounds [3 x [3 x double]], [3 x [3 x double]]* %7, i64 0, i64 0, i64 0
store double %16, double* %35
%36 = fneg double %13
%37 = getelementptr inbounds [3 x [3 x double]], [3 x [3 x double]]* %7, i64 0, i64 0, i64 1
store double %36, double* %37
%38 = getelementptr inbounds [3 x [3 x double]], [3 x [3 x double]]* %7, i64 0, i64 1, i64 0
store double %13, double* %38
%39 = getelementptr inbounds [3 x [3 x double]], [3 x [3 x double]]* %7, i64 0, i64 1, i64 1
store double %16, double* %39
%40 = getelementptr inbounds [3 x [3 x double]], [3 x [3 x double]]* %7, i64 0, i64 2, i64 2
store double 1.000000e+00, double* %40
%41 = bitcast [3 x double]* %0 to double**
%42 = call i32 @mat3_mul(double** %41, double** %17, double** %19)
%43 = call i32 @mat3_mul(double** %41, double** %41, double** %21)
ret void
}