; LLVM IR from glaretechnologies/substrata :: opus/opus-1.3.1/src (mapping_matrix)

; 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.MappingMatrix = type { i32, i32, i32 }

; 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 ptr @mapping_matrix_get_data(ptr noundef) #1

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

22:                                               ; preds = %70, %7
  %23 = load i32, ptr %16, align 4, !tbaa !9
  %24 = load i32, ptr %14, align 4, !tbaa !9
  %25 = icmp slt i32 %23, %24
  br i1 %25, label %26, label %73

26:                                               ; preds = %22
  %27 = load ptr, ptr %9, align 8, !tbaa !5
  %28 = load i32, ptr %11, align 4, !tbaa !9
  %29 = load i32, ptr %16, align 4, !tbaa !9
  %30 = mul nsw i32 %28, %29
  %31 = sext i32 %30 to i64
  %32 = getelementptr inbounds float, ptr %27, i64 %31
  %33 = load float, ptr %32, align 4, !tbaa !11
  store float %33, ptr %18, align 4, !tbaa !11
  store i32 0, ptr %17, align 4, !tbaa !9
  br label %34

34:                                               ; preds = %66, %26
  %35 = load i32, ptr %17, align 4, !tbaa !9
  %36 = load i32, ptr %13, align 4, !tbaa !9
  %37 = icmp slt i32 %35, %36
  br i1 %37, label %38, label %69

38:                                               ; preds = %34
  call void @llvm.lifetime.start.p0(i64 4, ptr %19) #2
  %39 = load ptr, ptr %15, align 8, !tbaa !5
  %40 = load ptr, ptr %8, align 8, !tbaa !5
  %41 = getelementptr inbounds %struct.MappingMatrix, ptr %40, i32 0, i32 0
  %42 = load i32, ptr %41, align 4, !tbaa !13
  %43 = load i32, ptr %10, align 4, !tbaa !9
  %44 = mul nsw i32 %42, %43
  %45 = load i32, ptr %17, align 4, !tbaa !9
  %46 = add nsw i32 %44, %45
  %47 = sext i32 %46 to i64
  %48 = getelementptr inbounds i16, ptr %39, i64 %47
  %49 = load i16, ptr %48, align 2, !tbaa !15
  %50 = sext i16 %49 to i32
  %51 = sitofp i32 %50 to float
  %52 = fmul float 0x3F00000000000000, %51
  %53 = load float, ptr %18, align 4, !tbaa !11
  %54 = fmul float %52, %53
  store float %54, ptr %19, align 4, !tbaa !11
  %55 = load float, ptr %19, align 4, !tbaa !11
  %56 = load ptr, ptr %12, align 8, !tbaa !5
  %57 = load i32, ptr %13, align 4, !tbaa !9
  %58 = load i32, ptr %16, align 4, !tbaa !9
  %59 = mul nsw i32 %57, %58
  %60 = load i32, ptr %17, align 4, !tbaa !9
  %61 = add nsw i32 %59, %60
  %62 = sext i32 %61 to i64
  %63 = getelementptr inbounds float, ptr %56, i64 %62
  %64 = load float, ptr %63, align 4, !tbaa !11
  %65 = fadd float %64, %55
  store float %65, ptr %63, align 4, !tbaa !11
  call void @llvm.lifetime.end.p0(i64 4, ptr %19) #2
  br label %66

66:                                               ; preds = %38
  %67 = load i32, ptr %17, align 4, !tbaa !9
  %68 = add nsw i32 %67, 1
  store i32 %68, ptr %17, align 4, !tbaa !9
  br label %34, !llvm.loop !17

69:                                               ; preds = %34
  br label %70

70:                                               ; preds = %69
  %71 = load i32, ptr %16, align 4, !tbaa !9
  %72 = add nsw i32 %71, 1
  store i32 %72, ptr %16, align 4, !tbaa !9
  br label %22, !llvm.loop !19

73:                                               ; preds = %22
  call void @llvm.lifetime.end.p0(i64 4, ptr %18) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %17) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %16) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %15) #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 = !{!"int", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"float", !7, i64 0}
