; LLVM IR from MRPT/mrpt :: 3rdparty/xspublic/xstypes (xsmatrix)

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

%struct.XsMatrix = type { ptr, i64, i64, i64, i64 }

; 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: nounwind uwtable
declare dso_local void @XsMatrix_assign(ptr noundef, i64 noundef, i64 noundef, i64 noundef, ptr noundef, i64 noundef) #1

; Function Attrs: nounwind uwtable
define dso_local void @XsMatrix_multiplyScalar(ptr noundef %0, double noundef %1, ptr noundef %2) #1 {
  %4 = alloca ptr, align 8
  %5 = alloca double, align 8
  %6 = alloca ptr, align 8
  %7 = alloca i64, align 8
  %8 = alloca i64, align 8
  %9 = alloca i64, align 8
  %10 = alloca i64, align 8
  store ptr %0, ptr %4, align 8, !tbaa !5
  store double %1, ptr %5, align 8, !tbaa !9
  store ptr %2, ptr %6, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #2
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #2
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #2
  %11 = load ptr, ptr %4, align 8, !tbaa !5
  %12 = getelementptr inbounds %struct.XsMatrix, ptr %11, i32 0, i32 3
  %13 = load i64, ptr %12, align 1, !tbaa !11
  store i64 %13, ptr %9, align 8, !tbaa !14
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #2
  %14 = load ptr, ptr %6, align 8, !tbaa !5
  %15 = load ptr, ptr %4, align 8, !tbaa !5
  %16 = getelementptr inbounds %struct.XsMatrix, ptr %15, i32 0, i32 1
  %17 = load i64, ptr %16, align 1, !tbaa !15
  %18 = load ptr, ptr %4, align 8, !tbaa !5
  %19 = getelementptr inbounds %struct.XsMatrix, ptr %18, i32 0, i32 2
  %20 = load i64, ptr %19, align 1, !tbaa !16
  call void @XsMatrix_assign(ptr noundef %14, i64 noundef %17, i64 noundef %20, i64 noundef 0, ptr noundef null, i64 noundef 0)
  %21 = load ptr, ptr %6, align 8, !tbaa !5
  %22 = getelementptr inbounds %struct.XsMatrix, ptr %21, i32 0, i32 3
  %23 = load i64, ptr %22, align 1, !tbaa !11
  store i64 %23, ptr %10, align 8, !tbaa !14
  store i64 0, ptr %7, align 8, !tbaa !14
  br label %24

24:                                               ; preds = %63, %3
  %25 = load i64, ptr %7, align 8, !tbaa !14
  %26 = load ptr, ptr %4, align 8, !tbaa !5
  %27 = getelementptr inbounds %struct.XsMatrix, ptr %26, i32 0, i32 1
  %28 = load i64, ptr %27, align 1, !tbaa !15
  %29 = icmp ult i64 %25, %28
  br i1 %29, label %30, label %66

30:                                               ; preds = %24
  store i64 0, ptr %8, align 8, !tbaa !14
  br label %31

31:                                               ; preds = %59, %30
  %32 = load i64, ptr %8, align 8, !tbaa !14
  %33 = load ptr, ptr %4, align 8, !tbaa !5
  %34 = getelementptr inbounds %struct.XsMatrix, ptr %33, i32 0, i32 2
  %35 = load i64, ptr %34, align 1, !tbaa !16
  %36 = icmp ult i64 %32, %35
  br i1 %36, label %37, label %62

37:                                               ; preds = %31
  %38 = load ptr, ptr %4, align 8, !tbaa !5
  %39 = getelementptr inbounds %struct.XsMatrix, ptr %38, i32 0, i32 0
  %40 = load ptr, ptr %39, align 1, !tbaa !17
  %41 = load i64, ptr %7, align 8, !tbaa !14
  %42 = load i64, ptr %9, align 8, !tbaa !14
  %43 = mul i64 %41, %42
  %44 = load i64, ptr %8, align 8, !tbaa !14
  %45 = add i64 %43, %44
  %46 = getelementptr inbounds double, ptr %40, i64 %45
  %47 = load double, ptr %46, align 8, !tbaa !9
  %48 = load double, ptr %5, align 8, !tbaa !9
  %49 = fmul double %47, %48
  %50 = load ptr, ptr %6, align 8, !tbaa !5
  %51 = getelementptr inbounds %struct.XsMatrix, ptr %50, i32 0, i32 0
  %52 = load ptr, ptr %51, align 1, !tbaa !17
  %53 = load i64, ptr %7, align 8, !tbaa !14
  %54 = load i64, ptr %10, align 8, !tbaa !14
  %55 = mul i64 %53, %54
  %56 = load i64, ptr %8, align 8, !tbaa !14
  %57 = add i64 %55, %56
  %58 = getelementptr inbounds double, ptr %52, i64 %57
  store double %49, ptr %58, align 8, !tbaa !9
  br label %59

59:                                               ; preds = %37
  %60 = load i64, ptr %8, align 8, !tbaa !14
  %61 = add i64 %60, 1
  store i64 %61, ptr %8, align 8, !tbaa !14
  br label %31, !llvm.loop !18

