; LLVM IR from Seeed-Studio/Seeed_Arduino_edgeimpulse :: src/edge-impulse-sdk/tensorflow/lite/micro (micro_utils)

; 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: mustprogress nounwind uwtable
declare dso_local noundef i32 @_ZN6tflite12ElementCountERK14TfLiteIntArray(ptr noundef nonnull align 4 dereferenceable(4)) #0

; 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

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare float @llvm.minnum.f32(float, float) #2

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare float @llvm.maxnum.f32(float, float) #2

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef float @_ZSt4fabsf(float noundef) #3

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare float @llvm.round.f32(float) #2

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN6tflite23SignedSymmetricQuantizeEPKfP14TfLiteIntArrayPsPf(ptr noundef %0, ptr noundef %1, ptr noundef %2, ptr noundef %3) #4 {
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca ptr, align 8
  %9 = alloca i32, align 4
  %10 = alloca float, align 4
  %11 = alloca float, align 4
  %12 = alloca i32, align 4
  %13 = alloca i32, align 4
  %14 = alloca i32, align 4
  store ptr %0, ptr %5, align 8, !tbaa !5
  store ptr %1, ptr %6, align 8, !tbaa !5
  store ptr %2, ptr %7, align 8, !tbaa !5
  store ptr %3, ptr %8, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #5
  %15 = load ptr, ptr %6, align 8, !tbaa !5
  %16 = call noundef i32 @_ZN6tflite12ElementCountERK14TfLiteIntArray(ptr noundef nonnull align 4 dereferenceable(4) %15)
  store i32 %16, ptr %9, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #5
  store float 0.000000e+00, ptr %10, align 4, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #5
  store float 0.000000e+00, ptr %11, align 4, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 4, ptr %12) #5
  store i32 0, ptr %12, align 4, !tbaa !9
  br label %17

17:                                               ; preds = %37, %4
  %18 = load i32, ptr %12, align 4, !tbaa !9
  %19 = load i32, ptr %9, align 4, !tbaa !9
  %20 = icmp slt i32 %18, %19
  br i1 %20, label %22, label %21

21:                                               ; preds = %17
  call void @llvm.lifetime.end.p0(i64 4, ptr %12) #5
  br label %40

22:                                               ; preds = %17
  %23 = load float, ptr %10, align 4, !tbaa !11
  %24 = load ptr, ptr %5, align 8, !tbaa !5
  %25 = load i32, ptr %12, align 4, !tbaa !9
  %26 = sext i32 %25 to i64
  %27 = getelementptr inbounds float, ptr %24, i64 %26
  %28 = load float, ptr %27, align 4, !tbaa !11
  %29 = call float @llvm.minnum.f32(float %23, float %28)
  store float %29, ptr %10, align 4, !tbaa !11
  %30 = load float, ptr %11, align 4, !tbaa !11
  %31 = load ptr, ptr %5, align 8, !tbaa !5
  %32 = load i32, ptr %12, align 4, !tbaa !9
  %33 = sext i32 %32 to i64
  %34 = getelementptr inbounds float, ptr %31, i64 %33
  %35 = load float, ptr %34, align 4, !tbaa !11
  %36 = call float @llvm.maxnum.f32(float %30, float %35)
  store float %36, ptr %11, align 4, !tbaa !11
  br label %37

37:                                               ; preds = %22
  %38 = load i32, ptr %12, align 4, !tbaa !9
  %39 = add nsw i32 %38, 1
  store i32 %39, ptr %12, align 4, !tbaa !9
  br label %17, !llvm.loop !13

40:                                               ; preds = %21
  %41 = load float, ptr %10, align 4, !tbaa !11
  %42 = call noundef float @_ZSt4fabsf(float noundef %41)
  %43 = load float, ptr %11, align 4, !tbaa !11
  %44 = call noundef float @_ZSt4fabsf(float noundef %43)
  %45 = call float @llvm.maxnum.f32(float %42, float %44)
  %46 = fdiv float %45, 3.276700e+04
  %47 = load ptr, ptr %8, align 8, !tbaa !5
  store float %46, ptr %47, align 4, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 4, ptr %13) #5
  store i32 0, ptr %13, align 4, !tbaa !9
  br label %48

48:                                               ; preds = %73, %40
  %49 = load i32, ptr %13, align 4, !tbaa !9
  %50 = load i32, ptr %9, align 4, !tbaa !9
  %51 = icmp slt i32 %49, %50
  br i1 %51, label %53, label %52

52:                                               ; preds = %48
  call void @llvm.lifetime.end.p0(i64 4, ptr %13) #5
  br label %76

