; LLVM IR from lzyrapx/Competitive-Programming :: HDUOJ/4003 (2).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"

%struct.Node = type { i32, i32, i32 }

@tree = external dso_local global [20005 x %struct.Node], align 16
@dp = external dso_local global [10005 x [15 x i32]], align 16
@head = external dso_local global [10005 x i32], align 16
@k = external dso_local global i32, align 4

; 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 i32, align 4
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  %10 = alloca i32, align 4
  store i32 %0, ptr %3, align 4, !tbaa !5
  store i32 %1, ptr %4, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #3
  %11 = load i32, ptr %3, align 4, !tbaa !5
  %12 = sext i32 %11 to i64
  %13 = getelementptr inbounds [10005 x i32], ptr @head, i64 0, i64 %12
  %14 = load i32, ptr %13, align 4, !tbaa !5
  store i32 %14, ptr %5, align 4, !tbaa !5
  br label %15

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

18:                                               ; preds = %15
  store i32 2, ptr %6, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #3
  br label %120

19:                                               ; preds = %15
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #3
  %20 = load i32, ptr %5, align 4, !tbaa !5
  %21 = sext i32 %20 to i64
  %22 = getelementptr inbounds [20005 x %struct.Node], ptr @tree, i64 0, i64 %21
  %23 = getelementptr inbounds %struct.Node, ptr %22, i32 0, i32 0
  %24 = load i32, ptr %23, align 4, !tbaa !9
  store i32 %24, ptr %7, align 4, !tbaa !5
  %25 = load i32, ptr %7, align 4, !tbaa !5
  %26 = load i32, ptr %4, align 4, !tbaa !5
  %27 = icmp eq i32 %25, %26
  br i1 %27, label %28, label %29

28:                                               ; preds = %19
  store i32 4, ptr %6, align 4
  br label %111

29:                                               ; preds = %19
  %30 = load i32, ptr %7, align 4, !tbaa !5
  %31 = load i32, ptr %3, align 4, !tbaa !5
  call void @_Z3dfsii(i32 noundef %30, i32 noundef %31)
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #3
  %32 = load i32, ptr @k, align 4, !tbaa !5
  store i32 %32, ptr %8, align 4, !tbaa !5
  br label %33

33:                                               ; preds = %107, %29
  %34 = load i32, ptr %8, align 4, !tbaa !5
  %35 = icmp sge i32 %34, 0
  br i1 %35, label %37, label %36

36:                                               ; preds = %33
  store i32 5, ptr %6, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #3
  br label %110

37:                                               ; preds = %33
  %38 = load i32, ptr %7, align 4, !tbaa !5
  %39 = sext i32 %38 to i64
  %40 = getelementptr inbounds [10005 x [15 x i32]], ptr @dp, i64 0, i64 %39
  %41 = getelementptr inbounds [15 x i32], ptr %40, i64 0, i64 0
  %42 = load i32, ptr %41, align 4, !tbaa !5
  %43 = load i32, ptr %5, align 4, !tbaa !5
  %44 = sext i32 %43 to i64
  %45 = getelementptr inbounds [20005 x %struct.Node], ptr @tree, i64 0, i64 %44
  %46 = getelementptr inbounds %struct.Node, ptr %45, i32 0, i32 2
  %47 = load i32, ptr %46, align 4, !tbaa !11
  %48 = mul nsw i32 2, %47
  %49 = add nsw i32 %42, %48
  %50 = load i32, ptr %3, align 4, !tbaa !5
  %51 = sext i32 %50 to i64
  %52 = getelementptr inbounds [10005 x [15 x i32]], ptr @dp, i64 0, i64 %51
  %53 = load i32, ptr %8, align 4, !tbaa !5
  %54 = sext i32 %53 to i64
  %55 = getelementptr inbounds [15 x i32], ptr %52, i64 0, i64 %54
  %56 = load i32, ptr %55, align 4, !tbaa !5
  %57 = add nsw i32 %56, %49
  store i32 %57, ptr %55, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #3
  store i32 1, ptr %9, align 4, !tbaa !5
  br label %58

58:                                               ; preds = %103, %37
  %59 = load i32, ptr %9, align 4, !tbaa !5
  %60 = load i32, ptr %8, align 4, !tbaa !5
  %61 = icmp sle i32 %59, %60
  br i1 %61, label %63, label %62

62:                                               ; preds = %58
  store i32 8, ptr %6, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #3
  br label %106

63:                                               ; preds = %58
  %64 = load i32, ptr %3, align 4, !tbaa !5
  %65 = sext i32 %64 to i64
  %66 = getelementptr inbounds [10005 x [15 x i32]], ptr @dp, i64 0, i64 %65
  %67 = load i32, ptr %8, align 4, !tbaa !5
  %68 = sext i32 %67 to i64
  %69 = getelementptr inbounds [15 x i32], ptr %66, i64 0, i64 %68
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #3
  %70 = load i32, ptr %3, align 4, !tbaa !5
  %71 = sext i32 %70 to i64
  %72 = getelementptr inbounds [10005 x [15 x i32]], ptr @dp, i64 0, i64 %71
  %73 = load i32, ptr %8, align 4, !tbaa !5
  %74 = load i32, ptr %9, align 4, !tbaa !5
  %75 = sub nsw i32 %73, %74
  %76 = sext i32 %75 to i64
  %77 = getelementptr inbounds [15 x i32], ptr %72, i64 0, i64 %76
  %78 = load i32, ptr %77, align 4, !tbaa !5
  %79 = load i32, ptr %7, align 4, !tbaa !5
  %80 = sext i32 %79 to i64
  %81 = getelementptr inbounds [10005 x [15 x i32]], ptr @dp, i64 0, i64 %80
  %82 = load i32, ptr %9, align 4, !tbaa !5
  %83 = sext i32 %82 to i64
  %84 = getelementptr inbounds [15 x i32], ptr %81, i64 0, i64 %83
  %85 = load i32, ptr %84, align 4, !tbaa !5
  %86 = add nsw i32 %78, %85
  %87 = load i32, ptr %9, align 4, !tbaa !5
  %88 = load i32, ptr %5, align 4, !tbaa !5
  %89 = sext i32 %88 to i64
  %90 = getelementptr inbounds [20005 x %struct.Node], ptr @tree, i64 0, i64 %89
  %91 = getelementptr inbounds %struct.Node, ptr %90, i32 0, i32 2
  %92 = load i32, ptr %91, align 4, !tbaa !11
  %93 = mul nsw i32 %87, %92
  %94 = add nsw i32 %86, %93
  store i32 %94, ptr %10, align 4, !tbaa !5
  %95 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZSt3minIiERKT_S2_S2_(ptr noundef nonnull align 4 dereferenceable(4) %69, ptr noundef nonnull align 4 dereferenceable(4) %10)
  %96 = load i32, ptr %95, align 4, !tbaa !5
  %97 = load i32, ptr %3, align 4, !tbaa !5
  %98 = sext i32 %97 to i64
  %99 = getelementptr inbounds [10005 x [15 x i32]], ptr @dp, i64 0, i64 %98
  %100 = load i32, ptr %8, align 4, !tbaa !5
  %101 = sext i32 %100 to i64
  %102 = getelementptr inbounds [15 x i32], ptr %99, i64 0, i64 %101
  store i32 %96, ptr %102, align 4, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #3
  br label %103

103:                                              ; preds = %63
  %104 = load i32, ptr %9, align 4, !tbaa !5
  %105 = add nsw i32 %104, 1
  store i32 %105, ptr %9, align 4, !tbaa !5
  br label %58, !llvm.loop !12

106:                                              ; preds = %62
  br label %107

107:                                              ; preds = %106
  %108 = load i32, ptr %8, align 4, !tbaa !5
  %109 = add nsw i32 %108, -1
  store i32 %109, ptr %8, align 4, !tbaa !5
  br label %33, !llvm.loop !14

110:                                              ; preds = %36
  store i32 0, ptr %6, align 4
  br label %111

111:                                              ; preds = %110, %28
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #3
  %112 = load i32, ptr %6, align 4
  switch i32 %112, label %121 [
    i32 0, label %113
    i32 4, label %114
  ]

113:                                              ; preds = %111
  br label %114

114:                                              ; preds = %113, %111
  %115 = load i32, ptr %5, align 4, !tbaa !5
  %116 = sext i32 %115 to i64
  %117 = getelementptr inbounds [20005 x %struct.Node], ptr @tree, i64 0, i64 %116
  %118 = getelementptr inbounds %struct.Node, ptr %117, i32 0, i32 1
  %119 = load i32, ptr %118, align 4, !tbaa !15
  store i32 %119, ptr %5, align 4, !tbaa !5
  br label %15, !llvm.loop !16

120:                                              ; preds = %18
  ret void

121:                                              ; preds = %111
  unreachable
}

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

; 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)) #2

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { 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 #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, !6, i64 0}
!10 = !{!"_ZTS4Node", !6, i64 0, !6, i64 4, !6, i64 8}
!11 = !{!10, !6, i64 8}
!12 = distinct !{!12, !13}
!13 = !{!"llvm.loop.mustprogress"}
!14 = distinct !{!14, !13}
!15 = !{!10, !6, i64 4}
!16 = distinct !{!16, !13}


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

%struct.Node = type { i32, i32, i32 }

@tree = external dso_local local_unnamed_addr global [20005 x %struct.Node], align 16
@dp = external dso_local global [10005 x [15 x i32]], align 16
@head = external dso_local local_unnamed_addr global [10005 x i32], align 16
@k = external dso_local local_unnamed_addr global i32, align 4

; 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 = sext i32 %0 to i64
  %5 = getelementptr inbounds [10005 x i32], ptr @head, i64 0, i64 %4
  %.02937 = load i32, ptr %5, align 4, !tbaa !5
  %.not38 = icmp eq i32 %.02937, -1
  br i1 %.not38, label %._crit_edge42, label %.lr.ph41

._crit_edge42:                                    ; preds = %.loopexit, %2
  ret void

.lr.ph41:                                         ; preds = %2, %.loopexit
  %.02939 = phi i32 [ %.029, %.loopexit ], [ %.02937, %2 ]
  %6 = sext i32 %.02939 to i64
  %7 = getelementptr inbounds [20005 x %struct.Node], ptr @tree, i64 0, i64 %6
  %8 = load i32, ptr %7, align 4, !tbaa !9
  %9 = icmp eq i32 %8, %1
  br i1 %9, label %.loopexit, label %10

10:                                               ; preds = %.lr.ph41
  call void @_Z3dfsii(i32 noundef %8, i32 noundef %0)
  %11 = load i32, ptr @k, align 4, !tbaa !5
  %12 = icmp sgt i32 %11, -1
  br i1 %12, label %.lr.ph36, label %.loopexit

.lr.ph36:                                         ; preds = %10
  %13 = sext i32 %8 to i64
  %14 = getelementptr inbounds [10005 x [15 x i32]], ptr @dp, i64 0, i64 %13
  %15 = getelementptr inbounds i8, ptr %7, i64 8
  %16 = add nuw i32 %11, 1
  %17 = zext i32 %16 to i64
  %18 = zext nneg i32 %11 to i64
  br label %19

19:                                               ; preds = %.lr.ph36, %._crit_edge
  %indvars.iv48 = phi i64 [ %18, %.lr.ph36 ], [ %indvars.iv.next49, %._crit_edge ]
  %indvars.iv46 = phi i64 [ %17, %.lr.ph36 ], [ %indvars.iv.next47, %._crit_edge ]
  %20 = load i32, ptr %14, align 4, !tbaa !5
  %21 = load i32, ptr %15, align 4, !tbaa !11
  %22 = shl nsw i32 %21, 1
  %23 = add nsw i32 %22, %20
  %24 = getelementptr inbounds [10005 x [15 x i32]], ptr @dp, i64 0, i64 %4, i64 %indvars.iv48
  %25 = load i32, ptr %24, align 4, !tbaa !5
  %26 = add nsw i32 %23, %25
  store i32 %26, ptr %24, align 4, !tbaa !5
  %.not3132 = icmp eq i64 %indvars.iv48, 0
  br i1 %.not3132, label %.loopexit, label %.lr.ph

._crit_edge:                                      ; preds = %.lr.ph
  %indvars.iv.next49 = add nsw i64 %indvars.iv48, -1
  %27 = icmp sgt i64 %indvars.iv48, 0
  %indvars.iv.next47 = add nsw i64 %indvars.iv46, -1
  br i1 %27, label %19, label %.loopexit, !llvm.loop !12

.lr.ph:                                           ; preds = %19, %.lr.ph
  %indvars.iv = phi i64 [ %indvars.iv.next, %.lr.ph ], [ 1, %19 ]
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %3) #3
  %28 = sub nsw i64 %indvars.iv48, %indvars.iv
  %29 = getelementptr inbounds [10005 x [15 x i32]], ptr @dp, i64 0, i64 %4, i64 %28
  %30 = load i32, ptr %29, align 4, !tbaa !5
  %31 = getelementptr inbounds [10005 x [15 x i32]], ptr @dp, i64 0, i64 %13, i64 %indvars.iv
  %32 = load i32, ptr %31, align 4, !tbaa !5
  %33 = add nsw i32 %32, %30
  %34 = load i32, ptr %15, align 4, !tbaa !11
  %35 = trunc nuw nsw i64 %indvars.iv to i32
  %36 = mul nsw i32 %34, %35
  %37 = add nsw i32 %33, %36
  store i32 %37, ptr %3, align 4, !tbaa !5
  %38 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZSt3minIiERKT_S2_S2_(ptr noundef nonnull align 4 dereferenceable(4) %24, ptr noundef nonnull align 4 dereferenceable(4) %3)
  %39 = load i32, ptr %38, align 4, !tbaa !5
  store i32 %39, ptr %24, align 4, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %3) #3
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %exitcond.not = icmp eq i64 %indvars.iv.next, %indvars.iv46
  br i1 %exitcond.not, label %._crit_edge, label %.lr.ph, !llvm.loop !14

.loopexit:                                        ; preds = %19, %._crit_edge, %10, %.lr.ph41
  %40 = getelementptr inbounds i8, ptr %7, i64 4
  %.029 = load i32, ptr %40, align 4, !tbaa !5
  %.not = icmp eq i32 %.029, -1
  br i1 %.not, label %._crit_edge42, label %.lr.ph41, !llvm.loop !15
}

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

; 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 #2

; Function Attrs: mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #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 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { 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 #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, !6, i64 0}
!10 = !{!"_ZTS4Node", !6, i64 0, !6, i64 4, !6, i64 8}
!11 = !{!10, !6, i64 8}
!12 = distinct !{!12, !13}
!13 = !{!"llvm.loop.mustprogress"}
!14 = distinct !{!14, !13}
!15 = distinct !{!15, !13}


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