; LLVM IR from tangjz/acm-icpc :: codeforces/gym/100827C.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
@ptr = external dso_local global [1001 x i32], align 16
@pos = external dso_local global [1001 x i32], align 16
@e = external dso_local global [7001 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 %118

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

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

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 [7001 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 [1001 x i32], ptr @pos, 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 [1001 x i32], ptr @pos, 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 %71

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 [7001 x %struct.Edge], ptr @e, i64 0, i64 %47
  %49 = getelementptr inbounds %struct.Edge, ptr %48, i32 0, i32 2
  %50 = load i32, ptr %49, align 4, !tbaa !13
  %51 = icmp sgt i32 %50, 0
  br i1 %51, label %52, label %71

52:                                               ; preds = %44
  %53 = load ptr, ptr %8, align 8, !tbaa !9
  %54 = load i32, ptr %53, align 4, !tbaa !5
  %55 = sext i32 %54 to i64
  %56 = getelementptr inbounds [7001 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 !11
  %59 = load ptr, ptr %8, align 8, !tbaa !9
  %60 = load i32, ptr %59, align 4, !tbaa !5
  %61 = sext i32 %60 to i64
  %62 = getelementptr inbounds [7001 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 %7, align 4, !tbaa !5
  %70 = icmp sgt i32 %69, 0
  br label %71

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

73:                                               ; preds = %71
  %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 = sext i32 %76 to i64
  %78 = getelementptr inbounds [7001 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 !13
  %81 = sub nsw i32 %80, %74
  store i32 %81, ptr %79, align 4, !tbaa !13
  %82 = load i32, ptr %7, align 4, !tbaa !5
  %83 = load ptr, ptr %8, 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 [7001 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 !13
  %90 = add nsw i32 %89, %82
  store i32 %90, ptr %88, align 4, !tbaa !13
  %91 = load i32, ptr %7, 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 %6, align 4, !tbaa !5
  %95 = load i32, ptr %5, align 4, !tbaa !5
  %96 = icmp eq i32 %94, %95
  br i1 %96, label %97, label %98

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

98:                                               ; preds = %73
  br label %99

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

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

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

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

112:                                              ; preds = %109
  %113 = load i32, ptr %4, align 4, !tbaa !5
  %114 = sext i32 %113 to i64
  %115 = getelementptr inbounds [1001 x i32], ptr @pos, i64 0, i64 %114
  store i32 -1, ptr %115, align 4, !tbaa !5
  br label %116

116:                                              ; preds = %112, %109
  %117 = load i32, ptr %6, align 4, !tbaa !5
  store i32 %117, 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 %118

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

; 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
@ptr = external dso_local local_unnamed_addr global [1001 x i32], align 16
@pos = external dso_local local_unnamed_addr global [1001 x i32], align 16
@e = external dso_local global [7001 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 %.thread

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

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

11:                                               ; preds = %.lr.ph, %._crit_edge39
  %.02638 = phi i32 [ 0, %.lr.ph ], [ %.1, %._crit_edge39 ]
  %12 = phi i32 [ %.pr, %.lr.ph ], [ %45, %._crit_edge39 ]
  %13 = sext i32 %12 to i64
  %14 = getelementptr inbounds [7001 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 [1001 x i32], ptr @pos, 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 = getelementptr inbounds [7001 x %struct.Edge], ptr @e, i64 0, i64 %13, i32 2
  %24 = load i32, ptr %23, align 4, !tbaa !11
  %25 = icmp sgt i32 %24, 0
  br i1 %25, label %26, label %.critedge

26:                                               ; preds = %22
  %27 = sub nsw i32 %1, %.02638
  store i32 %27, ptr %3, align 4, !tbaa !5
  %28 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZSt3minIiERKT_S2_S2_(ptr noundef nonnull align 4 dereferenceable(4) %23, ptr noundef nonnull align 4 dereferenceable(4) %3)
  %29 = load i32, ptr %28, align 4, !tbaa !5
  %30 = call noundef i32 @_Z3dfsii(i32 noundef %15, i32 noundef %29)
  %31 = icmp sgt i32 %30, 0
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %3) #3
  %.pre = load i32, ptr %9, align 4, !tbaa !5
  %32 = sext i32 %.pre to i64
  br i1 %31, label %33, label %._crit_edge39

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

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

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

._crit_edge:                                      ; preds = %._crit_edge39
  %.not33 = icmp eq i32 %.1, 0
  br i1 %.not33, label %._crit_edge.thread, label %.thread

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

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