; LLVM IR from VastoLorde95/Competitive-Programming :: CodeChef/Other/DIBZ2016/DZ16SHOP/A.ll (Z24minCostBipartiteMatchingv)

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

@n = external dso_local global i32, align 4
@matchingCount = external dso_local global i32, align 4
@res = external dso_local global i64, align 8
@front = external dso_local global i32, align 4
@back = external dso_local global i32, align 4

; 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
declare dso_local void @_Z18dualInitializationv() #1

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_Z20primalInitializationv() #2

; Function Attrs: mustprogress uwtable
declare dso_local void @_Z18pathInitializationv() #1

; Function Attrs: mustprogress uwtable
declare dso_local void @_Z19labelingPropogationRi(ptr noundef nonnull align 4 dereferenceable(4)) #1

; Function Attrs: mustprogress uwtable
declare dso_local void @_Z13dualIterationv() #1

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_Z15primalIterationRi(ptr noundef nonnull align 4 dereferenceable(4)) #2

; Function Attrs: mustprogress uwtable
define dso_local noundef i64 @_Z24minCostBipartiteMatchingv() #1 {
  %1 = alloca i32, align 4
  call void @_Z18dualInitializationv()
  call void @_Z20primalInitializationv()
  br label %2

2:                                                ; preds = %26, %0
  %3 = load i32, ptr @matchingCount, align 4, !tbaa !5
  %4 = load i32, ptr @n, align 4, !tbaa !5
  %5 = icmp slt i32 %3, %4
  br i1 %5, label %6, label %27

6:                                                ; preds = %2
  call void @_Z18pathInitializationv()
  call void @llvm.lifetime.start.p0(i64 4, ptr %1) #3
  store i32 -1, ptr %1, align 4, !tbaa !5
  br label %7

7:                                                ; preds = %25, %6
  %8 = load i32, ptr %1, align 4, !tbaa !5
  %9 = icmp eq i32 %8, -1
  br i1 %9, label %10, label %26

10:                                               ; preds = %7
  br label %11

11:                                               ; preds = %20, %10
  %12 = load i32, ptr %1, align 4, !tbaa !5
  %13 = icmp eq i32 %12, -1
  br i1 %13, label %14, label %18

14:                                               ; preds = %11
  %15 = load i32, ptr @front, align 4, !tbaa !5
  %16 = load i32, ptr @back, align 4, !tbaa !5
  %17 = icmp slt i32 %15, %16
  br label %18

18:                                               ; preds = %14, %11
  %19 = phi i1 [ false, %11 ], [ %17, %14 ]
  br i1 %19, label %20, label %21

20:                                               ; preds = %18
  call void @_Z19labelingPropogationRi(ptr noundef nonnull align 4 dereferenceable(4) %1)
  br label %11, !llvm.loop !9

21:                                               ; preds = %18
  %22 = load i32, ptr %1, align 4, !tbaa !5
  %23 = icmp eq i32 %22, -1
  br i1 %23, label %24, label %25

24:                                               ; preds = %21
  call void @_Z13dualIterationv()
  br label %25

25:                                               ; preds = %24, %21
  br label %7, !llvm.loop !11

26:                                               ; preds = %7
  call void @_Z15primalIterationRi(ptr noundef nonnull align 4 dereferenceable(4) %1)
  call void @llvm.lifetime.end.p0(i64 4, ptr %1) #3
  br label %2, !llvm.loop !12

27:                                               ; preds = %2
  %28 = load i64, ptr @res, align 8, !tbaa !13
  ret i64 %28
}

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 = { 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 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}
!11 = distinct !{!11, !10}
!12 = distinct !{!12, !10}
!13 = !{!14, !14, i64 0}
!14 = !{!"long long", !7, i64 0}


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

@n = external dso_local local_unnamed_addr global i32, align 4
@matchingCount = external dso_local local_unnamed_addr global i32, align 4
@res = external dso_local local_unnamed_addr global i64, align 8
@front = external dso_local local_unnamed_addr global i32, align 4
@back = external dso_local local_unnamed_addr global i32, align 4

; 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 uwtable
declare dso_local void @_Z18dualInitializationv() local_unnamed_addr #1

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_Z20primalInitializationv() local_unnamed_addr #2

