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

; 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.gmskdem_s = type { i32, i32, float, i32, ptr, ptr, { float, float }, 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: nounwind uwtable
define dso_local i32 @gmskdem_demodulate(ptr noundef %0, ptr noundef %1, ptr noundef %2) #1 {
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca i32, align 4
  %8 = alloca float, align 4
  %9 = alloca float, align 4
  %10 = alloca { float, float }, align 4
  %11 = alloca { float, float }, align 4
  store ptr %0, ptr %4, align 8, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !5
  store ptr %2, ptr %6, align 8, !tbaa !5
  %12 = load ptr, ptr %4, align 8, !tbaa !5
  %13 = getelementptr inbounds %struct.gmskdem_s, ptr %12, i32 0, i32 7
  %14 = load i32, ptr %13, align 8, !tbaa !9
  %15 = add i32 %14, 1
  store i32 %15, ptr %13, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #4
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #4
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #4
  store i32 0, ptr %7, align 4, !tbaa !13
  br label %16

16:                                               ; preds = %85, %3
  %17 = load i32, ptr %7, align 4, !tbaa !13
  %18 = load ptr, ptr %4, align 8, !tbaa !5
  %19 = getelementptr inbounds %struct.gmskdem_s, ptr %18, i32 0, i32 0
  %20 = load i32, ptr %19, align 8, !tbaa !14
  %21 = icmp ult i32 %17, %20
  br i1 %21, label %22, label %88

22:                                               ; preds = %16
  %23 = load ptr, ptr %4, align 8, !tbaa !5
  %24 = getelementptr inbounds %struct.gmskdem_s, ptr %23, i32 0, i32 6
  %25 = getelementptr inbounds { float, float }, ptr %24, i32 0, i32 0
  %26 = load float, ptr %25, align 8
  %27 = getelementptr inbounds { float, float }, ptr %24, i32 0, i32 1
  %28 = load float, ptr %27, align 4
  %29 = fneg float %28
  %30 = load ptr, ptr %5, align 8, !tbaa !5
  %31 = load i32, ptr %7, align 4, !tbaa !13
  %32 = zext i32 %31 to i64
  %33 = getelementptr inbounds { float, float }, ptr %30, i64 %32
  %34 = getelementptr inbounds { float, float }, ptr %33, i32 0, i32 0
  %35 = load float, ptr %34, align 4
  %36 = getelementptr inbounds { float, float }, ptr %33, i32 0, i32 1
  %37 = load float, ptr %36, align 4
  %38 = fmul float %26, %35
  %39 = fmul float %29, %37
  %40 = fmul float %26, %37
  %41 = fmul float %29, %35
  %42 = fsub float %38, %39
  %43 = fadd float %40, %41
  %44 = fcmp uno float %42, %42
  br i1 %44, label %45, label %53, !prof !15

45:                                               ; preds = %22
  %46 = fcmp uno float %43, %43
  br i1 %46, label %47, label %53, !prof !15

47:                                               ; preds = %45
  %48 = call <2 x float> @__mulsc3(float noundef %26, float noundef %29, float noundef %35, float noundef %37) #4
  store <2 x float> %48, ptr %10, align 4
  %49 = getelementptr inbounds { float, float }, ptr %10, i32 0, i32 0
  %50 = load float, ptr %49, align 4
  %51 = getelementptr inbounds { float, float }, ptr %10, i32 0, i32 1
  %52 = load float, ptr %51, align 4
  br label %53

53:                                               ; preds = %47, %45, %22
  %54 = phi float [ %42, %22 ], [ %42, %45 ], [ %50, %47 ]
  %55 = phi float [ %43, %22 ], [ %43, %45 ], [ %52, %47 ]
  %56 = getelementptr inbounds { float, float }, ptr %11, i32 0, i32 0
  %57 = getelementptr inbounds { float, float }, ptr %11, i32 0, i32 1
  store float %54, ptr %56, align 4
  store float %55, ptr %57, align 4
  %58 = load <2 x float>, ptr %11, align 4
  %59 = call float @cargf(<2 x float> noundef %58) #4
  store float %59, ptr %8, align 4, !tbaa !16
  %60 = load ptr, ptr %5, align 8, !tbaa !5
  %61 = load i32, ptr %7, align 4, !tbaa !13
  %62 = zext i32 %61 to i64
  %63 = getelementptr inbounds { float, float }, ptr %60, i64 %62
  %64 = getelementptr inbounds { float, float }, ptr %63, i32 0, i32 0
  %65 = load float, ptr %64, align 4
  %66 = getelementptr inbounds { float, float }, ptr %63, i32 0, i32 1
  %67 = load float, ptr %66, align 4
  %68 = load ptr, ptr %4, align 8, !tbaa !5
  %69 = getelementptr inbounds %struct.gmskdem_s, ptr %68, i32 0, i32 6
  %70 = getelementptr inbounds { float, float }, ptr %69, i32 0, i32 0
  %71 = getelementptr inbounds { float, float }, ptr %69, i32 0, i32 1
  store float %65, ptr %70, align 8
  store float %67, ptr %71, align 4
  %72 = load ptr, ptr %4, align 8, !tbaa !5
  %73 = getelementptr inbounds %struct.gmskdem_s, ptr %72, i32 0, i32 5
  %74 = load ptr, ptr %73, align 8, !tbaa !17
  %75 = load float, ptr %8, align 4, !tbaa !16
  %76 = call i32 @firfilt_rrrf_push(ptr noundef %74, float noundef %75)
  %77 = load i32, ptr %7, align 4, !tbaa !13
  %78 = icmp ne i32 %77, 0
  br i1 %78, label %79, label %80

79:                                               ; preds = %53
  br label %85

80:                                               ; preds = %53
  %81 = load ptr, ptr %4, align 8, !tbaa !5
  %82 = getelementptr inbounds %struct.gmskdem_s, ptr %81, i32 0, i32 5
  %83 = load ptr, ptr %82, align 8, !tbaa !17
  %84 = call i32 @firfilt_rrrf_execute(ptr noundef %83, ptr noundef %9)
  br label %85

85:                                               ; preds = %80, %79
  %86 = load i32, ptr %7, align 4, !tbaa !13
  %87 = add i32 %86, 1
  store i32 %87, ptr %7, align 4, !tbaa !13
  br label %16, !llvm.loop !18

88:                                               ; preds = %16
  %89 = load float, ptr %9, align 4, !tbaa !16
  %90 = fcmp ogt float %89, 0.000000e+00
  %91 = zext i1 %90 to i64
  %92 = select i1 %90, i32 1, i32 0
  %93 = load ptr, ptr %6, align 8, !tbaa !5
  store i32 %92, ptr %93, align 4, !tbaa !13
  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
}

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

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

