; LLVM IR from Aryansh-S/USACO :: other_impl/other-algos/Graph/DFS/FloodfillHelper.ll (Z3dfs2bdIiES0_)

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

%struct.bd = type { i32, i32, i32 }

@vis = external dso_local global [105 x [105 x i8]], align 16
@_ZL2xd = external hidden constant [4 x i32], align 16
@_ZL2yd = external hidden constant [4 x i32], align 16

; Function Attrs: mustprogress uwtable
define dso_local void @_Z3dfs2bdIiES0_(i64 %0, i32 %1, i64 %2, i32 %3) #0 {
  %5 = alloca %struct.bd, align 4
  %6 = alloca { i64, i32 }, align 4
  %7 = alloca %struct.bd, align 4
  %8 = alloca { i64, i32 }, align 4
  %9 = alloca i32, align 4
  %10 = alloca %struct.bd, align 4
  %11 = alloca { i64, i32 }, align 8
  %12 = alloca %struct.bd, align 4
  %13 = alloca { i64, i32 }, align 8
  %14 = alloca { i64, i32 }, align 4
  %15 = alloca { i64, i32 }, align 4
  %16 = getelementptr inbounds { i64, i32 }, ptr %6, i32 0, i32 0
  store i64 %0, ptr %16, align 4
  %17 = getelementptr inbounds { i64, i32 }, ptr %6, i32 0, i32 1
  store i32 %1, ptr %17, align 4
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %5, ptr align 4 %6, i64 12, i1 false)
  %18 = getelementptr inbounds { i64, i32 }, ptr %8, i32 0, i32 0
  store i64 %2, ptr %18, align 4
  %19 = getelementptr inbounds { i64, i32 }, ptr %8, i32 0, i32 1
  store i32 %3, ptr %19, align 4
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %7, ptr align 4 %8, i64 12, i1 false)
  %20 = call noundef i32 @_ZNK2bdIiEcviEv(ptr noundef nonnull align 4 dereferenceable(12) %5)
  %21 = sext i32 %20 to i64
  %22 = getelementptr inbounds [105 x [105 x i8]], ptr @vis, i64 0, i64 %21
  %23 = call noundef i32 @_ZNK2bdIiEcviEv(ptr noundef nonnull align 4 dereferenceable(12) %7)
  %24 = sext i32 %23 to i64
  %25 = getelementptr inbounds [105 x i8], ptr %22, i64 0, i64 %24
  %26 = load i8, ptr %25, align 1, !tbaa !5, !range !9, !noundef !10
  %27 = trunc i8 %26 to i1
  br i1 %27, label %62, label %28

28:                                               ; preds = %4
  %29 = call noundef i32 @_ZNK2bdIiEcviEv(ptr noundef nonnull align 4 dereferenceable(12) %5)
  %30 = sext i32 %29 to i64
  %31 = getelementptr inbounds [105 x [105 x i8]], ptr @vis, i64 0, i64 %30
  %32 = call noundef i32 @_ZNK2bdIiEcviEv(ptr noundef nonnull align 4 dereferenceable(12) %7)
  %33 = sext i32 %32 to i64
  %34 = getelementptr inbounds [105 x i8], ptr %31, i64 0, i64 %33
  store i8 1, ptr %34, align 1, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #4
  store i32 0, ptr %9, align 4, !tbaa !11
  br label %35

35:                                               ; preds = %58, %28
  %36 = load i32, ptr %9, align 4, !tbaa !11
  %37 = icmp slt i32 %36, 4
  br i1 %37, label %39, label %38

38:                                               ; preds = %35
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #4
  br label %61

39:                                               ; preds = %35
  %40 = load i32, ptr %9, align 4, !tbaa !11
  %41 = sext i32 %40 to i64
  %42 = getelementptr inbounds [4 x i32], ptr @_ZL2xd, i64 0, i64 %41
  %43 = load i32, ptr %42, align 4, !tbaa !11
  %44 = call { i64, i32 } @_ZN2bdIiEplEi(ptr noundef nonnull align 4 dereferenceable(12) %5, i32 noundef %43)
  store { i64, i32 } %44, ptr %11, align 8
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %10, ptr align 8 %11, i64 12, i1 false)
  %45 = load i32, ptr %9, align 4, !tbaa !11
  %46 = sext i32 %45 to i64
  %47 = getelementptr inbounds [4 x i32], ptr @_ZL2yd, i64 0, i64 %46
  %48 = load i32, ptr %47, align 4, !tbaa !11
  %49 = call { i64, i32 } @_ZN2bdIiEplEi(ptr noundef nonnull align 4 dereferenceable(12) %7, i32 noundef %48)
  store { i64, i32 } %49, ptr %13, align 8
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %12, ptr align 8 %13, i64 12, i1 false)
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %14, ptr align 4 %10, i64 12, i1 false)
  %50 = getelementptr inbounds { i64, i32 }, ptr %14, i32 0, i32 0
  %51 = load i64, ptr %50, align 4
  %52 = getelementptr inbounds { i64, i32 }, ptr %14, i32 0, i32 1
  %53 = load i32, ptr %52, align 4
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %15, ptr align 4 %12, i64 12, i1 false)
  %54 = getelementptr inbounds { i64, i32 }, ptr %15, i32 0, i32 0
  %55 = load i64, ptr %54, align 4
  %56 = getelementptr inbounds { i64, i32 }, ptr %15, i32 0, i32 1
  %57 = load i32, ptr %56, align 4
  call void @_Z3dfs2bdIiES0_(i64 %51, i32 %53, i64 %55, i32 %57)
  br label %58

58:                                               ; preds = %39
  %59 = load i32, ptr %9, align 4, !tbaa !11
  %60 = add nsw i32 %59, 1
  store i32 %60, ptr %9, align 4, !tbaa !11
  br label %35, !llvm.loop !13

61:                                               ; preds = %38
  br label %62

62:                                               ; preds = %61, %4
  ret void
}

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #1

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

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

; Function Attrs: mustprogress uwtable
declare dso_local { i64, i32 } @_ZN2bdIiEplEi(ptr noundef nonnull align 4 dereferenceable(12), i32 noundef) #0 align 2

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

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: readwrite) }
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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #4 = { 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 = !{!"bool", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{i8 0, i8 2}
!10 = !{}
!11 = !{!12, !12, i64 0}
!12 = !{!"int", !7, i64 0}
!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"

%struct.bd = type { i32, i32, i32 }

@vis = external dso_local local_unnamed_addr global [105 x [105 x i8]], align 16
@_ZL2xd = external hidden local_unnamed_addr constant [4 x i32], align 16
@_ZL2yd = external hidden local_unnamed_addr constant [4 x i32], align 16

; Function Attrs: mustprogress uwtable
define dso_local void @_Z3dfs2bdIiES0_(i64 %0, i32 %1, i64 %2, i32 %3) local_unnamed_addr #0 {
  %5 = alloca %struct.bd, align 8
  %6 = alloca %struct.bd, align 8
  store i64 %0, ptr %5, align 8
  %.sroa.219.0..sroa_idx = getelementptr inbounds i8, ptr %5, i64 8
  store i32 %1, ptr %.sroa.219.0..sroa_idx, align 8
  store i64 %2, ptr %6, align 8
  %.sroa.217.0..sroa_idx = getelementptr inbounds i8, ptr %6, i64 8
  store i32 %3, ptr %.sroa.217.0..sroa_idx, align 8
  %7 = call noundef i32 @_ZNK2bdIiEcviEv(ptr noundef nonnull align 4 dereferenceable(12) %5)
  %8 = sext i32 %7 to i64
  %9 = call noundef i32 @_ZNK2bdIiEcviEv(ptr noundef nonnull align 4 dereferenceable(12) %6)
  %10 = sext i32 %9 to i64
  %11 = getelementptr inbounds [105 x [105 x i8]], ptr @vis, i64 0, i64 %8, i64 %10
  %12 = load i8, ptr %11, align 1, !tbaa !5, !range !9, !noundef !10
  %13 = trunc nuw i8 %12 to i1
  br i1 %13, label %.loopexit, label %.loopexit.loopexit

.loopexit.loopexit:                               ; preds = %4
  %14 = call noundef i32 @_ZNK2bdIiEcviEv(ptr noundef nonnull align 4 dereferenceable(12) %5)
  %15 = sext i32 %14 to i64
  %16 = call noundef i32 @_ZNK2bdIiEcviEv(ptr noundef nonnull align 4 dereferenceable(12) %6)
  %17 = sext i32 %16 to i64
  %18 = getelementptr inbounds [105 x [105 x i8]], ptr @vis, i64 0, i64 %15, i64 %17
  store i8 1, ptr %18, align 1, !tbaa !5
  %19 = load i32, ptr @_ZL2xd, align 16, !tbaa !11
  %20 = call { i64, i32 } @_ZN2bdIiEplEi(ptr noundef nonnull align 4 dereferenceable(12) %5, i32 noundef %19)
  %.fca.0.extract7 = extractvalue { i64, i32 } %20, 0
  %.fca.1.extract8 = extractvalue { i64, i32 } %20, 1
  %21 = load i32, ptr @_ZL2yd, align 16, !tbaa !11
  %22 = call { i64, i32 } @_ZN2bdIiEplEi(ptr noundef nonnull align 4 dereferenceable(12) %6, i32 noundef %21)
  %.fca.0.extract = extractvalue { i64, i32 } %22, 0
  %.fca.1.extract = extractvalue { i64, i32 } %22, 1
  call void @_Z3dfs2bdIiES0_(i64 %.fca.0.extract7, i32 %.fca.1.extract8, i64 %.fca.0.extract, i32 %.fca.1.extract)
  %23 = load i32, ptr getelementptr inbounds (i8, ptr @_ZL2xd, i64 4), align 4, !tbaa !11
  %24 = call { i64, i32 } @_ZN2bdIiEplEi(ptr noundef nonnull align 4 dereferenceable(12) %5, i32 noundef %23)
  %.fca.0.extract7.1 = extractvalue { i64, i32 } %24, 0
  %.fca.1.extract8.1 = extractvalue { i64, i32 } %24, 1
  %25 = load i32, ptr getelementptr inbounds (i8, ptr @_ZL2yd, i64 4), align 4, !tbaa !11
  %26 = call { i64, i32 } @_ZN2bdIiEplEi(ptr noundef nonnull align 4 dereferenceable(12) %6, i32 noundef %25)
  %.fca.0.extract.1 = extractvalue { i64, i32 } %26, 0
  %.fca.1.extract.1 = extractvalue { i64, i32 } %26, 1
  call void @_Z3dfs2bdIiES0_(i64 %.fca.0.extract7.1, i32 %.fca.1.extract8.1, i64 %.fca.0.extract.1, i32 %.fca.1.extract.1)
  %27 = load i32, ptr getelementptr inbounds (i8, ptr @_ZL2xd, i64 8), align 8, !tbaa !11
  %28 = call { i64, i32 } @_ZN2bdIiEplEi(ptr noundef nonnull align 4 dereferenceable(12) %5, i32 noundef %27)
  %.fca.0.extract7.2 = extractvalue { i64, i32 } %28, 0
  %.fca.1.extract8.2 = extractvalue { i64, i32 } %28, 1
  %29 = load i32, ptr getelementptr inbounds (i8, ptr @_ZL2yd, i64 8), align 8, !tbaa !11
  %30 = call { i64, i32 } @_ZN2bdIiEplEi(ptr noundef nonnull align 4 dereferenceable(12) %6, i32 noundef %29)
  %.fca.0.extract.2 = extractvalue { i64, i32 } %30, 0
  %.fca.1.extract.2 = extractvalue { i64, i32 } %30, 1
  call void @_Z3dfs2bdIiES0_(i64 %.fca.0.extract7.2, i32 %.fca.1.extract8.2, i64 %.fca.0.extract.2, i32 %.fca.1.extract.2)
  %31 = load i32, ptr getelementptr inbounds (i8, ptr @_ZL2xd, i64 12), align 4, !tbaa !11
  %32 = call { i64, i32 } @_ZN2bdIiEplEi(ptr noundef nonnull align 4 dereferenceable(12) %5, i32 noundef %31)
  %.fca.0.extract7.3 = extractvalue { i64, i32 } %32, 0
  %.fca.1.extract8.3 = extractvalue { i64, i32 } %32, 1
  %33 = load i32, ptr getelementptr inbounds (i8, ptr @_ZL2yd, i64 12), align 4, !tbaa !11
  %34 = call { i64, i32 } @_ZN2bdIiEplEi(ptr noundef nonnull align 4 dereferenceable(12) %6, i32 noundef %33)
  %.fca.0.extract.3 = extractvalue { i64, i32 } %34, 0
  %.fca.1.extract.3 = extractvalue { i64, i32 } %34, 1
  call void @_Z3dfs2bdIiES0_(i64 %.fca.0.extract7.3, i32 %.fca.1.extract8.3, i64 %.fca.0.extract.3, i32 %.fca.1.extract.3)
  br label %.loopexit

.loopexit:                                        ; preds = %.loopexit.loopexit, %4
  ret void
}

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i32 @_ZNK2bdIiEcviEv(ptr noundef nonnull align 4 dereferenceable(12)) local_unnamed_addr #1 align 2

; Function Attrs: mustprogress uwtable
declare dso_local { i64, i32 } @_ZN2bdIiEplEi(ptr noundef nonnull align 4 dereferenceable(12), i32 noundef) local_unnamed_addr #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 = { 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 = !{!"bool", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{i8 0, i8 2}
!10 = !{}
!11 = !{!12, !12, i64 0}
!12 = !{!"int", !7, i64 0}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferAlignmentPass,InferFunctionAttrsPass,InstCombinePass,LoopRotatePass,LoopSimplifyPass,SROAPass,SimplifyCFGPass