; 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_short(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 i32, align 4
  %19 = alloca i32, 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) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %16) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %17) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %18) #3
  %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 = %74, %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 %77

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
  %34 = call signext i16 @FLOAT2INT16(float noundef %33)
  %35 = sext i16 %34 to i32
  store i32 %35, ptr %18, align 4, !tbaa !9
  store i32 0, ptr %17, align 4, !tbaa !9
  br label %36

36:                                               ; preds = %70, %26
  %37 = load i32, ptr %17, align 4, !tbaa !9
  %38 = load i32, ptr %13, align 4, !tbaa !9
  %39 = icmp slt i32 %37, %38
  br i1 %39, label %40, label %73

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

70:                                               ; preds = %40
  %71 = load i32, ptr %17, align 4, !tbaa !9
  %72 = add nsw i32 %71, 1
  store i32 %72, ptr %17, align 4, !tbaa !9
  br label %36, !llvm.loop !17

73:                                               ; preds = %36
  br label %74

74:                                               ; preds = %73
  %75 = load i32, ptr %16, align 4, !tbaa !9
  %76 = add nsw i32 %75, 1
  store i32 %76, ptr %16, align 4, !tbaa !9
  br label %22, !llvm.loop !19

77:                                               ; preds = %22
  call void @llvm.lifetime.end.p0(i64 4, ptr %18) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %17) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %16) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %15) #3
  ret void
}

