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

; 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_Matrix5scaleEf = external hidden unnamed_addr constant [6 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

; 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_Matrix5scaleEf(ptr noundef nonnull align 8 dereferenceable(49) %0, float noundef %1) unnamed_addr #2 align 2 {
  %3 = alloca ptr, align 8
  %4 = alloca float, align 4
  %5 = alloca i64, align 8
  store ptr %0, ptr %3, align 8, !tbaa !5
  store float %1, ptr %4, align 4, !tbaa !9
  %6 = load ptr, ptr %3, align 8
  %7 = getelementptr inbounds %class.Matrix, ptr %6, i32 0, i32 5
  %8 = load i64, ptr %7, align 8, !tbaa !11
  %9 = icmp ugt i64 %8, 0
  call void @_Z10_my_assertbPKciS0_(i1 noundef zeroext %9, ptr noundef @.str, i32 noundef 135, ptr noundef @__FUNCTION__._ZN10CPU_Matrix5scaleEf)
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #3
  store i64 0, ptr %5, align 8, !tbaa !16
  br label %10

10:                                               ; preds = %24, %2
  %11 = load i64, ptr %5, align 8, !tbaa !16
  %12 = getelementptr inbounds %class.Matrix, ptr %6, i32 0, i32 5
  %13 = load i64, ptr %12, align 8, !tbaa !11
  %14 = icmp ult i64 %11, %13
  br i1 %14, label %16, label %15

15:                                               ; preds = %10
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #3
  br label %27

16:                                               ; preds = %10
  %17 = load float, ptr %4, align 4, !tbaa !9
  %18 = getelementptr inbounds %class.Matrix, ptr %6, i32 0, i32 6
  %19 = load ptr, ptr %18, align 8, !tbaa !17
  %20 = load i64, ptr %5, align 8, !tbaa !16
  %21 = getelementptr inbounds float, ptr %19, i64 %20
  %22 = load float, ptr %21, align 4, !tbaa !9
  %23 = fmul float %22, %17
  store float %23, ptr %21, align 4, !tbaa !9
  br label %24

24:                                               ; preds = %16
  %25 = load i64, ptr %5, align 8, !tbaa !16
  %26 = add i64 %25, 1
  store i64 %26, ptr %5, align 8, !tbaa !16
  br label %10, !llvm.loop !18

27:                                               ; preds = %15
  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 = !{!"float", !7, i64 0}
!11 = !{!12, !14, i64 32}
!12 = !{!"_ZTS6Matrix", !13, i64 8, !14, i64 16, !14, i64 24, !14, i64 32, !6, i64 40, !15, i64 48}
!13 = !{!"_ZTS11DEVICE_NAME", !7, i64 0}
!14 = !{!"long", !7, i64 0}
!15 = !{!"bool", !7, i64 0}
!16 = !{!14, !14, i64 0}
!17 = !{!12, !6, i64 40}
!18 = distinct !{!18, !19}
!19 = !{!"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"

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

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

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN10CPU_Matrix5scaleEf(ptr nocapture noundef nonnull readonly align 8 dereferenceable(49) %0, float noundef %1) unnamed_addr #1 align 2 {
  %3 = getelementptr inbounds i8, ptr %0, i64 32
  %4 = load i64, ptr %3, align 8, !tbaa !5
  %5 = icmp ne i64 %4, 0
  tail call void @_Z10_my_assertbPKciS0_(i1 noundef zeroext %5, ptr noundef nonnull @.str, i32 noundef 135, ptr noundef nonnull @__FUNCTION__._ZN10CPU_Matrix5scaleEf)
  %6 = load i64, ptr %3, align 8, !tbaa !5
  %.not = icmp eq i64 %6, 0
  br i1 %.not, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %2
  %7 = getelementptr inbounds i8, ptr %0, i64 40
  %8 = load ptr, ptr %7, align 8, !tbaa !13
  %min.iters.check = icmp ult i64 %6, 8
  br i1 %min.iters.check, label %scalar.ph.preheader, label %vector.ph

scalar.ph.preheader:                              ; preds = %middle.block, %.lr.ph
  %.04.ph = phi i64 [ 0, %.lr.ph ], [ %n.vec, %middle.block ]
  br label %scalar.ph

vector.ph:                                        ; preds = %.lr.ph
  %n.vec = and i64 %6, -8
  %broadcast.splatinsert = insertelement <4 x float> poison, float %1, i64 0
  %broadcast.splat = shufflevector <4 x float> %broadcast.splatinsert, <4 x float> poison, <4 x i32> zeroinitializer
  br label %vector.body

vector.body:                                      ; preds = %vector.body, %vector.ph
  %index = phi i64 [ 0, %vector.ph ], [ %index.next, %vector.body ]
  %9 = getelementptr inbounds float, ptr %8, i64 %index
  %10 = getelementptr inbounds i8, ptr %9, i64 16
  %wide.load = load <4 x float>, ptr %9, align 4, !tbaa !14
  %wide.load5 = load <4 x float>, ptr %10, align 4, !tbaa !14
  %11 = fmul <4 x float> %wide.load, %broadcast.splat
  %12 = fmul <4 x float> %wide.load5, %broadcast.splat
  store <4 x float> %11, ptr %9, align 4, !tbaa !14
  store <4 x float> %12, ptr %10, align 4, !tbaa !14
  %index.next = add nuw i64 %index, 8
  %13 = icmp eq i64 %index.next, %n.vec
  br i1 %13, label %middle.block, label %vector.body, !llvm.loop !16

middle.block:                                     ; preds = %vector.body
  %cmp.n = icmp eq i64 %6, %n.vec
  br i1 %cmp.n, label %._crit_edge, label %scalar.ph.preheader

._crit_edge:                                      ; preds = %scalar.ph, %middle.block, %2
  ret void

scalar.ph:                                        ; preds = %scalar.ph.preheader, %scalar.ph
  %.04 = phi i64 [ %17, %scalar.ph ], [ %.04.ph, %scalar.ph.preheader ]
  %14 = getelementptr inbounds float, ptr %8, i64 %.04
  %15 = load float, ptr %14, align 4, !tbaa !14
  %16 = fmul float %15, %1
  store float %16, ptr %14, align 4, !tbaa !14
  %17 = add nuw i64 %.04, 1
  %exitcond.not = icmp eq i64 %17, %6
  br i1 %exitcond.not, label %._crit_edge, label %scalar.ph, !llvm.loop !20
}

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, !11, i64 40}
!14 = !{!15, !15, i64 0}
!15 = !{!"float", !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, !17, !19, !18}


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