#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*/ copyMat(int **, int **);
int /*<<< orphan*/ multiplyMat(int **, int **, int **, int);
void fastMatPow(int matFibo[][3], long long int pow, int mod, int powMat[][3]) {
  int identity[3][3] = {{1, 0, 0}, {0, 1, 0}, {0, 0, 1}};
  if (pow == 0) {
    copyMat(identity, powMat);
    return;
  }
  if (pow == 1) {
    copyMat(matFibo, powMat);
    return;
  }
  int root[3][3], temp[3][3];
  fastMatPow(matFibo, pow >> 1, mod, root);
  multiplyMat(root, root, temp, mod);
  if (pow & 1)
    multiplyMat(matFibo, temp, powMat, mod);
  else
    multiplyMat(identity, temp, powMat, mod);
}


x86 assembly (clang, -O0):
<fastMatPow>:
push   %rbp
mov    %rsp,%rbp
sub    $0xb0,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    %rcx,-0x20(%rbp)
lea    -0x50(%rbp),%rdi
xor    %esi,%esi
mov    $0x24,%edx
call   1050 <memset@plt>
movl   $0x1,-0x50(%rbp)
movl   $0x1,-0x40(%rbp)
movl   $0x1,-0x30(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    119c <fastMatPow+0x5c>
lea    -0x50(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   1030 <copyMat@plt>
jmp    122d <fastMatPow+0xed>
cmpq   $0x1,-0x10(%rbp)
jne    11b9 <fastMatPow+0x79>
mov    -0x8(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   1030 <copyMat@plt>
jmp    122d <fastMatPow+0xed>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
sar    $0x1,%rsi
mov    -0x14(%rbp),%edx
lea    -0x80(%rbp),%rcx
call   1040 <fastMatPow@plt>
lea    -0x80(%rbp),%rdi
lea    -0x80(%rbp),%rsi
lea    -0xb0(%rbp),%rdx
mov    -0x14(%rbp),%ecx
call   1060 <multiplyMat@plt>
mov    -0x10(%rbp),%rax
and    $0x1,%rax
cmp    $0x0,%rax
je     1216 <fastMatPow+0xd6>
mov    -0x8(%rbp),%rdi
lea    -0xb0(%rbp),%rsi
mov    -0x20(%rbp),%rdx
mov    -0x14(%rbp),%ecx
call   1060 <multiplyMat@plt>
jmp    122d <fastMatPow+0xed>
lea    -0x50(%rbp),%rdi
lea    -0xb0(%rbp),%rsi
mov    -0x20(%rbp),%rdx
mov    -0x14(%rbp),%ecx
call   1060 <multiplyMat@plt>
add    $0xb0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<fastMatPow>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x90,%rsp
mov    %rcx,%r14
mov    %rdi,%rbx
xorps  %xmm0,%xmm0
movaps %xmm0,(%rsp)
movaps %xmm0,0x10(%rsp)
movl   $0x1,(%rsp)
movl   $0x1,0x10(%rsp)
movl   $0x1,0x20(%rsp)
cmp    $0x1,%rsi
je     1183 <fastMatPow+0x53>
mov    %rsi,%rbp
test   %rsi,%rsi
jne    119d <fastMatPow+0x6d>
mov    %rsp,%rdi
mov    %r14,%rsi
call   1030 <copyMat@plt>
jmp    11ec <fastMatPow+0xbc>
mov    %rbx,%rdi
mov    %r14,%rsi
add    $0x90,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <copyMat@plt>
mov    %edx,%r15d
mov    %rbp,%rsi
sar    %rsi
lea    0x60(%rsp),%r12
mov    %rbx,%rdi
mov    %r12,%rcx
call   1040 <fastMatPow@plt>
lea    0x30(%rsp),%rdx
mov    %r12,%rdi
mov    %r12,%rsi
mov    %r15d,%ecx
call   1050 <multiplyMat@plt>
test   $0x1,%bpl
jne    11d9 <fastMatPow+0xa9>
mov    %rsp,%rdi
lea    0x30(%rsp),%rsi
jmp    11e1 <fastMatPow+0xb1>
lea    0x30(%rsp),%rsi
mov    %rbx,%rdi
mov    %r14,%rdx
mov    %r15d,%ecx
call   1050 <multiplyMat@plt>
add    $0x90,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define void @fastMatPow([3 x i32]* %0, i64 %1, i32 %2, [3 x i32]* %3) {
%5 = alloca [3 x i32]*
%6 = alloca i64
%7 = alloca i32
%8 = alloca [3 x i32]*
%9 = alloca [3 x [3 x i32]]
%10 = alloca [3 x [3 x i32]]
%11 = alloca [3 x [3 x i32]]
store [3 x i32]* %0, [3 x i32]** %5
store i64 %1, i64* %6
store i32 %2, i32* %7
store [3 x i32]* %3, [3 x i32]** %8
%12 = bitcast [3 x [3 x i32]]* %9 to i8*
%13 = bitcast i8* %12 to [3 x [3 x i32]]*
%14 = getelementptr inbounds [3 x [3 x i32]], [3 x [3 x i32]]* %13, i32 0, i32 0
%15 = getelementptr inbounds [3 x i32], [3 x i32]* %14, i32 0, i32 0
store i32 1, i32* %15
%16 = getelementptr inbounds [3 x [3 x i32]], [3 x [3 x i32]]* %13, i32 0, i32 1
%17 = getelementptr inbounds [3 x i32], [3 x i32]* %16, i32 0, i32 1
store i32 1, i32* %17
%18 = getelementptr inbounds [3 x [3 x i32]], [3 x [3 x i32]]* %13, i32 0, i32 2
%19 = getelementptr inbounds [3 x i32], [3 x i32]* %18, i32 0, i32 2
store i32 1, i32* %19
%20 = load i64, i64* %6
%21 = icmp eq i64 %20, 0
br i1 %21, label %22, label %28
22: ; preds = %4
%23 = getelementptr inbounds [3 x [3 x i32]], [3 x [3 x i32]]* %9, i64 0, i64 0
%24 = bitcast [3 x i32]* %23 to i32**
%25 = load [3 x i32]*, [3 x i32]** %8
%26 = bitcast [3 x i32]* %25 to i32**
%27 = call i32 @copyMat(i32** %24, i32** %26)
br label %72
28: ; preds = %4
%29 = load i64, i64* %6
%30 = icmp eq i64 %29, 1
br i1 %30, label %31, label %37
31: ; preds = %28
%32 = load [3 x i32]*, [3 x i32]** %5
%33 = bitcast [3 x i32]* %32 to i32**
%34 = load [3 x i32]*, [3 x i32]** %8
%35 = bitcast [3 x i32]* %34 to i32**
%36 = call i32 @copyMat(i32** %33, i32** %35)
br label %72
37: ; preds = %28
%38 = load [3 x i32]*, [3 x i32]** %5
%39 = load i64, i64* %6
%40 = ashr i64 %39, 1
%41 = load i32, i32* %7
%42 = getelementptr inbounds [3 x [3 x i32]], [3 x [3 x i32]]* %10, i64 0, i64 0
%43 = getelementptr inbounds [3 x [3 x i32]], [3 x [3 x i32]]* %10, i64 0, i64 0
%44 = bitcast [3 x i32]* %43 to i32**
%45 = getelementptr inbounds [3 x [3 x i32]], [3 x [3 x i32]]* %10, i64 0, i64 0
%46 = bitcast [3 x i32]* %45 to i32**
%47 = getelementptr inbounds [3 x [3 x i32]], [3 x [3 x i32]]* %11, i64 0, i64 0
%48 = bitcast [3 x i32]* %47 to i32**
%49 = load i32, i32* %7
%50 = call i32 @multiplyMat(i32** %44, i32** %46, i32** %48, i32 %49)
%51 = load i64, i64* %6
%52 = and i64 %51, 1
%53 = icmp ne i64 %52, 0
br i1 %53, label %54, label %63
54: ; preds = %37
%55 = load [3 x i32]*, [3 x i32]** %5
%56 = bitcast [3 x i32]* %55 to i32**
%57 = getelementptr inbounds [3 x [3 x i32]], [3 x [3 x i32]]* %11, i64 0, i64 0
%58 = bitcast [3 x i32]* %57 to i32**
%59 = load [3 x i32]*, [3 x i32]** %8
%60 = bitcast [3 x i32]* %59 to i32**
%61 = load i32, i32* %7
%62 = call i32 @multiplyMat(i32** %56, i32** %58, i32** %60, i32 %61)
br label %72
63: ; preds = %37
%64 = getelementptr inbounds [3 x [3 x i32]], [3 x [3 x i32]]* %9, i64 0, i64 0
%65 = bitcast [3 x i32]* %64 to i32**
%66 = getelementptr inbounds [3 x [3 x i32]], [3 x [3 x i32]]* %11, i64 0, i64 0
%67 = bitcast [3 x i32]* %66 to i32**
%68 = load [3 x i32]*, [3 x i32]** %8
%69 = bitcast [3 x i32]* %68 to i32**
%70 = load i32, i32* %7
%71 = call i32 @multiplyMat(i32** %65, i32** %67, i32** %69, i32 %70)
br label %72
72: ; preds = %22, %31, %63, %54
ret void
}

LLVM IR (-O2):
define void @fastMatPow([3 x i32]* %0, i64 %1, i32 %2, [3 x i32]* %3) {
%5 = alloca [3 x [3 x i32]]
%6 = alloca [3 x [3 x i32]]
%7 = alloca [3 x [3 x i32]]
%8 = bitcast [3 x [3 x i32]]* %5 to i8*
%9 = getelementptr inbounds [3 x [3 x i32]], [3 x [3 x i32]]* %5, i64 0, i64 0, i64 0
store i32 1, i32* %9
%10 = getelementptr inbounds [3 x [3 x i32]], [3 x [3 x i32]]* %5, i64 0, i64 1, i64 1
store i32 1, i32* %10
%11 = getelementptr inbounds [3 x [3 x i32]], [3 x [3 x i32]]* %5, i64 0, i64 2, i64 2
store i32 1, i32* %11
switch i64 %1, label %20 [
i64 0, label %12
i64 1, label %16
]
12: ; preds = %4
%13 = bitcast [3 x [3 x i32]]* %5 to i32**
%14 = bitcast [3 x i32]* %3 to i32**
%15 = call i32 @copyMat(i32** %13, i32** %14)
br label %39
16: ; preds = %4
%17 = bitcast [3 x i32]* %0 to i32**
%18 = bitcast [3 x i32]* %3 to i32**
%19 = tail call i32 @copyMat(i32** %17, i32** %18)
br label %39
20: ; preds = %4
%21 = bitcast [3 x [3 x i32]]* %6 to i8*
%22 = bitcast [3 x [3 x i32]]* %7 to i8*
%23 = ashr i64 %1, 1
%24 = getelementptr inbounds [3 x [3 x i32]], [3 x [3 x i32]]* %6, i64 0, i64 0
%25 = bitcast [3 x [3 x i32]]* %6 to i32**
%26 = bitcast [3 x [3 x i32]]* %7 to i32**
%27 = call i32 @multiplyMat(i32** %25, i32** %25, i32** %26, i32 %2)
%28 = and i64 %1, 1
%29 = icmp eq i64 %28, 0
br i1 %29, label %34, label %30
30: ; preds = %20
%31 = bitcast [3 x i32]* %0 to i32**
%32 = bitcast [3 x i32]* %3 to i32**
%33 = call i32 @multiplyMat(i32** %31, i32** %26, i32** %32, i32 %2)
br label %38
34: ; preds = %20
%35 = bitcast [3 x [3 x i32]]* %5 to i32**
%36 = bitcast [3 x i32]* %3 to i32**
%37 = call i32 @multiplyMat(i32** %35, i32** %26, i32** %36, i32 %2)
br label %38
38: ; preds = %34, %30
br label %39
39: ; preds = %38, %16, %12
ret void
}