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

; 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 speculatable willreturn memory(none)
declare { i64, i1 } @llvm.umul.with.overflow.i64(i64, i64) #0

; Function Attrs: nobuiltin allocsize(0)
declare noundef nonnull ptr @_Znam(i64 noundef) #1

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

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

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN6MatrixC2ERKS_(ptr noundef nonnull align 8 dereferenceable(16) %0, ptr noundef nonnull align 8 dereferenceable(16) %1) unnamed_addr #3 align 2 {
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  store ptr %0, ptr %3, align 8, !tbaa !5
  store ptr %1, ptr %4, align 8, !tbaa !5
  %8 = load ptr, ptr %3, align 8
  %9 = getelementptr inbounds %class.Matrix, ptr %8, i32 0, i32 0
  %10 = load ptr, ptr %4, align 8, !tbaa !5
  %11 = getelementptr inbounds %class.Matrix, ptr %10, i32 0, i32 0
  %12 = load i32, ptr %11, align 8, !tbaa !9
  store i32 %12, ptr %9, align 8, !tbaa !9
  %13 = getelementptr inbounds %class.Matrix, ptr %8, i32 0, i32 1
  %14 = load ptr, ptr %4, align 8, !tbaa !5
  %15 = getelementptr inbounds %class.Matrix, ptr %14, i32 0, i32 1
  %16 = load i32, ptr %15, align 4, !tbaa !12
  store i32 %16, ptr %13, align 4, !tbaa !12
  %17 = getelementptr inbounds %class.Matrix, ptr %8, i32 0, i32 2
  %18 = load ptr, ptr %4, align 8, !tbaa !5
  %19 = getelementptr inbounds %class.Matrix, ptr %18, i32 0, i32 0
  %20 = load i32, ptr %19, align 8, !tbaa !9
  %21 = sext i32 %20 to i64
  %22 = call { i64, i1 } @llvm.umul.with.overflow.i64(i64 %21, i64 8)
  %23 = extractvalue { i64, i1 } %22, 1
  %24 = extractvalue { i64, i1 } %22, 0
  %25 = select i1 %23, i64 -1, i64 %24
  %26 = call noalias noundef nonnull ptr @_Znam(i64 noundef %25) #4
  store ptr %26, ptr %17, align 8, !tbaa !13
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #5
  store i32 0, ptr %5, align 4, !tbaa !14
  br label %27

27:                                               ; preds = %78, %2
  %28 = load i32, ptr %5, align 4, !tbaa !14
  %29 = getelementptr inbounds %class.Matrix, ptr %8, i32 0, i32 0
  %30 = load i32, ptr %29, align 8, !tbaa !9
  %31 = icmp slt i32 %28, %30
  br i1 %31, label %33, label %32

32:                                               ; preds = %27
  store i32 2, ptr %6, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #5
  br label %81

33:                                               ; preds = %27
  %34 = getelementptr inbounds %class.Matrix, ptr %8, i32 0, i32 1
  %35 = load i32, ptr %34, align 4, !tbaa !12
  %36 = sext i32 %35 to i64
  %37 = call { i64, i1 } @llvm.umul.with.overflow.i64(i64 %36, i64 8)
  %38 = extractvalue { i64, i1 } %37, 1
  %39 = extractvalue { i64, i1 } %37, 0
  %40 = select i1 %38, i64 -1, i64 %39
  %41 = call noalias noundef nonnull ptr @_Znam(i64 noundef %40) #4
  %42 = getelementptr inbounds %class.Matrix, ptr %8, i32 0, i32 2
  %43 = load ptr, ptr %42, align 8, !tbaa !13
  %44 = load i32, ptr %5, align 4, !tbaa !14
  %45 = sext i32 %44 to i64
  %46 = getelementptr inbounds ptr, ptr %43, i64 %45
  store ptr %41, ptr %46, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #5
  store i32 0, ptr %7, align 4, !tbaa !14
  br label %47

47:                                               ; preds = %74, %33
  %48 = load i32, ptr %7, align 4, !tbaa !14
  %49 = getelementptr inbounds %class.Matrix, ptr %8, i32 0, i32 1
  %50 = load i32, ptr %49, align 4, !tbaa !12
  %51 = icmp slt i32 %48, %50
  br i1 %51, label %53, label %52

52:                                               ; preds = %47
  store i32 5, ptr %6, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #5
  br label %77

53:                                               ; preds = %47
  %54 = load ptr, ptr %4, align 8, !tbaa !5
  %55 = getelementptr inbounds %class.Matrix, ptr %54, i32 0, i32 2
  %56 = load ptr, ptr %55, align 8, !tbaa !13
  %57 = load i32, ptr %5, align 4, !tbaa !14
  %58 = sext i32 %57 to i64
  %59 = getelementptr inbounds ptr, ptr %56, i64 %58
  %60 = load ptr, ptr %59, align 8, !tbaa !5
  %61 = load i32, ptr %7, align 4, !tbaa !14
  %62 = sext i32 %61 to i64
  %63 = getelementptr inbounds double, ptr %60, i64 %62
  %64 = load double, ptr %63, align 8, !tbaa !15
  %65 = getelementptr inbounds %class.Matrix, ptr %8, i32 0, i32 2
  %66 = load ptr, ptr %65, align 8, !tbaa !13
  %67 = load i32, ptr %5, align 4, !tbaa !14
  %68 = sext i32 %67 to i64
  %69 = getelementptr inbounds ptr, ptr %66, i64 %68
  %70 = load ptr, ptr %69, align 8, !tbaa !5
  %71 = load i32, ptr %7, align 4, !tbaa !14
  %72 = sext i32 %71 to i64
  %73 = getelementptr inbounds double, ptr %70, i64 %72
  store double %64, ptr %73, align 8, !tbaa !15
  br label %74

74:                                               ; preds = %53
  %75 = load i32, ptr %7, align 4, !tbaa !14
  %76 = add nsw i32 %75, 1
  store i32 %76, ptr %7, align 4, !tbaa !14
  br label %47, !llvm.loop !17

77:                                               ; preds = %52
  br label %78

78:                                               ; preds = %77
  %79 = load i32, ptr %5, align 4, !tbaa !14
  %80 = add nsw i32 %79, 1
  store i32 %80, ptr %5, align 4, !tbaa !14
  br label %27, !llvm.loop !19

81:                                               ; preds = %32
  ret void
}

attributes #0 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #1 = { nobuiltin allocsize(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 willreturn memory(argmem: readwrite) }
attributes #3 = { 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 #4 = { builtin allocsize(0) }
attributes #5 = { 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 0}
!10 = !{!"_ZTS6Matrix", !11, i64 0, !11, i64 4, !6, i64 8}
!11 = !{!"int", !7, i64 0}
!12 = !{!10, !11, i64 4}
!13 = !{!10, !6, i64 8}
!14 = !{!11, !11, i64 0}
!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"

; Function Attrs: nobuiltin allocsize(0)
declare noundef nonnull ptr @_Znam(i64 noundef) local_unnamed_addr #0

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN6MatrixC2ERKS_(ptr nocapture noundef nonnull align 8 dereferenceable(16) %0, ptr nocapture noundef nonnull readonly align 8 dereferenceable(16) %1) unnamed_addr #1 align 2 {
  %3 = load i32, ptr %1, align 8, !tbaa !5
  store i32 %3, ptr %0, align 8, !tbaa !5
  %4 = getelementptr inbounds i8, ptr %0, i64 4
  %5 = getelementptr inbounds i8, ptr %1, i64 4
  %6 = load i32, ptr %5, align 4, !tbaa !11
  %.fr19 = freeze i32 %6
  store i32 %.fr19, ptr %4, align 4, !tbaa !11
  %7 = getelementptr inbounds i8, ptr %0, i64 8
  %8 = sext i32 %3 to i64
  %9 = icmp slt i32 %3, 0
  %10 = shl nsw i64 %8, 3
  %11 = select i1 %9, i64 -1, i64 %10
  %12 = tail call noalias noundef nonnull ptr @_Znam(i64 noundef %11) #2
  store ptr %12, ptr %7, align 8, !tbaa !12
  %13 = icmp sgt i32 %3, 0
  br i1 %13, label %.lr.ph17, label %._crit_edge18

.lr.ph17:                                         ; preds = %2
  %14 = zext nneg i32 %.fr19 to i64
  %15 = icmp slt i32 %.fr19, 0
  %16 = shl nuw nsw i64 %14, 3
  %17 = select i1 %15, i64 -1, i64 %16
  %18 = icmp sgt i32 %.fr19, 0
  %19 = getelementptr inbounds i8, ptr %1, i64 8
  %wide.trip.count30 = zext nneg i32 %3 to i64
  br i1 %18, label %.lr.ph.us.preheader, label %.lr.ph17.split

.lr.ph.us.preheader:                              ; preds = %.lr.ph17
  %wide.trip.count25 = zext nneg i32 %.fr19 to i64
  %min.iters.check = icmp ult i32 %.fr19, 4
  %n.vec = and i64 %wide.trip.count25, 2147483644
  %cmp.n = icmp eq i64 %n.vec, %wide.trip.count25
  %xtraiter = and i64 %wide.trip.count25, 3
  %lcmp.mod.not = icmp eq i64 %xtraiter, 0
  br label %.lr.ph.us

.lr.ph.us:                                        ; preds = %.lr.ph.us.preheader, %._crit_edge.us
  %20 = phi ptr [ %12, %.lr.ph.us.preheader ], [ %26, %._crit_edge.us ]
  %indvars.iv27 = phi i64 [ 0, %.lr.ph.us.preheader ], [ %indvars.iv.next28, %._crit_edge.us ]
  %21 = tail call noalias noundef nonnull ptr @_Znam(i64 noundef %17) #2
  %22 = getelementptr inbounds ptr, ptr %20, i64 %indvars.iv27
  store ptr %21, ptr %22, align 8, !tbaa !13
  %23 = load ptr, ptr %19, align 8, !tbaa !12
  %24 = getelementptr inbounds ptr, ptr %23, i64 %indvars.iv27
  %25 = load ptr, ptr %24, align 8, !tbaa !13
  %26 = load ptr, ptr %7, align 8, !tbaa !12
  %27 = getelementptr inbounds ptr, ptr %26, i64 %indvars.iv27
  %28 = load ptr, ptr %27, align 8, !tbaa !13
  %29 = ptrtoint ptr %28 to i64
  %30 = ptrtoint ptr %25 to i64
  %31 = sub i64 %29, %30
  %diff.check = icmp ult i64 %31, 32
  %or.cond = select i1 %min.iters.check, i1 true, i1 %diff.check
  br i1 %or.cond, label %scalar.ph.preheader, label %vector.body

vector.body:                                      ; preds = %.lr.ph.us, %vector.body
  %index = phi i64 [ %index.next, %vector.body ], [ 0, %.lr.ph.us ]
  %32 = getelementptr inbounds double, ptr %25, i64 %index
  %33 = getelementptr inbounds i8, ptr %32, i64 16
  %wide.load = load <2 x double>, ptr %32, align 8, !tbaa !14
  %wide.load34 = load <2 x double>, ptr %33, align 8, !tbaa !14
  %34 = getelementptr inbounds double, ptr %28, i64 %index
  %35 = getelementptr inbounds i8, ptr %34, i64 16
  store <2 x double> %wide.load, ptr %34, align 8, !tbaa !14
  store <2 x double> %wide.load34, ptr %35, align 8, !tbaa !14
  %index.next = add nuw i64 %index, 4
  %36 = icmp eq i64 %index.next, %n.vec
  br i1 %36, label %middle.block, label %vector.body, !llvm.loop !16

middle.block:                                     ; preds = %vector.body
  br i1 %cmp.n, label %._crit_edge.us, label %scalar.ph.preheader

scalar.ph.preheader:                              ; preds = %middle.block, %.lr.ph.us
  %indvars.iv22.ph = phi i64 [ 0, %.lr.ph.us ], [ %n.vec, %middle.block ]
  br i1 %lcmp.mod.not, label %scalar.ph.prol.loopexit, label %scalar.ph.prol

scalar.ph.prol:                                   ; preds = %scalar.ph.preheader, %scalar.ph.prol
  %indvars.iv22.prol = phi i64 [ %indvars.iv.next23.prol, %scalar.ph.prol ], [ %indvars.iv22.ph, %scalar.ph.preheader ]
  %prol.iter = phi i64 [ %prol.iter.next, %scalar.ph.prol ], [ 0, %scalar.ph.preheader ]
  %37 = getelementptr inbounds double, ptr %25, i64 %indvars.iv22.prol
  %38 = load double, ptr %37, align 8, !tbaa !14
  %39 = getelementptr inbounds double, ptr %28, i64 %indvars.iv22.prol
  store double %38, ptr %39, align 8, !tbaa !14
  %indvars.iv.next23.prol = add nuw nsw i64 %indvars.iv22.prol, 1
  %prol.iter.next = add i64 %prol.iter, 1
  %prol.iter.cmp.not = icmp eq i64 %prol.iter.next, %xtraiter
  br i1 %prol.iter.cmp.not, label %scalar.ph.prol.loopexit, label %scalar.ph.prol, !llvm.loop !20

scalar.ph.prol.loopexit:                          ; preds = %scalar.ph.prol, %scalar.ph.preheader
  %indvars.iv22.unr = phi i64 [ %indvars.iv22.ph, %scalar.ph.preheader ], [ %indvars.iv.next23.prol, %scalar.ph.prol ]
  %40 = sub nsw i64 %indvars.iv22.ph, %wide.trip.count25
  %41 = icmp ugt i64 %40, -4
  br i1 %41, label %._crit_edge.us, label %scalar.ph

scalar.ph:                                        ; preds = %scalar.ph.prol.loopexit, %scalar.ph
  %indvars.iv22 = phi i64 [ %indvars.iv.next23.3, %scalar.ph ], [ %indvars.iv22.unr, %scalar.ph.prol.loopexit ]
  %42 = getelementptr inbounds double, ptr %25, i64 %indvars.iv22
  %43 = load double, ptr %42, align 8, !tbaa !14
  %44 = getelementptr inbounds double, ptr %28, i64 %indvars.iv22
  store double %43, ptr %44, align 8, !tbaa !14
  %indvars.iv.next23 = add nuw nsw i64 %indvars.iv22, 1
  %45 = getelementptr inbounds double, ptr %25, i64 %indvars.iv.next23
  %46 = load double, ptr %45, align 8, !tbaa !14
  %47 = getelementptr inbounds double, ptr %28, i64 %indvars.iv.next23
  store double %46, ptr %47, align 8, !tbaa !14
  %indvars.iv.next23.1 = add nuw nsw i64 %indvars.iv22, 2
  %48 = getelementptr inbounds double, ptr %25, i64 %indvars.iv.next23.1
  %49 = load double, ptr %48, align 8, !tbaa !14
  %50 = getelementptr inbounds double, ptr %28, i64 %indvars.iv.next23.1
  store double %49, ptr %50, align 8, !tbaa !14
  %indvars.iv.next23.2 = add nuw nsw i64 %indvars.iv22, 3
  %51 = getelementptr inbounds double, ptr %25, i64 %indvars.iv.next23.2
  %52 = load double, ptr %51, align 8, !tbaa !14
  %53 = getelementptr inbounds double, ptr %28, i64 %indvars.iv.next23.2
  store double %52, ptr %53, align 8, !tbaa !14
  %indvars.iv.next23.3 = add nuw nsw i64 %indvars.iv22, 4
  %exitcond26.not.3 = icmp eq i64 %indvars.iv.next23.3, %wide.trip.count25
  br i1 %exitcond26.not.3, label %._crit_edge.us, label %scalar.ph, !llvm.loop !22

._crit_edge.us:                                   ; preds = %scalar.ph.prol.loopexit, %scalar.ph, %middle.block
  %indvars.iv.next28 = add nuw nsw i64 %indvars.iv27, 1
  %exitcond31.not = icmp eq i64 %indvars.iv.next28, %wide.trip.count30
  br i1 %exitcond31.not, label %._crit_edge18, label %.lr.ph.us, !llvm.loop !23

._crit_edge18:                                    ; preds = %.lr.ph17.split, %._crit_edge.us, %2
  ret void

.lr.ph17.split:                                   ; preds = %.lr.ph17, %.lr.ph17.split
  %indvars.iv = phi i64 [ %indvars.iv.next, %.lr.ph17.split ], [ 0, %.lr.ph17 ]
  %54 = tail call noalias noundef nonnull ptr @_Znam(i64 noundef %17) #2
  %55 = load ptr, ptr %7, align 8, !tbaa !12
  %56 = getelementptr inbounds ptr, ptr %55, i64 %indvars.iv
  store ptr %54, ptr %56, align 8, !tbaa !13
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %exitcond.not = icmp eq i64 %indvars.iv.next, %wide.trip.count30
  br i1 %exitcond.not, label %._crit_edge18, label %.lr.ph17.split, !llvm.loop !23
}

attributes #0 = { nobuiltin allocsize(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 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 = { builtin allocsize(0) }

!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 0}
!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 4}
!12 = !{!6, !10, i64 8}
!13 = !{!10, !10, i64 0}
!14 = !{!15, !15, i64 0}
!15 = !{!"double", !8, i64 0}
!16 = distinct !{!16, !17, !18, !19}
!17 = !{!"llvm.loop.mustprogress"}
!18 = !{!"llvm.loop.isvectorized", i32 1}
!19 = !{!"llvm.loop.unroll.runtime.disable"}
!20 = distinct !{!20, !21}
!21 = !{!"llvm.loop.unroll.disable"}
!22 = distinct !{!22, !17, !18}
!23 = distinct !{!23, !17}


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