; LLVM IR from Tunghohin/Competitive_Coding :: Daimayuan/556.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.edge = type { i32, i32 }

@e = external dso_local global [1000010 x %struct.edge], align 16
@head = external dso_local global [500010 x i32], align 16
@res = external dso_local global i32, align 4
@dp = external dso_local global [500010 x [2 x i32]], align 16
@val = external dso_local global [500010 x i32], 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 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
  %11 = load i32, ptr %3, align 4, !tbaa !5
  %12 = sext i32 %11 to i64
  %13 = getelementptr inbounds [500010 x [2 x i32]], ptr @dp, i64 0, i64 %12
  %14 = getelementptr inbounds [2 x i32], ptr %13, i64 0, i64 1
  store i32 1, ptr %14, align 4, !tbaa !5
  %15 = load i32, ptr %3, align 4, !tbaa !5
  %16 = sext i32 %15 to i64
  %17 = getelementptr inbounds [500010 x [2 x i32]], ptr @dp, i64 0, i64 %16
  %18 = getelementptr inbounds [2 x i32], ptr %17, i64 0, i64 0
  store i32 1, ptr %18, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #3
  %19 = load i32, ptr %3, align 4, !tbaa !5
  %20 = sext i32 %19 to i64
  %21 = getelementptr inbounds [500010 x i32], ptr @head, i64 0, i64 %20
  %22 = load i32, ptr %21, align 4, !tbaa !5
  store i32 %22, ptr %5, align 4, !tbaa !5
  br label %23

23:                                               ; preds = %102, %2
  %24 = load i32, ptr %5, align 4, !tbaa !5
  %25 = icmp ne i32 %24, 0
  br i1 %25, label %27, label %26

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

27:                                               ; preds = %23
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #3
  %28 = load i32, ptr %5, align 4, !tbaa !5
  %29 = sext i32 %28 to i64
  %30 = getelementptr inbounds [1000010 x %struct.edge], ptr @e, i64 0, i64 %29
  %31 = getelementptr inbounds %struct.edge, ptr %30, i32 0, i32 0
  %32 = load i32, ptr %31, align 8, !tbaa !9
  store i32 %32, ptr %7, align 4, !tbaa !5
  %33 = load i32, ptr %7, align 4, !tbaa !5
  %34 = load i32, ptr %4, align 4, !tbaa !5
  %35 = icmp eq i32 %33, %34
  br i1 %35, label %36, label %37

36:                                               ; preds = %27
  store i32 4, ptr %6, align 4
  br label %99

37:                                               ; preds = %27
  %38 = load i32, ptr %7, align 4, !tbaa !5
  %39 = load i32, ptr %3, align 4, !tbaa !5
  call void @_Z3dfsii(i32 noundef %38, i32 noundef %39)
  %40 = load i32, ptr %3, align 4, !tbaa !5
  %41 = sext i32 %40 to i64
  %42 = getelementptr inbounds [500010 x i32], ptr @val, i64 0, i64 %41
  %43 = load i32, ptr %42, align 4, !tbaa !5
  %44 = load i32, ptr %7, align 4, !tbaa !5
  %45 = sext i32 %44 to i64
  %46 = getelementptr inbounds [500010 x i32], ptr @val, i64 0, i64 %45
  %47 = load i32, ptr %46, align 4, !tbaa !5
  %48 = add nsw i32 %47, 1
  %49 = srem i32 %48, 3
  %50 = icmp eq i32 %43, %49
  br i1 %50, label %51, label %68

51:                                               ; preds = %37
  %52 = load i32, ptr %3, align 4, !tbaa !5
  %53 = sext i32 %52 to i64
  %54 = getelementptr inbounds [500010 x [2 x i32]], ptr @dp, i64 0, i64 %53
  %55 = getelementptr inbounds [2 x i32], ptr %54, i64 0, i64 0
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #3
  %56 = load i32, ptr %7, align 4, !tbaa !5
  %57 = sext i32 %56 to i64
  %58 = getelementptr inbounds [500010 x [2 x i32]], ptr @dp, i64 0, i64 %57
  %59 = getelementptr inbounds [2 x i32], ptr %58, i64 0, i64 0
  %60 = load i32, ptr %59, align 8, !tbaa !5
  %61 = add nsw i32 %60, 1
  store i32 %61, ptr %8, align 4, !tbaa !5
  %62 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZSt3maxIiERKT_S2_S2_(ptr noundef nonnull align 4 dereferenceable(4) %55, ptr noundef nonnull align 4 dereferenceable(4) %8)
  %63 = load i32, ptr %62, align 4, !tbaa !5
  %64 = load i32, ptr %3, align 4, !tbaa !5
  %65 = sext i32 %64 to i64
  %66 = getelementptr inbounds [500010 x [2 x i32]], ptr @dp, i64 0, i64 %65
  %67 = getelementptr inbounds [2 x i32], ptr %66, i64 0, i64 0
  store i32 %63, ptr %67, align 8, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #3
  br label %98

