; LLVM IR from tangjz/acm-icpc :: lydsy/4808.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 [40011 x i32], align 16
@lev = external dso_local global [40011 x i32], align 16
@e = external dso_local global [400011 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 %110

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 [40011 x i32], ptr @cur, i64 0, i64 %21
  store ptr %22, ptr %8, align 8, !tbaa !9
  br label %23

23:                                               ; preds = %92, %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 %100

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 [400011 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 [40011 x i32], ptr @lev, 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 [40011 x i32], ptr @lev, i64 0, i64 %39
  %41 = load i32, ptr %40, align 4, !tbaa !5
  %42 = add nsw i32 %41, 1
  %43 = icmp ne i32 %37, %42
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #3
  br i1 %43, label %64, label %44

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 [400011 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 [400011 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
  %63 = xor i1 %62, true
  br label %64

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

66:                                               ; preds = %64
  br label %92

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

90:                                               ; preds = %67
  store i32 2, ptr %9, align 4
  br label %100

91:                                               ; preds = %67
  br label %92

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

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

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

104:                                              ; preds = %101
  %105 = load i32, ptr %4, align 4, !tbaa !5
  %106 = sext i32 %105 to i64
  %107 = getelementptr inbounds [40011 x i32], ptr @lev, i64 0, i64 %106
  store i32 -1, ptr %107, align 4, !tbaa !5
  br label %108

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

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

; 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 [40011 x i32], align 16
@lev = external dso_local local_unnamed_addr global [40011 x i32], align 16
@e = external dso_local global [400011 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 %41

7:                                                ; preds = %2
  %8 = sext i32 %0 to i64
  %9 = getelementptr inbounds [40011 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 [40011 x i32], ptr @lev, 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 ], [ %39, %._crit_edge37 ]
  %13 = sext i32 %12 to i64
  %14 = getelementptr inbounds [400011 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 [40011 x i32], ptr @lev, 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
  %.not30 = icmp eq i32 %18, %20
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %3) #3
  br i1 %.not30, label %21, label %.critedge

21:                                               ; preds = %11
  %22 = sub nsw i32 %1, %.02434
  store i32 %22, ptr %3, align 4, !tbaa !5
  %23 = getelementptr inbounds [400011 x %struct.Edge], ptr @e, i64 0, i64 %13, i32 2
  %24 = 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) %23)
  %25 = load i32, ptr %24, align 4, !tbaa !5
  %26 = call noundef i32 @_Z3dfsii(i32 noundef %15, i32 noundef %25)
  %.not31 = icmp eq i32 %26, 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 %27

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

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

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

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

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

41:                                               ; 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