; LLVM IR from Seeed-Studio/Seeed_Arduino_edgeimpulse :: src/edge-impulse-sdk/tensorflow/lite/kernels/internal (quantization_util)

; 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: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #0

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #0

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN6tflite22NudgeQuantizationRangeEffiiPfS0_S0_(float noundef %0, float noundef %1, i32 noundef %2, i32 noundef %3, ptr noundef %4, ptr noundef %5, ptr noundef %6) #1 {
  %8 = alloca float, align 4
  %9 = alloca float, align 4
  %10 = alloca i32, align 4
  %11 = alloca i32, align 4
  %12 = alloca ptr, align 8
  %13 = alloca ptr, align 8
  %14 = alloca ptr, align 8
  %15 = alloca float, align 4
  %16 = alloca float, align 4
  %17 = alloca float, align 4
  %18 = alloca i16, align 2
  store float %0, ptr %8, align 4, !tbaa !5
  store float %1, ptr %9, align 4, !tbaa !5
  store i32 %2, ptr %10, align 4, !tbaa !9
  store i32 %3, ptr %11, align 4, !tbaa !9
  store ptr %4, ptr %12, align 8, !tbaa !11
  store ptr %5, ptr %13, align 8, !tbaa !11
  store ptr %6, ptr %14, align 8, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 4, ptr %15) #3
  %19 = load i32, ptr %10, align 4, !tbaa !9
  %20 = sitofp i32 %19 to float
  store float %20, ptr %15, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %16) #3
  %21 = load i32, ptr %11, align 4, !tbaa !9
  %22 = sitofp i32 %21 to float
  store float %22, ptr %16, align 4, !tbaa !5
  %23 = load float, ptr %9, align 4, !tbaa !5
  %24 = load float, ptr %8, align 4, !tbaa !5
  %25 = fsub float %23, %24
  %26 = load float, ptr %16, align 4, !tbaa !5
  %27 = load float, ptr %15, align 4, !tbaa !5
  %28 = fsub float %26, %27
  %29 = fdiv float %25, %28
  %30 = load ptr, ptr %14, align 8, !tbaa !11
  store float %29, ptr %30, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %17) #3
  %31 = load float, ptr %15, align 4, !tbaa !5
  %32 = load float, ptr %8, align 4, !tbaa !5
  %33 = load ptr, ptr %14, align 8, !tbaa !11
  %34 = load float, ptr %33, align 4, !tbaa !5
  %35 = fdiv float %32, %34
  %36 = fsub float %31, %35
  store float %36, ptr %17, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 2, ptr %18) #3
  %37 = load float, ptr %17, align 4, !tbaa !5
  %38 = load float, ptr %15, align 4, !tbaa !5
  %39 = fcmp olt float %37, %38
  br i1 %39, label %40, label %43

40:                                               ; preds = %7
  %41 = load i32, ptr %10, align 4, !tbaa !9
  %42 = trunc i32 %41 to i16
  store i16 %42, ptr %18, align 2, !tbaa !13
  br label %55

43:                                               ; preds = %7
  %44 = load float, ptr %17, align 4, !tbaa !5
  %45 = load float, ptr %16, align 4, !tbaa !5
  %46 = fcmp ogt float %44, %45
  br i1 %46, label %47, label %50

47:                                               ; preds = %43
  %48 = load i32, ptr %11, align 4, !tbaa !9
  %49 = trunc i32 %48 to i16
  store i16 %49, ptr %18, align 2, !tbaa !13
  br label %54

50:                                               ; preds = %43
  %51 = load float, ptr %17, align 4, !tbaa !5
  %52 = call noundef float @_ZN6tflite11TfLiteRoundIfEET_S1_(float noundef %51)
  %53 = fptoui float %52 to i16
  store i16 %53, ptr %18, align 2, !tbaa !13
  br label %54

54:                                               ; preds = %50, %47
  br label %55

55:                                               ; preds = %54, %40
  %56 = load float, ptr %15, align 4, !tbaa !5
  %57 = load i16, ptr %18, align 2, !tbaa !13
  %58 = zext i16 %57 to i32
  %59 = sitofp i32 %58 to float
  %60 = fsub float %56, %59
  %61 = load ptr, ptr %14, align 8, !tbaa !11
  %62 = load float, ptr %61, align 4, !tbaa !5
  %63 = fmul float %60, %62
  %64 = load ptr, ptr %12, align 8, !tbaa !11
  store float %63, ptr %64, align 4, !tbaa !5
  %65 = load float, ptr %16, align 4, !tbaa !5
  %66 = load i16, ptr %18, align 2, !tbaa !13
  %67 = zext i16 %66 to i32
  %68 = sitofp i32 %67 to float
  %69 = fsub float %65, %68
  %70 = load ptr, ptr %14, align 8, !tbaa !11
  %71 = load float, ptr %70, align 4, !tbaa !5
  %72 = fmul float %69, %71
  %73 = load ptr, ptr %13, align 8, !tbaa !11
  store float %72, ptr %73, align 4, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 2, ptr %18) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %17) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %16) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %15) #3
  ret void
}

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

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 #2 = { inlinehint 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 #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 = !{!"float", !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 = !{!"any pointer", !7, i64 0}
!13 = !{!14, !14, i64 0}
!14 = !{!"short", !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"

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN6tflite22NudgeQuantizationRangeEffiiPfS0_S0_(float noundef %0, float noundef %1, i32 noundef %2, i32 noundef %3, ptr nocapture noundef writeonly %4, ptr nocapture noundef writeonly %5, ptr nocapture noundef %6) local_unnamed_addr #0 {
  %8 = sitofp i32 %2 to float
  %9 = sitofp i32 %3 to float
  %10 = fsub float %1, %0
  %11 = fsub float %9, %8
  %12 = fdiv float %10, %11
  store float %12, ptr %6, align 4, !tbaa !5
  %13 = fdiv float %0, %12
  %14 = fsub float %8, %13
  %15 = fcmp olt float %14, %8
  br i1 %15, label %16, label %18

16:                                               ; preds = %7
  %17 = trunc i32 %2 to i16
  br label %25

18:                                               ; preds = %7
  %19 = fcmp ogt float %14, %9
  br i1 %19, label %20, label %22

20:                                               ; preds = %18
  %21 = trunc i32 %3 to i16
  br label %25

22:                                               ; preds = %18
  %23 = tail call noundef float @_ZN6tflite11TfLiteRoundIfEET_S1_(float noundef %14)
  %24 = fptoui float %23 to i16
  %.pre = load float, ptr %6, align 4, !tbaa !5
  br label %25

25:                                               ; preds = %20, %22, %16
  %26 = phi float [ %12, %16 ], [ %12, %20 ], [ %.pre, %22 ]
  %.0 = phi i16 [ %17, %16 ], [ %21, %20 ], [ %24, %22 ]
  %27 = uitofp i16 %.0 to float
  %28 = fsub float %8, %27
  %29 = fmul float %26, %28
  store float %29, ptr %4, align 4, !tbaa !5
  %30 = fsub float %9, %27
  %31 = load float, ptr %6, align 4, !tbaa !5
  %32 = fmul float %30, %31
  store float %32, ptr %5, align 4, !tbaa !5
  ret void
}

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local noundef float @_ZN6tflite11TfLiteRoundIfEET_S1_(float noundef) local_unnamed_addr #1

attributes #0 = { 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 #1 = { inlinehint 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" }

!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"}


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