; LLVM IR from tangjz/acm-icpc :: codeforces/gym/100825F.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 }

@T = external dso_local global i32, align 4
@lnk = external dso_local global [2610 x i32], align 16
@level = external dso_local global [2610 x i32], align 16
@e = external dso_local global [2600000 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 noundef i32 @_Z3dfsii(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
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  store i32 %0, ptr %4, align 4, !tbaa !5
  store i32 %1, ptr %5, align 4, !tbaa !5
  %10 = load i32, ptr %4, align 4, !tbaa !5
  %11 = load i32, ptr @T, align 4, !tbaa !5
  %12 = icmp eq i32 %10, %11
  br i1 %12, label %16, label %13

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

16:                                               ; preds = %13, %2
  %17 = load i32, ptr %5, align 4, !tbaa !5
  store i32 %17, ptr %3, align 4
  br label %103

18:                                               ; preds = %13
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #3
  store i32 0, ptr %6, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #3
  %19 = load i32, ptr %4, align 4, !tbaa !5
  %20 = sext i32 %19 to i64
  %21 = getelementptr inbounds [2610 x i32], ptr @lnk, i64 0, i64 %20
  %22 = load i32, ptr %21, align 4, !tbaa !5
  store i32 %22, ptr %7, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #3
  br label %23

23:                                               ; preds = %88, %18
  %24 = load i32, ptr %7, align 4, !tbaa !5
  %25 = icmp ne i32 %24, -1
  br i1 %25, label %27, label %26

26:                                               ; preds = %23
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #3
  br label %94

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

34:                                               ; preds = %27
  %35 = load i32, ptr %7, align 4, !tbaa !5
  %36 = sext i32 %35 to i64
  %37 = getelementptr inbounds [2600000 x %struct.Edge], ptr @e, i64 0, i64 %36
  %38 = getelementptr inbounds %struct.Edge, ptr %37, i32 0, i32 1
  %39 = load i32, ptr %38, align 4, !tbaa !11
  %40 = sext i32 %39 to i64
  %41 = getelementptr inbounds [2610 x i32], ptr @level, i64 0, i64 %40
  %42 = load i32, ptr %41, align 4, !tbaa !5
  %43 = load i32, ptr %4, align 4, !tbaa !5
  %44 = sext i32 %43 to i64
  %45 = getelementptr inbounds [2610 x i32], ptr @level, i64 0, i64 %44
  %46 = load i32, ptr %45, align 4, !tbaa !5
  %47 = add nsw i32 %46, 1
  %48 = icmp eq i32 %42, %47
  br i1 %48, label %49, label %66

49:                                               ; preds = %34
  %50 = load i32, ptr %7, align 4, !tbaa !5
  %51 = sext i32 %50 to i64
  %52 = getelementptr inbounds [2600000 x %struct.Edge], ptr @e, i64 0, i64 %51
  %53 = getelementptr inbounds %struct.Edge, ptr %52, i32 0, i32 1
  %54 = load i32, ptr %53, align 4, !tbaa !11
  %55 = load i32, ptr %7, align 4, !tbaa !5
  %56 = sext i32 %55 to i64
  %57 = getelementptr inbounds [2600000 x %struct.Edge], ptr @e, i64 0, i64 %56
  %58 = getelementptr inbounds %struct.Edge, ptr %57, i32 0, i32 2
  %59 = load i32, ptr %5, align 4, !tbaa !5
  %60 = load i32, ptr %6, align 4, !tbaa !5
  %61 = sub nsw i32 %59, %60
  store i32 %61, ptr %9, align 4, !tbaa !5
  %62 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZSt3minIiERKT_S2_S2_(ptr noundef nonnull align 4 dereferenceable(4) %58, ptr noundef nonnull align 4 dereferenceable(4) %9)
  %63 = load i32, ptr %62, align 4, !tbaa !5
  %64 = call noundef i32 @_Z3dfsii(i32 noundef %54, i32 noundef %63)
  store i32 %64, ptr %8, align 4, !tbaa !5
  %65 = icmp ne i32 %64, 0
  br label %66

66:                                               ; preds = %49, %34, %27
  %67 = phi i1 [ false, %34 ], [ false, %27 ], [ %65, %49 ]
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #3
  br i1 %67, label %68, label %87

68:                                               ; preds = %66
  %69 = load i32, ptr %8, align 4, !tbaa !5
  %70 = load i32, ptr %7, align 4, !tbaa !5
  %71 = sext i32 %70 to i64
  %72 = getelementptr inbounds [2600000 x %struct.Edge], ptr @e, i64 0, i64 %71
  %73 = getelementptr inbounds %struct.Edge, ptr %72, i32 0, i32 2
  %74 = load i32, ptr %73, align 4, !tbaa !9
  %75 = sub nsw i32 %74, %69
  store i32 %75, ptr %73, align 4, !tbaa !9
  %76 = load i32, ptr %8, align 4, !tbaa !5
  %77 = load i32, ptr %7, align 4, !tbaa !5
  %78 = xor i32 %77, 1
  %79 = sext i32 %78 to i64
  %80 = getelementptr inbounds [2600000 x %struct.Edge], ptr @e, i64 0, i64 %79
  %81 = getelementptr inbounds %struct.Edge, ptr %80, i32 0, i32 2
  %82 = load i32, ptr %81, align 4, !tbaa !9
  %83 = add nsw i32 %82, %76
  store i32 %83, ptr %81, align 4, !tbaa !9
  %84 = load i32, ptr %8, align 4, !tbaa !5
  %85 = load i32, ptr %6, align 4, !tbaa !5
  %86 = add nsw i32 %85, %84
  store i32 %86, ptr %6, align 4, !tbaa !5
  br label %87

87:                                               ; preds = %68, %66
  br label %88

88:                                               ; preds = %87
  %89 = load i32, ptr %7, align 4, !tbaa !5
  %90 = sext i32 %89 to i64
  %91 = getelementptr inbounds [2600000 x %struct.Edge], ptr @e, i64 0, i64 %90
  %92 = getelementptr inbounds %struct.Edge, ptr %91, i32 0, i32 0
  %93 = load i32, ptr %92, align 4, !tbaa !12
  store i32 %93, ptr %7, align 4, !tbaa !5
  br label %23, !llvm.loop !13

94:                                               ; preds = %26
  %95 = load i32, ptr %6, align 4, !tbaa !5
  %96 = icmp ne i32 %95, 0
  br i1 %96, label %101, label %97

97:                                               ; preds = %94
  %98 = load i32, ptr %4, align 4, !tbaa !5
  %99 = sext i32 %98 to i64
  %100 = getelementptr inbounds [2610 x i32], ptr @level, i64 0, i64 %99
  store i32 0, ptr %100, align 4, !tbaa !5
  br label %101

101:                                              ; preds = %97, %94
  %102 = load i32, ptr %6, align 4, !tbaa !5
  store i32 %102, ptr %3, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #3
  br label %103

103:                                              ; preds = %101, %16
  %104 = load i32, ptr %3, align 4
  ret i32 %104
}

; 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

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 = { 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 8}
!10 = !{!"_ZTS4Edge", !6, i64 0, !6, i64 4, !6, i64 8}
!11 = !{!10, !6, i64 4}
!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 }

