; LLVM IR from davidomanovic/CFD-FlowSolver :: src/Matrix.ll (ZNK6Matrix9transposeEv)

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

%class.Matrix = type { i64, i64, %"class.std::vector" }
%"class.std::vector" = type { %"struct.std::_Vector_base" }
%"struct.std::_Vector_base" = type { %"struct.std::_Vector_base<std::vector<double>, std::allocator<std::vector<double>>>::_Vector_impl" }
%"struct.std::_Vector_base<std::vector<double>, std::allocator<std::vector<double>>>::_Vector_impl" = type { %"struct.std::_Vector_base<std::vector<double>, std::allocator<std::vector<double>>>::_Vector_impl_data" }
%"struct.std::_Vector_base<std::vector<double>, std::allocator<std::vector<double>>>::_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
declare dso_local noundef nonnull align 8 dereferenceable(8) ptr @_ZN6MatrixclEmm(ptr noundef nonnull align 8 dereferenceable(40), i64 noundef, i64 noundef) #1 align 2

; Function Attrs: mustprogress uwtable
declare dso_local noundef nonnull align 8 dereferenceable(8) ptr @_ZNK6MatrixclEmm(ptr noundef nonnull align 8 dereferenceable(40), i64 noundef, i64 noundef) #1 align 2

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

; Function Attrs: mustprogress uwtable
define dso_local void @_ZNK6Matrix9transposeEv(ptr dead_on_unwind noalias writable sret(%class.Matrix) align 8 %0, ptr noundef nonnull align 8 dereferenceable(40) %1) #1 align 2 personality ptr @__gxx_personality_v0 {
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca i1, align 1
  %6 = alloca i64, align 8
  %7 = alloca i32, align 4
  %8 = alloca i64, align 8
  %9 = alloca ptr, align 8
  %10 = alloca i32, align 4
  store ptr %0, ptr %3, align 8
  store ptr %1, ptr %4, align 8, !tbaa !5
  %11 = load ptr, ptr %4, align 8
  store i1 false, ptr %5, align 1
  %12 = getelementptr inbounds %class.Matrix, ptr %11, i32 0, i32 1
  %13 = load i64, ptr %12, align 8, !tbaa !9
  %14 = getelementptr inbounds %class.Matrix, ptr %11, i32 0, i32 0
  %15 = load i64, ptr %14, align 8, !tbaa !16
  call void @_ZN6MatrixC1Emm(ptr noundef nonnull align 8 dereferenceable(40) %0, i64 noundef %13, i64 noundef %15)
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #3
  store i64 0, ptr %6, align 8, !tbaa !17
  br label %16

16:                                               ; preds = %47, %2
  %17 = load i64, ptr %6, align 8, !tbaa !17
  %18 = getelementptr inbounds %class.Matrix, ptr %11, i32 0, i32 0
  %19 = load i64, ptr %18, align 8, !tbaa !16
  %20 = icmp ult i64 %17, %19
  br i1 %20, label %22, label %21

21:                                               ; preds = %16
  store i32 2, ptr %7, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #3
  br label %50

22:                                               ; preds = %16
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #3
  store i64 0, ptr %8, align 8, !tbaa !17
  br label %23

23:                                               ; preds = %39, %22
  %24 = load i64, ptr %8, align 8, !tbaa !17
  %25 = getelementptr inbounds %class.Matrix, ptr %11, i32 0, i32 1
  %26 = load i64, ptr %25, align 8, !tbaa !9
  %27 = icmp ult i64 %24, %26
  br i1 %27, label %29, label %28

28:                                               ; preds = %23
  store i32 5, ptr %7, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #3
  br label %46

29:                                               ; preds = %23
  %30 = load i64, ptr %6, align 8, !tbaa !17
  %31 = load i64, ptr %8, align 8, !tbaa !17
  %32 = invoke noundef nonnull align 8 dereferenceable(8) ptr @_ZNK6MatrixclEmm(ptr noundef nonnull align 8 dereferenceable(40) %11, i64 noundef %30, i64 noundef %31)
          to label %33 unwind label %42

33:                                               ; preds = %29
  %34 = load double, ptr %32, align 8, !tbaa !18
  %35 = load i64, ptr %8, align 8, !tbaa !17
  %36 = load i64, ptr %6, align 8, !tbaa !17
  %37 = invoke noundef nonnull align 8 dereferenceable(8) ptr @_ZN6MatrixclEmm(ptr noundef nonnull align 8 dereferenceable(40) %0, i64 noundef %35, i64 noundef %36)
          to label %38 unwind label %42

38:                                               ; preds = %33
  store double %34, ptr %37, align 8, !tbaa !18
  br label %39

39:                                               ; preds = %38
  %40 = load i64, ptr %8, align 8, !tbaa !17
  %41 = add i64 %40, 1
  store i64 %41, ptr %8, align 8, !tbaa !17
  br label %23, !llvm.loop !20

42:                                               ; preds = %33, %29
  %43 = landingpad { ptr, i32 }
          cleanup
  %44 = extractvalue { ptr, i32 } %43, 0
  store ptr %44, ptr %9, align 8
  %45 = extractvalue { ptr, i32 } %43, 1
  store i32 %45, ptr %10, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #3
  call void @_ZN6MatrixD2Ev(ptr noundef nonnull align 8 dereferenceable(40) %0) #3
  br label %54

46:                                               ; preds = %28
  br label %47

47:                                               ; preds = %46
  %48 = load i64, ptr %6, align 8, !tbaa !17
  %49 = add i64 %48, 1
  store i64 %49, ptr %6, align 8, !tbaa !17
  br label %16, !llvm.loop !22

50:                                               ; preds = %21
  store i1 true, ptr %5, align 1
  store i32 1, ptr %7, align 4
  %51 = load i1, ptr %5, align 1
  br i1 %51, label %53, label %52

52:                                               ; preds = %50
  call void @_ZN6MatrixD2Ev(ptr noundef nonnull align 8 dereferenceable(40) %0) #3
  br label %53

53:                                               ; preds = %52, %50
  ret void

54:                                               ; preds = %42
  %55 = load ptr, ptr %9, align 8
  %56 = load i32, ptr %10, align 4
  %57 = insertvalue { ptr, i32 } poison, ptr %55, 0
  %58 = insertvalue { ptr, i32 } %57, i32 %56, 1
  resume { ptr, i32 } %58
}

declare void @_ZN6MatrixC1Emm(ptr, i64, i64)

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 = { inlinehint 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, !11, i64 8}
!10 = !{!"_ZTS6Matrix", !11, i64 0, !11, i64 8, !12, i64 16}
!11 = !{!"long", !7, i64 0}
!12 = !{!"_ZTSSt6vectorIS_IdSaIdEESaIS1_EE", !13, i64 0}
!13 = !{!"_ZTSSt12_Vector_baseISt6vectorIdSaIdEESaIS2_EE", !14, i64 0}
!14 = !{!"_ZTSNSt12_Vector_baseISt6vectorIdSaIdEESaIS2_EE12_Vector_implE", !15, i64 0}
!15 = !{!"_ZTSNSt12_Vector_baseISt6vectorIdSaIdEESaIS2_EE17_Vector_impl_dataE", !6, i64 0, !6, i64 8, !6, i64 16}
!16 = !{!10, !11, i64 0}
!17 = !{!11, !11, i64 0}
!18 = !{!19, !19, i64 0}
!19 = !{!"double", !7, i64 0}
!20 = distinct !{!20, !21}
!21 = !{!"llvm.loop.mustprogress"}
!22 = distinct !{!22, !21}


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

%class.Matrix = type { i64, i64, %"class.std::vector" }
%"class.std::vector" = type { %"struct.std::_Vector_base" }
%"struct.std::_Vector_base" = type { %"struct.std::_Vector_base<std::vector<double>, std::allocator<std::vector<double>>>::_Vector_impl" }
%"struct.std::_Vector_base<std::vector<double>, std::allocator<std::vector<double>>>::_Vector_impl" = type { %"struct.std::_Vector_base<std::vector<double>, std::allocator<std::vector<double>>>::_Vector_impl_data" }
%"struct.std::_Vector_base<std::vector<double>, std::allocator<std::vector<double>>>::_Vector_impl_data" = type { ptr, ptr, ptr }

declare i32 @__gxx_personality_v0(...)

; Function Attrs: mustprogress uwtable
declare dso_local noundef nonnull align 8 dereferenceable(8) ptr @_ZN6MatrixclEmm(ptr noundef nonnull align 8 dereferenceable(40), i64 noundef, i64 noundef) local_unnamed_addr #0 align 2

; Function Attrs: mustprogress uwtable
declare dso_local noundef nonnull align 8 dereferenceable(8) ptr @_ZNK6MatrixclEmm(ptr noundef nonnull align 8 dereferenceable(40), i64 noundef, i64 noundef) local_unnamed_addr #0 align 2

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local void @_ZN6MatrixD2Ev(ptr noundef nonnull align 8 dereferenceable(40)) unnamed_addr #1 align 2

