; 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.cpfskdem_s = type { i32, i32, i32, float, float, i32, i32, i32, i32, ptr, %union.anon.7, i32, i32, { float, float } }
%union.anon.7 = type { %struct.anon.9 }
%struct.anon.9 = type { 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

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

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

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare float @llvm.round.f32(float) #2

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

13:                                               ; preds = %111, %2
  %14 = load i32, ptr %5, align 4, !tbaa !9
  %15 = load ptr, ptr %3, align 8, !tbaa !5
  %16 = getelementptr inbounds %struct.cpfskdem_s, ptr %15, i32 0, i32 1
  %17 = load i32, ptr %16, align 4, !tbaa !11
  %18 = icmp ult i32 %14, %17
  br i1 %18, label %19, label %114

19:                                               ; preds = %13
  %20 = load ptr, ptr %3, align 8, !tbaa !5
  %21 = getelementptr inbounds %struct.cpfskdem_s, ptr %20, i32 0, i32 10
  %22 = getelementptr inbounds %struct.anon.9, ptr %21, i32 0, i32 0
  %23 = load ptr, ptr %22, align 8, !tbaa !14
  %24 = load ptr, ptr %4, align 8, !tbaa !5
  %25 = load i32, ptr %5, align 4, !tbaa !9
  %26 = zext i32 %25 to i64
  %27 = getelementptr inbounds { float, float }, ptr %24, i64 %26
  %28 = getelementptr inbounds { float, float }, ptr %27, i32 0, i32 0
  %29 = load float, ptr %28, align 4
  %30 = getelementptr inbounds { float, float }, ptr %27, i32 0, i32 1
  %31 = load float, ptr %30, align 4
  %32 = getelementptr inbounds { float, float }, ptr %7, i32 0, i32 0
  %33 = getelementptr inbounds { float, float }, ptr %7, i32 0, i32 1
  store float %29, ptr %32, align 4
  store float %31, ptr %33, align 4
  %34 = load <2 x float>, ptr %7, align 4
  %35 = call i32 @firfilt_crcf_push(ptr noundef %23, <2 x float> noundef %34)
  %36 = load i32, ptr %5, align 4, !tbaa !9
  %37 = icmp eq i32 %36, 0
  br i1 %37, label %38, label %110

38:                                               ; preds = %19
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #5
  %39 = load ptr, ptr %3, align 8, !tbaa !5
  %40 = getelementptr inbounds %struct.cpfskdem_s, ptr %39, i32 0, i32 10
  %41 = getelementptr inbounds %struct.anon.9, ptr %40, i32 0, i32 0
  %42 = load ptr, ptr %41, align 8, !tbaa !14
  %43 = call i32 @firfilt_crcf_execute(ptr noundef %42, ptr noundef %8)
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #5
  %44 = load ptr, ptr %3, align 8, !tbaa !5
  %45 = getelementptr inbounds %struct.cpfskdem_s, ptr %44, i32 0, i32 13
  %46 = getelementptr inbounds { float, float }, ptr %45, i32 0, i32 0
  %47 = load float, ptr %46, align 8
  %48 = getelementptr inbounds { float, float }, ptr %45, i32 0, i32 1
  %49 = load float, ptr %48, align 4
  %50 = fneg float %49
  %51 = getelementptr inbounds { float, float }, ptr %8, i32 0, i32 0
  %52 = load float, ptr %51, align 4
  %53 = getelementptr inbounds { float, float }, ptr %8, i32 0, i32 1
  %54 = load float, ptr %53, align 4
  %55 = fmul float %47, %52
  %56 = fmul float %50, %54
  %57 = fmul float %47, %54
  %58 = fmul float %50, %52
  %59 = fsub float %55, %56
  %60 = fadd float %57, %58
  %61 = fcmp uno float %59, %59
  br i1 %61, label %62, label %70, !prof !15

62:                                               ; preds = %38
  %63 = fcmp uno float %60, %60
  br i1 %63, label %64, label %70, !prof !15

64:                                               ; preds = %62
  %65 = call <2 x float> @__mulsc3(float noundef %47, float noundef %50, float noundef %52, float noundef %54) #5
  store <2 x float> %65, ptr %10, align 4
  %66 = getelementptr inbounds { float, float }, ptr %10, i32 0, i32 0
  %67 = load float, ptr %66, align 4
  %68 = getelementptr inbounds { float, float }, ptr %10, i32 0, i32 1
  %69 = load float, ptr %68, align 4
  br label %70

70:                                               ; preds = %64, %62, %38
  %71 = phi float [ %59, %38 ], [ %59, %62 ], [ %67, %64 ]
  %72 = phi float [ %60, %38 ], [ %60, %62 ], [ %69, %64 ]
  %73 = getelementptr inbounds { float, float }, ptr %11, i32 0, i32 0
  %74 = getelementptr inbounds { float, float }, ptr %11, i32 0, i32 1
  store float %71, ptr %73, align 4
  store float %72, ptr %74, align 4
  %75 = load <2 x float>, ptr %11, align 4
  %76 = call float @cargf(<2 x float> noundef %75) #5
  %77 = fpext float %76 to double
  %78 = load ptr, ptr %3, align 8, !tbaa !5
  %79 = getelementptr inbounds %struct.cpfskdem_s, ptr %78, i32 0, i32 4
  %80 = load float, ptr %79, align 8, !tbaa !16
  %81 = fpext float %80 to double
  %82 = fmul double %81, 0x400921FB54442D18
  %83 = fdiv double %77, %82
  %84 = fptrunc double %83 to float
  store float %84, ptr %9, align 4, !tbaa !17
  call void @llvm.lifetime.start.p0(i64 4, ptr %12) #5
  %85 = load float, ptr %9, align 4, !tbaa !17
  %86 = fpext float %85 to double
  %87 = load ptr, ptr %3, align 8, !tbaa !5
  %88 = getelementptr inbounds %struct.cpfskdem_s, ptr %87, i32 0, i32 6
  %89 = load i32, ptr %88, align 8, !tbaa !18
  %90 = uitofp i32 %89 to double
  %91 = fsub double %90, 1.000000e+00
  %92 = fadd double %86, %91
  %93 = fmul double %92, 5.000000e-01
  %94 = fptrunc double %93 to float
  store float %94, ptr %12, align 4, !tbaa !17
  %95 = load float, ptr %12, align 4, !tbaa !17
  %96 = call float @llvm.round.f32(float %95)
  %97 = fptosi float %96 to i32
  %98 = load ptr, ptr %3, align 8, !tbaa !5
  %99 = getelementptr inbounds %struct.cpfskdem_s, ptr %98, i32 0, i32 6
  %100 = load i32, ptr %99, align 8, !tbaa !18
  %101 = urem i32 %97, %100
  store i32 %101, ptr %6, align 4, !tbaa !9
  %102 = getelementptr inbounds { float, float }, ptr %8, i32 0, i32 0
  %103 = load float, ptr %102, align 4
  %104 = getelementptr inbounds { float, float }, ptr %8, i32 0, i32 1
  %105 = load float, ptr %104, align 4
  %106 = load ptr, ptr %3, align 8, !tbaa !5
  %107 = getelementptr inbounds %struct.cpfskdem_s, ptr %106, i32 0, i32 13
  %108 = getelementptr inbounds { float, float }, ptr %107, i32 0, i32 0
  %109 = getelementptr inbounds { float, float }, ptr %107, i32 0, i32 1
  store float %103, ptr %108, align 8
  store float %105, ptr %109, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %12) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #5
  br label %110

