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

; 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
@r = external dso_local global i32, align 4
@f = external dso_local global i32, align 4
@bfsVisited = external dso_local global [10000 x i8], align 16
@color = external dso_local global [10000 x i8], align 16

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

6:                                                ; preds = %43, %2
  %7 = load i32, ptr %5, align 4, !tbaa !5
  %8 = load i32, ptr %4, align 4, !tbaa !5
  %9 = icmp slt i32 %7, %8
  br i1 %9, label %11, label %10

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

11:                                               ; preds = %6
  %12 = load i32, ptr %3, align 4, !tbaa !5
  %13 = sext i32 %12 to i64
  %14 = getelementptr inbounds [10000 x [10000 x i32]], ptr @mat, i64 0, i64 %13
  %15 = load i32, ptr %5, align 4, !tbaa !5
  %16 = sext i32 %15 to i64
  %17 = getelementptr inbounds [10000 x i32], ptr %14, i64 0, i64 %16
  %18 = load i32, ptr %17, align 4, !tbaa !5
  %19 = icmp ne i32 %18, 0
  br i1 %19, label %20, label %42

20:                                               ; preds = %11
  %21 = load i32, ptr %5, align 4, !tbaa !5
  %22 = sext i32 %21 to i64
  %23 = getelementptr inbounds [10000 x i8], ptr @bfsVisited, i64 0, i64 %22
  %24 = load i8, ptr %23, align 1, !tbaa !9, !range !11, !noundef !12
  %25 = trunc i8 %24 to i1
  br i1 %25, label %42, label %26

26:                                               ; preds = %20
  %27 = load i32, ptr %5, align 4, !tbaa !5
  %28 = load i32, ptr @r, align 4, !tbaa !5
  %29 = add nsw i32 %28, 1
  store i32 %29, ptr @r, align 4, !tbaa !5
  %30 = sext i32 %29 to i64
  %31 = getelementptr inbounds [10000 x i32], ptr @bfsQ, i64 0, i64 %30
  store i32 %27, ptr %31, align 4, !tbaa !5
  %32 = load i32, ptr %3, align 4, !tbaa !5
  %33 = sext i32 %32 to i64
  %34 = getelementptr inbounds [10000 x i8], ptr @color, i64 0, i64 %33
  %35 = load i8, ptr %34, align 1, !tbaa !9, !range !11, !noundef !12
  %36 = trunc i8 %35 to i1
  %37 = xor i1 %36, true
  %38 = load i32, ptr %5, align 4, !tbaa !5
  %39 = sext i32 %38 to i64
  %40 = getelementptr inbounds [10000 x i8], ptr @color, i64 0, i64 %39
  %41 = zext i1 %37 to i8
  store i8 %41, ptr %40, align 1, !tbaa !9
  br label %42

42:                                               ; preds = %26, %20, %11
  br label %43

43:                                               ; preds = %42
  %44 = load i32, ptr %5, align 4, !tbaa !5
  %45 = add nsw i32 %44, 1
  store i32 %45, ptr %5, align 4, !tbaa !5
  br label %6, !llvm.loop !13

46:                                               ; preds = %10
  %47 = load i32, ptr @f, align 4, !tbaa !5
  %48 = load i32, ptr @r, align 4, !tbaa !5
  %49 = icmp sle i32 %47, %48
  br i1 %49, label %50, label %63

50:                                               ; preds = %46
  %51 = load i32, ptr @f, align 4, !tbaa !5
  %52 = sext i32 %51 to i64
  %53 = getelementptr inbounds [10000 x i32], ptr @bfsQ, i64 0, i64 %52
  %54 = load i32, ptr %53, align 4, !tbaa !5
  %55 = sext i32 %54 to i64
  %56 = getelementptr inbounds [10000 x i8], ptr @bfsVisited, i64 0, i64 %55
  store i8 1, ptr %56, align 1, !tbaa !9
  %57 = load i32, ptr @f, align 4, !tbaa !5
  %58 = add nsw i32 %57, 1
  store i32 %58, ptr @f, align 4, !tbaa !5
  %59 = sext i32 %57 to i64
  %60 = getelementptr inbounds [10000 x i32], ptr @bfsQ, i64 0, i64 %59
  %61 = load i32, ptr %60, align 4, !tbaa !5
  %62 = load i32, ptr %4, align 4, !tbaa !5
  call void @_Z7makeBFSii(i32 noundef %61, i32 noundef %62)
  br label %63

63:                                               ; preds = %50, %46
  ret void
}

; 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

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 = !{i8 0, i8 2}
!12 = !{}
!13 = distinct !{!13, !14}
!14 = !{!"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"

@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
@r = external dso_local local_unnamed_addr global i32, align 4
@f = external dso_local local_unnamed_addr global i32, align 4
@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 nofree norecurse nosync nounwind memory(readwrite, argmem: none, inaccessiblemem: none) uwtable
define dso_local void @_Z7makeBFSii(i32 noundef %0, i32 noundef %1) local_unnamed_addr #0 {
  %3 = icmp sgt i32 %1, 0
  %r.promoted15 = load i32, ptr @r, align 4, !tbaa !5
  %f.promoted = load i32, ptr @f, align 4, !tbaa !5
  br i1 %3, label %tailrecurse.us.preheader, label %.split

tailrecurse.us.preheader:                         ; preds = %2
  %4 = sext i32 %f.promoted to i64
  %wide.trip.count = zext nneg i32 %1 to i64
  br label %tailrecurse.us

tailrecurse.us:                                   ; preds = %tailrecurse.us.preheader, %7
  %indvars.iv28 = phi i64 [ %4, %tailrecurse.us.preheader ], [ %indvars.iv.next29, %7 ]
  %r.promoted19.us = phi i32 [ %r.promoted15, %tailrecurse.us.preheader ], [ %r.promoted17.us, %7 ]
  %.tr.us = phi i32 [ %0, %tailrecurse.us.preheader ], [ %9, %7 ]
  %5 = sext i32 %.tr.us to i64
  %6 = getelementptr inbounds [10000 x i8], ptr @color, i64 0, i64 %5
  br label %13

7:                                                ; preds = %._crit_edge.us
  %8 = getelementptr inbounds [10000 x i32], ptr @bfsQ, i64 0, i64 %indvars.iv28
  %9 = load i32, ptr %8, align 4, !tbaa !5
  %10 = sext i32 %9 to i64
  %11 = getelementptr inbounds [10000 x i8], ptr @bfsVisited, i64 0, i64 %10
  store i8 1, ptr %11, align 1, !tbaa !9
  %indvars.iv.next29 = add nsw i64 %indvars.iv28, 1
  %12 = trunc nsw i64 %indvars.iv.next29 to i32
  store i32 %12, ptr @f, align 4, !tbaa !5
  br label %tailrecurse.us

13:                                               ; preds = %tailrecurse.us, %29
  %indvars.iv24 = phi i64 [ 0, %tailrecurse.us ], [ %indvars.iv.next25, %29 ]
  %r.promoted18.us = phi i32 [ %r.promoted19.us, %tailrecurse.us ], [ %r.promoted17.us, %29 ]
  %14 = phi i32 [ %r.promoted19.us, %tailrecurse.us ], [ %30, %29 ]
  %15 = getelementptr inbounds [10000 x [10000 x i32]], ptr @mat, i64 0, i64 %5, i64 %indvars.iv24
  %16 = load i32, ptr %15, align 4, !tbaa !5
  %.not12.us = icmp eq i32 %16, 0
  br i1 %.not12.us, label %29, label %17

17:                                               ; preds = %13
  %18 = getelementptr inbounds [10000 x i8], ptr @bfsVisited, i64 0, i64 %indvars.iv24
  %19 = load i8, ptr %18, align 1, !tbaa !9, !range !11, !noundef !12
  %20 = trunc nuw i8 %19 to i1
  br i1 %20, label %29, label %21

21:                                               ; preds = %17
  %22 = add nsw i32 %14, 1
  store i32 %22, ptr @r, align 4, !tbaa !5
  %23 = sext i32 %22 to i64
  %24 = getelementptr inbounds [10000 x i32], ptr @bfsQ, i64 0, i64 %23
  %25 = trunc nuw nsw i64 %indvars.iv24 to i32
  store i32 %25, ptr %24, align 4, !tbaa !5
  %26 = load i8, ptr %6, align 1, !tbaa !9, !range !11, !noundef !12
  %27 = xor i8 %26, 1
  %28 = getelementptr inbounds [10000 x i8], ptr @color, i64 0, i64 %indvars.iv24
  store i8 %27, ptr %28, align 1, !tbaa !9
  br label %29

29:                                               ; preds = %21, %17, %13
  %r.promoted17.us = phi i32 [ %r.promoted18.us, %13 ], [ %r.promoted18.us, %17 ], [ %22, %21 ]
  %30 = phi i32 [ %14, %13 ], [ %14, %17 ], [ %22, %21 ]
  %indvars.iv.next25 = add nuw nsw i64 %indvars.iv24, 1
  %exitcond27.not = icmp eq i64 %indvars.iv.next25, %wide.trip.count
  br i1 %exitcond27.not, label %._crit_edge.us, label %13, !llvm.loop !13

._crit_edge.us:                                   ; preds = %29
  %31 = sext i32 %r.promoted17.us to i64
  %.not.us = icmp sgt i64 %indvars.iv28, %31
  br i1 %.not.us, label %.split21.us, label %7

.split:                                           ; preds = %2
  %.not22 = icmp sgt i32 %f.promoted, %r.promoted15
  br i1 %.not22, label %.split21.us, label %tailrecurse.preheader

tailrecurse.preheader:                            ; preds = %.split
  %32 = sext i32 %f.promoted to i64
  %33 = add i32 %r.promoted15, 1
  %34 = sub i32 %33, %f.promoted
  %35 = sub i32 %r.promoted15, %f.promoted
  %xtraiter = and i32 %34, 3
  %lcmp.mod.not = icmp eq i32 %xtraiter, 0
  br i1 %lcmp.mod.not, label %tailrecurse.prol.loopexit, label %tailrecurse.prol

tailrecurse.prol:                                 ; preds = %tailrecurse.preheader, %tailrecurse.prol
  %indvars.iv.prol = phi i64 [ %indvars.iv.next.prol, %tailrecurse.prol ], [ %32, %tailrecurse.preheader ]
  %prol.iter = phi i32 [ %prol.iter.next, %tailrecurse.prol ], [ 0, %tailrecurse.preheader ]
  %36 = getelementptr inbounds [10000 x i32], ptr @bfsQ, i64 0, i64 %indvars.iv.prol
  %37 = load i32, ptr %36, align 4, !tbaa !5
  %38 = sext i32 %37 to i64
  %39 = getelementptr inbounds [10000 x i8], ptr @bfsVisited, i64 0, i64 %38
  store i8 1, ptr %39, align 1, !tbaa !9
  %indvars.iv.next.prol = add nsw i64 %indvars.iv.prol, 1
  %prol.iter.next = add i32 %prol.iter, 1
  %prol.iter.cmp.not = icmp eq i32 %prol.iter.next, %xtraiter
  br i1 %prol.iter.cmp.not, label %tailrecurse.prol.loopexit, label %tailrecurse.prol, !llvm.loop !15

tailrecurse.prol.loopexit:                        ; preds = %tailrecurse.prol, %tailrecurse.preheader
  %indvars.iv.unr = phi i64 [ %32, %tailrecurse.preheader ], [ %indvars.iv.next.prol, %tailrecurse.prol ]
  %40 = icmp ult i32 %35, 3
  br i1 %40, label %tailrecurse..split21_crit_edge, label %tailrecurse

tailrecurse:                                      ; preds = %tailrecurse.prol.loopexit, %tailrecurse
  %indvars.iv = phi i64 [ %indvars.iv.next.3, %tailrecurse ], [ %indvars.iv.unr, %tailrecurse.prol.loopexit ]
  %41 = getelementptr inbounds [10000 x i32], ptr @bfsQ, i64 0, i64 %indvars.iv
  %42 = load i32, ptr %41, align 4, !tbaa !5
  %43 = sext i32 %42 to i64
  %44 = getelementptr inbounds [10000 x i8], ptr @bfsVisited, i64 0, i64 %43
  store i8 1, ptr %44, align 1, !tbaa !9
  %indvars.iv.next = add nsw i64 %indvars.iv, 1
  %45 = getelementptr inbounds [10000 x i32], ptr @bfsQ, i64 0, i64 %indvars.iv.next
  %46 = load i32, ptr %45, align 4, !tbaa !5
  %47 = sext i32 %46 to i64
  %48 = getelementptr inbounds [10000 x i8], ptr @bfsVisited, i64 0, i64 %47
  store i8 1, ptr %48, align 1, !tbaa !9
  %indvars.iv.next.1 = add nsw i64 %indvars.iv, 2
  %49 = getelementptr inbounds [10000 x i32], ptr @bfsQ, i64 0, i64 %indvars.iv.next.1
  %50 = load i32, ptr %49, align 4, !tbaa !5
  %51 = sext i32 %50 to i64
  %52 = getelementptr inbounds [10000 x i8], ptr @bfsVisited, i64 0, i64 %51
  store i8 1, ptr %52, align 1, !tbaa !9
  %indvars.iv.next.2 = add nsw i64 %indvars.iv, 3
  %53 = getelementptr inbounds [10000 x i32], ptr @bfsQ, i64 0, i64 %indvars.iv.next.2
  %54 = load i32, ptr %53, align 4, !tbaa !5
  %55 = sext i32 %54 to i64
  %56 = getelementptr inbounds [10000 x i8], ptr @bfsVisited, i64 0, i64 %55
  store i8 1, ptr %56, align 1, !tbaa !9
  %indvars.iv.next.3 = add nsw i64 %indvars.iv, 4
  %lftr.wideiv.3 = trunc i64 %indvars.iv.next.3 to i32
  %exitcond.not.3 = icmp eq i32 %33, %lftr.wideiv.3
  br i1 %exitcond.not.3, label %tailrecurse..split21_crit_edge, label %tailrecurse

tailrecurse..split21_crit_edge:                   ; preds = %tailrecurse, %tailrecurse.prol.loopexit
  store i32 %33, ptr @f, align 4, !tbaa !5
  br label %.split21.us

.split21.us:                                      ; preds = %._crit_edge.us, %.split, %tailrecurse..split21_crit_edge
  ret void
}

attributes #0 = { mustprogress nofree norecurse nosync nounwind memory(readwrite, argmem: none, inaccessiblemem: none) 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" }

!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, !16}
!16 = !{!"llvm.loop.unroll.disable"}


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