; 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: nounwind uwtable
define dso_local void @XsMatrix_construct(ptr noundef %0, i64 noundef %1, i64 noundef %2, i64 noundef %3, ptr noundef %4, i64 noundef %5) #0 {
  %7 = alloca ptr, align 8
  %8 = alloca i64, align 8
  %9 = alloca i64, align 8
  %10 = alloca i64, align 8
  %11 = alloca ptr, align 8
  %12 = alloca i64, align 8
  %13 = alloca i64, align 8
  %14 = alloca i64, align 8
  %15 = alloca ptr, align 8
  store ptr %0, ptr %7, align 8, !tbaa !5
  store i64 %1, ptr %8, align 8, !tbaa !9
  store i64 %2, ptr %9, align 8, !tbaa !9
  store i64 %3, ptr %10, align 8, !tbaa !9
  store ptr %4, ptr %11, align 8, !tbaa !5
  store i64 %5, ptr %12, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %13) #5
  call void @llvm.lifetime.start.p0(i64 8, ptr %14) #5
  %16 = load i64, ptr %8, align 8, !tbaa !9
  %17 = load i64, ptr %10, align 8, !tbaa !9
  %18 = mul i64 %16, %17
  store i64 %18, ptr %14, align 8, !tbaa !9
  %19 = load i64, ptr %10, align 8, !tbaa !9
  %20 = icmp eq i64 %19, 0
  br i1 %20, label %21, label %26

21:                                               ; preds = %6
  %22 = load i64, ptr %9, align 8, !tbaa !9
  store i64 %22, ptr %10, align 8, !tbaa !9
  %23 = load i64, ptr %8, align 8, !tbaa !9
  %24 = load i64, ptr %10, align 8, !tbaa !9
  %25 = mul i64 %23, %24
  store i64 %25, ptr %14, align 8, !tbaa !9
  br label %26

26:                                               ; preds = %21, %6
  %27 = load i64, ptr %14, align 8, !tbaa !9
  %28 = icmp ne i64 %27, 0
  br i1 %28, label %29, label %37

29:                                               ; preds = %26
  call void @llvm.lifetime.start.p0(i64 8, ptr %15) #5
  %30 = load i64, ptr %14, align 8, !tbaa !9
  %31 = mul i64 %30, 8
  %32 = call ptr @xsAlignedMalloc(i64 noundef %31)
  store ptr %32, ptr %15, align 8, !tbaa !5
  %33 = load ptr, ptr %15, align 8, !tbaa !5
  %34 = load ptr, ptr %7, align 8, !tbaa !5
  %35 = getelementptr inbounds %struct.XsMatrix, ptr %34, i32 0, i32 0
  store ptr %33, ptr %35, align 1, !tbaa !5
  %36 = call i32 @XsMatrix_incAllocCount()
  call void @llvm.lifetime.end.p0(i64 8, ptr %15) #5
  br label %40

37:                                               ; preds = %26
  %38 = load ptr, ptr %7, align 8, !tbaa !5
  %39 = getelementptr inbounds %struct.XsMatrix, ptr %38, i32 0, i32 0
  store ptr null, ptr %39, align 1, !tbaa !5
  br label %40

40:                                               ; preds = %37, %29
  %41 = load ptr, ptr %7, align 8, !tbaa !5
  %42 = getelementptr inbounds %struct.XsMatrix, ptr %41, i32 0, i32 4
  store i64 1, ptr %42, align 1, !tbaa !9
  %43 = load i64, ptr %8, align 8, !tbaa !9
  %44 = load ptr, ptr %7, align 8, !tbaa !5
  %45 = getelementptr inbounds %struct.XsMatrix, ptr %44, i32 0, i32 1
  store i64 %43, ptr %45, align 1, !tbaa !9
  %46 = load i64, ptr %9, align 8, !tbaa !9
  %47 = load ptr, ptr %7, align 8, !tbaa !5
  %48 = getelementptr inbounds %struct.XsMatrix, ptr %47, i32 0, i32 2
  store i64 %46, ptr %48, align 1, !tbaa !9
  %49 = load i64, ptr %10, align 8, !tbaa !9
  %50 = load ptr, ptr %7, align 8, !tbaa !5
  %51 = getelementptr inbounds %struct.XsMatrix, ptr %50, i32 0, i32 3
  store i64 %49, ptr %51, align 1, !tbaa !9
  %52 = load ptr, ptr %11, align 8, !tbaa !5
  %53 = icmp ne ptr %52, null
  br i1 %53, label %54, label %96

54:                                               ; preds = %40
  %55 = load i64, ptr %14, align 8, !tbaa !9
  %56 = icmp ne i64 %55, 0
  br i1 %56, label %57, label %96

57:                                               ; preds = %54
  %58 = load i64, ptr %12, align 8, !tbaa !9
  %59 = icmp eq i64 %58, 0
  br i1 %59, label %64, label %60

