; LLVM IR from moarseniy/CudaFEMproject :: FEMproject/matrix_pack/src/cpu_matrix.ll (ZN10CPU_Matrix11getDiagonalEmR6Matrix)

; 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 <{ ptr, i32, [4 x i8], i64, i64, i64, ptr, i8, [7 x i8] }>

@.str = external hidden unnamed_addr constant [100 x i8], align 1
@__FUNCTION__._ZN10CPU_Matrix11getDiagonalEmR6Matrix = external hidden unnamed_addr constant [12 x i8], align 1

declare void @_Z10_my_assertbPKciS0_(i1 noundef zeroext, ptr noundef, i32 noundef, ptr noundef) #0

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

declare noundef ptr @_ZNK6Matrix8get_dataEv(ptr noundef nonnull align 8 dereferenceable(49)) #0

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

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN10CPU_Matrix11getDiagonalEmR6Matrix(ptr noundef nonnull align 8 dereferenceable(49) %0, i64 noundef %1, ptr noundef nonnull align 8 dereferenceable(49) %2) unnamed_addr #2 align 2 {
  %4 = alloca ptr, align 8
  %5 = alloca i64, align 8
  %6 = alloca ptr, align 8
  %7 = alloca i64, align 8
  %8 = alloca i32, align 4
  %9 = alloca i64, align 8
  store ptr %0, ptr %4, align 8, !tbaa !5
  store i64 %1, ptr %5, align 8, !tbaa !9
  store ptr %2, ptr %6, align 8, !tbaa !5
  %10 = load ptr, ptr %4, align 8
  %11 = getelementptr inbounds %class.Matrix, ptr %10, i32 0, i32 5
  %12 = load i64, ptr %11, align 8, !tbaa !11
  %13 = icmp ugt i64 %12, 0
  call void @_Z10_my_assertbPKciS0_(i1 noundef zeroext %13, ptr noundef @.str, i32 noundef 297, ptr noundef @__FUNCTION__._ZN10CPU_Matrix11getDiagonalEmR6Matrix)
  %14 = load ptr, ptr %6, align 8, !tbaa !5
  %15 = getelementptr inbounds %class.Matrix, ptr %10, i32 0, i32 3
  %16 = load i64, ptr %15, align 8, !tbaa !15
  %17 = load i64, ptr %5, align 8, !tbaa !9
  %18 = load ptr, ptr %14, align 8, !tbaa !16
  %19 = getelementptr inbounds ptr, ptr %18, i64 26
  %20 = load ptr, ptr %19, align 8
  call void %20(ptr noundef nonnull align 8 dereferenceable(49) %14, i64 noundef %16, i64 noundef %17)
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #3
  store i64 0, ptr %7, align 8, !tbaa !9
  br label %21

21:                                               ; preds = %60, %3
  %22 = load i64, ptr %7, align 8, !tbaa !9
  %23 = getelementptr inbounds %class.Matrix, ptr %10, i32 0, i32 3
  %24 = load i64, ptr %23, align 8, !tbaa !15
  %25 = icmp ult i64 %22, %24
  br i1 %25, label %27, label %26

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

27:                                               ; preds = %21
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #3
  store i64 0, ptr %9, align 8, !tbaa !9
  br label %28

28:                                               ; preds = %56, %27
  %29 = load i64, ptr %9, align 8, !tbaa !9
  %30 = load i64, ptr %5, align 8, !tbaa !9
  %31 = icmp ult i64 %29, %30
  br i1 %31, label %33, label %32

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

