; LLVM IR from ShahjalalShohag/code-library :: Graph Theory/Boruvka's Algorithm.ll (Z3addii)

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

@t = external dso_local global [6000270 x [2 x i32]], align 16
@sz = external dso_local global i32, align 4
@el = external dso_local global [6000270 x i32], align 16
@tot = external dso_local global [6000270 x i32], align 16

; Function Attrs: mustprogress nounwind uwtable
define dso_local void @_Z3addii(i32 noundef %0, i32 noundef %1) #0 {
  %3 = alloca i32, align 4
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  %7 = alloca i8, align 1
  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
  %8 = load i32, ptr %5, align 4, !tbaa !5
  %9 = sext i32 %8 to i64
  %10 = getelementptr inbounds [6000270 x i32], ptr @tot, i64 0, i64 %9
  %11 = load i32, ptr %10, align 4, !tbaa !5
  %12 = add nsw i32 %11, 1
  store i32 %12, ptr %10, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #2
  store i32 30, ptr %6, align 4, !tbaa !5
  br label %13

13:                                               ; preds = %57, %2
  %14 = load i32, ptr %6, align 4, !tbaa !5
  %15 = icmp sge i32 %14, 0
  br i1 %15, label %17, label %16

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

17:                                               ; preds = %13
  call void @llvm.lifetime.start.p0(i64 1, ptr %7) #2
  %18 = load i32, ptr %3, align 4, !tbaa !5
  %19 = load i32, ptr %6, align 4, !tbaa !5
  %20 = shl i32 1, %19
  %21 = and i32 %18, %20
  %22 = icmp ne i32 %21, 0
  %23 = zext i1 %22 to i8
  store i8 %23, ptr %7, align 1, !tbaa !9
  %24 = load i32, ptr %5, align 4, !tbaa !5
  %25 = sext i32 %24 to i64
  %26 = getelementptr inbounds [6000270 x [2 x i32]], ptr @t, i64 0, i64 %25
  %27 = load i8, ptr %7, align 1, !tbaa !9, !range !11, !noundef !12
  %28 = trunc i8 %27 to i1
  %29 = zext i1 %28 to i64
  %30 = getelementptr inbounds [2 x i32], ptr %26, i64 0, i64 %29
  %31 = load i32, ptr %30, align 4, !tbaa !5
  %32 = icmp eq i32 %31, 0
  br i1 %32, label %33, label %43

33:                                               ; preds = %17
  %34 = load i32, ptr @sz, align 4, !tbaa !5
  %35 = add nsw i32 %34, 1
  store i32 %35, ptr @sz, align 4, !tbaa !5
  %36 = load i32, ptr %5, align 4, !tbaa !5
  %37 = sext i32 %36 to i64
  %38 = getelementptr inbounds [6000270 x [2 x i32]], ptr @t, i64 0, i64 %37
  %39 = load i8, ptr %7, align 1, !tbaa !9, !range !11, !noundef !12
  %40 = trunc i8 %39 to i1
  %41 = zext i1 %40 to i64
  %42 = getelementptr inbounds [2 x i32], ptr %38, i64 0, i64 %41
  store i32 %35, ptr %42, align 4, !tbaa !5
  br label %43

43:                                               ; preds = %33, %17
  %44 = load i32, ptr %5, align 4, !tbaa !5
  %45 = sext i32 %44 to i64
  %46 = getelementptr inbounds [6000270 x [2 x i32]], ptr @t, i64 0, i64 %45
  %47 = load i8, ptr %7, align 1, !tbaa !9, !range !11, !noundef !12
  %48 = trunc i8 %47 to i1
  %49 = zext i1 %48 to i64
  %50 = getelementptr inbounds [2 x i32], ptr %46, i64 0, i64 %49
  %51 = load i32, ptr %50, align 4, !tbaa !5
  store i32 %51, ptr %5, align 4, !tbaa !5
  %52 = load i32, ptr %5, align 4, !tbaa !5
  %53 = sext i32 %52 to i64
  %54 = getelementptr inbounds [6000270 x i32], ptr @tot, i64 0, i64 %53
  %55 = load i32, ptr %54, align 4, !tbaa !5
  %56 = add nsw i32 %55, 1
  store i32 %56, ptr %54, align 4, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 1, ptr %7) #2
  br label %57