62:                                               ; preds = %31
  br label %63

63:                                               ; preds = %62
  %64 = load i64, ptr %7, align 8, !tbaa !14
  %65 = add i64 %64, 1
  store i64 %65, ptr %7, align 8, !tbaa !14
  br label %24, !llvm.loop !20

66:                                               ; preds = %24
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #2
  ret void
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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, !6, i64 0}
!6 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"double", !7, i64 0}
!11 = !{!12, !13, i64 24}
!12 = !{!"XsMatrix", !6, i64 0, !13, i64 8, !13, i64 16, !13, i64 24, !13, i64 32}
!13 = !{!"long", !7, i64 0}
!14 = !{!13, !13, i64 0}
!15 = !{!12, !13, i64 8}
!16 = !{!12, !13, i64 16}
!17 = !{!12, !6, i64 0}
!18 = distinct !{!18, !19}
!19 = !{!"llvm.loop.mustprogress"}
!20 = distinct !{!20, !19}


; 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: nounwind uwtable
declare dso_local void @XsMatrix_assign(ptr noundef, i64 noundef, i64 noundef, i64 noundef, ptr noundef, i64 noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local void @XsMatrix_multiplyScalar(ptr nocapture noundef readonly %0, double noundef %1, ptr noundef %2) local_unnamed_addr #0 {
  %4 = getelementptr inbounds i8, ptr %0, i64 24
  %5 = load i64, ptr %4, align 1, !tbaa !5
  %6 = getelementptr inbounds i8, ptr %0, i64 8
  %7 = load i64, ptr %6, align 1, !tbaa !11
  %8 = getelementptr inbounds i8, ptr %0, i64 16
  %9 = load i64, ptr %8, align 1, !tbaa !12
  tail call void @XsMatrix_assign(ptr noundef %2, i64 noundef %7, i64 noundef %9, i64 noundef 0, ptr noundef null, i64 noundef 0)
  %10 = getelementptr inbounds i8, ptr %2, i64 24
  %11 = load i64, ptr %10, align 1, !tbaa !5
  %12 = load i64, ptr %6, align 1, !tbaa !11
  %.not = icmp eq i64 %12, 0
  br i1 %.not, label %._crit_edge22, label %.preheader.lr.ph

.preheader.lr.ph:                                 ; preds = %3
  %13 = load i64, ptr %8, align 1, !tbaa !12
  %.not23 = icmp eq i64 %13, 0
  br i1 %.not23, label %._crit_edge22, label %.preheader.lr.ph.split.us

.preheader.lr.ph.split.us:                        ; preds = %.preheader.lr.ph
  %14 = load ptr, ptr %0, align 1, !tbaa !13
  %15 = load ptr, ptr %2, align 1, !tbaa !13
  %16 = add i64 %12, -1
  %17 = mul i64 %11, %16
  %18 = add i64 %17, %13
  %19 = shl i64 %18, 3
  %scevgep = getelementptr i8, ptr %15, i64 %19
  %20 = mul i64 %5, %16
  %21 = add i64 %20, %13
  %22 = shl i64 %21, 3
  %scevgep26 = getelementptr i8, ptr %14, i64 %22
  %min.iters.check = icmp ult i64 %13, 6
  %bound0 = icmp ult ptr %15, %scevgep26
  %bound1 = icmp ult ptr %14, %scevgep
  %found.conflict = and i1 %bound0, %bound1
  %23 = or i64 %11, %5
  %24 = and i64 %23, 1152921504606846976
  %25 = icmp ne i64 %24, 0
  %26 = or i1 %found.conflict, %25
  %n.vec = and i64 %13, -4
  %broadcast.splatinsert = insertelement <2 x double> poison, double %1, i64 0
  %broadcast.splat = shufflevector <2 x double> %broadcast.splatinsert, <2 x double> poison, <2 x i32> zeroinitializer
  %cmp.n = icmp eq i64 %13, %n.vec
  %xtraiter = and i64 %13, 3
  %lcmp.mod.not = icmp eq i64 %xtraiter, 0
  br label %.preheader.us

.preheader.us:                                    ; preds = %._crit_edge.us, %.preheader.lr.ph.split.us
  %.021.us = phi i64 [ 0, %.preheader.lr.ph.split.us ], [ %65, %._crit_edge.us ]
  %27 = mul i64 %.021.us, %5
  %28 = getelementptr double, ptr %14, i64 %27
  %29 = mul i64 %.021.us, %11
  %30 = getelementptr double, ptr %15, i64 %29
  %brmerge = select i1 %min.iters.check, i1 true, i1 %26
  br i1 %brmerge, label %scalar.ph.preheader, label %vector.body

vector.body:                                      ; preds = %.preheader.us, %vector.body
  %index = phi i64 [ %index.next, %vector.body ], [ 0, %.preheader.us ]
  %31 = getelementptr double, ptr %28, i64 %index
  %32 = getelementptr i8, ptr %31, i64 16
  %wide.load = load <2 x double>, ptr %31, align 8, !tbaa !14, !alias.scope !16
  %wide.load28 = load <2 x double>, ptr %32, align 8, !tbaa !14, !alias.scope !16
  %33 = fmul <2 x double> %wide.load, %broadcast.splat
  %34 = fmul <2 x double> %wide.load28, %broadcast.splat
  %35 = getelementptr double, ptr %30, i64 %index
  %36 = getelementptr i8, ptr %35, i64 16
  store <2 x double> %33, ptr %35, align 8, !tbaa !14, !alias.scope !19, !noalias !16
  store <2 x double> %34, ptr %36, align 8, !tbaa !14, !alias.scope !19, !noalias !16
  %index.next = add nuw i64 %index, 4
  %37 = icmp eq i64 %index.next, %n.vec
  br i1 %37, label %middle.block, label %vector.body, !llvm.loop !21

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

scalar.ph.preheader:                              ; preds = %.preheader.us, %middle.block
  %.01920.us.ph = phi i64 [ 0, %.preheader.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
  %.01920.us.prol = phi i64 [ %42, %scalar.ph.prol ], [ %.01920.us.ph, %scalar.ph.preheader ]
  %prol.iter = phi i64 [ %prol.iter.next, %scalar.ph.prol ], [ 0, %scalar.ph.preheader ]
  %38 = getelementptr double, ptr %28, i64 %.01920.us.prol
  %39 = load double, ptr %38, align 8, !tbaa !14
  %40 = fmul double %39, %1
  %41 = getelementptr double, ptr %30, i64 %.01920.us.prol
  store double %40, ptr %41, align 8, !tbaa !14
  %42 = add nuw i64 %.01920.us.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 !25

scalar.ph.prol.loopexit:                          ; preds = %scalar.ph.prol, %scalar.ph.preheader
  %.01920.us.unr = phi i64 [ %.01920.us.ph, %scalar.ph.preheader ], [ %42, %scalar.ph.prol ]
  %43 = sub i64 %.01920.us.ph, %13
  %44 = icmp ugt i64 %43, -4
  br i1 %44, label %._crit_edge.us, label %scalar.ph

scalar.ph:                                        ; preds = %scalar.ph.prol.loopexit, %scalar.ph
  %.01920.us = phi i64 [ %64, %scalar.ph ], [ %.01920.us.unr, %scalar.ph.prol.loopexit ]
  %45 = getelementptr double, ptr %28, i64 %.01920.us
  %46 = load double, ptr %45, align 8, !tbaa !14
  %47 = fmul double %46, %1
  %48 = getelementptr double, ptr %30, i64 %.01920.us
  store double %47, ptr %48, align 8, !tbaa !14
  %49 = add nuw i64 %.01920.us, 1
  %50 = getelementptr double, ptr %28, i64 %49
  %51 = load double, ptr %50, align 8, !tbaa !14
  %52 = fmul double %51, %1
  %53 = getelementptr double, ptr %30, i64 %49
  store double %52, ptr %53, align 8, !tbaa !14
  %54 = add nuw i64 %.01920.us, 2
  %55 = getelementptr double, ptr %28, i64 %54
  %56 = load double, ptr %55, align 8, !tbaa !14
  %57 = fmul double %56, %1
  %58 = getelementptr double, ptr %30, i64 %54
  store double %57, ptr %58, align 8, !tbaa !14
  %59 = add nuw i64 %.01920.us, 3
  %60 = getelementptr double, ptr %28, i64 %59
  %61 = load double, ptr %60, align 8, !tbaa !14
  %62 = fmul double %61, %1
  %63 = getelementptr double, ptr %30, i64 %59
  store double %62, ptr %63, align 8, !tbaa !14
  %64 = add nuw i64 %.01920.us, 4
  %exitcond.not.3 = icmp eq i64 %64, %13
  br i1 %exitcond.not.3, label %._crit_edge.us, label %scalar.ph, !llvm.loop !27

._crit_edge.us:                                   ; preds = %scalar.ph.prol.loopexit, %scalar.ph, %middle.block
  %65 = add nuw i64 %.021.us, 1
  %exitcond25.not = icmp eq i64 %65, %12
  br i1 %exitcond25.not, label %._crit_edge22, label %.preheader.us, !llvm.loop !28

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

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

!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 24}
!6 = !{!"XsMatrix", !7, i64 0, !10, i64 8, !10, i64 16, !10, i64 24, !10, i64 32}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"long", !8, i64 0}
!11 = !{!6, !10, i64 8}
!12 = !{!6, !10, i64 16}
!13 = !{!6, !7, i64 0}
!14 = !{!15, !15, i64 0}
!15 = !{!"double", !8, i64 0}
!16 = !{!17}
!17 = distinct !{!17, !18}
!18 = distinct !{!18, !"LVerDomain"}
!19 = !{!20}
!20 = distinct !{!20, !18}
!21 = distinct !{!21, !22, !23, !24}
!22 = !{!"llvm.loop.mustprogress"}
!23 = !{!"llvm.loop.isvectorized", i32 1}
!24 = !{!"llvm.loop.unroll.runtime.disable"}
!25 = distinct !{!25, !26}
!26 = !{!"llvm.loop.unroll.disable"}
!27 = distinct !{!27, !22, !23}
!28 = distinct !{!28, !22}


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