; LLVM IR from vmartinv/eldiego :: flow/dinic.ll (Z9dinic_dfsix)

; 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"

%"class.std::vector" = type { %"struct.std::_Vector_base" }
%"struct.std::_Vector_base" = type { %"struct.std::_Vector_base<Edge, std::allocator<Edge>>::_Vector_impl" }
%"struct.std::_Vector_base<Edge, std::allocator<Edge>>::_Vector_impl" = type { %"struct.std::_Vector_base<Edge, std::allocator<Edge>>::_Vector_impl_data" }
%"struct.std::_Vector_base<Edge, std::allocator<Edge>>::_Vector_impl_data" = type { ptr, ptr, ptr }
%struct.Edge = type { i32, i32, i64, i64 }

@dst = external dso_local global i32, align 4
@dist = external dso_local global [300 x i32], align 16
@work = external dso_local global [300 x i32], align 16
@G = external dso_local global [300 x %"class.std::vector"], 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: mustprogress nounwind uwtable
declare dso_local noundef i64 @_ZNKSt6vectorI4EdgeSaIS0_EE4sizeEv(ptr noundef nonnull align 8 dereferenceable(24)) #1 align 2

; 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 i64 @_Z9dinic_dfsix(i32 noundef %0, i64 noundef %1) #2 {
  %3 = alloca i64, align 8
  %4 = alloca i32, align 4
  %5 = alloca i64, align 8
  %6 = alloca ptr, align 8
  %7 = alloca i32, align 4
  %8 = alloca ptr, align 8
  %9 = alloca i32, align 4
  %10 = alloca i64, align 8
  %11 = alloca i64, align 8
  store i32 %0, ptr %4, align 4, !tbaa !5
  store i64 %1, ptr %5, align 8, !tbaa !9
  %12 = load i32, ptr %4, align 4, !tbaa !5
  %13 = load i32, ptr @dst, align 4, !tbaa !5
  %14 = icmp eq i32 %12, %13
  br i1 %14, label %15, label %17

15:                                               ; preds = %2
  %16 = load i64, ptr %5, align 8, !tbaa !9
  store i64 %16, ptr %3, align 8
  br label %110

17:                                               ; preds = %2
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #4
  %18 = load i32, ptr %4, align 4, !tbaa !5
  %19 = sext i32 %18 to i64
  %20 = getelementptr inbounds [300 x i32], ptr @work, i64 0, i64 %19
  store ptr %20, ptr %6, align 8, !tbaa !11
  br label %21

21:                                               ; preds = %103, %17
  %22 = load ptr, ptr %6, align 8, !tbaa !11
  %23 = load i32, ptr %22, align 4, !tbaa !5
  %24 = load i32, ptr %4, align 4, !tbaa !5
  %25 = sext i32 %24 to i64
  %26 = getelementptr inbounds [300 x %"class.std::vector"], ptr @G, i64 0, i64 %25
  %27 = call noundef i64 @_ZNKSt6vectorI4EdgeSaIS0_EE4sizeEv(ptr noundef nonnull align 8 dereferenceable(24) %26) #4
  %28 = trunc i64 %27 to i32
  %29 = icmp slt i32 %23, %28
  br i1 %29, label %31, label %30

30:                                               ; preds = %21
  store i32 2, ptr %7, align 4
  br label %107

31:                                               ; preds = %21
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #4
  %32 = load i32, ptr %4, align 4, !tbaa !5
  %33 = sext i32 %32 to i64
  %34 = getelementptr inbounds [300 x %"class.std::vector"], ptr @G, i64 0, i64 %33
  %35 = load ptr, ptr %6, align 8, !tbaa !11
  %36 = load i32, ptr %35, align 4, !tbaa !5
  %37 = sext i32 %36 to i64
  %38 = call noundef nonnull align 8 dereferenceable(24) ptr @_ZNSt6vectorI4EdgeSaIS0_EEixEm(ptr noundef nonnull align 8 dereferenceable(24) %34, i64 noundef %37) #4
  store ptr %38, ptr %8, align 8, !tbaa !11
  %39 = load ptr, ptr %8, align 8, !tbaa !11
  %40 = getelementptr inbounds %struct.Edge, ptr %39, i32 0, i32 3
  %41 = load i64, ptr %40, align 8, !tbaa !13
  %42 = load ptr, ptr %8, align 8, !tbaa !11
  %43 = getelementptr inbounds %struct.Edge, ptr %42, i32 0, i32 2
  %44 = load i64, ptr %43, align 8, !tbaa !15
  %45 = icmp sle i64 %41, %44
  br i1 %45, label %46, label %47

46:                                               ; preds = %31
  store i32 4, ptr %7, align 4
  br label %100

47:                                               ; preds = %31
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #4
  %48 = load ptr, ptr %8, align 8, !tbaa !11
  %49 = getelementptr inbounds %struct.Edge, ptr %48, i32 0, i32 0
  %50 = load i32, ptr %49, align 8, !tbaa !16
  store i32 %50, ptr %9, align 4, !tbaa !5
  %51 = load i32, ptr %9, align 4, !tbaa !5
  %52 = sext i32 %51 to i64
  %53 = getelementptr inbounds [300 x i32], ptr @dist, i64 0, i64 %52
  %54 = load i32, ptr %53, align 4, !tbaa !5
  %55 = load i32, ptr %4, align 4, !tbaa !5
  %56 = sext i32 %55 to i64
  %57 = getelementptr inbounds [300 x i32], ptr @dist, i64 0, i64 %56
  %58 = load i32, ptr %57, align 4, !tbaa !5
  %59 = add nsw i32 %58, 1
  %60 = icmp eq i32 %54, %59
  br i1 %60, label %61, label %98

61:                                               ; preds = %47
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #4
  %62 = load i32, ptr %9, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #4
  %63 = load ptr, ptr %8, align 8, !tbaa !11
  %64 = getelementptr inbounds %struct.Edge, ptr %63, i32 0, i32 3
  %65 = load i64, ptr %64, align 8, !tbaa !13
  %66 = load ptr, ptr %8, align 8, !tbaa !11
  %67 = getelementptr inbounds %struct.Edge, ptr %66, i32 0, i32 2
  %68 = load i64, ptr %67, align 8, !tbaa !15
  %69 = sub nsw i64 %65, %68
  store i64 %69, ptr %11, align 8, !tbaa !9
  %70 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZSt3minIxERKT_S2_S2_(ptr noundef nonnull align 8 dereferenceable(8) %5, ptr noundef nonnull align 8 dereferenceable(8) %11)
  %71 = load i64, ptr %70, align 8, !tbaa !9
  %72 = call noundef i64 @_Z9dinic_dfsix(i32 noundef %62, i64 noundef %71)
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #4
  store i64 %72, ptr %10, align 8, !tbaa !9
  %73 = load i64, ptr %10, align 8, !tbaa !9
  %74 = icmp sgt i64 %73, 0
  br i1 %74, label %75, label %94

75:                                               ; preds = %61
  %76 = load i64, ptr %10, align 8, !tbaa !9
  %77 = load ptr, ptr %8, align 8, !tbaa !11
  %78 = getelementptr inbounds %struct.Edge, ptr %77, i32 0, i32 2
  %79 = load i64, ptr %78, align 8, !tbaa !15
  %80 = add nsw i64 %79, %76
  store i64 %80, ptr %78, align 8, !tbaa !15
  %81 = load i64, ptr %10, align 8, !tbaa !9
  %82 = load i32, ptr %9, align 4, !tbaa !5
  %83 = sext i32 %82 to i64
  %84 = getelementptr inbounds [300 x %"class.std::vector"], ptr @G, i64 0, i64 %83
  %85 = load ptr, ptr %8, align 8, !tbaa !11
  %86 = getelementptr inbounds %struct.Edge, ptr %85, i32 0, i32 1
  %87 = load i32, ptr %86, align 4, !tbaa !17
  %88 = sext i32 %87 to i64
  %89 = call noundef nonnull align 8 dereferenceable(24) ptr @_ZNSt6vectorI4EdgeSaIS0_EEixEm(ptr noundef nonnull align 8 dereferenceable(24) %84, i64 noundef %88) #4
  %90 = getelementptr inbounds %struct.Edge, ptr %89, i32 0, i32 2
  %91 = load i64, ptr %90, align 8, !tbaa !15
  %92 = sub nsw i64 %91, %81
  store i64 %92, ptr %90, align 8, !tbaa !15
  %93 = load i64, ptr %10, align 8, !tbaa !9
  store i64 %93, ptr %3, align 8
  store i32 1, ptr %7, align 4
  br label %95

94:                                               ; preds = %61
  store i32 0, ptr %7, align 4
  br label %95

95:                                               ; preds = %94, %75
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #4
  %96 = load i32, ptr %7, align 4
  switch i32 %96, label %99 [
    i32 0, label %97
  ]

97:                                               ; preds = %95
  br label %98

98:                                               ; preds = %97, %47
  store i32 0, ptr %7, align 4
  br label %99

99:                                               ; preds = %98, %95
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #4
  br label %100

