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

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

@lnk = external dso_local global [500001 x i32], align 16
@tot = external dso_local global i64, align 8
@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: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #0

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

; Function Attrs: mustprogress uwtable
define dso_local void @_Z4dfs2ii(i32 noundef %0, i32 noundef %1) #1 {
  %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
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #2
  %8 = load i32, ptr %3, align 4, !tbaa !5
  %9 = sext i32 %8 to i64
  %10 = getelementptr inbounds [500001 x i32], ptr @lnk, i64 0, i64 %9
  %11 = load i32, ptr %10, align 4, !tbaa !5
  store i32 %11, ptr %5, align 4, !tbaa !5
  br label %12

12:                                               ; preds = %58, %2
  %13 = load i32, ptr %5, align 4, !tbaa !5
  %14 = icmp ne i32 %13, 0
  br i1 %14, label %16, label %15

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

16:                                               ; preds = %12
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #2
  %17 = load i32, ptr %5, align 4, !tbaa !5
  %18 = sext i32 %17 to i64
  %19 = getelementptr inbounds [1000003 x %struct.Edge], ptr @e, i64 0, i64 %18
  %20 = getelementptr inbounds %struct.Edge, ptr %19, i32 0, i32 1
  %21 = load i32, ptr %20, align 4, !tbaa !9
  store i32 %21, ptr %7, align 4, !tbaa !5
  %22 = load i32, ptr %7, align 4, !tbaa !5
  %23 = load i32, ptr %4, align 4, !tbaa !5
  %24 = icmp eq i32 %22, %23
  br i1 %24, label %25, label %26

25:                                               ; preds = %16
  store i32 4, ptr %6, align 4
  br label %55

26:                                               ; preds = %16
  %27 = load i32, ptr %3, align 4, !tbaa !5
  %28 = sext i32 %27 to i64
  %29 = getelementptr inbounds [500001 x i64], ptr @sum, i64 0, i64 %28
  %30 = load i64, ptr %29, align 8, !tbaa !11
  %31 = load i32, ptr %7, align 4, !tbaa !5
  %32 = sext i32 %31 to i64
  %33 = getelementptr inbounds [500001 x i64], ptr @sum, i64 0, i64 %32
  %34 = load i64, ptr %33, align 8, !tbaa !11
  %35 = sub nsw i64 %30, %34
  %36 = load i32, ptr %7, 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 !11
  %40 = sub nsw i64 %35, %39
  %41 = load i64, ptr @tot, align 8, !tbaa !11
  %42 = add nsw i64 %40, %41
  %43 = load i32, ptr %7, align 4, !tbaa !5
  %44 = sext i32 %43 to i64
  %45 = getelementptr inbounds [500001 x i64], ptr @sz, i64 0, i64 %44
  %46 = load i64, ptr %45, align 8, !tbaa !11
  %47 = sub nsw i64 %42, %46
  %48 = load i32, ptr %7, align 4, !tbaa !5
  %49 = sext i32 %48 to i64
  %50 = getelementptr inbounds [500001 x i64], ptr @sum, i64 0, i64 %49
  %51 = load i64, ptr %50, align 8, !tbaa !11
  %52 = add nsw i64 %51, %47
  store i64 %52, ptr %50, align 8, !tbaa !11
  %53 = load i32, ptr %7, align 4, !tbaa !5
  %54 = load i32, ptr %3, align 4, !tbaa !5
  call void @_Z4dfs2ii(i32 noundef %53, i32 noundef %54)
  store i32 0, ptr %6, align 4
  br label %55

55:                                               ; preds = %26, %25
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #2
  %56 = load i32, ptr %6, align 4
  switch i32 %56, label %65 [
    i32 0, label %57
    i32 4, label %58
  ]

57:                                               ; preds = %55
  br label %58

58:                                               ; preds = %57, %55
  %59 = load i32, ptr %5, align 4, !tbaa !5
  %60 = sext i32 %59 to i64
  %61 = getelementptr inbounds [1000003 x %struct.Edge], ptr @e, i64 0, i64 %60
  %62 = getelementptr inbounds %struct.Edge, ptr %61, i32 0, i32 0
  %63 = load i32, ptr %62, align 8, !tbaa !13
  store i32 %63, ptr %5, align 4, !tbaa !5
  br label %12, !llvm.loop !14

64:                                               ; preds = %15
  ret void

65:                                               ; preds = %55
  unreachable
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = { 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 4}
!10 = !{!"_ZTS4Edge", !6, i64 0, !6, i64 4}
!11 = !{!12, !12, i64 0}
!12 = !{!"long long", !7, i64 0}
!13 = !{!10, !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 }

@lnk = external dso_local local_unnamed_addr global [500001 x i32], align 16
@tot = external dso_local local_unnamed_addr global i64, align 8
@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 nofree nosync nounwind memory(readwrite, argmem: none, inaccessiblemem: none) uwtable
define dso_local void @_Z4dfs2ii(i32 noundef %0, i32 noundef %1) local_unnamed_addr #0 {
  %3 = sext i32 %0 to i64
  %4 = getelementptr inbounds [500001 x i32], ptr @lnk, i64 0, i64 %3
  %.015 = load i32, ptr %4, align 4, !tbaa !5
  %.not16 = icmp eq i32 %.015, 0
  br i1 %.not16, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %2
  %5 = getelementptr inbounds [500001 x i64], ptr @sum, i64 0, i64 %3
  br label %6

._crit_edge:                                      ; preds = %22, %2
  ret void

6:                                                ; preds = %.lr.ph, %22
  %.017 = phi i32 [ %.015, %.lr.ph ], [ %.0, %22 ]
  %7 = sext i32 %.017 to i64
  %8 = getelementptr inbounds [1000003 x %struct.Edge], ptr @e, i64 0, i64 %7
  %9 = getelementptr inbounds i8, ptr %8, i64 4
  %10 = load i32, ptr %9, align 4, !tbaa !9
  %11 = icmp eq i32 %10, %1
  br i1 %11, label %22, label %12

12:                                               ; preds = %6
  %13 = load i64, ptr %5, align 8, !tbaa !11
  %14 = sext i32 %10 to i64
  %15 = getelementptr inbounds [500001 x i64], ptr @sum, i64 0, i64 %14
  %16 = getelementptr inbounds [500001 x i64], ptr @sz, i64 0, i64 %14
  %17 = load i64, ptr %16, align 8, !tbaa !11
  %18 = load i64, ptr @tot, align 8, !tbaa !11
  %19 = add i64 %18, %13
  %20 = shl i64 %17, 1
  %21 = sub i64 %19, %20
  store i64 %21, ptr %15, align 8, !tbaa !11
  tail call void @_Z4dfs2ii(i32 noundef %10, i32 noundef %0)
  br label %22

22:                                               ; preds = %6, %12
  %.0 = load i32, ptr %8, align 8, !tbaa !5
  %.not = icmp eq i32 %.0, 0
  br i1 %.not, label %._crit_edge, label %6, !llvm.loop !13
}

attributes #0 = { mustprogress nofree nosync nounwind memory(readwrite, argmem: none, inaccessiblemem: none) 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, !6, i64 4}
!10 = !{!"_ZTS4Edge", !6, i64 0, !6, i64 4}
!11 = !{!12, !12, i64 0}
!12 = !{!"long long", !7, i64 0}
!13 = distinct !{!13, !14}
!14 = !{!"llvm.loop.mustprogress"}


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