; LLVM IR from HarshCasper/NeoAlgo :: C-Plus-Plus/graphs/FloodFill.ll (Z12floodFillBFSPA10_ciicc)

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

@row = external dso_local global [8 x i32], align 16
@col = external dso_local global [8 x i32], align 16

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef zeroext i1 @_Z4safePA10_ciic(ptr noundef, i32 noundef, i32 noundef, i8 noundef signext) #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 void @_Z12floodFillBFSPA10_ciicc(ptr noundef %0, i32 noundef %1, i32 noundef %2, i8 noundef signext %3, i8 noundef signext %4) #2 {
  %6 = alloca ptr, align 8
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  %9 = alloca i8, align 1
  %10 = alloca i8, align 1
  %11 = alloca i32, align 4
  store ptr %0, ptr %6, align 8, !tbaa !5
  store i32 %1, ptr %7, align 4, !tbaa !9
  store i32 %2, ptr %8, align 4, !tbaa !9
  store i8 %3, ptr %9, align 1, !tbaa !11
  store i8 %4, ptr %10, align 1, !tbaa !11
  %12 = load i8, ptr %10, align 1, !tbaa !11
  %13 = load ptr, ptr %6, align 8, !tbaa !5
  %14 = load i32, ptr %7, align 4, !tbaa !9
  %15 = sext i32 %14 to i64
  %16 = getelementptr inbounds [10 x i8], ptr %13, i64 %15
  %17 = load i32, ptr %8, align 4, !tbaa !9
  %18 = sext i32 %17 to i64
  %19 = getelementptr inbounds [10 x i8], ptr %16, i64 0, i64 %18
  store i8 %12, ptr %19, align 1, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #3
  store i32 0, ptr %11, align 4, !tbaa !9
  br label %20

20:                                               ; preds = %57, %5
  %21 = load i32, ptr %11, align 4, !tbaa !9
  %22 = icmp slt i32 %21, 8
  br i1 %22, label %24, label %23

23:                                               ; preds = %20
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #3
  br label %60

24:                                               ; preds = %20
  %25 = load ptr, ptr %6, align 8, !tbaa !5
  %26 = load i32, ptr %7, align 4, !tbaa !9
  %27 = load i32, ptr %11, align 4, !tbaa !9
  %28 = sext i32 %27 to i64
  %29 = getelementptr inbounds [8 x i32], ptr @row, i64 0, i64 %28
  %30 = load i32, ptr %29, align 4, !tbaa !9
  %31 = add nsw i32 %26, %30
  %32 = load i32, ptr %8, align 4, !tbaa !9
  %33 = load i32, ptr %11, align 4, !tbaa !9
  %34 = sext i32 %33 to i64
  %35 = getelementptr inbounds [8 x i32], ptr @col, i64 0, i64 %34
  %36 = load i32, ptr %35, align 4, !tbaa !9
  %37 = add nsw i32 %32, %36
  %38 = load i8, ptr %9, align 1, !tbaa !11
  %39 = call noundef zeroext i1 @_Z4safePA10_ciic(ptr noundef %25, i32 noundef %31, i32 noundef %37, i8 noundef signext %38)
  br i1 %39, label %40, label %56

40:                                               ; preds = %24
  %41 = load ptr, ptr %6, align 8, !tbaa !5
  %42 = load i32, ptr %7, align 4, !tbaa !9
  %43 = load i32, ptr %11, align 4, !tbaa !9
  %44 = sext i32 %43 to i64
  %45 = getelementptr inbounds [8 x i32], ptr @row, i64 0, i64 %44
  %46 = load i32, ptr %45, align 4, !tbaa !9
  %47 = add nsw i32 %42, %46
  %48 = load i32, ptr %8, align 4, !tbaa !9
  %49 = load i32, ptr %11, align 4, !tbaa !9
  %50 = sext i32 %49 to i64
  %51 = getelementptr inbounds [8 x i32], ptr @col, i64 0, i64 %50
  %52 = load i32, ptr %51, align 4, !tbaa !9
  %53 = add nsw i32 %48, %52
  %54 = load i8, ptr %9, align 1, !tbaa !11
  %55 = load i8, ptr %10, align 1, !tbaa !11
  call void @_Z12floodFillBFSPA10_ciicc(ptr noundef %41, i32 noundef %47, i32 noundef %53, i8 noundef signext %54, i8 noundef signext %55)
  br label %56

