; 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 uwtable
define dso_local i32 @modemcf_demodulate_soft_bpsk(ptr noundef %0, <2 x float> noundef %1, ptr noundef %2, ptr noundef %3) #1 {
  %5 = alloca { float, float }, align 4
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca ptr, align 8
  %9 = alloca float, align 4
  %10 = alloca float, align 4
  %11 = alloca i32, align 4
  %12 = alloca i32, align 4
  store <2 x float> %1, ptr %5, align 4
  store ptr %0, ptr %6, align 8, !tbaa !5
  store ptr %2, ptr %7, align 8, !tbaa !5
  store ptr %3, ptr %8, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #4
  store float 4.000000e+00, ptr %9, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #4
  %13 = getelementptr inbounds { float, float }, ptr %5, i32 0, i32 0
  %14 = load float, ptr %13, align 4
  %15 = getelementptr inbounds { float, float }, ptr %5, i32 0, i32 1
  %16 = load float, ptr %15, align 4
  %17 = fmul float -2.000000e+00, %14
  %18 = load float, ptr %9, align 4, !tbaa !9
  %19 = fmul float %17, %18
  store float %19, ptr %10, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #4
  %20 = load float, ptr %10, align 4, !tbaa !9
  %21 = call float @llvm.fmuladd.f32(float %20, float 1.600000e+01, float 1.270000e+02)
  %22 = fptosi float %21 to i32
  store i32 %22, ptr %11, align 4, !tbaa !11
  %23 = load i32, ptr %11, align 4, !tbaa !11
  %24 = icmp sgt i32 %23, 255
  br i1 %24, label %25, label %26

25:                                               ; preds = %4
  store i32 255, ptr %11, align 4, !tbaa !11
  br label %26

26:                                               ; preds = %25, %4
  %27 = load i32, ptr %11, align 4, !tbaa !11
  %28 = icmp slt i32 %27, 0
  br i1 %28, label %29, label %30

29:                                               ; preds = %26
  store i32 0, ptr %11, align 4, !tbaa !11
  br label %30

30:                                               ; preds = %29, %26
  %31 = load i32, ptr %11, align 4, !tbaa !11
  %32 = trunc i32 %31 to i8
  %33 = load ptr, ptr %8, align 8, !tbaa !5
  %34 = getelementptr inbounds i8, ptr %33, i64 0
  store i8 %32, ptr %34, align 1, !tbaa !13
  call void @llvm.lifetime.start.p0(i64 4, ptr %12) #4
  %35 = getelementptr inbounds { float, float }, ptr %5, i32 0, i32 0
  %36 = load float, ptr %35, align 4
  %37 = getelementptr inbounds { float, float }, ptr %5, i32 0, i32 1
  %38 = load float, ptr %37, align 4
  %39 = fcmp ogt float %36, 0.000000e+00
  %40 = zext i1 %39 to i64
  %41 = select i1 %39, i32 0, i32 1
  store i32 %41, ptr %12, align 4, !tbaa !11
  %42 = load ptr, ptr %6, align 8, !tbaa !5
  %43 = load i32, ptr %12, align 4, !tbaa !11
  %44 = load ptr, ptr %6, align 8, !tbaa !5
  %45 = getelementptr inbounds %struct.modemcf_s, ptr %44, i32 0, i32 7
  %46 = call i32 @modemcf_modulate_bpsk(ptr noundef %42, i32 noundef %43, ptr noundef %45)
  %47 = getelementptr inbounds { float, float }, ptr %5, i32 0, i32 0
  %48 = load float, ptr %47, align 4
  %49 = getelementptr inbounds { float, float }, ptr %5, i32 0, i32 1
  %50 = load float, ptr %49, align 4
  %51 = load ptr, ptr %6, align 8, !tbaa !5
  %52 = getelementptr inbounds %struct.modemcf_s, ptr %51, i32 0, i32 6
  %53 = getelementptr inbounds { float, float }, ptr %52, i32 0, i32 0
  %54 = getelementptr inbounds { float, float }, ptr %52, i32 0, i32 1
  store float %48, ptr %53, align 4
  store float %50, ptr %54, align 4
  %55 = load i32, ptr %12, align 4, !tbaa !11
  %56 = load ptr, ptr %7, align 8, !tbaa !5
  store i32 %55, ptr %56, align 4, !tbaa !11
  call void @llvm.lifetime.end.p0(i64 4, ptr %12) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #4
  ret i32 0
}

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

; Function Attrs: nounwind uwtable
declare dso_local i32 @modemcf_modulate_bpsk(ptr noundef, i32 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 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #3 = { 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 #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 = !{!"float", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"int", !7, i64 0}
!13 = !{!7, !7, i64 0}


; 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 uwtable
define dso_local noundef i32 @modemcf_demodulate_soft_bpsk(ptr noundef %0, <2 x float> noundef %1, ptr nocapture noundef writeonly %2, ptr nocapture noundef writeonly %3) local_unnamed_addr #0 {
  %5 = extractelement <2 x float> %1, i64 0
  %6 = fmul float %5, -2.000000e+00
  %7 = fmul float %6, 4.000000e+00
  %8 = tail call float @llvm.fmuladd.f32(float %7, float 1.600000e+01, float 1.270000e+02)
  %9 = fptosi float %8 to i32
  %spec.store.select = tail call i32 @llvm.smin.i32(i32 %9, i32 255)
  %spec.store.select1 = tail call i32 @llvm.smax.i32(i32 %spec.store.select, i32 0)
  %10 = trunc nuw i32 %spec.store.select1 to i8
  store i8 %10, ptr %3, align 1, !tbaa !5
  %11 = fcmp ule float %5, 0.000000e+00
  %12 = zext i1 %11 to i32
  %13 = getelementptr inbounds i8, ptr %0, i64 68
  %14 = tail call i32 @modemcf_modulate_bpsk(ptr noundef %0, i32 noundef %12, ptr noundef nonnull %13)
  %15 = getelementptr inbounds i8, ptr %0, i64 60
  store <2 x float> %1, ptr %15, align 4
  store i32 %12, ptr %2, align 4, !tbaa !8
  ret i32 0
}

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

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

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i32 @llvm.smin.i32(i32, i32) #3

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i32 @llvm.smax.i32(i32, i32) #3

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 = { mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none) }
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 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }

!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 = !{!"omnipotent char", !7, i64 0}
!7 = !{!"Simple C/C++ TBAA"}
!8 = !{!9, !9, i64 0}
!9 = !{!"int", !6, i64 0}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,PostOrderFunctionAttrsPass,SCCPPass,SLPVectorizerPass,SROAPass,SimplifyCFGPass,TailCallElimPass