; LLVM IR from tanakamasayuki/Arduino_TensorFlowLite_ESP32 :: src/tensorflow/lite/experimental/microfrontend/lib (pcan_gain_control_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"

%struct.PcanGainControlConfig = type { i32, float, float, i32 }

; Function Attrs: nounwind uwtable
define dso_local signext i16 @PcanGainLookupFunction(ptr noundef %0, i32 noundef %1, i32 noundef %2) #0 {
  %4 = alloca i16, align 2
  %5 = alloca ptr, align 8
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  %8 = alloca float, align 4
  %9 = alloca float, align 4
  %10 = alloca i32, align 4
  store ptr %0, ptr %5, align 8, !tbaa !5
  store i32 %1, ptr %6, align 4, !tbaa !9
  store i32 %2, ptr %7, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #3
  %11 = load i32, ptr %7, align 4, !tbaa !9
  %12 = uitofp i32 %11 to float
  %13 = load i32, ptr %6, align 4, !tbaa !9
  %14 = shl i32 1, %13
  %15 = uitofp i32 %14 to float
  %16 = fdiv float %12, %15
  store float %16, ptr %8, align 4, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #3
  %17 = load ptr, ptr %5, align 8, !tbaa !5
  %18 = getelementptr inbounds %struct.PcanGainControlConfig, ptr %17, i32 0, i32 3
  %19 = load i32, ptr %18, align 4, !tbaa !13
  %20 = shl i32 1, %19
  %21 = uitofp i32 %20 to float
  %22 = load float, ptr %8, align 4, !tbaa !11
  %23 = load ptr, ptr %5, align 8, !tbaa !5
  %24 = getelementptr inbounds %struct.PcanGainControlConfig, ptr %23, i32 0, i32 2
  %25 = load float, ptr %24, align 4, !tbaa !15
  %26 = fadd float %22, %25
  %27 = load ptr, ptr %5, align 8, !tbaa !5
  %28 = getelementptr inbounds %struct.PcanGainControlConfig, ptr %27, i32 0, i32 1
  %29 = load float, ptr %28, align 4, !tbaa !16
  %30 = fneg float %29
  %31 = call float @powf(float noundef %26, float noundef %30) #3
  %32 = fmul float %21, %31
  store float %32, ptr %9, align 4, !tbaa !11
  %33 = load float, ptr %9, align 4, !tbaa !11
  %34 = fcmp ogt float %33, 3.276700e+04
  br i1 %34, label %35, label %36

35:                                               ; preds = %3
  store i16 32767, ptr %4, align 2
  store i32 1, ptr %10, align 4
  br label %40

36:                                               ; preds = %3
  %37 = load float, ptr %9, align 4, !tbaa !11
  %38 = fadd float %37, 5.000000e-01
  %39 = fptosi float %38 to i16
  store i16 %39, ptr %4, align 2
  store i32 1, ptr %10, align 4
  br label %40

40:                                               ; preds = %36, %35
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #3
  %41 = load i16, ptr %4, align 2
  ret i16 %41
}

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

; Function Attrs: nounwind
declare float @powf(float noundef, float 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 = { nounwind "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 = !{!10, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"float", !7, i64 0}
!13 = !{!14, !10, i64 12}
!14 = !{!"PcanGainControlConfig", !10, i64 0, !12, i64 4, !12, i64 8, !10, i64 12}
!15 = !{!14, !12, i64 8}
!16 = !{!14, !12, i64 4}


; 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 nofree nounwind willreturn memory(write, argmem: readwrite) uwtable
define dso_local signext i16 @PcanGainLookupFunction(ptr nocapture noundef readonly %0, i32 noundef %1, i32 noundef %2) local_unnamed_addr #0 {
  %4 = uitofp i32 %2 to float
  %5 = shl nuw i32 1, %1
  %6 = uitofp i32 %5 to float
  %7 = fdiv float %4, %6
  %8 = getelementptr inbounds i8, ptr %0, i64 12
  %9 = load i32, ptr %8, align 4, !tbaa !5
  %10 = shl nuw i32 1, %9
  %11 = uitofp i32 %10 to float
  %12 = getelementptr inbounds i8, ptr %0, i64 8
  %13 = load float, ptr %12, align 4, !tbaa !11
  %14 = fadd float %7, %13
  %15 = getelementptr inbounds i8, ptr %0, i64 4
  %16 = load float, ptr %15, align 4, !tbaa !12
  %17 = fneg float %16
  %18 = tail call float @powf(float noundef %14, float noundef %17) #2
  %19 = fmul float %18, %11
  %20 = fcmp ogt float %19, 3.276700e+04
  %21 = fadd float %19, 5.000000e-01
  %22 = fptosi float %21 to i16
  %.0 = select i1 %20, i16 32767, i16 %22
  ret i16 %.0
}

; Function Attrs: mustprogress nofree nounwind willreturn memory(write)
declare float @powf(float noundef, float noundef) local_unnamed_addr #1

attributes #0 = { mustprogress nofree nounwind willreturn memory(write, argmem: readwrite) 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 nofree nounwind willreturn memory(write) "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 = { 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, !7, i64 12}
!6 = !{!"PcanGainControlConfig", !7, i64 0, !10, i64 4, !10, i64 8, !7, i64 12}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"float", !8, i64 0}
!11 = !{!6, !10, i64 8}
!12 = !{!6, !10, i64 4}


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