; LLVM IR from ahampriyanshu/algo-ds-101 :: Algorithms/Graph/Hopcroft_Karp (Hopcroft_Karp_algorithm)

; 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.bipartiteGraph = type { i32, i32, ptr, ptr, ptr, ptr }

; Function Attrs: mustprogress uwtable
define dso_local noundef i32 @_ZN14bipartiteGraph12hopcroftKarpEv(ptr noundef nonnull align 8 dereferenceable(40) %0) #0 align 2 {
  %2 = alloca ptr, align 8
  %3 = alloca i32, align 4
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  store ptr %0, ptr %2, align 8, !tbaa !5
  %7 = load ptr, ptr %2, align 8
  %8 = getelementptr inbounds %class.bipartiteGraph, ptr %7, i32 0, i32 0
  %9 = load i32, ptr %8, align 8, !tbaa !9
  %10 = add nsw i32 %9, 1
  %11 = sext i32 %10 to i64
  %12 = call { i64, i1 } @llvm.umul.with.overflow.i64(i64 %11, i64 4)
  %13 = extractvalue { i64, i1 } %12, 1
  %14 = extractvalue { i64, i1 } %12, 0
  %15 = select i1 %13, i64 -1, i64 %14
  %16 = call noalias noundef nonnull ptr @_Znam(i64 noundef %15) #4
  %17 = getelementptr inbounds %class.bipartiteGraph, ptr %7, i32 0, i32 2
  store ptr %16, ptr %17, align 8, !tbaa !12
  %18 = getelementptr inbounds %class.bipartiteGraph, ptr %7, i32 0, i32 1
  %19 = load i32, ptr %18, align 4, !tbaa !13
  %20 = add nsw i32 %19, 1
  %21 = sext i32 %20 to i64
  %22 = call { i64, i1 } @llvm.umul.with.overflow.i64(i64 %21, i64 4)
  %23 = extractvalue { i64, i1 } %22, 1
  %24 = extractvalue { i64, i1 } %22, 0
  %25 = select i1 %23, i64 -1, i64 %24
  %26 = call noalias noundef nonnull ptr @_Znam(i64 noundef %25) #4
  %27 = getelementptr inbounds %class.bipartiteGraph, ptr %7, i32 0, i32 3
  store ptr %26, ptr %27, align 8, !tbaa !14
  %28 = getelementptr inbounds %class.bipartiteGraph, ptr %7, i32 0, i32 0
  %29 = load i32, ptr %28, align 8, !tbaa !9
  %30 = add nsw i32 %29, 1
  %31 = sext i32 %30 to i64
  %32 = call { i64, i1 } @llvm.umul.with.overflow.i64(i64 %31, i64 4)
  %33 = extractvalue { i64, i1 } %32, 1
  %34 = extractvalue { i64, i1 } %32, 0
  %35 = select i1 %33, i64 -1, i64 %34
  %36 = call noalias noundef nonnull ptr @_Znam(i64 noundef %35) #4
  %37 = getelementptr inbounds %class.bipartiteGraph, ptr %7, i32 0, i32 4
  store ptr %36, ptr %37, align 8, !tbaa !15
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #5
  store i32 0, ptr %3, align 4, !tbaa !16
  br label %38

38:                                               ; preds = %50, %1
  %39 = load i32, ptr %3, align 4, !tbaa !16
  %40 = getelementptr inbounds %class.bipartiteGraph, ptr %7, i32 0, i32 0
  %41 = load i32, ptr %40, align 8, !tbaa !9
  %42 = icmp sle i32 %39, %41
  br i1 %42, label %44, label %43

43:                                               ; preds = %38
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #5
  br label %53

44:                                               ; preds = %38
  %45 = getelementptr inbounds %class.bipartiteGraph, ptr %7, i32 0, i32 2
  %46 = load ptr, ptr %45, align 8, !tbaa !12
  %47 = load i32, ptr %3, align 4, !tbaa !16
  %48 = sext i32 %47 to i64
  %49 = getelementptr inbounds i32, ptr %46, i64 %48
  store i32 0, ptr %49, align 4, !tbaa !16
  br label %50

50:                                               ; preds = %44
  %51 = load i32, ptr %3, align 4, !tbaa !16
  %52 = add nsw i32 %51, 1
  store i32 %52, ptr %3, align 4, !tbaa !16
  br label %38, !llvm.loop !17

53:                                               ; preds = %43
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #5
  store i32 0, ptr %4, align 4, !tbaa !16
  br label %54

54:                                               ; preds = %66, %53
  %55 = load i32, ptr %4, align 4, !tbaa !16
  %56 = getelementptr inbounds %class.bipartiteGraph, ptr %7, i32 0, i32 1
  %57 = load i32, ptr %56, align 4, !tbaa !13
  %58 = icmp sle i32 %55, %57
  br i1 %58, label %60, label %59

59:                                               ; preds = %54
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #5
  br label %69

60:                                               ; preds = %54
  %61 = getelementptr inbounds %class.bipartiteGraph, ptr %7, i32 0, i32 3
  %62 = load ptr, ptr %61, align 8, !tbaa !14
  %63 = load i32, ptr %4, align 4, !tbaa !16
  %64 = sext i32 %63 to i64
  %65 = getelementptr inbounds i32, ptr %62, i64 %64
  store i32 0, ptr %65, align 4, !tbaa !16
  br label %66

66:                                               ; preds = %60
  %67 = load i32, ptr %4, align 4, !tbaa !16
  %68 = add nsw i32 %67, 1
  store i32 %68, ptr %4, align 4, !tbaa !16
  br label %54, !llvm.loop !19

69:                                               ; preds = %59
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #5
  store i32 0, ptr %5, align 4, !tbaa !16
  br label %70

70:                                               ; preds = %97, %69
  %71 = call noundef zeroext i1 @_ZN14bipartiteGraph3bfsEv(ptr noundef nonnull align 8 dereferenceable(40) %7)
  br i1 %71, label %72, label %98

72:                                               ; preds = %70
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #5
  store i32 1, ptr %6, align 4, !tbaa !16
  br label %73

73:                                               ; preds = %94, %72
  %74 = load i32, ptr %6, align 4, !tbaa !16
  %75 = getelementptr inbounds %class.bipartiteGraph, ptr %7, i32 0, i32 0
  %76 = load i32, ptr %75, align 8, !tbaa !9
  %77 = icmp sle i32 %74, %76
  br i1 %77, label %79, label %78

78:                                               ; preds = %73
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #5
  br label %97

79:                                               ; preds = %73
  %80 = getelementptr inbounds %class.bipartiteGraph, ptr %7, i32 0, i32 2
  %81 = load ptr, ptr %80, align 8, !tbaa !12
  %82 = load i32, ptr %6, align 4, !tbaa !16
  %83 = sext i32 %82 to i64
  %84 = getelementptr inbounds i32, ptr %81, i64 %83
  %85 = load i32, ptr %84, align 4, !tbaa !16
  %86 = icmp eq i32 %85, 0
  br i1 %86, label %87, label %93

87:                                               ; preds = %79
  %88 = load i32, ptr %6, align 4, !tbaa !16
  %89 = call noundef zeroext i1 @_ZN14bipartiteGraph3dfsEi(ptr noundef nonnull align 8 dereferenceable(40) %7, i32 noundef %88)
  br i1 %89, label %90, label %93

90:                                               ; preds = %87
  %91 = load i32, ptr %5, align 4, !tbaa !16
  %92 = add nsw i32 %91, 1
  store i32 %92, ptr %5, align 4, !tbaa !16
  br label %93

93:                                               ; preds = %90, %87, %79
  br label %94

94:                                               ; preds = %93
  %95 = load i32, ptr %6, align 4, !tbaa !16
  %96 = add nsw i32 %95, 1
  store i32 %96, ptr %6, align 4, !tbaa !16
  br label %73, !llvm.loop !20

97:                                               ; preds = %78
  br label %70, !llvm.loop !21

98:                                               ; preds = %70
  %99 = load i32, ptr %5, align 4, !tbaa !16
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #5
  ret i32 %99
}

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare { i64, i1 } @llvm.umul.with.overflow.i64(i64, i64) #1

; Function Attrs: nobuiltin allocsize(0)
declare noundef nonnull ptr @_Znam(i64 noundef) #2

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #3

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #3

; Function Attrs: mustprogress uwtable
declare dso_local noundef zeroext i1 @_ZN14bipartiteGraph3bfsEv(ptr noundef nonnull align 8 dereferenceable(40)) #0 align 2

; Function Attrs: mustprogress uwtable
declare dso_local noundef zeroext i1 @_ZN14bipartiteGraph3dfsEi(ptr noundef nonnull align 8 dereferenceable(40), i32 noundef) #0 align 2

attributes #0 = { 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 #1 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #2 = { nobuiltin allocsize(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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #4 = { builtin allocsize(0) }
attributes #5 = { 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 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !11, i64 0}
!10 = !{!"_ZTS14bipartiteGraph", !11, i64 0, !11, i64 4, !6, i64 8, !6, i64 16, !6, i64 24, !6, i64 32}
!11 = !{!"int", !7, i64 0}
!12 = !{!10, !6, i64 8}
!13 = !{!10, !11, i64 4}
!14 = !{!10, !6, i64 16}
!15 = !{!10, !6, i64 24}
!16 = !{!11, !11, i64 0}
!17 = distinct !{!17, !18}
!18 = !{!"llvm.loop.mustprogress"}
!19 = distinct !{!19, !18}
!20 = distinct !{!20, !18}
!21 = distinct !{!21, !18}


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

; Function Attrs: mustprogress uwtable
define dso_local noundef i32 @_ZN14bipartiteGraph12hopcroftKarpEv(ptr noundef nonnull align 8 dereferenceable(40) %0) local_unnamed_addr #0 align 2 {
  %2 = load i32, ptr %0, align 8, !tbaa !5
  %3 = add i32 %2, 1
  %4 = sext i32 %3 to i64
  %5 = icmp slt i32 %2, -1
  %6 = shl nsw i64 %4, 2
  %7 = select i1 %5, i64 -1, i64 %6
  %8 = tail call noalias noundef nonnull ptr @_Znam(i64 noundef %7) #3
  %9 = getelementptr inbounds i8, ptr %0, i64 8
  store ptr %8, ptr %9, align 8, !tbaa !11
  %10 = getelementptr inbounds i8, ptr %0, i64 4
  %11 = load i32, ptr %10, align 4, !tbaa !12
  %12 = add i32 %11, 1
  %13 = sext i32 %12 to i64
  %14 = icmp slt i32 %11, -1
  %15 = shl nsw i64 %13, 2
  %16 = select i1 %14, i64 -1, i64 %15
  %17 = tail call noalias noundef nonnull ptr @_Znam(i64 noundef %16) #3
  %18 = getelementptr inbounds i8, ptr %0, i64 16
  store ptr %17, ptr %18, align 8, !tbaa !13
  %19 = tail call noalias noundef nonnull ptr @_Znam(i64 noundef %7) #3
  %20 = getelementptr inbounds i8, ptr %0, i64 24
  store ptr %19, ptr %20, align 8, !tbaa !14
  %.not19 = icmp slt i32 %2, 0
  br i1 %.not19, label %.preheader18, label %.lr.ph.preheader

.lr.ph.preheader:                                 ; preds = %1
  %21 = zext i32 %3 to i64
  %22 = shl nuw nsw i64 %21, 2
  tail call void @llvm.memset.p0.i64(ptr nonnull align 4 %8, i8 0, i64 %22, i1 false), !tbaa !15
  br label %.preheader18

.preheader18:                                     ; preds = %.lr.ph.preheader, %1
  %.not1521 = icmp slt i32 %11, 0
  br i1 %.not1521, label %.preheader17, label %.lr.ph23.preheader

.lr.ph23.preheader:                               ; preds = %.preheader18
  %23 = zext i32 %12 to i64
  %24 = shl nuw nsw i64 %23, 2
  tail call void @llvm.memset.p0.i64(ptr nonnull align 4 %17, i8 0, i64 %24, i1 false), !tbaa !15
  br label %.preheader17

.preheader17:                                     ; preds = %.lr.ph23.preheader, %.preheader18
  %25 = tail call noundef zeroext i1 @_ZN14bipartiteGraph3bfsEv(ptr noundef nonnull align 8 dereferenceable(40) %0)
  br i1 %25, label %.preheader, label %._crit_edge

.loopexit:                                        ; preds = %37, %.preheader
  %.1.lcssa = phi i32 [ %.01228, %.preheader ], [ %.2, %37 ]
  %26 = tail call noundef zeroext i1 @_ZN14bipartiteGraph3bfsEv(ptr noundef nonnull align 8 dereferenceable(40) %0)
  br i1 %26, label %.preheader, label %._crit_edge, !llvm.loop !16

.preheader:                                       ; preds = %.preheader17, %.loopexit
  %.01228 = phi i32 [ %.1.lcssa, %.loopexit ], [ 0, %.preheader17 ]
  %27 = load i32, ptr %0, align 8, !tbaa !5
  %.not1624 = icmp slt i32 %27, 1
  br i1 %.not1624, label %.loopexit, label %.lr.ph27

.lr.ph27:                                         ; preds = %.preheader, %37
  %28 = phi i32 [ %38, %37 ], [ %27, %.preheader ]
  %indvars.iv = phi i64 [ %indvars.iv.next, %37 ], [ 1, %.preheader ]
  %.125 = phi i32 [ %.2, %37 ], [ %.01228, %.preheader ]
  %29 = load ptr, ptr %9, align 8, !tbaa !11
  %30 = getelementptr inbounds i32, ptr %29, i64 %indvars.iv
  %31 = load i32, ptr %30, align 4, !tbaa !15
  %32 = icmp eq i32 %31, 0
  br i1 %32, label %33, label %37

33:                                               ; preds = %.lr.ph27
  %34 = trunc nuw nsw i64 %indvars.iv to i32
  %35 = tail call noundef zeroext i1 @_ZN14bipartiteGraph3dfsEi(ptr noundef nonnull align 8 dereferenceable(40) %0, i32 noundef %34)
  %36 = zext i1 %35 to i32
  %spec.select = add nsw i32 %.125, %36
  %.pre = load i32, ptr %0, align 8, !tbaa !5
  br label %37

37:                                               ; preds = %33, %.lr.ph27
  %38 = phi i32 [ %28, %.lr.ph27 ], [ %.pre, %33 ]
  %.2 = phi i32 [ %.125, %.lr.ph27 ], [ %spec.select, %33 ]
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %39 = sext i32 %38 to i64
  %.not16.not = icmp slt i64 %indvars.iv, %39
  br i1 %.not16.not, label %.lr.ph27, label %.loopexit, !llvm.loop !18

._crit_edge:                                      ; preds = %.loopexit, %.preheader17
  %.012.lcssa = phi i32 [ 0, %.preheader17 ], [ %.1.lcssa, %.loopexit ]
  ret i32 %.012.lcssa
}

; Function Attrs: nobuiltin allocsize(0)
declare noundef nonnull ptr @_Znam(i64 noundef) local_unnamed_addr #1

; Function Attrs: mustprogress uwtable
declare dso_local noundef zeroext i1 @_ZN14bipartiteGraph3bfsEv(ptr noundef nonnull align 8 dereferenceable(40)) local_unnamed_addr #0 align 2

; Function Attrs: mustprogress uwtable
declare dso_local noundef zeroext i1 @_ZN14bipartiteGraph3dfsEi(ptr noundef nonnull align 8 dereferenceable(40), i32 noundef) local_unnamed_addr #0 align 2

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #2

attributes #0 = { 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 #1 = { nobuiltin allocsize(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 = { nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #3 = { builtin allocsize(0) }

!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, !7, i64 0}
!6 = !{!"_ZTS14bipartiteGraph", !7, i64 0, !7, i64 4, !10, i64 8, !10, i64 16, !10, i64 24, !10, i64 32}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}
!10 = !{!"any pointer", !8, i64 0}
!11 = !{!6, !10, i64 8}
!12 = !{!6, !7, i64 4}
!13 = !{!6, !10, i64 16}
!14 = !{!6, !10, i64 24}
!15 = !{!7, !7, i64 0}
!16 = distinct !{!16, !17}
!17 = !{!"llvm.loop.mustprogress"}
!18 = distinct !{!18, !17}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LICMPass,LoopIdiomRecognizePass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass