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

; 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_q7(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 %39

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 %38

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

38:                                               ; preds = %20
  br label %58

39:                                               ; preds = %4
  br label %40

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

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

57:                                               ; preds = %40
  br label %58

58:                                               ; preds = %57, %38
  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 = distinct !{!12, !13}
!13 = !{!"llvm.loop.mustprogress"}
!14 = distinct !{!14, !13}


; 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_q7(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 %iter.check

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

vector.main.loop.iter.check:                      ; preds = %iter.check
  %min.iters.check31 = icmp ult i32 %3, 16
  br i1 %min.iters.check31, label %vec.epilog.ph, label %vector.ph

vector.ph:                                        ; preds = %vector.main.loop.iter.check
  %n.vec = and i64 %10, 4294967280
  %broadcast.splatinsert = insertelement <16 x i32> poison, i32 %9, i64 0
  %broadcast.splat = shufflevector <16 x i32> %broadcast.splatinsert, <16 x i32> poison, <16 x i32> zeroinitializer
  br label %vector.body

vector.body:                                      ; preds = %vector.body, %vector.ph
  %index = phi i64 [ 0, %vector.ph ], [ %index.next, %vector.body ]
  %next.gep = getelementptr i8, ptr %0, i64 %index
  %next.gep32 = getelementptr i8, ptr %2, i64 %index
  %wide.load = load <16 x i8>, ptr %next.gep, align 1, !tbaa !5
  %12 = sext <16 x i8> %wide.load to <16 x i32>
  %13 = ashr <16 x i32> %12, %broadcast.splat
  %14 = trunc nsw <16 x i32> %13 to <16 x i8>
  store <16 x i8> %14, ptr %next.gep32, align 1, !tbaa !5
  %index.next = add nuw i64 %index, 16
  %15 = icmp eq i64 %index.next, %n.vec
  br i1 %15, label %middle.block, label %vector.body, !llvm.loop !8

middle.block:                                     ; preds = %vector.body
  %cmp.n = icmp eq i64 %n.vec, %10
  br i1 %cmp.n, label %.loopexit, label %vec.epilog.iter.check

vec.epilog.iter.check:                            ; preds = %middle.block
  %ind.end41 = getelementptr i8, ptr %2, i64 %n.vec
  %.cast37 = trunc nuw i64 %n.vec to i32
  %ind.end38 = sub i32 %3, %.cast37
  %ind.end35 = getelementptr i8, ptr %0, i64 %n.vec
  %n.vec.remaining = and i64 %10, 8
  %min.epilog.iters.check.not.not = icmp eq i64 %n.vec.remaining, 0
  br i1 %min.epilog.iters.check.not.not, label %vec.epilog.scalar.ph.preheader, label %vec.epilog.ph

vec.epilog.scalar.ph.preheader:                   ; preds = %vec.epilog.middle.block, %iter.check, %vec.epilog.iter.check
  %.122.ph = phi ptr [ %0, %iter.check ], [ %ind.end35, %vec.epilog.iter.check ], [ %ind.end, %vec.epilog.middle.block ]
  %.11321.ph = phi i32 [ %3, %iter.check ], [ %ind.end38, %vec.epilog.iter.check ], [ %ind.end36, %vec.epilog.middle.block ]
  %.11520.ph = phi ptr [ %2, %iter.check ], [ %ind.end41, %vec.epilog.iter.check ], [ %ind.end40, %vec.epilog.middle.block ]
  %16 = 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 %vec.epilog.scalar.ph.prol.loopexit, label %vec.epilog.scalar.ph.prol

vec.epilog.scalar.ph.prol:                        ; preds = %vec.epilog.scalar.ph.preheader, %vec.epilog.scalar.ph.prol
  %.122.prol = phi ptr [ %17, %vec.epilog.scalar.ph.prol ], [ %.122.ph, %vec.epilog.scalar.ph.preheader ]
  %.11321.prol = phi i32 [ %23, %vec.epilog.scalar.ph.prol ], [ %.11321.ph, %vec.epilog.scalar.ph.preheader ]
  %.11520.prol = phi ptr [ %22, %vec.epilog.scalar.ph.prol ], [ %.11520.ph, %vec.epilog.scalar.ph.preheader ]
  %prol.iter = phi i32 [ %prol.iter.next, %vec.epilog.scalar.ph.prol ], [ 0, %vec.epilog.scalar.ph.preheader ]
  %17 = getelementptr inbounds i8, ptr %.122.prol, i64 1
  %18 = load i8, ptr %.122.prol, align 1, !tbaa !5
  %19 = sext i8 %18 to i32
  %20 = ashr i32 %19, %9
  %21 = trunc nsw i32 %20 to i8
  %22 = getelementptr inbounds i8, ptr %.11520.prol, i64 1
  store i8 %21, ptr %.11520.prol, align 1, !tbaa !5
  %23 = 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 %vec.epilog.scalar.ph.prol.loopexit, label %vec.epilog.scalar.ph.prol, !llvm.loop !12

vec.epilog.scalar.ph.prol.loopexit:               ; preds = %vec.epilog.scalar.ph.prol, %vec.epilog.scalar.ph.preheader
  %.122.unr = phi ptr [ %.122.ph, %vec.epilog.scalar.ph.preheader ], [ %17, %vec.epilog.scalar.ph.prol ]
  %.11321.unr = phi i32 [ %.11321.ph, %vec.epilog.scalar.ph.preheader ], [ %23, %vec.epilog.scalar.ph.prol ]
  %.11520.unr = phi ptr [ %.11520.ph, %vec.epilog.scalar.ph.preheader ], [ %22, %vec.epilog.scalar.ph.prol ]
  %24 = icmp ult i32 %16, 3
  br i1 %24, label %.loopexit, label %vec.epilog.scalar.ph

vec.epilog.ph:                                    ; preds = %vector.main.loop.iter.check, %vec.epilog.iter.check
  %vec.epilog.resume.val = phi i64 [ %n.vec, %vec.epilog.iter.check ], [ 0, %vector.main.loop.iter.check ]
  %n.vec34 = and i64 %10, 4294967288
  %ind.end = getelementptr i8, ptr %0, i64 %n.vec34
  %.cast = trunc nuw i64 %n.vec34 to i32
  %ind.end36 = sub i32 %3, %.cast
  %ind.end40 = getelementptr i8, ptr %2, i64 %n.vec34
  %broadcast.splatinsert47 = insertelement <8 x i32> poison, i32 %9, i64 0
  %broadcast.splat48 = shufflevector <8 x i32> %broadcast.splatinsert47, <8 x i32> poison, <8 x i32> zeroinitializer
  br label %vec.epilog.vector.body

vec.epilog.vector.body:                           ; preds = %vec.epilog.vector.body, %vec.epilog.ph
  %index43 = phi i64 [ %vec.epilog.resume.val, %vec.epilog.ph ], [ %index.next49, %vec.epilog.vector.body ]
  %next.gep44 = getelementptr i8, ptr %0, i64 %index43
  %next.gep45 = getelementptr i8, ptr %2, i64 %index43
  %wide.load46 = load <8 x i8>, ptr %next.gep44, align 1, !tbaa !5
  %25 = sext <8 x i8> %wide.load46 to <8 x i32>
  %26 = ashr <8 x i32> %25, %broadcast.splat48
  %27 = trunc nsw <8 x i32> %26 to <8 x i8>
  store <8 x i8> %27, ptr %next.gep45, align 1, !tbaa !5
  %index.next49 = add nuw i64 %index43, 8
  %28 = icmp eq i64 %index.next49, %n.vec34
  br i1 %28, label %vec.epilog.middle.block, label %vec.epilog.vector.body, !llvm.loop !14

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

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

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

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

.loopexit:                                        ; preds = %vec.epilog.scalar.ph.prol.loopexit, %vec.epilog.scalar.ph, %.lr.ph27, %middle.block, %vec.epilog.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 = !{!"omnipotent char", !7, i64 0}
!7 = !{!"Simple C/C++ TBAA"}
!8 = distinct !{!8, !9, !10, !11}
!9 = !{!"llvm.loop.mustprogress"}
!10 = !{!"llvm.loop.isvectorized", i32 1}
!11 = !{!"llvm.loop.unroll.runtime.disable"}
!12 = distinct !{!12, !13}
!13 = !{!"llvm.loop.unroll.disable"}
!14 = distinct !{!14, !9, !10, !11}
!15 = distinct !{!15, !9}
!16 = distinct !{!16, !9, !10}


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