declare i32 @firfilt_rrrf_push(ptr noundef, float noundef) #3

declare i32 @firfilt_rrrf_execute(ptr noundef, ptr noundef) #3

attributes #0 = { nocallback nofree nosync 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 = { 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 = { "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, !11, i64 40}
!10 = !{!"gmskdem_s", !11, i64 0, !11, i64 4, !12, i64 8, !11, i64 12, !6, i64 16, !6, i64 24, !7, i64 32, !11, i64 40}
!11 = !{!"int", !7, i64 0}
!12 = !{!"float", !7, i64 0}
!13 = !{!11, !11, i64 0}
!14 = !{!10, !11, i64 0}
!15 = !{!"branch_weights", i32 1, i32 1048575}
!16 = !{!12, !12, i64 0}
!17 = !{!10, !6, i64 24}
!18 = distinct !{!18, !19}
!19 = !{!"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

; Function Attrs: nounwind uwtable
define dso_local noundef i32 @gmskdem_demodulate(ptr nocapture noundef %0, ptr nocapture noundef readonly %1, ptr nocapture noundef writeonly %2) local_unnamed_addr #1 {
  %4 = alloca float, align 4
  %5 = getelementptr inbounds i8, ptr %0, i64 40
  %6 = load i32, ptr %5, align 8, !tbaa !5
  %7 = add i32 %6, 1
  store i32 %7, ptr %5, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %4) #4
  %8 = load i32, ptr %0, align 8, !tbaa !12
  %.not17 = icmp eq i32 %8, 0
  br i1 %.not17, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %3
  %9 = getelementptr inbounds i8, ptr %0, i64 32
  %10 = getelementptr inbounds i8, ptr %0, i64 24
  %11 = load <2 x float>, ptr %9, align 8
  %12 = extractelement <2 x float> %11, i64 1
  %13 = fneg float %12
  %14 = load <2 x float>, ptr %1, align 4
  %15 = shufflevector <2 x float> %14, <2 x float> poison, <2 x i32> <i32 1, i32 0>
  %16 = fmul <2 x float> %11, %14
  %shift = shufflevector <2 x float> %16, <2 x float> poison, <2 x i32> <i32 1, i32 poison>
  %17 = fadd <2 x float> %16, %shift
  %18 = extractelement <2 x float> %17, i64 0
  %19 = fmul <2 x float> %11, %15
  %shift23 = shufflevector <2 x float> %19, <2 x float> poison, <2 x i32> <i32 1, i32 poison>
  %20 = fsub <2 x float> %19, %shift23
  %21 = extractelement <2 x float> %20, i64 0
  %22 = fcmp uno float %18, 0.000000e+00
  br i1 %22, label %23, label %30, !prof !13

23:                                               ; preds = %.lr.ph
  %24 = fcmp uno float %21, 0.000000e+00
  br i1 %24, label %25, label %30, !prof !13

25:                                               ; preds = %23
  %26 = extractelement <2 x float> %11, i64 0
  %27 = extractelement <2 x float> %14, i64 0
  %28 = extractelement <2 x float> %14, i64 1
  %29 = tail call <2 x float> @__mulsc3(float noundef %26, float noundef %13, float noundef %27, float noundef %28) #4
  %.sroa.02.0.vec.extract.peel = extractelement <2 x float> %29, i64 0
  %.sroa.02.4.vec.extract.peel = extractelement <2 x float> %29, i64 1
  br label %30

30:                                               ; preds = %25, %23, %.lr.ph
  %31 = phi float [ %18, %.lr.ph ], [ %18, %23 ], [ %.sroa.02.0.vec.extract.peel, %25 ]
  %32 = phi float [ %21, %.lr.ph ], [ %21, %23 ], [ %.sroa.02.4.vec.extract.peel, %25 ]
  %.sroa.0.0.vec.insert.peel = insertelement <2 x float> poison, float %31, i64 0
  %.sroa.0.4.vec.insert.peel = insertelement <2 x float> %.sroa.0.0.vec.insert.peel, float %32, i64 1
  %33 = tail call float @cargf(<2 x float> noundef %.sroa.0.4.vec.insert.peel) #4
  %34 = load <2 x float>, ptr %1, align 4
  store <2 x float> %34, ptr %9, align 8
  %35 = load ptr, ptr %10, align 8, !tbaa !14
  %36 = tail call i32 @firfilt_rrrf_push(ptr noundef %35, float noundef %33) #4
  %37 = load ptr, ptr %10, align 8, !tbaa !14
  %38 = call i32 @firfilt_rrrf_execute(ptr noundef %37, ptr noundef nonnull %4) #4
  %39 = load i32, ptr %0, align 8, !tbaa !12
  %40 = icmp ugt i32 %39, 1
  br i1 %40, label %.peel.next, label %._crit_edge.loopexit

.peel.next:                                       ; preds = %30, %61
  %indvars.iv = phi i64 [ %indvars.iv.next, %61 ], [ 1, %30 ]
  %41 = getelementptr inbounds { float, float }, ptr %1, i64 %indvars.iv
  %42 = load <2 x float>, ptr %9, align 8
  %43 = extractelement <2 x float> %42, i64 1
  %44 = fneg float %43
  %45 = load <2 x float>, ptr %41, align 4
  %46 = shufflevector <2 x float> %45, <2 x float> poison, <2 x i32> <i32 1, i32 0>
  %47 = fmul <2 x float> %42, %45
  %shift24 = shufflevector <2 x float> %47, <2 x float> poison, <2 x i32> <i32 1, i32 poison>
  %48 = fadd <2 x float> %47, %shift24
  %49 = extractelement <2 x float> %48, i64 0
  %50 = fmul <2 x float> %42, %46
  %shift25 = shufflevector <2 x float> %50, <2 x float> poison, <2 x i32> <i32 1, i32 poison>
  %51 = fsub <2 x float> %50, %shift25
  %52 = extractelement <2 x float> %51, i64 0
  %53 = fcmp uno float %49, 0.000000e+00
  br i1 %53, label %54, label %61, !prof !13

54:                                               ; preds = %.peel.next
  %55 = fcmp uno float %52, 0.000000e+00
  br i1 %55, label %56, label %61, !prof !13

56:                                               ; preds = %54
  %57 = extractelement <2 x float> %42, i64 0
  %58 = extractelement <2 x float> %45, i64 0
  %59 = extractelement <2 x float> %45, i64 1
  %60 = call <2 x float> @__mulsc3(float noundef %57, float noundef %44, float noundef %58, float noundef %59) #4
  %.sroa.02.0.vec.extract = extractelement <2 x float> %60, i64 0
  %.sroa.02.4.vec.extract = extractelement <2 x float> %60, i64 1
  br label %61

61:                                               ; preds = %56, %54, %.peel.next
  %62 = phi float [ %49, %.peel.next ], [ %49, %54 ], [ %.sroa.02.0.vec.extract, %56 ]
  %63 = phi float [ %52, %.peel.next ], [ %52, %54 ], [ %.sroa.02.4.vec.extract, %56 ]
  %.sroa.0.0.vec.insert = insertelement <2 x float> poison, float %62, i64 0
  %.sroa.0.4.vec.insert = insertelement <2 x float> %.sroa.0.0.vec.insert, float %63, i64 1
  %64 = call float @cargf(<2 x float> noundef %.sroa.0.4.vec.insert) #4
  %65 = load <2 x float>, ptr %41, align 4
  store <2 x float> %65, ptr %9, align 8
  %66 = load ptr, ptr %10, align 8, !tbaa !14
  %67 = call i32 @firfilt_rrrf_push(ptr noundef %66, float noundef %64) #4
  %.pre = load i32, ptr %0, align 8, !tbaa !12
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %68 = zext i32 %.pre to i64
  %69 = icmp ult i64 %indvars.iv.next, %68
  br i1 %69, label %.peel.next, label %._crit_edge.loopexit, !llvm.loop !15

._crit_edge.loopexit:                             ; preds = %61, %30
  %.pre22 = load float, ptr %4, align 4, !tbaa !18
  %70 = fcmp ogt float %.pre22, 0.000000e+00
  %71 = zext i1 %70 to i32
  br label %._crit_edge

._crit_edge:                                      ; preds = %._crit_edge.loopexit, %3
  %72 = phi i32 [ %71, %._crit_edge.loopexit ], [ 0, %3 ]
  store i32 %72, ptr %2, align 4, !tbaa !19
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %4) #4
  ret i32 0
}

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

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

declare i32 @firfilt_rrrf_push(ptr noundef, float noundef) local_unnamed_addr #3

declare i32 @firfilt_rrrf_execute(ptr noundef, ptr noundef) local_unnamed_addr #3

attributes #0 = { mustprogress nocallback nofree nosync 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 = { 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 = { "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 40}
!6 = !{!"gmskdem_s", !7, i64 0, !7, i64 4, !10, i64 8, !7, i64 12, !11, i64 16, !11, i64 24, !8, i64 32, !7, i64 40}
!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 0}
!13 = !{!"branch_weights", i32 1, i32 1048575}
!14 = !{!6, !11, i64 24}
!15 = distinct !{!15, !16, !17}
!16 = !{!"llvm.loop.mustprogress"}
!17 = !{!"llvm.loop.peeled.count", i32 1}
!18 = !{!10, !10, i64 0}
!19 = !{!7, !7, i64 0}


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