; LLVM IR from tensorflow/tflite-micro :: tensorflow/lite/experimental/microfrontend/lib (filterbank)

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

%struct.FilterbankState = type { i32, i32, i32, ptr, ptr, ptr, ptr, ptr, ptr }
%struct.complex_int16_t = type { i16, i16 }

; Function Attrs: nounwind uwtable
define dso_local void @FilterbankConvertFftComplexToEnergy(ptr noundef %0, ptr noundef %1, ptr noundef %2) #0 {
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  %10 = alloca i32, align 4
  %11 = alloca i32, align 4
  store ptr %0, ptr %4, align 8, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !5
  store ptr %2, ptr %6, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #2
  %12 = load ptr, ptr %4, align 8, !tbaa !5
  %13 = getelementptr inbounds %struct.FilterbankState, ptr %12, i32 0, i32 2
  %14 = load i32, ptr %13, align 8, !tbaa !9
  store i32 %14, ptr %7, align 4, !tbaa !12
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #2
  %15 = load ptr, ptr %4, align 8, !tbaa !5
  %16 = getelementptr inbounds %struct.FilterbankState, ptr %15, i32 0, i32 1
  %17 = load i32, ptr %16, align 4, !tbaa !13
  %18 = load ptr, ptr %6, align 8, !tbaa !5
  %19 = sext i32 %17 to i64
  %20 = getelementptr inbounds i32, ptr %18, i64 %19
  store ptr %20, ptr %6, align 8, !tbaa !5
  %21 = load ptr, ptr %4, align 8, !tbaa !5
  %22 = getelementptr inbounds %struct.FilterbankState, ptr %21, i32 0, i32 1
  %23 = load i32, ptr %22, align 4, !tbaa !13
  %24 = load ptr, ptr %5, align 8, !tbaa !5
  %25 = sext i32 %23 to i64
  %26 = getelementptr inbounds %struct.complex_int16_t, ptr %24, i64 %25
  store ptr %26, ptr %5, align 8, !tbaa !5
  %27 = load ptr, ptr %4, align 8, !tbaa !5
  %28 = getelementptr inbounds %struct.FilterbankState, ptr %27, i32 0, i32 1
  %29 = load i32, ptr %28, align 4, !tbaa !13
  store i32 %29, ptr %8, align 4, !tbaa !12
  br label %30

30:                                               ; preds = %55, %3
  %31 = load i32, ptr %8, align 4, !tbaa !12
  %32 = load i32, ptr %7, align 4, !tbaa !12
  %33 = icmp slt i32 %31, %32
  br i1 %33, label %34, label %58

34:                                               ; preds = %30
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #2
  %35 = load ptr, ptr %5, align 8, !tbaa !5
  %36 = getelementptr inbounds %struct.complex_int16_t, ptr %35, i32 0, i32 0
  %37 = load i16, ptr %36, align 2, !tbaa !14
  %38 = sext i16 %37 to i32
  store i32 %38, ptr %9, align 4, !tbaa !12
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #2
  %39 = load ptr, ptr %5, align 8, !tbaa !5
  %40 = getelementptr inbounds %struct.complex_int16_t, ptr %39, i32 0, i32 1
  %41 = load i16, ptr %40, align 2, !tbaa !17
  %42 = sext i16 %41 to i32
  store i32 %42, ptr %10, align 4, !tbaa !12
  %43 = load ptr, ptr %5, align 8, !tbaa !5
  %44 = getelementptr inbounds %struct.complex_int16_t, ptr %43, i32 1
  store ptr %44, ptr %5, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #2
  %45 = load i32, ptr %9, align 4, !tbaa !12
  %46 = load i32, ptr %9, align 4, !tbaa !12
  %47 = mul nsw i32 %45, %46
  %48 = load i32, ptr %10, align 4, !tbaa !12
  %49 = load i32, ptr %10, align 4, !tbaa !12
  %50 = mul nsw i32 %48, %49
  %51 = add nsw i32 %47, %50
  store i32 %51, ptr %11, align 4, !tbaa !12
  %52 = load i32, ptr %11, align 4, !tbaa !12
  %53 = load ptr, ptr %6, align 8, !tbaa !5
  %54 = getelementptr inbounds i32, ptr %53, i32 1
  store ptr %54, ptr %6, align 8, !tbaa !5
  store i32 %52, ptr %53, align 4, !tbaa !12
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #2
  br label %55