; Function Attrs: mustprogress uwtable
define dso_local void @_ZNK6Matrix9transposeEv(ptr dead_on_unwind noalias writable sret(%class.Matrix) align 8 %0, ptr noundef nonnull align 8 dereferenceable(40) %1) local_unnamed_addr #0 align 2 personality ptr @__gxx_personality_v0 {
  %3 = getelementptr inbounds i8, ptr %1, i64 8
  %4 = load i64, ptr %3, align 8, !tbaa !5
  %5 = load i64, ptr %1, align 8, !tbaa !15
  tail call void @_ZN6MatrixC1Emm(ptr noundef nonnull align 8 dereferenceable(40) %0, i64 noundef %4, i64 noundef %5)
  %6 = load i64, ptr %1, align 8, !tbaa !15
  %.not = icmp eq i64 %6, 0
  %7 = load i64, ptr %3, align 8
  %.not15 = icmp eq i64 %7, 0
  %or.cond = select i1 %.not, i1 true, i1 %.not15
  br i1 %or.cond, label %._crit_edge14, label %.preheader

.preheader:                                       ; preds = %2, %._crit_edge
  %8 = phi i64 [ %10, %._crit_edge ], [ %6, %2 ]
  %9 = phi i64 [ %11, %._crit_edge ], [ 1, %2 ]
  %.013 = phi i64 [ %12, %._crit_edge ], [ 0, %2 ]
  %.not16 = icmp eq i64 %9, 0
  br i1 %.not16, label %._crit_edge, label %.lr.ph

._crit_edge.loopexit:                             ; preds = %18
  %.pre = load i64, ptr %1, align 8, !tbaa !15
  br label %._crit_edge

._crit_edge:                                      ; preds = %._crit_edge.loopexit, %.preheader
  %10 = phi i64 [ %.pre, %._crit_edge.loopexit ], [ %8, %.preheader ]
  %11 = phi i64 [ %20, %._crit_edge.loopexit ], [ 0, %.preheader ]
  %12 = add nuw i64 %.013, 1
  %13 = icmp ult i64 %12, %10
  br i1 %13, label %.preheader, label %._crit_edge14, !llvm.loop !16

.lr.ph:                                           ; preds = %.preheader, %18
  %.01112 = phi i64 [ %19, %18 ], [ 0, %.preheader ]
  %14 = invoke noundef nonnull align 8 dereferenceable(8) ptr @_ZNK6MatrixclEmm(ptr noundef nonnull align 8 dereferenceable(40) %1, i64 noundef %.013, i64 noundef %.01112)
          to label %15 unwind label %22

15:                                               ; preds = %.lr.ph
  %16 = load double, ptr %14, align 8, !tbaa !19
  %17 = invoke noundef nonnull align 8 dereferenceable(8) ptr @_ZN6MatrixclEmm(ptr noundef nonnull align 8 dereferenceable(40) %0, i64 noundef %.01112, i64 noundef %.013)
          to label %18 unwind label %22

18:                                               ; preds = %15
  store double %16, ptr %17, align 8, !tbaa !19
  %19 = add nuw i64 %.01112, 1
  %20 = load i64, ptr %3, align 8, !tbaa !5
  %21 = icmp ult i64 %19, %20
  br i1 %21, label %.lr.ph, label %._crit_edge.loopexit, !llvm.loop !21

22:                                               ; preds = %15, %.lr.ph
  %23 = landingpad { ptr, i32 }
          cleanup
  tail call void @_ZN6MatrixD2Ev(ptr noundef nonnull align 8 dereferenceable(40) %0) #2
  resume { ptr, i32 } %23

._crit_edge14:                                    ; preds = %._crit_edge, %2
  ret void
}

declare void @_ZN6MatrixC1Emm(ptr, i64, i64) local_unnamed_addr

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 = { inlinehint 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, !7, i64 8}
!6 = !{!"_ZTS6Matrix", !7, i64 0, !7, i64 8, !10, i64 16}
!7 = !{!"long", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}
!10 = !{!"_ZTSSt6vectorIS_IdSaIdEESaIS1_EE", !11, i64 0}
!11 = !{!"_ZTSSt12_Vector_baseISt6vectorIdSaIdEESaIS2_EE", !12, i64 0}
!12 = !{!"_ZTSNSt12_Vector_baseISt6vectorIdSaIdEESaIS2_EE12_Vector_implE", !13, i64 0}
!13 = !{!"_ZTSNSt12_Vector_baseISt6vectorIdSaIdEESaIS2_EE17_Vector_impl_dataE", !14, i64 0, !14, i64 8, !14, i64 16}
!14 = !{!"any pointer", !8, i64 0}
!15 = !{!6, !7, i64 0}
!16 = distinct !{!16, !17, !18}
!17 = !{!"llvm.loop.mustprogress"}
!18 = !{!"llvm.loop.unswitch.partial.disable"}
!19 = !{!20, !20, i64 0}
!20 = !{!"double", !8, i64 0}
!21 = distinct !{!21, !17}


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