; LLVM IR from manishbisht/Competitive-Programming :: Algorithms/Dynamic Programming/Fabonacci Number - Memoization.ll (Z9fabonaccix)

; Unoptimized IR (clang -disable-llvm-passes):
target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128"
target triple = "x86_64-unknown-linux-gnu"

@fab = external dso_local global [100 x i64], align 16

; Function Attrs: mustprogress uwtable
define dso_local noundef i64 @_Z9fabonaccix(i64 noundef %0) #0 {
  %2 = alloca i64, align 8
  store i64 %0, ptr %2, align 8, !tbaa !5
  %3 = load i64, ptr %2, align 8, !tbaa !5
  %4 = getelementptr inbounds [100 x i64], ptr @fab, i64 0, i64 %3
  %5 = load i64, ptr %4, align 8, !tbaa !5
  %6 = icmp eq i64 %5, -1
  br i1 %6, label %7, label %25

7:                                                ; preds = %1
  %8 = load i64, ptr %2, align 8, !tbaa !5
  %9 = icmp sle i64 %8, 1
  br i1 %9, label %10, label %14

10:                                               ; preds = %7
  %11 = load i64, ptr %2, align 8, !tbaa !5
  %12 = load i64, ptr %2, align 8, !tbaa !5
  %13 = getelementptr inbounds [100 x i64], ptr @fab, i64 0, i64 %12
  store i64 %11, ptr %13, align 8, !tbaa !5
  br label %24

14:                                               ; preds = %7
  %15 = load i64, ptr %2, align 8, !tbaa !5
  %16 = sub nsw i64 %15, 1
  %17 = call noundef i64 @_Z9fabonaccix(i64 noundef %16)
  %18 = load i64, ptr %2, align 8, !tbaa !5
  %19 = sub nsw i64 %18, 2
  %20 = call noundef i64 @_Z9fabonaccix(i64 noundef %19)
  %21 = add nsw i64 %17, %20
  %22 = load i64, ptr %2, align 8, !tbaa !5
  %23 = getelementptr inbounds [100 x i64], ptr @fab, i64 0, i64 %22
  store i64 %21, ptr %23, align 8, !tbaa !5
  br label %24

24:                                               ; preds = %14, %10
  br label %25

25:                                               ; preds = %24, %1
  %26 = load i64, ptr %2, align 8, !tbaa !5
  %27 = getelementptr inbounds [100 x i64], ptr @fab, i64 0, i64 %26
  %28 = load i64, ptr %27, align 8, !tbaa !5
  ret i64 %28
}

attributes #0 = { mustprogress uwtable "min-legal-vector-width"="0" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cmov,+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" }

!llvm.module.flags = !{!0, !1, !2, !3}
!llvm.ident = !{!4}

!0 = !{i32 1, !"wchar_size", i32 4}
!1 = !{i32 8, !"PIC Level", i32 2}
!2 = !{i32 7, !"PIE Level", i32 2}
!3 = !{i32 7, !"uwtable", i32 2}
!4 = !{!"clang version 19.1.0 (git@github.com:llvm/llvm-project.git a4bf6cd7cfb1a1421ba92bca9d017b49936c55e4)"}
!5 = !{!6, !6, i64 0}
!6 = !{!"long long", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}


; Optimized IR (opt -passes='default<O3>'):
target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128"
target triple = "x86_64-unknown-linux-gnu"

@fab = external dso_local local_unnamed_addr global [100 x i64], align 16

; Function Attrs: mustprogress nofree nosync nounwind memory(readwrite, argmem: none, inaccessiblemem: none) uwtable
define dso_local noundef i64 @_Z9fabonaccix(i64 noundef %0) local_unnamed_addr #0 {
  %2 = getelementptr inbounds [100 x i64], ptr @fab, i64 0, i64 %0
  %3 = load i64, ptr %2, align 8, !tbaa !5
  %4 = icmp eq i64 %3, -1
  br i1 %4, label %5, label %13

5:                                                ; preds = %1
  %6 = icmp slt i64 %0, 2
  br i1 %6, label %.sink.split, label %7

7:                                                ; preds = %5
  %8 = add nsw i64 %0, -1
  %9 = tail call noundef i64 @_Z9fabonaccix(i64 noundef %8)
  %10 = add nsw i64 %0, -2
  %11 = tail call noundef i64 @_Z9fabonaccix(i64 noundef %10)
  %12 = add nsw i64 %11, %9
  br label %.sink.split

.sink.split:                                      ; preds = %5, %7
  %.sink = phi i64 [ %12, %7 ], [ %0, %5 ]
  store i64 %.sink, ptr %2, align 8, !tbaa !5
  br label %13

13:                                               ; preds = %.sink.split, %1
  %14 = phi i64 [ %3, %1 ], [ %.sink, %.sink.split ]
  ret i64 %14
}

attributes #0 = { mustprogress nofree nosync nounwind memory(readwrite, argmem: none, inaccessiblemem: none) uwtable "min-legal-vector-width"="0" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cmov,+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" }

!llvm.module.flags = !{!0, !1, !2, !3}
!llvm.ident = !{!4}

!0 = !{i32 1, !"wchar_size", i32 4}
!1 = !{i32 8, !"PIC Level", i32 2}
!2 = !{i32 7, !"PIE Level", i32 2}
!3 = !{i32 7, !"uwtable", i32 2}
!4 = !{!"clang version 19.1.0 (git@github.com:llvm/llvm-project.git a4bf6cd7cfb1a1421ba92bca9d017b49936c55e4)"}
!5 = !{!6, !6, i64 0}
!6 = !{!"long long", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,InstCombinePass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass