; LLVM IR from amritansh22/Data-Structures-and-Algorithms-in-cpp :: Longest_Palindromic_Subsequence.ll (Z3lpsPcii)

; 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
declare dso_local noundef i32 @_Z3maxii(i32 noundef, i32 noundef) #0

; Function Attrs: mustprogress uwtable
define dso_local noundef i32 @_Z3lpsPcii(ptr noundef %0, i32 noundef %1, i32 noundef %2) #1 {
  %4 = alloca i32, align 4
  %5 = alloca ptr, align 8
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  store ptr %0, ptr %5, align 8, !tbaa !5
  store i32 %1, ptr %6, align 4, !tbaa !9
  store i32 %2, ptr %7, align 4, !tbaa !9
  %8 = load i32, ptr %6, align 4, !tbaa !9
  %9 = load i32, ptr %7, align 4, !tbaa !9
  %10 = icmp eq i32 %8, %9
  br i1 %10, label %11, label %12

11:                                               ; preds = %3
  store i32 1, ptr %4, align 4
  br label %66

12:                                               ; preds = %3
  %13 = load ptr, ptr %5, align 8, !tbaa !5
  %14 = load i32, ptr %6, align 4, !tbaa !9
  %15 = sext i32 %14 to i64
  %16 = getelementptr inbounds i8, ptr %13, i64 %15
  %17 = load i8, ptr %16, align 1, !tbaa !11
  %18 = sext i8 %17 to i32
  %19 = load ptr, ptr %5, align 8, !tbaa !5
  %20 = load i32, ptr %7, align 4, !tbaa !9
  %21 = sext i32 %20 to i64
  %22 = getelementptr inbounds i8, ptr %19, i64 %21
  %23 = load i8, ptr %22, align 1, !tbaa !11
  %24 = sext i8 %23 to i32
  %25 = icmp eq i32 %18, %24
  br i1 %25, label %26, label %32

26:                                               ; preds = %12
  %27 = load i32, ptr %6, align 4, !tbaa !9
  %28 = add nsw i32 %27, 1
  %29 = load i32, ptr %7, align 4, !tbaa !9
  %30 = icmp eq i32 %28, %29
  br i1 %30, label %31, label %32

31:                                               ; preds = %26
  store i32 2, ptr %4, align 4
  br label %66

32:                                               ; preds = %26, %12
  %33 = load ptr, ptr %5, align 8, !tbaa !5
  %34 = load i32, ptr %6, align 4, !tbaa !9
  %35 = sext i32 %34 to i64
  %36 = getelementptr inbounds i8, ptr %33, i64 %35
  %37 = load i8, ptr %36, align 1, !tbaa !11
  %38 = sext i8 %37 to i32
  %39 = load ptr, ptr %5, align 8, !tbaa !5
  %40 = load i32, ptr %7, align 4, !tbaa !9
  %41 = sext i32 %40 to i64
  %42 = getelementptr inbounds i8, ptr %39, i64 %41
  %43 = load i8, ptr %42, align 1, !tbaa !11
  %44 = sext i8 %43 to i32
  %45 = icmp eq i32 %38, %44
  br i1 %45, label %46, label %54

46:                                               ; preds = %32
  %47 = load ptr, ptr %5, align 8, !tbaa !5
  %48 = load i32, ptr %6, align 4, !tbaa !9
  %49 = add nsw i32 %48, 1
  %50 = load i32, ptr %7, align 4, !tbaa !9
  %51 = sub nsw i32 %50, 1
  %52 = call noundef i32 @_Z3lpsPcii(ptr noundef %47, i32 noundef %49, i32 noundef %51)
  %53 = add nsw i32 %52, 2
  store i32 %53, ptr %4, align 4
  br label %66

54:                                               ; preds = %32
  %55 = load ptr, ptr %5, align 8, !tbaa !5
  %56 = load i32, ptr %6, align 4, !tbaa !9
  %57 = load i32, ptr %7, align 4, !tbaa !9
  %58 = sub nsw i32 %57, 1
  %59 = call noundef i32 @_Z3lpsPcii(ptr noundef %55, i32 noundef %56, i32 noundef %58)
  %60 = load ptr, ptr %5, align 8, !tbaa !5
  %61 = load i32, ptr %6, align 4, !tbaa !9
  %62 = add nsw i32 %61, 1
  %63 = load i32, ptr %7, align 4, !tbaa !9
  %64 = call noundef i32 @_Z3lpsPcii(ptr noundef %60, i32 noundef %62, i32 noundef %63)
  %65 = call noundef i32 @_Z3maxii(i32 noundef %59, i32 noundef %64)
  store i32 %65, ptr %4, align 4
  br label %66

66:                                               ; preds = %54, %46, %31, %11
  %67 = load i32, ptr %4, align 4
  ret i32 %67
}

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 = { 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 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = !{!7, !7, i64 0}


; 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 nounwind uwtable
declare dso_local noundef i32 @_Z3maxii(i32 noundef, i32 noundef) local_unnamed_addr #0

; Function Attrs: mustprogress nounwind uwtable
define dso_local noundef i32 @_Z3lpsPcii(ptr noundef %0, i32 noundef %1, i32 noundef %2) local_unnamed_addr #0 {
  %4 = icmp eq i32 %1, %2
  br i1 %4, label %common.ret62, label %.lr.ph.preheader

.lr.ph.preheader:                                 ; preds = %3
  %5 = sext i32 %2 to i64
  %6 = sext i32 %1 to i64
  br label %.lr.ph

.lr.ph:                                           ; preds = %.lr.ph.preheader, %tailrecurse
  %indvars.iv40 = phi i64 [ %6, %.lr.ph.preheader ], [ %indvars.iv.next41, %tailrecurse ]
  %indvars.iv = phi i64 [ %5, %.lr.ph.preheader ], [ %indvars.iv.next, %tailrecurse ]
  %accumulator.tr30 = phi i32 [ 0, %.lr.ph.preheader ], [ %14, %tailrecurse ]
  %7 = getelementptr inbounds i8, ptr %0, i64 %indvars.iv40
  %8 = load i8, ptr %7, align 1, !tbaa !5
  %9 = getelementptr inbounds i8, ptr %0, i64 %indvars.iv
  %10 = load i8, ptr %9, align 1, !tbaa !5
  %11 = icmp eq i8 %8, %10
  %indvars.iv.next41 = add nsw i64 %indvars.iv40, 1
  %12 = icmp eq i64 %indvars.iv.next41, %indvars.iv
  %or.cond = select i1 %11, i1 %12, i1 false
  br i1 %or.cond, label %._crit_edge.loopexit, label %13

13:                                               ; preds = %.lr.ph
  br i1 %11, label %tailrecurse, label %16

tailrecurse:                                      ; preds = %13
  %indvars.iv.next = add nsw i64 %indvars.iv, -1
  %14 = add nuw nsw i32 %accumulator.tr30, 2
  %15 = icmp eq i64 %indvars.iv.next41, %indvars.iv.next
  br i1 %15, label %._crit_edge.loopexit, label %.lr.ph

common.ret62:                                     ; preds = %._crit_edge.loopexit, %3, %16
  %common.ret62.op = phi i32 [ %accumulator.ret.tr, %16 ], [ 1, %3 ], [ %24, %._crit_edge.loopexit ]
  ret i32 %common.ret62.op

16:                                               ; preds = %13
  %17 = trunc nsw i64 %indvars.iv to i32
  %18 = trunc nsw i64 %indvars.iv.next41 to i32
  %19 = trunc nsw i64 %indvars.iv40 to i32
  %20 = add nsw i32 %17, -1
  %21 = tail call noundef i32 @_Z3lpsPcii(ptr noundef nonnull %0, i32 noundef %19, i32 noundef %20)
  %22 = tail call noundef i32 @_Z3lpsPcii(ptr noundef nonnull %0, i32 noundef %18, i32 noundef %17)
  %23 = tail call noundef i32 @_Z3maxii(i32 noundef %21, i32 noundef %22)
  %accumulator.ret.tr = add nsw i32 %23, %accumulator.tr30
  br label %common.ret62

._crit_edge.loopexit:                             ; preds = %.lr.ph, %tailrecurse
  %accumulator.tr.lcssa.ph = phi i32 [ %14, %tailrecurse ], [ %accumulator.tr30, %.lr.ph ]
  %.0.ph = phi i32 [ 1, %tailrecurse ], [ 2, %.lr.ph ]
  %24 = add nsw i32 %.0.ph, %accumulator.tr.lcssa.ph
  br label %common.ret62
}

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

!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 = !{!"omnipotent char", !7, i64 0}
!7 = !{!"Simple C++ TBAA"}


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