#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*/ EXIT_FAILURE;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ free(long *);
scalar_t__ malloc(int);
int /*<<< orphan*/ pisano_sequence(long, long **, long *);
int /*<<< orphan*/ stderr;
long get_fibonaccihuge(long n, long m) {
  long *Psequence = (long *)malloc(sizeof(long));
  if (!(*Psequence)) {
    fprintf(stderr, "Cannot allocate memory\n");
    exit(EXIT_FAILURE);
  }
  long Pinerval;
  long out = 0;
  pisano_sequence(m, &Psequence, &Pinerval);
  out = (long)Psequence[(n % Pinerval)];
  free(Psequence);
  Psequence = NULL;
  return out;
}


x86 assembly (clang, -O0):
<get_fibonaccihuge>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    $0x8,%edi
call   1060 <malloc@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
cmpq   $0x0,(%rax)
jne    119f <get_fibonaccihuge+0x4f>
mov    0x2e5d(%rip),%rax
mov    (%rax),%edi
lea    0xe74(%rip),%rsi
call   1050 <fprintf@plt>
mov    0x2e40(%rip),%rax
mov    (%rax),%edi
call   1070 <exit@plt>
movq   $0x0,-0x28(%rbp)
mov    -0x10(%rbp),%rdi
lea    -0x18(%rbp),%rsi
lea    -0x20(%rbp),%rdx
call   1040 <pisano_sequence@plt>
mov    -0x18(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x8(%rbp),%rax
cqto
idivq  -0x20(%rbp)
mov    -0x30(%rbp),%rax
mov    (%rax,%rdx,8),%rax
mov    %rax,-0x28(%rbp)
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
movq   $0x0,-0x18(%rbp)
mov    -0x28(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_fibonaccihuge>:
push   %r14
push   %rbx
sub    $0x18,%rsp
mov    %rsi,%r14
mov    %rdi,%rbx
mov    $0x8,%edi
call   1060 <malloc@plt>
mov    %rax,0x8(%rsp)
cmpq   $0x0,(%rax)
je     11be <get_fibonaccihuge+0x6e>
lea    0x8(%rsp),%rsi
lea    0x10(%rsp),%rdx
mov    %r14,%rdi
call   1040 <pisano_sequence@plt>
mov    0x8(%rsp),%rdi
mov    0x10(%rsp),%rcx
mov    %rbx,%rax
or     %rcx,%rax
shr    $0x20,%rax
je     11a4 <get_fibonaccihuge+0x54>
mov    %rbx,%rax
cqto
idiv   %rcx
jmp    11aa <get_fibonaccihuge+0x5a>
mov    %ebx,%eax
xor    %edx,%edx
div    %ecx
mov    (%rdi,%rdx,8),%rbx
call   1030 <free@plt>
mov    %rbx,%rax
add    $0x18,%rsp
pop    %rbx
pop    %r14
ret
mov    0x2e1b(%rip),%rax
mov    (%rax),%edi
lea    0xe32(%rip),%rsi
call   1050 <fprintf@plt>
mov    0x2dfe(%rip),%rax
mov    (%rax),%edi
call   1070 <exit@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [24 x i8] c"Cannot allocate memory\0A\00"
@EXIT_FAILURE = global i32 0
define i64 @get_fibonaccihuge(i64 %0, i64 %1) {
%3 = alloca i64
%4 = alloca i64
%5 = alloca i64*
%6 = alloca i64
%7 = alloca i64
store i64 %0, i64* %3
store i64 %1, i64* %4
%8 = call i64 @malloc(i32 8)
%9 = inttoptr i64 %8 to i64*
store i64* %9, i64** %5
%10 = load i64*, i64** %5
%11 = load i64, i64* %10
%12 = icmp ne i64 %11, 0
br i1 %12, label %18, label %13
13: ; preds = %2
%14 = load i32, i32* @stderr
%15 = call i32 @fprintf(i32 %14, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0))
%16 = load i32, i32* @EXIT_FAILURE
%17 = call i32 @exit(i32 %16)
unreachable
18: ; preds = %2
store i64 0, i64* %7
%19 = load i64, i64* %4
%20 = call i32 @pisano_sequence(i64 %19, i64** %5, i64* %6)
%21 = load i64*, i64** %5
%22 = load i64, i64* %3
%23 = load i64, i64* %6
%24 = srem i64 %22, %23
%25 = getelementptr inbounds i64, i64* %21, i64 %24
%26 = load i64, i64* %25
store i64 %26, i64* %7
%27 = load i64*, i64** %5
%28 = call i32 @free(i64* %27)
store i64* null, i64** %5
%29 = load i64, i64* %7
ret i64 %29
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [24 x i8] c"Cannot allocate memory\0A\00"
@EXIT_FAILURE = global i32 0
define i64 @get_fibonaccihuge(i64 %0, i64 %1) {
%3 = alloca i64*
%4 = alloca i64
%5 = bitcast i64** %3 to i8*
%6 = tail call i64 @malloc(i32 8)
%7 = inttoptr i64 %6 to i64*
store i64* %7, i64** %3
%8 = load i64, i64* %7
%9 = icmp eq i64 %8, 0
br i1 %9, label %10, label %15
10: ; preds = %2
%11 = load i32, i32* @stderr
%12 = tail call i32 @fprintf(i32 %11, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0))
%13 = load i32, i32* @EXIT_FAILURE
%14 = tail call i32 @exit(i32 %13)
unreachable
15: ; preds = %2
%16 = bitcast i64* %4 to i8*
%17 = call i32 @pisano_sequence(i64 %1, i64** %3, i64* %4)
%18 = load i64*, i64** %3
%19 = load i64, i64* %4
%20 = srem i64 %0, %19
%21 = getelementptr inbounds i64, i64* %18, i64 %20
%22 = load i64, i64* %21
%23 = call i32 @free(i64* %18)
ret i64 %22
}