; LLVM IR from div-bargali/Data-Structures-and-Algorithms :: C++/Algorithms/Graph-Algorithms/Number_of_Islands.ll (Z12countIslandsPA5_i)

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

; Function Attrs: mustprogress uwtable
declare dso_local void @_Z3DFSPA5_iiiPA5_b(ptr noundef, i32 noundef, i32 noundef, ptr 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 i32 @_Z12countIslandsPA5_i(ptr noundef %0) #0 {
  %2 = alloca ptr, align 8
  %3 = alloca [5 x [5 x i8]], align 16
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  store ptr %0, ptr %2, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 25, ptr %3) #3
  %8 = getelementptr inbounds [5 x [5 x i8]], ptr %3, i64 0, i64 0
  call void @llvm.memset.p0.i64(ptr align 16 %8, i8 0, i64 25, i1 false)
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #3
  store i32 0, ptr %4, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #3
  store i32 0, ptr %5, align 4, !tbaa !9
  br label %9

9:                                                ; preds = %49, %1
  %10 = load i32, ptr %5, align 4, !tbaa !9
  %11 = icmp slt i32 %10, 5
  br i1 %11, label %13, label %12

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

13:                                               ; preds = %9
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #3
  store i32 0, ptr %7, align 4, !tbaa !9
  br label %14

14:                                               ; preds = %45, %13
  %15 = load i32, ptr %7, align 4, !tbaa !9
  %16 = icmp slt i32 %15, 5
  br i1 %16, label %18, label %17

17:                                               ; preds = %14
  store i32 5, ptr %6, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #3
  br label %48

18:                                               ; preds = %14
  %19 = load ptr, ptr %2, align 8, !tbaa !5
  %20 = load i32, ptr %5, align 4, !tbaa !9
  %21 = sext i32 %20 to i64
  %22 = getelementptr inbounds [5 x i32], ptr %19, i64 %21
  %23 = load i32, ptr %7, align 4, !tbaa !9
  %24 = sext i32 %23 to i64
  %25 = getelementptr inbounds [5 x i32], ptr %22, i64 0, i64 %24
  %26 = load i32, ptr %25, align 4, !tbaa !9
  %27 = icmp ne i32 %26, 0
  br i1 %27, label %28, label %44

28:                                               ; preds = %18
  %29 = load i32, ptr %5, align 4, !tbaa !9
  %30 = sext i32 %29 to i64
  %31 = getelementptr inbounds [5 x [5 x i8]], ptr %3, i64 0, i64 %30
  %32 = load i32, ptr %7, align 4, !tbaa !9
  %33 = sext i32 %32 to i64
  %34 = getelementptr inbounds [5 x i8], ptr %31, i64 0, i64 %33
  %35 = load i8, ptr %34, align 1, !tbaa !11, !range !13, !noundef !14
  %36 = trunc i8 %35 to i1
  br i1 %36, label %44, label %37

37:                                               ; preds = %28
  %38 = load ptr, ptr %2, align 8, !tbaa !5
  %39 = load i32, ptr %5, align 4, !tbaa !9
  %40 = load i32, ptr %7, align 4, !tbaa !9
  %41 = getelementptr inbounds [5 x [5 x i8]], ptr %3, i64 0, i64 0
  call void @_Z3DFSPA5_iiiPA5_b(ptr noundef %38, i32 noundef %39, i32 noundef %40, ptr noundef %41)
  %42 = load i32, ptr %4, align 4, !tbaa !9
  %43 = add nsw i32 %42, 1
  store i32 %43, ptr %4, align 4, !tbaa !9
  br label %44

44:                                               ; preds = %37, %28, %18
  br label %45

45:                                               ; preds = %44
  %46 = load i32, ptr %7, align 4, !tbaa !9
  %47 = add nsw i32 %46, 1
  store i32 %47, ptr %7, align 4, !tbaa !9
  br label %14, !llvm.loop !15

48:                                               ; preds = %17
  br label %49

49:                                               ; preds = %48
  %50 = load i32, ptr %5, align 4, !tbaa !9
  %51 = add nsw i32 %50, 1
  store i32 %51, ptr %5, align 4, !tbaa !9
  br label %9, !llvm.loop !17

52:                                               ; preds = %12
  %53 = load i32, ptr %4, align 4, !tbaa !9
  store i32 1, ptr %6, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #3
  call void @llvm.lifetime.end.p0(i64 25, ptr %3) #3
  ret i32 %53
}

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


; 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
declare dso_local void @_Z3DFSPA5_iiiPA5_b(ptr noundef, i32 noundef, i32 noundef, ptr noundef) local_unnamed_addr #0

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

; Function Attrs: mustprogress 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 i32 @_Z12countIslandsPA5_i(ptr noundef %0) local_unnamed_addr #0 {
  %2 = alloca [5 x [5 x i8]], align 16
  call void @llvm.lifetime.start.p0(i64 25, ptr nonnull %2) #3
  call void @llvm.memset.p0.i64(ptr noundef nonnull align 16 dereferenceable(25) %2, i8 0, i64 25, i1 false)
  br label %.preheader

.preheader:                                       ; preds = %1, %53
  %indvars.iv = phi i64 [ 0, %1 ], [ %indvars.iv.next, %53 ]
  %.01417 = phi i32 [ 0, %1 ], [ %.2.4, %53 ]
  %3 = getelementptr inbounds [5 x i32], ptr %0, i64 %indvars.iv, i64 0
  %4 = load i32, ptr %3, align 4, !tbaa !5
  %.not = icmp eq i32 %4, 0
  br i1 %.not, label %13, label %6

5:                                                ; preds = %53
  call void @llvm.lifetime.end.p0(i64 25, ptr nonnull %2) #3
  ret i32 %.2.4

