; LLVM IR from Lodour/ACM-CheatSheet :: src/7_动态规划/1_子序列/2_最长上升子序列LIS.ll (Z3LISPi)

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

@n = external dso_local global i32, align 4
@a = external dso_local global [100100 x i32], align 16
@b = external dso_local global [100100 x i32], align 16
@f = external dso_local global [100100 x i32], align 16

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i32 @_Z4Findiii(i32 noundef, i32 noundef, i32 noundef) #0

; 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

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

8:                                                ; preds = %47, %1
  %9 = load i32, ptr %4, align 4, !tbaa !9
  %10 = load i32, ptr @n, align 4, !tbaa !9
  %11 = icmp sle i32 %9, %10
  br i1 %11, label %13, label %12

12:                                               ; preds = %8
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #2
  br label %50

13:                                               ; preds = %8
  %14 = load i32, ptr %4, align 4, !tbaa !9
  %15 = sext i32 %14 to i64
  %16 = getelementptr inbounds [100100 x i32], ptr @a, i64 0, i64 %15
  %17 = load i32, ptr %16, align 4, !tbaa !9
  %18 = load i32, ptr %3, align 4, !tbaa !9
  %19 = sext i32 %18 to i64
  %20 = getelementptr inbounds [100100 x i32], ptr @b, i64 0, i64 %19
  %21 = load i32, ptr %20, align 4, !tbaa !9
  %22 = icmp sgt i32 %17, %21
  br i1 %22, label %23, label %36

23:                                               ; preds = %13
  %24 = load i32, ptr %4, align 4, !tbaa !9
  %25 = sext i32 %24 to i64
  %26 = getelementptr inbounds [100100 x i32], ptr @a, i64 0, i64 %25
  %27 = load i32, ptr %26, align 4, !tbaa !9
  %28 = load i32, ptr %3, align 4, !tbaa !9
  %29 = add nsw i32 %28, 1
  store i32 %29, ptr %3, align 4, !tbaa !9
  %30 = sext i32 %29 to i64
  %31 = getelementptr inbounds [100100 x i32], ptr @b, i64 0, i64 %30
  store i32 %27, ptr %31, align 4, !tbaa !9
  %32 = load i32, ptr %3, align 4, !tbaa !9
  %33 = load i32, ptr %4, align 4, !tbaa !9
  %34 = sext i32 %33 to i64
  %35 = getelementptr inbounds [100100 x i32], ptr @f, i64 0, i64 %34
  store i32 %32, ptr %35, align 4, !tbaa !9
  br label %46

36:                                               ; preds = %13
  %37 = load i32, ptr %4, align 4, !tbaa !9
  %38 = sext i32 %37 to i64
  %39 = getelementptr inbounds [100100 x i32], ptr @a, i64 0, i64 %38
  %40 = load i32, ptr %39, align 4, !tbaa !9
  %41 = load i32, ptr %4, align 4, !tbaa !9
  %42 = load i32, ptr %3, align 4, !tbaa !9
  %43 = call noundef i32 @_Z4Findiii(i32 noundef %41, i32 noundef 1, i32 noundef %42)
  %44 = sext i32 %43 to i64
  %45 = getelementptr inbounds [100100 x i32], ptr @b, i64 0, i64 %44
  store i32 %40, ptr %45, align 4, !tbaa !9
  br label %46

46:                                               ; preds = %36, %23
  br label %47

47:                                               ; preds = %46
  %48 = load i32, ptr %4, align 4, !tbaa !9
  %49 = add nsw i32 %48, 1
  store i32 %49, ptr %4, align 4, !tbaa !9
  br label %8, !llvm.loop !11

50:                                               ; preds = %12
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #2
  %51 = load i32, ptr @n, align 4, !tbaa !9
  store i32 %51, ptr %5, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #2
  %52 = load i32, ptr %3, align 4, !tbaa !9
  store i32 %52, ptr %6, align 4, !tbaa !9
  br label %53

53:                                               ; preds = %80, %50
  %54 = load i32, ptr %5, align 4, !tbaa !9
  %55 = icmp sge i32 %54, 1
  br i1 %55, label %56, label %59

56:                                               ; preds = %53
  %57 = load i32, ptr %6, align 4, !tbaa !9
  %58 = icmp sge i32 %57, 1
  br label %59

59:                                               ; preds = %56, %53
  %60 = phi i1 [ false, %53 ], [ %58, %56 ]
  br i1 %60, label %62, label %61

61:                                               ; preds = %59
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #2
  br label %83

62:                                               ; preds = %59
  %63 = load i32, ptr %5, align 4, !tbaa !9
  %64 = sext i32 %63 to i64
  %65 = getelementptr inbounds [100100 x i32], ptr @f, i64 0, i64 %64
  %66 = load i32, ptr %65, align 4, !tbaa !9
  %67 = load i32, ptr %6, align 4, !tbaa !9
  %68 = icmp eq i32 %66, %67
  br i1 %68, label %69, label %79

69:                                               ; preds = %62
  %70 = load i32, ptr %5, align 4, !tbaa !9
  %71 = sext i32 %70 to i64
  %72 = getelementptr inbounds [100100 x i32], ptr @a, i64 0, i64 %71
  %73 = load i32, ptr %72, align 4, !tbaa !9
  %74 = load ptr, ptr %2, align 8, !tbaa !5
  %75 = load i32, ptr %6, align 4, !tbaa !9
  %76 = add nsw i32 %75, -1
  store i32 %76, ptr %6, align 4, !tbaa !9
  %77 = sext i32 %76 to i64
  %78 = getelementptr inbounds i32, ptr %74, i64 %77
  store i32 %73, ptr %78, align 4, !tbaa !9
  br label %79

79:                                               ; preds = %69, %62
  br label %80

80:                                               ; preds = %79
  %81 = load i32, ptr %5, align 4, !tbaa !9
  %82 = add nsw i32 %81, -1
  store i32 %82, ptr %5, align 4, !tbaa !9
  br label %53, !llvm.loop !13

83:                                               ; preds = %61
  %84 = load i32, ptr %3, align 4, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #2
  ret i32 %84
}

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

@n = external dso_local local_unnamed_addr global i32, align 4
@a = external dso_local local_unnamed_addr global [100100 x i32], align 16
@b = external dso_local local_unnamed_addr global [100100 x i32], align 16
@f = external dso_local local_unnamed_addr global [100100 x i32], align 16

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i32 @_Z4Findiii(i32 noundef, i32 noundef, i32 noundef) local_unnamed_addr #0

; Function Attrs: mustprogress nounwind uwtable
define dso_local noundef i32 @_Z3LISPi(ptr nocapture noundef writeonly %0) local_unnamed_addr #0 {
  store i32 1, ptr getelementptr inbounds (i8, ptr @f, i64 4), align 4, !tbaa !5
  %2 = load i32, ptr getelementptr inbounds (i8, ptr @a, i64 4), align 4, !tbaa !5
  store i32 %2, ptr getelementptr inbounds (i8, ptr @b, i64 4), align 4, !tbaa !5
  %3 = load i32, ptr @n, align 4, !tbaa !5
  %.not27 = icmp slt i32 %3, 2
  br i1 %.not27, label %.preheader, label %.lr.ph

.preheader:                                       ; preds = %25, %1
  %.022.lcssa = phi i32 [ 1, %1 ], [ %.123, %25 ]
  %.lcssa = phi i32 [ %3, %1 ], [ %26, %25 ]
  %4 = icmp sgt i32 %.lcssa, 0
  %5 = icmp sgt i32 %.022.lcssa, 0
  %6 = and i1 %4, %5
  br i1 %6, label %.lr.ph33.preheader, label %._crit_edge

.lr.ph33.preheader:                               ; preds = %.preheader
  %7 = zext nneg i32 %.lcssa to i64
  br label %.lr.ph33

.lr.ph:                                           ; preds = %1, %25
  %8 = phi i32 [ %26, %25 ], [ %3, %1 ]
  %indvars.iv = phi i64 [ %indvars.iv.next, %25 ], [ 2, %1 ]
  %.02228 = phi i32 [ %.123, %25 ], [ 1, %1 ]
  %9 = getelementptr inbounds [100100 x i32], ptr @a, i64 0, i64 %indvars.iv
  %10 = load i32, ptr %9, align 4, !tbaa !5
  %11 = sext i32 %.02228 to i64
  %12 = getelementptr inbounds [100100 x i32], ptr @b, i64 0, i64 %11
  %13 = load i32, ptr %12, align 4, !tbaa !5
  %14 = icmp sgt i32 %10, %13
  br i1 %14, label %15, label %20

15:                                               ; preds = %.lr.ph
  %16 = add nsw i32 %.02228, 1
  %17 = sext i32 %16 to i64
  %18 = getelementptr inbounds [100100 x i32], ptr @b, i64 0, i64 %17
  store i32 %10, ptr %18, align 4, !tbaa !5
  %19 = getelementptr inbounds [100100 x i32], ptr @f, i64 0, i64 %indvars.iv
  store i32 %16, ptr %19, align 4, !tbaa !5
  br label %25

20:                                               ; preds = %.lr.ph
  %21 = trunc nuw nsw i64 %indvars.iv to i32
  %22 = tail call noundef i32 @_Z4Findiii(i32 noundef %21, i32 noundef 1, i32 noundef %.02228)
  %23 = sext i32 %22 to i64
  %24 = getelementptr inbounds [100100 x i32], ptr @b, i64 0, i64 %23
  store i32 %10, ptr %24, align 4, !tbaa !5
  %.pre = load i32, ptr @n, align 4, !tbaa !5
  br label %25

25:                                               ; preds = %15, %20
  %26 = phi i32 [ %8, %15 ], [ %.pre, %20 ]
  %.123 = phi i32 [ %16, %15 ], [ %.02228, %20 ]
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %27 = sext i32 %26 to i64
  %.not.not = icmp slt i64 %indvars.iv, %27
  br i1 %.not.not, label %.lr.ph, label %.preheader, !llvm.loop !9

._crit_edge:                                      ; preds = %37, %.preheader
  ret i32 %.022.lcssa

.lr.ph33:                                         ; preds = %.lr.ph33.preheader, %37
  %indvars.iv36 = phi i64 [ %7, %.lr.ph33.preheader ], [ %indvars.iv.next37, %37 ]
  %.032 = phi i32 [ %.022.lcssa, %.lr.ph33.preheader ], [ %.1, %37 ]
  %28 = getelementptr inbounds [100100 x i32], ptr @f, i64 0, i64 %indvars.iv36
  %29 = load i32, ptr %28, align 4, !tbaa !5
  %30 = icmp eq i32 %29, %.032
  br i1 %30, label %31, label %37

31:                                               ; preds = %.lr.ph33
  %32 = getelementptr inbounds [100100 x i32], ptr @a, i64 0, i64 %indvars.iv36
  %33 = load i32, ptr %32, align 4, !tbaa !5
  %34 = add nsw i32 %.032, -1
  %35 = zext nneg i32 %34 to i64
  %36 = getelementptr inbounds i32, ptr %0, i64 %35
  store i32 %33, ptr %36, align 4, !tbaa !5
  br label %37

37:                                               ; preds = %.lr.ph33, %31
  %.1 = phi i32 [ %34, %31 ], [ %.032, %.lr.ph33 ]
  %indvars.iv.next37 = add nsw i64 %indvars.iv36, -1
  %38 = icmp sgt i64 %indvars.iv36, 1
  %39 = icmp sgt i32 %.1, 0
  %40 = and i1 %38, %39
  br i1 %40, label %.lr.ph33, label %._crit_edge, !llvm.loop !11
}

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


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