; 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 }

declare <2 x float> @__mulsc3(float, float, float, float)

; Function Attrs: nounwind uwtable
define dso_local float @modemcf_get_demodulator_phase_error(ptr noundef %0) #0 {
  %2 = alloca ptr, align 8
  %3 = alloca { float, float }, align 4
  store ptr %0, ptr %2, align 8, !tbaa !5
  %4 = load ptr, ptr %2, align 8, !tbaa !5
  %5 = getelementptr inbounds %struct.modemcf_s, ptr %4, i32 0, i32 6
  %6 = getelementptr inbounds { float, float }, ptr %5, i32 0, i32 0
  %7 = load float, ptr %6, align 4
  %8 = getelementptr inbounds { float, float }, ptr %5, i32 0, i32 1
  %9 = load float, ptr %8, align 4
  %10 = load ptr, ptr %2, align 8, !tbaa !5
  %11 = getelementptr inbounds %struct.modemcf_s, ptr %10, i32 0, i32 7
  %12 = getelementptr inbounds { float, float }, ptr %11, i32 0, i32 0
  %13 = load float, ptr %12, align 4
  %14 = getelementptr inbounds { float, float }, ptr %11, i32 0, i32 1
  %15 = load float, ptr %14, align 4
  %16 = fneg float %15
  %17 = fmul float %7, %13
  %18 = fmul float %9, %16
  %19 = fmul float %7, %16
  %20 = fmul float %9, %13
  %21 = fsub float %17, %18
  %22 = fadd float %19, %20
  %23 = fcmp uno float %21, %21
  br i1 %23, label %24, label %32, !prof !9

24:                                               ; preds = %1
  %25 = fcmp uno float %22, %22
  br i1 %25, label %26, label %32, !prof !9

26:                                               ; preds = %24
  %27 = call <2 x float> @__mulsc3(float noundef %7, float noundef %9, float noundef %13, float noundef %16) #1
  store <2 x float> %27, ptr %3, align 4
  %28 = getelementptr inbounds { float, float }, ptr %3, i32 0, i32 0
  %29 = load float, ptr %28, align 4
  %30 = getelementptr inbounds { float, float }, ptr %3, i32 0, i32 1
  %31 = load float, ptr %30, align 4
  br label %32

32:                                               ; preds = %26, %24, %1
  %33 = phi float [ %21, %1 ], [ %21, %24 ], [ %29, %26 ]
  %34 = phi float [ %22, %1 ], [ %22, %24 ], [ %31, %26 ]
  ret float %34
}

attributes #0 = { 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 #1 = { 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 = !{!"branch_weights", i32 1, i32 1048575}


; 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"

declare <2 x float> @__mulsc3(float, float, float, float) local_unnamed_addr

; Function Attrs: nounwind uwtable
define dso_local float @modemcf_get_demodulator_phase_error(ptr nocapture noundef readonly %0) local_unnamed_addr #0 {
  %2 = getelementptr inbounds i8, ptr %0, i64 60
  %3 = getelementptr inbounds i8, ptr %0, i64 68
  %4 = load <2 x float>, ptr %2, align 4
  %5 = load <2 x float>, ptr %3, align 4
  %6 = extractelement <2 x float> %5, i64 1
  %7 = fneg float %6
  %8 = extractelement <2 x float> %4, i64 1
  %9 = extractelement <2 x float> %5, i64 0
  %10 = fmul float %8, %9
  %11 = fmul <2 x float> %4, %5
  %shift = shufflevector <2 x float> %11, <2 x float> poison, <2 x i32> <i32 1, i32 poison>
  %12 = fadd <2 x float> %11, %shift
  %13 = extractelement <2 x float> %12, i64 0
  %14 = extractelement <2 x float> %4, i64 0
  %15 = fmul float %14, %6
  %16 = fsub float %10, %15
  %17 = fcmp uno float %13, 0.000000e+00
  br i1 %17, label %18, label %22, !prof !5

18:                                               ; preds = %1
  %19 = fcmp uno float %16, 0.000000e+00
  br i1 %19, label %20, label %22, !prof !5

20:                                               ; preds = %18
  %21 = tail call <2 x float> @__mulsc3(float noundef %14, float noundef %8, float noundef %9, float noundef %7) #1
  %.sroa.0.4.vec.extract = extractelement <2 x float> %21, i64 1
  br label %22

22:                                               ; preds = %20, %18, %1
  %23 = phi float [ %16, %1 ], [ %16, %18 ], [ %.sroa.0.4.vec.extract, %20 ]
  ret float %23
}

attributes #0 = { 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 #1 = { 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 = !{!"branch_weights", i32 1, i32 1048575}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,InstCombinePass,PostOrderFunctionAttrsPass,ReassociatePass,SLPVectorizerPass,SROAPass,TailCallElimPass,VectorCombinePass