#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 /*<<< orphan*/ mpz_t;

/* Variables and functions */
int /*<<< orphan*/ mpz_init_set_ui(int /*<<< orphan*/, int);
int /*<<< orphan*/ mpz_set(int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ power(int /*<<< orphan*/ **, unsigned long);
void fib(unsigned long int n, mpz_t result) {
  mpz_t F[2][2];
  mpz_init_set_ui(F[0][0], 1);
  mpz_init_set_ui(F[0][1], 1);
  mpz_init_set_ui(F[1][0], 1);
  mpz_init_set_ui(F[1][1], 0);
  if (n == 0) {
    return;
  }
  power(F, n - 1);
  mpz_set(result, F[0][0]);
}


x86 assembly (clang, -O0):
<fib>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    -0x20(%rbp),%edi
mov    $0x1,%esi
call   1050 <mpz_init_set_ui@plt>
mov    -0x1c(%rbp),%edi
mov    $0x1,%esi
call   1050 <mpz_init_set_ui@plt>
mov    -0x18(%rbp),%edi
mov    $0x1,%esi
call   1050 <mpz_init_set_ui@plt>
mov    -0x14(%rbp),%edi
xor    %esi,%esi
call   1050 <mpz_init_set_ui@plt>
cmpq   $0x0,-0x8(%rbp)
jne    1180 <fib+0x50>
jmp    119c <fib+0x6c>
lea    -0x20(%rbp),%rdi
mov    -0x8(%rbp),%rsi
sub    $0x1,%rsi
call   1030 <power@plt>
mov    -0xc(%rbp),%edi
mov    -0x20(%rbp),%esi
call   1040 <mpz_set@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<fib>:
push   %rbp
push   %rbx
sub    $0x18,%rsp
mov    %esi,%ebp
mov    %rdi,%rbx
mov    $0x1,%esi
call   1050 <mpz_init_set_ui@plt>
mov    $0x1,%esi
call   1050 <mpz_init_set_ui@plt>
mov    $0x1,%esi
call   1050 <mpz_init_set_ui@plt>
xor    %esi,%esi
call   1050 <mpz_init_set_ui@plt>
test   %rbx,%rbx
je     117e <fib+0x4e>
add    $0xffffffffffffffff,%rbx
mov    %rsp,%rdi
mov    %rbx,%rsi
call   1030 <power@plt>
mov    (%rsp),%esi
mov    %ebp,%edi
call   1040 <mpz_set@plt>
add    $0x18,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
define void @fib(i64 %0, i32 %1) {
%3 = alloca i64
%4 = alloca i32
%5 = alloca [2 x [2 x i32]]
store i64 %0, i64* %3
store i32 %1, i32* %4
%6 = getelementptr inbounds [2 x [2 x i32]], [2 x [2 x i32]]* %5, i64 0, i64 0
%7 = getelementptr inbounds [2 x i32], [2 x i32]* %6, i64 0, i64 0
%8 = load i32, i32* %7
%9 = call i32 @mpz_init_set_ui(i32 %8, i32 1)
%10 = getelementptr inbounds [2 x [2 x i32]], [2 x [2 x i32]]* %5, i64 0, i64 0
%11 = getelementptr inbounds [2 x i32], [2 x i32]* %10, i64 0, i64 1
%12 = load i32, i32* %11
%13 = call i32 @mpz_init_set_ui(i32 %12, i32 1)
%14 = getelementptr inbounds [2 x [2 x i32]], [2 x [2 x i32]]* %5, i64 0, i64 1
%15 = getelementptr inbounds [2 x i32], [2 x i32]* %14, i64 0, i64 0
%16 = load i32, i32* %15
%17 = call i32 @mpz_init_set_ui(i32 %16, i32 1)
%18 = getelementptr inbounds [2 x [2 x i32]], [2 x [2 x i32]]* %5, i64 0, i64 1
%19 = getelementptr inbounds [2 x i32], [2 x i32]* %18, i64 0, i64 1
%20 = load i32, i32* %19
%21 = call i32 @mpz_init_set_ui(i32 %20, i32 0)
%22 = load i64, i64* %3
%23 = icmp eq i64 %22, 0
br i1 %23, label %24, label %25
24: ; preds = %2
br label %36
25: ; preds = %2
%26 = getelementptr inbounds [2 x [2 x i32]], [2 x [2 x i32]]* %5, i64 0, i64 0
%27 = bitcast [2 x i32]* %26 to i32**
%28 = load i64, i64* %3
%29 = sub i64 %28, 1
%30 = call i32 @power(i32** %27, i64 %29)
%31 = load i32, i32* %4
%32 = getelementptr inbounds [2 x [2 x i32]], [2 x [2 x i32]]* %5, i64 0, i64 0
%33 = getelementptr inbounds [2 x i32], [2 x i32]* %32, i64 0, i64 0
%34 = load i32, i32* %33
%35 = call i32 @mpz_set(i32 %31, i32 %34)
br label %36
36: ; preds = %25, %24
ret void
}

LLVM IR (-O2):
define void @fib(i64 %0, i32 %1) {
%3 = alloca [2 x [2 x i32]]
%4 = bitcast [2 x [2 x i32]]* %3 to i8*
%5 = tail call i32 @mpz_init_set_ui(i32 undef, i32 1)
%6 = tail call i32 @mpz_init_set_ui(i32 undef, i32 1)
%7 = tail call i32 @mpz_init_set_ui(i32 undef, i32 1)
%8 = tail call i32 @mpz_init_set_ui(i32 undef, i32 0)
%9 = icmp eq i64 %0, 0
br i1 %9, label %17, label %10
10: ; preds = %2
%11 = getelementptr inbounds [2 x [2 x i32]], [2 x [2 x i32]]* %3, i64 0, i64 0, i64 0
%12 = bitcast [2 x [2 x i32]]* %3 to i32**
%13 = add i64 %0, -1
%14 = call i32 @power(i32** %12, i64 %13)
%15 = load i32, i32* %11
%16 = call i32 @mpz_set(i32 %1, i32 %15)
br label %17
17: ; preds = %2, %10
ret void
}