; Function Attrs: inlinehint nounwind uwtable
declare hidden signext i16 @FLOAT2INT16(float noundef) #2

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 = { 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 #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/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_short(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
  br i1 %9, label %.lr.ph24, label %._crit_edge25

.lr.ph24:                                         ; preds = %7
  %10 = icmp sgt i32 %5, 0
  %11 = sext i32 %3 to i64
  br i1 %10, label %.lr.ph.us.preheader, label %.lr.ph24.split.preheader

.lr.ph24.split.preheader:                         ; preds = %.lr.ph24
  %wide.trip.count = zext nneg i32 %6 to i64
  br label %.lr.ph24.split

.lr.ph.us.preheader:                              ; preds = %.lr.ph24
  %12 = zext nneg i32 %5 to i64
  %wide.trip.count36 = zext nneg i32 %6 to i64
  %wide.trip.count31 = zext nneg i32 %5 to i64
  %13 = mul nuw nsw i64 %wide.trip.count36, %wide.trip.count31
  %14 = shl nuw nsw i64 %13, 1
  %scevgep = getelementptr i8, ptr %4, i64 %14
  %15 = shl nuw nsw i64 %wide.trip.count31, 1
  %scevgep42 = getelementptr i8, ptr %8, i64 %15
  %min.iters.check = icmp ult i32 %5, 8
  %n.vec = and i64 %wide.trip.count31, 2147483640
  %cmp.n = icmp eq i64 %n.vec, %wide.trip.count31
  %xtraiter = and i64 %wide.trip.count31, 1
  %lcmp.mod.not = icmp eq i64 %xtraiter, 0
  %16 = add nsw i64 %wide.trip.count31, -1
  br label %.lr.ph.us

.lr.ph.us:                                        ; preds = %.lr.ph.us.preheader, %._crit_edge.us
  %indvars.iv33 = phi i64 [ 0, %.lr.ph.us.preheader ], [ %indvars.iv.next34, %._crit_edge.us ]
  %17 = mul nsw i64 %indvars.iv33, %11
  %18 = getelementptr inbounds float, ptr %1, i64 %17
  %19 = load float, ptr %18, align 4, !tbaa !5
  %20 = tail call signext i16 @FLOAT2INT16(float noundef %19)
  %21 = sext i16 %20 to i32
  %22 = load i32, ptr %0, align 4, !tbaa !9
  %23 = mul nsw i32 %22, %2
  %24 = mul nuw nsw i64 %indvars.iv33, %12
  %25 = sext i32 %23 to i64
  %invariant.gep = getelementptr i16, ptr %8, i64 %25
  %invariant.gep39 = getelementptr inbounds i16, ptr %4, i64 %24
  br i1 %min.iters.check, label %scalar.ph.preheader, label %vector.memcheck

vector.memcheck:                                  ; preds = %.lr.ph.us
  %26 = shl nsw i64 %25, 1
  %scevgep43 = getelementptr i8, ptr %scevgep42, i64 %26
  %bound0 = icmp ugt ptr %scevgep43, %4
  %bound1 = icmp ult ptr %invariant.gep, %scevgep
  %found.conflict = and i1 %bound0, %bound1
  br i1 %found.conflict, label %scalar.ph.preheader, label %vector.ph

vector.ph:                                        ; preds = %vector.memcheck
  %broadcast.splatinsert = insertelement <8 x i32> poison, i32 %21, i64 0
  %broadcast.splat = shufflevector <8 x i32> %broadcast.splatinsert, <8 x i32> poison, <8 x i32> zeroinitializer
  br label %vector.body

vector.body:                                      ; preds = %vector.body, %vector.ph
  %index = phi i64 [ 0, %vector.ph ], [ %index.next, %vector.body ]
  %27 = getelementptr i16, ptr %invariant.gep, i64 %index
  %wide.load = load <8 x i16>, ptr %27, align 2, !tbaa !12, !alias.scope !14
  %28 = sext <8 x i16> %wide.load to <8 x i32>
  %29 = mul nsw <8 x i32> %broadcast.splat, %28
  %30 = add nsw <8 x i32> %29, <i32 16384, i32 16384, i32 16384, i32 16384, i32 16384, i32 16384, i32 16384, i32 16384>
  %31 = lshr <8 x i32> %30, <i32 15, i32 15, i32 15, i32 15, i32 15, i32 15, i32 15, i32 15>
  %32 = getelementptr inbounds i16, ptr %invariant.gep39, i64 %index
  %wide.load44 = load <8 x i16>, ptr %32, align 2, !tbaa !12, !alias.scope !17, !noalias !14
  %33 = trunc <8 x i32> %31 to <8 x i16>
  %34 = add <8 x i16> %wide.load44, %33
  store <8 x i16> %34, ptr %32, align 2, !tbaa !12, !alias.scope !17, !noalias !14
  %index.next = add nuw i64 %index, 8
  %35 = icmp eq i64 %index.next, %n.vec
  br i1 %35, label %middle.block, label %vector.body, !llvm.loop !19

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

scalar.ph.preheader:                              ; preds = %middle.block, %vector.memcheck, %.lr.ph.us
  %indvars.iv28.ph = phi i64 [ 0, %vector.memcheck ], [ 0, %.lr.ph.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
  %gep.prol = getelementptr i16, ptr %invariant.gep, i64 %indvars.iv28.ph
  %36 = load i16, ptr %gep.prol, align 2, !tbaa !12
  %37 = sext i16 %36 to i32
  %38 = mul nsw i32 %37, %21
  %39 = add nsw i32 %38, 16384
  %40 = lshr i32 %39, 15
  %gep40.prol = getelementptr inbounds i16, ptr %invariant.gep39, i64 %indvars.iv28.ph
  %41 = load i16, ptr %gep40.prol, align 2, !tbaa !12
  %42 = trunc i32 %40 to i16
  %43 = add i16 %41, %42
  store i16 %43, ptr %gep40.prol, align 2, !tbaa !12
  %indvars.iv.next29.prol = or disjoint i64 %indvars.iv28.ph, 1
  br label %scalar.ph.prol.loopexit

scalar.ph.prol.loopexit:                          ; preds = %scalar.ph.prol, %scalar.ph.preheader
  %indvars.iv28.unr = phi i64 [ %indvars.iv28.ph, %scalar.ph.preheader ], [ %indvars.iv.next29.prol, %scalar.ph.prol ]
  %44 = icmp eq i64 %indvars.iv28.ph, %16
  br i1 %44, label %._crit_edge.us, label %scalar.ph

scalar.ph:                                        ; preds = %scalar.ph.prol.loopexit, %scalar.ph
  %indvars.iv28 = phi i64 [ %indvars.iv.next29.1, %scalar.ph ], [ %indvars.iv28.unr, %scalar.ph.prol.loopexit ]
  %gep = getelementptr i16, ptr %invariant.gep, i64 %indvars.iv28
  %45 = load i16, ptr %gep, align 2, !tbaa !12
  %46 = sext i16 %45 to i32
  %47 = mul nsw i32 %46, %21
  %48 = add nsw i32 %47, 16384
  %49 = lshr i32 %48, 15
  %gep40 = getelementptr inbounds i16, ptr %invariant.gep39, i64 %indvars.iv28
  %50 = load i16, ptr %gep40, align 2, !tbaa !12
  %51 = trunc i32 %49 to i16
  %52 = add i16 %50, %51
  store i16 %52, ptr %gep40, align 2, !tbaa !12
  %indvars.iv.next29 = add nuw nsw i64 %indvars.iv28, 1
  %gep.1 = getelementptr i16, ptr %invariant.gep, i64 %indvars.iv.next29
  %53 = load i16, ptr %gep.1, align 2, !tbaa !12
  %54 = sext i16 %53 to i32
  %55 = mul nsw i32 %54, %21
  %56 = add nsw i32 %55, 16384
  %57 = lshr i32 %56, 15
  %gep40.1 = getelementptr inbounds i16, ptr %invariant.gep39, i64 %indvars.iv.next29
  %58 = load i16, ptr %gep40.1, align 2, !tbaa !12
  %59 = trunc i32 %57 to i16
  %60 = add i16 %58, %59
  store i16 %60, ptr %gep40.1, align 2, !tbaa !12
  %indvars.iv.next29.1 = add nuw nsw i64 %indvars.iv28, 2
  %exitcond32.not.1 = icmp eq i64 %indvars.iv.next29.1, %wide.trip.count31
  br i1 %exitcond32.not.1, label %._crit_edge.us, label %scalar.ph, !llvm.loop !23

._crit_edge.us:                                   ; preds = %scalar.ph.prol.loopexit, %scalar.ph, %middle.block
  %indvars.iv.next34 = add nuw nsw i64 %indvars.iv33, 1
  %exitcond37.not = icmp eq i64 %indvars.iv.next34, %wide.trip.count36
  br i1 %exitcond37.not, label %._crit_edge25, label %.lr.ph.us, !llvm.loop !24

.lr.ph24.split:                                   ; preds = %.lr.ph24.split.preheader, %.lr.ph24.split
  %indvars.iv = phi i64 [ 0, %.lr.ph24.split.preheader ], [ %indvars.iv.next, %.lr.ph24.split ]
  %61 = mul nsw i64 %indvars.iv, %11
  %62 = getelementptr inbounds float, ptr %1, i64 %61
  %63 = load float, ptr %62, align 4, !tbaa !5
  %64 = tail call signext i16 @FLOAT2INT16(float noundef %63)
  %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_edge25, label %.lr.ph24.split, !llvm.loop !24

._crit_edge25:                                    ; preds = %.lr.ph24.split, %._crit_edge.us, %7
  ret void
}

; Function Attrs: inlinehint nounwind uwtable
declare hidden signext i16 @FLOAT2INT16(float noundef) local_unnamed_addr #1

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

!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 = !{!"float", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !11, i64 0}
!10 = !{!"MappingMatrix", !11, i64 0, !11, i64 4, !11, i64 8}
!11 = !{!"int", !7, i64 0}
!12 = !{!13, !13, i64 0}
!13 = !{!"short", !7, i64 0}
!14 = !{!15}
!15 = distinct !{!15, !16}
!16 = distinct !{!16, !"LVerDomain"}
!17 = !{!18}
!18 = distinct !{!18, !16}
!19 = distinct !{!19, !20, !21, !22}
!20 = !{!"llvm.loop.mustprogress"}
!21 = !{!"llvm.loop.isvectorized", i32 1}
!22 = !{!"llvm.loop.unroll.runtime.disable"}
!23 = distinct !{!23, !20, !21}
!24 = distinct !{!24, !20}


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