; LLVM IR from lzyrapx/Competitive-Programming :: ACdream/1102（树形dp）.ll (Z4findiii)

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

@f = external dso_local global [3010 x i32], align 16
@d = external dso_local global [3010 x i32], align 16
@id = external dso_local global [3010 x i32], align 16
@cnt = external dso_local global i32, align 4

; Function Attrs: mustprogress nounwind uwtable
define dso_local void @_Z4findiii(i32 noundef %0, i32 noundef %1, i32 noundef %2) #0 {
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  store i32 %0, ptr %4, align 4, !tbaa !5
  store i32 %1, ptr %5, align 4, !tbaa !5
  store i32 %2, ptr %6, align 4, !tbaa !5
  store i32 0, ptr @cnt, align 4, !tbaa !5
  %7 = load i32, ptr %5, align 4, !tbaa !5
  %8 = sext i32 %7 to i64
  %9 = getelementptr inbounds [3010 x i32], ptr @d, i64 0, i64 %8
  %10 = load i32, ptr %9, align 4, !tbaa !5
  %11 = load i32, ptr %6, align 4, !tbaa !5
  %12 = sext i32 %11 to i64
  %13 = getelementptr inbounds [3010 x i32], ptr @d, i64 0, i64 %12
  %14 = load i32, ptr %13, align 4, !tbaa !5
  %15 = icmp slt i32 %10, %14
  br i1 %15, label %16, label %17

16:                                               ; preds = %3
  call void @_ZSt4swapIiENSt9enable_ifIXsr6__and_ISt6__not_ISt15__is_tuple_likeIT_EESt21is_move_constructibleIS3_ESt18is_move_assignableIS3_EEE5valueEvE4typeERS3_SC_(ptr noundef nonnull align 4 dereferenceable(4) %5, ptr noundef nonnull align 4 dereferenceable(4) %6) #2
  br label %17

17:                                               ; preds = %16, %3
  br label %18

18:                                               ; preds = %28, %17
  %19 = load i32, ptr %5, align 4, !tbaa !5
  %20 = sext i32 %19 to i64
  %21 = getelementptr inbounds [3010 x i32], ptr @d, i64 0, i64 %20
  %22 = load i32, ptr %21, align 4, !tbaa !5
  %23 = load i32, ptr %6, align 4, !tbaa !5
  %24 = sext i32 %23 to i64
  %25 = getelementptr inbounds [3010 x i32], ptr @d, i64 0, i64 %24
  %26 = load i32, ptr %25, align 4, !tbaa !5
  %27 = icmp ne i32 %22, %26
  br i1 %27, label %28, label %38

28:                                               ; preds = %18
  %29 = load i32, ptr %5, align 4, !tbaa !5
  %30 = load i32, ptr @cnt, align 4, !tbaa !5
  %31 = add nsw i32 %30, 1
  store i32 %31, ptr @cnt, align 4, !tbaa !5
  %32 = sext i32 %30 to i64
  %33 = getelementptr inbounds [3010 x i32], ptr @id, i64 0, i64 %32
  store i32 %29, ptr %33, align 4, !tbaa !5
  %34 = load i32, ptr %5, align 4, !tbaa !5
  %35 = sext i32 %34 to i64
  %36 = getelementptr inbounds [3010 x i32], ptr @f, i64 0, i64 %35
  %37 = load i32, ptr %36, align 4, !tbaa !5
  store i32 %37, ptr %5, align 4, !tbaa !5
  br label %18, !llvm.loop !9

38:                                               ; preds = %18
  br label %39

39:                                               ; preds = %43, %38
  %40 = load i32, ptr %5, align 4, !tbaa !5
  %41 = load i32, ptr %6, align 4, !tbaa !5
  %42 = icmp ne i32 %40, %41
  br i1 %42, label %43, label %62