56:                                               ; preds = %40, %24
  br label %57

57:                                               ; preds = %56
  %58 = load i32, ptr %11, align 4, !tbaa !9
  %59 = add nsw i32 %58, 1
  store i32 %59, ptr %11, align 4, !tbaa !9
  br label %20, !llvm.loop !12

60:                                               ; preds = %23
  ret void
}

attributes #0 = { 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 #1 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = { 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, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = !{!7, !7, i64 0}
!12 = distinct !{!12, !13}
!13 = !{!"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"

@row = external dso_local local_unnamed_addr global [8 x i32], align 16
@col = external dso_local local_unnamed_addr global [8 x i32], align 16

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef zeroext i1 @_Z4safePA10_ciic(ptr noundef, i32 noundef, i32 noundef, i8 noundef signext) local_unnamed_addr #0

; Function Attrs: mustprogress nounwind uwtable
define dso_local void @_Z12floodFillBFSPA10_ciicc(ptr noundef %0, i32 noundef %1, i32 noundef %2, i8 noundef signext %3, i8 noundef signext %4) local_unnamed_addr #0 {
  br label %tailrecurse

tailrecurse:                                      ; preds = %91, %5
  %.tr20 = phi i32 [ %1, %5 ], [ %93, %91 ]
  %.tr21 = phi i32 [ %2, %5 ], [ %95, %91 ]
  %6 = sext i32 %.tr20 to i64
  %7 = sext i32 %.tr21 to i64
  %8 = getelementptr inbounds [10 x i8], ptr %0, i64 %6, i64 %7
  store i8 %4, ptr %8, align 1, !tbaa !5
  %9 = load i32, ptr @row, align 16, !tbaa !8
  %10 = add nsw i32 %9, %.tr20
  %11 = load i32, ptr @col, align 16, !tbaa !8
  %12 = add nsw i32 %11, %.tr21
  %13 = tail call noundef zeroext i1 @_Z4safePA10_ciic(ptr noundef %0, i32 noundef %10, i32 noundef %12, i8 noundef signext %3)
  br i1 %13, label %14, label %19

14:                                               ; preds = %tailrecurse
  %15 = load i32, ptr @row, align 16, !tbaa !8
  %16 = add nsw i32 %15, %.tr20
  %17 = load i32, ptr @col, align 16, !tbaa !8
  %18 = add nsw i32 %17, %.tr21
  tail call void @_Z12floodFillBFSPA10_ciicc(ptr noundef nonnull %0, i32 noundef %16, i32 noundef %18, i8 noundef signext %3, i8 noundef signext %4)
  br label %19

19:                                               ; preds = %tailrecurse, %14
  %20 = load i32, ptr getelementptr inbounds (i8, ptr @row, i64 4), align 4, !tbaa !8
  %21 = add nsw i32 %20, %.tr20
  %22 = load i32, ptr getelementptr inbounds (i8, ptr @col, i64 4), align 4, !tbaa !8
  %23 = add nsw i32 %22, %.tr21
  %24 = tail call noundef zeroext i1 @_Z4safePA10_ciic(ptr noundef nonnull %0, i32 noundef %21, i32 noundef %23, i8 noundef signext %3)
  br i1 %24, label %25, label %30

25:                                               ; preds = %19
  %26 = load i32, ptr getelementptr inbounds (i8, ptr @row, i64 4), align 4, !tbaa !8
  %27 = add nsw i32 %26, %.tr20
  %28 = load i32, ptr getelementptr inbounds (i8, ptr @col, i64 4), align 4, !tbaa !8
  %29 = add nsw i32 %28, %.tr21
  tail call void @_Z12floodFillBFSPA10_ciicc(ptr noundef nonnull %0, i32 noundef %27, i32 noundef %29, i8 noundef signext %3, i8 noundef signext %4)
  br label %30

30:                                               ; preds = %25, %19
  %31 = load i32, ptr getelementptr inbounds (i8, ptr @row, i64 8), align 8, !tbaa !8
  %32 = add nsw i32 %31, %.tr20
  %33 = load i32, ptr getelementptr inbounds (i8, ptr @col, i64 8), align 8, !tbaa !8
  %34 = add nsw i32 %33, %.tr21
  %35 = tail call noundef zeroext i1 @_Z4safePA10_ciic(ptr noundef nonnull %0, i32 noundef %32, i32 noundef %34, i8 noundef signext %3)
  br i1 %35, label %36, label %41

36:                                               ; preds = %30
  %37 = load i32, ptr getelementptr inbounds (i8, ptr @row, i64 8), align 8, !tbaa !8
  %38 = add nsw i32 %37, %.tr20
  %39 = load i32, ptr getelementptr inbounds (i8, ptr @col, i64 8), align 8, !tbaa !8
  %40 = add nsw i32 %39, %.tr21
  tail call void @_Z12floodFillBFSPA10_ciicc(ptr noundef nonnull %0, i32 noundef %38, i32 noundef %40, i8 noundef signext %3, i8 noundef signext %4)
  br label %41

41:                                               ; preds = %36, %30
  %42 = load i32, ptr getelementptr inbounds (i8, ptr @row, i64 12), align 4, !tbaa !8
  %43 = add nsw i32 %42, %.tr20
  %44 = load i32, ptr getelementptr inbounds (i8, ptr @col, i64 12), align 4, !tbaa !8
  %45 = add nsw i32 %44, %.tr21
  %46 = tail call noundef zeroext i1 @_Z4safePA10_ciic(ptr noundef nonnull %0, i32 noundef %43, i32 noundef %45, i8 noundef signext %3)
  br i1 %46, label %47, label %52

47:                                               ; preds = %41
  %48 = load i32, ptr getelementptr inbounds (i8, ptr @row, i64 12), align 4, !tbaa !8
  %49 = add nsw i32 %48, %.tr20
  %50 = load i32, ptr getelementptr inbounds (i8, ptr @col, i64 12), align 4, !tbaa !8
  %51 = add nsw i32 %50, %.tr21
  tail call void @_Z12floodFillBFSPA10_ciicc(ptr noundef nonnull %0, i32 noundef %49, i32 noundef %51, i8 noundef signext %3, i8 noundef signext %4)
  br label %52

52:                                               ; preds = %47, %41
  %53 = load i32, ptr getelementptr inbounds (i8, ptr @row, i64 16), align 16, !tbaa !8
  %54 = add nsw i32 %53, %.tr20
  %55 = load i32, ptr getelementptr inbounds (i8, ptr @col, i64 16), align 16, !tbaa !8
  %56 = add nsw i32 %55, %.tr21
  %57 = tail call noundef zeroext i1 @_Z4safePA10_ciic(ptr noundef nonnull %0, i32 noundef %54, i32 noundef %56, i8 noundef signext %3)
  br i1 %57, label %58, label %63

58:                                               ; preds = %52
  %59 = load i32, ptr getelementptr inbounds (i8, ptr @row, i64 16), align 16, !tbaa !8
  %60 = add nsw i32 %59, %.tr20
  %61 = load i32, ptr getelementptr inbounds (i8, ptr @col, i64 16), align 16, !tbaa !8
  %62 = add nsw i32 %61, %.tr21
  tail call void @_Z12floodFillBFSPA10_ciicc(ptr noundef nonnull %0, i32 noundef %60, i32 noundef %62, i8 noundef signext %3, i8 noundef signext %4)
  br label %63

63:                                               ; preds = %58, %52
  %64 = load i32, ptr getelementptr inbounds (i8, ptr @row, i64 20), align 4, !tbaa !8
  %65 = add nsw i32 %64, %.tr20
  %66 = load i32, ptr getelementptr inbounds (i8, ptr @col, i64 20), align 4, !tbaa !8
  %67 = add nsw i32 %66, %.tr21
  %68 = tail call noundef zeroext i1 @_Z4safePA10_ciic(ptr noundef nonnull %0, i32 noundef %65, i32 noundef %67, i8 noundef signext %3)
  br i1 %68, label %69, label %74

69:                                               ; preds = %63
  %70 = load i32, ptr getelementptr inbounds (i8, ptr @row, i64 20), align 4, !tbaa !8
  %71 = add nsw i32 %70, %.tr20
  %72 = load i32, ptr getelementptr inbounds (i8, ptr @col, i64 20), align 4, !tbaa !8
  %73 = add nsw i32 %72, %.tr21
  tail call void @_Z12floodFillBFSPA10_ciicc(ptr noundef nonnull %0, i32 noundef %71, i32 noundef %73, i8 noundef signext %3, i8 noundef signext %4)
  br label %74

74:                                               ; preds = %69, %63
  %75 = load i32, ptr getelementptr inbounds (i8, ptr @row, i64 24), align 8, !tbaa !8
  %76 = add nsw i32 %75, %.tr20
  %77 = load i32, ptr getelementptr inbounds (i8, ptr @col, i64 24), align 8, !tbaa !8
  %78 = add nsw i32 %77, %.tr21
  %79 = tail call noundef zeroext i1 @_Z4safePA10_ciic(ptr noundef nonnull %0, i32 noundef %76, i32 noundef %78, i8 noundef signext %3)
  br i1 %79, label %80, label %85

80:                                               ; preds = %74
  %81 = load i32, ptr getelementptr inbounds (i8, ptr @row, i64 24), align 8, !tbaa !8
  %82 = add nsw i32 %81, %.tr20
  %83 = load i32, ptr getelementptr inbounds (i8, ptr @col, i64 24), align 8, !tbaa !8
  %84 = add nsw i32 %83, %.tr21
  tail call void @_Z12floodFillBFSPA10_ciicc(ptr noundef nonnull %0, i32 noundef %82, i32 noundef %84, i8 noundef signext %3, i8 noundef signext %4)
  br label %85

85:                                               ; preds = %80, %74
  %86 = load i32, ptr getelementptr inbounds (i8, ptr @row, i64 28), align 4, !tbaa !8
  %87 = add nsw i32 %86, %.tr20
  %88 = load i32, ptr getelementptr inbounds (i8, ptr @col, i64 28), align 4, !tbaa !8
  %89 = add nsw i32 %88, %.tr21
  %90 = tail call noundef zeroext i1 @_Z4safePA10_ciic(ptr noundef nonnull %0, i32 noundef %87, i32 noundef %89, i8 noundef signext %3)
  br i1 %90, label %91, label %96

91:                                               ; preds = %85
  %92 = load i32, ptr getelementptr inbounds (i8, ptr @row, i64 28), align 4, !tbaa !8
  %93 = add nsw i32 %92, %.tr20
  %94 = load i32, ptr getelementptr inbounds (i8, ptr @col, i64 28), align 4, !tbaa !8
  %95 = add nsw i32 %94, %.tr21
  br label %tailrecurse

96:                                               ; preds = %85
  ret void
}

attributes #0 = { 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" }

!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 = !{!"omnipotent char", !7, i64 0}
!7 = !{!"Simple C++ TBAA"}
!8 = !{!9, !9, i64 0}
!9 = !{!"int", !6, i64 0}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GVNPass,GlobalOptPass,IndVarSimplifyPass,InferAlignmentPass,InferFunctionAttrsPass,InstCombinePass,LoopRotatePass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass