; LLVM IR from tangjz/acm-icpc :: lydsy/3577.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
@cur = external dso_local global [64654 x i32], align 16
@level = external dso_local global [64654 x i32], align 16
@e = external dso_local global [646540 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 %17, label %14

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

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

19:                                               ; preds = %14
  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
  %20 = load i32, ptr %4, align 4, !tbaa !5
  %21 = sext i32 %20 to i64
  %22 = getelementptr inbounds [64654 x i32], ptr @cur, i64 0, i64 %21
  store ptr %22, ptr %8, align 8, !tbaa !9
  br label %23

23:                                               ; preds = %91, %19
  %24 = load ptr, ptr %8, align 8, !tbaa !9
  %25 = load i32, ptr %24, align 4, !tbaa !5
  %26 = icmp ne i32 %25, -1
  br i1 %26, label %28, label %27

27:                                               ; preds = %23
  store i32 2, ptr %9, align 4
  br label %99

28:                                               ; preds = %23
  %29 = load ptr, ptr %8, align 8, !tbaa !9
  %30 = load i32, ptr %29, align 4, !tbaa !5
  %31 = sext i32 %30 to i64
  %32 = getelementptr inbounds [646540 x %struct.Edge], ptr @e, i64 0, i64 %31
  %33 = getelementptr inbounds %struct.Edge, ptr %32, i32 0, i32 1
  %34 = load i32, ptr %33, align 4, !tbaa !11
  %35 = sext i32 %34 to i64
  %36 = getelementptr inbounds [64654 x i32], ptr @level, i64 0, i64 %35
  %37 = load i32, ptr %36, align 4, !tbaa !5
  %38 = load i32, ptr %4, align 4, !tbaa !5
  %39 = sext i32 %38 to i64
  %40 = getelementptr inbounds [64654 x i32], ptr @level, i64 0, i64 %39
  %41 = load i32, ptr %40, align 4, !tbaa !5
  %42 = add nsw i32 %41, 1
  %43 = icmp eq i32 %37, %42
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #3
  br i1 %43, label %44, label %63

44:                                               ; preds = %28
  %45 = load ptr, ptr %8, align 8, !tbaa !9
  %46 = load i32, ptr %45, align 4, !tbaa !5
  %47 = sext i32 %46 to i64
  %48 = getelementptr inbounds [646540 x %struct.Edge], ptr @e, i64 0, i64 %47
  %49 = getelementptr inbounds %struct.Edge, ptr %48, i32 0, i32 1
  %50 = load i32, ptr %49, align 4, !tbaa !11
  %51 = load i32, ptr %5, align 4, !tbaa !5
  %52 = load i32, ptr %6, align 4, !tbaa !5
  %53 = sub nsw i32 %51, %52
  store i32 %53, ptr %10, align 4, !tbaa !5
  %54 = load ptr, ptr %8, align 8, !tbaa !9
  %55 = load i32, ptr %54, align 4, !tbaa !5
  %56 = sext i32 %55 to i64
  %57 = getelementptr inbounds [646540 x %struct.Edge], ptr @e, i64 0, i64 %56
  %58 = getelementptr inbounds %struct.Edge, ptr %57, i32 0, i32 2
  %59 = 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) %58)
  %60 = load i32, ptr %59, align 4, !tbaa !5
  %61 = call noundef i32 @_Z3dfsii(i32 noundef %50, i32 noundef %60)
  store i32 %61, ptr %7, align 4, !tbaa !5
  %62 = icmp ne i32 %61, 0
  br label %63

63:                                               ; preds = %44, %28
  %64 = phi i1 [ false, %28 ], [ %62, %44 ]
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #3
  br i1 %64, label %65, label %90

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

88:                                               ; preds = %65
  store i32 2, ptr %9, align 4
  br label %99

89:                                               ; preds = %65
  br label %90

90:                                               ; preds = %89, %63
  br label %91

91:                                               ; preds = %90
  %92 = load ptr, ptr %8, align 8, !tbaa !9
  %93 = load i32, ptr %92, align 4, !tbaa !5
  %94 = sext i32 %93 to i64
  %95 = getelementptr inbounds [646540 x %struct.Edge], ptr @e, i64 0, i64 %94
  %96 = getelementptr inbounds %struct.Edge, ptr %95, i32 0, i32 0
  %97 = load i32, ptr %96, align 4, !tbaa !14
  %98 = load ptr, ptr %8, align 8, !tbaa !9
  store i32 %97, ptr %98, align 4, !tbaa !5
  br label %23, !llvm.loop !15

99:                                               ; preds = %88, %27
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #3
  br label %100

100:                                              ; preds = %99
  %101 = load i32, ptr %6, align 4, !tbaa !5
  %102 = icmp ne i32 %101, 0
  br i1 %102, label %107, label %103

103:                                              ; preds = %100
  %104 = load i32, ptr %4, align 4, !tbaa !5
  %105 = sext i32 %104 to i64
  %106 = getelementptr inbounds [64654 x i32], ptr @level, i64 0, i64 %105
  store i32 0, ptr %106, align 4, !tbaa !5
  br label %107

107:                                              ; preds = %103, %100
  %108 = load i32, ptr %6, align 4, !tbaa !5
  store i32 %108, 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 %109

109:                                              ; preds = %107, %17
  %110 = load i32, ptr %3, align 4
  ret i32 %110
}

; 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
@cur = external dso_local local_unnamed_addr global [64654 x i32], align 16
@level = external dso_local local_unnamed_addr global [64654 x i32], align 16
@e = external dso_local global [646540 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 %42

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

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

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

22:                                               ; preds = %11
  %23 = sub nsw i32 %1, %.02434
  store i32 %23, ptr %3, align 4, !tbaa !5
  %24 = getelementptr inbounds [646540 x %struct.Edge], ptr @e, i64 0, i64 %13, i32 2
  %25 = 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) %24)
  %26 = load i32, ptr %25, align 4, !tbaa !5
  %27 = call noundef i32 @_Z3dfsii(i32 noundef %15, i32 noundef %26)
  %.not31 = icmp eq i32 %27, 0
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %3) #3
  %.pre = load i32, ptr %9, align 4, !tbaa !5
  %.pre38 = sext i32 %.pre to i64
  br i1 %.not31, label %._crit_edge37, label %28

28:                                               ; preds = %22
  %29 = getelementptr inbounds [646540 x %struct.Edge], ptr @e, i64 0, i64 %.pre38, i32 2
  %30 = load i32, ptr %29, align 4, !tbaa !11
  %31 = sub nsw i32 %30, %27
  store i32 %31, ptr %29, align 4, !tbaa !11
  %32 = xor i32 %.pre, 1
  %33 = sext i32 %32 to i64
  %34 = getelementptr inbounds [646540 x %struct.Edge], ptr @e, i64 0, i64 %33, i32 2
  %35 = load i32, ptr %34, align 4, !tbaa !11
  %36 = add nsw i32 %35, %27
  store i32 %36, ptr %34, align 4, !tbaa !11
  %37 = add nsw i32 %27, %.02434
  %38 = icmp eq i32 %37, %1
  br i1 %38, label %._crit_edge, label %._crit_edge37

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

._crit_edge37:                                    ; preds = %22, %.critedge, %28
  %.pre-phi = phi i64 [ %13, %.critedge ], [ %.pre38, %28 ], [ %.pre38, %22 ]
  %.1 = phi i32 [ %.02434, %.critedge ], [ %37, %28 ], [ %.02434, %22 ]
  %39 = getelementptr inbounds [646540 x %struct.Edge], ptr @e, i64 0, i64 %.pre-phi
  %40 = load i32, ptr %39, align 4, !tbaa !12
  store i32 %40, ptr %9, align 4, !tbaa !5
  %.not = icmp eq i32 %40, -1
  br i1 %.not, label %._crit_edge, label %11, !llvm.loop !13

._crit_edge:                                      ; preds = %._crit_edge37, %28
  %.2 = phi i32 [ %.1, %._crit_edge37 ], [ %1, %28 ]
  %.not32 = icmp eq i32 %.2, 0
  br i1 %.not32, label %._crit_edge.thread, label %42

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

42:                                               ; preds = %._crit_edge, %._crit_edge.thread, %2
  %.0 = phi i32 [ %1, %2 ], [ 0, %._crit_edge.thread ], [ %.2, %._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 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,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LICMPass,LoopRotatePass,LoopSimplifyPass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass