; LLVM IR from Tunghohin/Competitive_Coding :: Luogu/p1270.ll (Z3dfsii)

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

@t = external dso_local global [1010 x i32], align 16
@val = external dso_local global [1010 x i32], align 16
@dp = external dso_local global [1010 x [1010 x i64]], align 16

; Function Attrs: mustprogress uwtable
define dso_local void @_Z3dfsii(i32 noundef %0, i32 noundef %1) #0 {
  %3 = alloca i32, align 4
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  %7 = alloca i64, align 8
  store i32 %0, ptr %3, align 4, !tbaa !5
  store i32 %1, ptr %4, align 4, !tbaa !5
  %8 = load i32, ptr %3, align 4, !tbaa !5
  %9 = sext i32 %8 to i64
  %10 = getelementptr inbounds [1010 x [1010 x i64]], ptr @dp, i64 0, i64 %9
  %11 = load i32, ptr %4, align 4, !tbaa !5
  %12 = sext i32 %11 to i64
  %13 = getelementptr inbounds [1010 x i64], ptr %10, i64 0, i64 %12
  %14 = load i64, ptr %13, align 8, !tbaa !9
  %15 = icmp ne i64 %14, 0
  br i1 %15, label %19, label %16

16:                                               ; preds = %2
  %17 = load i32, ptr %4, align 4, !tbaa !5
  %18 = icmp ne i32 %17, 0
  br i1 %18, label %20, label %19

19:                                               ; preds = %16, %2
  br label %114

20:                                               ; preds = %16
  %21 = load i32, ptr %3, align 4, !tbaa !5
  %22 = sext i32 %21 to i64
  %23 = getelementptr inbounds [1010 x i32], ptr @val, i64 0, i64 %22
  %24 = load i32, ptr %23, align 4, !tbaa !5
  %25 = icmp ne i32 %24, 0
  br i1 %25, label %26, label %46

26:                                               ; preds = %20
  %27 = load i32, ptr %3, align 4, !tbaa !5
  %28 = sext i32 %27 to i64
  %29 = getelementptr inbounds [1010 x i32], ptr @val, i64 0, i64 %28
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #3
  %30 = load i32, ptr %4, align 4, !tbaa !5
  %31 = load i32, ptr %3, align 4, !tbaa !5
  %32 = sext i32 %31 to i64
  %33 = getelementptr inbounds [1010 x i32], ptr @t, i64 0, i64 %32
  %34 = load i32, ptr %33, align 4, !tbaa !5
  %35 = sub nsw i32 %30, %34
  %36 = sdiv i32 %35, 5
  store i32 %36, ptr %5, align 4, !tbaa !5
  %37 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZSt3minIiERKT_S2_S2_(ptr noundef nonnull align 4 dereferenceable(4) %29, ptr noundef nonnull align 4 dereferenceable(4) %5)
  %38 = load i32, ptr %37, align 4, !tbaa !5
  %39 = sext i32 %38 to i64
  %40 = load i32, ptr %3, align 4, !tbaa !5
  %41 = sext i32 %40 to i64
  %42 = getelementptr inbounds [1010 x [1010 x i64]], ptr @dp, i64 0, i64 %41
  %43 = load i32, ptr %4, align 4, !tbaa !5
  %44 = sext i32 %43 to i64
  %45 = getelementptr inbounds [1010 x i64], ptr %42, i64 0, i64 %44
  store i64 %39, ptr %45, align 8, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #3
  br label %114

46:                                               ; preds = %20
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #3
  store i32 0, ptr %6, align 4, !tbaa !5
  br label %47

47:                                               ; preds = %111, %46
  %48 = load i32, ptr %6, align 4, !tbaa !5
  %49 = load i32, ptr %4, align 4, !tbaa !5
  %50 = load i32, ptr %3, align 4, !tbaa !5
  %51 = sext i32 %50 to i64
  %52 = getelementptr inbounds [1010 x i32], ptr @t, i64 0, i64 %51
  %53 = load i32, ptr %52, align 4, !tbaa !5
  %54 = sub nsw i32 %49, %53
  %55 = icmp sle i32 %48, %54
  br i1 %55, label %57, label %56

56:                                               ; preds = %47
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #3
  br label %114

57:                                               ; preds = %47
  %58 = load i32, ptr %3, align 4, !tbaa !5
  %59 = shl i32 %58, 1
  %60 = load i32, ptr %6, align 4, !tbaa !5
  call void @_Z3dfsii(i32 noundef %59, i32 noundef %60)
  %61 = load i32, ptr %3, align 4, !tbaa !5
  %62 = shl i32 %61, 1
  %63 = or i32 %62, 1
  %64 = load i32, ptr %4, align 4, !tbaa !5
  %65 = load i32, ptr %3, align 4, !tbaa !5
  %66 = sext i32 %65 to i64
  %67 = getelementptr inbounds [1010 x i32], ptr @t, i64 0, i64 %66
  %68 = load i32, ptr %67, align 4, !tbaa !5
  %69 = sub nsw i32 %64, %68
  %70 = load i32, ptr %6, align 4, !tbaa !5
  %71 = sub nsw i32 %69, %70
  call void @_Z3dfsii(i32 noundef %63, i32 noundef %71)
  %72 = load i32, ptr %3, align 4, !tbaa !5
  %73 = sext i32 %72 to i64
  %74 = getelementptr inbounds [1010 x [1010 x i64]], ptr @dp, i64 0, i64 %73
  %75 = load i32, ptr %4, align 4, !tbaa !5
  %76 = sext i32 %75 to i64
  %77 = getelementptr inbounds [1010 x i64], ptr %74, i64 0, i64 %76
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #3
  %78 = load i32, ptr %3, align 4, !tbaa !5
  %79 = shl i32 %78, 1
  %80 = sext i32 %79 to i64
  %81 = getelementptr inbounds [1010 x [1010 x i64]], ptr @dp, i64 0, i64 %80
  %82 = load i32, ptr %6, align 4, !tbaa !5
  %83 = sext i32 %82 to i64
  %84 = getelementptr inbounds [1010 x i64], ptr %81, i64 0, i64 %83
  %85 = load i64, ptr %84, align 8, !tbaa !9
  %86 = load i32, ptr %3, align 4, !tbaa !5
  %87 = shl i32 %86, 1
  %88 = or i32 %87, 1
  %89 = sext i32 %88 to i64
  %90 = getelementptr inbounds [1010 x [1010 x i64]], ptr @dp, i64 0, i64 %89
  %91 = load i32, ptr %4, align 4, !tbaa !5
  %92 = load i32, ptr %3, align 4, !tbaa !5
  %93 = sext i32 %92 to i64
  %94 = getelementptr inbounds [1010 x i32], ptr @t, i64 0, i64 %93
  %95 = load i32, ptr %94, align 4, !tbaa !5
  %96 = sub nsw i32 %91, %95
  %97 = load i32, ptr %6, align 4, !tbaa !5
  %98 = sub nsw i32 %96, %97
  %99 = sext i32 %98 to i64
  %100 = getelementptr inbounds [1010 x i64], ptr %90, i64 0, i64 %99
  %101 = load i64, ptr %100, align 8, !tbaa !9
  %102 = add nsw i64 %85, %101
  store i64 %102, ptr %7, align 8, !tbaa !9
  %103 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZSt3maxIxERKT_S2_S2_(ptr noundef nonnull align 8 dereferenceable(8) %77, ptr noundef nonnull align 8 dereferenceable(8) %7)
  %104 = load i64, ptr %103, align 8, !tbaa !9
  %105 = load i32, ptr %3, align 4, !tbaa !5
  %106 = sext i32 %105 to i64
  %107 = getelementptr inbounds [1010 x [1010 x i64]], ptr @dp, i64 0, i64 %106
  %108 = load i32, ptr %4, align 4, !tbaa !5
  %109 = sext i32 %108 to i64
  %110 = getelementptr inbounds [1010 x i64], ptr %107, i64 0, i64 %109
  store i64 %104, ptr %110, align 8, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #3
  br label %111

111:                                              ; preds = %57
  %112 = load i32, ptr %6, align 4, !tbaa !5
  %113 = add nsw i32 %112, 1
  store i32 %113, ptr %6, align 4, !tbaa !5
  br label %47, !llvm.loop !11

114:                                              ; preds = %56, %26, %19
  ret void
}

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef nonnull align 4 dereferenceable(4) ptr @_ZSt3minIiERKT_S2_S2_(ptr noundef nonnull align 4 dereferenceable(4), ptr noundef nonnull align 4 dereferenceable(4)) #1

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #2

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #2

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef nonnull align 8 dereferenceable(8) ptr @_ZSt3maxIxERKT_S2_S2_(ptr noundef nonnull align 8 dereferenceable(8), ptr noundef nonnull align 8 dereferenceable(8)) #1

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" }
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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #3 = { 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 = !{!10, !10, i64 0}
!10 = !{!"long long", !7, i64 0}
!11 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}


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

@t = external dso_local local_unnamed_addr global [1010 x i32], align 16
@val = external dso_local global [1010 x i32], align 16
@dp = external dso_local global [1010 x [1010 x i64]], align 16

; Function Attrs: mustprogress nounwind uwtable
define dso_local void @_Z3dfsii(i32 noundef %0, i32 noundef %1) local_unnamed_addr #0 {
  %3 = alloca i32, align 4
  %4 = alloca i64, align 8
  %5 = sext i32 %0 to i64
  %6 = sext i32 %1 to i64
  %7 = getelementptr inbounds [1010 x [1010 x i64]], ptr @dp, i64 0, i64 %5, i64 %6
  %8 = load i64, ptr %7, align 8, !tbaa !5
  %9 = icmp eq i64 %8, 0
  %10 = icmp ne i32 %1, 0
  %or.cond = and i1 %10, %9
  br i1 %or.cond, label %11, label %.loopexit

11:                                               ; preds = %2
  %12 = getelementptr inbounds [1010 x i32], ptr @val, i64 0, i64 %5
  %13 = load i32, ptr %12, align 4, !tbaa !9
  %.not = icmp eq i32 %13, 0
  br i1 %.not, label %.preheader, label %20

.preheader:                                       ; preds = %11
  %14 = getelementptr inbounds [1010 x i32], ptr @t, i64 0, i64 %5
  %15 = load i32, ptr %14, align 4, !tbaa !9
  %.not3135 = icmp sgt i32 %15, %1
  br i1 %.not3135, label %.loopexit, label %.lr.ph

.lr.ph:                                           ; preds = %.preheader
  %16 = shl i32 %0, 1
  %17 = or disjoint i32 %16, 1
  %18 = sext i32 %16 to i64
  %19 = sext i32 %17 to i64
  br label %28

20:                                               ; preds = %11
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %3) #3
  %21 = getelementptr inbounds [1010 x i32], ptr @t, i64 0, i64 %5
  %22 = load i32, ptr %21, align 4, !tbaa !9
  %23 = sub nsw i32 %1, %22
  %24 = sdiv i32 %23, 5
  store i32 %24, ptr %3, align 4, !tbaa !9
  %25 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZSt3minIiERKT_S2_S2_(ptr noundef nonnull align 4 dereferenceable(4) %12, ptr noundef nonnull align 4 dereferenceable(4) %3)
  %26 = load i32, ptr %25, align 4, !tbaa !9
  %27 = sext i32 %26 to i64
  store i64 %27, ptr %7, align 8, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %3) #3
  br label %.loopexit

28:                                               ; preds = %.lr.ph, %28
  %indvars.iv = phi i64 [ 0, %.lr.ph ], [ %indvars.iv.next, %28 ]
  %.0.neg37 = phi i32 [ 0, %.lr.ph ], [ %.0.neg, %28 ]
  %29 = trunc nuw nsw i64 %indvars.iv to i32
  call void @_Z3dfsii(i32 noundef %16, i32 noundef %29)
  %30 = load i32, ptr %14, align 4, !tbaa !9
  %.neg32 = add i32 %.0.neg37, %1
  %31 = sub i32 %.neg32, %30
  call void @_Z3dfsii(i32 noundef %17, i32 noundef %31)
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %4) #3
  %32 = getelementptr inbounds [1010 x [1010 x i64]], ptr @dp, i64 0, i64 %18, i64 %indvars.iv
  %33 = load i64, ptr %32, align 8, !tbaa !5
  %34 = load i32, ptr %14, align 4, !tbaa !9
  %35 = sub i32 %.neg32, %34
  %36 = sext i32 %35 to i64
  %37 = getelementptr inbounds [1010 x [1010 x i64]], ptr @dp, i64 0, i64 %19, i64 %36
  %38 = load i64, ptr %37, align 8, !tbaa !5
  %39 = add nsw i64 %38, %33
  store i64 %39, ptr %4, align 8, !tbaa !5
  %40 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZSt3maxIxERKT_S2_S2_(ptr noundef nonnull align 8 dereferenceable(8) %7, ptr noundef nonnull align 8 dereferenceable(8) %4)
  %41 = load i64, ptr %40, align 8, !tbaa !5
  store i64 %41, ptr %7, align 8, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %4) #3
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %.0.neg = xor i32 %29, -1
  %42 = load i32, ptr %14, align 4, !tbaa !9
  %43 = sub nsw i32 %1, %42
  %44 = sext i32 %43 to i64
  %.not31.not = icmp slt i64 %indvars.iv, %44
  br i1 %.not31.not, label %28, label %.loopexit, !llvm.loop !11

.loopexit:                                        ; preds = %28, %.preheader, %2, %20
  ret void
}

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef nonnull align 4 dereferenceable(4) ptr @_ZSt3minIiERKT_S2_S2_(ptr noundef nonnull align 4 dereferenceable(4), ptr noundef nonnull align 4 dereferenceable(4)) local_unnamed_addr #1

; Function Attrs: mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #2

; Function Attrs: mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #2

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef nonnull align 8 dereferenceable(8) ptr @_ZSt3maxIxERKT_S2_S2_(ptr noundef nonnull align 8 dereferenceable(8), ptr noundef nonnull align 8 dereferenceable(8)) 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 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #3 = { 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 = !{!"long long", !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"}


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