; LLVM IR from tangjz/acm-icpc :: lydsy/3068.ll (Z4dfs1ii)

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

@a = external dso_local global [500001 x i32], align 16
@lnk = external dso_local global [500001 x i32], align 16
@f = external dso_local global [500001 x i32], align 16
@g = external dso_local global [500001 x i32], align 16
@sz = external dso_local global [500001 x i64], align 16
@sum = external dso_local global [500001 x i64], align 16
@e = external dso_local global [1000003 x %struct.Edge], align 16

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_Z5reseti(i32 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 @_Z4dfs1ii(i32 noundef %0, i32 noundef %1) #2 {
  %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
  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 [500001 x i32], ptr @g, i64 0, i64 %9
  store i32 0, ptr %10, align 4, !tbaa !5
  %11 = load i32, ptr %3, align 4, !tbaa !5
  %12 = sext i32 %11 to i64
  %13 = getelementptr inbounds [500001 x i32], ptr @f, i64 0, i64 %12
  store i32 0, ptr %13, align 4, !tbaa !5
  %14 = load i32, ptr %3, align 4, !tbaa !5
  %15 = sext i32 %14 to i64
  %16 = getelementptr inbounds [500001 x i32], ptr @a, i64 0, i64 %15
  %17 = load i32, ptr %16, align 4, !tbaa !5
  %18 = sext i32 %17 to i64
  %19 = load i32, ptr %3, align 4, !tbaa !5
  %20 = sext i32 %19 to i64
  %21 = getelementptr inbounds [500001 x i64], ptr @sz, i64 0, i64 %20
  store i64 %18, ptr %21, align 8, !tbaa !9
  %22 = load i32, ptr %3, align 4, !tbaa !5
  %23 = sext i32 %22 to i64
  %24 = getelementptr inbounds [500001 x i64], ptr @sum, i64 0, i64 %23
  store i64 0, ptr %24, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #3
  %25 = load i32, ptr %3, align 4, !tbaa !5
  %26 = sext i32 %25 to i64
  %27 = getelementptr inbounds [500001 x i32], ptr @lnk, i64 0, i64 %26
  %28 = load i32, ptr %27, align 4, !tbaa !5
  store i32 %28, ptr %5, align 4, !tbaa !5
  br label %29

29:                                               ; preds = %116, %2
  %30 = load i32, ptr %5, align 4, !tbaa !5
  %31 = icmp ne i32 %30, 0
  br i1 %31, label %33, label %32

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

33:                                               ; preds = %29
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #3
  %34 = load i32, ptr %5, align 4, !tbaa !5
  %35 = sext i32 %34 to i64
  %36 = getelementptr inbounds [1000003 x %struct.Edge], ptr @e, i64 0, i64 %35
  %37 = getelementptr inbounds %struct.Edge, ptr %36, i32 0, i32 1
  %38 = load i32, ptr %37, align 4, !tbaa !11
  store i32 %38, ptr %7, align 4, !tbaa !5
  %39 = load i32, ptr %7, align 4, !tbaa !5
  %40 = load i32, ptr %4, align 4, !tbaa !5
  %41 = icmp eq i32 %39, %40
  br i1 %41, label %42, label %43

42:                                               ; preds = %33
  store i32 4, ptr %6, align 4
  br label %113

43:                                               ; preds = %33
  %44 = load i32, ptr %7, align 4, !tbaa !5
  %45 = load i32, ptr %3, align 4, !tbaa !5
  call void @_Z4dfs1ii(i32 noundef %44, i32 noundef %45)
  %46 = load i32, ptr %7, align 4, !tbaa !5
  %47 = sext i32 %46 to i64
  %48 = getelementptr inbounds [500001 x i64], ptr @sz, i64 0, i64 %47
  %49 = load i64, ptr %48, align 8, !tbaa !9
  %50 = load i32, ptr %3, align 4, !tbaa !5
  %51 = sext i32 %50 to i64
  %52 = getelementptr inbounds [500001 x i64], ptr @sz, i64 0, i64 %51
  %53 = load i64, ptr %52, align 8, !tbaa !9
  %54 = add nsw i64 %53, %49
  store i64 %54, ptr %52, align 8, !tbaa !9
  %55 = load i32, ptr %7, align 4, !tbaa !5
  %56 = sext i32 %55 to i64
  %57 = getelementptr inbounds [500001 x i64], ptr @sum, i64 0, i64 %56
  %58 = load i64, ptr %57, align 8, !tbaa !9
  %59 = load i32, ptr %7, align 4, !tbaa !5
  %60 = sext i32 %59 to i64
  %61 = getelementptr inbounds [500001 x i64], ptr @sz, i64 0, i64 %60
  %62 = load i64, ptr %61, align 8, !tbaa !9
  %63 = add nsw i64 %58, %62
  %64 = load i32, ptr %3, align 4, !tbaa !5
  %65 = sext i32 %64 to i64
  %66 = getelementptr inbounds [500001 x i64], ptr @sum, i64 0, i64 %65
  %67 = load i64, ptr %66, align 8, !tbaa !9
  %68 = add nsw i64 %67, %63
  store i64 %68, ptr %66, align 8, !tbaa !9
  %69 = load i32, ptr %3, align 4, !tbaa !5
  %70 = sext i32 %69 to i64
  %71 = getelementptr inbounds [500001 x i32], ptr @f, i64 0, i64 %70
  %72 = load i32, ptr %71, align 4, !tbaa !5
  %73 = sext i32 %72 to i64
  %74 = getelementptr inbounds [500001 x i64], ptr @sz, i64 0, i64 %73
  %75 = load i64, ptr %74, align 8, !tbaa !9
  %76 = load i32, ptr %7, align 4, !tbaa !5
  %77 = sext i32 %76 to i64
  %78 = getelementptr inbounds [500001 x i64], ptr @sz, i64 0, i64 %77
  %79 = load i64, ptr %78, align 8, !tbaa !9
  %80 = icmp slt i64 %75, %79
  br i1 %80, label %81, label %93

81:                                               ; preds = %43
  %82 = load i32, ptr %3, align 4, !tbaa !5
  %83 = sext i32 %82 to i64
  %84 = getelementptr inbounds [500001 x i32], ptr @f, i64 0, i64 %83
  %85 = load i32, ptr %84, align 4, !tbaa !5
  %86 = load i32, ptr %3, align 4, !tbaa !5
  %87 = sext i32 %86 to i64
  %88 = getelementptr inbounds [500001 x i32], ptr @g, i64 0, i64 %87
  store i32 %85, ptr %88, align 4, !tbaa !5
  %89 = load i32, ptr %7, align 4, !tbaa !5
  %90 = load i32, ptr %3, align 4, !tbaa !5
  %91 = sext i32 %90 to i64
  %92 = getelementptr inbounds [500001 x i32], ptr @f, i64 0, i64 %91
  store i32 %89, ptr %92, align 4, !tbaa !5
  br label %112

93:                                               ; preds = %43
  %94 = load i32, ptr %3, align 4, !tbaa !5
  %95 = sext i32 %94 to i64
  %96 = getelementptr inbounds [500001 x i32], ptr @g, i64 0, i64 %95
  %97 = load i32, ptr %96, align 4, !tbaa !5
  %98 = sext i32 %97 to i64
  %99 = getelementptr inbounds [500001 x i64], ptr @sz, i64 0, i64 %98
  %100 = load i64, ptr %99, align 8, !tbaa !9
  %101 = load i32, ptr %7, align 4, !tbaa !5
  %102 = sext i32 %101 to i64
  %103 = getelementptr inbounds [500001 x i64], ptr @sz, i64 0, i64 %102
  %104 = load i64, ptr %103, align 8, !tbaa !9
  %105 = icmp slt i64 %100, %104
  br i1 %105, label %106, label %111

106:                                              ; preds = %93
  %107 = load i32, ptr %7, align 4, !tbaa !5
  %108 = load i32, ptr %3, align 4, !tbaa !5
  %109 = sext i32 %108 to i64
  %110 = getelementptr inbounds [500001 x i32], ptr @g, i64 0, i64 %109
  store i32 %107, ptr %110, align 4, !tbaa !5
  br label %111

111:                                              ; preds = %106, %93
  br label %112

112:                                              ; preds = %111, %81
  store i32 0, ptr %6, align 4
  br label %113

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

115:                                              ; preds = %113
  br label %116

116:                                              ; preds = %115, %113
  %117 = load i32, ptr %5, align 4, !tbaa !5
  %118 = sext i32 %117 to i64
  %119 = getelementptr inbounds [1000003 x %struct.Edge], ptr @e, i64 0, i64 %118
  %120 = getelementptr inbounds %struct.Edge, ptr %119, i32 0, i32 0
  %121 = load i32, ptr %120, align 8, !tbaa !13
  store i32 %121, ptr %5, align 4, !tbaa !5
  br label %29, !llvm.loop !14

122:                                              ; preds = %32
  %123 = load i32, ptr %3, align 4, !tbaa !5
  call void @_Z5reseti(i32 noundef %123)
  ret void

124:                                              ; preds = %113
  unreachable
}

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 = { 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 = !{!12, !6, i64 4}
!12 = !{!"_ZTS4Edge", !6, i64 0, !6, i64 4}
!13 = !{!12, !6, i64 0}
!14 = distinct !{!14, !15}
!15 = !{!"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 }

@a = external dso_local local_unnamed_addr global [500001 x i32], align 16
@lnk = external dso_local local_unnamed_addr global [500001 x i32], align 16
@f = external dso_local local_unnamed_addr global [500001 x i32], align 16
@g = external dso_local local_unnamed_addr global [500001 x i32], align 16
@sz = external dso_local local_unnamed_addr global [500001 x i64], align 16
@sum = external dso_local local_unnamed_addr global [500001 x i64], align 16
@e = external dso_local local_unnamed_addr global [1000003 x %struct.Edge], align 16

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

; Function Attrs: mustprogress nounwind uwtable
define dso_local void @_Z4dfs1ii(i32 noundef %0, i32 noundef %1) local_unnamed_addr #0 {
  %3 = sext i32 %0 to i64
  %4 = getelementptr inbounds [500001 x i32], ptr @g, i64 0, i64 %3
  store i32 0, ptr %4, align 4, !tbaa !5
  %5 = getelementptr inbounds [500001 x i32], ptr @f, i64 0, i64 %3
  store i32 0, ptr %5, align 4, !tbaa !5
  %6 = getelementptr inbounds [500001 x i32], ptr @a, i64 0, i64 %3
  %7 = load i32, ptr %6, align 4, !tbaa !5
  %8 = sext i32 %7 to i64
  %9 = getelementptr inbounds [500001 x i64], ptr @sz, i64 0, i64 %3
  store i64 %8, ptr %9, align 8, !tbaa !9
  %10 = getelementptr inbounds [500001 x i64], ptr @sum, i64 0, i64 %3
  store i64 0, ptr %10, align 8, !tbaa !9
  %11 = getelementptr inbounds [500001 x i32], ptr @lnk, i64 0, i64 %3
  %.031 = load i32, ptr %11, align 4, !tbaa !5
  %.not32 = icmp eq i32 %.031, 0
  br i1 %.not32, label %._crit_edge, label %.lr.ph

._crit_edge:                                      ; preds = %41, %2
  tail call void @_Z5reseti(i32 noundef %0)
  ret void

.lr.ph:                                           ; preds = %2, %41
  %.033 = phi i32 [ %.0, %41 ], [ %.031, %2 ]
  %12 = sext i32 %.033 to i64
  %13 = getelementptr inbounds [1000003 x %struct.Edge], ptr @e, i64 0, i64 %12
  %14 = getelementptr inbounds i8, ptr %13, i64 4
  %15 = load i32, ptr %14, align 4, !tbaa !11
  %16 = icmp eq i32 %15, %1
  br i1 %16, label %41, label %17

17:                                               ; preds = %.lr.ph
  tail call void @_Z4dfs1ii(i32 noundef %15, i32 noundef %0)
  %18 = sext i32 %15 to i64
  %19 = getelementptr inbounds [500001 x i64], ptr @sz, i64 0, i64 %18
  %20 = load i64, ptr %19, align 8, !tbaa !9
  %21 = load i64, ptr %9, align 8, !tbaa !9
  %22 = add nsw i64 %21, %20
  store i64 %22, ptr %9, align 8, !tbaa !9
  %23 = getelementptr inbounds [500001 x i64], ptr @sum, i64 0, i64 %18
  %24 = load i64, ptr %23, align 8, !tbaa !9
  %25 = load i64, ptr %19, align 8, !tbaa !9
  %26 = add nsw i64 %25, %24
  %27 = load i64, ptr %10, align 8, !tbaa !9
  %28 = add nsw i64 %26, %27
  store i64 %28, ptr %10, align 8, !tbaa !9
  %29 = load i32, ptr %5, align 4, !tbaa !5
  %30 = sext i32 %29 to i64
  %31 = getelementptr inbounds [500001 x i64], ptr @sz, i64 0, i64 %30
  %32 = load i64, ptr %31, align 8, !tbaa !9
  %33 = icmp slt i64 %32, %25
  br i1 %33, label %34, label %35

34:                                               ; preds = %17
  store i32 %29, ptr %4, align 4, !tbaa !5
  br label %.sink.split

35:                                               ; preds = %17
  %36 = load i32, ptr %4, align 4, !tbaa !5
  %37 = sext i32 %36 to i64
  %38 = getelementptr inbounds [500001 x i64], ptr @sz, i64 0, i64 %37
  %39 = load i64, ptr %38, align 8, !tbaa !9
  %40 = icmp slt i64 %39, %25
  br i1 %40, label %.sink.split, label %41

.sink.split:                                      ; preds = %35, %34
  %.sink = phi ptr [ %5, %34 ], [ %4, %35 ]
  store i32 %15, ptr %.sink, align 4, !tbaa !5
  br label %41

41:                                               ; preds = %.sink.split, %35, %.lr.ph
  %.0 = load i32, ptr %13, align 8, !tbaa !5
  %.not = icmp eq i32 %.0, 0
  br i1 %.not, label %._crit_edge, label %.lr.ph, !llvm.loop !13
}

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

!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 = !{!12, !6, i64 4}
!12 = !{!"_ZTS4Edge", !6, i64 0, !6, i64 4}
!13 = distinct !{!13, !14}
!14 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,InferAlignmentPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass