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

; 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.fskdem_s = type { i32, i32, float, i32, float, i32, ptr, ptr, ptr, ptr, 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: nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memmove.p0.p0.i64(ptr nocapture writeonly, ptr nocapture readonly, i64, i1 immarg) #1

; Function Attrs: nounwind uwtable
define dso_local i32 @fskdem_demodulate(ptr noundef %0, ptr noundef %1) #2 {
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca float, align 4
  %6 = alloca i32, align 4
  %7 = alloca float, align 4
  %8 = alloca { float, float }, align 4
  store ptr %0, ptr %3, align 8, !tbaa !5
  store ptr %1, ptr %4, align 8, !tbaa !5
  %9 = load ptr, ptr %3, align 8, !tbaa !5
  %10 = getelementptr inbounds %struct.fskdem_s, ptr %9, i32 0, i32 6
  %11 = load ptr, ptr %10, align 8, !tbaa !9
  %12 = load ptr, ptr %4, align 8, !tbaa !5
  %13 = load ptr, ptr %3, align 8, !tbaa !5
  %14 = getelementptr inbounds %struct.fskdem_s, ptr %13, i32 0, i32 1
  %15 = load i32, ptr %14, align 4, !tbaa !13
  %16 = zext i32 %15 to i64
  %17 = mul i64 %16, 8
  call void @llvm.memmove.p0.p0.i64(ptr align 4 %11, ptr align 4 %12, i64 %17, i1 false)
  %18 = load ptr, ptr %3, align 8, !tbaa !5
  %19 = getelementptr inbounds %struct.fskdem_s, ptr %18, i32 0, i32 8
  %20 = load ptr, ptr %19, align 8, !tbaa !14
  %21 = call i32 @fft_execute(ptr noundef %20)
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #5
  store float 0.000000e+00, ptr %5, align 4, !tbaa !15
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #5
  store i32 0, ptr %6, align 4, !tbaa !16
  store i32 0, ptr %6, align 4, !tbaa !16
  br label %22

22:                                               ; preds = %61, %2
  %23 = load i32, ptr %6, align 4, !tbaa !16
  %24 = load ptr, ptr %3, align 8, !tbaa !5
  %25 = getelementptr inbounds %struct.fskdem_s, ptr %24, i32 0, i32 3
  %26 = load i32, ptr %25, align 4, !tbaa !17
  %27 = icmp ult i32 %23, %26
  br i1 %27, label %28, label %64

28:                                               ; preds = %22
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #5
  %29 = load ptr, ptr %3, align 8, !tbaa !5
  %30 = getelementptr inbounds %struct.fskdem_s, ptr %29, i32 0, i32 7
  %31 = load ptr, ptr %30, align 8, !tbaa !18
  %32 = load ptr, ptr %3, align 8, !tbaa !5
  %33 = getelementptr inbounds %struct.fskdem_s, ptr %32, i32 0, i32 9
  %34 = load ptr, ptr %33, align 8, !tbaa !19
  %35 = load i32, ptr %6, align 4, !tbaa !16
  %36 = zext i32 %35 to i64
  %37 = getelementptr inbounds i32, ptr %34, i64 %36
  %38 = load i32, ptr %37, align 4, !tbaa !16
  %39 = zext i32 %38 to i64
  %40 = getelementptr inbounds { float, float }, ptr %31, i64 %39
  %41 = getelementptr inbounds { float, float }, ptr %40, i32 0, i32 0
  %42 = load float, ptr %41, align 4
  %43 = getelementptr inbounds { float, float }, ptr %40, i32 0, i32 1
  %44 = load float, ptr %43, align 4
  %45 = getelementptr inbounds { float, float }, ptr %8, i32 0, i32 0
  %46 = getelementptr inbounds { float, float }, ptr %8, i32 0, i32 1
  store float %42, ptr %45, align 4
  store float %44, ptr %46, align 4
  %47 = load <2 x float>, ptr %8, align 4
  %48 = call float @cabsf(<2 x float> noundef %47) #5
  store float %48, ptr %7, align 4, !tbaa !15
  %49 = load i32, ptr %6, align 4, !tbaa !16
  %50 = icmp eq i32 %49, 0
  br i1 %50, label %55, label %51

51:                                               ; preds = %28
  %52 = load float, ptr %7, align 4, !tbaa !15
  %53 = load float, ptr %5, align 4, !tbaa !15
  %54 = fcmp ogt float %52, %53
  br i1 %54, label %55, label %60

55:                                               ; preds = %51, %28
  %56 = load i32, ptr %6, align 4, !tbaa !16
  %57 = load ptr, ptr %3, align 8, !tbaa !5
  %58 = getelementptr inbounds %struct.fskdem_s, ptr %57, i32 0, i32 10
  store i32 %56, ptr %58, align 8, !tbaa !20
  %59 = load float, ptr %7, align 4, !tbaa !15
  store float %59, ptr %5, align 4, !tbaa !15
  br label %60

60:                                               ; preds = %55, %51
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #5
  br label %61

61:                                               ; preds = %60
  %62 = load i32, ptr %6, align 4, !tbaa !16
  %63 = add i32 %62, 1
  store i32 %63, ptr %6, align 4, !tbaa !16
  br label %22, !llvm.loop !21

64:                                               ; preds = %22
  %65 = load ptr, ptr %3, align 8, !tbaa !5
  %66 = getelementptr inbounds %struct.fskdem_s, ptr %65, i32 0, i32 10
  %67 = load i32, ptr %66, align 8, !tbaa !20
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #5
  ret i32 %67
}

declare i32 @fft_execute(ptr noundef) #3

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

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
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 = { "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 "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, !6, i64 24}
!10 = !{!"fskdem_s", !11, i64 0, !11, i64 4, !12, i64 8, !11, i64 12, !12, i64 16, !11, i64 20, !6, i64 24, !6, i64 32, !6, i64 40, !6, i64 48, !11, i64 56}
!11 = !{!"int", !7, i64 0}
!12 = !{!"float", !7, i64 0}
!13 = !{!10, !11, i64 4}
!14 = !{!10, !6, i64 40}
!15 = !{!12, !12, i64 0}
!16 = !{!11, !11, i64 0}
!17 = !{!10, !11, i64 12}
!18 = !{!10, !6, i64 32}
!19 = !{!10, !6, i64 48}
!20 = !{!10, !11, i64 56}
!21 = distinct !{!21, !22}
!22 = !{!"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 nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memmove.p0.p0.i64(ptr nocapture writeonly, ptr nocapture readonly, i64, i1 immarg) #0

; Function Attrs: nounwind uwtable
define dso_local i32 @fskdem_demodulate(ptr nocapture noundef %0, ptr nocapture noundef readonly %1) local_unnamed_addr #1 {
  %3 = getelementptr inbounds i8, ptr %0, i64 24
  %4 = load ptr, ptr %3, align 8, !tbaa !5
  %5 = getelementptr inbounds i8, ptr %0, i64 4
  %6 = load i32, ptr %5, align 4, !tbaa !12
  %7 = zext i32 %6 to i64
  %8 = shl nuw nsw i64 %7, 3
  tail call void @llvm.memmove.p0.p0.i64(ptr align 4 %4, ptr align 4 %1, i64 %8, i1 false)
  %9 = getelementptr inbounds i8, ptr %0, i64 40
  %10 = load ptr, ptr %9, align 8, !tbaa !13
  %11 = tail call i32 @fft_execute(ptr noundef %10) #4
  %12 = getelementptr inbounds i8, ptr %0, i64 12
  %13 = load i32, ptr %12, align 4, !tbaa !14
  %.not = icmp eq i32 %13, 0
  br i1 %.not, label %._crit_edge, label %14

14:                                               ; preds = %2
  %15 = getelementptr inbounds i8, ptr %0, i64 32
  %16 = getelementptr inbounds i8, ptr %0, i64 48
  %17 = getelementptr inbounds i8, ptr %0, i64 56
  %18 = load ptr, ptr %15, align 8, !tbaa !15
  %19 = load ptr, ptr %16, align 8, !tbaa !16
  %20 = load i32, ptr %19, align 4, !tbaa !17
  %21 = zext i32 %20 to i64
  %22 = getelementptr inbounds { float, float }, ptr %18, i64 %21
  %23 = load <2 x float>, ptr %22, align 4
  %24 = tail call float @cabsf(<2 x float> noundef %23) #4
  store i32 0, ptr %17, align 8, !tbaa !18
  %25 = load i32, ptr %12, align 4, !tbaa !14
  %26 = icmp ugt i32 %25, 1
  br i1 %26, label %.peel.next, label %._crit_edge

.peel.next:                                       ; preds = %14, %38
  %indvars.iv = phi i64 [ %indvars.iv.next, %38 ], [ 1, %14 ]
  %.019 = phi float [ %.1, %38 ], [ %24, %14 ]
  %27 = load ptr, ptr %15, align 8, !tbaa !15
  %28 = load ptr, ptr %16, align 8, !tbaa !16
  %29 = getelementptr inbounds i32, ptr %28, i64 %indvars.iv
  %30 = load i32, ptr %29, align 4, !tbaa !17
  %31 = zext i32 %30 to i64
  %32 = getelementptr inbounds { float, float }, ptr %27, i64 %31
  %33 = load <2 x float>, ptr %32, align 4
  %34 = tail call float @cabsf(<2 x float> noundef %33) #4
  %35 = fcmp ogt float %34, %.019
  br i1 %35, label %36, label %38

36:                                               ; preds = %.peel.next
  %37 = trunc nuw i64 %indvars.iv to i32
  store i32 %37, ptr %17, align 8, !tbaa !18
  br label %38

38:                                               ; preds = %.peel.next, %36
  %.1 = phi float [ %34, %36 ], [ %.019, %.peel.next ]
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %39 = load i32, ptr %12, align 4, !tbaa !14
  %40 = zext i32 %39 to i64
  %41 = icmp ult i64 %indvars.iv.next, %40
  br i1 %41, label %.peel.next, label %._crit_edge, !llvm.loop !19

._crit_edge:                                      ; preds = %38, %14, %2
  %42 = getelementptr inbounds i8, ptr %0, i64 56
  %43 = load i32, ptr %42, align 8, !tbaa !18
  ret i32 %43
}

declare i32 @fft_execute(ptr noundef) local_unnamed_addr #2

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

attributes #0 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 #2 = { "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 "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, !11, i64 24}
!6 = !{!"fskdem_s", !7, i64 0, !7, i64 4, !10, i64 8, !7, i64 12, !10, i64 16, !7, i64 20, !11, i64 24, !11, i64 32, !11, i64 40, !11, i64 48, !7, i64 56}
!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 = !{!6, !7, i64 4}
!13 = !{!6, !11, i64 40}
!14 = !{!6, !7, i64 12}
!15 = !{!6, !11, i64 32}
!16 = !{!6, !11, i64 48}
!17 = !{!7, !7, i64 0}
!18 = !{!6, !7, i64 56}
!19 = distinct !{!19, !20, !21}
!20 = !{!"llvm.loop.mustprogress"}
!21 = !{!"llvm.loop.peeled.count", i32 1}


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