; LLVM IR from VAR-solutions/Algorithms :: Graphs/check bipartite/cpp/CheckBipartite.ll (Z14checkBipartitei)

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

@mat = external dso_local global [10000 x [10000 x i32]], align 16
@bfsQ = external dso_local global [10000 x i32], align 16
@bfsVisited = external dso_local global [10000 x i8], align 16
@color = external dso_local global [10000 x i8], align 16

; Function Attrs: mustprogress uwtable
declare dso_local void @_Z7makeBFSii(i32 noundef, i32 noundef) #0

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

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

; Function Attrs: mustprogress uwtable
define dso_local noundef zeroext i1 @_Z14checkBipartitei(i32 noundef %0) #0 {
  %2 = alloca i32, align 4
  %3 = alloca i8, align 1
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  store i32 %0, ptr %2, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 1, ptr %3) #2
  store i8 1, ptr %3, align 1, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #2
  store i32 0, ptr %4, align 4, !tbaa !5
  br label %8

8:                                                ; preds = %18, %1
  %9 = load i32, ptr %4, align 4, !tbaa !5
  %10 = icmp slt i32 %9, 10000
  br i1 %10, label %11, label %21

11:                                               ; preds = %8
  %12 = load i32, ptr %4, align 4, !tbaa !5
  %13 = sext i32 %12 to i64
  %14 = getelementptr inbounds [10000 x i32], ptr @bfsQ, i64 0, i64 %13
  store i32 0, ptr %14, align 4, !tbaa !5
  %15 = load i32, ptr %4, align 4, !tbaa !5
  %16 = sext i32 %15 to i64
  %17 = getelementptr inbounds [10000 x i8], ptr @bfsVisited, i64 0, i64 %16
  store i8 0, ptr %17, align 1, !tbaa !9
  br label %18

18:                                               ; preds = %11
  %19 = load i32, ptr %4, align 4, !tbaa !5
  %20 = add nsw i32 %19, 1
  store i32 %20, ptr %4, align 4, !tbaa !5
  br label %8, !llvm.loop !11

21:                                               ; preds = %8
  store i8 1, ptr @color, align 16, !tbaa !9
  %22 = load i32, ptr %2, align 4, !tbaa !5
  call void @_Z7makeBFSii(i32 noundef 0, i32 noundef %22)
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #2
  store i32 0, ptr %5, align 4, !tbaa !5
  br label %23

23:                                               ; preds = %64, %21
  %24 = load i32, ptr %5, align 4, !tbaa !5
  %25 = load i32, ptr %2, align 4, !tbaa !5
  %26 = icmp slt i32 %24, %25
  br i1 %26, label %28, label %27

27:                                               ; preds = %23
  store i32 5, ptr %6, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #2
  br label %67

28:                                               ; preds = %23
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #2
  store i32 0, ptr %7, align 4, !tbaa !5
  br label %29

29:                                               ; preds = %59, %28
  %30 = load i32, ptr %7, align 4, !tbaa !5
  %31 = load i32, ptr %2, align 4, !tbaa !5
  %32 = icmp slt i32 %30, %31
  br i1 %32, label %34, label %33

33:                                               ; preds = %29
  store i32 8, ptr %6, align 4
  br label %62

34:                                               ; preds = %29
  %35 = load i32, ptr %5, align 4, !tbaa !5
  %36 = sext i32 %35 to i64
  %37 = getelementptr inbounds [10000 x [10000 x i32]], ptr @mat, i64 0, i64 %36
  %38 = load i32, ptr %7, align 4, !tbaa !5
  %39 = sext i32 %38 to i64
  %40 = getelementptr inbounds [10000 x i32], ptr %37, i64 0, i64 %39
  %41 = load i32, ptr %40, align 4, !tbaa !5
  %42 = icmp eq i32 %41, 1
  br i1 %42, label %43, label %58

43:                                               ; preds = %34
  %44 = load i32, ptr %5, align 4, !tbaa !5
  %45 = sext i32 %44 to i64
  %46 = getelementptr inbounds [10000 x i8], ptr @color, i64 0, i64 %45
  %47 = load i8, ptr %46, align 1, !tbaa !9, !range !13, !noundef !14
  %48 = trunc i8 %47 to i1
  %49 = zext i1 %48 to i32
  %50 = load i32, ptr %7, align 4, !tbaa !5
  %51 = sext i32 %50 to i64
  %52 = getelementptr inbounds [10000 x i8], ptr @color, i64 0, i64 %51
  %53 = load i8, ptr %52, align 1, !tbaa !9, !range !13, !noundef !14
  %54 = trunc i8 %53 to i1
  %55 = zext i1 %54 to i32
  %56 = icmp eq i32 %49, %55
  br i1 %56, label %57, label %58

57:                                               ; preds = %43
  store i8 0, ptr %3, align 1, !tbaa !9
  store i32 8, ptr %6, align 4
  br label %62

58:                                               ; preds = %43, %34
  br label %59

59:                                               ; preds = %58
  %60 = load i32, ptr %7, align 4, !tbaa !5
  %61 = add nsw i32 %60, 1
  store i32 %61, ptr %7, align 4, !tbaa !5
  br label %29, !llvm.loop !15

62:                                               ; preds = %57, %33
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #2
  br label %63

63:                                               ; preds = %62
  br label %64

64:                                               ; preds = %63
  %65 = load i32, ptr %5, align 4, !tbaa !5
  %66 = add nsw i32 %65, 1
  store i32 %66, ptr %5, align 4, !tbaa !5
  br label %23, !llvm.loop !16

67:                                               ; preds = %27
  %68 = load i8, ptr %3, align 1, !tbaa !9, !range !13, !noundef !14
  %69 = trunc i8 %68 to i1
  store i32 1, ptr %6, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #2
  call void @llvm.lifetime.end.p0(i64 1, ptr %3) #2
  ret i1 %69
}

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 willreturn memory(argmem: readwrite) }
attributes #2 = { 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 = !{!"bool", !7, i64 0}
!11 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}
!13 = !{i8 0, i8 2}
!14 = !{}
!15 = distinct !{!15, !12}
!16 = distinct !{!16, !12}


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

@mat = external dso_local local_unnamed_addr global [10000 x [10000 x i32]], align 16
@bfsQ = external dso_local local_unnamed_addr global [10000 x i32], align 16
@bfsVisited = external dso_local local_unnamed_addr global [10000 x i8], align 16
@color = external dso_local local_unnamed_addr global [10000 x i8], align 16

; Function Attrs: mustprogress uwtable
declare dso_local void @_Z7makeBFSii(i32 noundef, i32 noundef) local_unnamed_addr #0

; Function Attrs: mustprogress uwtable
define dso_local noundef zeroext i1 @_Z14checkBipartitei(i32 noundef %0) local_unnamed_addr #0 {
  tail call void @llvm.memset.p0.i64(ptr noundef nonnull align 16 dereferenceable(40000) @bfsQ, i8 0, i64 40000, i1 false), !tbaa !5
  tail call void @llvm.memset.p0.i64(ptr noundef nonnull align 16 dereferenceable(10000) @bfsVisited, i8 0, i64 10000, i1 false), !tbaa !9
  store i8 1, ptr @color, align 16, !tbaa !9
  tail call void @_Z7makeBFSii(i32 noundef 0, i32 noundef %0)
  %2 = icmp sgt i32 %0, 0
  br i1 %2, label %.preheader.us.preheader, label %._crit_edge26

.preheader.us.preheader:                          ; preds = %1
  %wide.trip.count31 = zext nneg i32 %0 to i64
  %xtraiter = and i64 %wide.trip.count31, 1
  %3 = icmp eq i32 %0, 1
  br i1 %3, label %._crit_edge26.loopexit.unr-lcssa, label %.preheader.us.preheader.new

