; LLVM IR from FedericaPaoli1/stm32-speech-recognition-and-traduction :: Drivers/CMSIS/DSP/Source/BasicMathFunctions (arm_shift_q15)

; 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 @arm_shift_q15(ptr noundef %0, i8 noundef signext %1, ptr noundef %2, i32 noundef %3) #0 {
  %5 = alloca ptr, align 8
  %6 = alloca i8, align 1
  %7 = alloca ptr, align 8
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  %10 = alloca i8, align 1
  store ptr %0, ptr %5, align 8, !tbaa !5
  store i8 %1, ptr %6, align 1, !tbaa !9
  store ptr %2, ptr %7, align 8, !tbaa !5
  store i32 %3, ptr %8, align 4, !tbaa !10
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #3
  call void @llvm.lifetime.start.p0(i64 1, ptr %10) #3
  %11 = load i8, ptr %6, align 1, !tbaa !9
  %12 = sext i8 %11 to i32
  %13 = and i32 %12, 128
  %14 = trunc i32 %13 to i8
  store i8 %14, ptr %10, align 1, !tbaa !9
  %15 = load i32, ptr %8, align 4, !tbaa !10
  store i32 %15, ptr %9, align 4, !tbaa !10
  %16 = load i8, ptr %10, align 1, !tbaa !9
  %17 = zext i8 %16 to i32
  %18 = icmp eq i32 %17, 0
  br i1 %18, label %19, label %38

19:                                               ; preds = %4
  br label %20

20:                                               ; preds = %23, %19
  %21 = load i32, ptr %9, align 4, !tbaa !10
  %22 = icmp ugt i32 %21, 0
  br i1 %22, label %23, label %37

23:                                               ; preds = %20
  %24 = load ptr, ptr %5, align 8, !tbaa !5
  %25 = getelementptr inbounds i16, ptr %24, i32 1
  store ptr %25, ptr %5, align 8, !tbaa !5
  %26 = load i16, ptr %24, align 2, !tbaa !12
  %27 = sext i16 %26 to i32
  %28 = load i8, ptr %6, align 1, !tbaa !9
  %29 = sext i8 %28 to i32
  %30 = shl i32 %27, %29
  %31 = call i32 @__SSAT(i32 noundef %30, i32 noundef 16)
  %32 = trunc i32 %31 to i16
  %33 = load ptr, ptr %7, align 8, !tbaa !5
  %34 = getelementptr inbounds i16, ptr %33, i32 1
  store ptr %34, ptr %7, align 8, !tbaa !5
  store i16 %32, ptr %33, align 2, !tbaa !12
  %35 = load i32, ptr %9, align 4, !tbaa !10
  %36 = add i32 %35, -1
  store i32 %36, ptr %9, align 4, !tbaa !10
  br label %20, !llvm.loop !14

37:                                               ; preds = %20
  br label %57

38:                                               ; preds = %4
  br label %39

39:                                               ; preds = %42, %38
  %40 = load i32, ptr %9, align 4, !tbaa !10
  %41 = icmp ugt i32 %40, 0
  br i1 %41, label %42, label %56

42:                                               ; preds = %39
  %43 = load ptr, ptr %5, align 8, !tbaa !5
  %44 = getelementptr inbounds i16, ptr %43, i32 1
  store ptr %44, ptr %5, align 8, !tbaa !5
  %45 = load i16, ptr %43, align 2, !tbaa !12
  %46 = sext i16 %45 to i32
  %47 = load i8, ptr %6, align 1, !tbaa !9
  %48 = sext i8 %47 to i32
  %49 = sub nsw i32 0, %48
  %50 = ashr i32 %46, %49
  %51 = trunc i32 %50 to i16
  %52 = load ptr, ptr %7, align 8, !tbaa !5
  %53 = getelementptr inbounds i16, ptr %52, i32 1
  store ptr %53, ptr %7, align 8, !tbaa !5
  store i16 %51, ptr %52, align 2, !tbaa !12
  %54 = load i32, ptr %9, align 4, !tbaa !10
  %55 = add i32 %54, -1
  store i32 %55, ptr %9, align 4, !tbaa !10
  br label %39, !llvm.loop !16

56:                                               ; preds = %39
  br label %57

57:                                               ; preds = %56, %37
  call void @llvm.lifetime.end.p0(i64 1, ptr %10) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #3
  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: alwaysinline nounwind uwtable
declare hidden i32 @__SSAT(i32 noundef, i32 noundef) #2

; 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 = { alwaysinline 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 = !{!7, !7, i64 0}
!10 = !{!11, !11, i64 0}
!11 = !{!"int", !7, i64 0}
!12 = !{!13, !13, i64 0}
!13 = !{!"short", !7, i64 0}
!14 = distinct !{!14, !15}
!15 = !{!"llvm.loop.mustprogress"}
!16 = distinct !{!16, !15}


; 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 @arm_shift_q15(ptr nocapture noundef readonly %0, i8 noundef signext %1, ptr nocapture noundef writeonly %2, i32 noundef %3) local_unnamed_addr #0 {
  %5 = ptrtoint ptr %0 to i64
  %6 = ptrtoint ptr %2 to i64
  %7 = sext i8 %1 to i32
  %8 = icmp sgt i8 %1, -1
  %.not1623 = icmp eq i32 %3, 0
  br i1 %8, label %.preheader, label %.preheader17

.preheader17:                                     ; preds = %4
  br i1 %.not1623, label %.loopexit, label %.lr.ph

.lr.ph:                                           ; preds = %.preheader17
  %9 = sub nsw i32 0, %7
  %10 = zext i32 %3 to i64
  %min.iters.check = icmp ult i32 %3, 16
  %11 = sub i64 %6, %5
  %diff.check = icmp ult i64 %11, 32
  %or.cond = or i1 %min.iters.check, %diff.check
  br i1 %or.cond, label %scalar.ph.preheader, label %vector.ph

scalar.ph.preheader:                              ; preds = %middle.block, %.lr.ph
  %.122.ph = phi ptr [ %0, %.lr.ph ], [ %ind.end, %middle.block ]
  %.11321.ph = phi i32 [ %3, %.lr.ph ], [ %ind.end31, %middle.block ]
  %.11520.ph = phi ptr [ %2, %.lr.ph ], [ %ind.end33, %middle.block ]
  %12 = add i32 %.11321.ph, -1
  %xtraiter = and i32 %.11321.ph, 3
  %lcmp.mod.not = icmp eq i32 %xtraiter, 0
  br i1 %lcmp.mod.not, label %scalar.ph.prol.loopexit, label %scalar.ph.prol

scalar.ph.prol:                                   ; preds = %scalar.ph.preheader, %scalar.ph.prol
  %.122.prol = phi ptr [ %13, %scalar.ph.prol ], [ %.122.ph, %scalar.ph.preheader ]
  %.11321.prol = phi i32 [ %19, %scalar.ph.prol ], [ %.11321.ph, %scalar.ph.preheader ]
  %.11520.prol = phi ptr [ %18, %scalar.ph.prol ], [ %.11520.ph, %scalar.ph.preheader ]
  %prol.iter = phi i32 [ %prol.iter.next, %scalar.ph.prol ], [ 0, %scalar.ph.preheader ]
  %13 = getelementptr inbounds i8, ptr %.122.prol, i64 2
  %14 = load i16, ptr %.122.prol, align 2, !tbaa !5
  %15 = sext i16 %14 to i32
  %16 = ashr i32 %15, %9
  %17 = trunc nsw i32 %16 to i16
  %18 = getelementptr inbounds i8, ptr %.11520.prol, i64 2
  store i16 %17, ptr %.11520.prol, align 2, !tbaa !5
  %19 = add i32 %.11321.prol, -1
  %prol.iter.next = add i32 %prol.iter, 1
  %prol.iter.cmp.not = icmp eq i32 %prol.iter.next, %xtraiter
  br i1 %prol.iter.cmp.not, label %scalar.ph.prol.loopexit, label %scalar.ph.prol, !llvm.loop !9

scalar.ph.prol.loopexit:                          ; preds = %scalar.ph.prol, %scalar.ph.preheader
  %.122.unr = phi ptr [ %.122.ph, %scalar.ph.preheader ], [ %13, %scalar.ph.prol ]
  %.11321.unr = phi i32 [ %.11321.ph, %scalar.ph.preheader ], [ %19, %scalar.ph.prol ]
  %.11520.unr = phi ptr [ %.11520.ph, %scalar.ph.preheader ], [ %18, %scalar.ph.prol ]
  %20 = icmp ult i32 %12, 3
  br i1 %20, label %.loopexit, label %scalar.ph

vector.ph:                                        ; preds = %.lr.ph
  %n.vec = and i64 %10, 4294967280
  %21 = shl nuw nsw i64 %n.vec, 1
  %ind.end = getelementptr i8, ptr %0, i64 %21
  %.cast = trunc nuw i64 %n.vec to i32
  %ind.end31 = sub i32 %3, %.cast
  %22 = shl nuw nsw i64 %n.vec, 1
  %ind.end33 = getelementptr i8, ptr %2, i64 %22
  %broadcast.splatinsert = insertelement <8 x i32> poison, i32 %9, 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 ]
  %offset.idx = shl i64 %index, 1
  %next.gep = getelementptr i8, ptr %0, i64 %offset.idx
  %offset.idx36 = shl i64 %index, 1
  %next.gep37 = getelementptr i8, ptr %2, i64 %offset.idx36
  %23 = getelementptr i8, ptr %next.gep, i64 16
  %wide.load = load <8 x i16>, ptr %next.gep, align 2, !tbaa !5
  %wide.load39 = load <8 x i16>, ptr %23, align 2, !tbaa !5
  %24 = sext <8 x i16> %wide.load to <8 x i32>
  %25 = sext <8 x i16> %wide.load39 to <8 x i32>
  %26 = ashr <8 x i32> %24, %broadcast.splat
  %27 = ashr <8 x i32> %25, %broadcast.splat
  %28 = trunc nsw <8 x i32> %26 to <8 x i16>
  %29 = trunc nsw <8 x i32> %27 to <8 x i16>
  %30 = getelementptr i8, ptr %next.gep37, i64 16
  store <8 x i16> %28, ptr %next.gep37, align 2, !tbaa !5
  store <8 x i16> %29, ptr %30, align 2, !tbaa !5
  %index.next = add nuw i64 %index, 16
  %31 = icmp eq i64 %index.next, %n.vec
  br i1 %31, label %middle.block, label %vector.body, !llvm.loop !11

middle.block:                                     ; preds = %vector.body
  %cmp.n = icmp eq i64 %n.vec, %10
  br i1 %cmp.n, label %.loopexit, label %scalar.ph.preheader

.preheader:                                       ; preds = %4
  br i1 %.not1623, label %.loopexit, label %.lr.ph27

.lr.ph27:                                         ; preds = %.preheader, %.lr.ph27
  %.026 = phi ptr [ %32, %.lr.ph27 ], [ %0, %.preheader ]
  %.01225 = phi i32 [ %39, %.lr.ph27 ], [ %3, %.preheader ]
  %.01424 = phi ptr [ %38, %.lr.ph27 ], [ %2, %.preheader ]
  %32 = getelementptr inbounds i8, ptr %.026, i64 2
  %33 = load i16, ptr %.026, align 2, !tbaa !5
  %34 = sext i16 %33 to i32
  %35 = shl i32 %34, %7
  %36 = tail call i32 @__SSAT(i32 noundef %35, i32 noundef 16)
  %37 = trunc i32 %36 to i16
  %38 = getelementptr inbounds i8, ptr %.01424, i64 2
  store i16 %37, ptr %.01424, align 2, !tbaa !5
  %39 = add i32 %.01225, -1
  %.not16 = icmp eq i32 %39, 0
  br i1 %.not16, label %.loopexit, label %.lr.ph27, !llvm.loop !15

scalar.ph:                                        ; preds = %scalar.ph.prol.loopexit, %scalar.ph
  %.122 = phi ptr [ %58, %scalar.ph ], [ %.122.unr, %scalar.ph.prol.loopexit ]
  %.11321 = phi i32 [ %64, %scalar.ph ], [ %.11321.unr, %scalar.ph.prol.loopexit ]
  %.11520 = phi ptr [ %63, %scalar.ph ], [ %.11520.unr, %scalar.ph.prol.loopexit ]
  %40 = getelementptr inbounds i8, ptr %.122, i64 2
  %41 = load i16, ptr %.122, align 2, !tbaa !5
  %42 = sext i16 %41 to i32
  %43 = ashr i32 %42, %9
  %44 = trunc nsw i32 %43 to i16
  %45 = getelementptr inbounds i8, ptr %.11520, i64 2
  store i16 %44, ptr %.11520, align 2, !tbaa !5
  %46 = getelementptr inbounds i8, ptr %.122, i64 4
  %47 = load i16, ptr %40, align 2, !tbaa !5
  %48 = sext i16 %47 to i32
  %49 = ashr i32 %48, %9
  %50 = trunc nsw i32 %49 to i16
  %51 = getelementptr inbounds i8, ptr %.11520, i64 4
  store i16 %50, ptr %45, align 2, !tbaa !5
  %52 = getelementptr inbounds i8, ptr %.122, i64 6
  %53 = load i16, ptr %46, align 2, !tbaa !5
  %54 = sext i16 %53 to i32
  %55 = ashr i32 %54, %9
  %56 = trunc nsw i32 %55 to i16
  %57 = getelementptr inbounds i8, ptr %.11520, i64 6
  store i16 %56, ptr %51, align 2, !tbaa !5
  %58 = getelementptr inbounds i8, ptr %.122, i64 8
  %59 = load i16, ptr %52, align 2, !tbaa !5
  %60 = sext i16 %59 to i32
  %61 = ashr i32 %60, %9
  %62 = trunc nsw i32 %61 to i16
  %63 = getelementptr inbounds i8, ptr %.11520, i64 8
  store i16 %62, ptr %57, align 2, !tbaa !5
  %64 = add i32 %.11321, -4
  %.not.3 = icmp eq i32 %64, 0
  br i1 %.not.3, label %.loopexit, label %scalar.ph, !llvm.loop !16

.loopexit:                                        ; preds = %scalar.ph.prol.loopexit, %scalar.ph, %.lr.ph27, %middle.block, %.preheader17, %.preheader
  ret void
}

; Function Attrs: alwaysinline nounwind uwtable
declare hidden i32 @__SSAT(i32 noundef, i32 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 = { alwaysinline 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 = !{!"short", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = distinct !{!9, !10}
!10 = !{!"llvm.loop.unroll.disable"}
!11 = distinct !{!11, !12, !13, !14}
!12 = !{!"llvm.loop.mustprogress"}
!13 = !{!"llvm.loop.isvectorized", i32 1}
!14 = !{!"llvm.loop.unroll.runtime.disable"}
!15 = distinct !{!15, !12}
!16 = distinct !{!16, !12, !13}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LICMPass,LoopLoadEliminationPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,LoopVectorizePass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass