; LLVM IR from tangjz/acm-icpc :: hdu/5535.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 [10010 x i32], align 16
@level = external dso_local global [10010 x i32], align 16
@e = external dso_local global [120020 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
  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 %111

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

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

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

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

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

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

70:                                               ; preds = %51, %35, %27
  %71 = phi i1 [ false, %35 ], [ false, %27 ], [ %69, %51 ]
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #3
  br i1 %71, label %72, label %93

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

93:                                               ; preds = %72, %70
  br label %94

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

102:                                              ; preds = %26
  %103 = load i32, ptr %6, align 4, !tbaa !5
  %104 = icmp ne i32 %103, 0
  br i1 %104, label %109, label %105

105:                                              ; preds = %102
  %106 = load i32, ptr %4, align 4, !tbaa !5
  %107 = sext i32 %106 to i64
  %108 = getelementptr inbounds [10010 x i32], ptr @level, i64 0, i64 %107
  store i32 0, ptr %108, align 4, !tbaa !5
  br label %109

109:                                              ; preds = %105, %102
  %110 = load i32, ptr %6, align 4, !tbaa !5
  store i32 %110, ptr %3, 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 %111

111:                                              ; preds = %109, %16
  %112 = load i32, ptr %3, align 4
  ret i32 %112
}

; 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 [10010 x i32], align 16
@level = external dso_local local_unnamed_addr global [10010 x i32], align 16
@e = external dso_local global [120020 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 %45

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

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

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

11:                                               ; preds = %.lr.ph, %._crit_edge34
  %.02433 = phi i32 [ 0, %.lr.ph ], [ %.1, %._crit_edge34 ]
  %12 = phi i32 [ %.pr, %.lr.ph ], [ %43, %._crit_edge34 ]
  %13 = sext i32 %12 to i64
  %14 = getelementptr inbounds [120020 x %struct.Edge], ptr @e, i64 0, i64 %13, i32 2
  %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 [120020 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 [10010 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, %.02433
  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)
  %.not31 = 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
  %.pre35 = sext i32 %.pre to i64
  br i1 %.not31, label %._crit_edge34, label %32

32:                                               ; preds = %26
  %33 = getelementptr inbounds [120020 x %struct.Edge], ptr @e, i64 0, i64 %.pre35, 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 [120020 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, %.02433
  br label %._crit_edge34

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

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

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

45:                                               ; 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 = !{!10, !6, i64 0}
!13 = distinct !{!13, !14}
!14 = !{!"llvm.loop.mustprogress"}


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