; LLVM IR from arasgungore/EE242-projects :: ComputingEigenvaluesAndEigenvectors/main.ll (ZNK6Matrix12getTransposeEv)

; 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 { i32, i32, ptr }

; 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: mustprogress uwtable
define dso_local void @_ZNK6Matrix12getTransposeEv(ptr dead_on_unwind noalias writable sret(%class.Matrix) align 8 %0, ptr noundef nonnull align 8 dereferenceable(16) %1) #1 align 2 {
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca i1, align 1
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  store ptr %0, ptr %3, align 8
  store ptr %1, ptr %4, align 8, !tbaa !5
  %9 = load ptr, ptr %4, align 8
  store i1 false, ptr %5, align 1
  %10 = getelementptr inbounds %class.Matrix, ptr %9, i32 0, i32 1
  %11 = load i32, ptr %10, align 4, !tbaa !9
  %12 = getelementptr inbounds %class.Matrix, ptr %9, i32 0, i32 0
  %13 = load i32, ptr %12, align 8, !tbaa !12
  call void @_ZN6MatrixC1Eii(ptr noundef nonnull align 8 dereferenceable(16) %0, i32 noundef %11, i32 noundef %13)
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #2
  store i32 0, ptr %6, align 4, !tbaa !13
  br label %14

14:                                               ; preds = %51, %2
  %15 = load i32, ptr %6, align 4, !tbaa !13
  %16 = getelementptr inbounds %class.Matrix, ptr %9, i32 0, i32 0
  %17 = load i32, ptr %16, align 8, !tbaa !12
  %18 = icmp slt i32 %15, %17
  br i1 %18, label %20, label %19

19:                                               ; preds = %14
  store i32 2, ptr %7, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #2
  br label %54

20:                                               ; preds = %14
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #2
  store i32 0, ptr %8, align 4, !tbaa !13
  br label %21

21:                                               ; preds = %47, %20
  %22 = load i32, ptr %8, align 4, !tbaa !13
  %23 = getelementptr inbounds %class.Matrix, ptr %9, i32 0, i32 1
  %24 = load i32, ptr %23, align 4, !tbaa !9
  %25 = icmp slt i32 %22, %24
  br i1 %25, label %27, label %26

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

27:                                               ; preds = %21
  %28 = getelementptr inbounds %class.Matrix, ptr %9, i32 0, i32 2
  %29 = load ptr, ptr %28, align 8, !tbaa !14
  %30 = load i32, ptr %6, align 4, !tbaa !13
  %31 = sext i32 %30 to i64
  %32 = getelementptr inbounds ptr, ptr %29, i64 %31
  %33 = load ptr, ptr %32, align 8, !tbaa !5
  %34 = load i32, ptr %8, align 4, !tbaa !13
  %35 = sext i32 %34 to i64
  %36 = getelementptr inbounds double, ptr %33, i64 %35
  %37 = load double, ptr %36, align 8, !tbaa !15
  %38 = getelementptr inbounds %class.Matrix, ptr %0, i32 0, i32 2
  %39 = load ptr, ptr %38, align 8, !tbaa !14
  %40 = load i32, ptr %8, align 4, !tbaa !13
  %41 = sext i32 %40 to i64
  %42 = getelementptr inbounds ptr, ptr %39, i64 %41
  %43 = load ptr, ptr %42, align 8, !tbaa !5
  %44 = load i32, ptr %6, align 4, !tbaa !13
  %45 = sext i32 %44 to i64
  %46 = getelementptr inbounds double, ptr %43, i64 %45
  store double %37, ptr %46, align 8, !tbaa !15
  br label %47

47:                                               ; preds = %27
  %48 = load i32, ptr %8, align 4, !tbaa !13
  %49 = add nsw i32 %48, 1
  store i32 %49, ptr %8, align 4, !tbaa !13
  br label %21, !llvm.loop !17

50:                                               ; preds = %26
  br label %51

51:                                               ; preds = %50
  %52 = load i32, ptr %6, align 4, !tbaa !13
  %53 = add nsw i32 %52, 1
  store i32 %53, ptr %6, align 4, !tbaa !13
  br label %14, !llvm.loop !19

54:                                               ; preds = %19
  store i1 true, ptr %5, align 1
  store i32 1, ptr %7, align 4
  %55 = load i1, ptr %5, align 1
  br i1 %55, label %57, label %56

56:                                               ; preds = %54
  call void @_ZN6MatrixD1Ev(ptr noundef nonnull align 8 dereferenceable(16) %0) #2
  br label %57

