; 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: nounwind
declare float @cabsf(<2 x float> noundef) #1

; Function Attrs: nounwind uwtable
declare dso_local i32 @modemcf_modulate_arb(ptr noundef, i32 noundef, ptr noundef) #2

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

12:                                               ; preds = %49, %3
  %13 = load i32, ptr %7, align 4, !tbaa !9
  %14 = load ptr, ptr %5, align 8, !tbaa !5
  %15 = getelementptr inbounds %struct.modemcf_s, ptr %14, i32 0, i32 2
  %16 = load i32, ptr %15, align 8, !tbaa !13
  %17 = icmp ult i32 %13, %16
  br i1 %17, label %18, label %52

18:                                               ; preds = %12
  %19 = getelementptr inbounds { float, float }, ptr %4, i32 0, i32 0
  %20 = load float, ptr %19, align 4
  %21 = getelementptr inbounds { float, float }, ptr %4, i32 0, i32 1
  %22 = load float, ptr %21, align 4
  %23 = load ptr, ptr %5, align 8, !tbaa !5
  %24 = getelementptr inbounds %struct.modemcf_s, ptr %23, i32 0, i32 4
  %25 = load ptr, ptr %24, align 8, !tbaa !15
  %26 = load i32, ptr %7, align 4, !tbaa !9
  %27 = zext i32 %26 to i64
  %28 = getelementptr inbounds { float, float }, ptr %25, i64 %27
  %29 = getelementptr inbounds { float, float }, ptr %28, i32 0, i32 0
  %30 = load float, ptr %29, align 4
  %31 = getelementptr inbounds { float, float }, ptr %28, i32 0, i32 1
  %32 = load float, ptr %31, align 4
  %33 = fsub float %20, %30
  %34 = fsub float %22, %32
  %35 = getelementptr inbounds { float, float }, ptr %11, i32 0, i32 0
  %36 = getelementptr inbounds { float, float }, ptr %11, i32 0, i32 1
  store float %33, ptr %35, align 4
  store float %34, ptr %36, align 4
  %37 = load <2 x float>, ptr %11, align 4
  %38 = call float @cabsf(<2 x float> noundef %37) #4
  store float %38, ptr %9, align 4, !tbaa !11
  %39 = load i32, ptr %7, align 4, !tbaa !9
  %40 = icmp eq i32 %39, 0
  br i1 %40, label %45, label %41

41:                                               ; preds = %18
  %42 = load float, ptr %9, align 4, !tbaa !11
  %43 = load float, ptr %10, align 4, !tbaa !11
  %44 = fcmp olt float %42, %43
  br i1 %44, label %45, label %48

45:                                               ; preds = %41, %18
  %46 = load float, ptr %9, align 4, !tbaa !11
  store float %46, ptr %10, align 4, !tbaa !11
  %47 = load i32, ptr %7, align 4, !tbaa !9
  store i32 %47, ptr %8, align 4, !tbaa !9
  br label %48

48:                                               ; preds = %45, %41
  br label %49

49:                                               ; preds = %48
  %50 = load i32, ptr %7, align 4, !tbaa !9
  %51 = add i32 %50, 1
  store i32 %51, ptr %7, align 4, !tbaa !9
  br label %12, !llvm.loop !16

52:                                               ; preds = %12
  %53 = load i32, ptr %8, align 4, !tbaa !9
  %54 = load ptr, ptr %6, align 8, !tbaa !5
  store i32 %53, ptr %54, align 4, !tbaa !9
  %55 = load ptr, ptr %5, align 8, !tbaa !5
  %56 = load ptr, ptr %6, align 8, !tbaa !5
  %57 = load i32, ptr %56, align 4, !tbaa !9
  %58 = load ptr, ptr %5, align 8, !tbaa !5
  %59 = getelementptr inbounds %struct.modemcf_s, ptr %58, i32 0, i32 7
  %60 = call i32 @modemcf_modulate_arb(ptr noundef %55, i32 noundef %57, ptr noundef %59)
  %61 = getelementptr inbounds { float, float }, ptr %4, i32 0, i32 0
  %62 = load float, ptr %61, align 4
  %63 = getelementptr inbounds { float, float }, ptr %4, i32 0, i32 1
  %64 = load float, ptr %63, align 4
  %65 = load ptr, ptr %5, align 8, !tbaa !5
  %66 = getelementptr inbounds %struct.modemcf_s, ptr %65, i32 0, i32 6
  %67 = getelementptr inbounds { float, float }, ptr %66, i32 0, i32 0
  %68 = getelementptr inbounds { float, float }, ptr %66, i32 0, i32 1
  store float %62, ptr %67, align 4
  store float %64, ptr %68, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #4
  ret i32 0
}

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 = { 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 #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 = !{!"int", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"float", !7, i64 0}
!13 = !{!14, !10, i64 8}
!14 = !{!"modemcf_s", !10, i64 0, !10, i64 4, !10, i64 8, !7, i64 12, !6, i64 48, !10, i64 56, !7, i64 60, !7, i64 68, !7, i64 80, !6, i64 224, !6, i64 232, !6, i64 240, !10, i64 248}
!15 = !{!14, !6, i64 48}
!16 = distinct !{!16, !17}
!17 = !{!"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: nounwind
declare float @cabsf(<2 x float> noundef) local_unnamed_addr #0

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

; Function Attrs: nounwind uwtable
define dso_local noundef i32 @modemcf_demodulate_arb(ptr noundef %0, <2 x float> noundef %1, ptr nocapture noundef writeonly %2) local_unnamed_addr #2 {
  %4 = getelementptr inbounds i8, ptr %0, i64 8
  %5 = load i32, ptr %4, align 8, !tbaa !5
  %.not = icmp eq i32 %5, 0
  br i1 %.not, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %3
  %6 = getelementptr inbounds i8, ptr %0, i64 48
  %7 = load ptr, ptr %6, align 8, !tbaa !11
  %8 = load <2 x float>, ptr %7, align 4
  %9 = fsub <2 x float> %1, %8
  %10 = tail call float @cabsf(<2 x float> noundef %9) #3
  %11 = load i32, ptr %4, align 8, !tbaa !5
  %12 = icmp ugt i32 %11, 1
  br i1 %12, label %.peel.next, label %._crit_edge

.peel.next:                                       ; preds = %.lr.ph, %.peel.next
  %indvars.iv = phi i64 [ %indvars.iv.next, %.peel.next ], [ 1, %.lr.ph ]
  %.026 = phi float [ %.1, %.peel.next ], [ %10, %.lr.ph ]
  %.02224 = phi i32 [ %.123, %.peel.next ], [ 0, %.lr.ph ]
  %13 = load ptr, ptr %6, align 8, !tbaa !11
  %14 = getelementptr inbounds { float, float }, ptr %13, i64 %indvars.iv
  %15 = load <2 x float>, ptr %14, align 4
  %16 = fsub <2 x float> %1, %15
  %17 = tail call float @cabsf(<2 x float> noundef %16) #3
  %18 = fcmp olt float %17, %.026
  %19 = trunc nuw i64 %indvars.iv to i32
  %.123 = select i1 %18, i32 %19, i32 %.02224
  %.1 = select i1 %18, float %17, float %.026
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %20 = load i32, ptr %4, align 8, !tbaa !5
  %21 = zext i32 %20 to i64
  %22 = icmp ult i64 %indvars.iv.next, %21
  br i1 %22, label %.peel.next, label %._crit_edge, !llvm.loop !12

._crit_edge:                                      ; preds = %.peel.next, %3, %.lr.ph
  %.022.lcssa = phi i32 [ 0, %.lr.ph ], [ 0, %3 ], [ %.123, %.peel.next ]
  store i32 %.022.lcssa, ptr %2, align 4, !tbaa !15
  %23 = getelementptr inbounds i8, ptr %0, i64 68
  %24 = tail call i32 @modemcf_modulate_arb(ptr noundef nonnull %0, i32 noundef %.022.lcssa, ptr noundef nonnull %23)
  %25 = getelementptr inbounds i8, ptr %0, i64 60
  store <2 x float> %1, ptr %25, align 4
  ret i32 0
}

attributes #0 = { 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 #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 = { 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 = { 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, !14}
!13 = !{!"llvm.loop.mustprogress"}
!14 = !{!"llvm.loop.peeled.count", i32 1}
!15 = !{!7, !7, i64 0}


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