6:                                                ; preds = %.preheader
  %7 = getelementptr inbounds [5 x [5 x i8]], ptr %2, i64 0, i64 %indvars.iv, i64 0
  %8 = load i8, ptr %7, align 1, !tbaa !9, !range !11, !noundef !12
  %9 = trunc nuw i8 %8 to i1
  br i1 %9, label %13, label %10

10:                                               ; preds = %6
  %11 = trunc nuw nsw i64 %indvars.iv to i32
  call void @_Z3DFSPA5_iiiPA5_b(ptr noundef nonnull %0, i32 noundef %11, i32 noundef 0, ptr noundef nonnull %2)
  %12 = add nsw i32 %.01417, 1
  br label %13

13:                                               ; preds = %.preheader, %6, %10
  %.2 = phi i32 [ %.01417, %6 ], [ %12, %10 ], [ %.01417, %.preheader ]
  %14 = getelementptr inbounds [5 x i32], ptr %0, i64 %indvars.iv, i64 1
  %15 = load i32, ptr %14, align 4, !tbaa !5
  %.not.1 = icmp eq i32 %15, 0
  br i1 %.not.1, label %23, label %16

16:                                               ; preds = %13
  %17 = getelementptr inbounds [5 x [5 x i8]], ptr %2, i64 0, i64 %indvars.iv, i64 1
  %18 = load i8, ptr %17, align 1, !tbaa !9, !range !11, !noundef !12
  %19 = trunc nuw i8 %18 to i1
  br i1 %19, label %23, label %20

20:                                               ; preds = %16
  %21 = trunc nuw nsw i64 %indvars.iv to i32
  call void @_Z3DFSPA5_iiiPA5_b(ptr noundef nonnull %0, i32 noundef %21, i32 noundef 1, ptr noundef nonnull %2)
  %22 = add nsw i32 %.2, 1
  br label %23

23:                                               ; preds = %20, %16, %13
  %.2.1 = phi i32 [ %.2, %16 ], [ %22, %20 ], [ %.2, %13 ]
  %24 = getelementptr inbounds [5 x i32], ptr %0, i64 %indvars.iv, i64 2
  %25 = load i32, ptr %24, align 4, !tbaa !5
  %.not.2 = icmp eq i32 %25, 0
  br i1 %.not.2, label %33, label %26

26:                                               ; preds = %23
  %27 = getelementptr inbounds [5 x [5 x i8]], ptr %2, i64 0, i64 %indvars.iv, i64 2
  %28 = load i8, ptr %27, align 1, !tbaa !9, !range !11, !noundef !12
  %29 = trunc nuw i8 %28 to i1
  br i1 %29, label %33, label %30

30:                                               ; preds = %26
  %31 = trunc nuw nsw i64 %indvars.iv to i32
  call void @_Z3DFSPA5_iiiPA5_b(ptr noundef nonnull %0, i32 noundef %31, i32 noundef 2, ptr noundef nonnull %2)
  %32 = add nsw i32 %.2.1, 1
  br label %33

33:                                               ; preds = %30, %26, %23
  %.2.2 = phi i32 [ %.2.1, %26 ], [ %32, %30 ], [ %.2.1, %23 ]
  %34 = getelementptr inbounds [5 x i32], ptr %0, i64 %indvars.iv, i64 3
  %35 = load i32, ptr %34, align 4, !tbaa !5
  %.not.3 = icmp eq i32 %35, 0
  br i1 %.not.3, label %43, label %36

36:                                               ; preds = %33
  %37 = getelementptr inbounds [5 x [5 x i8]], ptr %2, i64 0, i64 %indvars.iv, i64 3
  %38 = load i8, ptr %37, align 1, !tbaa !9, !range !11, !noundef !12
  %39 = trunc nuw i8 %38 to i1
  br i1 %39, label %43, label %40

40:                                               ; preds = %36
  %41 = trunc nuw nsw i64 %indvars.iv to i32
  call void @_Z3DFSPA5_iiiPA5_b(ptr noundef nonnull %0, i32 noundef %41, i32 noundef 3, ptr noundef nonnull %2)
  %42 = add nsw i32 %.2.2, 1
  br label %43

43:                                               ; preds = %40, %36, %33
  %.2.3 = phi i32 [ %.2.2, %36 ], [ %42, %40 ], [ %.2.2, %33 ]
  %44 = getelementptr inbounds [5 x i32], ptr %0, i64 %indvars.iv, i64 4
  %45 = load i32, ptr %44, align 4, !tbaa !5
  %.not.4 = icmp eq i32 %45, 0
  br i1 %.not.4, label %53, label %46

46:                                               ; preds = %43
  %47 = getelementptr inbounds [5 x [5 x i8]], ptr %2, i64 0, i64 %indvars.iv, i64 4
  %48 = load i8, ptr %47, align 1, !tbaa !9, !range !11, !noundef !12
  %49 = trunc nuw i8 %48 to i1
  br i1 %49, label %53, label %50

50:                                               ; preds = %46
  %51 = trunc nuw nsw i64 %indvars.iv to i32
  call void @_Z3DFSPA5_iiiPA5_b(ptr noundef nonnull %0, i32 noundef %51, i32 noundef 4, ptr noundef nonnull %2)
  %52 = add nsw i32 %.2.3, 1
  br label %53

53:                                               ; preds = %50, %46, %43
  %.2.4 = phi i32 [ %.2.3, %46 ], [ %52, %50 ], [ %.2.3, %43 ]
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %exitcond.not = icmp eq i64 %indvars.iv.next, 5
  br i1 %exitcond.not, label %5, label %.preheader, !llvm.loop !13
}

; Function Attrs: mustprogress 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 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: write) }
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 = !{!"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"}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,LCSSAPass,LICMPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,SROAPass,SimplifyCFGPass