33:                                               ; preds = %28
  %34 = getelementptr inbounds %class.Matrix, ptr %10, i32 0, i32 6
  %35 = load ptr, ptr %34, align 8, !tbaa !18
  %36 = getelementptr inbounds %class.Matrix, ptr %10, i32 0, i32 4
  %37 = load i64, ptr %36, align 8, !tbaa !19
  %38 = load i64, ptr %7, align 8, !tbaa !9
  %39 = mul i64 %37, %38
  %40 = load i64, ptr %5, align 8, !tbaa !9
  %41 = load i64, ptr %9, align 8, !tbaa !9
  %42 = mul i64 %40, %41
  %43 = add i64 %39, %42
  %44 = load i64, ptr %9, align 8, !tbaa !9
  %45 = add i64 %43, %44
  %46 = getelementptr inbounds float, ptr %35, i64 %45
  %47 = load float, ptr %46, align 4, !tbaa !20
  %48 = load ptr, ptr %6, align 8, !tbaa !5
  %49 = call noundef ptr @_ZNK6Matrix8get_dataEv(ptr noundef nonnull align 8 dereferenceable(49) %48)
  %50 = load i64, ptr %9, align 8, !tbaa !9
  %51 = load i64, ptr %5, align 8, !tbaa !9
  %52 = load i64, ptr %7, align 8, !tbaa !9
  %53 = mul i64 %51, %52
  %54 = add i64 %50, %53
  %55 = getelementptr inbounds float, ptr %49, i64 %54
  store float %47, ptr %55, align 4, !tbaa !20
  br label %56

56:                                               ; preds = %33
  %57 = load i64, ptr %9, align 8, !tbaa !9
  %58 = add i64 %57, 1
  store i64 %58, ptr %9, align 8, !tbaa !9
  br label %28, !llvm.loop !22

59:                                               ; preds = %32
  br label %60

60:                                               ; preds = %59
  %61 = load i64, ptr %7, align 8, !tbaa !9
  %62 = add i64 %61, 1
  store i64 %62, ptr %7, align 8, !tbaa !9
  br label %21, !llvm.loop !24

63:                                               ; preds = %26
  ret void
}

attributes #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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { 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 #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 = !{!"long", !7, i64 0}
!11 = !{!12, !10, i64 32}
!12 = !{!"_ZTS6Matrix", !13, i64 8, !10, i64 16, !10, i64 24, !10, i64 32, !6, i64 40, !14, i64 48}
!13 = !{!"_ZTS11DEVICE_NAME", !7, i64 0}
!14 = !{!"bool", !7, i64 0}
!15 = !{!12, !10, i64 16}
!16 = !{!17, !17, i64 0}
!17 = !{!"vtable pointer", !8, i64 0}
!18 = !{!12, !6, i64 40}
!19 = !{!12, !10, i64 24}
!20 = !{!21, !21, i64 0}
!21 = !{!"float", !7, i64 0}
!22 = distinct !{!22, !23}
!23 = !{!"llvm.loop.mustprogress"}
!24 = distinct !{!24, !23}


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

@.str = external hidden unnamed_addr constant [100 x i8], align 1
@__FUNCTION__._ZN10CPU_Matrix11getDiagonalEmR6Matrix = external hidden unnamed_addr constant [12 x i8], align 1

declare void @_Z10_my_assertbPKciS0_(i1 noundef zeroext, ptr noundef, i32 noundef, ptr noundef) local_unnamed_addr #0

declare noundef ptr @_ZNK6Matrix8get_dataEv(ptr noundef nonnull align 8 dereferenceable(49)) local_unnamed_addr #0

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN10CPU_Matrix11getDiagonalEmR6Matrix(ptr nocapture noundef nonnull readonly align 8 dereferenceable(49) %0, i64 noundef %1, ptr noundef nonnull align 8 dereferenceable(49) %2) unnamed_addr #1 align 2 {
  %4 = getelementptr inbounds i8, ptr %0, i64 32
  %5 = load i64, ptr %4, align 8, !tbaa !5
  %6 = icmp ne i64 %5, 0
  tail call void @_Z10_my_assertbPKciS0_(i1 noundef zeroext %6, ptr noundef nonnull @.str, i32 noundef 297, ptr noundef nonnull @__FUNCTION__._ZN10CPU_Matrix11getDiagonalEmR6Matrix)
  %7 = getelementptr inbounds i8, ptr %0, i64 16
  %8 = load i64, ptr %7, align 8, !tbaa !13
  %9 = load ptr, ptr %2, align 8, !tbaa !14
  %10 = getelementptr inbounds i8, ptr %9, i64 208
  %11 = load ptr, ptr %10, align 8
  tail call void %11(ptr noundef nonnull align 8 dereferenceable(49) %2, i64 noundef %8, i64 noundef %1)
  %12 = load i64, ptr %7, align 8, !tbaa !13
  %.not = icmp eq i64 %12, 0
  br i1 %.not, label %._crit_edge19, label %.preheader.lr.ph