@T = external dso_local local_unnamed_addr global i32, align 4
@lnk = external dso_local local_unnamed_addr global [2610 x i32], align 16
@level = external dso_local local_unnamed_addr global [2610 x i32], align 16
@e = external dso_local global [2600000 x %struct.Edge], align 16

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

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

; Function Attrs: mustprogress nounwind uwtable
define dso_local noundef i32 @_Z3dfsii(i32 noundef %0, i32 noundef %1) local_unnamed_addr #1 {
  %3 = alloca i32, align 4
  %4 = load i32, ptr @T, align 4, !tbaa !5
  %5 = icmp ne i32 %4, %0
  %6 = icmp ne i32 %1, 0
  %or.cond = and i1 %6, %5
  br i1 %or.cond, label %7, label %41

7:                                                ; preds = %2
  %8 = sext i32 %0 to i64
  %9 = getelementptr inbounds [2610 x i32], ptr @lnk, i64 0, i64 %8
  %.02432 = load i32, ptr %9, align 4, !tbaa !5
  %.not33 = icmp eq i32 %.02432, -1
  br i1 %.not33, label %._crit_edge.thread, label %.lr.ph

.lr.ph:                                           ; preds = %7
  %10 = getelementptr inbounds [2610 x i32], ptr @level, i64 0, i64 %8
  br label %11

._crit_edge:                                      ; preds = %39
  %.not29 = icmp eq i32 %.1, 0
  br i1 %.not29, label %._crit_edge.thread, label %41

11:                                               ; preds = %.lr.ph, %39
  %.02435 = phi i32 [ %.02432, %.lr.ph ], [ %.024, %39 ]
  %.02534 = phi i32 [ 0, %.lr.ph ], [ %.1, %39 ]
  %12 = sext i32 %.02435 to i64
  %13 = getelementptr inbounds [2600000 x %struct.Edge], ptr @e, i64 0, i64 %12
  %14 = getelementptr inbounds i8, ptr %13, i64 8
  %15 = load i32, ptr %14, align 4, !tbaa !9
  %.not30 = icmp eq i32 %15, 0
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %3) #3
  br i1 %.not30, label %.critedge, label %16

16:                                               ; preds = %11
  %17 = getelementptr inbounds i8, ptr %13, i64 4
  %18 = load i32, ptr %17, align 4, !tbaa !11
  %19 = sext i32 %18 to i64
  %20 = getelementptr inbounds [2610 x i32], ptr @level, i64 0, i64 %19
  %21 = load i32, ptr %20, align 4, !tbaa !5
  %22 = load i32, ptr %10, align 4, !tbaa !5
  %23 = add nsw i32 %22, 1
  %24 = icmp eq i32 %21, %23
  br i1 %24, label %25, label %.critedge

25:                                               ; preds = %16
  %26 = sub nsw i32 %1, %.02534
  store i32 %26, ptr %3, align 4, !tbaa !5
  %27 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZSt3minIiERKT_S2_S2_(ptr noundef nonnull align 4 dereferenceable(4) %14, ptr noundef nonnull align 4 dereferenceable(4) %3)
  %28 = load i32, ptr %27, align 4, !tbaa !5
  %29 = call noundef i32 @_Z3dfsii(i32 noundef %18, i32 noundef %28)
  %.not31 = icmp eq i32 %29, 0
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %3) #3
  br i1 %.not31, label %39, label %30

30:                                               ; preds = %25
  %31 = load i32, ptr %14, align 4, !tbaa !9
  %32 = sub nsw i32 %31, %29
  store i32 %32, ptr %14, align 4, !tbaa !9
  %33 = xor i32 %.02435, 1
  %34 = sext i32 %33 to i64
  %35 = getelementptr inbounds [2600000 x %struct.Edge], ptr @e, i64 0, i64 %34, i32 2
  %36 = load i32, ptr %35, align 4, !tbaa !9
  %37 = add nsw i32 %36, %29
  store i32 %37, ptr %35, align 4, !tbaa !9
  %38 = add nsw i32 %29, %.02534
  br label %39

.critedge:                                        ; preds = %11, %16
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %3) #3
  br label %39

39:                                               ; preds = %25, %30, %.critedge
  %.1 = phi i32 [ %38, %30 ], [ %.02534, %25 ], [ %.02534, %.critedge ]
  %.024 = load i32, ptr %13, align 4, !tbaa !5
  %.not = icmp eq i32 %.024, -1
  br i1 %.not, label %._crit_edge, label %11, !llvm.loop !12

._crit_edge.thread:                               ; preds = %7, %._crit_edge
  %40 = getelementptr inbounds [2610 x i32], ptr @level, i64 0, i64 %8
  store i32 0, ptr %40, align 4, !tbaa !5
  br label %41

41:                                               ; preds = %._crit_edge, %._crit_edge.thread, %2
  %.0 = phi i32 [ %1, %2 ], [ 0, %._crit_edge.thread ], [ %.1, %._crit_edge ]
  ret i32 %.0
}

; 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

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


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