60:                                               ; preds = %57
  %61 = load i64, ptr %12, align 8, !tbaa !9
  %62 = load i64, ptr %10, align 8, !tbaa !9
  %63 = icmp eq i64 %61, %62
  br i1 %63, label %64, label %71

64:                                               ; preds = %60, %57
  %65 = load ptr, ptr %7, align 8, !tbaa !5
  %66 = getelementptr inbounds %struct.XsMatrix, ptr %65, i32 0, i32 0
  %67 = load ptr, ptr %66, align 1, !tbaa !11
  %68 = load ptr, ptr %11, align 8, !tbaa !5
  %69 = load i64, ptr %14, align 8, !tbaa !9
  %70 = mul i64 %69, 8
  call void @llvm.memcpy.p0.p0.i64(ptr align 8 %67, ptr align 8 %68, i64 %70, i1 false)
  br label %95

71:                                               ; preds = %60
  store i64 0, ptr %13, align 8, !tbaa !9
  br label %72

72:                                               ; preds = %91, %71
  %73 = load i64, ptr %13, align 8, !tbaa !9
  %74 = load i64, ptr %8, align 8, !tbaa !9
  %75 = icmp ult i64 %73, %74
  br i1 %75, label %76, label %94

76:                                               ; preds = %72
  %77 = load ptr, ptr %7, align 8, !tbaa !5
  %78 = getelementptr inbounds %struct.XsMatrix, ptr %77, i32 0, i32 0
  %79 = load ptr, ptr %78, align 1, !tbaa !11
  %80 = load i64, ptr %13, align 8, !tbaa !9
  %81 = load i64, ptr %10, align 8, !tbaa !9
  %82 = mul i64 %80, %81
  %83 = getelementptr inbounds double, ptr %79, i64 %82
  %84 = load ptr, ptr %11, align 8, !tbaa !5
  %85 = load i64, ptr %13, align 8, !tbaa !9
  %86 = load i64, ptr %12, align 8, !tbaa !9
  %87 = mul i64 %85, %86
  %88 = getelementptr inbounds double, ptr %84, i64 %87
  %89 = load i64, ptr %9, align 8, !tbaa !9
  %90 = mul i64 %89, 8
  call void @llvm.memcpy.p0.p0.i64(ptr align 8 %83, ptr align 8 %88, i64 %90, i1 false)
  br label %91

91:                                               ; preds = %76
  %92 = load i64, ptr %13, align 8, !tbaa !9
  %93 = add i64 %92, 1
  store i64 %93, ptr %13, align 8, !tbaa !9
  br label %72, !llvm.loop !13

94:                                               ; preds = %72
  br label %95

95:                                               ; preds = %94, %64
  br label %96

96:                                               ; preds = %95, %54, %40
  call void @llvm.lifetime.end.p0(i64 8, ptr %14) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %13) #5
  ret void
}

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

declare ptr @xsAlignedMalloc(i64 noundef) #2

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

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #3

; Function Attrs: inlinehint nounwind uwtable
declare hidden i32 @XsMatrix_incAllocCount() #4

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" }
attributes #1 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { "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 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #4 = { inlinehint 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 #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/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"long", !7, i64 0}
!11 = !{!12, !6, i64 0}
!12 = !{!"XsMatrix", !6, i64 0, !10, i64 8, !10, i64 16, !10, i64 24, !10, i64 32}
!13 = distinct !{!13, !14}
!14 = !{!"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"

; Function Attrs: nounwind uwtable
define dso_local void @XsMatrix_construct(ptr nocapture noundef %0, i64 noundef %1, i64 noundef %2, i64 noundef %3, ptr noundef readonly %4, i64 noundef %5) local_unnamed_addr #0 {
  %7 = icmp eq i64 %3, 0
  %spec.select = select i1 %7, i64 %2, i64 %3
  %.036 = mul i64 %spec.select, %1
  %.not = icmp eq i64 %.036, 0
  br i1 %.not, label %.thread, label %12

.thread:                                          ; preds = %6
  store ptr null, ptr %0, align 1, !tbaa !5
  %8 = getelementptr inbounds i8, ptr %0, i64 32
  store i64 1, ptr %8, align 1, !tbaa !9
  %9 = getelementptr inbounds i8, ptr %0, i64 8
  store i64 %1, ptr %9, align 1, !tbaa !9
  %10 = getelementptr inbounds i8, ptr %0, i64 16
  store i64 %2, ptr %10, align 1, !tbaa !9
  %11 = getelementptr inbounds i8, ptr %0, i64 24
  store i64 %spec.select, ptr %11, align 1, !tbaa !9
  br label %.loopexit

12:                                               ; preds = %6
  %13 = shl i64 %.036, 3
  %14 = tail call ptr @xsAlignedMalloc(i64 noundef %13) #4
  store ptr %14, ptr %0, align 1, !tbaa !5
  %15 = tail call i32 @XsMatrix_incAllocCount()
  %16 = getelementptr inbounds i8, ptr %0, i64 32
  store i64 1, ptr %16, align 1, !tbaa !9
  %17 = getelementptr inbounds i8, ptr %0, i64 8
  store i64 %1, ptr %17, align 1, !tbaa !9
  %18 = getelementptr inbounds i8, ptr %0, i64 16
  store i64 %2, ptr %18, align 1, !tbaa !9
  %19 = getelementptr inbounds i8, ptr %0, i64 24
  store i64 %spec.select, ptr %19, align 1, !tbaa !9
  %.not44 = icmp eq ptr %4, null
  br i1 %.not44, label %.loopexit, label %20

20:                                               ; preds = %12
  %21 = icmp eq i64 %5, 0
  %22 = icmp eq i64 %spec.select, %5
  %or.cond41 = or i1 %21, %22
  br i1 %or.cond41, label %25, label %.preheader

.preheader:                                       ; preds = %20
  %.not45 = icmp eq i64 %1, 0
  br i1 %.not45, label %.loopexit, label %.lr.ph

.lr.ph:                                           ; preds = %.preheader
  %23 = shl i64 %2, 3
  %xtraiter = and i64 %1, 1
  %24 = icmp eq i64 %1, 1
  br i1 %24, label %.loopexit.loopexit.unr-lcssa, label %.lr.ph.new

.lr.ph.new:                                       ; preds = %.lr.ph
  %unroll_iter = and i64 %1, -2
  br label %27

25:                                               ; preds = %20
  %26 = load ptr, ptr %0, align 1, !tbaa !11
  tail call void @llvm.memcpy.p0.p0.i64(ptr align 8 %26, ptr nonnull align 8 %4, i64 %13, i1 false)
  br label %.loopexit

27:                                               ; preds = %27, %.lr.ph.new
  %.03743 = phi i64 [ 0, %.lr.ph.new ], [ %39, %27 ]
  %niter = phi i64 [ 0, %.lr.ph.new ], [ %niter.next.1, %27 ]
  %28 = load ptr, ptr %0, align 1, !tbaa !11
  %29 = mul i64 %.03743, %spec.select
  %30 = getelementptr inbounds double, ptr %28, i64 %29
  %31 = mul i64 %.03743, %5
  %32 = getelementptr inbounds double, ptr %4, i64 %31
  tail call void @llvm.memcpy.p0.p0.i64(ptr align 8 %30, ptr nonnull align 8 %32, i64 %23, i1 false)
  %33 = or disjoint i64 %.03743, 1
  %34 = load ptr, ptr %0, align 1, !tbaa !11
  %35 = mul i64 %33, %spec.select
  %36 = getelementptr inbounds double, ptr %34, i64 %35
  %37 = mul i64 %33, %5
  %38 = getelementptr inbounds double, ptr %4, i64 %37
  tail call void @llvm.memcpy.p0.p0.i64(ptr align 8 %36, ptr nonnull align 8 %38, i64 %23, i1 false)
  %39 = add nuw i64 %.03743, 2
  %niter.next.1 = add i64 %niter, 2
  %niter.ncmp.1 = icmp eq i64 %niter.next.1, %unroll_iter
  br i1 %niter.ncmp.1, label %.loopexit.loopexit.unr-lcssa, label %27, !llvm.loop !13

.loopexit.loopexit.unr-lcssa:                     ; preds = %27, %.lr.ph
  %.03743.unr = phi i64 [ 0, %.lr.ph ], [ %39, %27 ]
  %lcmp.mod.not = icmp eq i64 %xtraiter, 0
  br i1 %lcmp.mod.not, label %.loopexit, label %.loopexit.loopexit.epilog-lcssa

.loopexit.loopexit.epilog-lcssa:                  ; preds = %.loopexit.loopexit.unr-lcssa
  %40 = load ptr, ptr %0, align 1, !tbaa !11
  %41 = mul i64 %.03743.unr, %spec.select
  %42 = getelementptr inbounds double, ptr %40, i64 %41
  %43 = mul i64 %.03743.unr, %5
  %44 = getelementptr inbounds double, ptr %4, i64 %43
  tail call void @llvm.memcpy.p0.p0.i64(ptr align 8 %42, ptr nonnull align 8 %44, i64 %23, i1 false)
  br label %.loopexit

.loopexit:                                        ; preds = %.loopexit.loopexit.epilog-lcssa, %.loopexit.loopexit.unr-lcssa, %.preheader, %.thread, %25, %12
  ret void
}

declare ptr @xsAlignedMalloc(i64 noundef) local_unnamed_addr #1

; Function Attrs: mustprogress nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #2

; Function Attrs: inlinehint nounwind uwtable
declare hidden i32 @XsMatrix_incAllocCount() local_unnamed_addr #3

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" }
attributes #1 = { "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 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #3 = { inlinehint 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 #4 = { 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 = !{!"long", !7, i64 0}
!11 = !{!12, !6, i64 0}
!12 = !{!"XsMatrix", !6, i64 0, !10, i64 8, !10, i64 16, !10, i64 24, !10, i64 32}
!13 = distinct !{!13, !14}
!14 = !{!"llvm.loop.mustprogress"}


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