!13 = !{!14, !10, i64 0}
!14 = !{!"MappingMatrix", !10, i64 0, !10, i64 4, !10, i64 8}
!15 = !{!16, !16, i64 0}
!16 = !{!"short", !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: nounwind uwtable
declare dso_local ptr @mapping_matrix_get_data(ptr noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local void @mapping_matrix_multiply_channel_out_float(ptr noundef %0, ptr nocapture noundef readonly %1, i32 noundef %2, i32 noundef %3, ptr nocapture noundef %4, i32 noundef %5, i32 noundef %6) local_unnamed_addr #0 {
  %8 = tail call ptr @mapping_matrix_get_data(ptr noundef %0)
  %9 = icmp sgt i32 %6, 0
  %10 = icmp sgt i32 %5, 0
  %or.cond = and i1 %9, %10
  br i1 %or.cond, label %.lr.ph24.split.us, label %._crit_edge25

.lr.ph24.split.us:                                ; preds = %7
  %11 = load i32, ptr %0, align 4, !tbaa !5
  %12 = mul nsw i32 %11, %2
  %13 = sext i32 %12 to i64
  %14 = sext i32 %3 to i64
  %15 = zext nneg i32 %5 to i64
  %wide.trip.count31 = zext nneg i32 %6 to i64
  %wide.trip.count = zext nneg i32 %5 to i64
  %invariant.gep = getelementptr i16, ptr %8, i64 %13
  %min.iters.check = icmp ult i32 %5, 8
  %n.vec = and i64 %wide.trip.count, 2147483640
  %cmp.n = icmp eq i64 %n.vec, %wide.trip.count
  br label %.lr.ph.us

.lr.ph.us:                                        ; preds = %._crit_edge.us, %.lr.ph24.split.us
  %indvars.iv28 = phi i64 [ %indvars.iv.next29, %._crit_edge.us ], [ 0, %.lr.ph24.split.us ]
  %16 = mul nsw i64 %indvars.iv28, %14
  %17 = getelementptr inbounds float, ptr %1, i64 %16
  %18 = load float, ptr %17, align 4, !tbaa !10
  %19 = mul nuw nsw i64 %indvars.iv28, %15
  %invariant.gep33 = getelementptr inbounds float, ptr %4, i64 %19
  br i1 %min.iters.check, label %scalar.ph.preheader, label %vector.ph

vector.ph:                                        ; preds = %.lr.ph.us
  %broadcast.splatinsert = insertelement <4 x float> poison, float %18, 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 ]
  %20 = getelementptr i16, ptr %invariant.gep, i64 %index
  %21 = getelementptr i8, ptr %20, i64 8
  %wide.load = load <4 x i16>, ptr %20, align 2, !tbaa !12
  %wide.load35 = load <4 x i16>, ptr %21, align 2, !tbaa !12
  %22 = sitofp <4 x i16> %wide.load to <4 x float>
  %23 = sitofp <4 x i16> %wide.load35 to <4 x float>
  %24 = fmul <4 x float> %22, <float 0x3F00000000000000, float 0x3F00000000000000, float 0x3F00000000000000, float 0x3F00000000000000>
  %25 = fmul <4 x float> %23, <float 0x3F00000000000000, float 0x3F00000000000000, float 0x3F00000000000000, float 0x3F00000000000000>
  %26 = fmul <4 x float> %broadcast.splat, %24
  %27 = fmul <4 x float> %broadcast.splat, %25
  %28 = getelementptr inbounds float, ptr %invariant.gep33, i64 %index
  %29 = getelementptr inbounds i8, ptr %28, i64 16
  %wide.load36 = load <4 x float>, ptr %28, align 4, !tbaa !10
  %wide.load37 = load <4 x float>, ptr %29, align 4, !tbaa !10
  %30 = fadd <4 x float> %wide.load36, %26
  %31 = fadd <4 x float> %wide.load37, %27
  store <4 x float> %30, ptr %28, align 4, !tbaa !10
  store <4 x float> %31, ptr %29, align 4, !tbaa !10
  %index.next = add nuw i64 %index, 8
  %32 = icmp eq i64 %index.next, %n.vec
  br i1 %32, label %middle.block, label %vector.body, !llvm.loop !14

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.iv.ph = phi i64 [ 0, %.lr.ph.us ], [ %n.vec, %middle.block ]
  br label %scalar.ph

scalar.ph:                                        ; preds = %scalar.ph.preheader, %scalar.ph
  %indvars.iv = phi i64 [ %indvars.iv.next, %scalar.ph ], [ %indvars.iv.ph, %scalar.ph.preheader ]
  %gep = getelementptr i16, ptr %invariant.gep, i64 %indvars.iv
  %33 = load i16, ptr %gep, align 2, !tbaa !12
  %34 = sitofp i16 %33 to float
  %35 = fmul float %34, 0x3F00000000000000
  %36 = fmul float %18, %35
  %gep34 = getelementptr inbounds float, ptr %invariant.gep33, i64 %indvars.iv
  %37 = load float, ptr %gep34, align 4, !tbaa !10
  %38 = fadd float %37, %36
  store float %38, ptr %gep34, align 4, !tbaa !10
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %exitcond.not = icmp eq i64 %indvars.iv.next, %wide.trip.count
  br i1 %exitcond.not, label %._crit_edge.us, label %scalar.ph, !llvm.loop !18

._crit_edge.us:                                   ; preds = %scalar.ph, %middle.block
  %indvars.iv.next29 = add nuw nsw i64 %indvars.iv28, 1
  %exitcond32.not = icmp eq i64 %indvars.iv.next29, %wide.trip.count31
  br i1 %exitcond32.not, label %._crit_edge25, label %.lr.ph.us, !llvm.loop !19

._crit_edge25:                                    ; preds = %._crit_edge.us, %7
  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, !7, i64 0}
!6 = !{!"MappingMatrix", !7, i64 0, !7, i64 4, !7, i64 8}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!11, !11, i64 0}
!11 = !{!"float", !8, i64 0}
!12 = !{!13, !13, i64 0}
!13 = !{!"short", !8, i64 0}
!14 = distinct !{!14, !15, !16, !17}
!15 = !{!"llvm.loop.mustprogress"}
!16 = !{!"llvm.loop.isvectorized", i32 1}
!17 = !{!"llvm.loop.unroll.runtime.disable"}
!18 = distinct !{!18, !15, !17, !16}
!19 = distinct !{!19, !15}


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