; LLVM IR from CactiLab/Sherloc-Cortex-M-CFVD :: Sherloc_runtime/evaluation/src/edn (libedn)

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

; Function Attrs: nounwind uwtable
define dso_local void @vec_mpy1(ptr noundef %0, ptr noundef %1, i16 noundef signext %2) #0 {
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca i16, align 2
  %7 = alloca i64, align 8
  store ptr %0, ptr %4, align 8, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !5
  store i16 %2, ptr %6, align 2, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #2
  store i64 0, ptr %7, align 8, !tbaa !11
  br label %8

8:                                                ; preds = %28, %3
  %9 = load i64, ptr %7, align 8, !tbaa !11
  %10 = icmp slt i64 %9, 150
  br i1 %10, label %11, label %31

11:                                               ; preds = %8
  %12 = load i16, ptr %6, align 2, !tbaa !9
  %13 = sext i16 %12 to i32
  %14 = load ptr, ptr %5, align 8, !tbaa !5
  %15 = load i64, ptr %7, align 8, !tbaa !11
  %16 = getelementptr inbounds i16, ptr %14, i64 %15
  %17 = load i16, ptr %16, align 2, !tbaa !9
  %18 = sext i16 %17 to i32
  %19 = mul nsw i32 %13, %18
  %20 = ashr i32 %19, 15
  %21 = load ptr, ptr %4, align 8, !tbaa !5
  %22 = load i64, ptr %7, align 8, !tbaa !11
  %23 = getelementptr inbounds i16, ptr %21, i64 %22
  %24 = load i16, ptr %23, align 2, !tbaa !9
  %25 = sext i16 %24 to i32
  %26 = add nsw i32 %25, %20
  %27 = trunc i32 %26 to i16
  store i16 %27, ptr %23, align 2, !tbaa !9
  br label %28

28:                                               ; preds = %11
  %29 = load i64, ptr %7, align 8, !tbaa !11
  %30 = add nsw i64 %29, 1
  store i64 %30, ptr %7, align 8, !tbaa !11
  br label %8, !llvm.loop !13

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

; 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

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 = { 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 = !{!"short", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"long", !7, i64 0}
!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: nofree norecurse nosync nounwind memory(argmem: readwrite) uwtable
define dso_local void @vec_mpy1(ptr nocapture noundef %0, ptr nocapture noundef readonly %1, i16 noundef signext %2) local_unnamed_addr #0 {
vector.memcheck:
  %3 = sext i16 %2 to i32
  %scevgep = getelementptr i8, ptr %0, i64 300
  %scevgep7 = getelementptr i8, ptr %1, i64 300
  %bound0 = icmp ugt ptr %scevgep7, %0
  %bound1 = icmp ugt ptr %scevgep, %1
  %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 %3, 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 ]
  %4 = getelementptr inbounds i16, ptr %1, i64 %index
  %5 = getelementptr inbounds i8, ptr %4, i64 16
  %wide.load = load <8 x i16>, ptr %4, align 2, !tbaa !5, !alias.scope !9
  %wide.load8 = load <8 x i16>, ptr %5, align 2, !tbaa !5, !alias.scope !9
  %6 = sext <8 x i16> %wide.load to <8 x i32>
  %7 = sext <8 x i16> %wide.load8 to <8 x i32>
  %8 = mul nsw <8 x i32> %broadcast.splat, %6
  %9 = mul nsw <8 x i32> %broadcast.splat, %7
  %10 = lshr <8 x i32> %8, <i32 15, i32 15, i32 15, i32 15, i32 15, i32 15, i32 15, i32 15>
  %11 = lshr <8 x i32> %9, <i32 15, i32 15, i32 15, i32 15, i32 15, i32 15, i32 15, i32 15>
  %12 = getelementptr inbounds i16, ptr %0, i64 %index
  %13 = getelementptr inbounds i8, ptr %12, i64 16
  %wide.load9 = load <8 x i16>, ptr %12, align 2, !tbaa !5, !alias.scope !12, !noalias !9
  %wide.load10 = load <8 x i16>, ptr %13, align 2, !tbaa !5, !alias.scope !12, !noalias !9
  %14 = trunc <8 x i32> %10 to <8 x i16>
  %15 = trunc <8 x i32> %11 to <8 x i16>
  %16 = add <8 x i16> %wide.load9, %14
  %17 = add <8 x i16> %wide.load10, %15
  store <8 x i16> %16, ptr %12, align 2, !tbaa !5, !alias.scope !12, !noalias !9
  store <8 x i16> %17, ptr %13, align 2, !tbaa !5, !alias.scope !12, !noalias !9
  %index.next = add nuw i64 %index, 16
  %18 = icmp eq i64 %index.next, 144
  br i1 %18, label %scalar.ph.preheader, label %vector.body, !llvm.loop !14

scalar.ph.preheader:                              ; preds = %vector.body, %vector.memcheck
  %.06.ph = phi i64 [ 0, %vector.memcheck ], [ 144, %vector.body ]
  br label %scalar.ph

scalar.ph:                                        ; preds = %scalar.ph, %scalar.ph.preheader
  %.06 = phi i64 [ %.06.ph, %scalar.ph.preheader ], [ %38, %scalar.ph ]
  %19 = getelementptr inbounds i16, ptr %1, i64 %.06
  %20 = load i16, ptr %19, align 2, !tbaa !5
  %21 = sext i16 %20 to i32
  %22 = mul nsw i32 %21, %3
  %23 = lshr i32 %22, 15
  %24 = getelementptr inbounds i16, ptr %0, i64 %.06
  %25 = load i16, ptr %24, align 2, !tbaa !5
  %26 = trunc i32 %23 to i16
  %27 = add i16 %25, %26
  store i16 %27, ptr %24, align 2, !tbaa !5
  %28 = or disjoint i64 %.06, 1
  %29 = getelementptr inbounds i16, ptr %1, i64 %28
  %30 = load i16, ptr %29, align 2, !tbaa !5
  %31 = sext i16 %30 to i32
  %32 = mul nsw i32 %31, %3
  %33 = lshr i32 %32, 15
  %34 = getelementptr inbounds i16, ptr %0, i64 %28
  %35 = load i16, ptr %34, align 2, !tbaa !5
  %36 = trunc i32 %33 to i16
  %37 = add i16 %35, %36
  store i16 %37, ptr %34, align 2, !tbaa !5
  %38 = add nuw nsw i64 %.06, 2
  %exitcond.not.1 = icmp eq i64 %38, 150
  br i1 %exitcond.not.1, label %.loopexit, label %scalar.ph, !llvm.loop !18

.loopexit:                                        ; preds = %scalar.ph
  ret void
}

attributes #0 = { nofree norecurse nosync nounwind memory(argmem: readwrite) 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 = !{!"short", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10}
!10 = distinct !{!10, !11}
!11 = distinct !{!11, !"LVerDomain"}
!12 = !{!13}
!13 = distinct !{!13, !11}
!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, !16}


; Effective O3 passes: GlobalOptPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,LICMPass,LoopLoadEliminationPass,LoopRotatePass,LoopUnrollPass,LoopVectorizePass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass