#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 */
typedef int uint64_t;

/* Variables and functions */
int /*<<< orphan*/ mult_matrix(int *, int *, int);
uint64_t fibonacci(uint64_t n, uint64_t module) {
  uint64_t power[] = {0, 1, 1, 1};
  uint64_t result[] = {1, 0, 0, 1};
  while (n) {
    if (n & 1) {
      mult_matrix(result, power, module);
    }
    mult_matrix(power, power, module);
    n >>= 1;
  }
  return result[1];
}


x86 assembly (clang, -O0):
<fibonacci>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    0xedb(%rip),%rax
mov    %rax,-0x20(%rbp)
mov    0xed8(%rip),%rax
mov    %rax,-0x18(%rbp)
mov    0xed5(%rip),%rax
mov    %rax,-0x30(%rbp)
mov    0xed2(%rip),%rax
mov    %rax,-0x28(%rbp)
cmpl   $0x0,-0x4(%rbp)
je     1191 <fibonacci+0x81>
mov    -0x4(%rbp),%eax
and    $0x1,%eax
cmp    $0x0,%eax
je     1173 <fibonacci+0x63>
lea    -0x30(%rbp),%rdi
lea    -0x20(%rbp),%rsi
mov    -0x8(%rbp),%edx
call   1030 <mult_matrix@plt>
lea    -0x20(%rbp),%rdi
lea    -0x20(%rbp),%rsi
mov    -0x8(%rbp),%edx
call   1030 <mult_matrix@plt>
mov    -0x4(%rbp),%eax
sar    $0x1,%eax
mov    %eax,-0x4(%rbp)
jmp    114a <fibonacci+0x3a>
mov    -0x2c(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<fibonacci>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x28,%rsp
movaps 0xedf(%rip),%xmm0
movaps %xmm0,0x10(%rsp)
movaps 0xee3(%rip),%xmm0
movaps %xmm0,(%rsp)
test   %edi,%edi
je     1183 <fibonacci+0x73>
mov    %esi,%ebx
mov    %edi,%ebp
lea    0x10(%rsp),%r14
mov    %rsp,%r15
jmp    1168 <fibonacci+0x58>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    %r14,%rdi
mov    %r14,%rsi
mov    %ebx,%edx
call   1030 <mult_matrix@plt>
mov    %ebp,%eax
sar    %eax
cmp    $0x1,%ebp
mov    %eax,%ebp
jbe    117d <fibonacci+0x6d>
test   $0x1,%bpl
je     1150 <fibonacci+0x40>
mov    %r15,%rdi
mov    %r14,%rsi
mov    %ebx,%edx
call   1030 <mult_matrix@plt>
jmp    1150 <fibonacci+0x40>
mov    0x4(%rsp),%eax
jmp    1185 <fibonacci+0x75>
xor    %eax,%eax
add    $0x28,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
@__const.fibonacci.power = [4 x i32] [i32 0, i32 1, i32 1, i32 1]
@__const.fibonacci.result = [4 x i32] [i32 1, i32 0, i32 0, i32 1]
define i32 @fibonacci(i32 %0, i32 %1) {
%3 = alloca [4 x i32]
%4 = alloca [4 x i32]
%5 = bitcast [4 x i32]* %3 to i8*
%6 = bitcast [4 x i32]* %4 to i8*
%7 = icmp eq i32 %0, 0
br i1 %7, label %24, label %8
8: ; preds = %2
%9 = getelementptr inbounds [4 x i32], [4 x i32]* %4, i64 0, i64 0
%10 = getelementptr inbounds [4 x i32], [4 x i32]* %3, i64 0, i64 0
br label %11
11: ; preds = %8, %17
%12 = phi i32 [ %0, %8 ], [ %19, %17 ]
%13 = and i32 %12, 1
%14 = icmp eq i32 %13, 0
br i1 %14, label %17, label %15
15: ; preds = %11
%16 = call i32 @mult_matrix(i32* %9, i32* %10, i32 %1)
br label %17
17: ; preds = %15, %11
%18 = call i32 @mult_matrix(i32* %10, i32* %10, i32 %1)
%19 = ashr i32 %12, 1
%20 = icmp ult i32 %12, 2
br i1 %20, label %21, label %11
21: ; preds = %17
%22 = getelementptr inbounds [4 x i32], [4 x i32]* %4, i64 0, i64 1
%23 = load i32, i32* %22
br label %24
24: ; preds = %21, %2
%25 = phi i32 [ %23, %21 ], [ 0, %2 ]
ret i32 %25
}