; LLVM IR from Lakhankumawat/LearnCPP :: G-Graphs/I-Implementation/PathMatrix.ll (Z12power_matrixiPA100_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"

@adj = external dso_local global [100 x [100 x i32]], align 16
@n = external dso_local global i32, align 4

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

; Function Attrs: mustprogress uwtable
define dso_local void @_Z12power_matrixiPA100_i(i32 noundef %0, ptr noundef %1) #1 {
  %3 = alloca i32, align 4
  %4 = alloca ptr, align 8
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  %8 = alloca [100 x [100 x i32]], align 16
  store i32 %0, ptr %3, align 4, !tbaa !5
  store ptr %1, ptr %4, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #3
  call void @llvm.lifetime.start.p0(i64 40000, ptr %8) #3
  store i32 0, ptr %5, align 4, !tbaa !5
  br label %9

9:                                                ; preds = %37, %2
  %10 = load i32, ptr %5, align 4, !tbaa !5
  %11 = load i32, ptr @n, align 4, !tbaa !5
  %12 = icmp slt i32 %10, %11
  br i1 %12, label %13, label %40

13:                                               ; preds = %9
  store i32 0, ptr %6, align 4, !tbaa !5
  br label %14

14:                                               ; preds = %33, %13
  %15 = load i32, ptr %6, align 4, !tbaa !5
  %16 = load i32, ptr @n, align 4, !tbaa !5
  %17 = icmp slt i32 %15, %16
  br i1 %17, label %18, label %36

18:                                               ; preds = %14
  %19 = load i32, ptr %5, align 4, !tbaa !5
  %20 = sext i32 %19 to i64
  %21 = getelementptr inbounds [100 x [100 x i32]], ptr @adj, i64 0, i64 %20
  %22 = load i32, ptr %6, align 4, !tbaa !5
  %23 = sext i32 %22 to i64
  %24 = getelementptr inbounds [100 x i32], ptr %21, i64 0, i64 %23
  %25 = load i32, ptr %24, align 4, !tbaa !5
  %26 = load ptr, ptr %4, align 8, !tbaa !9
  %27 = load i32, ptr %5, align 4, !tbaa !5
  %28 = sext i32 %27 to i64
  %29 = getelementptr inbounds [100 x i32], ptr %26, i64 %28
  %30 = load i32, ptr %6, align 4, !tbaa !5
  %31 = sext i32 %30 to i64
  %32 = getelementptr inbounds [100 x i32], ptr %29, i64 0, i64 %31
  store i32 %25, ptr %32, align 4, !tbaa !5
  br label %33

33:                                               ; preds = %18
  %34 = load i32, ptr %6, align 4, !tbaa !5
  %35 = add nsw i32 %34, 1
  store i32 %35, ptr %6, align 4, !tbaa !5
  br label %14, !llvm.loop !11

36:                                               ; preds = %14
  br label %37

37:                                               ; preds = %36
  %38 = load i32, ptr %5, align 4, !tbaa !5
  %39 = add nsw i32 %38, 1
  store i32 %39, ptr %5, align 4, !tbaa !5
  br label %9, !llvm.loop !13

40:                                               ; preds = %9
  store i32 1, ptr %7, align 4, !tbaa !5
  br label %41

41:                                               ; preds = %80, %40
  %42 = load i32, ptr %7, align 4, !tbaa !5
  %43 = load i32, ptr %3, align 4, !tbaa !5
  %44 = icmp slt i32 %42, %43
  br i1 %44, label %45, label %83

45:                                               ; preds = %41
  %46 = load ptr, ptr %4, align 8, !tbaa !9
  %47 = getelementptr inbounds [100 x [100 x i32]], ptr %8, i64 0, i64 0
  call void @_Z8multiplyPA100_iS0_S0_(ptr noundef %46, ptr noundef @adj, ptr noundef %47)
  store i32 0, ptr %5, align 4, !tbaa !5
  br label %48

48:                                               ; preds = %76, %45
  %49 = load i32, ptr %5, align 4, !tbaa !5
  %50 = load i32, ptr @n, align 4, !tbaa !5
  %51 = icmp slt i32 %49, %50
  br i1 %51, label %52, label %79

52:                                               ; preds = %48
  store i32 0, ptr %6, align 4, !tbaa !5
  br label %53

53:                                               ; preds = %72, %52
  %54 = load i32, ptr %6, align 4, !tbaa !5
  %55 = load i32, ptr @n, align 4, !tbaa !5
  %56 = icmp slt i32 %54, %55
  br i1 %56, label %57, label %75

57:                                               ; preds = %53
  %58 = load i32, ptr %5, align 4, !tbaa !5
  %59 = sext i32 %58 to i64
  %60 = getelementptr inbounds [100 x [100 x i32]], ptr %8, i64 0, i64 %59
  %61 = load i32, ptr %6, align 4, !tbaa !5
  %62 = sext i32 %61 to i64
  %63 = getelementptr inbounds [100 x i32], ptr %60, i64 0, i64 %62
  %64 = load i32, ptr %63, align 4, !tbaa !5
  %65 = load ptr, ptr %4, align 8, !tbaa !9
  %66 = load i32, ptr %5, align 4, !tbaa !5
  %67 = sext i32 %66 to i64
  %68 = getelementptr inbounds [100 x i32], ptr %65, i64 %67
  %69 = load i32, ptr %6, align 4, !tbaa !5
  %70 = sext i32 %69 to i64
  %71 = getelementptr inbounds [100 x i32], ptr %68, i64 0, i64 %70
  store i32 %64, ptr %71, align 4, !tbaa !5
  br label %72

72:                                               ; preds = %57
  %73 = load i32, ptr %6, align 4, !tbaa !5
  %74 = add nsw i32 %73, 1
  store i32 %74, ptr %6, align 4, !tbaa !5
  br label %53, !llvm.loop !14

75:                                               ; preds = %53
  br label %76

76:                                               ; preds = %75
  %77 = load i32, ptr %5, align 4, !tbaa !5
  %78 = add nsw i32 %77, 1
  store i32 %78, ptr %5, align 4, !tbaa !5
  br label %48, !llvm.loop !15

79:                                               ; preds = %48
  br label %80

80:                                               ; preds = %79
  %81 = load i32, ptr %7, align 4, !tbaa !5
  %82 = add nsw i32 %81, 1
  store i32 %82, ptr %7, align 4, !tbaa !5
  br label %41, !llvm.loop !16

83:                                               ; preds = %41
  call void @llvm.lifetime.end.p0(i64 40000, ptr %8) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #3
  ret void
}

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

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_Z8multiplyPA100_iS0_S0_(ptr noundef, ptr noundef, ptr noundef) #2

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 #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 = { 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 = !{!"any pointer", !7, i64 0}
!11 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}
!13 = distinct !{!13, !12}
!14 = distinct !{!14, !12}
!15 = distinct !{!15, !12}
!16 = distinct !{!16, !12}


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

