; LLVM IR from VAR-solutions/Algorithms :: Dynamic Programming/common sub sequence/cpp/LCS.ll (Z9PrintPathPPiPcS1_ii)

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

@_ZZ9PrintPathPPiPcS1_iiE1k = external hidden global i32, align 4

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

13:                                               ; preds = %5
  %14 = load i32, ptr %10, align 4, !tbaa !9
  %15 = icmp eq i32 %14, 0
  br i1 %15, label %16, label %17

16:                                               ; preds = %13, %5
  br label %89

17:                                               ; preds = %13
  %18 = load ptr, ptr %6, align 8, !tbaa !5
  %19 = load i32, ptr %9, align 4, !tbaa !9
  %20 = sext i32 %19 to i64
  %21 = getelementptr inbounds ptr, ptr %18, i64 %20
  %22 = load ptr, ptr %21, align 8, !tbaa !5
  %23 = load i32, ptr %10, align 4, !tbaa !9
  %24 = sext i32 %23 to i64
  %25 = getelementptr inbounds i32, ptr %22, i64 %24
  %26 = load i32, ptr %25, align 4, !tbaa !9
  %27 = icmp eq i32 %26, 1
  br i1 %27, label %28, label %35

28:                                               ; preds = %17
  %29 = load ptr, ptr %6, align 8, !tbaa !5
  %30 = load ptr, ptr %7, align 8, !tbaa !5
  %31 = load ptr, ptr %8, align 8, !tbaa !5
  %32 = load i32, ptr %9, align 4, !tbaa !9
  %33 = load i32, ptr %10, align 4, !tbaa !9
  %34 = sub nsw i32 %33, 1
  call void @_Z9PrintPathPPiPcS1_ii(ptr noundef %29, ptr noundef %30, ptr noundef %31, i32 noundef %32, i32 noundef %34)
  br label %89

35:                                               ; preds = %17
  %36 = load ptr, ptr %6, align 8, !tbaa !5
  %37 = load i32, ptr %9, align 4, !tbaa !9
  %38 = sext i32 %37 to i64
  %39 = getelementptr inbounds ptr, ptr %36, i64 %38
  %40 = load ptr, ptr %39, align 8, !tbaa !5
  %41 = load i32, ptr %10, align 4, !tbaa !9
  %42 = sext i32 %41 to i64
  %43 = getelementptr inbounds i32, ptr %40, i64 %42
  %44 = load i32, ptr %43, align 4, !tbaa !9
  %45 = icmp eq i32 %44, 2
  br i1 %45, label %46, label %53

46:                                               ; preds = %35
  %47 = load ptr, ptr %6, align 8, !tbaa !5
  %48 = load ptr, ptr %7, align 8, !tbaa !5
  %49 = load ptr, ptr %8, align 8, !tbaa !5
  %50 = load i32, ptr %9, align 4, !tbaa !9
  %51 = sub nsw i32 %50, 1
  %52 = load i32, ptr %10, align 4, !tbaa !9
  call void @_Z9PrintPathPPiPcS1_ii(ptr noundef %47, ptr noundef %48, ptr noundef %49, i32 noundef %51, i32 noundef %52)
  br label %88

53:                                               ; preds = %35
  %54 = load ptr, ptr %6, align 8, !tbaa !5
  %55 = load i32, ptr %9, align 4, !tbaa !9
  %56 = sext i32 %55 to i64
  %57 = getelementptr inbounds ptr, ptr %54, i64 %56
  %58 = load ptr, ptr %57, align 8, !tbaa !5
  %59 = load i32, ptr %10, align 4, !tbaa !9
  %60 = sext i32 %59 to i64
  %61 = getelementptr inbounds i32, ptr %58, i64 %60
  %62 = load i32, ptr %61, align 4, !tbaa !9
  %63 = icmp eq i32 %62, 0
  br i1 %63, label %64, label %86

64:                                               ; preds = %53
  %65 = load ptr, ptr %7, align 8, !tbaa !5
  %66 = load i32, ptr %9, align 4, !tbaa !9
  %67 = sext i32 %66 to i64
  %68 = getelementptr inbounds i8, ptr %65, i64 %67
  %69 = load i8, ptr %68, align 1, !tbaa !11
  %70 = load ptr, ptr %8, align 8, !tbaa !5
  %71 = load i32, ptr @_ZZ9PrintPathPPiPcS1_iiE1k, align 4, !tbaa !9
  %72 = add nsw i32 %71, 1
  store i32 %72, ptr @_ZZ9PrintPathPPiPcS1_iiE1k, align 4, !tbaa !9
  %73 = sext i32 %71 to i64
  %74 = getelementptr inbounds i8, ptr %70, i64 %73
  store i8 %69, ptr %74, align 1, !tbaa !11
  %75 = load ptr, ptr %8, align 8, !tbaa !5
  %76 = load i32, ptr @_ZZ9PrintPathPPiPcS1_iiE1k, align 4, !tbaa !9
  %77 = sext i32 %76 to i64
  %78 = getelementptr inbounds i8, ptr %75, i64 %77
  store i8 0, ptr %78, align 1, !tbaa !11
  %79 = load ptr, ptr %6, align 8, !tbaa !5
  %80 = load ptr, ptr %7, align 8, !tbaa !5
  %81 = load ptr, ptr %8, align 8, !tbaa !5
  %82 = load i32, ptr %9, align 4, !tbaa !9
  %83 = sub nsw i32 %82, 1
  %84 = load i32, ptr %10, align 4, !tbaa !9
  %85 = sub nsw i32 %84, 1
  call void @_Z9PrintPathPPiPcS1_ii(ptr noundef %79, ptr noundef %80, ptr noundef %81, i32 noundef %83, i32 noundef %85)
  br label %87

86:                                               ; preds = %53
  br label %89

87:                                               ; preds = %64
  br label %88

88:                                               ; preds = %87, %46
  br label %89

89:                                               ; preds = %88, %86, %28, %16
  ret void
}

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 = !{!"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"

@_ZZ9PrintPathPPiPcS1_iiE1k = external hidden local_unnamed_addr global i32, align 4

; Function Attrs: mustprogress nofree norecurse nosync nounwind memory(readwrite, inaccessiblemem: none) uwtable
define dso_local void @_Z9PrintPathPPiPcS1_ii(ptr nocapture noundef readonly %0, ptr nocapture noundef readonly %1, ptr nocapture noundef writeonly %2, i32 noundef %3, i32 noundef %4) local_unnamed_addr #0 {
  %6 = icmp eq i32 %3, 0
  %7 = icmp eq i32 %4, 0
  %or.cond3945 = or i1 %6, %7
  br i1 %or.cond3945, label %tailrecurse.outer._crit_edge, label %.lr.ph.split.preheader

.lr.ph.split.preheader:                           ; preds = %5, %tailrecurse.outer.backedge
  %.tr35.ph47 = phi i32 [ %.tr35.ph.be, %tailrecurse.outer.backedge ], [ %4, %5 ]
  %.tr34.ph46 = phi i32 [ %.tr34.ph.be, %tailrecurse.outer.backedge ], [ %3, %5 ]
  %8 = sext i32 %.tr34.ph46 to i64
  %9 = getelementptr inbounds ptr, ptr %0, i64 %8
  %10 = load ptr, ptr %9, align 8, !tbaa !5
  %11 = sext i32 %.tr35.ph47 to i64
  br label %.lr.ph.split

.lr.ph.split:                                     ; preds = %.lr.ph.split.preheader, %tailrecurse
  %indvars.iv = phi i64 [ %11, %.lr.ph.split.preheader ], [ %indvars.iv.next, %tailrecurse ]
  %12 = getelementptr inbounds i32, ptr %10, i64 %indvars.iv
  %13 = load i32, ptr %12, align 4, !tbaa !9
  switch i32 %13, label %tailrecurse.outer._crit_edge [
    i32 1, label %tailrecurse
    i32 2, label %.split.us
    i32 0, label %.split42.us
  ]

tailrecurse:                                      ; preds = %.lr.ph.split
  %indvars.iv.next = add nsw i64 %indvars.iv, -1
  %14 = icmp eq i64 %indvars.iv.next, 0
  br i1 %14, label %tailrecurse.outer._crit_edge, label %.lr.ph.split

.split.us:                                        ; preds = %.lr.ph.split
  %15 = trunc nsw i64 %indvars.iv to i32
  br label %tailrecurse.outer.backedge

tailrecurse.outer.backedge:                       ; preds = %.split.us, %.split42.us
  %.tr35.ph.be = phi i32 [ %28, %.split42.us ], [ %15, %.split.us ]
  %.tr34.ph.be = add i32 %.tr34.ph46, -1
  %16 = icmp eq i32 %.tr34.ph.be, 0
  %17 = icmp eq i32 %.tr35.ph.be, 0
  %or.cond39 = or i1 %16, %17
  br i1 %or.cond39, label %tailrecurse.outer._crit_edge, label %.lr.ph.split.preheader

.split42.us:                                      ; preds = %.lr.ph.split
  %18 = trunc nsw i64 %indvars.iv to i32
  %19 = getelementptr inbounds i8, ptr %1, i64 %8
  %20 = load i8, ptr %19, align 1, !tbaa !11
  %21 = load i32, ptr @_ZZ9PrintPathPPiPcS1_iiE1k, align 4, !tbaa !9
  %22 = add nsw i32 %21, 1
  store i32 %22, ptr @_ZZ9PrintPathPPiPcS1_iiE1k, align 4, !tbaa !9
  %23 = sext i32 %21 to i64
  %24 = getelementptr inbounds i8, ptr %2, i64 %23
  store i8 %20, ptr %24, align 1, !tbaa !11
  %25 = load i32, ptr @_ZZ9PrintPathPPiPcS1_iiE1k, align 4, !tbaa !9
  %26 = sext i32 %25 to i64
  %27 = getelementptr inbounds i8, ptr %2, i64 %26
  store i8 0, ptr %27, align 1, !tbaa !11
  %28 = add nsw i32 %18, -1
  br label %tailrecurse.outer.backedge

tailrecurse.outer._crit_edge:                     ; preds = %tailrecurse.outer.backedge, %tailrecurse, %.lr.ph.split, %5
  ret void
}

attributes #0 = { mustprogress nofree norecurse nosync nounwind memory(readwrite, 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 = !{!"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}


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