100:                                              ; preds = %99, %46
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #4
  %101 = load i32, ptr %7, align 4
  switch i32 %101, label %107 [
    i32 0, label %102
    i32 4, label %103
  ]

102:                                              ; preds = %100
  br label %103

103:                                              ; preds = %102, %100
  %104 = load ptr, ptr %6, align 8, !tbaa !11
  %105 = load i32, ptr %104, align 4, !tbaa !5
  %106 = add nsw i32 %105, 1
  store i32 %106, ptr %104, align 4, !tbaa !5
  br label %21, !llvm.loop !18

107:                                              ; preds = %100, %30
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #4
  %108 = load i32, ptr %7, align 4
  switch i32 %108, label %112 [
    i32 2, label %109
    i32 1, label %110
  ]

109:                                              ; preds = %107
  store i64 0, ptr %3, align 8
  br label %110

110:                                              ; preds = %109, %107, %15
  %111 = load i64, ptr %3, align 8
  ret i64 %111

112:                                              ; preds = %107
  unreachable
}

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef nonnull align 8 dereferenceable(24) ptr @_ZNSt6vectorI4EdgeSaIS0_EEixEm(ptr noundef nonnull align 8 dereferenceable(24), i64 noundef) #1 align 2

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef nonnull align 8 dereferenceable(8) ptr @_ZSt3minIxERKT_S2_S2_(ptr noundef nonnull align 8 dereferenceable(8), ptr noundef nonnull align 8 dereferenceable(8)) #3

attributes #0 = { 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 = { 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 #3 = { 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 #4 = { 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 = !{!"long long", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"any pointer", !7, i64 0}
!13 = !{!14, !10, i64 16}
!14 = !{!"_ZTS4Edge", !6, i64 0, !6, i64 4, !10, i64 8, !10, i64 16}
!15 = !{!14, !10, i64 8}
!16 = !{!14, !6, i64 0}
!17 = !{!14, !6, i64 4}
!18 = distinct !{!18, !19}
!19 = !{!"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"

%"class.std::vector" = type { %"struct.std::_Vector_base" }
%"struct.std::_Vector_base" = type { %"struct.std::_Vector_base<Edge, std::allocator<Edge>>::_Vector_impl" }
%"struct.std::_Vector_base<Edge, std::allocator<Edge>>::_Vector_impl" = type { %"struct.std::_Vector_base<Edge, std::allocator<Edge>>::_Vector_impl_data" }
%"struct.std::_Vector_base<Edge, std::allocator<Edge>>::_Vector_impl_data" = type { ptr, ptr, ptr }

@dst = external dso_local local_unnamed_addr global i32, align 4
@dist = external dso_local local_unnamed_addr global [300 x i32], align 16
@work = external dso_local local_unnamed_addr global [300 x i32], align 16
@G = external dso_local global [300 x %"class.std::vector"], 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 nounwind uwtable
declare dso_local noundef i64 @_ZNKSt6vectorI4EdgeSaIS0_EE4sizeEv(ptr noundef nonnull align 8 dereferenceable(24)) local_unnamed_addr #1 align 2

; 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 i64 @_Z9dinic_dfsix(i32 noundef %0, i64 noundef %1) local_unnamed_addr #1 {
  %3 = alloca i64, align 8
  %4 = alloca i64, align 8
  store i64 %1, ptr %3, align 8, !tbaa !5
  %5 = load i32, ptr @dst, align 4, !tbaa !9
  %6 = icmp eq i32 %5, %0
  br i1 %6, label %.loopexit, label %7

7:                                                ; preds = %2
  %8 = sext i32 %0 to i64
  %9 = getelementptr inbounds [300 x i32], ptr @work, i64 0, i64 %8
  %10 = getelementptr inbounds [300 x %"class.std::vector"], ptr @G, i64 0, i64 %8
  %11 = load i32, ptr %9, align 4, !tbaa !9
  %12 = tail call noundef i64 @_ZNKSt6vectorI4EdgeSaIS0_EE4sizeEv(ptr noundef nonnull align 8 dereferenceable(24) %10) #3
  %13 = trunc i64 %12 to i32
  %.not3843 = icmp slt i32 %11, %13
  br i1 %.not3843, label %.lr.ph, label %.loopexit

.lr.ph:                                           ; preds = %7
  %14 = getelementptr inbounds [300 x i32], ptr @dist, i64 0, i64 %8
  br label %15

15:                                               ; preds = %.lr.ph, %select.unfold
  %16 = load i32, ptr %9, align 4, !tbaa !9
  %17 = sext i32 %16 to i64
  %18 = call noundef nonnull align 8 dereferenceable(24) ptr @_ZNSt6vectorI4EdgeSaIS0_EEixEm(ptr noundef nonnull align 8 dereferenceable(24) %10, i64 noundef %17) #3
  %19 = getelementptr inbounds i8, ptr %18, i64 16
  %20 = load i64, ptr %19, align 8, !tbaa !11
  %21 = getelementptr inbounds i8, ptr %18, i64 8
  %22 = load i64, ptr %21, align 8, !tbaa !13
  %.not = icmp sgt i64 %20, %22
  br i1 %.not, label %23, label %select.unfold

23:                                               ; preds = %15
  %24 = load i32, ptr %18, align 8, !tbaa !14
  %25 = sext i32 %24 to i64
  %26 = getelementptr inbounds [300 x i32], ptr @dist, i64 0, i64 %25
  %27 = load i32, ptr %26, align 4, !tbaa !9
  %28 = load i32, ptr %14, align 4, !tbaa !9
  %29 = add nsw i32 %28, 1
  %30 = icmp eq i32 %27, %29
  br i1 %30, label %31, label %select.unfold

31:                                               ; preds = %23
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %4) #3
  %32 = sub nsw i64 %20, %22
  store i64 %32, ptr %4, align 8, !tbaa !5
  %33 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZSt3minIxERKT_S2_S2_(ptr noundef nonnull align 8 dereferenceable(8) %3, ptr noundef nonnull align 8 dereferenceable(8) %4)
  %34 = load i64, ptr %33, align 8, !tbaa !5
  %35 = call noundef i64 @_Z9dinic_dfsix(i32 noundef %24, i64 noundef %34)
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %4) #3
  %36 = icmp slt i64 %35, 1
  br i1 %36, label %select.unfold, label %37

37:                                               ; preds = %31
  %38 = getelementptr inbounds i8, ptr %18, i64 8
  %39 = load i64, ptr %38, align 8, !tbaa !13
  %40 = add nsw i64 %39, %35
  store i64 %40, ptr %38, align 8, !tbaa !13
  %41 = getelementptr inbounds [300 x %"class.std::vector"], ptr @G, i64 0, i64 %25
  %42 = getelementptr inbounds i8, ptr %18, i64 4
  %43 = load i32, ptr %42, align 4, !tbaa !15
  %44 = sext i32 %43 to i64
  %45 = call noundef nonnull align 8 dereferenceable(24) ptr @_ZNSt6vectorI4EdgeSaIS0_EEixEm(ptr noundef nonnull align 8 dereferenceable(24) %41, i64 noundef %44) #3
  %46 = getelementptr inbounds i8, ptr %45, i64 8
  %47 = load i64, ptr %46, align 8, !tbaa !13
  %48 = sub nsw i64 %47, %35
  store i64 %48, ptr %46, align 8, !tbaa !13
  br label %.loopexit

select.unfold:                                    ; preds = %31, %15, %23
  %49 = load i32, ptr %9, align 4, !tbaa !9
  %50 = add nsw i32 %49, 1
  store i32 %50, ptr %9, align 4, !tbaa !9
  %51 = call noundef i64 @_ZNKSt6vectorI4EdgeSaIS0_EE4sizeEv(ptr noundef nonnull align 8 dereferenceable(24) %10) #3
  %52 = trunc i64 %51 to i32
  %.not38 = icmp slt i32 %50, %52
  br i1 %.not38, label %15, label %.loopexit, !llvm.loop !16

.loopexit:                                        ; preds = %select.unfold, %7, %37, %2
  %.6 = phi i64 [ %1, %2 ], [ %35, %37 ], [ 0, %7 ], [ 0, %select.unfold ]
  ret i64 %.6
}

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef nonnull align 8 dereferenceable(24) ptr @_ZNSt6vectorI4EdgeSaIS0_EEixEm(ptr noundef nonnull align 8 dereferenceable(24), i64 noundef) local_unnamed_addr #1 align 2

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef nonnull align 8 dereferenceable(8) ptr @_ZSt3minIxERKT_S2_S2_(ptr noundef nonnull align 8 dereferenceable(8), ptr noundef nonnull align 8 dereferenceable(8)) 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 = !{!"long long", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = !{!12, !6, i64 16}
!12 = !{!"_ZTS4Edge", !10, i64 0, !10, i64 4, !6, i64 8, !6, i64 16}
!13 = !{!12, !6, i64 8}
!14 = !{!12, !10, i64 0}
!15 = !{!12, !10, i64 4}
!16 = distinct !{!16, !17}
!17 = !{!"llvm.loop.mustprogress"}


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