; LLVM IR from Dutta-SD/Numerical_Methods :: Linear_Algebra (Jacobi)

; 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: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #0

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

; Function Attrs: nounwind uwtable
define dso_local void @MatMult(ptr noundef %0, ptr noundef %1, ptr noundef %2) #1 {
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  store ptr %0, ptr %4, align 8, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !5
  store ptr %2, ptr %6, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #3
  store i32 0, ptr %7, align 4, !tbaa !9
  br label %10

10:                                               ; preds = %48, %3
  %11 = load i32, ptr %7, align 4, !tbaa !9
  %12 = icmp slt i32 %11, 4
  br i1 %12, label %13, label %51

13:                                               ; preds = %10
  %14 = load ptr, ptr %6, align 8, !tbaa !5
  %15 = load i32, ptr %7, align 4, !tbaa !9
  %16 = sext i32 %15 to i64
  %17 = getelementptr inbounds [1 x double], ptr %14, i64 %16
  %18 = getelementptr inbounds [1 x double], ptr %17, i64 0, i64 0
  store double 0.000000e+00, ptr %18, align 8, !tbaa !11
  store i32 0, ptr %9, align 4, !tbaa !9
  br label %19

19:                                               ; preds = %44, %13
  %20 = load i32, ptr %9, align 4, !tbaa !9
  %21 = icmp slt i32 %20, 4
  br i1 %21, label %22, label %47

22:                                               ; preds = %19
  %23 = load ptr, ptr %4, align 8, !tbaa !5
  %24 = load i32, ptr %7, align 4, !tbaa !9
  %25 = sext i32 %24 to i64
  %26 = getelementptr inbounds [4 x double], ptr %23, i64 %25
  %27 = load i32, ptr %9, align 4, !tbaa !9
  %28 = sext i32 %27 to i64
  %29 = getelementptr inbounds [4 x double], ptr %26, i64 0, i64 %28
  %30 = load double, ptr %29, align 8, !tbaa !11
  %31 = load ptr, ptr %5, align 8, !tbaa !5
  %32 = load i32, ptr %9, align 4, !tbaa !9
  %33 = sext i32 %32 to i64
  %34 = getelementptr inbounds [1 x double], ptr %31, i64 %33
  %35 = getelementptr inbounds [1 x double], ptr %34, i64 0, i64 0
  %36 = load double, ptr %35, align 8, !tbaa !11
  %37 = load ptr, ptr %6, align 8, !tbaa !5
  %38 = load i32, ptr %7, align 4, !tbaa !9
  %39 = sext i32 %38 to i64
  %40 = getelementptr inbounds [1 x double], ptr %37, i64 %39
  %41 = getelementptr inbounds [1 x double], ptr %40, i64 0, i64 0
  %42 = load double, ptr %41, align 8, !tbaa !11
  %43 = call double @llvm.fmuladd.f64(double %30, double %36, double %42)
  store double %43, ptr %41, align 8, !tbaa !11
  br label %44

44:                                               ; preds = %22
  %45 = load i32, ptr %9, align 4, !tbaa !9
  %46 = add nsw i32 %45, 1
  store i32 %46, ptr %9, align 4, !tbaa !9
  br label %19, !llvm.loop !13

47:                                               ; preds = %19
  br label %48

48:                                               ; preds = %47
  %49 = load i32, ptr %7, align 4, !tbaa !9
  %50 = add nsw i32 %49, 1
  store i32 %50, ptr %7, align 4, !tbaa !9
  br label %10, !llvm.loop !15

51:                                               ; preds = %10
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #3
  ret void
}

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare double @llvm.fmuladd.f64(double, double, double) #2

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
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/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"double", !7, i64 0}
!13 = distinct !{!13, !14}
!14 = !{!"llvm.loop.mustprogress"}
!15 = distinct !{!15, !14}


; 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 nofree norecurse nosync nounwind willreturn memory(argmem: readwrite) uwtable
define dso_local void @MatMult(ptr nocapture noundef readonly %0, ptr nocapture noundef readonly %1, ptr nocapture noundef writeonly %2) local_unnamed_addr #0 {
  store double 0.000000e+00, ptr %2, align 8, !tbaa !5
  %4 = load double, ptr %0, align 8, !tbaa !5
  %5 = load double, ptr %1, align 8, !tbaa !5
  %6 = tail call double @llvm.fmuladd.f64(double %4, double %5, double 0.000000e+00)
  store double %6, ptr %2, align 8, !tbaa !5
  %7 = getelementptr inbounds i8, ptr %0, i64 8
  %8 = load double, ptr %7, align 8, !tbaa !5
  %9 = getelementptr inbounds i8, ptr %1, i64 8
  %10 = load double, ptr %9, align 8, !tbaa !5
  %11 = tail call double @llvm.fmuladd.f64(double %8, double %10, double %6)
  store double %11, ptr %2, align 8, !tbaa !5
  %12 = getelementptr inbounds i8, ptr %0, i64 16
  %13 = load double, ptr %12, align 8, !tbaa !5
  %14 = getelementptr inbounds i8, ptr %1, i64 16
  %15 = load double, ptr %14, align 8, !tbaa !5
  %16 = tail call double @llvm.fmuladd.f64(double %13, double %15, double %11)
  store double %16, ptr %2, align 8, !tbaa !5
  %17 = getelementptr inbounds i8, ptr %0, i64 24
  %18 = load double, ptr %17, align 8, !tbaa !5
  %19 = getelementptr inbounds i8, ptr %1, i64 24
  %20 = load double, ptr %19, align 8, !tbaa !5
  %21 = tail call double @llvm.fmuladd.f64(double %18, double %20, double %16)
  store double %21, ptr %2, align 8, !tbaa !5
  %22 = getelementptr inbounds i8, ptr %2, i64 8
  store double 0.000000e+00, ptr %22, align 8, !tbaa !5
  %23 = getelementptr inbounds i8, ptr %0, i64 32
  %24 = load double, ptr %23, align 8, !tbaa !5
  %25 = load double, ptr %1, align 8, !tbaa !5
  %26 = tail call double @llvm.fmuladd.f64(double %24, double %25, double 0.000000e+00)
  store double %26, ptr %22, align 8, !tbaa !5
  %27 = getelementptr inbounds i8, ptr %0, i64 40
  %28 = load double, ptr %27, align 8, !tbaa !5
  %29 = load double, ptr %9, align 8, !tbaa !5
  %30 = tail call double @llvm.fmuladd.f64(double %28, double %29, double %26)
  store double %30, ptr %22, align 8, !tbaa !5
  %31 = getelementptr inbounds i8, ptr %0, i64 48
  %32 = load double, ptr %31, align 8, !tbaa !5
  %33 = load double, ptr %14, align 8, !tbaa !5
  %34 = tail call double @llvm.fmuladd.f64(double %32, double %33, double %30)
  store double %34, ptr %22, align 8, !tbaa !5
  %35 = getelementptr inbounds i8, ptr %0, i64 56
  %36 = load double, ptr %35, align 8, !tbaa !5
  %37 = load double, ptr %19, align 8, !tbaa !5
  %38 = tail call double @llvm.fmuladd.f64(double %36, double %37, double %34)
  store double %38, ptr %22, align 8, !tbaa !5
  %39 = getelementptr inbounds i8, ptr %2, i64 16
  store double 0.000000e+00, ptr %39, align 8, !tbaa !5
  %40 = getelementptr inbounds i8, ptr %0, i64 64
  %41 = load double, ptr %40, align 8, !tbaa !5
  %42 = load double, ptr %1, align 8, !tbaa !5
  %43 = tail call double @llvm.fmuladd.f64(double %41, double %42, double 0.000000e+00)
  store double %43, ptr %39, align 8, !tbaa !5
  %44 = getelementptr inbounds i8, ptr %0, i64 72
  %45 = load double, ptr %44, align 8, !tbaa !5
  %46 = load double, ptr %9, align 8, !tbaa !5
  %47 = tail call double @llvm.fmuladd.f64(double %45, double %46, double %43)
  store double %47, ptr %39, align 8, !tbaa !5
  %48 = getelementptr inbounds i8, ptr %0, i64 80
  %49 = load double, ptr %48, align 8, !tbaa !5
  %50 = load double, ptr %14, align 8, !tbaa !5
  %51 = tail call double @llvm.fmuladd.f64(double %49, double %50, double %47)
  store double %51, ptr %39, align 8, !tbaa !5
  %52 = getelementptr inbounds i8, ptr %0, i64 88
  %53 = load double, ptr %52, align 8, !tbaa !5
  %54 = load double, ptr %19, align 8, !tbaa !5
  %55 = tail call double @llvm.fmuladd.f64(double %53, double %54, double %51)
  store double %55, ptr %39, align 8, !tbaa !5
  %56 = getelementptr inbounds i8, ptr %2, i64 24
  store double 0.000000e+00, ptr %56, align 8, !tbaa !5
  %57 = getelementptr inbounds i8, ptr %0, i64 96
  %58 = load double, ptr %57, align 8, !tbaa !5
  %59 = load double, ptr %1, align 8, !tbaa !5
  %60 = tail call double @llvm.fmuladd.f64(double %58, double %59, double 0.000000e+00)
  store double %60, ptr %56, align 8, !tbaa !5
  %61 = getelementptr inbounds i8, ptr %0, i64 104
  %62 = load double, ptr %61, align 8, !tbaa !5
  %63 = load double, ptr %9, align 8, !tbaa !5
  %64 = tail call double @llvm.fmuladd.f64(double %62, double %63, double %60)
  store double %64, ptr %56, align 8, !tbaa !5
  %65 = getelementptr inbounds i8, ptr %0, i64 112
  %66 = load double, ptr %65, align 8, !tbaa !5
  %67 = load double, ptr %14, align 8, !tbaa !5
  %68 = tail call double @llvm.fmuladd.f64(double %66, double %67, double %64)
  store double %68, ptr %56, align 8, !tbaa !5
  %69 = getelementptr inbounds i8, ptr %0, i64 120
  %70 = load double, ptr %69, align 8, !tbaa !5
  %71 = load double, ptr %19, align 8, !tbaa !5
  %72 = tail call double @llvm.fmuladd.f64(double %70, double %71, double %68)
  store double %72, ptr %56, align 8, !tbaa !5
  ret void
}

; Function Attrs: mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare double @llvm.fmuladd.f64(double, double, double) #1

attributes #0 = { mustprogress nofree norecurse nosync nounwind willreturn memory(argmem: readwrite) 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 speculatable willreturn memory(none) }

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


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