; LLVM IR from tangjz/acm-icpc :: codeforces/gym/100443B.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
@lev = external dso_local global [301 x i32], align 16
@cur = external dso_local global [301 x i32], align 16
@e = external dso_local global [60003 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 ptr, align 8
  %9 = alloca i32, align 4
  %10 = alloca i32, align 4
  store i32 %0, ptr %4, align 4, !tbaa !5
  store i32 %1, ptr %5, align 4, !tbaa !5
  %11 = load i32, ptr %4, align 4, !tbaa !5
  %12 = load i32, ptr @T, align 4, !tbaa !5
  %13 = icmp eq i32 %11, %12
  br i1 %13, label %14, label %16

14:                                               ; preds = %2
  %15 = load i32, ptr %5, align 4, !tbaa !5
  store i32 %15, ptr %3, align 4
  br label %114

16:                                               ; preds = %2
  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
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #3
  %17 = load i32, ptr %4, align 4, !tbaa !5
  %18 = sext i32 %17 to i64
  %19 = getelementptr inbounds [301 x i32], ptr @cur, i64 0, i64 %18
  store ptr %19, ptr %8, align 8, !tbaa !9
  br label %20

20:                                               ; preds = %96, %16
  %21 = load ptr, ptr %8, align 8, !tbaa !9
  %22 = load i32, ptr %21, align 4, !tbaa !5
  %23 = icmp ne i32 %22, -1
  br i1 %23, label %25, label %24

24:                                               ; preds = %20
  store i32 2, ptr %9, align 4
  br label %104

25:                                               ; preds = %20
  %26 = load ptr, ptr %8, align 8, !tbaa !9
  %27 = load i32, ptr %26, align 4, !tbaa !5
  %28 = sext i32 %27 to i64
  %29 = getelementptr inbounds [60003 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 !11
  %32 = sext i32 %31 to i64
  %33 = getelementptr inbounds [301 x i32], ptr @lev, i64 0, i64 %32
  %34 = load i32, ptr %33, align 4, !tbaa !5
  %35 = load i32, ptr %4, align 4, !tbaa !5
  %36 = sext i32 %35 to i64
  %37 = getelementptr inbounds [301 x i32], ptr @lev, i64 0, i64 %36
  %38 = load i32, ptr %37, align 4, !tbaa !5
  %39 = add nsw i32 %38, 1
  %40 = icmp eq i32 %34, %39
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #3
  br i1 %40, label %41, label %68

41:                                               ; preds = %25
  %42 = load ptr, ptr %8, align 8, !tbaa !9
  %43 = load i32, ptr %42, align 4, !tbaa !5
  %44 = sext i32 %43 to i64
  %45 = getelementptr inbounds [60003 x %struct.Edge], ptr @e, i64 0, i64 %44
  %46 = getelementptr inbounds %struct.Edge, ptr %45, i32 0, i32 2
  %47 = load i32, ptr %46, align 4, !tbaa !13
  %48 = icmp sgt i32 %47, 0
  br i1 %48, label %49, label %68

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

68:                                               ; preds = %49, %41, %25
  %69 = phi i1 [ false, %41 ], [ false, %25 ], [ %67, %49 ]
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #3
  br i1 %69, label %70, label %95

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

93:                                               ; preds = %70
  store i32 2, ptr %9, align 4
  br label %104

94:                                               ; preds = %70
  br label %95

95:                                               ; preds = %94, %68
  br label %96

96:                                               ; preds = %95
  %97 = load ptr, ptr %8, align 8, !tbaa !9
  %98 = load i32, ptr %97, align 4, !tbaa !5
  %99 = sext i32 %98 to i64
  %100 = getelementptr inbounds [60003 x %struct.Edge], ptr @e, i64 0, i64 %99
  %101 = getelementptr inbounds %struct.Edge, ptr %100, i32 0, i32 0
  %102 = load i32, ptr %101, align 4, !tbaa !14
  %103 = load ptr, ptr %8, align 8, !tbaa !9
  store i32 %102, ptr %103, align 4, !tbaa !5
  br label %20, !llvm.loop !15

104:                                              ; preds = %93, %24
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #3
  br label %105

105:                                              ; preds = %104
  %106 = load i32, ptr %6, align 4, !tbaa !5
  %107 = icmp ne i32 %106, 0
  br i1 %107, label %112, label %108

108:                                              ; preds = %105
  %109 = load i32, ptr %4, align 4, !tbaa !5
  %110 = sext i32 %109 to i64
  %111 = getelementptr inbounds [301 x i32], ptr @lev, i64 0, i64 %110
  store i32 -1, ptr %111, align 4, !tbaa !5
  br label %112

112:                                              ; preds = %108, %105
  %113 = load i32, ptr %6, align 4, !tbaa !5
  store i32 %113, ptr %3, align 4
  store i32 1, ptr %9, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #3
  br label %114

114:                                              ; preds = %112, %14
  %115 = load i32, ptr %3, align 4
  ret i32 %115
}

; 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, !10, i64 0}
!10 = !{!"any pointer", !7, i64 0}
!11 = !{!12, !6, i64 4}
!12 = !{!"_ZTS4Edge", !6, i64 0, !6, i64 4, !6, i64 8}
!13 = !{!12, !6, i64 8}
!14 = !{!12, !6, i64 0}
!15 = distinct !{!15, !16}
!16 = !{!"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
@lev = external dso_local local_unnamed_addr global [301 x i32], align 16
@cur = external dso_local local_unnamed_addr global [301 x i32], align 16
@e = external dso_local global [60003 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 eq i32 %4, %0
  br i1 %5, label %.thread, label %6

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

.lr.ph:                                           ; preds = %6
  %9 = getelementptr inbounds [301 x i32], ptr @lev, i64 0, i64 %7
  br label %10

10:                                               ; preds = %.lr.ph, %._crit_edge35
  %.02334 = phi i32 [ 0, %.lr.ph ], [ %.1, %._crit_edge35 ]
  %11 = phi i32 [ %.pr, %.lr.ph ], [ %45, %._crit_edge35 ]
  %12 = sext i32 %11 to i64
  %13 = getelementptr inbounds [60003 x %struct.Edge], ptr @e, i64 0, i64 %12, i32 1
  %14 = load i32, ptr %13, align 4, !tbaa !9
  %15 = sext i32 %14 to i64
  %16 = getelementptr inbounds [301 x i32], ptr @lev, i64 0, i64 %15
  %17 = load i32, ptr %16, align 4, !tbaa !5
  %18 = load i32, ptr %9, align 4, !tbaa !5
  %19 = add nsw i32 %18, 1
  %20 = icmp eq i32 %17, %19
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %3) #3
  br i1 %20, label %21, label %.critedge

21:                                               ; preds = %10
  %22 = getelementptr inbounds [60003 x %struct.Edge], ptr @e, i64 0, i64 %12, i32 2
  %23 = load i32, ptr %22, align 4, !tbaa !11
  %24 = icmp sgt i32 %23, 0
  br i1 %24, label %25, label %.critedge

25:                                               ; preds = %21
  %26 = sub nsw i32 %1, %.02334
  store i32 %26, ptr %3, align 4, !tbaa !5
  %27 = getelementptr inbounds [60003 x %struct.Edge], ptr @e, i64 0, i64 %12, i32 2
  %28 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZSt3minIiERKT_S2_S2_(ptr noundef nonnull align 4 dereferenceable(4) %3, ptr noundef nonnull align 4 dereferenceable(4) %27)
  %29 = load i32, ptr %28, align 4, !tbaa !5
  %30 = call noundef i32 @_Z3dfsii(i32 noundef %14, i32 noundef %29)
  %31 = icmp sgt i32 %30, 0
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %3) #3
  %.pre = load i32, ptr %8, align 4, !tbaa !5
  %32 = sext i32 %.pre to i64
  br i1 %31, label %33, label %._crit_edge35

