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

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

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

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

29:                                               ; preds = %28, %25
  %30 = load i32, ptr %11, align 4, !tbaa !11
  %31 = trunc i32 %30 to i8
  %32 = load ptr, ptr %8, align 8, !tbaa !5
  %33 = getelementptr inbounds i8, ptr %32, i64 0
  store i8 %31, ptr %33, align 1, !tbaa !13
  %34 = getelementptr inbounds { float, float }, ptr %5, i32 0, i32 0
  %35 = load float, ptr %34, align 4
  %36 = getelementptr inbounds { float, float }, ptr %5, i32 0, i32 1
  %37 = load float, ptr %36, align 4
  %38 = fmul float -2.000000e+00, %35
  %39 = load float, ptr %9, align 4, !tbaa !9
  %40 = fmul float %38, %39
  store float %40, ptr %10, align 4, !tbaa !9
  %41 = load float, ptr %10, align 4, !tbaa !9
  %42 = call float @llvm.fmuladd.f32(float %41, float 1.600000e+01, float 1.270000e+02)
  %43 = fptosi float %42 to i32
  store i32 %43, ptr %11, align 4, !tbaa !11
  %44 = load i32, ptr %11, align 4, !tbaa !11
  %45 = icmp sgt i32 %44, 255
  br i1 %45, label %46, label %47

46:                                               ; preds = %29
  store i32 255, ptr %11, align 4, !tbaa !11
  br label %47

47:                                               ; preds = %46, %29
  %48 = load i32, ptr %11, align 4, !tbaa !11
  %49 = icmp slt i32 %48, 0
  br i1 %49, label %50, label %51

50:                                               ; preds = %47
  store i32 0, ptr %11, align 4, !tbaa !11
  br label %51

51:                                               ; preds = %50, %47
  %52 = load i32, ptr %11, align 4, !tbaa !11
  %53 = trunc i32 %52 to i8
  %54 = load ptr, ptr %8, align 8, !tbaa !5
  %55 = getelementptr inbounds i8, ptr %54, i64 1
  store i8 %53, ptr %55, align 1, !tbaa !13
  %56 = getelementptr inbounds { float, float }, ptr %5, i32 0, i32 0
  %57 = load float, ptr %56, align 4
  %58 = getelementptr inbounds { float, float }, ptr %5, i32 0, i32 1
  %59 = load float, ptr %58, align 4
  %60 = fcmp ogt float %57, 0.000000e+00
  %61 = zext i1 %60 to i64
  %62 = select i1 %60, i32 0, i32 1
  %63 = getelementptr inbounds { float, float }, ptr %5, i32 0, i32 0
  %64 = load float, ptr %63, align 4
  %65 = getelementptr inbounds { float, float }, ptr %5, i32 0, i32 1
  %66 = load float, ptr %65, align 4
  %67 = fcmp ogt float %66, 0.000000e+00
  %68 = zext i1 %67 to i64
  %69 = select i1 %67, i32 0, i32 2
  %70 = add nsw i32 %62, %69
  %71 = load ptr, ptr %7, align 8, !tbaa !5
  store i32 %70, ptr %71, align 4, !tbaa !11
  %72 = load ptr, ptr %6, align 8, !tbaa !5
  %73 = load ptr, ptr %7, align 8, !tbaa !5
  %74 = load i32, ptr %73, align 4, !tbaa !11
  %75 = load ptr, ptr %6, align 8, !tbaa !5
  %76 = getelementptr inbounds %struct.modemcf_s, ptr %75, i32 0, i32 7
  %77 = call i32 @modemcf_modulate_qpsk(ptr noundef %72, i32 noundef %74, ptr noundef %76)
  %78 = getelementptr inbounds { float, float }, ptr %5, i32 0, i32 0
  %79 = load float, ptr %78, align 4
  %80 = getelementptr inbounds { float, float }, ptr %5, i32 0, i32 1
  %81 = load float, ptr %80, align 4
  %82 = load ptr, ptr %6, align 8, !tbaa !5
  %83 = getelementptr inbounds %struct.modemcf_s, ptr %82, i32 0, i32 6
  %84 = getelementptr inbounds { float, float }, ptr %83, i32 0, i32 0
  %85 = getelementptr inbounds { float, float }, ptr %83, i32 0, i32 1
  store float %79, ptr %84, align 4
  store float %81, ptr %85, align 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_qpsk(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_qpsk(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 1
  %6 = extractelement <2 x float> %1, i64 0
  %7 = fmul float %5, -2.000000e+00
  %8 = fmul float %7, 0x4017333340000000
  %9 = tail call float @llvm.fmuladd.f32(float %8, float 1.600000e+01, float 1.270000e+02)
  %10 = fptosi float %9 to i32
  %spec.store.select = tail call i32 @llvm.smin.i32(i32 %10, i32 255)
  %spec.store.select2 = tail call i32 @llvm.smax.i32(i32 %spec.store.select, i32 0)
  %11 = trunc nuw i32 %spec.store.select2 to i8
  store i8 %11, ptr %3, align 1, !tbaa !5
  %12 = fmul float %6, -2.000000e+00
  %13 = fmul float %12, 0x4017333340000000
  %14 = tail call float @llvm.fmuladd.f32(float %13, float 1.600000e+01, float 1.270000e+02)
  %15 = fptosi float %14 to i32
  %spec.store.select1 = tail call i32 @llvm.smin.i32(i32 %15, i32 255)
  %spec.store.select3 = tail call i32 @llvm.smax.i32(i32 %spec.store.select1, i32 0)
  %16 = trunc nuw i32 %spec.store.select3 to i8
  %17 = getelementptr inbounds i8, ptr %3, i64 1
  store i8 %16, ptr %17, align 1, !tbaa !5
  %18 = fcmp ule float %6, 0.000000e+00
  %19 = zext i1 %18 to i32
  %20 = fcmp ogt float %5, 0.000000e+00
  %21 = select i1 %20, i32 0, i32 2
  %22 = or disjoint i32 %21, %19
  store i32 %22, ptr %2, align 4, !tbaa !8
  %23 = getelementptr inbounds i8, ptr %0, i64 68
  %24 = tail call i32 @modemcf_modulate_qpsk(ptr noundef %0, i32 noundef %22, ptr noundef nonnull %23)
  %25 = getelementptr inbounds i8, ptr %0, i64 60
  store <2 x float> %1, ptr %25, align 4
  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_qpsk(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,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,PostOrderFunctionAttrsPass,SCCPPass,SLPVectorizerPass,SROAPass,SimplifyCFGPass,TailCallElimPass