55:                                               ; preds = %34
  %56 = load i32, ptr %8, align 4, !tbaa !12
  %57 = add nsw i32 %56, 1
  store i32 %57, ptr %8, align 4, !tbaa !12
  br label %30, !llvm.loop !18

58:                                               ; preds = %30
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #2
  call void @llvm.lifetime.end.p0(i64 4, 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, !11, i64 8}
!10 = !{!"FilterbankState", !11, i64 0, !11, i64 4, !11, i64 8, !6, i64 16, !6, i64 24, !6, i64 32, !6, i64 40, !6, i64 48, !6, i64 56}
!11 = !{!"int", !7, i64 0}
!12 = !{!11, !11, i64 0}
!13 = !{!10, !11, i64 4}
!14 = !{!15, !16, i64 0}
!15 = !{!"complex_int16_t", !16, i64 0, !16, i64 2}
!16 = !{!"short", !7, i64 0}
!17 = !{!15, !16, i64 2}
!18 = distinct !{!18, !19}
!19 = !{!"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"

%struct.complex_int16_t = type { i16, i16 }

; Function Attrs: nofree norecurse nosync nounwind memory(readwrite, inaccessiblemem: none) uwtable
define dso_local void @FilterbankConvertFftComplexToEnergy(ptr nocapture noundef readonly %0, ptr nocapture noundef readonly %1, ptr nocapture noundef writeonly %2) local_unnamed_addr #0 {
  %4 = getelementptr inbounds i8, ptr %0, i64 8
  %5 = load i32, ptr %4, align 8, !tbaa !5
  %6 = getelementptr inbounds i8, ptr %0, i64 4
  %7 = load i32, ptr %6, align 4, !tbaa !11
  %8 = icmp slt i32 %7, %5
  br i1 %8, label %.lr.ph.preheader, label %._crit_edge

.lr.ph.preheader:                                 ; preds = %3
  %9 = sext i32 %7 to i64
  %10 = getelementptr inbounds %struct.complex_int16_t, ptr %1, i64 %9
  %11 = getelementptr inbounds i32, ptr %2, i64 %9
  %12 = xor i32 %7, -1
  %13 = add i32 %5, %12
  %14 = zext i32 %13 to i64
  %15 = add nuw nsw i64 %14, 1
  %min.iters.check = icmp ult i32 %13, 7
  br i1 %min.iters.check, label %.lr.ph.preheader34, label %vector.ph

vector.ph:                                        ; preds = %.lr.ph.preheader
  %n.vec = and i64 %15, 8589934584
  %16 = shl nuw nsw i64 %n.vec, 2
  %ind.end = getelementptr i8, ptr %10, i64 %16
  %17 = shl nuw nsw i64 %n.vec, 2
  %ind.end22 = getelementptr i8, ptr %11, i64 %17
  %.cast = trunc i64 %n.vec to i32
  %ind.end24 = add i32 %7, %.cast
  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
  %18 = or disjoint i64 %offset.idx, 16
  %next.gep = getelementptr i8, ptr %10, i64 %offset.idx
  %next.gep26 = getelementptr i8, ptr %10, i64 %18
  %offset.idx27 = shl i64 %index, 2
  %next.gep28 = getelementptr i8, ptr %11, i64 %offset.idx27
  %wide.vec = load <8 x i16>, ptr %next.gep, align 2, !tbaa !12
  %wide.vec30 = load <8 x i16>, ptr %next.gep26, align 2, !tbaa !12
  %strided.vec = shufflevector <8 x i16> %wide.vec, <8 x i16> poison, <4 x i32> <i32 0, i32 2, i32 4, i32 6>
  %strided.vec31 = shufflevector <8 x i16> %wide.vec30, <8 x i16> poison, <4 x i32> <i32 0, i32 2, i32 4, i32 6>
  %strided.vec32 = shufflevector <8 x i16> %wide.vec, <8 x i16> poison, <4 x i32> <i32 1, i32 3, i32 5, i32 7>
  %strided.vec33 = shufflevector <8 x i16> %wide.vec30, <8 x i16> poison, <4 x i32> <i32 1, i32 3, i32 5, i32 7>
  %19 = sext <4 x i16> %strided.vec to <4 x i32>
  %20 = sext <4 x i16> %strided.vec31 to <4 x i32>
  %21 = sext <4 x i16> %strided.vec32 to <4 x i32>
  %22 = sext <4 x i16> %strided.vec33 to <4 x i32>
  %23 = mul nsw <4 x i32> %19, %19
  %24 = mul nsw <4 x i32> %20, %20
  %25 = mul nsw <4 x i32> %21, %21
  %26 = mul nsw <4 x i32> %22, %22
  %27 = add nuw nsw <4 x i32> %25, %23
  %28 = add nuw nsw <4 x i32> %26, %24
  %29 = getelementptr i8, ptr %next.gep28, i64 16
  store <4 x i32> %27, ptr %next.gep28, align 4, !tbaa !14
  store <4 x i32> %28, ptr %29, align 4, !tbaa !14
  %index.next = add nuw i64 %index, 8
  %30 = icmp eq i64 %index.next, %n.vec
  br i1 %30, label %middle.block, label %vector.body, !llvm.loop !15

middle.block:                                     ; preds = %vector.body
  %cmp.n = icmp eq i64 %15, %n.vec
  br i1 %cmp.n, label %._crit_edge, label %.lr.ph.preheader34

.lr.ph.preheader34:                               ; preds = %middle.block, %.lr.ph.preheader
  %.021.ph = phi ptr [ %10, %.lr.ph.preheader ], [ %ind.end, %middle.block ]
  %.01720.ph = phi ptr [ %11, %.lr.ph.preheader ], [ %ind.end22, %middle.block ]
  %.01819.ph = phi i32 [ %7, %.lr.ph.preheader ], [ %ind.end24, %middle.block ]
  br label %.lr.ph

.lr.ph:                                           ; preds = %.lr.ph.preheader34, %.lr.ph
  %.021 = phi ptr [ %36, %.lr.ph ], [ %.021.ph, %.lr.ph.preheader34 ]
  %.01720 = phi ptr [ %40, %.lr.ph ], [ %.01720.ph, %.lr.ph.preheader34 ]
  %.01819 = phi i32 [ %41, %.lr.ph ], [ %.01819.ph, %.lr.ph.preheader34 ]
  %31 = load i16, ptr %.021, align 2, !tbaa !19
  %32 = sext i16 %31 to i32
  %33 = getelementptr inbounds i8, ptr %.021, i64 2
  %34 = load i16, ptr %33, align 2, !tbaa !21
  %35 = sext i16 %34 to i32
  %36 = getelementptr inbounds i8, ptr %.021, i64 4
  %37 = mul nsw i32 %32, %32
  %38 = mul nsw i32 %35, %35
  %39 = add nuw nsw i32 %38, %37
  %40 = getelementptr inbounds i8, ptr %.01720, i64 4
  store i32 %39, ptr %.01720, align 4, !tbaa !14
  %41 = add nsw i32 %.01819, 1
  %exitcond.not = icmp eq i32 %41, %5
  br i1 %exitcond.not, label %._crit_edge, label %.lr.ph, !llvm.loop !22

._crit_edge:                                      ; preds = %.lr.ph, %middle.block, %3
  ret void
}

attributes #0 = { nofree norecurse nosync nounwind memory(readwrite, inaccessiblemem: 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, !7, i64 8}
!6 = !{!"FilterbankState", !7, i64 0, !7, i64 4, !7, i64 8, !10, i64 16, !10, i64 24, !10, i64 32, !10, i64 40, !10, i64 48, !10, i64 56}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"any pointer", !8, i64 0}
!11 = !{!6, !7, i64 4}
!12 = !{!13, !13, i64 0}
!13 = !{!"short", !8, i64 0}
!14 = !{!7, !7, i64 0}
!15 = distinct !{!15, !16, !17, !18}
!16 = !{!"llvm.loop.mustprogress"}
!17 = !{!"llvm.loop.isvectorized", i32 1}
!18 = !{!"llvm.loop.unroll.runtime.disable"}
!19 = !{!20, !13, i64 0}
!20 = !{!"complex_int16_t", !13, i64 0, !13, i64 2}
!21 = !{!20, !13, i64 2}
!22 = distinct !{!22, !16, !18, !17}


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