; Function Attrs: mustprogress uwtable
declare dso_local void @_Z18pathInitializationv() local_unnamed_addr #1

; Function Attrs: mustprogress uwtable
declare dso_local void @_Z19labelingPropogationRi(ptr noundef nonnull align 4 dereferenceable(4)) local_unnamed_addr #1

; Function Attrs: mustprogress uwtable
declare dso_local void @_Z13dualIterationv() local_unnamed_addr #1

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_Z15primalIterationRi(ptr noundef nonnull align 4 dereferenceable(4)) local_unnamed_addr #2

; Function Attrs: mustprogress uwtable
define dso_local noundef i64 @_Z24minCostBipartiteMatchingv() local_unnamed_addr #1 {
  %1 = alloca i32, align 4
  tail call void @_Z18dualInitializationv()
  tail call void @_Z20primalInitializationv()
  %2 = load i32, ptr @matchingCount, align 4, !tbaa !5
  %3 = load i32, ptr @n, align 4, !tbaa !5
  %4 = icmp slt i32 %2, %3
  br i1 %4, label %.lr.ph2, label %._crit_edge3

.lr.ph2:                                          ; preds = %0, %18
  call void @_Z18pathInitializationv()
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %1) #3
  store i32 -1, ptr %1, align 4, !tbaa !5
  %.pre5 = load i32, ptr @front, align 4
  %.pre7 = load i32, ptr @back, align 4
  br label %.preheader

.preheader:                                       ; preds = %.lr.ph2, %14
  %5 = phi i32 [ %.pre7, %.lr.ph2 ], [ %15, %14 ]
  %6 = phi i32 [ %.pre5, %.lr.ph2 ], [ %16, %14 ]
  %7 = icmp slt i32 %6, %5
  br i1 %7, label %.lr.ph, label %._crit_edge.thread

.lr.ph:                                           ; preds = %.preheader, %.lr.ph
  call void @_Z19labelingPropogationRi(ptr noundef nonnull align 4 dereferenceable(4) %1)
  %8 = load i32, ptr %1, align 4, !tbaa !5
  %9 = icmp eq i32 %8, -1
  %10 = load i32, ptr @front, align 4
  %11 = load i32, ptr @back, align 4
  %12 = icmp slt i32 %10, %11
  %13 = select i1 %9, i1 %12, i1 false
  br i1 %13, label %.lr.ph, label %._crit_edge, !llvm.loop !9

._crit_edge:                                      ; preds = %.lr.ph
  br i1 %9, label %._crit_edge.thread, label %14

._crit_edge.thread:                               ; preds = %.preheader, %._crit_edge
  call void @_Z13dualIterationv()
  %.pre = load i32, ptr @front, align 4
  %.pre6 = load i32, ptr @back, align 4
  %.pr.pre = load i32, ptr %1, align 4, !tbaa !5
  br label %14

14:                                               ; preds = %._crit_edge.thread, %._crit_edge
  %.pr = phi i32 [ %.pr.pre, %._crit_edge.thread ], [ %8, %._crit_edge ]
  %15 = phi i32 [ %.pre6, %._crit_edge.thread ], [ %11, %._crit_edge ]
  %16 = phi i32 [ %.pre, %._crit_edge.thread ], [ %10, %._crit_edge ]
  %17 = icmp eq i32 %.pr, -1
  br i1 %17, label %.preheader, label %18, !llvm.loop !11

18:                                               ; preds = %14
  call void @_Z15primalIterationRi(ptr noundef nonnull align 4 dereferenceable(4) %1)
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %1) #3
  %19 = load i32, ptr @matchingCount, align 4, !tbaa !5
  %20 = load i32, ptr @n, align 4, !tbaa !5
  %21 = icmp slt i32 %19, %20
  br i1 %21, label %.lr.ph2, label %._crit_edge3, !llvm.loop !12

._crit_edge3:                                     ; preds = %18, %0
  %22 = load i64, ptr @res, align 8, !tbaa !13
  ret i64 %22
}

attributes #0 = { mustprogress 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 = { 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 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}
!11 = distinct !{!11, !10}
!12 = distinct !{!12, !10}
!13 = !{!14, !14, i64 0}
!14 = !{!"long long", !7, i64 0}


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