57:                                               ; preds = %43
  %58 = load i32, ptr %6, align 4, !tbaa !5
  %59 = add nsw i32 %58, -1
  store i32 %59, ptr %6, align 4, !tbaa !5
  br label %13, !llvm.loop !13

60:                                               ; preds = %16
  %61 = load i32, ptr %4, align 4, !tbaa !5
  %62 = load i32, ptr %5, align 4, !tbaa !5
  %63 = sext i32 %62 to i64
  %64 = getelementptr inbounds [6000270 x i32], ptr @el, i64 0, i64 %63
  store i32 %61, ptr %64, align 4, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #2
  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 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 = { 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"

@t = external dso_local local_unnamed_addr global [6000270 x [2 x i32]], align 16
@sz = external dso_local local_unnamed_addr global i32, align 4
@el = external dso_local local_unnamed_addr global [6000270 x i32], align 16
@tot = external dso_local local_unnamed_addr global [6000270 x i32], align 16

; Function Attrs: mustprogress nofree norecurse nosync nounwind memory(readwrite, argmem: none, inaccessiblemem: none) uwtable
define dso_local void @_Z3addii(i32 noundef %0, i32 noundef %1) local_unnamed_addr #0 {
  %3 = load i32, ptr @tot, align 16, !tbaa !5
  %4 = add nsw i32 %3, 1
  store i32 %4, ptr @tot, align 16, !tbaa !5
  %sz.promoted = load i32, ptr @sz, align 4, !tbaa !5
  br label %7

5:                                                ; preds = %19
  %6 = getelementptr inbounds [6000270 x i32], ptr @el, i64 0, i64 %22
  store i32 %1, ptr %6, align 4, !tbaa !5
  ret void

7:                                                ; preds = %2, %19
  %.016 = phi i32 [ 0, %2 ], [ %20, %19 ]
  %.01415 = phi i32 [ 30, %2 ], [ %26, %19 ]
  %8 = phi i32 [ %sz.promoted, %2 ], [ %21, %19 ]
  %9 = shl nuw i32 1, %.01415
  %10 = and i32 %9, %0
  %11 = icmp ne i32 %10, 0
  %12 = sext i32 %.016 to i64
  %13 = zext i1 %11 to i64
  %14 = getelementptr inbounds [6000270 x [2 x i32]], ptr @t, i64 0, i64 %12, i64 %13
  %15 = load i32, ptr %14, align 4, !tbaa !5
  %16 = icmp eq i32 %15, 0
  br i1 %16, label %17, label %19

17:                                               ; preds = %7
  %18 = add nsw i32 %8, 1
  store i32 %18, ptr @sz, align 4, !tbaa !5
  store i32 %18, ptr %14, align 4, !tbaa !5
  br label %19

19:                                               ; preds = %17, %7
  %20 = phi i32 [ %18, %17 ], [ %15, %7 ]
  %21 = phi i32 [ %18, %17 ], [ %8, %7 ]
  %22 = sext i32 %20 to i64
  %23 = getelementptr inbounds [6000270 x i32], ptr @tot, i64 0, i64 %22
  %24 = load i32, ptr %23, align 4, !tbaa !5
  %25 = add nsw i32 %24, 1
  store i32 %25, ptr %23, align 4, !tbaa !5
  %26 = add nsw i32 %.01415, -1
  %.not = icmp eq i32 %.01415, 0
  br i1 %.not, label %5, label %7, !llvm.loop !9
}

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 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}


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