.preheader.lr.ph:                                 ; preds = %3
  %.not20 = icmp eq i64 %1, 0
  %13 = getelementptr inbounds i8, ptr %0, i64 40
  %14 = getelementptr inbounds i8, ptr %0, i64 24
  br i1 %.not20, label %._crit_edge19, label %.preheader.us

.preheader.us:                                    ; preds = %.preheader.lr.ph, %._crit_edge.us
  %.01518.us = phi i64 [ %29, %._crit_edge.us ], [ 0, %.preheader.lr.ph ]
  %15 = mul i64 %.01518.us, %1
  br label %16

16:                                               ; preds = %.preheader.us, %16
  %.017.us = phi i64 [ 0, %.preheader.us ], [ %28, %16 ]
  %17 = load ptr, ptr %13, align 8, !tbaa !16
  %18 = load i64, ptr %14, align 8, !tbaa !17
  %19 = mul i64 %18, %.01518.us
  %20 = mul i64 %.017.us, %1
  %21 = getelementptr float, ptr %17, i64 %19
  %22 = getelementptr float, ptr %21, i64 %20
  %23 = getelementptr float, ptr %22, i64 %.017.us
  %24 = load float, ptr %23, align 4, !tbaa !18
  %25 = tail call noundef ptr @_ZNK6Matrix8get_dataEv(ptr noundef nonnull align 8 dereferenceable(49) %2)
  %26 = getelementptr float, ptr %25, i64 %.017.us
  %27 = getelementptr float, ptr %26, i64 %15
  store float %24, ptr %27, align 4, !tbaa !18
  %28 = add nuw i64 %.017.us, 1
  %exitcond.not = icmp eq i64 %28, %1
  br i1 %exitcond.not, label %._crit_edge.us, label %16, !llvm.loop !20

._crit_edge.us:                                   ; preds = %16
  %29 = add nuw i64 %.01518.us, 1
  %30 = load i64, ptr %7, align 8, !tbaa !13
  %31 = icmp ult i64 %29, %30
  br i1 %31, label %.preheader.us, label %._crit_edge19, !llvm.loop !22

._crit_edge19:                                    ; preds = %._crit_edge.us, %.preheader.lr.ph, %3
  ret void
}

attributes #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" }

!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, !10, i64 32}
!6 = !{!"_ZTS6Matrix", !7, i64 8, !10, i64 16, !10, i64 24, !10, i64 32, !11, i64 40, !12, i64 48}
!7 = !{!"_ZTS11DEVICE_NAME", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}
!10 = !{!"long", !8, i64 0}
!11 = !{!"any pointer", !8, i64 0}
!12 = !{!"bool", !8, i64 0}
!13 = !{!6, !10, i64 16}
!14 = !{!15, !15, i64 0}
!15 = !{!"vtable pointer", !9, i64 0}
!16 = !{!6, !11, i64 40}
!17 = !{!6, !10, i64 24}
!18 = !{!19, !19, i64 0}
!19 = !{!"float", !8, i64 0}
!20 = distinct !{!20, !21}
!21 = !{!"llvm.loop.mustprogress"}
!22 = distinct !{!22, !21}


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