33:                                               ; preds = %25
  %34 = getelementptr inbounds [60003 x %struct.Edge], ptr @e, i64 0, i64 %32, i32 2
  %35 = load i32, ptr %34, align 4, !tbaa !11
  %36 = sub nsw i32 %35, %30
  store i32 %36, ptr %34, align 4, !tbaa !11
  %37 = xor i32 %.pre, 1
  %38 = sext i32 %37 to i64
  %39 = getelementptr inbounds [60003 x %struct.Edge], ptr @e, i64 0, i64 %38, i32 2
  %40 = load i32, ptr %39, align 4, !tbaa !11
  %41 = add nsw i32 %40, %30
  store i32 %41, ptr %39, align 4, !tbaa !11
  %42 = add nuw nsw i32 %30, %.02334
  %43 = icmp eq i32 %42, %1
  br i1 %43, label %.thread, label %._crit_edge35

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

._crit_edge35:                                    ; preds = %25, %.critedge, %33
  %.pre-phi = phi i64 [ %12, %.critedge ], [ %32, %33 ], [ %32, %25 ]
  %.1 = phi i32 [ %.02334, %.critedge ], [ %42, %33 ], [ %.02334, %25 ]
  %44 = getelementptr inbounds [60003 x %struct.Edge], ptr @e, i64 0, i64 %.pre-phi
  %45 = load i32, ptr %44, align 4, !tbaa !12
  store i32 %45, ptr %8, align 4, !tbaa !5
  %.not = icmp eq i32 %45, -1
  br i1 %.not, label %._crit_edge, label %10, !llvm.loop !13

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

._crit_edge.thread:                               ; preds = %6, %._crit_edge
  %46 = getelementptr inbounds [301 x i32], ptr @lev, i64 0, i64 %7
  store i32 -1, ptr %46, align 4, !tbaa !5
  br label %.thread

.thread:                                          ; preds = %33, %._crit_edge, %._crit_edge.thread, %2
  %.0 = phi i32 [ %1, %2 ], [ 0, %._crit_edge.thread ], [ %.1, %._crit_edge ], [ %1, %33 ]
  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 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"}


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