#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*/ MatMatModM(double **, double **, double **, double);
void MatPowModM(double A[3][3], double B[3][3], double m, long n) {
  int i, j;
  double W[3][3];
  for (i = 0; i < 3; i++) {
    for (j = 0; j < 3; ++j) {
      W[i][j] = A[i][j];
      B[i][j] = 0.0;
    }
  }
  for (j = 0; j < 3; ++j)
    B[j][j] = 1.0;
  while (n > 0) {
    if (n % 2)
      MatMatModM(W, B, B, m);
    MatMatModM(W, W, W, m);
    n /= 2;
  }
}


x86 assembly (clang, -O0):
<MatPowModM>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movsd  %xmm0,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
cmpl   $0x3,-0x24(%rbp)
jge    11b7 <MatPowModM+0xa7>
movl   $0x0,-0x28(%rbp)
cmpl   $0x3,-0x28(%rbp)
jge    11a4 <MatPowModM+0x94>
mov    -0x8(%rbp),%rax
movslq -0x24(%rbp),%rcx
imul   $0x18,%rcx,%rcx
add    %rcx,%rax
movslq -0x28(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
movslq -0x24(%rbp),%rcx
lea    -0x70(%rbp),%rax
imul   $0x18,%rcx,%rcx
add    %rcx,%rax
movslq -0x28(%rbp),%rcx
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x10(%rbp),%rax
movslq -0x24(%rbp),%rcx
imul   $0x18,%rcx,%rcx
add    %rcx,%rax
movslq -0x28(%rbp),%rcx
xorps  %xmm0,%xmm0
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x28(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x28(%rbp)
jmp    1141 <MatPowModM+0x31>
jmp    11a9 <MatPowModM+0x99>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    1130 <MatPowModM+0x20>
movl   $0x0,-0x28(%rbp)
cmpl   $0x3,-0x28(%rbp)
jge    11f6 <MatPowModM+0xe6>
mov    -0x10(%rbp),%rax
movslq -0x28(%rbp),%rcx
imul   $0x18,%rcx,%rcx
add    %rcx,%rax
movslq -0x28(%rbp),%rcx
movsd  0xe1d(%rip),%xmm0
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x28(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x28(%rbp)
jmp    11be <MatPowModM+0xae>
jmp    11fb <MatPowModM+0xeb>
cmpq   $0x0,-0x20(%rbp)
jle    1261 <MatPowModM+0x151>
mov    -0x20(%rbp),%rax
mov    $0x2,%ecx
cqto
idiv   %rcx
cmp    $0x0,%rdx
je     1234 <MatPowModM+0x124>
lea    -0x70(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x10(%rbp),%rdx
movsd  -0x18(%rbp),%xmm0
call   1030 <MatMatModM@plt>
lea    -0x70(%rbp),%rdi
lea    -0x70(%rbp),%rsi
lea    -0x70(%rbp),%rdx
movsd  -0x18(%rbp),%xmm0
call   1030 <MatMatModM@plt>
mov    -0x20(%rbp),%rax
mov    $0x2,%ecx
cqto
idiv   %rcx
mov    %rax,-0x20(%rbp)
jmp    11fb <MatPowModM+0xeb>
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<MatPowModM>:
push   %r15
push   %r14
push   %rbx
sub    $0x60,%rsp
movsd  %xmm0,0x8(%rsp)
movsd  (%rdi),%xmm0
movsd  %xmm0,0x10(%rsp)
movq   $0x0,(%rsi)
movsd  0x8(%rdi),%xmm0
movsd  %xmm0,0x18(%rsp)
movq   $0x0,0x8(%rsi)
movsd  0x10(%rdi),%xmm0
movsd  %xmm0,0x20(%rsp)
movq   $0x0,0x10(%rsi)
movsd  0x18(%rdi),%xmm0
movsd  %xmm0,0x28(%rsp)
movq   $0x0,0x18(%rsi)
movsd  0x20(%rdi),%xmm0
movsd  %xmm0,0x30(%rsp)
movq   $0x0,0x20(%rsi)
movsd  0x28(%rdi),%xmm0
movsd  %xmm0,0x38(%rsp)
movq   $0x0,0x28(%rsi)
movsd  0x30(%rdi),%xmm0
movsd  %xmm0,0x40(%rsp)
movq   $0x0,0x30(%rsi)
movsd  0x38(%rdi),%xmm0
movsd  %xmm0,0x48(%rsp)
movq   $0x0,0x38(%rsi)
movsd  0x40(%rdi),%xmm0
movsd  %xmm0,0x50(%rsp)
movabs $0x3ff0000000000000,%rax
mov    %rax,(%rsi)
mov    %rax,0x20(%rsi)
mov    %rax,0x40(%rsi)
test   %rdx,%rdx
jle    122e <MatPowModM+0x11e>
mov    %rdx,%rbx
mov    %rsi,%r14
lea    0x10(%rsp),%r15
jmp    1213 <MatPowModM+0x103>
nopw   0x0(%rax,%rax,1)
mov    %r15,%rdi
mov    %r15,%rsi
mov    %r15,%rdx
movsd  0x8(%rsp),%xmm0
call   1030 <MatMatModM@plt>
mov    %rbx,%rax
shr    %rax
cmp    $0x1,%rbx
mov    %rax,%rbx
jbe    122e <MatPowModM+0x11e>
test   $0x1,%bl
je     11f0 <MatPowModM+0xe0>
mov    %r15,%rdi
mov    %r14,%rsi
mov    %r14,%rdx
movsd  0x8(%rsp),%xmm0
call   1030 <MatMatModM@plt>
jmp    11f0 <MatPowModM+0xe0>
add    $0x60,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

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

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