110:                                              ; preds = %70, %19
  br label %111

111:                                              ; preds = %110
  %112 = load i32, ptr %5, align 4, !tbaa !9
  %113 = add i32 %112, 1
  store i32 %113, ptr %5, align 4, !tbaa !9
  br label %13, !llvm.loop !19

114:                                              ; preds = %13
  %115 = load i32, ptr %6, align 4, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #5
  ret i32 %115
}

declare i32 @firfilt_crcf_push(ptr noundef, <2 x float> noundef) #4

declare i32 @firfilt_crcf_execute(ptr noundef, ptr noundef) #4

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
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 = { "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 #5 = { 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, !10, i64 4}
!12 = !{!"cpfskdem_s", !10, i64 0, !10, i64 4, !10, i64 8, !13, i64 12, !13, i64 16, !10, i64 20, !10, i64 24, !10, i64 28, !10, i64 32, !6, i64 40, !7, i64 48, !10, i64 56, !10, i64 60, !7, i64 64}
!13 = !{!"float", !7, i64 0}
!14 = !{!7, !7, i64 0}
!15 = !{!"branch_weights", i32 1, i32 1048575}
!16 = !{!12, !13, i64 16}
!17 = !{!13, !13, i64 0}
!18 = !{!12, !10, i64 24}
!19 = distinct !{!19, !20}
!20 = !{!"llvm.loop.mustprogress"}


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

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

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

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

; Function Attrs: mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare float @llvm.round.f32(float) #2

; Function Attrs: nounwind uwtable
define dso_local i32 @cpfskdem_demodulate_noncoherent(ptr nocapture noundef %0, ptr nocapture noundef readonly %1) local_unnamed_addr #3 {
  %3 = alloca { float, float }, align 8
  %4 = getelementptr inbounds i8, ptr %0, i64 4
  %5 = load i32, ptr %4, align 4, !tbaa !5
  %.not = icmp eq i32 %5, 0
  br i1 %.not, label %._crit_edge, label %6

6:                                                ; preds = %2
  %7 = getelementptr inbounds i8, ptr %0, i64 48
  %8 = getelementptr inbounds i8, ptr %0, i64 64
  %9 = getelementptr inbounds i8, ptr %0, i64 16
  %10 = getelementptr inbounds i8, ptr %0, i64 24
  %11 = load ptr, ptr %7, align 8, !tbaa !12
  %12 = load <2 x float>, ptr %1, align 4
  %13 = tail call i32 @firfilt_crcf_push(ptr noundef %11, <2 x float> noundef %12) #5
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %3) #5
  %14 = load ptr, ptr %7, align 8, !tbaa !12
  %15 = call i32 @firfilt_crcf_execute(ptr noundef %14, ptr noundef nonnull %3) #5
  %16 = load <2 x float>, ptr %8, align 8
  %17 = extractelement <2 x float> %16, i64 1
  %18 = fneg float %17
  %19 = load <2 x float>, ptr %3, align 8
  %20 = shufflevector <2 x float> %19, <2 x float> poison, <2 x i32> <i32 1, i32 0>
  %21 = fmul <2 x float> %16, %19
  %shift = shufflevector <2 x float> %21, <2 x float> poison, <2 x i32> <i32 1, i32 poison>
  %22 = fadd <2 x float> %21, %shift
  %23 = extractelement <2 x float> %22, i64 0
  %24 = fmul <2 x float> %16, %20
  %shift25 = shufflevector <2 x float> %24, <2 x float> poison, <2 x i32> <i32 1, i32 poison>
  %25 = fsub <2 x float> %24, %shift25
  %26 = extractelement <2 x float> %25, i64 0
  %27 = fcmp uno float %23, 0.000000e+00
  br i1 %27, label %28, label %35, !prof !13

28:                                               ; preds = %6
  %29 = fcmp uno float %26, 0.000000e+00
  br i1 %29, label %30, label %35, !prof !13

30:                                               ; preds = %28
  %31 = extractelement <2 x float> %16, i64 0
  %32 = extractelement <2 x float> %19, i64 0
  %33 = extractelement <2 x float> %19, i64 1
  %34 = call <2 x float> @__mulsc3(float noundef %31, float noundef %18, float noundef %32, float noundef %33) #5
  %.sroa.02.0.vec.extract.peel = extractelement <2 x float> %34, i64 0
  %.sroa.02.4.vec.extract.peel = extractelement <2 x float> %34, i64 1
  br label %35

35:                                               ; preds = %6, %28, %30
  %36 = phi float [ %23, %6 ], [ %23, %28 ], [ %.sroa.02.0.vec.extract.peel, %30 ]
  %37 = phi float [ %26, %6 ], [ %26, %28 ], [ %.sroa.02.4.vec.extract.peel, %30 ]
  %.sroa.0.0.vec.insert.peel = insertelement <2 x float> poison, float %36, i64 0
  %.sroa.0.4.vec.insert.peel = insertelement <2 x float> %.sroa.0.0.vec.insert.peel, float %37, i64 1
  %38 = call float @cargf(<2 x float> noundef %.sroa.0.4.vec.insert.peel) #5
  %39 = fpext float %38 to double
  %40 = load float, ptr %9, align 8, !tbaa !14
  %41 = fpext float %40 to double
  %42 = fmul double %41, 0x400921FB54442D18
  %43 = fdiv double %39, %42
  %44 = fptrunc double %43 to float
  %45 = fpext float %44 to double
  %46 = load i32, ptr %10, align 8, !tbaa !15
  %47 = uitofp i32 %46 to double
  %48 = fadd double %47, -1.000000e+00
  %49 = fadd double %48, %45
  %50 = fmul double %49, 5.000000e-01
  %51 = fptrunc double %50 to float
  %52 = call float @llvm.round.f32(float %51)
  %53 = fptosi float %52 to i32
  %54 = urem i32 %53, %46
  %55 = load <2 x float>, ptr %3, align 8
  store <2 x float> %55, ptr %8, align 8
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %3) #5
  %56 = load i32, ptr %4, align 4, !tbaa !5
  %57 = icmp ugt i32 %56, 1
  br i1 %57, label %.peel.next, label %._crit_edge

.peel.next:                                       ; preds = %35, %.peel.next
  %indvars.iv = phi i64 [ %indvars.iv.next, %.peel.next ], [ 1, %35 ]
  %58 = load ptr, ptr %7, align 8, !tbaa !12
  %59 = getelementptr inbounds { float, float }, ptr %1, i64 %indvars.iv
  %60 = load <2 x float>, ptr %59, align 4
  %61 = call i32 @firfilt_crcf_push(ptr noundef %58, <2 x float> noundef %60) #5
  %.pre = load i32, ptr %4, align 4, !tbaa !5
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %62 = zext i32 %.pre to i64
  %63 = icmp ult i64 %indvars.iv.next, %62
  br i1 %63, label %.peel.next, label %._crit_edge, !llvm.loop !16

._crit_edge:                                      ; preds = %.peel.next, %35, %2
  %.019.lcssa = phi i32 [ 0, %2 ], [ %54, %35 ], [ %54, %.peel.next ]
  ret i32 %.019.lcssa
}

declare i32 @firfilt_crcf_push(ptr noundef, <2 x float> noundef) local_unnamed_addr #4

declare i32 @firfilt_crcf_execute(ptr noundef, ptr noundef) local_unnamed_addr #4

attributes #0 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = { mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none) }
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 = { "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 #5 = { 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 4}
!6 = !{!"cpfskdem_s", !7, i64 0, !7, i64 4, !7, i64 8, !10, i64 12, !10, i64 16, !7, i64 20, !7, i64 24, !7, i64 28, !7, i64 32, !11, i64 40, !8, i64 48, !7, i64 56, !7, i64 60, !8, i64 64}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"float", !8, i64 0}
!11 = !{!"any pointer", !8, i64 0}
!12 = !{!8, !8, i64 0}
!13 = !{!"branch_weights", i32 1, i32 1048575}
!14 = !{!6, !10, i64 16}
!15 = !{!6, !7, i64 24}
!16 = distinct !{!16, !17, !18}
!17 = !{!"llvm.loop.mustprogress"}
!18 = !{!"llvm.loop.peeled.count", i32 1}


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