53:                                               ; preds = %48
  call void @llvm.lifetime.start.p0(i64 4, ptr %14) #5
  %54 = load ptr, ptr %5, align 8, !tbaa !5
  %55 = load i32, ptr %13, align 4, !tbaa !9
  %56 = sext i32 %55 to i64
  %57 = getelementptr inbounds float, ptr %54, i64 %56
  %58 = load float, ptr %57, align 4, !tbaa !11
  %59 = load ptr, ptr %8, align 8, !tbaa !5
  %60 = load float, ptr %59, align 4, !tbaa !11
  %61 = fdiv float %58, %60
  %62 = call float @llvm.round.f32(float %61)
  %63 = fptosi float %62 to i32
  store i32 %63, ptr %14, align 4, !tbaa !9
  %64 = load i32, ptr %14, align 4, !tbaa !9
  %65 = sitofp i32 %64 to float
  %66 = call float @llvm.maxnum.f32(float -3.276700e+04, float %65)
  %67 = call float @llvm.minnum.f32(float 3.276700e+04, float %66)
  %68 = fptosi float %67 to i16
  %69 = load ptr, ptr %7, align 8, !tbaa !5
  %70 = load i32, ptr %13, align 4, !tbaa !9
  %71 = sext i32 %70 to i64
  %72 = getelementptr inbounds i16, ptr %69, i64 %71
  store i16 %68, ptr %72, align 2, !tbaa !15
  call void @llvm.lifetime.end.p0(i64 4, ptr %14) #5
  br label %73

73:                                               ; preds = %53
  %74 = load i32, ptr %13, align 4, !tbaa !9
  %75 = add nsw i32 %74, 1
  store i32 %75, ptr %13, align 4, !tbaa !9
  br label %48, !llvm.loop !17

76:                                               ; preds = %52
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #5
  ret void
}

attributes #0 = { mustprogress 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 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #3 = { inlinehint mustprogress 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 #4 = { mustprogress 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 #5 = { 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++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"float", !7, i64 0}
!13 = distinct !{!13, !14}
!14 = !{!"llvm.loop.mustprogress"}
!15 = !{!16, !16, i64 0}
!16 = !{!"short", !7, i64 0}
!17 = distinct !{!17, !14}


; 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: mustprogress nounwind uwtable
declare dso_local noundef i32 @_ZN6tflite12ElementCountERK14TfLiteIntArray(ptr noundef nonnull align 4 dereferenceable(4)) local_unnamed_addr #0

; Function Attrs: mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare float @llvm.minnum.f32(float, float) #1

; Function Attrs: mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare float @llvm.maxnum.f32(float, float) #1

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef float @_ZSt4fabsf(float noundef) local_unnamed_addr #2

; Function Attrs: mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare float @llvm.round.f32(float) #1

; Function Attrs: mustprogress nounwind uwtable
define dso_local void @_ZN6tflite23SignedSymmetricQuantizeEPKfP14TfLiteIntArrayPsPf(ptr nocapture noundef readonly %0, ptr noundef nonnull %1, ptr nocapture noundef writeonly %2, ptr nocapture noundef writeonly %3) local_unnamed_addr #0 {
  %5 = tail call noundef i32 @_ZN6tflite12ElementCountERK14TfLiteIntArray(ptr noundef nonnull align 4 dereferenceable(4) %1)
  %6 = icmp sgt i32 %5, 0
  br i1 %6, label %.lr.ph.preheader, label %._crit_edge

.lr.ph.preheader:                                 ; preds = %4
  %wide.trip.count = zext nneg i32 %5 to i64
  br label %.lr.ph

._crit_edge:                                      ; preds = %.lr.ph, %4
  %.023.lcssa = phi float [ 0.000000e+00, %4 ], [ %24, %.lr.ph ]
  %.0.lcssa = phi float [ 0.000000e+00, %4 ], [ %23, %.lr.ph ]
  %7 = tail call noundef float @_ZSt4fabsf(float noundef %.0.lcssa)
  %8 = tail call noundef float @_ZSt4fabsf(float noundef %.023.lcssa)
  %9 = tail call float @llvm.maxnum.f32(float %7, float %8)
  %10 = fdiv float %9, 3.276700e+04
  store float %10, ptr %3, align 4, !tbaa !5
  br i1 %6, label %.lr.ph31.preheader, label %._crit_edge32

.lr.ph31.preheader:                               ; preds = %._crit_edge
  %wide.trip.count38 = zext nneg i32 %5 to i64
  %min.iters.check = icmp ult i32 %5, 4
  br i1 %min.iters.check, label %.lr.ph31.preheader42, label %vector.ph

.lr.ph31.preheader42:                             ; preds = %middle.block, %.lr.ph31.preheader
  %indvars.iv35.ph = phi i64 [ 0, %.lr.ph31.preheader ], [ %n.vec, %middle.block ]
  br label %.lr.ph31

vector.ph:                                        ; preds = %.lr.ph31.preheader
  %n.vec = and i64 %wide.trip.count38, 2147483644
  %broadcast.splatinsert = insertelement <4 x float> poison, float %10, i64 0
  %broadcast.splat = shufflevector <4 x float> %broadcast.splatinsert, <4 x float> 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 ]
  %11 = getelementptr inbounds float, ptr %0, i64 %index
  %wide.load = load <4 x float>, ptr %11, align 4, !tbaa !5
  %12 = fdiv <4 x float> %wide.load, %broadcast.splat
  %13 = tail call <4 x float> @llvm.round.v4f32(<4 x float> %12)
  %14 = fptosi <4 x float> %13 to <4 x i32>
  %15 = sitofp <4 x i32> %14 to <4 x float>
  %16 = tail call <4 x float> @llvm.maxnum.v4f32(<4 x float> %15, <4 x float> <float -3.276700e+04, float -3.276700e+04, float -3.276700e+04, float -3.276700e+04>)
  %17 = tail call <4 x float> @llvm.minnum.v4f32(<4 x float> %16, <4 x float> <float 3.276700e+04, float 3.276700e+04, float 3.276700e+04, float 3.276700e+04>)
  %18 = fptosi <4 x float> %17 to <4 x i16>
  %19 = getelementptr inbounds i16, ptr %2, i64 %index
  store <4 x i16> %18, ptr %19, align 2, !tbaa !9
  %index.next = add nuw i64 %index, 4
  %20 = icmp eq i64 %index.next, %n.vec
  br i1 %20, label %middle.block, label %vector.body, !llvm.loop !11

middle.block:                                     ; preds = %vector.body
  %cmp.n = icmp eq i64 %n.vec, %wide.trip.count38
  br i1 %cmp.n, label %._crit_edge32, label %.lr.ph31.preheader42

.lr.ph:                                           ; preds = %.lr.ph.preheader, %.lr.ph
  %indvars.iv = phi i64 [ 0, %.lr.ph.preheader ], [ %indvars.iv.next, %.lr.ph ]
  %.027 = phi float [ 0.000000e+00, %.lr.ph.preheader ], [ %23, %.lr.ph ]
  %.02325 = phi float [ 0.000000e+00, %.lr.ph.preheader ], [ %24, %.lr.ph ]
  %21 = getelementptr inbounds float, ptr %0, i64 %indvars.iv
  %22 = load float, ptr %21, align 4, !tbaa !5
  %23 = tail call float @llvm.minnum.f32(float %.027, float %22)
  %24 = tail call float @llvm.maxnum.f32(float %.02325, float %22)
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %exitcond.not = icmp eq i64 %indvars.iv.next, %wide.trip.count
  br i1 %exitcond.not, label %._crit_edge, label %.lr.ph, !llvm.loop !15

._crit_edge32:                                    ; preds = %.lr.ph31, %middle.block, %._crit_edge
  ret void

.lr.ph31:                                         ; preds = %.lr.ph31.preheader42, %.lr.ph31
  %indvars.iv35 = phi i64 [ %indvars.iv.next36, %.lr.ph31 ], [ %indvars.iv35.ph, %.lr.ph31.preheader42 ]
  %25 = getelementptr inbounds float, ptr %0, i64 %indvars.iv35
  %26 = load float, ptr %25, align 4, !tbaa !5
  %27 = fdiv float %26, %10
  %28 = tail call float @llvm.round.f32(float %27)
  %29 = fptosi float %28 to i32
  %30 = sitofp i32 %29 to float
  %31 = tail call float @llvm.maxnum.f32(float %30, float -3.276700e+04)
  %32 = tail call float @llvm.minnum.f32(float %31, float 3.276700e+04)
  %33 = fptosi float %32 to i16
  %34 = getelementptr inbounds i16, ptr %2, i64 %indvars.iv35
  store i16 %33, ptr %34, align 2, !tbaa !9
  %indvars.iv.next36 = add nuw nsw i64 %indvars.iv35, 1
  %exitcond39.not = icmp eq i64 %indvars.iv.next36, %wide.trip.count38
  br i1 %exitcond39.not, label %._crit_edge32, label %.lr.ph31, !llvm.loop !16
}

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare <4 x float> @llvm.round.v4f32(<4 x float>) #3

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare <4 x float> @llvm.maxnum.v4f32(<4 x float>, <4 x float>) #3

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare <4 x float> @llvm.minnum.v4f32(<4 x float>, <4 x float>) #3

attributes #0 = { mustprogress 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 = { mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #2 = { inlinehint mustprogress 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 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }

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


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