; LLVM IR from tangjz/acm-icpc :: lydsy/2127.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 [50003 x i32], align 16
@cur = external dso_local global [50003 x i32], align 16
@e = external dso_local global [280003 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 [50003 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 i32, ptr %4, align 4, !tbaa !5
  %27 = sext i32 %26 to i64
  %28 = getelementptr inbounds [50003 x i32], ptr @lev, i64 0, i64 %27
  %29 = load i32, ptr %28, align 4, !tbaa !5
  %30 = add nsw i32 %29, 1
  %31 = load ptr, ptr %8, align 8, !tbaa !9
  %32 = load i32, ptr %31, align 4, !tbaa !5
  %33 = sext i32 %32 to i64
  %34 = getelementptr inbounds [280003 x %struct.Edge], ptr @e, i64 0, i64 %33
  %35 = getelementptr inbounds %struct.Edge, ptr %34, i32 0, i32 1
  %36 = load i32, ptr %35, align 4, !tbaa !11
  %37 = sext i32 %36 to i64
  %38 = getelementptr inbounds [50003 x i32], ptr @lev, i64 0, i64 %37
  %39 = load i32, ptr %38, align 4, !tbaa !5
  %40 = icmp eq i32 %30, %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 [280003 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 [280003 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 ptr, ptr %8, align 8, !tbaa !9
  %57 = load i32, ptr %56, align 4, !tbaa !5
  %58 = sext i32 %57 to i64
  %59 = getelementptr inbounds [280003 x %struct.Edge], ptr @e, i64 0, i64 %58
  %60 = getelementptr inbounds %struct.Edge, ptr %59, i32 0, i32 2
  %61 = load i32, ptr %5, align 4, !tbaa !5
  %62 = load i32, ptr %6, align 4, !tbaa !5
  %63 = sub nsw i32 %61, %62
  store i32 %63, ptr %10, align 4, !tbaa !5
  %64 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZSt3minIiERKT_S2_S2_(ptr noundef nonnull align 4 dereferenceable(4) %60, ptr noundef nonnull align 4 dereferenceable(4) %10)
  %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 [280003 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 [280003 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 [280003 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 [50003 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 [50003 x i32], align 16
@cur = external dso_local local_unnamed_addr global [50003 x i32], align 16
@e = external dso_local global [280003 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 [50003 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 [50003 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 ], [ %44, %._crit_edge35 ]
  %12 = load i32, ptr %9, align 4, !tbaa !5
  %13 = add nsw i32 %12, 1
  %14 = sext i32 %11 to i64
  %15 = getelementptr inbounds [280003 x %struct.Edge], ptr @e, i64 0, i64 %14, i32 1
  %16 = load i32, ptr %15, align 4, !tbaa !9
  %17 = sext i32 %16 to i64
  %18 = getelementptr inbounds [50003 x i32], ptr @lev, i64 0, i64 %17
  %19 = load i32, ptr %18, align 4, !tbaa !5
  %20 = icmp eq i32 %13, %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 [280003 x %struct.Edge], ptr @e, i64 0, i64 %14, 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 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZSt3minIiERKT_S2_S2_(ptr noundef nonnull align 4 dereferenceable(4) %22, ptr noundef nonnull align 4 dereferenceable(4) %3)
  %28 = load i32, ptr %27, align 4, !tbaa !5
  %29 = call noundef i32 @_Z3dfsii(i32 noundef %16, i32 noundef %28)
  %30 = icmp sgt i32 %29, 0
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %3) #3
  %.pre = load i32, ptr %8, align 4, !tbaa !5
  %31 = sext i32 %.pre to i64
  br i1 %30, label %32, label %._crit_edge35

32:                                               ; preds = %25
  %33 = getelementptr inbounds [280003 x %struct.Edge], ptr @e, i64 0, i64 %31, i32 2
  %34 = load i32, ptr %33, align 4, !tbaa !11
  %35 = sub nsw i32 %34, %29
  store i32 %35, ptr %33, align 4, !tbaa !11
  %36 = xor i32 %.pre, 1
  %37 = sext i32 %36 to i64
  %38 = getelementptr inbounds [280003 x %struct.Edge], ptr @e, i64 0, i64 %37, i32 2
  %39 = load i32, ptr %38, align 4, !tbaa !11
  %40 = add nsw i32 %39, %29
  store i32 %40, ptr %38, align 4, !tbaa !11
  %41 = add nuw nsw i32 %29, %.02334
  %42 = icmp eq i32 %41, %1
  br i1 %42, 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, %32
  %.pre-phi = phi i64 [ %14, %.critedge ], [ %31, %32 ], [ %31, %25 ]
  %.1 = phi i32 [ %.02334, %.critedge ], [ %41, %32 ], [ %.02334, %25 ]
  %43 = getelementptr inbounds [280003 x %struct.Edge], ptr @e, i64 0, i64 %.pre-phi
  %44 = load i32, ptr %43, align 4, !tbaa !12
  store i32 %44, ptr %8, align 4, !tbaa !5
  %.not = icmp eq i32 %44, -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
  %45 = getelementptr inbounds [50003 x i32], ptr @lev, i64 0, i64 %7
  store i32 -1, ptr %45, align 4, !tbaa !5
  br label %.thread

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