; LLVM IR from jgaeddert/liquid-dsp :: src/agc/src (agc_rrrf)

; 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.agc_rrrf_s = type { float, float, float, float, float, i32, i32, float, i32, i32 }

; 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: nounwind uwtable
define dso_local i32 @agc_rrrf_execute(ptr noundef %0, float noundef %1, ptr noundef %2) #1 {
  %4 = alloca i32, align 4
  %5 = alloca ptr, align 8
  %6 = alloca float, align 4
  %7 = alloca ptr, align 8
  %8 = alloca float, align 4
  %9 = alloca i32, align 4
  store ptr %0, ptr %5, align 8, !tbaa !5
  store float %1, ptr %6, align 4, !tbaa !9
  store ptr %2, ptr %7, align 8, !tbaa !5
  %10 = load float, ptr %6, align 4, !tbaa !9
  %11 = load ptr, ptr %5, align 8, !tbaa !5
  %12 = getelementptr inbounds %struct.agc_rrrf_s, ptr %11, i32 0, i32 0
  %13 = load float, ptr %12, align 4, !tbaa !11
  %14 = fmul float %10, %13
  %15 = load ptr, ptr %7, align 8, !tbaa !5
  store float %14, ptr %15, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #4
  %16 = load ptr, ptr %7, align 8, !tbaa !5
  %17 = load float, ptr %16, align 4, !tbaa !9
  %18 = load ptr, ptr %7, align 8, !tbaa !5
  %19 = load float, ptr %18, align 4, !tbaa !9
  %20 = fmul float %17, %19
  %21 = fmul float %17, -0.000000e+00
  store float %20, ptr %8, align 4, !tbaa !9
  %22 = load ptr, ptr %5, align 8, !tbaa !5
  %23 = getelementptr inbounds %struct.agc_rrrf_s, ptr %22, i32 0, i32 3
  %24 = load float, ptr %23, align 4, !tbaa !14
  %25 = fpext float %24 to double
  %26 = fsub double 1.000000e+00, %25
  %27 = load ptr, ptr %5, align 8, !tbaa !5
  %28 = getelementptr inbounds %struct.agc_rrrf_s, ptr %27, i32 0, i32 4
  %29 = load float, ptr %28, align 4, !tbaa !15
  %30 = fpext float %29 to double
  %31 = load ptr, ptr %5, align 8, !tbaa !5
  %32 = getelementptr inbounds %struct.agc_rrrf_s, ptr %31, i32 0, i32 3
  %33 = load float, ptr %32, align 4, !tbaa !14
  %34 = load float, ptr %8, align 4, !tbaa !9
  %35 = fmul float %33, %34
  %36 = fpext float %35 to double
  %37 = call double @llvm.fmuladd.f64(double %26, double %30, double %36)
  %38 = fptrunc double %37 to float
  %39 = load ptr, ptr %5, align 8, !tbaa !5
  %40 = getelementptr inbounds %struct.agc_rrrf_s, ptr %39, i32 0, i32 4
  store float %38, ptr %40, align 4, !tbaa !15
  %41 = load ptr, ptr %5, align 8, !tbaa !5
  %42 = getelementptr inbounds %struct.agc_rrrf_s, ptr %41, i32 0, i32 5
  %43 = load i32, ptr %42, align 4, !tbaa !16
  %44 = icmp ne i32 %43, 0
  br i1 %44, label %45, label %46

45:                                               ; preds = %3
  store i32 0, ptr %4, align 4
  store i32 1, ptr %9, align 4
  br label %88

46:                                               ; preds = %3
  %47 = load ptr, ptr %5, align 8, !tbaa !5
  %48 = getelementptr inbounds %struct.agc_rrrf_s, ptr %47, i32 0, i32 4
  %49 = load float, ptr %48, align 4, !tbaa !15
  %50 = fcmp ogt float %49, 0x3EB0C6F7A0000000
  br i1 %50, label %51, label %66

