; LLVM IR from tangjz/acm-icpc :: 51nod/1442.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 [210 x i32], align 16
@level = external dso_local global [210 x i32], align 16
@e = external dso_local global [1420 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 ptr, align 8
  %8 = alloca i32, align 4
  %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 %117

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 8, ptr %7) #3
  %20 = load i32, ptr %4, align 4, !tbaa !5
  %21 = sext i32 %20 to i64
  %22 = getelementptr inbounds [210 x i32], ptr @cur, i64 0, i64 %21
  store ptr %22, ptr %7, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #3
  br label %23

23:                                               ; preds = %99, %19
  %24 = load ptr, ptr %7, 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 %107

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

36:                                               ; preds = %28
  %37 = load ptr, ptr %7, align 8, !tbaa !9
  %38 = load i32, ptr %37, align 4, !tbaa !5
  %39 = sext i32 %38 to i64
  %40 = getelementptr inbounds [1420 x %struct.Edge], ptr @e, i64 0, i64 %39
  %41 = getelementptr inbounds %struct.Edge, ptr %40, i32 0, i32 1
  %42 = load i32, ptr %41, align 4, !tbaa !13
  %43 = sext i32 %42 to i64
  %44 = getelementptr inbounds [210 x i32], ptr @level, i64 0, i64 %43
  %45 = load i32, ptr %44, align 4, !tbaa !5
  %46 = load i32, ptr %4, align 4, !tbaa !5
  %47 = sext i32 %46 to i64
  %48 = getelementptr inbounds [210 x i32], ptr @level, i64 0, i64 %47
  %49 = load i32, ptr %48, align 4, !tbaa !5
  %50 = add nsw i32 %49, 1
  %51 = icmp eq i32 %45, %50
  br i1 %51, label %52, label %71

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

71:                                               ; preds = %52, %36, %28
  %72 = phi i1 [ false, %36 ], [ false, %28 ], [ %70, %52 ]
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #3
  br i1 %72, label %73, label %98

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

96:                                               ; preds = %73
  store i32 2, ptr %9, align 4
  br label %107

97:                                               ; preds = %73
  br label %98

98:                                               ; preds = %97, %71
  br label %99

99:                                               ; preds = %98
  %100 = load ptr, ptr %7, align 8, !tbaa !9
  %101 = load i32, ptr %100, align 4, !tbaa !5
  %102 = sext i32 %101 to i64
  %103 = getelementptr inbounds [1420 x %struct.Edge], ptr @e, i64 0, i64 %102
  %104 = getelementptr inbounds %struct.Edge, ptr %103, i32 0, i32 0
  %105 = load i32, ptr %104, align 4, !tbaa !14
  %106 = load ptr, ptr %7, align 8, !tbaa !9
  store i32 %105, ptr %106, align 4, !tbaa !5
  br label %23, !llvm.loop !15

107:                                              ; preds = %96, %27
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #3
  br label %108

108:                                              ; preds = %107
  %109 = load i32, ptr %6, align 4, !tbaa !5
  %110 = icmp ne i32 %109, 0
  br i1 %110, label %115, label %111

111:                                              ; preds = %108
  %112 = load i32, ptr %4, align 4, !tbaa !5
  %113 = sext i32 %112 to i64
  %114 = getelementptr inbounds [210 x i32], ptr @level, i64 0, i64 %113
  store i32 0, ptr %114, align 4, !tbaa !5
  br label %115

115:                                              ; preds = %111, %108
  %116 = load i32, ptr %6, align 4, !tbaa !5
  store i32 %116, ptr %3, align 4
  store i32 1, ptr %9, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #3
  br label %117

117:                                              ; preds = %115, %17
  %118 = load i32, ptr %3, align 4
  ret i32 %118
}

; 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 8}
!12 = !{!"_ZTS4Edge", !6, i64 0, !6, i64 4, !6, i64 8}
!13 = !{!12, !6, i64 4}
!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 [210 x i32], align 16
@level = external dso_local local_unnamed_addr global [210 x i32], align 16
@e = external dso_local global [1420 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 %46

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

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

11:                                               ; preds = %.lr.ph, %._crit_edge39
  %.02536 = phi i32 [ 0, %.lr.ph ], [ %.1, %._crit_edge39 ]
  %12 = phi i32 [ %.pr, %.lr.ph ], [ %44, %._crit_edge39 ]
  %13 = sext i32 %12 to i64
  %14 = getelementptr inbounds [1420 x %struct.Edge], ptr @e, i64 0, i64 %13, i32 2
  %15 = load i32, ptr %14, align 4, !tbaa !9
  %.not32 = icmp eq i32 %15, 0
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %3) #3
  br i1 %.not32, label %.critedge, label %16

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

26:                                               ; preds = %16
  %27 = getelementptr inbounds i8, ptr %17, i64 8
  %28 = sub nsw i32 %1, %.02536
  store i32 %28, ptr %3, align 4, !tbaa !5
  %29 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZSt3minIiERKT_S2_S2_(ptr noundef nonnull align 4 dereferenceable(4) %27, ptr noundef nonnull align 4 dereferenceable(4) %3)
  %30 = load i32, ptr %29, align 4, !tbaa !5
  %31 = call noundef i32 @_Z3dfsii(i32 noundef %19, i32 noundef %30)
  %.not33 = icmp eq i32 %31, 0
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %3) #3
  %.pre = load i32, ptr %9, align 4, !tbaa !5
  %.pre40 = sext i32 %.pre to i64
  br i1 %.not33, label %._crit_edge39, label %32

32:                                               ; preds = %26
  %33 = getelementptr inbounds [1420 x %struct.Edge], ptr @e, i64 0, i64 %.pre40, i32 2
  %34 = load i32, ptr %33, align 4, !tbaa !9
  %35 = sub nsw i32 %34, %31
  store i32 %35, ptr %33, align 4, !tbaa !9
  %36 = xor i32 %.pre, 1
  %37 = sext i32 %36 to i64
  %38 = getelementptr inbounds [1420 x %struct.Edge], ptr @e, i64 0, i64 %37, i32 2
  %39 = load i32, ptr %38, align 4, !tbaa !9
  %40 = add nsw i32 %39, %31
  store i32 %40, ptr %38, align 4, !tbaa !9
  %41 = add nsw i32 %31, %.02536
  %42 = icmp eq i32 %41, %1
  br i1 %42, label %._crit_edge, label %._crit_edge39

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

._crit_edge39:                                    ; preds = %26, %.critedge, %32
  %.pre-phi = phi i64 [ %13, %.critedge ], [ %.pre40, %32 ], [ %.pre40, %26 ]
  %.1 = phi i32 [ %.02536, %.critedge ], [ %41, %32 ], [ %.02536, %26 ]
  %43 = getelementptr inbounds [1420 x %struct.Edge], ptr @e, i64 0, i64 %.pre-phi
  %44 = load i32, ptr %43, align 4, !tbaa !12
  store i32 %44, ptr %9, align 4, !tbaa !5
  %.not = icmp eq i32 %44, -1
  br i1 %.not, label %._crit_edge, label %11, !llvm.loop !13

._crit_edge:                                      ; preds = %._crit_edge39, %32
  %.2 = phi i32 [ %.1, %._crit_edge39 ], [ %1, %32 ]
  %.not34 = icmp eq i32 %.2, 0
  br i1 %.not34, label %._crit_edge.thread, label %46

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

46:                                               ; 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 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"}


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