; LLVM IR from tangjz/acm-icpc :: 51nod/1325.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 [61 x i32], align 16
@level = external dso_local global [61 x i32], align 16
@e = external dso_local global [488 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 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 %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
  %20 = load i32, ptr %4, align 4, !tbaa !5
  %21 = sext i32 %20 to i64
  %22 = getelementptr inbounds [61 x i32], ptr @cur, i64 0, i64 %21
  %23 = load i32, ptr %22, align 4, !tbaa !5
  store i32 %23, ptr %7, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #3
  br label %24

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

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

28:                                               ; preds = %24
  %29 = load i32, ptr %7, align 4, !tbaa !5
  %30 = sext i32 %29 to i64
  %31 = getelementptr inbounds [488 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 !9
  %34 = icmp ne i32 %33, 0
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #3
  br i1 %34, label %35, label %67

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

50:                                               ; preds = %35
  %51 = load i32, ptr %7, align 4, !tbaa !5
  %52 = sext i32 %51 to i64
  %53 = getelementptr inbounds [488 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 i32, ptr %7, align 4, !tbaa !5
  %57 = sext i32 %56 to i64
  %58 = getelementptr inbounds [488 x %struct.Edge], ptr @e, i64 0, i64 %57
  %59 = getelementptr inbounds %struct.Edge, ptr %58, i32 0, i32 2
  %60 = load i32, ptr %5, align 4, !tbaa !5
  %61 = load i32, ptr %6, align 4, !tbaa !5
  %62 = sub nsw i32 %60, %61
  store i32 %62, ptr %10, align 4, !tbaa !5
  %63 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZSt3minIiERKT_S2_S2_(ptr noundef nonnull align 4 dereferenceable(4) %59, ptr noundef nonnull align 4 dereferenceable(4) %10)
  %64 = load i32, ptr %63, align 4, !tbaa !5
  %65 = call noundef i32 @_Z3dfsii(i32 noundef %55, i32 noundef %64)
  store i32 %65, ptr %8, align 4, !tbaa !5
  %66 = icmp ne i32 %65, 0
  br label %67

67:                                               ; preds = %50, %35, %28
  %68 = phi i1 [ false, %35 ], [ false, %28 ], [ %66, %50 ]
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #3
  br i1 %68, label %69, label %92

69:                                               ; preds = %67
  %70 = load i32, ptr %8, align 4, !tbaa !5
  %71 = load i32, ptr %7, align 4, !tbaa !5
  %72 = sext i32 %71 to i64
  %73 = getelementptr inbounds [488 x %struct.Edge], ptr @e, i64 0, i64 %72
  %74 = getelementptr inbounds %struct.Edge, ptr %73, i32 0, i32 2
  %75 = load i32, ptr %74, align 4, !tbaa !9
  %76 = sub nsw i32 %75, %70
  store i32 %76, ptr %74, align 4, !tbaa !9
  %77 = load i32, ptr %8, align 4, !tbaa !5
  %78 = load i32, ptr %7, align 4, !tbaa !5
  %79 = xor i32 %78, 1
  %80 = sext i32 %79 to i64
  %81 = getelementptr inbounds [488 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 !9
  %84 = add nsw i32 %83, %77
  store i32 %84, ptr %82, align 4, !tbaa !9
  %85 = load i32, ptr %8, 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 = %69
  store i32 2, ptr %9, align 4
  br label %99

91:                                               ; preds = %69
  br label %92

92:                                               ; preds = %91, %67
  br label %93

93:                                               ; preds = %92
  %94 = load i32, ptr %7, align 4, !tbaa !5
  %95 = sext i32 %94 to i64
  %96 = getelementptr inbounds [488 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 !12
  store i32 %98, ptr %7, align 4, !tbaa !5
  br label %24, !llvm.loop !13

99:                                               ; preds = %90, %27
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #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 [61 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 %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, !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"}


; 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 [61 x i32], align 16
@level = external dso_local local_unnamed_addr global [61 x i32], align 16
@e = external dso_local global [488 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 [61 x i32], ptr @cur, i64 0, i64 %8
  %.02535 = load i32, ptr %9, align 4, !tbaa !5
  %.not36 = icmp eq i32 %.02535, -1
  br i1 %.not36, label %._crit_edge.thread, label %.lr.ph

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

11:                                               ; preds = %.lr.ph, %40
  %.02538 = phi i32 [ %.02535, %.lr.ph ], [ %.025, %40 ]
  %.02637 = phi i32 [ 0, %.lr.ph ], [ %.1, %40 ]
  %12 = sext i32 %.02538 to i64
  %13 = getelementptr inbounds [488 x %struct.Edge], ptr @e, i64 0, i64 %12
  %14 = getelementptr inbounds i8, ptr %13, i64 8
  %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 i8, ptr %13, i64 4
  %18 = load i32, ptr %17, align 4, !tbaa !11
  %19 = sext i32 %18 to i64
  %20 = getelementptr inbounds [61 x i32], ptr @level, i64 0, i64 %19
  %21 = load i32, ptr %20, align 4, !tbaa !5
  %22 = load i32, ptr %10, align 4, !tbaa !5
  %23 = add nsw i32 %22, 1
  %24 = icmp eq i32 %21, %23
  br i1 %24, label %25, label %.critedge

25:                                               ; preds = %16
  %26 = sub nsw i32 %1, %.02637
  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) %14, ptr noundef nonnull align 4 dereferenceable(4) %3)
  %28 = load i32, ptr %27, align 4, !tbaa !5
  %29 = call noundef i32 @_Z3dfsii(i32 noundef %18, i32 noundef %28)
  %.not33 = icmp eq i32 %29, 0
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %3) #3
  br i1 %.not33, label %40, label %30

30:                                               ; preds = %25
  %31 = load i32, ptr %14, align 4, !tbaa !9
  %32 = sub nsw i32 %31, %29
  store i32 %32, ptr %14, align 4, !tbaa !9
  %33 = xor i32 %.02538, 1
  %34 = sext i32 %33 to i64
  %35 = getelementptr inbounds [488 x %struct.Edge], ptr @e, i64 0, i64 %34, i32 2
  %36 = load i32, ptr %35, align 4, !tbaa !9
  %37 = add nsw i32 %36, %29
  store i32 %37, ptr %35, align 4, !tbaa !9
  %38 = add nsw i32 %29, %.02637
  %39 = icmp eq i32 %38, %1
  br i1 %39, label %._crit_edge, label %40

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

40:                                               ; preds = %25, %.critedge, %30
  %.1 = phi i32 [ %38, %30 ], [ %.02637, %25 ], [ %.02637, %.critedge ]
  %.025 = load i32, ptr %13, align 4, !tbaa !5
  %.not = icmp eq i32 %.025, -1
  br i1 %.not, label %._crit_edge, label %11, !llvm.loop !12

._crit_edge:                                      ; preds = %40, %30
  %.2 = phi i32 [ %.1, %40 ], [ %1, %30 ]
  %.not34 = icmp eq i32 %.2, 0
  br i1 %.not34, label %._crit_edge.thread, label %42

._crit_edge.thread:                               ; preds = %7, %._crit_edge
  %41 = getelementptr inbounds [61 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 8}
!10 = !{!"_ZTS4Edge", !6, i64 0, !6, i64 4, !6, i64 8}
!11 = !{!10, !6, i64 4}
!12 = distinct !{!12, !13}
!13 = !{!"llvm.loop.mustprogress"}


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