51:                                               ; preds = %46
  %52 = load ptr, ptr %5, align 8, !tbaa !5
  %53 = getelementptr inbounds %struct.agc_rrrf_s, ptr %52, i32 0, i32 3
  %54 = load float, ptr %53, align 4, !tbaa !14
  %55 = fmul float -5.000000e-01, %54
  %56 = load ptr, ptr %5, align 8, !tbaa !5
  %57 = getelementptr inbounds %struct.agc_rrrf_s, ptr %56, i32 0, i32 4
  %58 = load float, ptr %57, align 4, !tbaa !15
  %59 = call float @logf(float noundef %58) #4
  %60 = fmul float %55, %59
  %61 = call float @expf(float noundef %60) #4, !tbaa !17
  %62 = load ptr, ptr %5, align 8, !tbaa !5
  %63 = getelementptr inbounds %struct.agc_rrrf_s, ptr %62, i32 0, i32 0
  %64 = load float, ptr %63, align 4, !tbaa !11
  %65 = fmul float %64, %61
  store float %65, ptr %63, align 4, !tbaa !11
  br label %66

66:                                               ; preds = %51, %46
  %67 = load ptr, ptr %5, align 8, !tbaa !5
  %68 = getelementptr inbounds %struct.agc_rrrf_s, ptr %67, i32 0, i32 0
  %69 = load float, ptr %68, align 4, !tbaa !11
  %70 = fcmp ogt float %69, 1.000000e+06
  br i1 %70, label %71, label %72

71:                                               ; preds = %66
  br label %76

72:                                               ; preds = %66
  %73 = load ptr, ptr %5, align 8, !tbaa !5
  %74 = getelementptr inbounds %struct.agc_rrrf_s, ptr %73, i32 0, i32 0
  %75 = load float, ptr %74, align 4, !tbaa !11
  br label %76

76:                                               ; preds = %72, %71
  %77 = phi float [ 1.000000e+06, %71 ], [ %75, %72 ]
  %78 = load ptr, ptr %5, align 8, !tbaa !5
  %79 = getelementptr inbounds %struct.agc_rrrf_s, ptr %78, i32 0, i32 0
  store float %77, ptr %79, align 4, !tbaa !11
  %80 = load ptr, ptr %5, align 8, !tbaa !5
  %81 = call i32 @agc_rrrf_squelch_update_mode(ptr noundef %80)
  %82 = load ptr, ptr %5, align 8, !tbaa !5
  %83 = getelementptr inbounds %struct.agc_rrrf_s, ptr %82, i32 0, i32 1
  %84 = load float, ptr %83, align 4, !tbaa !18
  %85 = load ptr, ptr %7, align 8, !tbaa !5
  %86 = load float, ptr %85, align 4, !tbaa !9
  %87 = fmul float %86, %84
  store float %87, ptr %85, align 4, !tbaa !9
  store i32 0, ptr %4, align 4
  store i32 1, ptr %9, align 4
  br label %88

88:                                               ; preds = %76, %45
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #4
  %89 = load i32, ptr %4, align 4
  ret i32 %89
}

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare double @llvm.fmuladd.f64(double, double, double) #2

; Function Attrs: nounwind
declare float @expf(float noundef) #3

; Function Attrs: nounwind
declare float @logf(float noundef) #3

; Function Attrs: nounwind uwtable
declare dso_local i32 @agc_rrrf_squelch_update_mode(ptr noundef) #1

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 #2 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #3 = { 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 #4 = { 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 = !{!"float", !7, i64 0}
!11 = !{!12, !10, i64 0}
!12 = !{!"agc_rrrf_s", !10, i64 0, !10, i64 4, !10, i64 8, !10, i64 12, !10, i64 16, !13, i64 20, !13, i64 24, !10, i64 28, !13, i64 32, !13, i64 36}
!13 = !{!"int", !7, i64 0}
!14 = !{!12, !10, i64 12}
!15 = !{!12, !10, i64 16}
!16 = !{!12, !13, i64 20}
!17 = !{!13, !13, i64 0}
!18 = !{!12, !10, 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: nounwind uwtable
define dso_local noundef i32 @agc_rrrf_execute(ptr noundef %0, float noundef %1, ptr nocapture noundef %2) local_unnamed_addr #0 {
  %4 = load float, ptr %0, align 4, !tbaa !5
  %5 = fmul float %4, %1
  store float %5, ptr %2, align 4, !tbaa !11
  %6 = fmul float %5, %5
  %7 = getelementptr inbounds i8, ptr %0, i64 12
  %8 = load float, ptr %7, align 4, !tbaa !12
  %9 = fpext float %8 to double
  %10 = fsub double 1.000000e+00, %9
  %11 = getelementptr inbounds i8, ptr %0, i64 16
  %12 = load float, ptr %11, align 4, !tbaa !13
  %13 = fpext float %12 to double
  %14 = fmul float %8, %6
  %15 = fpext float %14 to double
  %16 = tail call double @llvm.fmuladd.f64(double %10, double %13, double %15)
  %17 = fptrunc double %16 to float
  store float %17, ptr %11, align 4, !tbaa !13
  %18 = getelementptr inbounds i8, ptr %0, i64 20
  %19 = load i32, ptr %18, align 4, !tbaa !14
  %.not = icmp eq i32 %19, 0
  br i1 %.not, label %20, label %38

20:                                               ; preds = %3
  %21 = fcmp ogt float %17, 0x3EB0C6F7A0000000
  br i1 %21, label %22, label %._crit_edge

._crit_edge:                                      ; preds = %20
  %.pre = load float, ptr %0, align 4, !tbaa !5
  br label %29

22:                                               ; preds = %20
  %23 = fmul float %8, -5.000000e-01
  %24 = tail call float @logf(float noundef %17) #3
  %25 = fmul float %23, %24
  %26 = tail call float @expf(float noundef %25) #3, !tbaa !15
  %27 = load float, ptr %0, align 4, !tbaa !5
  %28 = fmul float %26, %27
  br label %29

29:                                               ; preds = %._crit_edge, %22
  %30 = phi float [ %.pre, %._crit_edge ], [ %28, %22 ]
  %31 = fcmp ogt float %30, 1.000000e+06
  %32 = select i1 %31, float 1.000000e+06, float %30
  store float %32, ptr %0, align 4, !tbaa !5
  %33 = tail call i32 @agc_rrrf_squelch_update_mode(ptr noundef nonnull %0)
  %34 = getelementptr inbounds i8, ptr %0, i64 4
  %35 = load float, ptr %34, align 4, !tbaa !16
  %36 = load float, ptr %2, align 4, !tbaa !11
  %37 = fmul float %35, %36
  store float %37, ptr %2, align 4, !tbaa !11
  br label %38

38:                                               ; preds = %3, %29
  ret i32 0
}

; Function Attrs: mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare double @llvm.fmuladd.f64(double, double, double) #1

; Function Attrs: mustprogress nofree nounwind willreturn memory(write)
declare float @expf(float noundef) local_unnamed_addr #2

; Function Attrs: mustprogress nofree nounwind willreturn memory(write)
declare float @logf(float noundef) local_unnamed_addr #2

; Function Attrs: nounwind uwtable
declare dso_local i32 @agc_rrrf_squelch_update_mode(ptr noundef) local_unnamed_addr #0

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 = { mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #2 = { 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 #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, !7, i64 0}
!6 = !{!"agc_rrrf_s", !7, i64 0, !7, i64 4, !7, i64 8, !7, i64 12, !7, i64 16, !10, i64 20, !10, i64 24, !7, i64 28, !10, i64 32, !10, i64 36}
!7 = !{!"float", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"int", !8, i64 0}
!11 = !{!7, !7, i64 0}
!12 = !{!6, !7, i64 12}
!13 = !{!6, !7, i64 16}
!14 = !{!6, !10, i64 20}
!15 = !{!10, !10, i64 0}
!16 = !{!6, !7, i64 4}


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