#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 */
int /*<<< orphan*/ mat_cast_matrix_3d_to_3l(long **, double **);
int /*<<< orphan*/ mat_cast_matrix_3l_to_3d(double **, long **);
int /*<<< orphan*/ mat_check_identity_matrix_ld3(long **, double **, int);
int /*<<< orphan*/ mat_get_similar_matrix_ld3(double **, long **, double **,
                                              int /*<<< orphan*/);
int grg_transform_rotations(long (*transformed_rots)[3][3],
                            long (*rotations)[3][3], const int num_rot,
                            const long D_diag[3], long Q[3][3]) {
  int i, j, k;
  double r[3][3], Q_double[3][3];
  mat_cast_matrix_3l_to_3d(Q_double, Q);
  for (i = 0; i < num_rot; i++) {
    mat_get_similar_matrix_ld3(r, rotations[i], Q_double, 0);
    for (j = 0; j < 3; j++) {
      for (k = 0; k < 3; k++) {
        r[j][k] *= D_diag[j];
        r[j][k] /= D_diag[k];
      }
    }
    mat_cast_matrix_3d_to_3l(transformed_rots[i], r);
    if (!mat_check_identity_matrix_ld3(transformed_rots[i], r, 1e-5)) {
      return 0;
    }
  }
  return 1;
}


x86 assembly (clang, -O0):
<grg_transform_rotations>:
push   %rbp
mov    %rsp,%rbp
sub    $0xe0,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
mov    %rcx,-0x28(%rbp)
mov    %r8,-0x30(%rbp)
lea    -0xe0(%rbp),%rdi
mov    -0x30(%rbp),%rsi
call   1060 <mat_cast_matrix_3l_to_3d@plt>
movl   $0x0,-0x34(%rbp)
mov    -0x34(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jge    12a8 <grg_transform_rotations+0x168>
lea    -0x90(%rbp),%rdi
mov    -0x18(%rbp),%rsi
movslq -0x34(%rbp),%rax
imul   $0x48,%rax,%rax
add    %rax,%rsi
lea    -0xe0(%rbp),%rdx
xor    %ecx,%ecx
call   1040 <mat_get_similar_matrix_ld3@plt>
movl   $0x0,-0x38(%rbp)
cmpl   $0x3,-0x38(%rbp)
jge    1248 <grg_transform_rotations+0x108>
movl   $0x0,-0x3c(%rbp)
cmpl   $0x3,-0x3c(%rbp)
jge    1235 <grg_transform_rotations+0xf5>
mov    -0x28(%rbp),%rax
movslq -0x38(%rbp),%rcx
cvtsi2sdq (%rax,%rcx,8),%xmm0
movslq -0x38(%rbp),%rcx
lea    -0x90(%rbp),%rax
imul   $0x18,%rcx,%rcx
add    %rcx,%rax
movslq -0x3c(%rbp),%rcx
mulsd  (%rax,%rcx,8),%xmm0
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x28(%rbp),%rax
movslq -0x3c(%rbp),%rcx
cvtsi2sdq (%rax,%rcx,8),%xmm1
movslq -0x38(%rbp),%rcx
lea    -0x90(%rbp),%rax
imul   $0x18,%rcx,%rcx
add    %rcx,%rax
movslq -0x3c(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
divsd  %xmm1,%xmm0
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x3c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x3c(%rbp)
jmp    11bd <grg_transform_rotations+0x7d>
jmp    123a <grg_transform_rotations+0xfa>
mov    -0x38(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x38(%rbp)
jmp    11ac <grg_transform_rotations+0x6c>
mov    -0x10(%rbp),%rdi
movslq -0x34(%rbp),%rax
imul   $0x48,%rax,%rax
add    %rax,%rdi
lea    -0x90(%rbp),%rsi
call   1030 <mat_cast_matrix_3d_to_3l@plt>
mov    -0x10(%rbp),%rdi
movslq -0x34(%rbp),%rax
imul   $0x48,%rax,%rax
add    %rax,%rdi
lea    -0x90(%rbp),%rsi
xor    %edx,%edx
call   1050 <mat_check_identity_matrix_ld3@plt>
cmp    $0x0,%eax
jne    1295 <grg_transform_rotations+0x155>
movl   $0x0,-0x4(%rbp)
jmp    12af <grg_transform_rotations+0x16f>
jmp    129a <grg_transform_rotations+0x15a>
mov    -0x34(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x34(%rbp)
jmp    1175 <grg_transform_rotations+0x35>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0xe0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<grg_transform_rotations>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x98,%rsp
mov    %rcx,%r14
mov    %edx,%ebp
mov    %rsi,%r15
mov    %rdi,%rbx
lea    0x50(%rsp),%rdi
mov    %r8,%rsi
call   1060 <mat_cast_matrix_3l_to_3d@plt>
test   %ebp,%ebp
jle    126f <grg_transform_rotations+0x12f>
mov    %ebp,%r13d
mov    %rsp,%r12
xor    %ebp,%ebp
nopl   0x0(%rax)
mov    %r12,%rdi
mov    %r15,%rsi
lea    0x50(%rsp),%rdx
xor    %ecx,%ecx
call   1040 <mat_get_similar_matrix_ld3@plt>
movdqu (%r14),%xmm0
pshufd $0xee,%xmm0,%xmm1
movq   %xmm1,%rax
xorps  %xmm1,%xmm1
cvtsi2sd %rax,%xmm1
movq   %xmm0,%rax
xorps  %xmm0,%xmm0
cvtsi2sd %rax,%xmm0
movapd %xmm0,%xmm2
unpcklpd %xmm1,%xmm2
movapd %xmm0,%xmm3
unpcklpd %xmm0,%xmm3
mulpd  (%rsp),%xmm3
divpd  %xmm2,%xmm3
movapd %xmm3,(%rsp)
xorps  %xmm3,%xmm3
cvtsi2sdq 0x10(%r14),%xmm3
movapd 0x10(%rsp),%xmm4
mulpd  %xmm2,%xmm4
movapd %xmm3,%xmm5
unpcklpd %xmm0,%xmm5
divpd  %xmm5,%xmm4
movapd %xmm4,0x10(%rsp)
movapd %xmm1,%xmm0
unpcklpd %xmm1,%xmm0
mulpd  0x20(%rsp),%xmm0
unpcklpd %xmm3,%xmm1
divpd  %xmm1,%xmm0
movapd %xmm0,0x20(%rsp)
movapd %xmm3,%xmm0
unpcklpd %xmm3,%xmm0
mulpd  0x30(%rsp),%xmm0
divpd  %xmm2,%xmm0
movapd %xmm0,0x30(%rsp)
movsd  0x40(%rsp),%xmm0
mulsd  %xmm3,%xmm0
divsd  %xmm3,%xmm0
movsd  %xmm0,0x40(%rsp)
mov    %rbx,%rdi
mov    %r12,%rsi
call   1030 <mat_cast_matrix_3d_to_3l@plt>
mov    %rbx,%rdi
mov    %r12,%rsi
xor    %edx,%edx
call   1050 <mat_check_identity_matrix_ld3@plt>
test   %eax,%eax
je     1274 <grg_transform_rotations+0x134>
add    $0x48,%r15
add    $0x48,%rbx
add    $0xffffffffffffffff,%r13
jne    1180 <grg_transform_rotations+0x40>
mov    $0x1,%ebp
mov    %ebp,%eax
add    $0x98,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @grg_transform_rotations([3 x [3 x i64]]* %0, [3 x [3 x i64]]* %1, i32 %2, i64* %3, [3 x i64]* %4) {
%6 = alloca i32
%7 = alloca [3 x [3 x i64]]*
%8 = alloca [3 x [3 x i64]]*
%9 = alloca i32
%10 = alloca i64*
%11 = alloca [3 x i64]*
%12 = alloca i32
%13 = alloca i32
%14 = alloca i32
%15 = alloca [3 x [3 x double]]
%16 = alloca [3 x [3 x double]]
store [3 x [3 x i64]]* %0, [3 x [3 x i64]]** %7
store [3 x [3 x i64]]* %1, [3 x [3 x i64]]** %8
store i32 %2, i32* %9
store i64* %3, i64** %10
store [3 x i64]* %4, [3 x i64]** %11
%17 = getelementptr inbounds [3 x [3 x double]], [3 x [3 x double]]* %16, i64 0, i64 0
%18 = bitcast [3 x double]* %17 to double**
%19 = load [3 x i64]*, [3 x i64]** %11
%20 = bitcast [3 x i64]* %19 to i64**
%21 = call i32 @mat_cast_matrix_3l_to_3d(double** %18, i64** %20)
store i32 0, i32* %12
br label %22
22: ; preds = %103, %5
%23 = load i32, i32* %12
%24 = load i32, i32* %9
%25 = icmp slt i32 %23, %24
br i1 %25, label %26, label %106
26: ; preds = %22
%27 = getelementptr inbounds [3 x [3 x double]], [3 x [3 x double]]* %15, i64 0, i64 0
%28 = bitcast [3 x double]* %27 to double**
%29 = load [3 x [3 x i64]]*, [3 x [3 x i64]]** %8
%30 = load i32, i32* %12
%31 = sext i32 %30 to i64
%32 = getelementptr inbounds [3 x [3 x i64]], [3 x [3 x i64]]* %29, i64 %31
%33 = getelementptr inbounds [3 x [3 x i64]], [3 x [3 x i64]]* %32, i64 0, i64 0
%34 = bitcast [3 x i64]* %33 to i64**
%35 = getelementptr inbounds [3 x [3 x double]], [3 x [3 x double]]* %16, i64 0, i64 0
%36 = bitcast [3 x double]* %35 to double**
%37 = call i32 @mat_get_similar_matrix_ld3(double** %28, i64** %34, double** %36, i32 0)
store i32 0, i32* %13
br label %38
38: ; preds = %78, %26
%39 = load i32, i32* %13
%40 = icmp slt i32 %39, 3
br i1 %40, label %41, label %81
41: ; preds = %38
store i32 0, i32* %14
br label %42
42: ; preds = %74, %41
%43 = load i32, i32* %14
%44 = icmp slt i32 %43, 3
br i1 %44, label %45, label %77
45: ; preds = %42
%46 = load i64*, i64** %10
%47 = load i32, i32* %13
%48 = sext i32 %47 to i64
%49 = getelementptr inbounds i64, i64* %46, i64 %48
%50 = load i64, i64* %49
%51 = sitofp i64 %50 to double
%52 = load i32, i32* %13
%53 = sext i32 %52 to i64
%54 = getelementptr inbounds [3 x [3 x double]], [3 x [3 x double]]* %15, i64 0, i64 %53
%55 = load i32, i32* %14
%56 = sext i32 %55 to i64
%57 = getelementptr inbounds [3 x double], [3 x double]* %54, i64 0, i64 %56
%58 = load double, double* %57
%59 = fmul double %58, %51
store double %59, double* %57
%60 = load i64*, i64** %10
%61 = load i32, i32* %14
%62 = sext i32 %61 to i64
%63 = getelementptr inbounds i64, i64* %60, i64 %62
%64 = load i64, i64* %63
%65 = sitofp i64 %64 to double
%66 = load i32, i32* %13
%67 = sext i32 %66 to i64
%68 = getelementptr inbounds [3 x [3 x double]], [3 x [3 x double]]* %15, i64 0, i64 %67
%69 = load i32, i32* %14
%70 = sext i32 %69 to i64
%71 = getelementptr inbounds [3 x double], [3 x double]* %68, i64 0, i64 %70
%72 = load double, double* %71
%73 = fdiv double %72, %65
store double %73, double* %71
br label %74
74: ; preds = %45
%75 = load i32, i32* %14
%76 = add nsw i32 %75, 1
store i32 %76, i32* %14
br label %42
77: ; preds = %42
br label %78
78: ; preds = %77
%79 = load i32, i32* %13
%80 = add nsw i32 %79, 1
store i32 %80, i32* %13
br label %38
81: ; preds = %38
%82 = load [3 x [3 x i64]]*, [3 x [3 x i64]]** %7
%83 = load i32, i32* %12
%84 = sext i32 %83 to i64
%85 = getelementptr inbounds [3 x [3 x i64]], [3 x [3 x i64]]* %82, i64 %84
%86 = getelementptr inbounds [3 x [3 x i64]], [3 x [3 x i64]]* %85, i64 0, i64 0
%87 = bitcast [3 x i64]* %86 to i64**
%88 = getelementptr inbounds [3 x [3 x double]], [3 x [3 x double]]* %15, i64 0, i64 0
%89 = bitcast [3 x double]* %88 to double**
%90 = call i32 @mat_cast_matrix_3d_to_3l(i64** %87, double** %89)
%91 = load [3 x [3 x i64]]*, [3 x [3 x i64]]** %7
%92 = load i32, i32* %12
%93 = sext i32 %92 to i64
%94 = getelementptr inbounds [3 x [3 x i64]], [3 x [3 x i64]]* %91, i64 %93
%95 = getelementptr inbounds [3 x [3 x i64]], [3 x [3 x i64]]* %94, i64 0, i64 0
%96 = bitcast [3 x i64]* %95 to i64**
%97 = getelementptr inbounds [3 x [3 x double]], [3 x [3 x double]]* %15, i64 0, i64 0
%98 = bitcast [3 x double]* %97 to double**
%99 = call i32 @mat_check_identity_matrix_ld3(i64** %96, double** %98, i32 0)
%100 = icmp ne i32 %99, 0
br i1 %100, label %102, label %101
101: ; preds = %81
store i32 0, i32* %6
br label %107
102: ; preds = %81
br label %103
103: ; preds = %102
%104 = load i32, i32* %12
%105 = add nsw i32 %104, 1
store i32 %105, i32* %12
br label %22
106: ; preds = %22
store i32 1, i32* %6
br label %107
107: ; preds = %106, %101
%108 = load i32, i32* %6
ret i32 %108
}

LLVM IR (-O2):
define i32 @grg_transform_rotations([3 x [3 x i64]]* %0, [3 x [3 x i64]]* %1, i32 %2, i64* nocapture %3, [3 x i64]* %4) {
%6 = alloca [3 x [3 x double]]
%7 = alloca [3 x [3 x double]]
%8 = bitcast [3 x [3 x double]]* %6 to i8*
%9 = bitcast [3 x [3 x double]]* %7 to i8*
%10 = bitcast [3 x [3 x double]]* %7 to double**
%11 = bitcast [3 x i64]* %4 to i64**
%12 = call i32 @mat_cast_matrix_3l_to_3d(double** %10, i64** %11)
%13 = icmp sgt i32 %2, 0
br i1 %13, label %14, label %70
14: ; preds = %5
%15 = bitcast [3 x [3 x double]]* %6 to double**
%16 = getelementptr inbounds [3 x [3 x double]], [3 x [3 x double]]* %6, i64 0, i64 2, i64 0
%17 = zext i32 %2 to i64
%18 = getelementptr inbounds [3 x [3 x double]], [3 x [3 x double]]* %6, i64 0, i64 0, i64 2
%19 = getelementptr inbounds i64, i64* %3, i64 2
%20 = getelementptr inbounds [3 x [3 x double]], [3 x [3 x double]]* %6, i64 0, i64 1, i64 1
%21 = getelementptr inbounds [3 x [3 x double]], [3 x [3 x double]]* %6, i64 0, i64 2, i64 2
%22 = bitcast [3 x [3 x double]]* %6 to <2 x double>*
%23 = bitcast i64* %3 to <2 x i64>*
%24 = bitcast [3 x [3 x double]]* %6 to <2 x double>*
%25 = bitcast double* %18 to <2 x double>*
%26 = bitcast double* %18 to <2 x double>*
%27 = bitcast double* %20 to <2 x double>*
%28 = bitcast double* %20 to <2 x double>*
%29 = bitcast double* %16 to <2 x double>*
%30 = bitcast double* %16 to <2 x double>*
br label %33
31: ; preds = %33
%32 = icmp eq i64 %69, %17
br i1 %32, label %70, label %33
33: ; preds = %14, %31
%34 = phi i64 [ 0, %14 ], [ %69, %31 ]
%35 = getelementptr inbounds [3 x [3 x i64]], [3 x [3 x i64]]* %1, i64 %34, i64 0
%36 = bitcast [3 x i64]* %35 to i64**
%37 = call i32 @mat_get_similar_matrix_ld3(double** %15, i64** %36, double** %10, i32 0)
%38 = load <2 x double>, <2 x double>* %22
%39 = load <2 x i64>, <2 x i64>* %23
%40 = sitofp <2 x i64> %39 to <2 x double>
%41 = shufflevector <2 x double> %40, <2 x double> undef, <2 x i32> zeroinitializer
%42 = fmul <2 x double> %38, %41
%43 = fdiv <2 x double> %42, %40
store <2 x double> %43, <2 x double>* %24
%44 = load i64, i64* %19
%45 = sitofp i64 %44 to double
%46 = load <2 x double>, <2 x double>* %25
%47 = fmul <2 x double> %46, %40
%48 = insertelement <2 x double> poison, double %45, i64 0
%49 = shufflevector <2 x double> %48, <2 x double> %40, <2 x i32> <i32 0, i32 2>
%50 = fdiv <2 x double> %47, %49
store <2 x double> %50, <2 x double>* %26
%51 = load <2 x double>, <2 x double>* %27
%52 = shufflevector <2 x double> %40, <2 x double> undef, <2 x i32> <i32 1, i32 undef>
%53 = shufflevector <2 x double> %40, <2 x double> poison, <2 x i32> <i32 1, i32 1>
%54 = fmul <2 x double> %51, %53
%55 = insertelement <2 x double> %52, double %45, i64 1
%56 = fdiv <2 x double> %54, %55
store <2 x double> %56, <2 x double>* %28
%57 = load <2 x double>, <2 x double>* %29
%58 = shufflevector <2 x double> %48, <2 x double> poison, <2 x i32> zeroinitializer
%59 = fmul <2 x double> %57, %58
%60 = fdiv <2 x double> %59, %40
store <2 x double> %60, <2 x double>* %30
%61 = load double, double* %21
%62 = fmul double %61, %45
%63 = fdiv double %62, %45
store double %63, double* %21
%64 = getelementptr inbounds [3 x [3 x i64]], [3 x [3 x i64]]* %0, i64 %34, i64 0
%65 = bitcast [3 x i64]* %64 to i64**
%66 = call i32 @mat_cast_matrix_3d_to_3l(i64** %65, double** %15)
%67 = call i32 @mat_check_identity_matrix_ld3(i64** %65, double** %15, i32 0)
%68 = icmp eq i32 %67, 0
%69 = add nuw nsw i64 %34, 1
br i1 %68, label %70, label %31
70: ; preds = %33, %31, %5
%71 = phi i32 [ 1, %5 ], [ 1, %31 ], [ 0, %33 ]
ret i32 %71
}