; LLVM IR from jgaeddert/liquid-dsp :: src/modem/src (modemcf)

; 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.modemcf_s = type { i32, i32, i32, [8 x float], ptr, i32, { float, float }, { float, float }, %union.anon, ptr, ptr, ptr, i32 }
%union.anon = type { %struct.anon.3 }
%struct.anon.3 = type { i32, [8 x i32], [8 x float], [8 x float], [8 x float], ptr }

; 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: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare float @llvm.fmuladd.f32(float, float, float) #1

; Function Attrs: nounwind
declare float @cabsf(<2 x float> noundef) #2

; Function Attrs: nounwind uwtable
define dso_local i32 @modemcf_arb_scale(ptr noundef %0) #3 {
  %2 = alloca ptr, align 8
  %3 = alloca i32, align 4
  %4 = alloca float, align 4
  %5 = alloca float, align 4
  %6 = alloca { float, float }, align 4
  store ptr %0, ptr %2, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #4
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #4
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #4
  store float 0.000000e+00, ptr %5, align 4, !tbaa !9
  store i32 0, ptr %3, align 4, !tbaa !11
  br label %7

7:                                                ; preds = %32, %1
  %8 = load i32, ptr %3, align 4, !tbaa !11
  %9 = load ptr, ptr %2, align 8, !tbaa !5
  %10 = getelementptr inbounds %struct.modemcf_s, ptr %9, i32 0, i32 2
  %11 = load i32, ptr %10, align 8, !tbaa !13
  %12 = icmp ult i32 %8, %11
  br i1 %12, label %13, label %35

13:                                               ; preds = %7
  %14 = load ptr, ptr %2, align 8, !tbaa !5
  %15 = getelementptr inbounds %struct.modemcf_s, ptr %14, i32 0, i32 4
  %16 = load ptr, ptr %15, align 8, !tbaa !15
  %17 = load i32, ptr %3, align 4, !tbaa !11
  %18 = zext i32 %17 to i64
  %19 = getelementptr inbounds { float, float }, ptr %16, i64 %18
  %20 = getelementptr inbounds { float, float }, ptr %19, i32 0, i32 0
  %21 = load float, ptr %20, align 4
  %22 = getelementptr inbounds { float, float }, ptr %19, i32 0, i32 1
  %23 = load float, ptr %22, align 4
  %24 = getelementptr inbounds { float, float }, ptr %6, i32 0, i32 0
  %25 = getelementptr inbounds { float, float }, ptr %6, i32 0, i32 1
  store float %21, ptr %24, align 4
  store float %23, ptr %25, align 4
  %26 = load <2 x float>, ptr %6, align 4
  %27 = call float @cabsf(<2 x float> noundef %26) #4
  store float %27, ptr %4, align 4, !tbaa !9
  %28 = load float, ptr %4, align 4, !tbaa !9
  %29 = load float, ptr %4, align 4, !tbaa !9
  %30 = load float, ptr %5, align 4, !tbaa !9
  %31 = call float @llvm.fmuladd.f32(float %28, float %29, float %30)
  store float %31, ptr %5, align 4, !tbaa !9
  br label %32

32:                                               ; preds = %13
  %33 = load i32, ptr %3, align 4, !tbaa !11
  %34 = add i32 %33, 1
  store i32 %34, ptr %3, align 4, !tbaa !11
  br label %7, !llvm.loop !16

35:                                               ; preds = %7
  %36 = load float, ptr %5, align 4, !tbaa !9
  %37 = load ptr, ptr %2, align 8, !tbaa !5
  %38 = getelementptr inbounds %struct.modemcf_s, ptr %37, i32 0, i32 2
  %39 = load i32, ptr %38, align 8, !tbaa !13
  %40 = uitofp i32 %39 to float
  %41 = fdiv float %36, %40
  %42 = call float @sqrtf(float noundef %41) #4
  store float %42, ptr %5, align 4, !tbaa !9
  store i32 0, ptr %3, align 4, !tbaa !11
  br label %43

43:                                               ; preds = %65, %35
  %44 = load i32, ptr %3, align 4, !tbaa !11
  %45 = load ptr, ptr %2, align 8, !tbaa !5
  %46 = getelementptr inbounds %struct.modemcf_s, ptr %45, i32 0, i32 2
  %47 = load i32, ptr %46, align 8, !tbaa !13
  %48 = icmp ult i32 %44, %47
  br i1 %48, label %49, label %68

49:                                               ; preds = %43
  %50 = load float, ptr %5, align 4, !tbaa !9
  %51 = load ptr, ptr %2, align 8, !tbaa !5
  %52 = getelementptr inbounds %struct.modemcf_s, ptr %51, i32 0, i32 4
  %53 = load ptr, ptr %52, align 8, !tbaa !15
  %54 = load i32, ptr %3, align 4, !tbaa !11
  %55 = zext i32 %54 to i64
  %56 = getelementptr inbounds { float, float }, ptr %53, i64 %55
  %57 = getelementptr inbounds { float, float }, ptr %56, i32 0, i32 0
  %58 = load float, ptr %57, align 4
  %59 = getelementptr inbounds { float, float }, ptr %56, i32 0, i32 1
  %60 = load float, ptr %59, align 4
  %61 = fdiv float %58, %50
  %62 = fdiv float %60, %50
  %63 = getelementptr inbounds { float, float }, ptr %56, i32 0, i32 0
  %64 = getelementptr inbounds { float, float }, ptr %56, i32 0, i32 1
  store float %61, ptr %63, align 4
  store float %62, ptr %64, align 4
  br label %65

