unsigned long
find_nth_fibo_using_dynamic_programming_memoization(unsigned long num) {
  unsigned long fibo_array[50 + 1];
  unsigned long i;
  if (num > 50) {
    return (-1);
  }
  if (num == 0) {
    return (0);
  }
  if (num == 1) {
    return (1);
  }
  fibo_array[0] = 0;
  fibo_array[1] = 1;
  for (i = 2; i <= num; ++i) {
    fibo_array[i] = fibo_array[i - 2] + fibo_array[i - 1];
  }
  return (fibo_array[num]);
}


x86 assembly (clang, -O0):
<find_nth_fibo_using_dynamic_programming_memoization>:
push   %rbp
mov    %rsp,%rbp
sub    $0x140,%rsp
mov    %rdi,-0x10(%rbp)
cmpq   $0x32,-0x10(%rbp)
jbe    1127 <find_nth_fibo_using_dynamic_programming_memoization+0x27>
movq   $0xffffffffffffffff,-0x8(%rbp)
ff
jmp    11e5 <find_nth_fibo_using_dynamic_programming_memoization+0xe5>
cmpq   $0x0,-0x10(%rbp)
jne    113f <find_nth_fibo_using_dynamic_programming_memoization+0x3f>
movq   $0x0,-0x8(%rbp)
jmp    11e5 <find_nth_fibo_using_dynamic_programming_memoization+0xe5>
cmpq   $0x1,-0x10(%rbp)
jne    1157 <find_nth_fibo_using_dynamic_programming_memoization+0x57>
movq   $0x1,-0x8(%rbp)
jmp    11e5 <find_nth_fibo_using_dynamic_programming_memoization+0xe5>
movq   $0x0,-0x1b0(%rbp)
movq   $0x1,-0x1a8(%rbp)
movq   $0x2,-0x1b8(%rbp)
mov    -0x1b8(%rbp),%rax
cmp    -0x10(%rbp),%rax
ja     11d5 <find_nth_fibo_using_dynamic_programming_memoization+0xd5>
mov    -0x1b8(%rbp),%rax
sub    $0x2,%rax
mov    -0x1b0(%rbp,%rax,8),%rcx
ff
mov    -0x1b8(%rbp),%rax
sub    $0x1,%rax
add    -0x1b0(%rbp,%rax,8),%rcx
ff
mov    -0x1b8(%rbp),%rax
mov    %rcx,-0x1b0(%rbp,%rax,8)
ff
mov    -0x1b8(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x1b8(%rbp)
jmp    1178 <find_nth_fibo_using_dynamic_programming_memoization+0x78>
mov    -0x10(%rbp),%rax
mov    -0x1b0(%rbp,%rax,8),%rax
ff
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x140,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<find_nth_fibo_using_dynamic_programming_memoization>:
mov    $0xffffffffffffffff,%rax
cmp    $0x32,%rdi
ja     11e5 <find_nth_fibo_using_dynamic_programming_memoization+0xe5>
test   %rdi,%rdi
je     1122 <find_nth_fibo_using_dynamic_programming_memoization+0x22>
cmp    $0x1,%rdi
jne    1126 <find_nth_fibo_using_dynamic_programming_memoization+0x26>
mov    $0x1,%eax
ret
mov    %rdi,%rax
ret
sub    $0x118,%rsp
movaps 0xecc(%rip),%xmm0
movaps %xmm0,-0x80(%rsp)
lea    -0x1(%rdi),%r9
lea    -0x2(%rdi),%rcx
mov    %r9d,%r8d
and    $0x3,%r8d
cmp    $0x3,%rcx
jae    115c <find_nth_fibo_using_dynamic_programming_memoization+0x5c>
mov    $0x2,%esi
mov    $0x1,%edx
xor    %ecx,%ecx
jmp    11a2 <find_nth_fibo_using_dynamic_programming_memoization+0xa2>
and    $0xfffffffffffffffc,%r9
neg    %r9
mov    $0x2,%esi
mov    $0x1,%edx
xor    %ecx,%ecx
nop
add    %rdx,%rcx
mov    %rcx,-0x80(%rsp,%rsi,8)
add    %rcx,%rdx
mov    %rdx,-0x78(%rsp,%rsi,8)
add    %rdx,%rcx
mov    %rcx,-0x70(%rsp,%rsi,8)
add    %rcx,%rdx
mov    %rdx,-0x68(%rsp,%rsi,8)
lea    (%r9,%rsi,1),%rax
add    $0x4,%rax
add    $0x4,%rsi
cmp    $0x2,%rax
jne    1170 <find_nth_fibo_using_dynamic_programming_memoization+0x70>
test   %r8,%r8
je     11d9 <find_nth_fibo_using_dynamic_programming_memoization+0xd9>
lea    (%rsp,%rsi,8),%r9
add    $0xffffffffffffff80,%r9
xor    %esi,%esi
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    %rdx,%rax
add    %rdx,%rcx
mov    %rcx,(%r9,%rsi,8)
add    $0x1,%rsi
mov    %rcx,%rdx
mov    %rax,%rcx
cmp    %rsi,%r8
jne    11c0 <find_nth_fibo_using_dynamic_programming_memoization+0xc0>
mov    -0x80(%rsp,%rdi,8),%rax
add    $0x118,%rsp
ret

LLVM IR (-O0):
define i64 @find_nth_fibo_using_dynamic_programming_memoization(i64 %0) {
%2 = alloca i64
%3 = alloca i64
%4 = alloca [51 x i64]
%5 = alloca i64
store i64 %0, i64* %3
%6 = load i64, i64* %3
%7 = icmp ugt i64 %6, 50
br i1 %7, label %8, label %9
8: ; preds = %1
store i64 -1, i64* %2
br label %43
9: ; preds = %1
%10 = load i64, i64* %3
%11 = icmp eq i64 %10, 0
br i1 %11, label %12, label %13
12: ; preds = %9
store i64 0, i64* %2
br label %43
13: ; preds = %9
%14 = load i64, i64* %3
%15 = icmp eq i64 %14, 1
br i1 %15, label %16, label %17
16: ; preds = %13
store i64 1, i64* %2
br label %43
17: ; preds = %13
%18 = getelementptr inbounds [51 x i64], [51 x i64]* %4, i64 0, i64 0
store i64 0, i64* %18
%19 = getelementptr inbounds [51 x i64], [51 x i64]* %4, i64 0, i64 1
store i64 1, i64* %19
store i64 2, i64* %5
br label %20
20: ; preds = %36, %17
%21 = load i64, i64* %5
%22 = load i64, i64* %3
%23 = icmp ule i64 %21, %22
br i1 %23, label %24, label %39
24: ; preds = %20
%25 = load i64, i64* %5
%26 = sub i64 %25, 2
%27 = getelementptr inbounds [51 x i64], [51 x i64]* %4, i64 0, i64 %26
%28 = load i64, i64* %27
%29 = load i64, i64* %5
%30 = sub i64 %29, 1
%31 = getelementptr inbounds [51 x i64], [51 x i64]* %4, i64 0, i64 %30
%32 = load i64, i64* %31
%33 = add i64 %28, %32
%34 = load i64, i64* %5
%35 = getelementptr inbounds [51 x i64], [51 x i64]* %4, i64 0, i64 %34
store i64 %33, i64* %35
br label %36
36: ; preds = %24
%37 = load i64, i64* %5
%38 = add i64 %37, 1
store i64 %38, i64* %5
br label %20
39: ; preds = %20
%40 = load i64, i64* %3
%41 = getelementptr inbounds [51 x i64], [51 x i64]* %4, i64 0, i64 %40
%42 = load i64, i64* %41
store i64 %42, i64* %2
br label %43
43: ; preds = %39, %16, %12, %8
%44 = load i64, i64* %2
ret i64 %44
}

LLVM IR (-O2):
define i64 @find_nth_fibo_using_dynamic_programming_memoization(i64 %0) {
%2 = alloca [51 x i64]
%3 = bitcast [51 x i64]* %2 to i8*
%4 = icmp ugt i64 %0, 50
br i1 %4, label %52, label %5
5: ; preds = %1
switch i64 %0, label %7 [
i64 0, label %52
i64 1, label %6
]
6: ; preds = %5
br label %52
7: ; preds = %5
%8 = bitcast [51 x i64]* %2 to <2 x i64>*
store <2 x i64> <i64 0, i64 1>, <2 x i64>* %8
%9 = add i64 %0, -1
%10 = add i64 %0, -2
%11 = and i64 %9, 3
%12 = icmp ult i64 %10, 3
br i1 %12, label %34, label %13
13: ; preds = %7
%14 = and i64 %9, -4
br label %15
15: ; preds = %15, %13
%16 = phi i64 [ 1, %13 ], [ %29, %15 ]
%17 = phi i64 [ 0, %13 ], [ %26, %15 ]
%18 = phi i64 [ 2, %13 ], [ %31, %15 ]
%19 = phi i64 [ 0, %13 ], [ %32, %15 ]
%20 = add i64 %16, %17
%21 = getelementptr inbounds [51 x i64], [51 x i64]* %2, i64 0, i64 %18
store i64 %20, i64* %21
%22 = or i64 %18, 1
%23 = add i64 %20, %16
%24 = getelementptr inbounds [51 x i64], [51 x i64]* %2, i64 0, i64 %22
store i64 %23, i64* %24
%25 = add nuw i64 %18, 2
%26 = add i64 %23, %20
%27 = getelementptr inbounds [51 x i64], [51 x i64]* %2, i64 0, i64 %25
store i64 %26, i64* %27
%28 = add nuw i64 %18, 3
%29 = add i64 %26, %23
%30 = getelementptr inbounds [51 x i64], [51 x i64]* %2, i64 0, i64 %28
store i64 %29, i64* %30
%31 = add nuw i64 %18, 4
%32 = add i64 %19, 4
%33 = icmp eq i64 %32, %14
br i1 %33, label %34, label %15
34: ; preds = %15, %7
%35 = phi i64 [ 1, %7 ], [ %29, %15 ]
%36 = phi i64 [ 0, %7 ], [ %26, %15 ]
%37 = phi i64 [ 2, %7 ], [ %31, %15 ]
%38 = icmp eq i64 %11, 0
br i1 %38, label %49, label %39
39: ; preds = %34, %39
%40 = phi i64 [ %44, %39 ], [ %35, %34 ]
%41 = phi i64 [ %40, %39 ], [ %36, %34 ]
%42 = phi i64 [ %46, %39 ], [ %37, %34 ]
%43 = phi i64 [ %47, %39 ], [ 0, %34 ]
%44 = add i64 %40, %41
%45 = getelementptr inbounds [51 x i64], [51 x i64]* %2, i64 0, i64 %42
store i64 %44, i64* %45
%46 = add nuw i64 %42, 1
%47 = add i64 %43, 1
%48 = icmp eq i64 %47, %11
br i1 %48, label %49, label %39
49: ; preds = %39, %34
%50 = getelementptr inbounds [51 x i64], [51 x i64]* %2, i64 0, i64 %0
%51 = load i64, i64* %50
br label %52
52: ; preds = %5, %1, %49, %6
%53 = phi i64 [ 1, %6 ], [ %51, %49 ], [ -1, %1 ], [ %0, %5 ]
ret i64 %53
}