43:                                               ; preds = %39
  %44 = load i32, ptr %5, align 4, !tbaa !5
  %45 = load i32, ptr @cnt, align 4, !tbaa !5
  %46 = add nsw i32 %45, 1
  store i32 %46, ptr @cnt, align 4, !tbaa !5
  %47 = sext i32 %45 to i64
  %48 = getelementptr inbounds [3010 x i32], ptr @id, i64 0, i64 %47
  store i32 %44, ptr %48, align 4, !tbaa !5
  %49 = load i32, ptr %6, align 4, !tbaa !5
  %50 = load i32, ptr @cnt, align 4, !tbaa !5
  %51 = add nsw i32 %50, 1
  store i32 %51, ptr @cnt, align 4, !tbaa !5
  %52 = sext i32 %50 to i64
  %53 = getelementptr inbounds [3010 x i32], ptr @id, i64 0, i64 %52
  store i32 %49, ptr %53, align 4, !tbaa !5
  %54 = load i32, ptr %5, align 4, !tbaa !5
  %55 = sext i32 %54 to i64
  %56 = getelementptr inbounds [3010 x i32], ptr @f, i64 0, i64 %55
  %57 = load i32, ptr %56, align 4, !tbaa !5
  store i32 %57, ptr %5, align 4, !tbaa !5
  %58 = load i32, ptr %6, align 4, !tbaa !5
  %59 = sext i32 %58 to i64
  %60 = getelementptr inbounds [3010 x i32], ptr @f, i64 0, i64 %59
  %61 = load i32, ptr %60, align 4, !tbaa !5
  store i32 %61, ptr %6, align 4, !tbaa !5
  br label %39, !llvm.loop !11

62:                                               ; preds = %39
  br label %63

63:                                               ; preds = %67, %62
  %64 = load i32, ptr %5, align 4, !tbaa !5
  %65 = load i32, ptr %4, align 4, !tbaa !5
  %66 = icmp ne i32 %64, %65
  br i1 %66, label %67, label %77

67:                                               ; preds = %63
  %68 = load i32, ptr %5, align 4, !tbaa !5
  %69 = load i32, ptr @cnt, align 4, !tbaa !5
  %70 = add nsw i32 %69, 1
  store i32 %70, ptr @cnt, align 4, !tbaa !5
  %71 = sext i32 %69 to i64
  %72 = getelementptr inbounds [3010 x i32], ptr @id, i64 0, i64 %71
  store i32 %68, ptr %72, align 4, !tbaa !5
  %73 = load i32, ptr %5, align 4, !tbaa !5
  %74 = sext i32 %73 to i64
  %75 = getelementptr inbounds [3010 x i32], ptr @f, i64 0, i64 %74
  %76 = load i32, ptr %75, align 4, !tbaa !5
  store i32 %76, ptr %5, align 4, !tbaa !5
  br label %63, !llvm.loop !12

77:                                               ; preds = %63
  %78 = load i32, ptr %4, align 4, !tbaa !5
  %79 = load i32, ptr @cnt, align 4, !tbaa !5
  %80 = add nsw i32 %79, 1
  store i32 %80, ptr @cnt, align 4, !tbaa !5
  %81 = sext i32 %79 to i64
  %82 = getelementptr inbounds [3010 x i32], ptr @id, i64 0, i64 %81
  store i32 %78, ptr %82, align 4, !tbaa !5
  ret void
}

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local void @_ZSt4swapIiENSt9enable_ifIXsr6__and_ISt6__not_ISt15__is_tuple_likeIT_EESt21is_move_constructibleIS3_ESt18is_move_assignableIS3_EEE5valueEvE4typeERS3_SC_(ptr noundef nonnull align 4 dereferenceable(4), ptr noundef nonnull align 4 dereferenceable(4)) #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 = { inlinehint 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 #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 = !{!"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}
!12 = distinct !{!12, !10}


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

@f = external dso_local local_unnamed_addr global [3010 x i32], align 16
@d = external dso_local local_unnamed_addr global [3010 x i32], align 16
@id = external dso_local local_unnamed_addr global [3010 x i32], align 16
@cnt = external dso_local local_unnamed_addr global i32, align 4

; Function Attrs: mustprogress nounwind uwtable
define dso_local void @_Z4findiii(i32 noundef %0, i32 noundef %1, i32 noundef %2) local_unnamed_addr #0 {
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  store i32 %1, ptr %4, align 4, !tbaa !5
  store i32 %2, ptr %5, align 4, !tbaa !5
  store i32 0, ptr @cnt, align 4, !tbaa !5
  %6 = sext i32 %1 to i64
  %7 = getelementptr inbounds [3010 x i32], ptr @d, i64 0, i64 %6
  %8 = load i32, ptr %7, align 4, !tbaa !5
  %9 = sext i32 %2 to i64
  %10 = getelementptr inbounds [3010 x i32], ptr @d, i64 0, i64 %9
  %11 = load i32, ptr %10, align 4, !tbaa !5
  %12 = icmp slt i32 %8, %11
  br i1 %12, label %13, label %14

13:                                               ; preds = %3
  call void @_ZSt4swapIiENSt9enable_ifIXsr6__and_ISt6__not_ISt15__is_tuple_likeIT_EESt21is_move_constructibleIS3_ESt18is_move_assignableIS3_EEE5valueEvE4typeERS3_SC_(ptr noundef nonnull align 4 dereferenceable(4) %4, ptr noundef nonnull align 4 dereferenceable(4) %5) #2
  %.pre = load i32, ptr %5, align 4, !tbaa !5
  %.phi.trans.insert = sext i32 %.pre to i64
  %.phi.trans.insert36 = getelementptr inbounds [3010 x i32], ptr @d, i64 0, i64 %.phi.trans.insert
  %.pre37 = load i32, ptr %.phi.trans.insert36, align 4, !tbaa !5
  %.promoted.pre = load i32, ptr %4, align 4, !tbaa !5
  %cnt.promoted.pre = load i32, ptr @cnt, align 4, !tbaa !5
  %.phi.trans.insert40 = sext i32 %.promoted.pre to i64
  %.phi.trans.insert41 = getelementptr inbounds [3010 x i32], ptr @d, i64 0, i64 %.phi.trans.insert40
  %.pre42 = load i32, ptr %.phi.trans.insert41, align 4, !tbaa !5
  br label %14

14:                                               ; preds = %13, %3
  %.pre-phi47 = phi i64 [ %.phi.trans.insert40, %13 ], [ %6, %3 ]
  %15 = phi i32 [ %.pre42, %13 ], [ %8, %3 ]
  %cnt.promoted = phi i32 [ %cnt.promoted.pre, %13 ], [ 0, %3 ]
  %.promoted = phi i32 [ %.promoted.pre, %13 ], [ %1, %3 ]
  %16 = phi i32 [ %.pre37, %13 ], [ %11, %3 ]
  %.promoted10 = phi i32 [ %.pre, %13 ], [ %2, %3 ]
  %.not7 = icmp eq i32 %15, %16
  br i1 %.not7, label %.preheader6, label %.lr.ph.preheader

.lr.ph.preheader:                                 ; preds = %14
  %17 = sext i32 %cnt.promoted to i64
  br label %.lr.ph

..preheader6_crit_edge:                           ; preds = %.lr.ph
  %18 = trunc nsw i64 %indvars.iv.next to i32
  br label %.preheader6

.preheader6:                                      ; preds = %..preheader6_crit_edge, %14
  %cnt.promoted11 = phi i32 [ %18, %..preheader6_crit_edge ], [ %cnt.promoted, %14 ]
  %.promoted9 = phi i32 [ %24, %..preheader6_crit_edge ], [ %.promoted, %14 ]
  %.not412 = icmp eq i32 %.promoted9, %.promoted10
  br i1 %.not412, label %.preheader, label %.lr.ph13.preheader

.lr.ph13.preheader:                               ; preds = %.preheader6
  %19 = sext i32 %cnt.promoted11 to i64
  br label %.lr.ph13

.lr.ph:                                           ; preds = %.lr.ph.preheader, %.lr.ph
  %indvars.iv = phi i64 [ %17, %.lr.ph.preheader ], [ %indvars.iv.next, %.lr.ph ]
  %20 = phi i64 [ %.pre-phi47, %.lr.ph.preheader ], [ %25, %.lr.ph ]
  %21 = phi i32 [ %.promoted, %.lr.ph.preheader ], [ %24, %.lr.ph ]
  %indvars.iv.next = add nsw i64 %indvars.iv, 1
  %22 = getelementptr inbounds [3010 x i32], ptr @id, i64 0, i64 %indvars.iv
  store i32 %21, ptr %22, align 4, !tbaa !5
  %23 = getelementptr inbounds [3010 x i32], ptr @f, i64 0, i64 %20
  %24 = load i32, ptr %23, align 4, !tbaa !5
  %25 = sext i32 %24 to i64
  %26 = getelementptr inbounds [3010 x i32], ptr @d, i64 0, i64 %25
  %27 = load i32, ptr %26, align 4, !tbaa !5
  %.not = icmp eq i32 %27, %16
  br i1 %.not, label %..preheader6_crit_edge, label %.lr.ph, !llvm.loop !9

..preheader_crit_edge:                            ; preds = %.lr.ph13
  %28 = trunc nsw i64 %indvars.iv.next31 to i32
  br label %.preheader

.preheader:                                       ; preds = %..preheader_crit_edge, %.preheader6
  %cnt.promoted18 = phi i32 [ %28, %..preheader_crit_edge ], [ %cnt.promoted11, %.preheader6 ]
  %.promoted17 = phi i32 [ %37, %..preheader_crit_edge ], [ %.promoted10, %.preheader6 ]
  %.not519 = icmp eq i32 %.promoted17, %0
  br i1 %.not519, label %47, label %.lr.ph20.preheader

.lr.ph20.preheader:                               ; preds = %.preheader
  %29 = sext i32 %cnt.promoted18 to i64
  br label %.lr.ph20

.lr.ph13:                                         ; preds = %.lr.ph13.preheader, %.lr.ph13
  %indvars.iv30 = phi i64 [ %19, %.lr.ph13.preheader ], [ %indvars.iv.next31, %.lr.ph13 ]
  %30 = phi i32 [ %.promoted9, %.lr.ph13.preheader ], [ %37, %.lr.ph13 ]
  %31 = phi i32 [ %.promoted10, %.lr.ph13.preheader ], [ %40, %.lr.ph13 ]
  %32 = add nsw i64 %indvars.iv30, 1
  %33 = getelementptr inbounds [3010 x i32], ptr @id, i64 0, i64 %indvars.iv30
  store i32 %30, ptr %33, align 4, !tbaa !5
  %indvars.iv.next31 = add nsw i64 %indvars.iv30, 2
  %34 = getelementptr inbounds [3010 x i32], ptr @id, i64 0, i64 %32
  store i32 %31, ptr %34, align 4, !tbaa !5
  %35 = sext i32 %30 to i64
  %36 = getelementptr inbounds [3010 x i32], ptr @f, i64 0, i64 %35
  %37 = load i32, ptr %36, align 4, !tbaa !5
  %38 = sext i32 %31 to i64
  %39 = getelementptr inbounds [3010 x i32], ptr @f, i64 0, i64 %38
  %40 = load i32, ptr %39, align 4, !tbaa !5
  %.not4 = icmp eq i32 %37, %40
  br i1 %.not4, label %..preheader_crit_edge, label %.lr.ph13, !llvm.loop !11

.lr.ph20:                                         ; preds = %.lr.ph20.preheader, %.lr.ph20
  %indvars.iv33 = phi i64 [ %29, %.lr.ph20.preheader ], [ %indvars.iv.next34, %.lr.ph20 ]
  %41 = phi i32 [ %.promoted17, %.lr.ph20.preheader ], [ %45, %.lr.ph20 ]
  %indvars.iv.next34 = add nsw i64 %indvars.iv33, 1
  %42 = getelementptr inbounds [3010 x i32], ptr @id, i64 0, i64 %indvars.iv33
  store i32 %41, ptr %42, align 4, !tbaa !5
  %43 = sext i32 %41 to i64
  %44 = getelementptr inbounds [3010 x i32], ptr @f, i64 0, i64 %43
  %45 = load i32, ptr %44, align 4, !tbaa !5
  %.not5 = icmp eq i32 %45, %0
  br i1 %.not5, label %._crit_edge, label %.lr.ph20, !llvm.loop !12

._crit_edge:                                      ; preds = %.lr.ph20
  %46 = trunc nsw i64 %indvars.iv.next34 to i32
  br label %47

47:                                               ; preds = %._crit_edge, %.preheader
  %48 = phi i32 [ %46, %._crit_edge ], [ %cnt.promoted18, %.preheader ]
  %49 = add nsw i32 %48, 1
  store i32 %49, ptr @cnt, align 4, !tbaa !5
  %50 = sext i32 %48 to i64
  %51 = getelementptr inbounds [3010 x i32], ptr @id, i64 0, i64 %50
  store i32 %0, ptr %51, align 4, !tbaa !5
  ret void
}

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local void @_ZSt4swapIiENSt9enable_ifIXsr6__and_ISt6__not_ISt15__is_tuple_likeIT_EESt21is_move_constructibleIS3_ESt18is_move_assignableIS3_EEE5valueEvE4typeERS3_SC_(ptr noundef nonnull align 4 dereferenceable(4), ptr noundef nonnull align 4 dereferenceable(4)) local_unnamed_addr #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 = { inlinehint 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 #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 = !{!"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}
!12 = distinct !{!12, !10}


; Effective O3 passes: BDCEPass,DSEPass,EarlyCSEPass,GVNPass,GlobalOptPass,IndVarSimplifyPass,InferAlignmentPass,InstCombinePass,InstSimplifyPass,LCSSAPass,LICMPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,SROAPass,SimplifyCFGPass