68:                                               ; preds = %37
  %69 = load i32, ptr %7, align 4, !tbaa !5
  %70 = sext i32 %69 to i64
  %71 = getelementptr inbounds [500010 x i32], ptr @val, i64 0, i64 %70
  %72 = load i32, ptr %71, align 4, !tbaa !5
  %73 = load i32, ptr %3, align 4, !tbaa !5
  %74 = sext i32 %73 to i64
  %75 = getelementptr inbounds [500010 x i32], ptr @val, i64 0, i64 %74
  %76 = load i32, ptr %75, align 4, !tbaa !5
  %77 = add nsw i32 %76, 1
  %78 = srem i32 %77, 3
  %79 = icmp eq i32 %72, %78
  br i1 %79, label %80, label %97

80:                                               ; preds = %68
  %81 = load i32, ptr %3, align 4, !tbaa !5
  %82 = sext i32 %81 to i64
  %83 = getelementptr inbounds [500010 x [2 x i32]], ptr @dp, i64 0, i64 %82
  %84 = getelementptr inbounds [2 x i32], ptr %83, i64 0, i64 1
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #3
  %85 = load i32, ptr %7, align 4, !tbaa !5
  %86 = sext i32 %85 to i64
  %87 = getelementptr inbounds [500010 x [2 x i32]], ptr @dp, i64 0, i64 %86
  %88 = getelementptr inbounds [2 x i32], ptr %87, i64 0, i64 1
  %89 = load i32, ptr %88, align 4, !tbaa !5
  %90 = add nsw i32 %89, 1
  store i32 %90, ptr %9, align 4, !tbaa !5
  %91 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZSt3maxIiERKT_S2_S2_(ptr noundef nonnull align 4 dereferenceable(4) %84, ptr noundef nonnull align 4 dereferenceable(4) %9)
  %92 = load i32, ptr %91, align 4, !tbaa !5
  %93 = load i32, ptr %3, align 4, !tbaa !5
  %94 = sext i32 %93 to i64
  %95 = getelementptr inbounds [500010 x [2 x i32]], ptr @dp, i64 0, i64 %94
  %96 = getelementptr inbounds [2 x i32], ptr %95, i64 0, i64 1
  store i32 %92, ptr %96, align 4, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #3
  br label %97

97:                                               ; preds = %80, %68
  br label %98

98:                                               ; preds = %97, %51
  store i32 0, ptr %6, align 4
  br label %99

99:                                               ; preds = %98, %36
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #3
  %100 = load i32, ptr %6, align 4
  switch i32 %100, label %123 [
    i32 0, label %101
    i32 4, label %102
  ]

101:                                              ; preds = %99
  br label %102

102:                                              ; preds = %101, %99
  %103 = load i32, ptr %5, align 4, !tbaa !5
  %104 = sext i32 %103 to i64
  %105 = getelementptr inbounds [1000010 x %struct.edge], ptr @e, i64 0, i64 %104
  %106 = getelementptr inbounds %struct.edge, ptr %105, i32 0, i32 1
  %107 = load i32, ptr %106, align 4, !tbaa !11
  store i32 %107, ptr %5, align 4, !tbaa !5
  br label %23, !llvm.loop !12

108:                                              ; preds = %26
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #3
  %109 = load i32, ptr %3, align 4, !tbaa !5
  %110 = sext i32 %109 to i64
  %111 = getelementptr inbounds [500010 x [2 x i32]], ptr @dp, i64 0, i64 %110
  %112 = getelementptr inbounds [2 x i32], ptr %111, i64 0, i64 0
  %113 = load i32, ptr %112, align 8, !tbaa !5
  %114 = load i32, ptr %3, align 4, !tbaa !5
  %115 = sext i32 %114 to i64
  %116 = getelementptr inbounds [500010 x [2 x i32]], ptr @dp, i64 0, i64 %115
  %117 = getelementptr inbounds [2 x i32], ptr %116, i64 0, i64 1
  %118 = load i32, ptr %117, align 4, !tbaa !5
  %119 = add nsw i32 %113, %118
  %120 = sub nsw i32 %119, 1
  store i32 %120, ptr %10, align 4, !tbaa !5
  %121 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZSt3maxIiERKT_S2_S2_(ptr noundef nonnull align 4 dereferenceable(4) @res, ptr noundef nonnull align 4 dereferenceable(4) %10)
  %122 = load i32, ptr %121, align 4, !tbaa !5
  store i32 %122, ptr @res, align 4, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #3
  ret void

123:                                              ; preds = %99
  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 @_ZSt3maxIiERKT_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 = !{!"_ZTS4edge", !6, i64 0, !6, i64 4}
!11 = !{!10, !6, i64 4}
!12 = distinct !{!12, !13}
!13 = !{!"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"

%struct.edge = type { i32, i32 }

@e = external dso_local local_unnamed_addr global [1000010 x %struct.edge], align 16
@head = external dso_local local_unnamed_addr global [500010 x i32], align 16
@res = external dso_local global i32, align 4
@dp = external dso_local global [500010 x [2 x i32]], align 16
@val = external dso_local local_unnamed_addr global [500010 x i32], 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 i32, align 4
  %5 = alloca i32, align 4
  %6 = sext i32 %0 to i64
  %7 = getelementptr inbounds [500010 x [2 x i32]], ptr @dp, i64 0, i64 %6
  %8 = getelementptr inbounds i8, ptr %7, i64 4
  store i32 1, ptr %8, align 4, !tbaa !5
  store i32 1, ptr %7, align 8, !tbaa !5
  %9 = getelementptr inbounds [500010 x i32], ptr @head, i64 0, i64 %6
  %.024 = load i32, ptr %9, align 4, !tbaa !5
  %.not25 = icmp eq i32 %.024, 0
  br i1 %.not25, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %2
  %10 = getelementptr inbounds [500010 x i32], ptr @val, i64 0, i64 %6
  br label %16

._crit_edge.loopexit:                             ; preds = %45
  %.pre = load i32, ptr %7, align 8, !tbaa !5
  %.pre27 = load i32, ptr %8, align 4, !tbaa !5
  %11 = add i32 %.pre, -1
  %12 = add i32 %11, %.pre27
  br label %._crit_edge

._crit_edge:                                      ; preds = %._crit_edge.loopexit, %2
  %13 = phi i32 [ %12, %._crit_edge.loopexit ], [ 1, %2 ]
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %5) #3
  store i32 %13, ptr %5, align 4, !tbaa !5
  %14 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZSt3maxIiERKT_S2_S2_(ptr noundef nonnull align 4 dereferenceable(4) @res, ptr noundef nonnull align 4 dereferenceable(4) %5)
  %15 = load i32, ptr %14, align 4, !tbaa !5
  store i32 %15, ptr @res, align 4, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %5) #3
  ret void

16:                                               ; preds = %.lr.ph, %45
  %.026 = phi i32 [ %.024, %.lr.ph ], [ %.0, %45 ]
  %17 = sext i32 %.026 to i64
  %18 = getelementptr inbounds [1000010 x %struct.edge], ptr @e, i64 0, i64 %17
  %19 = load i32, ptr %18, align 8, !tbaa !9
  %20 = icmp eq i32 %19, %1
  br i1 %20, label %45, label %21

21:                                               ; preds = %16
  call void @_Z3dfsii(i32 noundef %19, i32 noundef %0)
  %22 = load i32, ptr %10, align 4, !tbaa !5
  %23 = sext i32 %19 to i64
  %24 = getelementptr inbounds [500010 x i32], ptr @val, i64 0, i64 %23
  %25 = load i32, ptr %24, align 4, !tbaa !5
  %26 = add nsw i32 %25, 1
  %27 = srem i32 %26, 3
  %28 = icmp eq i32 %22, %27
  br i1 %28, label %29, label %35

29:                                               ; preds = %21
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %3) #3
  %30 = getelementptr inbounds [500010 x [2 x i32]], ptr @dp, i64 0, i64 %23
  %31 = load i32, ptr %30, align 8, !tbaa !5
  %32 = add nsw i32 %31, 1
  store i32 %32, ptr %3, align 4, !tbaa !5
  %33 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZSt3maxIiERKT_S2_S2_(ptr noundef nonnull align 4 dereferenceable(4) %7, ptr noundef nonnull align 4 dereferenceable(4) %3)
  %34 = load i32, ptr %33, align 4, !tbaa !5
  store i32 %34, ptr %7, align 8, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %3) #3
  br label %45

35:                                               ; preds = %21
  %36 = add nsw i32 %22, 1
  %37 = srem i32 %36, 3
  %38 = icmp eq i32 %25, %37
  br i1 %38, label %39, label %45

39:                                               ; preds = %35
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %4) #3
  %40 = getelementptr inbounds [500010 x [2 x i32]], ptr @dp, i64 0, i64 %23, i64 1
  %41 = load i32, ptr %40, align 4, !tbaa !5
  %42 = add nsw i32 %41, 1
  store i32 %42, ptr %4, align 4, !tbaa !5
  %43 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZSt3maxIiERKT_S2_S2_(ptr noundef nonnull align 4 dereferenceable(4) %8, ptr noundef nonnull align 4 dereferenceable(4) %4)
  %44 = load i32, ptr %43, align 4, !tbaa !5
  store i32 %44, ptr %8, align 4, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %4) #3
  br label %45

45:                                               ; preds = %29, %39, %35, %16
  %46 = getelementptr inbounds i8, ptr %18, i64 4
  %.0 = load i32, ptr %46, align 4, !tbaa !5
  %.not = icmp eq i32 %.0, 0
  br i1 %.not, label %._crit_edge.loopexit, label %16, !llvm.loop !11
}

; 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 @_ZSt3maxIiERKT_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 = !{!"_ZTS4edge", !6, i64 0, !6, i64 4}
!11 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}


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