#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 */
unsigned int *MemAlloc(int);
int /*<<< orphan*/ MemFree(unsigned int **);
unsigned int FibnoFunction(unsigned int ulNum) {
  unsigned int *pulStackBt;
  unsigned int *pulStackTop;
  unsigned int ulSumRet;
  pulStackBt = MemAlloc(sizeof(unsigned int) * (ulNum + 1));
  if (pulStackBt == 0) {
    return -1;
  }
  pulStackTop = pulStackBt + ulNum;
  pulStackTop[0] = 0;
  if (ulNum > 0) {
    pulStackTop[-1] = 1;
  }
  while (pulStackTop > pulStackBt + 1) {
    pulStackTop[-2] = pulStackTop[-1] + pulStackTop[0];
    pulStackTop--;
  }
  ulSumRet = *pulStackBt;
  MemFree(&pulStackBt);
  return ulSumRet;
}


x86 assembly (clang, -O0):
<FibnoFunction>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,%eax
shl    $0x2,%rax
mov    %eax,%edi
call   1040 <MemAlloc@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1159 <FibnoFunction+0x39>
movl   $0xffffffff,-0x4(%rbp)
jmp    11e1 <FibnoFunction+0xc1>
mov    -0x10(%rbp),%rax
mov    -0x8(%rbp),%ecx
shl    $0x2,%rcx
add    %rcx,%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
movl   $0x0,(%rax)
cmpl   $0x0,-0x8(%rbp)
jbe    118a <FibnoFunction+0x6a>
mov    -0x18(%rbp),%rax
movl   $0x1,-0x4(%rax)
jmp    118f <FibnoFunction+0x6f>
mov    -0x18(%rbp),%rax
mov    -0x10(%rbp),%rcx
add    $0x4,%rcx
cmp    %rcx,%rax
jbe    11c9 <FibnoFunction+0xa9>
mov    -0x18(%rbp),%rax
mov    -0x4(%rax),%ecx
mov    -0x18(%rbp),%rax
add    (%rax),%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,-0x8(%rax)
mov    -0x18(%rbp),%rax
add    $0xfffffffffffffffc,%rax
mov    %rax,-0x18(%rbp)
jmp    118f <FibnoFunction+0x6f>
mov    -0x10(%rbp),%rax
mov    (%rax),%eax
mov    %eax,-0x1c(%rbp)
lea    -0x10(%rbp),%rdi
call   1030 <MemFree@plt>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<FibnoFunction>:
push   %rbx
sub    $0x10,%rsp
mov    %edi,%ebx
lea    0x4(,%rbx,4),%edi
call   1040 <MemAlloc@plt>
mov    %rax,0x8(%rsp)
test   %rax,%rax
je     1184 <FibnoFunction+0x64>
mov    %ebx,%ecx
movl   $0x0,(%rax,%rcx,4)
test   %ebx,%ebx
je     1176 <FibnoFunction+0x56>
movl   $0x1,-0x4(%rax,%rcx,4)
cmp    $0x1,%ebx
je     1176 <FibnoFunction+0x56>
add    $0x1,%rcx
xor    %edx,%edx
nopl   (%rax)
mov    -0x8(%rax,%rcx,4),%esi
add    %esi,%edx
mov    %edx,-0xc(%rax,%rcx,4)
add    $0xffffffffffffffff,%rcx
mov    %esi,%edx
cmp    $0x2,%rcx
ja     1160 <FibnoFunction+0x40>
mov    (%rax),%ebx
lea    0x8(%rsp),%rdi
call   1030 <MemFree@plt>
jmp    1189 <FibnoFunction+0x69>
mov    $0xffffffff,%ebx
mov    %ebx,%eax
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
define i32 @FibnoFunction(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32*
%5 = alloca i32*
%6 = alloca i32
store i32 %0, i32* %3
%7 = load i32, i32* %3
%8 = add i32 %7, 1
%9 = zext i32 %8 to i64
%10 = mul i64 4, %9
%11 = trunc i64 %10 to i32
%12 = call i32* @MemAlloc(i32 %11)
store i32* %12, i32** %4
%13 = load i32*, i32** %4
%14 = icmp eq i32* %13, null
br i1 %14, label %15, label %16
15: ; preds = %1
store i32 -1, i32* %2
br label %51
16: ; preds = %1
%17 = load i32*, i32** %4
%18 = load i32, i32* %3
%19 = zext i32 %18 to i64
%20 = getelementptr inbounds i32, i32* %17, i64 %19
store i32* %20, i32** %5
%21 = load i32*, i32** %5
%22 = getelementptr inbounds i32, i32* %21, i64 0
store i32 0, i32* %22
%23 = load i32, i32* %3
%24 = icmp ugt i32 %23, 0
br i1 %24, label %25, label %28
25: ; preds = %16
%26 = load i32*, i32** %5
%27 = getelementptr inbounds i32, i32* %26, i64 -1
store i32 1, i32* %27
br label %28
28: ; preds = %25, %16
br label %29
29: ; preds = %34, %28
%30 = load i32*, i32** %5
%31 = load i32*, i32** %4
%32 = getelementptr inbounds i32, i32* %31, i64 1
%33 = icmp ugt i32* %30, %32
br i1 %33, label %34, label %46
34: ; preds = %29
%35 = load i32*, i32** %5
%36 = getelementptr inbounds i32, i32* %35, i64 -1
%37 = load i32, i32* %36
%38 = load i32*, i32** %5
%39 = getelementptr inbounds i32, i32* %38, i64 0
%40 = load i32, i32* %39
%41 = add i32 %37, %40
%42 = load i32*, i32** %5
%43 = getelementptr inbounds i32, i32* %42, i64 -2
store i32 %41, i32* %43
%44 = load i32*, i32** %5
%45 = getelementptr inbounds i32, i32* %44, i32 -1
store i32* %45, i32** %5
br label %29
46: ; preds = %29
%47 = load i32*, i32** %4
%48 = load i32, i32* %47
store i32 %48, i32* %6
%49 = call i32 @MemFree(i32** %4)
%50 = load i32, i32* %6
store i32 %50, i32* %2
br label %51
51: ; preds = %46, %15
%52 = load i32, i32* %2
ret i32 %52
}

LLVM IR (-O2):
define i32 @FibnoFunction(i32 %0) {
%2 = alloca i32*
%3 = bitcast i32** %2 to i8*
%4 = shl i32 %0, 2
%5 = add i32 %4, 4
%6 = tail call i32* @MemAlloc(i32 %5)
store i32* %6, i32** %2
%7 = icmp eq i32* %6, null
br i1 %7, label %29, label %8
8: ; preds = %1
%9 = zext i32 %0 to i64
%10 = getelementptr inbounds i32, i32* %6, i64 %9
store i32 0, i32* %10
%11 = icmp eq i32 %0, 0
br i1 %11, label %26, label %12
12: ; preds = %8
%13 = getelementptr inbounds i32, i32* %10, i64 -1
store i32 1, i32* %13
%14 = icmp eq i32 %0, 1
br i1 %14, label %26, label %15
15: ; preds = %12
%16 = getelementptr inbounds i32, i32* %6, i64 -2
br label %17
17: ; preds = %15, %17
%18 = phi i32 [ %22, %17 ], [ 0, %15 ]
%19 = phi i64 [ %20, %17 ], [ %9, %15 ]
%20 = add nsw i64 %19, -1
%21 = getelementptr inbounds i32, i32* %6, i64 %20
%22 = load i32, i32* %21
%23 = add i32 %18, %22
%24 = getelementptr inbounds i32, i32* %16, i64 %19
store i32 %23, i32* %24
%25 = icmp ugt i64 %19, 2
br i1 %25, label %17, label %26
26: ; preds = %17, %8, %12
%27 = load i32, i32* %6
%28 = call i32 @MemFree(i32** %2)
br label %29
29: ; preds = %1, %26
%30 = phi i32 [ %27, %26 ], [ -1, %1 ]
ret i32 %30
}