; LLVM IR from ravireddy07/cpp-book :: src/Fibonacci/Nth-fibbanacci.ll (Z9SetValuesPx)

; 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"

; Function Attrs: mustprogress nounwind uwtable
define dso_local void @_Z9SetValuesPx(ptr noundef %0) #0 {
  %2 = alloca ptr, align 8
  %3 = alloca i64, align 8
  store ptr %0, ptr %2, align 8, !tbaa !5
  %4 = load ptr, ptr %2, align 8, !tbaa !5
  %5 = getelementptr inbounds i64, ptr %4, i64 0
  store i64 0, ptr %5, align 8, !tbaa !9
  %6 = load ptr, ptr %2, align 8, !tbaa !5
  %7 = getelementptr inbounds i64, ptr %6, i64 1
  store i64 1, ptr %7, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %3) #2
  store i64 2, ptr %3, align 8, !tbaa !9
  br label %8

8:                                                ; preds = %28, %1
  %9 = load i64, ptr %3, align 8, !tbaa !9
  %10 = icmp slt i64 %9, 300
  br i1 %10, label %12, label %11

11:                                               ; preds = %8
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #2
  br label %31

12:                                               ; preds = %8
  %13 = load ptr, ptr %2, align 8, !tbaa !5
  %14 = load i64, ptr %3, align 8, !tbaa !9
  %15 = sub nsw i64 %14, 1
  %16 = getelementptr inbounds i64, ptr %13, i64 %15
  %17 = load i64, ptr %16, align 8, !tbaa !9
  %18 = load ptr, ptr %2, align 8, !tbaa !5
  %19 = load i64, ptr %3, align 8, !tbaa !9
  %20 = sub nsw i64 %19, 2
  %21 = getelementptr inbounds i64, ptr %18, i64 %20
  %22 = load i64, ptr %21, align 8, !tbaa !9
  %23 = add nsw i64 %17, %22
  %24 = srem i64 %23, 100
  %25 = load ptr, ptr %2, align 8, !tbaa !5
  %26 = load i64, ptr %3, align 8, !tbaa !9
  %27 = getelementptr inbounds i64, ptr %25, i64 %26
  store i64 %24, ptr %27, align 8, !tbaa !9
  br label %28

28:                                               ; preds = %12
  %29 = load i64, ptr %3, align 8, !tbaa !9
  %30 = add nsw i64 %29, 1
  store i64 %30, ptr %3, align 8, !tbaa !9
  br label %8, !llvm.loop !11

31:                                               ; preds = %11
  ret void
}

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #1

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #1

attributes #0 = { mustprogress nounwind 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" }
attributes #1 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { nounwind }

!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 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"long long", !7, i64 0}
!11 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}


; 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"

; Function Attrs: mustprogress nofree norecurse nosync nounwind memory(argmem: readwrite) uwtable
define dso_local void @_Z9SetValuesPx(ptr nocapture noundef %0) local_unnamed_addr #0 {
  store i64 0, ptr %0, align 8, !tbaa !5
  %2 = getelementptr inbounds i8, ptr %0, i64 8
  store i64 1, ptr %2, align 8, !tbaa !5
  br label %4

3:                                                ; preds = %4
  ret void

4:                                                ; preds = %4, %1
  %store_forwarded = phi i64 [ 1, %1 ], [ %15, %4 ]
  %.09 = phi i64 [ 2, %1 ], [ %16, %4 ]
  %5 = getelementptr i64, ptr %0, i64 %.09
  %6 = getelementptr i8, ptr %5, i64 -16
  %7 = load i64, ptr %6, align 8, !tbaa !5
  %8 = add nsw i64 %7, %store_forwarded
  %9 = srem i64 %8, 100
  store i64 %9, ptr %5, align 8, !tbaa !5
  %10 = or disjoint i64 %.09, 1
  %11 = getelementptr i64, ptr %0, i64 %10
  %12 = getelementptr i8, ptr %11, i64 -16
  %13 = load i64, ptr %12, align 8, !tbaa !5
  %14 = add nsw i64 %13, %9
  %15 = srem i64 %14, 100
  store i64 %15, ptr %11, align 8, !tbaa !5
  %16 = add nuw nsw i64 %.09, 2
  %exitcond.not.1 = icmp eq i64 %16, 300
  br i1 %exitcond.not.1, label %3, label %4, !llvm.loop !9
}

attributes #0 = { mustprogress nofree norecurse nosync nounwind memory(argmem: readwrite) 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"}
!9 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,LoopLoadEliminationPass,LoopRotatePass,LoopUnrollPass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass