; LLVM IR from tangjz/acm-icpc :: 51nod/Contest/Baishan_Geek_Challenge/D.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, i32 }

@tot = external dso_local global i32, align 4
@lnk = external dso_local global [100010 x i32], align 16
@e = external dso_local global [200020 x %struct.Edge], align 16
@dep = external dso_local global [100010 x i32], align 16
@seq = external dso_local global [200020 x i32], align 16
@pos = external dso_local global [100010 x i32], align 16
@Dist = external dso_local global [100010 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
  store i32 %0, ptr %3, align 4, !tbaa !5
  store i32 %1, ptr %4, align 4, !tbaa !5
  %9 = load i32, ptr %3, align 4, !tbaa !5
  %10 = load i32, ptr @tot, align 4, !tbaa !5
  %11 = add nsw i32 %10, 1
  store i32 %11, ptr @tot, align 4, !tbaa !5
  %12 = sext i32 %11 to i64
  %13 = getelementptr inbounds [200020 x i32], ptr @seq, i64 0, i64 %12
  store i32 %9, ptr %13, align 4, !tbaa !5
  %14 = load i32, ptr @tot, align 4, !tbaa !5
  %15 = load i32, ptr %3, align 4, !tbaa !5
  %16 = sext i32 %15 to i64
  %17 = getelementptr inbounds [100010 x i32], ptr @pos, i64 0, i64 %16
  store i32 %14, ptr %17, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #2
  %18 = load i32, ptr %3, align 4, !tbaa !5
  %19 = sext i32 %18 to i64
  %20 = getelementptr inbounds [100010 x i32], ptr @lnk, i64 0, i64 %19
  %21 = load i32, ptr %20, align 4, !tbaa !5
  store i32 %21, ptr %5, align 4, !tbaa !5
  br label %22

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

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

26:                                               ; preds = %22
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #2
  %27 = load i32, ptr %5, align 4, !tbaa !5
  %28 = sext i32 %27 to i64
  %29 = getelementptr inbounds [200020 x %struct.Edge], ptr @e, i64 0, i64 %28
  %30 = getelementptr inbounds %struct.Edge, ptr %29, i32 0, i32 1
  %31 = load i32, ptr %30, align 4, !tbaa !9
  store i32 %31, ptr %7, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #2
  %32 = load i32, ptr %5, align 4, !tbaa !5
  %33 = sext i32 %32 to i64
  %34 = getelementptr inbounds [200020 x %struct.Edge], ptr @e, i64 0, i64 %33
  %35 = getelementptr inbounds %struct.Edge, ptr %34, i32 0, i32 2
  %36 = load i32, ptr %35, align 4, !tbaa !11
  store i32 %36, ptr %8, align 4, !tbaa !5
  %37 = load i32, ptr %7, align 4, !tbaa !5
  %38 = load i32, ptr %4, align 4, !tbaa !5
  %39 = icmp eq i32 %37, %38
  br i1 %39, label %40, label %41

40:                                               ; preds = %26
  store i32 4, ptr %6, align 4
  br label %66

41:                                               ; preds = %26
  %42 = load i32, ptr %3, align 4, !tbaa !5
  %43 = sext i32 %42 to i64
  %44 = getelementptr inbounds [100010 x i32], ptr @dep, i64 0, i64 %43
  %45 = load i32, ptr %44, align 4, !tbaa !5
  %46 = add nsw i32 %45, 1
  %47 = load i32, ptr %7, align 4, !tbaa !5
  %48 = sext i32 %47 to i64
  %49 = getelementptr inbounds [100010 x i32], ptr @dep, i64 0, i64 %48
  store i32 %46, ptr %49, align 4, !tbaa !5
  %50 = load i32, ptr %3, align 4, !tbaa !5
  %51 = sext i32 %50 to i64
  %52 = getelementptr inbounds [100010 x i32], ptr @Dist, i64 0, i64 %51
  %53 = load i32, ptr %52, align 4, !tbaa !5
  %54 = load i32, ptr %8, align 4, !tbaa !5
  %55 = add nsw i32 %53, %54
  %56 = load i32, ptr %7, align 4, !tbaa !5
  %57 = sext i32 %56 to i64
  %58 = getelementptr inbounds [100010 x i32], ptr @Dist, i64 0, i64 %57
  store i32 %55, ptr %58, align 4, !tbaa !5
  %59 = load i32, ptr %7, align 4, !tbaa !5
  %60 = load i32, ptr %3, align 4, !tbaa !5
  call void @_Z3dfsii(i32 noundef %59, i32 noundef %60)
  %61 = load i32, ptr %3, align 4, !tbaa !5
  %62 = load i32, ptr @tot, align 4, !tbaa !5
  %63 = add nsw i32 %62, 1
  store i32 %63, ptr @tot, align 4, !tbaa !5
  %64 = sext i32 %63 to i64
  %65 = getelementptr inbounds [200020 x i32], ptr @seq, i64 0, i64 %64
  store i32 %61, ptr %65, align 4, !tbaa !5
  store i32 0, ptr %6, align 4
  br label %66

66:                                               ; preds = %41, %40
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #2
  %67 = load i32, ptr %6, align 4
  switch i32 %67, label %76 [
    i32 0, label %68
    i32 4, label %69
  ]

68:                                               ; preds = %66
  br label %69

69:                                               ; preds = %68, %66
  %70 = load i32, ptr %5, align 4, !tbaa !5
  %71 = sext i32 %70 to i64
  %72 = getelementptr inbounds [200020 x %struct.Edge], ptr @e, i64 0, i64 %71
  %73 = getelementptr inbounds %struct.Edge, ptr %72, i32 0, i32 0
  %74 = load i32, ptr %73, align 4, !tbaa !12
  store i32 %74, ptr %5, align 4, !tbaa !5
  br label %22, !llvm.loop !13

75:                                               ; preds = %25
  ret void

76:                                               ; preds = %66
  unreachable
}

; 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

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 = { 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, !6, i64 8}
!11 = !{!10, !6, i64 8}
!12 = !{!10, !6, i64 0}
!13 = distinct !{!13, !14}
!14 = !{!"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, i32 }

@tot = external dso_local local_unnamed_addr global i32, align 4
@lnk = external dso_local local_unnamed_addr global [100010 x i32], align 16
@e = external dso_local local_unnamed_addr global [200020 x %struct.Edge], align 16
@dep = external dso_local local_unnamed_addr global [100010 x i32], align 16
@seq = external dso_local local_unnamed_addr global [200020 x i32], align 16
@pos = external dso_local local_unnamed_addr global [100010 x i32], align 16
@Dist = external dso_local local_unnamed_addr global [100010 x i32], align 16

; Function Attrs: mustprogress nofree nosync nounwind memory(readwrite, argmem: none, inaccessiblemem: none) uwtable
define dso_local void @_Z3dfsii(i32 noundef %0, i32 noundef %1) local_unnamed_addr #0 {
  %3 = load i32, ptr @tot, align 4, !tbaa !5
  %4 = add nsw i32 %3, 1
  store i32 %4, ptr @tot, align 4, !tbaa !5
  %5 = sext i32 %4 to i64
  %6 = getelementptr inbounds [200020 x i32], ptr @seq, i64 0, i64 %5
  store i32 %0, ptr %6, align 4, !tbaa !5
  %7 = sext i32 %0 to i64
  %8 = getelementptr inbounds [100010 x i32], ptr @pos, i64 0, i64 %7
  store i32 %4, ptr %8, align 4, !tbaa !5
  %9 = getelementptr inbounds [100010 x i32], ptr @lnk, i64 0, i64 %7
  %.018 = load i32, ptr %9, align 4, !tbaa !5
  %.not19 = icmp eq i32 %.018, 0
  br i1 %.not19, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %2
  %10 = getelementptr inbounds [100010 x i32], ptr @dep, i64 0, i64 %7
  %11 = getelementptr inbounds [100010 x i32], ptr @Dist, i64 0, i64 %7
  br label %12

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

12:                                               ; preds = %.lr.ph, %32
  %.020 = phi i32 [ %.018, %.lr.ph ], [ %.0, %32 ]
  %13 = sext i32 %.020 to i64
  %14 = getelementptr inbounds [200020 x %struct.Edge], ptr @e, i64 0, i64 %13
  %15 = getelementptr inbounds i8, ptr %14, i64 4
  %16 = load i32, ptr %15, align 4, !tbaa !9
  %17 = icmp eq i32 %16, %1
  br i1 %17, label %32, label %18

18:                                               ; preds = %12
  %19 = getelementptr inbounds i8, ptr %14, i64 8
  %20 = load i32, ptr %19, align 4, !tbaa !11
  %21 = load i32, ptr %10, align 4, !tbaa !5
  %22 = add nsw i32 %21, 1
  %23 = sext i32 %16 to i64
  %24 = getelementptr inbounds [100010 x i32], ptr @dep, i64 0, i64 %23
  store i32 %22, ptr %24, align 4, !tbaa !5
  %25 = load i32, ptr %11, align 4, !tbaa !5
  %26 = add nsw i32 %25, %20
  %27 = getelementptr inbounds [100010 x i32], ptr @Dist, i64 0, i64 %23
  store i32 %26, ptr %27, align 4, !tbaa !5
  tail call void @_Z3dfsii(i32 noundef %16, i32 noundef %0)
  %28 = load i32, ptr @tot, align 4, !tbaa !5
  %29 = add nsw i32 %28, 1
  store i32 %29, ptr @tot, align 4, !tbaa !5
  %30 = sext i32 %29 to i64
  %31 = getelementptr inbounds [200020 x i32], ptr @seq, i64 0, i64 %30
  store i32 %0, ptr %31, align 4, !tbaa !5
  br label %32

32:                                               ; preds = %12, %18
  %.0 = load i32, ptr %14, align 4, !tbaa !5
  %.not = icmp eq i32 %.0, 0
  br i1 %.not, label %._crit_edge, label %12, !llvm.loop !12
}

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, !6, i64 8}
!11 = !{!10, !6, i64 8}
!12 = distinct !{!12, !13}
!13 = !{!"llvm.loop.mustprogress"}


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