@adj = external dso_local global [100 x [100 x i32]], align 16
@n = external dso_local local_unnamed_addr global i32, align 4

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

; Function Attrs: mustprogress nounwind uwtable
define dso_local void @_Z12power_matrixiPA100_i(i32 noundef %0, ptr noundef %1) local_unnamed_addr #1 {
  %3 = alloca [100 x [100 x i32]], align 16
  call void @llvm.lifetime.start.p0(i64 40000, ptr nonnull %3) #2
  %4 = load i32, ptr @n, align 4, !tbaa !5
  %5 = icmp sgt i32 %4, 0
  br i1 %5, label %.preheader25, label %.preheader24

.preheader25:                                     ; preds = %2, %._crit_edge
  %6 = phi i32 [ %15, %._crit_edge ], [ %4, %2 ]
  %indvars.iv39 = phi i64 [ %indvars.iv.next40, %._crit_edge ], [ 0, %2 ]
  %7 = icmp sgt i32 %6, 0
  br i1 %7, label %.lr.ph, label %.preheader25.._crit_edge_crit_edge

.preheader25.._crit_edge_crit_edge:               ; preds = %.preheader25
  %.pre = sext i32 %6 to i64
  br label %._crit_edge

.preheader24:                                     ; preds = %._crit_edge, %2
  %8 = icmp sgt i32 %0, 1
  br i1 %8, label %.lr.ph34, label %._crit_edge35

.lr.ph:                                           ; preds = %.preheader25, %.lr.ph
  %indvars.iv = phi i64 [ %indvars.iv.next, %.lr.ph ], [ 0, %.preheader25 ]
  %9 = getelementptr inbounds [100 x [100 x i32]], ptr @adj, i64 0, i64 %indvars.iv39, i64 %indvars.iv
  %10 = load i32, ptr %9, align 4, !tbaa !5
  %11 = getelementptr inbounds [100 x i32], ptr %1, i64 %indvars.iv39, i64 %indvars.iv
  store i32 %10, ptr %11, align 4, !tbaa !5
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %12 = load i32, ptr @n, align 4, !tbaa !5
  %13 = sext i32 %12 to i64
  %14 = icmp slt i64 %indvars.iv.next, %13
  br i1 %14, label %.lr.ph, label %._crit_edge, !llvm.loop !9

