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

; 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_q31(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 i32, ptr %24, i32 1
  store ptr %25, ptr %5, align 8, !tbaa !5
  %26 = load i32, ptr %24, align 4, !tbaa !10
  %27 = sext i32 %26 to i64
  %28 = load i8, ptr %6, align 1, !tbaa !9
  %29 = sext i8 %28 to i32
  %30 = zext i32 %29 to i64
  %31 = shl i64 %27, %30
  %32 = call i32 @clip_q63_to_q31(i64 noundef %31)
  %33 = load ptr, ptr %7, align 8, !tbaa !5
  %34 = getelementptr inbounds i32, ptr %33, i32 1
  store ptr %34, ptr %7, align 8, !tbaa !5
  store i32 %32, ptr %33, align 4, !tbaa !10
  %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 !12

37:                                               ; preds = %20
  br label %55

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

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

54:                                               ; preds = %39
  br label %55

55:                                               ; preds = %54, %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 @clip_q63_to_q31(i64 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_q31(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, 8
  %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 [ %17, %scalar.ph.prol ], [ %.11321.ph, %scalar.ph.preheader ]
  %.11520.prol = phi ptr [ %16, %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 4
  %14 = load i32, ptr %.122.prol, align 4, !tbaa !5
  %15 = ashr i32 %14, %9
  %16 = getelementptr inbounds i8, ptr %.11520.prol, i64 4
  store i32 %15, ptr %.11520.prol, align 4, !tbaa !5
  %17 = 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 ], [ %17, %scalar.ph.prol ]
  %.11520.unr = phi ptr [ %.11520.ph, %scalar.ph.preheader ], [ %16, %scalar.ph.prol ]
  %18 = icmp ult i32 %12, 3
  br i1 %18, label %.loopexit, label %scalar.ph

vector.ph:                                        ; preds = %.lr.ph
  %n.vec = and i64 %10, 4294967288
  %19 = shl nuw nsw i64 %n.vec, 2
  %ind.end = getelementptr i8, ptr %0, i64 %19
  %.cast = trunc nuw i64 %n.vec to i32
  %ind.end31 = sub i32 %3, %.cast
  %20 = shl nuw nsw i64 %n.vec, 2
  %ind.end33 = getelementptr i8, ptr %2, i64 %20
  %broadcast.splatinsert = insertelement <4 x i32> poison, i32 %9, i64 0
  %broadcast.splat = shufflevector <4 x i32> %broadcast.splatinsert, <4 x i32> 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 ]
  %offset.idx = shl i64 %index, 2
  %next.gep = getelementptr i8, ptr %0, i64 %offset.idx
  %offset.idx36 = shl i64 %index, 2
  %next.gep37 = getelementptr i8, ptr %2, i64 %offset.idx36
  %21 = getelementptr i8, ptr %next.gep, i64 16
  %wide.load = load <4 x i32>, ptr %next.gep, align 4, !tbaa !5
  %wide.load39 = load <4 x i32>, ptr %21, align 4, !tbaa !5
  %22 = ashr <4 x i32> %wide.load, %broadcast.splat
  %23 = ashr <4 x i32> %wide.load39, %broadcast.splat
  %24 = getelementptr i8, ptr %next.gep37, i64 16
  store <4 x i32> %22, ptr %next.gep37, align 4, !tbaa !5
  store <4 x i32> %23, ptr %24, align 4, !tbaa !5
  %index.next = add nuw i64 %index, 8
  %25 = icmp eq i64 %index.next, %n.vec
  br i1 %25, 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
  %26 = zext nneg i32 %7 to i64
  br label %27

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

scalar.ph:                                        ; preds = %scalar.ph.prol.loopexit, %scalar.ph
  %.122 = phi ptr [ %47, %scalar.ph ], [ %.122.unr, %scalar.ph.prol.loopexit ]
  %.11321 = phi i32 [ %51, %scalar.ph ], [ %.11321.unr, %scalar.ph.prol.loopexit ]
  %.11520 = phi ptr [ %50, %scalar.ph ], [ %.11520.unr, %scalar.ph.prol.loopexit ]
  %35 = getelementptr inbounds i8, ptr %.122, i64 4
  %36 = load i32, ptr %.122, align 4, !tbaa !5
  %37 = ashr i32 %36, %9
  %38 = getelementptr inbounds i8, ptr %.11520, i64 4
  store i32 %37, ptr %.11520, align 4, !tbaa !5
  %39 = getelementptr inbounds i8, ptr %.122, i64 8
  %40 = load i32, ptr %35, align 4, !tbaa !5
  %41 = ashr i32 %40, %9
  %42 = getelementptr inbounds i8, ptr %.11520, i64 8
  store i32 %41, ptr %38, align 4, !tbaa !5
  %43 = getelementptr inbounds i8, ptr %.122, i64 12
  %44 = load i32, ptr %39, align 4, !tbaa !5
  %45 = ashr i32 %44, %9
  %46 = getelementptr inbounds i8, ptr %.11520, i64 12
  store i32 %45, ptr %42, align 4, !tbaa !5
  %47 = getelementptr inbounds i8, ptr %.122, i64 16
  %48 = load i32, ptr %43, align 4, !tbaa !5
  %49 = ashr i32 %48, %9
  %50 = getelementptr inbounds i8, ptr %.11520, i64 16
  store i32 %49, ptr %46, align 4, !tbaa !5
  %51 = add i32 %.11321, -4
  %.not.3 = icmp eq i32 %51, 0
  br i1 %.not.3, label %.loopexit, label %scalar.ph, !llvm.loop !16

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

; Function Attrs: alwaysinline nounwind uwtable
declare hidden i32 @clip_q63_to_q31(i64 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 = !{!"int", !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