57:                                               ; preds = %56, %54
  ret void
}

declare void @_ZN6MatrixC1Eii(ptr, i32, i32)

declare void @_ZN6MatrixD1Ev(ptr)

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 = { 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 4}
!10 = !{!"_ZTS6Matrix", !11, i64 0, !11, i64 4, !6, i64 8}
!11 = !{!"int", !7, i64 0}
!12 = !{!10, !11, i64 0}
!13 = !{!11, !11, i64 0}
!14 = !{!10, !6, i64 8}
!15 = !{!16, !16, i64 0}
!16 = !{!"double", !7, i64 0}
!17 = distinct !{!17, !18}
!18 = !{!"llvm.loop.mustprogress"}
!19 = distinct !{!19, !18}


; 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 { i32, i32, ptr }

; Function Attrs: mustprogress uwtable
define dso_local void @_ZNK6Matrix12getTransposeEv(ptr dead_on_unwind noalias writable sret(%class.Matrix) align 8 %0, ptr nocapture noundef nonnull readonly align 8 dereferenceable(16) %1) local_unnamed_addr #0 align 2 {
  %3 = getelementptr inbounds i8, ptr %1, i64 4
  %4 = load i32, ptr %3, align 4, !tbaa !5
  %5 = load i32, ptr %1, align 8, !tbaa !11
  tail call void @_ZN6MatrixC1Eii(ptr noundef nonnull align 8 dereferenceable(16) %0, i32 noundef %4, i32 noundef %5)
  %6 = load i32, ptr %1, align 8, !tbaa !11
  %7 = icmp sgt i32 %6, 0
  br i1 %7, label %.preheader.lr.ph, label %._crit_edge12

.preheader.lr.ph:                                 ; preds = %2
  %8 = load i32, ptr %3, align 4, !tbaa !5
  %9 = icmp sgt i32 %8, 0
  %10 = getelementptr inbounds i8, ptr %1, i64 8
  %11 = load ptr, ptr %10, align 8
  %12 = getelementptr inbounds i8, ptr %0, i64 8
  %13 = load ptr, ptr %12, align 8
  br i1 %9, label %.preheader.us.preheader, label %._crit_edge12

.preheader.us.preheader:                          ; preds = %.preheader.lr.ph
  %wide.trip.count18 = zext nneg i32 %6 to i64
  %wide.trip.count = zext nneg i32 %8 to i64
  %xtraiter = and i64 %wide.trip.count, 3
  %14 = icmp ult i32 %8, 4
  %unroll_iter = and i64 %wide.trip.count, 2147483644
  %lcmp.mod.not = icmp eq i64 %xtraiter, 0
  br label %.preheader.us

.preheader.us:                                    ; preds = %.preheader.us.preheader, %._crit_edge.us
  %indvars.iv15 = phi i64 [ 0, %.preheader.us.preheader ], [ %indvars.iv.next16, %._crit_edge.us ]
  %15 = getelementptr inbounds ptr, ptr %11, i64 %indvars.iv15
  %16 = load ptr, ptr %15, align 8, !tbaa !12
  br i1 %14, label %._crit_edge.us.unr-lcssa, label %.preheader.us.new

.preheader.us.new:                                ; preds = %.preheader.us, %.preheader.us.new
  %indvars.iv = phi i64 [ %indvars.iv.next.3, %.preheader.us.new ], [ 0, %.preheader.us ]
  %niter = phi i64 [ %niter.next.3, %.preheader.us.new ], [ 0, %.preheader.us ]
  %17 = getelementptr inbounds double, ptr %16, i64 %indvars.iv
  %18 = load double, ptr %17, align 8, !tbaa !13
  %19 = getelementptr inbounds ptr, ptr %13, i64 %indvars.iv
  %20 = load ptr, ptr %19, align 8, !tbaa !12
  %21 = getelementptr inbounds double, ptr %20, i64 %indvars.iv15
  store double %18, ptr %21, align 8, !tbaa !13
  %indvars.iv.next = or disjoint i64 %indvars.iv, 1
  %22 = getelementptr inbounds double, ptr %16, i64 %indvars.iv.next
  %23 = load double, ptr %22, align 8, !tbaa !13
  %24 = getelementptr inbounds ptr, ptr %13, i64 %indvars.iv.next
  %25 = load ptr, ptr %24, align 8, !tbaa !12
  %26 = getelementptr inbounds double, ptr %25, i64 %indvars.iv15
  store double %23, ptr %26, align 8, !tbaa !13
  %indvars.iv.next.1 = or disjoint i64 %indvars.iv, 2
  %27 = getelementptr inbounds double, ptr %16, i64 %indvars.iv.next.1
  %28 = load double, ptr %27, align 8, !tbaa !13
  %29 = getelementptr inbounds ptr, ptr %13, i64 %indvars.iv.next.1
  %30 = load ptr, ptr %29, align 8, !tbaa !12
  %31 = getelementptr inbounds double, ptr %30, i64 %indvars.iv15
  store double %28, ptr %31, align 8, !tbaa !13
  %indvars.iv.next.2 = or disjoint i64 %indvars.iv, 3
  %32 = getelementptr inbounds double, ptr %16, i64 %indvars.iv.next.2
  %33 = load double, ptr %32, align 8, !tbaa !13
  %34 = getelementptr inbounds ptr, ptr %13, i64 %indvars.iv.next.2
  %35 = load ptr, ptr %34, align 8, !tbaa !12
  %36 = getelementptr inbounds double, ptr %35, i64 %indvars.iv15
  store double %33, ptr %36, align 8, !tbaa !13
  %indvars.iv.next.3 = add nuw nsw i64 %indvars.iv, 4
  %niter.next.3 = add i64 %niter, 4
  %niter.ncmp.3 = icmp eq i64 %niter.next.3, %unroll_iter
  br i1 %niter.ncmp.3, label %._crit_edge.us.unr-lcssa, label %.preheader.us.new, !llvm.loop !15

._crit_edge.us.unr-lcssa:                         ; preds = %.preheader.us.new, %.preheader.us
  %indvars.iv.unr = phi i64 [ 0, %.preheader.us ], [ %indvars.iv.next.3, %.preheader.us.new ]
  br i1 %lcmp.mod.not, label %._crit_edge.us, label %.epil.preheader

.epil.preheader:                                  ; preds = %._crit_edge.us.unr-lcssa, %.epil.preheader
  %indvars.iv.epil = phi i64 [ %indvars.iv.next.epil, %.epil.preheader ], [ %indvars.iv.unr, %._crit_edge.us.unr-lcssa ]
  %epil.iter = phi i64 [ %epil.iter.next, %.epil.preheader ], [ 0, %._crit_edge.us.unr-lcssa ]
  %37 = getelementptr inbounds double, ptr %16, i64 %indvars.iv.epil
  %38 = load double, ptr %37, align 8, !tbaa !13
  %39 = getelementptr inbounds ptr, ptr %13, i64 %indvars.iv.epil
  %40 = load ptr, ptr %39, align 8, !tbaa !12
  %41 = getelementptr inbounds double, ptr %40, i64 %indvars.iv15
  store double %38, ptr %41, align 8, !tbaa !13
  %indvars.iv.next.epil = add nuw nsw i64 %indvars.iv.epil, 1
  %epil.iter.next = add i64 %epil.iter, 1
  %epil.iter.cmp.not = icmp eq i64 %epil.iter.next, %xtraiter
  br i1 %epil.iter.cmp.not, label %._crit_edge.us, label %.epil.preheader, !llvm.loop !17

._crit_edge.us:                                   ; preds = %.epil.preheader, %._crit_edge.us.unr-lcssa
  %indvars.iv.next16 = add nuw nsw i64 %indvars.iv15, 1
  %exitcond19.not = icmp eq i64 %indvars.iv.next16, %wide.trip.count18
  br i1 %exitcond19.not, label %._crit_edge12, label %.preheader.us, !llvm.loop !19

._crit_edge12:                                    ; preds = %._crit_edge.us, %.preheader.lr.ph, %2
  ret void
}

declare void @_ZN6MatrixC1Eii(ptr, i32, i32) 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" }

!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 4}
!6 = !{!"_ZTS6Matrix", !7, i64 0, !7, i64 4, !10, i64 8}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}
!10 = !{!"any pointer", !8, i64 0}
!11 = !{!6, !7, i64 0}
!12 = !{!10, !10, i64 0}
!13 = !{!14, !14, i64 0}
!14 = !{!"double", !8, i64 0}
!15 = distinct !{!15, !16}
!16 = !{!"llvm.loop.mustprogress"}
!17 = distinct !{!17, !18}
!18 = !{!"llvm.loop.unroll.disable"}
!19 = distinct !{!19, !16}


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