._crit_edge:                                      ; preds = %.lr.ph, %.preheader25.._crit_edge_crit_edge
  %.pre-phi = phi i64 [ %.pre, %.preheader25.._crit_edge_crit_edge ], [ %13, %.lr.ph ]
  %15 = phi i32 [ %6, %.preheader25.._crit_edge_crit_edge ], [ %12, %.lr.ph ]
  %indvars.iv.next40 = add nuw nsw i64 %indvars.iv39, 1
  %16 = icmp slt i64 %indvars.iv.next40, %.pre-phi
  br i1 %16, label %.preheader25, label %.preheader24, !llvm.loop !11

.lr.ph34:                                         ; preds = %.preheader24, %._crit_edge32
  %.033 = phi i32 [ %29, %._crit_edge32 ], [ 1, %.preheader24 ]
  call void @_Z8multiplyPA100_iS0_S0_(ptr noundef %1, ptr noundef nonnull @adj, ptr noundef nonnull %3)
  %17 = load i32, ptr @n, align 4, !tbaa !5
  %18 = icmp sgt i32 %17, 0
  br i1 %18, label %.preheader, label %._crit_edge32

.preheader:                                       ; preds = %.lr.ph34, %._crit_edge30
  %19 = phi i32 [ %27, %._crit_edge30 ], [ %17, %.lr.ph34 ]
  %indvars.iv45 = phi i64 [ %indvars.iv.next46, %._crit_edge30 ], [ 0, %.lr.ph34 ]
  %20 = icmp sgt i32 %19, 0
  br i1 %20, label %.lr.ph29, label %.preheader.._crit_edge30_crit_edge

.preheader.._crit_edge30_crit_edge:               ; preds = %.preheader
  %.pre48 = sext i32 %19 to i64
  br label %._crit_edge30

.lr.ph29:                                         ; preds = %.preheader, %.lr.ph29
  %indvars.iv42 = phi i64 [ %indvars.iv.next43, %.lr.ph29 ], [ 0, %.preheader ]
  %21 = getelementptr inbounds [100 x [100 x i32]], ptr %3, i64 0, i64 %indvars.iv45, i64 %indvars.iv42
  %22 = load i32, ptr %21, align 4, !tbaa !5
  %23 = getelementptr inbounds [100 x i32], ptr %1, i64 %indvars.iv45, i64 %indvars.iv42
  store i32 %22, ptr %23, align 4, !tbaa !5
  %indvars.iv.next43 = add nuw nsw i64 %indvars.iv42, 1
  %24 = load i32, ptr @n, align 4, !tbaa !5
  %25 = sext i32 %24 to i64
  %26 = icmp slt i64 %indvars.iv.next43, %25
  br i1 %26, label %.lr.ph29, label %._crit_edge30, !llvm.loop !13

._crit_edge30:                                    ; preds = %.lr.ph29, %.preheader.._crit_edge30_crit_edge
  %.pre-phi49 = phi i64 [ %.pre48, %.preheader.._crit_edge30_crit_edge ], [ %25, %.lr.ph29 ]
  %27 = phi i32 [ %19, %.preheader.._crit_edge30_crit_edge ], [ %24, %.lr.ph29 ]
  %indvars.iv.next46 = add nuw nsw i64 %indvars.iv45, 1
  %28 = icmp slt i64 %indvars.iv.next46, %.pre-phi49
  br i1 %28, label %.preheader, label %._crit_edge32, !llvm.loop !14

._crit_edge32:                                    ; preds = %._crit_edge30, %.lr.ph34
  %29 = add nuw nsw i32 %.033, 1
  %exitcond.not = icmp eq i32 %29, %0
  br i1 %exitcond.not, label %._crit_edge35, label %.lr.ph34, !llvm.loop !15

._crit_edge35:                                    ; preds = %._crit_edge32, %.preheader24
  call void @llvm.lifetime.end.p0(i64 40000, ptr nonnull %3) #2
  ret void
}

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

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_Z8multiplyPA100_iS0_S0_(ptr noundef, ptr noundef, ptr noundef) local_unnamed_addr #1

attributes #0 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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" }
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 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}
!11 = distinct !{!11, !10, !12}
!12 = !{!"llvm.loop.unswitch.partial.disable"}
!13 = distinct !{!13, !10}
!14 = distinct !{!14, !10, !12}
!15 = distinct !{!15, !10}


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