.preheader.us.preheader.new:                      ; preds = %.preheader.us.preheader
  %unroll_iter = and i64 %wide.trip.count31, 2147483646
  br label %.preheader.us

.preheader.us:                                    ; preds = %._crit_edge.us.1, %.preheader.us.preheader.new
  %indvars.iv29 = phi i64 [ 0, %.preheader.us.preheader.new ], [ %indvars.iv.next30.1, %._crit_edge.us.1 ]
  %.01824.us = phi i1 [ true, %.preheader.us.preheader.new ], [ %.1.us.1, %._crit_edge.us.1 ]
  %niter = phi i64 [ 0, %.preheader.us.preheader.new ], [ %niter.next.1, %._crit_edge.us.1 ]
  %4 = getelementptr inbounds [10000 x i8], ptr @color, i64 0, i64 %indvars.iv29
  br label %5

5:                                                ; preds = %.preheader.us, %14
  %indvars.iv = phi i64 [ 0, %.preheader.us ], [ %indvars.iv.next, %14 ]
  %6 = getelementptr inbounds [10000 x [10000 x i32]], ptr @mat, i64 0, i64 %indvars.iv29, i64 %indvars.iv
  %7 = load i32, ptr %6, align 4, !tbaa !5
  %8 = icmp eq i32 %7, 1
  br i1 %8, label %9, label %14

9:                                                ; preds = %5
  %10 = load i8, ptr %4, align 2, !tbaa !9, !range !11, !noundef !12
  %11 = getelementptr inbounds [10000 x i8], ptr @color, i64 0, i64 %indvars.iv
  %12 = load i8, ptr %11, align 1, !tbaa !9, !range !11, !noundef !12
  %13 = icmp eq i8 %10, %12
  br i1 %13, label %._crit_edge.us, label %14

14:                                               ; preds = %9, %5
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %exitcond.not = icmp eq i64 %indvars.iv.next, %wide.trip.count31
  br i1 %exitcond.not, label %._crit_edge.us, label %5, !llvm.loop !13

._crit_edge.us:                                   ; preds = %14, %9
  %.1.us = phi i1 [ false, %9 ], [ %.01824.us, %14 ]
  %indvars.iv.next30 = or disjoint i64 %indvars.iv29, 1
  %15 = getelementptr inbounds [10000 x i8], ptr @color, i64 0, i64 %indvars.iv.next30
  br label %16

16:                                               ; preds = %25, %._crit_edge.us
  %indvars.iv.1 = phi i64 [ 0, %._crit_edge.us ], [ %indvars.iv.next.1, %25 ]
  %17 = getelementptr inbounds [10000 x [10000 x i32]], ptr @mat, i64 0, i64 %indvars.iv.next30, i64 %indvars.iv.1
  %18 = load i32, ptr %17, align 4, !tbaa !5
  %19 = icmp eq i32 %18, 1
  br i1 %19, label %20, label %25

20:                                               ; preds = %16
  %21 = load i8, ptr %15, align 1, !tbaa !9, !range !11, !noundef !12
  %22 = getelementptr inbounds [10000 x i8], ptr @color, i64 0, i64 %indvars.iv.1
  %23 = load i8, ptr %22, align 1, !tbaa !9, !range !11, !noundef !12
  %24 = icmp eq i8 %21, %23
  br i1 %24, label %._crit_edge.us.1, label %25

25:                                               ; preds = %20, %16
  %indvars.iv.next.1 = add nuw nsw i64 %indvars.iv.1, 1
  %exitcond.not.1 = icmp eq i64 %indvars.iv.next.1, %wide.trip.count31
  br i1 %exitcond.not.1, label %._crit_edge.us.1, label %16, !llvm.loop !13

._crit_edge.us.1:                                 ; preds = %25, %20
  %.1.us.1 = phi i1 [ false, %20 ], [ %.1.us, %25 ]
  %indvars.iv.next30.1 = add nuw nsw i64 %indvars.iv29, 2
  %niter.next.1 = add i64 %niter, 2
  %niter.ncmp.1 = icmp eq i64 %niter.next.1, %unroll_iter
  br i1 %niter.ncmp.1, label %._crit_edge26.loopexit.unr-lcssa, label %.preheader.us, !llvm.loop !15

._crit_edge26.loopexit.unr-lcssa:                 ; preds = %._crit_edge.us.1, %.preheader.us.preheader
  %.1.us.lcssa.ph = phi i1 [ poison, %.preheader.us.preheader ], [ %.1.us.1, %._crit_edge.us.1 ]
  %indvars.iv29.unr = phi i64 [ 0, %.preheader.us.preheader ], [ %indvars.iv.next30.1, %._crit_edge.us.1 ]
  %.01824.us.unr = phi i1 [ true, %.preheader.us.preheader ], [ %.1.us.1, %._crit_edge.us.1 ]
  %lcmp.mod.not = icmp eq i64 %xtraiter, 0
  br i1 %lcmp.mod.not, label %._crit_edge26, label %.preheader.us.epil

.preheader.us.epil:                               ; preds = %._crit_edge26.loopexit.unr-lcssa
  %26 = getelementptr inbounds [10000 x i8], ptr @color, i64 0, i64 %indvars.iv29.unr
  br label %27

27:                                               ; preds = %36, %.preheader.us.epil
  %indvars.iv.epil = phi i64 [ 0, %.preheader.us.epil ], [ %indvars.iv.next.epil, %36 ]
  %28 = getelementptr inbounds [10000 x [10000 x i32]], ptr @mat, i64 0, i64 %indvars.iv29.unr, i64 %indvars.iv.epil
  %29 = load i32, ptr %28, align 4, !tbaa !5
  %30 = icmp eq i32 %29, 1
  br i1 %30, label %31, label %36

31:                                               ; preds = %27
  %32 = load i8, ptr %26, align 1, !tbaa !9, !range !11, !noundef !12
  %33 = getelementptr inbounds [10000 x i8], ptr @color, i64 0, i64 %indvars.iv.epil
  %34 = load i8, ptr %33, align 1, !tbaa !9, !range !11, !noundef !12
  %35 = icmp eq i8 %32, %34
  br i1 %35, label %._crit_edge26, label %36

36:                                               ; preds = %31, %27
  %indvars.iv.next.epil = add nuw nsw i64 %indvars.iv.epil, 1
  %exitcond.not.epil = icmp eq i64 %indvars.iv.next.epil, %wide.trip.count31
  br i1 %exitcond.not.epil, label %._crit_edge26, label %27, !llvm.loop !13

._crit_edge26:                                    ; preds = %._crit_edge26.loopexit.unr-lcssa, %36, %31, %1
  %.018.lcssa = phi i1 [ true, %1 ], [ %.1.us.lcssa.ph, %._crit_edge26.loopexit.unr-lcssa ], [ false, %31 ], [ %.01824.us.unr, %36 ]
  ret i1 %.018.lcssa
}

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

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 nounwind willreturn memory(argmem: write) }

!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 = !{!"bool", !7, i64 0}
!11 = !{i8 0, i8 2}
!12 = !{}
!13 = distinct !{!13, !14}
!14 = !{!"llvm.loop.mustprogress"}
!15 = distinct !{!15, !14}


; Effective O3 passes: AggressiveInstCombinePass,EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferAlignmentPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LICMPass,LoopIdiomRecognizePass,LoopInstSimplifyPass,LoopRotatePass,LoopSimplifyCFGPass,LoopSimplifyPass,LoopUnrollPass,SROAPass,SimplifyCFGPass,TailCallElimPass