; LLVM IR from FedericaPaoli1/stm32-speech-recognition-and-traduction :: Drivers/CMSIS/DSP/Source/FastMathFunctions (arm_sin_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"

@sinTable_q15 = external constant [513 x i16], align 16

; Function Attrs: nounwind uwtable
define dso_local signext i16 @arm_sin_q15(i16 noundef signext %0) #0 {
  %2 = alloca i16, align 2
  %3 = alloca i16, align 2
  %4 = alloca i32, align 4
  %5 = alloca i16, align 2
  %6 = alloca i16, align 2
  %7 = alloca i16, align 2
  store i16 %0, ptr %2, align 2, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 2, ptr %3) #2
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #2
  call void @llvm.lifetime.start.p0(i64 2, ptr %5) #2
  call void @llvm.lifetime.start.p0(i64 2, ptr %6) #2
  call void @llvm.lifetime.start.p0(i64 2, ptr %7) #2
  %8 = load i16, ptr %2, align 2, !tbaa !5
  %9 = sext i16 %8 to i32
  %10 = icmp slt i32 %9, 0
  br i1 %10, label %11, label %16

11:                                               ; preds = %1
  %12 = load i16, ptr %2, align 2, !tbaa !5
  %13 = zext i16 %12 to i32
  %14 = add nsw i32 %13, 32768
  %15 = trunc i32 %14 to i16
  store i16 %15, ptr %2, align 2, !tbaa !5
  br label %16

16:                                               ; preds = %11, %1
  %17 = load i16, ptr %2, align 2, !tbaa !5
  %18 = sext i16 %17 to i32
  %19 = lshr i32 %18, 6
  store i32 %19, ptr %4, align 4, !tbaa !9
  %20 = load i16, ptr %2, align 2, !tbaa !5
  %21 = sext i16 %20 to i32
  %22 = load i32, ptr %4, align 4, !tbaa !9
  %23 = shl i32 %22, 6
  %24 = sub nsw i32 %21, %23
  %25 = shl i32 %24, 9
  %26 = trunc i32 %25 to i16
  store i16 %26, ptr %7, align 2, !tbaa !5
  %27 = load i32, ptr %4, align 4, !tbaa !9
  %28 = sext i32 %27 to i64
  %29 = getelementptr inbounds [513 x i16], ptr @sinTable_q15, i64 0, i64 %28
  %30 = load i16, ptr %29, align 2, !tbaa !5
  store i16 %30, ptr %5, align 2, !tbaa !5
  %31 = load i32, ptr %4, align 4, !tbaa !9
  %32 = add nsw i32 %31, 1
  %33 = sext i32 %32 to i64
  %34 = getelementptr inbounds [513 x i16], ptr @sinTable_q15, i64 0, i64 %33
  %35 = load i16, ptr %34, align 2, !tbaa !5
  store i16 %35, ptr %6, align 2, !tbaa !5
  %36 = load i16, ptr %7, align 2, !tbaa !5
  %37 = sext i16 %36 to i32
  %38 = sub nsw i32 32768, %37
  %39 = load i16, ptr %5, align 2, !tbaa !5
  %40 = sext i16 %39 to i32
  %41 = mul nsw i32 %38, %40
  %42 = ashr i32 %41, 16
  %43 = trunc i32 %42 to i16
  store i16 %43, ptr %3, align 2, !tbaa !5
  %44 = load i16, ptr %3, align 2, !tbaa !5
  %45 = sext i16 %44 to i32
  %46 = shl i32 %45, 16
  %47 = load i16, ptr %7, align 2, !tbaa !5
  %48 = sext i16 %47 to i32
  %49 = load i16, ptr %6, align 2, !tbaa !5
  %50 = sext i16 %49 to i32
  %51 = mul nsw i32 %48, %50
  %52 = add nsw i32 %46, %51
  %53 = ashr i32 %52, 16
  %54 = trunc i32 %53 to i16
  store i16 %54, ptr %3, align 2, !tbaa !5
  %55 = load i16, ptr %3, align 2, !tbaa !5
  %56 = sext i16 %55 to i32
  %57 = shl i32 %56, 1
  %58 = trunc i32 %57 to i16
  call void @llvm.lifetime.end.p0(i64 2, ptr %7) #2
  call void @llvm.lifetime.end.p0(i64 2, ptr %6) #2
  call void @llvm.lifetime.end.p0(i64 2, ptr %5) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #2
  call void @llvm.lifetime.end.p0(i64 2, ptr %3) #2
  ret i16 %58
}

; 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 = !{!"short", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"int", !7, i64 0}


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

@sinTable_q15 = external local_unnamed_addr constant [513 x i16], align 16

; Function Attrs: mustprogress nofree norecurse nosync nounwind willreturn memory(none) uwtable
define dso_local signext i16 @arm_sin_q15(i16 noundef signext %0) local_unnamed_addr #0 {
  %2 = lshr i16 %0, 6
  %3 = and i16 %2, 511
  %4 = shl i16 %0, 9
  %5 = and i16 %4, 32256
  %6 = zext nneg i16 %3 to i64
  %7 = getelementptr inbounds [513 x i16], ptr @sinTable_q15, i64 0, i64 %6
  %8 = load i16, ptr %7, align 2, !tbaa !5
  %narrow = add nuw nsw i16 %3, 1
  %9 = zext nneg i16 %narrow to i64
  %10 = getelementptr inbounds [513 x i16], ptr @sinTable_q15, i64 0, i64 %9
  %11 = load i16, ptr %10, align 2, !tbaa !5
  %12 = zext nneg i16 %5 to i32
  %13 = sub nuw nsw i32 32768, %12
  %14 = sext i16 %8 to i32
  %15 = mul nsw i32 %13, %14
  %16 = and i32 %15, 2147418112
  %17 = sext i16 %11 to i32
  %18 = mul nsw i32 %17, %12
  %19 = add i32 %16, %18
  %20 = lshr i32 %19, 15
  %21 = trunc i32 %20 to i16
  %22 = and i16 %21, -2
  ret i16 %22
}

attributes #0 = { mustprogress nofree norecurse nosync nounwind willreturn memory(none) 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"}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass