; LLVM IR from Gripnook/numerical-methods :: Assignment1/report/src (finite-differences)

; 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.std::pair.12" = type <{ %"class.Numeric::Matrix", i32, [4 x i8] }>
%"class.Numeric::Matrix" = type { i32, i32, %"class.std::vector" }
%"class.std::vector" = type { %"struct.std::_Vector_base" }
%"struct.std::_Vector_base" = type { %"struct.std::_Vector_base<FiniteDifferences::Node, std::allocator<FiniteDifferences::Node>>::_Vector_impl" }
%"struct.std::_Vector_base<FiniteDifferences::Node, std::allocator<FiniteDifferences::Node>>::_Vector_impl" = type { %"struct.std::_Vector_base<FiniteDifferences::Node, std::allocator<FiniteDifferences::Node>>::_Vector_impl_data" }
%"struct.std::_Vector_base<FiniteDifferences::Node, std::allocator<FiniteDifferences::Node>>::_Vector_impl_data" = type { ptr, ptr, ptr }
%"class.std::vector.14" = type { %"struct.std::_Vector_base.15" }
%"struct.std::_Vector_base.15" = type { %"struct.std::_Vector_base<FiniteDifferences::Node_internal, std::allocator<FiniteDifferences::Node_internal>>::_Vector_impl" }
%"struct.std::_Vector_base<FiniteDifferences::Node_internal, std::allocator<FiniteDifferences::Node_internal>>::_Vector_impl" = type { %"struct.std::_Vector_base<FiniteDifferences::Node_internal, std::allocator<FiniteDifferences::Node_internal>>::_Vector_impl_data" }
%"struct.std::_Vector_base<FiniteDifferences::Node_internal, std::allocator<FiniteDifferences::Node_internal>>::_Vector_impl_data" = type { ptr, ptr, ptr }

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

declare i32 @__gxx_personality_v0(...)

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

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN17FiniteDifferences3sorEN7Numeric6MatrixINS_4NodeEEERKSt6vectorISt4pairIiiESaIS6_EEd(ptr dead_on_unwind noalias writable sret(%"struct.std::pair.12") align 8 %0, ptr noundef %1, ptr noundef nonnull align 8 dereferenceable(24) %2, double noundef %3) #1 personality ptr @__gxx_personality_v0 {
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca double, align 8
  %9 = alloca %"class.std::vector.14", align 8
  %10 = alloca i32, align 4
  %11 = alloca ptr, align 8
  %12 = alloca i32, align 4
  store ptr %0, ptr %5, align 8
  store ptr %1, ptr %6, align 8, !tbaa !5
  store ptr %2, ptr %7, align 8, !tbaa !5
  store double %3, ptr %8, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 24, ptr %9) #3
  %13 = load ptr, ptr %7, align 8, !tbaa !5
  call void @_ZN17FiniteDifferences10precomputeERKN7Numeric6MatrixINS_4NodeEEERKSt6vectorISt4pairIiiESaIS8_EE(ptr dead_on_unwind writable sret(%"class.std::vector.14") align 8 %9, ptr noundef nonnull align 8 dereferenceable(32) %1, ptr noundef nonnull align 8 dereferenceable(24) %13)
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #3
  store i32 0, ptr %10, align 4, !tbaa !11
  br label %14

14:                                               ; preds = %23, %4
  %15 = load i32, ptr %10, align 4, !tbaa !11
  %16 = add nsw i32 %15, 1
  store i32 %16, ptr %10, align 4, !tbaa !11
  %17 = load ptr, ptr %7, align 8, !tbaa !5
  %18 = load double, ptr %8, align 8, !tbaa !9
  invoke void @_ZN17FiniteDifferences9updateSorERN7Numeric6MatrixINS_4NodeEEERKSt6vectorISt4pairIiiESaIS7_EERKS5_INS_13Node_internalESaISC_EEd(ptr noundef nonnull align 8 dereferenceable(32) %1, ptr noundef nonnull align 8 dereferenceable(24) %17, ptr noundef nonnull align 8 dereferenceable(24) %9, double noundef %18)
          to label %19 unwind label %27

19:                                               ; preds = %14
  br label %20

20:                                               ; preds = %19
  %21 = load ptr, ptr %7, align 8, !tbaa !5
  %22 = invoke noundef zeroext i1 @_ZN17FiniteDifferences4stopERKN7Numeric6MatrixINS_4NodeEEERKSt6vectorISt4pairIiiESaIS8_EERKS6_INS_13Node_internalESaISD_EE(ptr noundef nonnull align 8 dereferenceable(32) %1, ptr noundef nonnull align 8 dereferenceable(24) %21, ptr noundef nonnull align 8 dereferenceable(24) %9)
          to label %23 unwind label %27

23:                                               ; preds = %20
  %24 = xor i1 %22, true
  br i1 %24, label %14, label %25, !llvm.loop !13

25:                                               ; preds = %23
  invoke void @_ZNSt4pairIN7Numeric6MatrixIN17FiniteDifferences4NodeEEEiEC2IRS4_RiTnNSt9enable_ifIXaaclsr5_PCCPE22_MoveConstructiblePairIT_T0_EEclsr5_PCCPE30_ImplicitlyMoveConvertiblePairISA_SB_EEEbE4typeELb1EEEOSA_OSB_(ptr noundef nonnull align 8 dereferenceable(36) %0, ptr noundef nonnull align 8 dereferenceable(32) %1, ptr noundef nonnull align 4 dereferenceable(4) %10)
          to label %26 unwind label %27

26:                                               ; preds = %25
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #3
  call void @_ZNSt6vectorIN17FiniteDifferences13Node_internalESaIS1_EED2Ev(ptr noundef nonnull align 8 dereferenceable(24) %9) #3
  call void @llvm.lifetime.end.p0(i64 24, ptr %9) #3
  ret void

27:                                               ; preds = %25, %20, %14
  %28 = landingpad { ptr, i32 }
          cleanup
  %29 = extractvalue { ptr, i32 } %28, 0
  store ptr %29, ptr %11, align 8
  %30 = extractvalue { ptr, i32 } %28, 1
  store i32 %30, ptr %12, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #3
  call void @_ZNSt6vectorIN17FiniteDifferences13Node_internalESaIS1_EED2Ev(ptr noundef nonnull align 8 dereferenceable(24) %9) #3
  call void @llvm.lifetime.end.p0(i64 24, ptr %9) #3
  br label %31

31:                                               ; preds = %27
  %32 = load ptr, ptr %11, align 8
  %33 = load i32, ptr %12, align 4
  %34 = insertvalue { ptr, i32 } poison, ptr %32, 0
  %35 = insertvalue { ptr, i32 } %34, i32 %33, 1
  resume { ptr, i32 } %35
}

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN17FiniteDifferences10precomputeERKN7Numeric6MatrixINS_4NodeEEERKSt6vectorISt4pairIiiESaIS8_EE(ptr dead_on_unwind noalias writable sret(%"class.std::vector.14") align 8, ptr noundef nonnull align 8 dereferenceable(32), ptr noundef nonnull align 8 dereferenceable(24)) #1

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN17FiniteDifferences9updateSorERN7Numeric6MatrixINS_4NodeEEERKSt6vectorISt4pairIiiESaIS7_EERKS5_INS_13Node_internalESaISC_EEd(ptr noundef nonnull align 8 dereferenceable(32), ptr noundef nonnull align 8 dereferenceable(24), ptr noundef nonnull align 8 dereferenceable(24), double noundef) #1

; Function Attrs: mustprogress uwtable
declare dso_local noundef zeroext i1 @_ZN17FiniteDifferences4stopERKN7Numeric6MatrixINS_4NodeEEERKSt6vectorISt4pairIiiESaIS8_EERKS6_INS_13Node_internalESaISD_EE(ptr noundef nonnull align 8 dereferenceable(32), ptr noundef nonnull align 8 dereferenceable(24), ptr noundef nonnull align 8 dereferenceable(24)) #1

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZNSt4pairIN7Numeric6MatrixIN17FiniteDifferences4NodeEEEiEC2IRS4_RiTnNSt9enable_ifIXaaclsr5_PCCPE22_MoveConstructiblePairIT_T0_EEclsr5_PCCPE30_ImplicitlyMoveConvertiblePairISA_SB_EEEbE4typeELb1EEEOSA_OSB_(ptr noundef nonnull align 8 dereferenceable(36), ptr noundef nonnull align 8 dereferenceable(32), ptr noundef nonnull align 4 dereferenceable(4)) unnamed_addr #1 align 2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZNSt6vectorIN17FiniteDifferences13Node_internalESaIS1_EED2Ev(ptr noundef nonnull align 8 dereferenceable(24)) unnamed_addr #2 align 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 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"double", !7, i64 0}
!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.std::pair.12" = type <{ %"class.Numeric::Matrix", i32, [4 x i8] }>
%"class.Numeric::Matrix" = type { i32, i32, %"class.std::vector" }
%"class.std::vector" = type { %"struct.std::_Vector_base" }
%"struct.std::_Vector_base" = type { %"struct.std::_Vector_base<FiniteDifferences::Node, std::allocator<FiniteDifferences::Node>>::_Vector_impl" }
%"struct.std::_Vector_base<FiniteDifferences::Node, std::allocator<FiniteDifferences::Node>>::_Vector_impl" = type { %"struct.std::_Vector_base<FiniteDifferences::Node, std::allocator<FiniteDifferences::Node>>::_Vector_impl_data" }
%"struct.std::_Vector_base<FiniteDifferences::Node, std::allocator<FiniteDifferences::Node>>::_Vector_impl_data" = type { ptr, ptr, ptr }
%"class.std::vector.14" = type { %"struct.std::_Vector_base.15" }
%"struct.std::_Vector_base.15" = type { %"struct.std::_Vector_base<FiniteDifferences::Node_internal, std::allocator<FiniteDifferences::Node_internal>>::_Vector_impl" }
%"struct.std::_Vector_base<FiniteDifferences::Node_internal, std::allocator<FiniteDifferences::Node_internal>>::_Vector_impl" = type { %"struct.std::_Vector_base<FiniteDifferences::Node_internal, std::allocator<FiniteDifferences::Node_internal>>::_Vector_impl_data" }
%"struct.std::_Vector_base<FiniteDifferences::Node_internal, std::allocator<FiniteDifferences::Node_internal>>::_Vector_impl_data" = type { ptr, ptr, ptr }

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

declare i32 @__gxx_personality_v0(...)

; 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 uwtable
define dso_local void @_ZN17FiniteDifferences3sorEN7Numeric6MatrixINS_4NodeEEERKSt6vectorISt4pairIiiESaIS6_EEd(ptr dead_on_unwind noalias writable sret(%"struct.std::pair.12") align 8 %0, ptr noundef nonnull %1, ptr noundef nonnull align 8 dereferenceable(24) %2, double noundef %3) local_unnamed_addr #1 personality ptr @__gxx_personality_v0 {
  %5 = alloca %"class.std::vector.14", align 8
  %6 = alloca i32, align 4
  call void @llvm.lifetime.start.p0(i64 24, ptr nonnull %5) #3
  call void @_ZN17FiniteDifferences10precomputeERKN7Numeric6MatrixINS_4NodeEEERKSt6vectorISt4pairIiiESaIS8_EE(ptr dead_on_unwind nonnull writable sret(%"class.std::vector.14") align 8 %5, ptr noundef nonnull align 8 dereferenceable(32) %1, ptr noundef nonnull align 8 dereferenceable(24) %2)
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %6) #3
  br label %7

7:                                                ; preds = %12, %4
  %8 = phi i32 [ %9, %12 ], [ 0, %4 ]
  %9 = add nuw nsw i32 %8, 1
  store i32 %9, ptr %6, align 4, !tbaa !5
  invoke void @_ZN17FiniteDifferences9updateSorERN7Numeric6MatrixINS_4NodeEEERKSt6vectorISt4pairIiiESaIS7_EERKS5_INS_13Node_internalESaISC_EEd(ptr noundef nonnull align 8 dereferenceable(32) %1, ptr noundef nonnull align 8 dereferenceable(24) %2, ptr noundef nonnull align 8 dereferenceable(24) %5, double noundef %3)
          to label %10 unwind label %.loopexit

10:                                               ; preds = %7
  %11 = invoke noundef zeroext i1 @_ZN17FiniteDifferences4stopERKN7Numeric6MatrixINS_4NodeEEERKSt6vectorISt4pairIiiESaIS8_EERKS6_INS_13Node_internalESaISD_EE(ptr noundef nonnull align 8 dereferenceable(32) %1, ptr noundef nonnull align 8 dereferenceable(24) %2, ptr noundef nonnull align 8 dereferenceable(24) %5)
          to label %12 unwind label %.loopexit

12:                                               ; preds = %10
  br i1 %11, label %13, label %7, !llvm.loop !9

13:                                               ; preds = %12
  invoke void @_ZNSt4pairIN7Numeric6MatrixIN17FiniteDifferences4NodeEEEiEC2IRS4_RiTnNSt9enable_ifIXaaclsr5_PCCPE22_MoveConstructiblePairIT_T0_EEclsr5_PCCPE30_ImplicitlyMoveConvertiblePairISA_SB_EEEbE4typeELb1EEEOSA_OSB_(ptr noundef nonnull align 8 dereferenceable(36) %0, ptr noundef nonnull align 8 dereferenceable(32) %1, ptr noundef nonnull align 4 dereferenceable(4) %6)
          to label %14 unwind label %.loopexit.split-lp

14:                                               ; preds = %13
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %6) #3
  call void @_ZNSt6vectorIN17FiniteDifferences13Node_internalESaIS1_EED2Ev(ptr noundef nonnull align 8 dereferenceable(24) %5) #3
  call void @llvm.lifetime.end.p0(i64 24, ptr nonnull %5) #3
  ret void

.loopexit:                                        ; preds = %7, %10
  %lpad.loopexit = landingpad { ptr, i32 }
          cleanup
  br label %15

.loopexit.split-lp:                               ; preds = %13
  %lpad.loopexit.split-lp = landingpad { ptr, i32 }
          cleanup
  br label %15

15:                                               ; preds = %.loopexit.split-lp, %.loopexit
  %lpad.phi = phi { ptr, i32 } [ %lpad.loopexit, %.loopexit ], [ %lpad.loopexit.split-lp, %.loopexit.split-lp ]
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %6) #3
  call void @_ZNSt6vectorIN17FiniteDifferences13Node_internalESaIS1_EED2Ev(ptr noundef nonnull align 8 dereferenceable(24) %5) #3
  call void @llvm.lifetime.end.p0(i64 24, ptr nonnull %5) #3
  resume { ptr, i32 } %lpad.phi
}

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN17FiniteDifferences10precomputeERKN7Numeric6MatrixINS_4NodeEEERKSt6vectorISt4pairIiiESaIS8_EE(ptr dead_on_unwind noalias writable sret(%"class.std::vector.14") align 8, ptr noundef nonnull align 8 dereferenceable(32), ptr noundef nonnull align 8 dereferenceable(24)) local_unnamed_addr #1

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN17FiniteDifferences9updateSorERN7Numeric6MatrixINS_4NodeEEERKSt6vectorISt4pairIiiESaIS7_EERKS5_INS_13Node_internalESaISC_EEd(ptr noundef nonnull align 8 dereferenceable(32), ptr noundef nonnull align 8 dereferenceable(24), ptr noundef nonnull align 8 dereferenceable(24), double noundef) local_unnamed_addr #1

; Function Attrs: mustprogress uwtable
declare dso_local noundef zeroext i1 @_ZN17FiniteDifferences4stopERKN7Numeric6MatrixINS_4NodeEEERKSt6vectorISt4pairIiiESaIS8_EERKS6_INS_13Node_internalESaISD_EE(ptr noundef nonnull align 8 dereferenceable(32), ptr noundef nonnull align 8 dereferenceable(24), ptr noundef nonnull align 8 dereferenceable(24)) local_unnamed_addr #1

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZNSt4pairIN7Numeric6MatrixIN17FiniteDifferences4NodeEEEiEC2IRS4_RiTnNSt9enable_ifIXaaclsr5_PCCPE22_MoveConstructiblePairIT_T0_EEclsr5_PCCPE30_ImplicitlyMoveConvertiblePairISA_SB_EEEbE4typeELb1EEEOSA_OSB_(ptr noundef nonnull align 8 dereferenceable(36), ptr noundef nonnull align 8 dereferenceable(32), ptr noundef nonnull align 4 dereferenceable(4)) unnamed_addr #1 align 2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZNSt6vectorIN17FiniteDifferences13Node_internalESaIS1_EED2Ev(ptr noundef nonnull align 8 dereferenceable(24)) unnamed_addr #2 align 2

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


; Effective O3 passes: DSEPass,EarlyCSEPass,GVNPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,LoopSimplifyPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass