; LLVM IR from MinhasKamal/AlgorithmImplementations :: playWithNumbers/fibonaciiNumber (FibonaciiSerise)

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

@.str = external hidden unnamed_addr constant [25 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [3 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [26 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [40 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [19 x i8], align 1

; Function Attrs: nounwind uwtable
define dso_local i32 @main() #0 {
  %1 = alloca i32, align 4
  %2 = alloca i32, align 4
  %3 = alloca i32, align 4
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  %6 = alloca i64, align 8
  %7 = alloca i64, align 8
  %8 = alloca i64, align 8
  %9 = alloca i32, align 4
  store i32 0, ptr %1, align 4
  call void @llvm.lifetime.start.p0(i64 4, ptr %2) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #3
  %10 = call i32 (ptr, ...) @printf(ptr noundef @.str)
  %11 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str.1, ptr noundef %2)
  %12 = call i32 (ptr, ...) @printf(ptr noundef @.str.2)
  %13 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str.1, ptr noundef %3)
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #3
  %14 = load i32, ptr %2, align 4, !tbaa !5
  store i32 %14, ptr %4, align 4, !tbaa !5
  br label %15

15:                                               ; preds = %46, %0
  %16 = load i32, ptr %4, align 4, !tbaa !5
  %17 = load i32, ptr %3, align 4, !tbaa !5
  %18 = icmp sle i32 %16, %17
  br i1 %18, label %19, label %49

19:                                               ; preds = %15
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #3
  store i64 0, ptr %6, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #3
  store i64 1, ptr %7, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #3
  store i32 1, ptr %5, align 4, !tbaa !5
  br label %20

20:                                               ; preds = %30, %19
  %21 = load i32, ptr %5, align 4, !tbaa !5
  %22 = load i32, ptr %4, align 4, !tbaa !5
  %23 = icmp slt i32 %21, %22
  br i1 %23, label %24, label %33

24:                                               ; preds = %20
  %25 = load i64, ptr %7, align 8, !tbaa !9
  store i64 %25, ptr %8, align 8, !tbaa !9
  %26 = load i64, ptr %6, align 8, !tbaa !9
  %27 = load i64, ptr %7, align 8, !tbaa !9
  %28 = add nsw i64 %26, %27
  store i64 %28, ptr %7, align 8, !tbaa !9
  %29 = load i64, ptr %8, align 8, !tbaa !9
  store i64 %29, ptr %6, align 8, !tbaa !9
  br label %30

30:                                               ; preds = %24
  %31 = load i32, ptr %5, align 4, !tbaa !5
  %32 = add nsw i32 %31, 1
  store i32 %32, ptr %5, align 4, !tbaa !5
  br label %20, !llvm.loop !11

33:                                               ; preds = %20
  %34 = load i64, ptr %6, align 8, !tbaa !9
  %35 = icmp slt i64 %34, 0
  br i1 %35, label %36, label %38

36:                                               ; preds = %33
  %37 = call i32 (ptr, ...) @printf(ptr noundef @.str.3)
  store i32 0, ptr %1, align 4
  store i32 1, ptr %9, align 4
  br label %43

38:                                               ; preds = %33
  %39 = load i32, ptr %4, align 4, !tbaa !5
  %40 = load i64, ptr %6, align 8, !tbaa !9
  %41 = call i32 (ptr, ...) @printf(ptr noundef @.str.4, i32 noundef %39, i64 noundef %40)
  br label %42

42:                                               ; preds = %38
  store i32 0, ptr %9, align 4
  br label %43

43:                                               ; preds = %42, %36
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #3
  %44 = load i32, ptr %9, align 4
  switch i32 %44, label %50 [
    i32 0, label %45
  ]

45:                                               ; preds = %43
  br label %46

46:                                               ; preds = %45
  %47 = load i32, ptr %4, align 4, !tbaa !5
  %48 = add nsw i32 %47, 1
  store i32 %48, ptr %4, align 4, !tbaa !5
  br label %15, !llvm.loop !13

49:                                               ; preds = %15
  store i32 0, ptr %1, align 4
  store i32 1, ptr %9, align 4
  br label %50

50:                                               ; preds = %49, %43
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %2) #3
  %51 = load i32, ptr %1, align 4
  ret i32 %51
}

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

declare i32 @printf(ptr noundef, ...) #2

declare i32 @__isoc99_scanf(ptr noundef, ...) #2

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

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


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

@.str = external hidden unnamed_addr constant [25 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [3 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [26 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [40 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [19 x i8], align 1

; Function Attrs: nofree nounwind uwtable
define dso_local noundef i32 @main() local_unnamed_addr #0 {
  %1 = alloca i32, align 4
  %2 = alloca i32, align 4
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %1) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %2) #3
  %3 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str)
  %4 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str.1, ptr noundef nonnull %1)
  %5 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.2)
  %6 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str.1, ptr noundef nonnull %2)
  %7 = load i32, ptr %1, align 4, !tbaa !5
  %8 = load i32, ptr %2, align 4, !tbaa !5
  %.not22 = icmp sgt i32 %7, %8
  br i1 %.not22, label %.loopexit, label %.preheader.preheader

.preheader.preheader:                             ; preds = %0
  %9 = add i32 %7, -1
  %10 = add i32 %7, -2
  br label %.preheader

.preheader:                                       ; preds = %.preheader.preheader, %._crit_edge.thread
  %indvar = phi i32 [ 0, %.preheader.preheader ], [ %indvar.next, %._crit_edge.thread ]
  %.01823 = phi i32 [ %7, %.preheader.preheader ], [ %28, %._crit_edge.thread ]
  %11 = add i32 %9, %indvar
  %12 = icmp sgt i32 %.01823, 1
  br i1 %12, label %.lr.ph.preheader, label %._crit_edge.thread

.lr.ph.preheader:                                 ; preds = %.preheader
  %13 = add i32 %10, %indvar
  %xtraiter = and i32 %11, 7
  %14 = icmp ult i32 %13, 7
  br i1 %14, label %._crit_edge.unr-lcssa, label %.lr.ph.preheader.new

.lr.ph.preheader.new:                             ; preds = %.lr.ph.preheader
  %unroll_iter = and i32 %11, -8
  br label %.lr.ph

.lr.ph:                                           ; preds = %.lr.ph, %.lr.ph.preheader.new
  %.01521 = phi i64 [ 1, %.lr.ph.preheader.new ], [ %22, %.lr.ph ]
  %.01620 = phi i64 [ 0, %.lr.ph.preheader.new ], [ %21, %.lr.ph ]
  %niter = phi i32 [ 0, %.lr.ph.preheader.new ], [ %niter.next.7, %.lr.ph ]
  %15 = add nsw i64 %.01521, %.01620
  %16 = add nsw i64 %15, %.01521
  %17 = add nsw i64 %16, %15
  %18 = add nsw i64 %17, %16
  %19 = add nsw i64 %18, %17
  %20 = add nsw i64 %19, %18
  %21 = add nsw i64 %20, %19
  %22 = add nsw i64 %21, %20
  %niter.next.7 = add i32 %niter, 8
  %niter.ncmp.7 = icmp eq i32 %niter.next.7, %unroll_iter
  br i1 %niter.ncmp.7, label %._crit_edge.unr-lcssa, label %.lr.ph, !llvm.loop !9

._crit_edge.unr-lcssa:                            ; preds = %.lr.ph, %.lr.ph.preheader
  %.01521.lcssa.ph = phi i64 [ poison, %.lr.ph.preheader ], [ %21, %.lr.ph ]
  %.01521.unr = phi i64 [ 1, %.lr.ph.preheader ], [ %22, %.lr.ph ]
  %.01620.unr = phi i64 [ 0, %.lr.ph.preheader ], [ %21, %.lr.ph ]
  %lcmp.mod.not = icmp eq i32 %xtraiter, 0
  br i1 %lcmp.mod.not, label %._crit_edge, label %.lr.ph.epil

.lr.ph.epil:                                      ; preds = %._crit_edge.unr-lcssa, %.lr.ph.epil
  %.01521.epil = phi i64 [ %23, %.lr.ph.epil ], [ %.01521.unr, %._crit_edge.unr-lcssa ]
  %.01620.epil = phi i64 [ %.01521.epil, %.lr.ph.epil ], [ %.01620.unr, %._crit_edge.unr-lcssa ]
  %epil.iter = phi i32 [ %epil.iter.next, %.lr.ph.epil ], [ 0, %._crit_edge.unr-lcssa ]
  %23 = add nsw i64 %.01521.epil, %.01620.epil
  %epil.iter.next = add i32 %epil.iter, 1
  %epil.iter.cmp.not = icmp eq i32 %epil.iter.next, %xtraiter
  br i1 %epil.iter.cmp.not, label %._crit_edge, label %.lr.ph.epil, !llvm.loop !11

._crit_edge:                                      ; preds = %.lr.ph.epil, %._crit_edge.unr-lcssa
  %.01521.lcssa = phi i64 [ %.01521.lcssa.ph, %._crit_edge.unr-lcssa ], [ %.01521.epil, %.lr.ph.epil ]
  %24 = icmp sgt i64 %.01521.lcssa, -1
  br i1 %24, label %._crit_edge.thread, label %25

25:                                               ; preds = %._crit_edge
  %26 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.3)
  br label %.loopexit

._crit_edge.thread:                               ; preds = %.preheader, %._crit_edge
  %.016.lcssa25 = phi i64 [ %.01521.lcssa, %._crit_edge ], [ 0, %.preheader ]
  %27 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.4, i32 noundef %.01823, i64 noundef %.016.lcssa25)
  %28 = add nsw i32 %.01823, 1
  %29 = load i32, ptr %2, align 4, !tbaa !5
  %.not.not = icmp slt i32 %.01823, %29
  %indvar.next = add i32 %indvar, 1
  br i1 %.not.not, label %.preheader, label %.loopexit, !llvm.loop !13

.loopexit:                                        ; preds = %._crit_edge.thread, %0, %25
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %2) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %1) #3
  ret i32 0
}

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

; Function Attrs: nofree nounwind
declare noundef i32 @printf(ptr nocapture noundef readonly, ...) local_unnamed_addr #2

; Function Attrs: nofree nounwind
declare noundef i32 @__isoc99_scanf(ptr nocapture noundef readonly, ...) local_unnamed_addr #2

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

attributes #0 = { nofree 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 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { nofree nounwind "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 #3 = { 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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}
!11 = distinct !{!11, !12}
!12 = !{!"llvm.loop.unroll.disable"}
!13 = distinct !{!13, !10}


; Effective O3 passes: CorrelatedValuePropagationPass,GVNPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass