#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*/ computeMatPowMod(long long **, int, int, long long **);
long long int computeFibonacciMod(int n, int mod) {
  if (n == 1)
    return 1;
  if (n == 0)
    return 0;
  long long int fiboMat[2][2] = {{1, 1}, {1, 0}}, powerFiboMat[2][2];
  computeMatPowMod(fiboMat, n - 1, mod, powerFiboMat);
  return powerFiboMat[0][0];
}


x86 assembly (clang, -O0):
<computeFibonacciMod>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %edi,-0xc(%rbp)
mov    %esi,-0x10(%rbp)
cmpl   $0x1,-0xc(%rbp)
jne    1135 <computeFibonacciMod+0x25>
movq   $0x1,-0x8(%rbp)
jmp    1196 <computeFibonacciMod+0x86>
cmpl   $0x0,-0xc(%rbp)
jne    114c <computeFibonacciMod+0x3c>
movq   $0x0,-0x8(%rbp)
jmp    1196 <computeFibonacciMod+0x86>
mov    0xead(%rip),%rax
mov    %rax,-0x30(%rbp)
mov    0xeaa(%rip),%rax
mov    %rax,-0x28(%rbp)
mov    0xea7(%rip),%rax
mov    %rax,-0x20(%rbp)
mov    0xea4(%rip),%rax
mov    %rax,-0x18(%rbp)
lea    -0x30(%rbp),%rdi
mov    -0xc(%rbp),%esi
sub    $0x1,%esi
mov    -0x10(%rbp),%edx
lea    -0x50(%rbp),%rcx
call   1030 <computeMatPowMod@plt>
mov    -0x50(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<computeFibonacciMod>:
cmp    $0x1,%edi
je     1120 <computeFibonacciMod+0x10>
mov    %esi,%edx
mov    %edi,%esi
test   %edi,%edi
jne    1126 <computeFibonacciMod+0x16>
xor    %eax,%eax
ret
mov    $0x1,%eax
ret
sub    $0x48,%rsp
movaps 0xedf(%rip),%xmm0
movaps %xmm0,0x10(%rsp)
movaps 0xec3(%rip),%xmm0
movaps %xmm0,(%rsp)
add    $0xffffffff,%esi
mov    %rsp,%rdi
lea    0x20(%rsp),%rcx
call   1030 <computeMatPowMod@plt>
mov    0x20(%rsp),%rax
add    $0x48,%rsp
ret

LLVM IR (-O0):
@__const.computeFibonacciMod.fiboMat = [2 x [2 x i64]] [[2 x i64] [i64 1, i64 1], [2 x i64] [i64 1, i64 0]]
define i64 @computeFibonacciMod(i32 %0, i32 %1) {
%3 = alloca i64
%4 = alloca i32
%5 = alloca i32
%6 = alloca [2 x [2 x i64]]
%7 = alloca [2 x [2 x i64]]
store i32 %0, i32* %4
store i32 %1, i32* %5
%8 = load i32, i32* %4
%9 = icmp eq i32 %8, 1
br i1 %9, label %10, label %11
10: ; preds = %2
store i64 1, i64* %3
br label %28
11: ; preds = %2
%12 = load i32, i32* %4
%13 = icmp eq i32 %12, 0
br i1 %13, label %14, label %15
14: ; preds = %11
store i64 0, i64* %3
br label %28
15: ; preds = %11
%16 = bitcast [2 x [2 x i64]]* %6 to i8*
%17 = getelementptr inbounds [2 x [2 x i64]], [2 x [2 x i64]]* %6, i64 0, i64 0
%18 = bitcast [2 x i64]* %17 to i64**
%19 = load i32, i32* %4
%20 = sub nsw i32 %19, 1
%21 = load i32, i32* %5
%22 = getelementptr inbounds [2 x [2 x i64]], [2 x [2 x i64]]* %7, i64 0, i64 0
%23 = bitcast [2 x i64]* %22 to i64**
%24 = call i32 @computeMatPowMod(i64** %18, i32 %20, i32 %21, i64** %23)
%25 = getelementptr inbounds [2 x [2 x i64]], [2 x [2 x i64]]* %7, i64 0, i64 0
%26 = getelementptr inbounds [2 x i64], [2 x i64]* %25, i64 0, i64 0
%27 = load i64, i64* %26
store i64 %27, i64* %3
br label %28
28: ; preds = %15, %14, %10
%29 = load i64, i64* %3
ret i64 %29
}

LLVM IR (-O2):
@__const.computeFibonacciMod.fiboMat = [2 x [2 x i64]] [[2 x i64] [i64 1, i64 1], [2 x i64] [i64 1, i64 0]]
define i64 @computeFibonacciMod(i32 %0, i32 %1) {
%3 = alloca [2 x [2 x i64]]
%4 = alloca [2 x [2 x i64]]
switch i32 %0, label %6 [
i32 1, label %15
i32 0, label %5
]
5: ; preds = %2
br label %15
6: ; preds = %2
%7 = bitcast [2 x [2 x i64]]* %3 to i8*
%8 = bitcast [2 x [2 x i64]]* %4 to i8*
%9 = bitcast [2 x [2 x i64]]* %3 to i64**
%10 = add nsw i32 %0, -1
%11 = bitcast [2 x [2 x i64]]* %4 to i64**
%12 = call i32 @computeMatPowMod(i64** %9, i32 %10, i32 %1, i64** %11)
%13 = getelementptr inbounds [2 x [2 x i64]], [2 x [2 x i64]]* %4, i64 0, i64 0, i64 0
%14 = load i64, i64* %13
br label %15
15: ; preds = %2, %6, %5
%16 = phi i64 [ 0, %5 ], [ %14, %6 ], [ 1, %2 ]
ret i64 %16
}