; LLVM IR from lzyrapx/Competitive-Programming :: ACdream/1086（背包+dp）.ll (Z4initv)

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

@dp = external dso_local global [6200 x i32], align 16
@fa = external dso_local global [6200 x i32], align 16
@a = external dso_local global [6200 x i32], align 16
@_ZL3inf = external hidden constant i32, align 4

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i32 @_Z5checkx(i64 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 uwtable
define dso_local void @_Z4initv() #2 {
  %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
  call void @llvm.lifetime.start.p0(i64 4, ptr %1) #5
  store i32 0, ptr %1, align 4, !tbaa !5
  call void @_ZSt4fillIPiiEvT_S1_RKT0_(ptr noundef @dp, ptr noundef getelementptr inbounds (i32, ptr @dp, i64 6170), ptr noundef nonnull align 4 dereferenceable(4) @_ZL3inf)
  call void @llvm.memset.p0.i64(ptr align 16 @fa, i8 -1, i64 24800, i1 false)
  call void @llvm.lifetime.start.p0(i64 4, ptr %2) #5
  store i32 1, ptr %2, align 4, !tbaa !5
  br label %6

6:                                                ; preds = %22, %0
  %7 = load i32, ptr %2, align 4, !tbaa !5
  %8 = icmp sle i32 %7, 6161
  br i1 %8, label %10, label %9

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

10:                                               ; preds = %6
  %11 = load i32, ptr %2, align 4, !tbaa !5
  %12 = sext i32 %11 to i64
  %13 = call noundef i32 @_Z5checkx(i64 noundef %12)
  %14 = icmp ne i32 %13, 0
  br i1 %14, label %15, label %21

15:                                               ; preds = %10
  %16 = load i32, ptr %2, align 4, !tbaa !5
  %17 = load i32, ptr %1, align 4, !tbaa !5
  %18 = add nsw i32 %17, 1
  store i32 %18, ptr %1, align 4, !tbaa !5
  %19 = sext i32 %17 to i64
  %20 = getelementptr inbounds [6200 x i32], ptr @a, i64 0, i64 %19
  store i32 %16, ptr %20, align 4, !tbaa !5
  br label %21

21:                                               ; preds = %15, %10
  br label %22

22:                                               ; preds = %21
  %23 = load i32, ptr %2, align 4, !tbaa !5
  %24 = add nsw i32 %23, 1
  store i32 %24, ptr %2, align 4, !tbaa !5
  br label %6, !llvm.loop !9

25:                                               ; preds = %9
  store i32 0, ptr @dp, align 16, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #5
  store i32 1, ptr %3, align 4, !tbaa !5
  br label %26

26:                                               ; preds = %89, %25
  %27 = load i32, ptr %3, align 4, !tbaa !5
  %28 = icmp sle i32 %27, 6161
  br i1 %28, label %30, label %29

29:                                               ; preds = %26
  store i32 5, ptr %4, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #5
  br label %92

30:                                               ; preds = %26
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #5
  store i32 0, ptr %5, align 4, !tbaa !5
  br label %31

31:                                               ; preds = %85, %30
  %32 = load i32, ptr %5, align 4, !tbaa !5
  %33 = load i32, ptr %1, align 4, !tbaa !5
  %34 = icmp slt i32 %32, %33
  br i1 %34, label %35, label %42

35:                                               ; preds = %31
  %36 = load i32, ptr %3, align 4, !tbaa !5
  %37 = load i32, ptr %5, align 4, !tbaa !5
  %38 = sext i32 %37 to i64
  %39 = getelementptr inbounds [6200 x i32], ptr @a, i64 0, i64 %38
  %40 = load i32, ptr %39, align 4, !tbaa !5
  %41 = icmp sge i32 %36, %40
  br label %42

42:                                               ; preds = %35, %31
  %43 = phi i1 [ false, %31 ], [ %41, %35 ]
  br i1 %43, label %45, label %44

44:                                               ; preds = %42
  store i32 8, ptr %4, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #5
  br label %88

45:                                               ; preds = %42
  %46 = load i32, ptr %3, align 4, !tbaa !5
  %47 = sext i32 %46 to i64
  %48 = getelementptr inbounds [6200 x i32], ptr @dp, i64 0, i64 %47
  %49 = load i32, ptr %48, align 4, !tbaa !5
  %50 = load i32, ptr %3, align 4, !tbaa !5
  %51 = load i32, ptr %5, align 4, !tbaa !5
  %52 = sext i32 %51 to i64
  %53 = getelementptr inbounds [6200 x i32], ptr @a, i64 0, i64 %52
  %54 = load i32, ptr %53, align 4, !tbaa !5
  %55 = sub nsw i32 %50, %54
  %56 = sext i32 %55 to i64
  %57 = getelementptr inbounds [6200 x i32], ptr @dp, i64 0, i64 %56
  %58 = load i32, ptr %57, align 4, !tbaa !5
  %59 = add nsw i32 %58, 1
  %60 = icmp sgt i32 %49, %59
  br i1 %60, label %61, label %84

61:                                               ; preds = %45
  %62 = load i32, ptr %3, align 4, !tbaa !5
  %63 = load i32, ptr %5, align 4, !tbaa !5
  %64 = sext i32 %63 to i64
  %65 = getelementptr inbounds [6200 x i32], ptr @a, i64 0, i64 %64
  %66 = load i32, ptr %65, align 4, !tbaa !5
  %67 = sub nsw i32 %62, %66
  %68 = sext i32 %67 to i64
  %69 = getelementptr inbounds [6200 x i32], ptr @dp, i64 0, i64 %68
  %70 = load i32, ptr %69, align 4, !tbaa !5
  %71 = add nsw i32 %70, 1
  %72 = load i32, ptr %3, align 4, !tbaa !5
  %73 = sext i32 %72 to i64
  %74 = getelementptr inbounds [6200 x i32], ptr @dp, i64 0, i64 %73
  store i32 %71, ptr %74, align 4, !tbaa !5
  %75 = load i32, ptr %3, align 4, !tbaa !5
  %76 = load i32, ptr %5, align 4, !tbaa !5
  %77 = sext i32 %76 to i64
  %78 = getelementptr inbounds [6200 x i32], ptr @a, i64 0, i64 %77
  %79 = load i32, ptr %78, align 4, !tbaa !5
  %80 = sub nsw i32 %75, %79
  %81 = load i32, ptr %3, align 4, !tbaa !5
  %82 = sext i32 %81 to i64
  %83 = getelementptr inbounds [6200 x i32], ptr @fa, i64 0, i64 %82
  store i32 %80, ptr %83, align 4, !tbaa !5
  br label %84

84:                                               ; preds = %61, %45
  br label %85

85:                                               ; preds = %84
  %86 = load i32, ptr %5, align 4, !tbaa !5
  %87 = add nsw i32 %86, 1
  store i32 %87, ptr %5, align 4, !tbaa !5
  br label %31, !llvm.loop !11

88:                                               ; preds = %44
  br label %89

89:                                               ; preds = %88
  %90 = load i32, ptr %3, align 4, !tbaa !5
  %91 = add nsw i32 %90, 1
  store i32 %91, ptr %3, align 4, !tbaa !5
  br label %26, !llvm.loop !12

92:                                               ; preds = %29
  call void @llvm.lifetime.end.p0(i64 4, ptr %1) #5
  ret void
}

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local void @_ZSt4fillIPiiEvT_S1_RKT0_(ptr noundef, ptr noundef, ptr noundef nonnull align 4 dereferenceable(4)) #3

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #4

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 = { 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" }
attributes #3 = { inlinehint 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" }
attributes #4 = { nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #5 = { 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"

@dp = external dso_local global [6200 x i32], align 16
@fa = external dso_local local_unnamed_addr global [6200 x i32], align 16
@a = external dso_local local_unnamed_addr global [6200 x i32], align 16
@_ZL3inf = external hidden constant i32, align 4

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

; Function Attrs: mustprogress uwtable
define dso_local void @_Z4initv() local_unnamed_addr #1 {
  tail call void @_ZSt4fillIPiiEvT_S1_RKT0_(ptr noundef nonnull @dp, ptr noundef nonnull getelementptr inbounds (i8, ptr @dp, i64 24680), ptr noundef nonnull align 4 dereferenceable(4) @_ZL3inf)
  tail call void @llvm.memset.p0.i64(ptr noundef nonnull align 16 dereferenceable(24800) @fa, i8 -1, i64 24800, i1 false)
  br label %20

1:                                                ; preds = %27
  store i32 0, ptr @dp, align 16, !tbaa !5
  %2 = icmp sgt i32 %.1, 0
  br i1 %2, label %.preheader.us.preheader, label %.split33.us

.preheader.us.preheader:                          ; preds = %1
  %wide.trip.count = zext nneg i32 %.1 to i64
  br label %.preheader.us

.preheader.us:                                    ; preds = %.preheader.us.preheader, %.critedge.us
  %indvars.iv40 = phi i64 [ 1, %.preheader.us.preheader ], [ %indvars.iv.next41, %.critedge.us ]
  %3 = getelementptr inbounds [6200 x i32], ptr @dp, i64 0, i64 %indvars.iv40
  %4 = getelementptr inbounds [6200 x i32], ptr @fa, i64 0, i64 %indvars.iv40
  %5 = trunc nuw nsw i64 %indvars.iv40 to i32
  br label %6

6:                                                ; preds = %.preheader.us, %19
  %indvars.iv36 = phi i64 [ 0, %.preheader.us ], [ %indvars.iv.next37, %19 ]
  %7 = getelementptr inbounds [6200 x i32], ptr @a, i64 0, i64 %indvars.iv36
  %8 = load i32, ptr %7, align 4, !tbaa !5
  %9 = sext i32 %8 to i64
  %.not.us = icmp slt i64 %indvars.iv40, %9
  br i1 %.not.us, label %.critedge.us, label %10

10:                                               ; preds = %6
  %11 = load i32, ptr %3, align 4, !tbaa !5
  %12 = sub nsw i32 %5, %8
  %13 = sext i32 %12 to i64
  %14 = getelementptr inbounds [6200 x i32], ptr @dp, i64 0, i64 %13
  %15 = load i32, ptr %14, align 4, !tbaa !5
  %16 = add nsw i32 %15, 1
  %17 = icmp sgt i32 %11, %16
  br i1 %17, label %18, label %19

18:                                               ; preds = %10
  store i32 %16, ptr %3, align 4, !tbaa !5
  store i32 %12, ptr %4, align 4, !tbaa !5
  br label %19

19:                                               ; preds = %18, %10
  %indvars.iv.next37 = add nuw nsw i64 %indvars.iv36, 1
  %exitcond39.not = icmp eq i64 %indvars.iv.next37, %wide.trip.count
  br i1 %exitcond39.not, label %.critedge.us, label %6, !llvm.loop !9

.critedge.us:                                     ; preds = %6, %19
  %indvars.iv.next41 = add nuw nsw i64 %indvars.iv40, 1
  %exitcond43.not = icmp eq i64 %indvars.iv.next41, 6162
  br i1 %exitcond43.not, label %.split33.us, label %.preheader.us, !llvm.loop !11

20:                                               ; preds = %0, %27
  %indvars.iv = phi i64 [ 1, %0 ], [ %indvars.iv.next, %27 ]
  %.02327 = phi i32 [ 0, %0 ], [ %.1, %27 ]
  %21 = tail call noundef i32 @_Z5checkx(i64 noundef %indvars.iv)
  %.not26 = icmp eq i32 %21, 0
  br i1 %.not26, label %27, label %22

22:                                               ; preds = %20
  %23 = add nsw i32 %.02327, 1
  %24 = sext i32 %.02327 to i64
  %25 = getelementptr inbounds [6200 x i32], ptr @a, i64 0, i64 %24
  %26 = trunc nuw nsw i64 %indvars.iv to i32
  store i32 %26, ptr %25, align 4, !tbaa !5
  br label %27

27:                                               ; preds = %20, %22
  %.1 = phi i32 [ %23, %22 ], [ %.02327, %20 ]
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %exitcond.not = icmp eq i64 %indvars.iv.next, 6162
  br i1 %exitcond.not, label %1, label %20, !llvm.loop !12

.split33.us:                                      ; preds = %.critedge.us, %1
  ret void
}

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local void @_ZSt4fillIPiiEvT_S1_RKT0_(ptr noundef, ptr noundef, ptr noundef nonnull align 4 dereferenceable(4)) local_unnamed_addr #2

; Function Attrs: mustprogress nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #3

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" }
attributes #2 = { inlinehint 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" }
attributes #3 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: write) }

!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: EarlyCSEPass,GVNPass,GlobalOptPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LICMPass,LoopRotatePass,LoopSimplifyCFGPass,LoopSimplifyPass,LoopUnrollPass,SROAPass,SimplifyCFGPass,TailCallElimPass