65:                                               ; preds = %49
  %66 = load i32, ptr %3, align 4, !tbaa !11
  %67 = add i32 %66, 1
  store i32 %67, ptr %3, align 4, !tbaa !11
  br label %43, !llvm.loop !18

68:                                               ; preds = %43
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #4
  ret i32 0
}

; Function Attrs: nounwind
declare float @sqrtf(float noundef) #2

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
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 uwtable "min-legal-vector-width"="64" "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, !12, i64 0}
!12 = !{!"int", !7, i64 0}
!13 = !{!14, !12, i64 8}
!14 = !{!"modemcf_s", !12, i64 0, !12, i64 4, !12, i64 8, !7, i64 12, !6, i64 48, !12, i64 56, !7, i64 60, !7, i64 68, !7, i64 80, !6, i64 224, !6, i64 232, !6, i64 240, !12, i64 248}
!15 = !{!14, !6, i64 48}
!16 = distinct !{!16, !17}
!17 = !{!"llvm.loop.mustprogress"}
!18 = distinct !{!18, !17}


; 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 nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare float @llvm.fmuladd.f32(float, float, float) #0

; Function Attrs: nounwind
declare float @cabsf(<2 x float> noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
define dso_local noundef i32 @modemcf_arb_scale(ptr nocapture noundef readonly %0) local_unnamed_addr #2 {
  %2 = getelementptr inbounds i8, ptr %0, i64 8
  %3 = load i32, ptr %2, align 8, !tbaa !5
  %.not = icmp eq i32 %3, 0
  br i1 %.not, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %1
  %4 = getelementptr inbounds i8, ptr %0, i64 48
  br label %5

5:                                                ; preds = %.lr.ph, %5
  %indvars.iv = phi i64 [ 0, %.lr.ph ], [ %indvars.iv.next, %5 ]
  %.020 = phi float [ 0.000000e+00, %.lr.ph ], [ %10, %5 ]
  %6 = load ptr, ptr %4, align 8, !tbaa !11
  %7 = getelementptr inbounds { float, float }, ptr %6, i64 %indvars.iv
  %8 = load <2 x float>, ptr %7, align 4
  %9 = tail call float @cabsf(<2 x float> noundef %8) #4
  %10 = tail call float @llvm.fmuladd.f32(float %9, float %9, float %.020)
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %11 = load i32, ptr %2, align 8, !tbaa !5
  %12 = zext i32 %11 to i64
  %13 = icmp ult i64 %indvars.iv.next, %12
  br i1 %13, label %5, label %._crit_edge.loopexit, !llvm.loop !12

._crit_edge.loopexit:                             ; preds = %5
  %14 = uitofp i32 %11 to float
  %15 = fdiv float %10, %14
  br label %._crit_edge

._crit_edge:                                      ; preds = %._crit_edge.loopexit, %1
  %16 = phi float [ 0x7FF8000000000000, %1 ], [ %15, %._crit_edge.loopexit ]
  %17 = tail call float @sqrtf(float noundef %16) #4
  %18 = load i32, ptr %2, align 8, !tbaa !5
  %.not26 = icmp eq i32 %18, 0
  br i1 %.not26, label %._crit_edge25, label %.lr.ph24

.lr.ph24:                                         ; preds = %._crit_edge
  %19 = getelementptr inbounds i8, ptr %0, i64 48
  %20 = insertelement <2 x float> poison, float %17, i64 0
  %21 = shufflevector <2 x float> %20, <2 x float> poison, <2 x i32> zeroinitializer
  br label %22

22:                                               ; preds = %.lr.ph24, %22
  %indvars.iv30 = phi i64 [ 0, %.lr.ph24 ], [ %indvars.iv.next31, %22 ]
  %23 = load ptr, ptr %19, align 8, !tbaa !11
  %24 = getelementptr inbounds { float, float }, ptr %23, i64 %indvars.iv30
  %25 = load <2 x float>, ptr %24, align 4
  %26 = fdiv <2 x float> %25, %21
  store <2 x float> %26, ptr %24, align 4
  %indvars.iv.next31 = add nuw nsw i64 %indvars.iv30, 1
  %27 = load i32, ptr %2, align 8, !tbaa !5
  %28 = zext i32 %27 to i64
  %29 = icmp ult i64 %indvars.iv.next31, %28
  br i1 %29, label %22, label %._crit_edge25, !llvm.loop !14

._crit_edge25:                                    ; preds = %22, %._crit_edge
  ret i32 0
}

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

attributes #0 = { mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #1 = { 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 #2 = { nounwind uwtable "min-legal-vector-width"="64" "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 = { 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 #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, !7, i64 8}
!6 = !{!"modemcf_s", !7, i64 0, !7, i64 4, !7, i64 8, !8, i64 12, !10, i64 48, !7, i64 56, !8, i64 60, !8, i64 68, !8, i64 80, !10, i64 224, !10, i64 232, !10, i64 240, !7, i64 248}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"any pointer", !8, i64 0}
!11 = !{!6, !10, i64 48}
!12 = distinct !{!12, !13}
!13 = !{!"llvm.loop.mustprogress"}
!14 = distinct !{!14, !13}


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