; 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.freqmod_s = type { float, float, i32, i16, 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: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare float @llvm.round.f32(float) #1

; Function Attrs: nounwind uwtable
define dso_local i32 @freqmod_modulate(ptr noundef %0, float noundef %1, ptr noundef %2) #2 {
  %4 = alloca ptr, align 8
  %5 = alloca float, align 4
  %6 = alloca ptr, align 8
  %7 = alloca i32, align 4
  store ptr %0, ptr %4, align 8, !tbaa !5
  store float %1, ptr %5, align 4, !tbaa !9
  store ptr %2, ptr %6, align 8, !tbaa !5
  %8 = load ptr, ptr %4, align 8, !tbaa !5
  %9 = getelementptr inbounds %struct.freqmod_s, ptr %8, i32 0, i32 3
  %10 = load i16, ptr %9, align 4, !tbaa !11
  %11 = zext i16 %10 to i32
  %12 = add nsw i32 %11, 65536
  %13 = load ptr, ptr %4, align 8, !tbaa !5
  %14 = getelementptr inbounds %struct.freqmod_s, ptr %13, i32 0, i32 1
  %15 = load float, ptr %14, align 4, !tbaa !15
  %16 = load float, ptr %5, align 4, !tbaa !9
  %17 = fmul float %15, %16
  %18 = call float @llvm.round.f32(float %17)
  %19 = fptosi float %18 to i32
  %20 = add nsw i32 %12, %19
  %21 = and i32 %20, 65535
  %22 = trunc i32 %21 to i16
  %23 = load ptr, ptr %4, align 8, !tbaa !5
  %24 = getelementptr inbounds %struct.freqmod_s, ptr %23, i32 0, i32 3
  store i16 %22, ptr %24, align 4, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #3
  %25 = load ptr, ptr %4, align 8, !tbaa !5
  %26 = getelementptr inbounds %struct.freqmod_s, ptr %25, i32 0, i32 3
  %27 = load i16, ptr %26, align 4, !tbaa !11
  %28 = zext i16 %27 to i32
  %29 = add nsw i32 %28, 32
  %30 = ashr i32 %29, 6
  %31 = and i32 %30, 1023
  store i32 %31, ptr %7, align 4, !tbaa !16
  %32 = load ptr, ptr %4, align 8, !tbaa !5
  %33 = getelementptr inbounds %struct.freqmod_s, ptr %32, i32 0, i32 4
  %34 = load ptr, ptr %33, align 8, !tbaa !17
  %35 = load i32, ptr %7, align 4, !tbaa !16
  %36 = zext i32 %35 to i64
  %37 = getelementptr inbounds { float, float }, ptr %34, i64 %36
  %38 = getelementptr inbounds { float, float }, ptr %37, i32 0, i32 0
  %39 = load float, ptr %38, align 4
  %40 = getelementptr inbounds { float, float }, ptr %37, i32 0, i32 1
  %41 = load float, ptr %40, align 4
  %42 = load ptr, ptr %6, align 8, !tbaa !5
  %43 = getelementptr inbounds { float, float }, ptr %42, i32 0, i32 0
  %44 = getelementptr inbounds { float, float }, ptr %42, i32 0, i32 1
  store float %39, ptr %43, align 4
  store float %41, ptr %44, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #3
  ret i32 0
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 = { 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, !14, i64 12}
!12 = !{!"freqmod_s", !10, i64 0, !10, i64 4, !13, i64 8, !14, i64 12, !6, i64 16}
!13 = !{!"int", !7, i64 0}
!14 = !{!"short", !7, i64 0}
!15 = !{!12, !10, i64 4}
!16 = !{!13, !13, i64 0}
!17 = !{!12, !6, i64 16}


; 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 speculatable willreturn memory(none)
declare float @llvm.round.f32(float) #0

; Function Attrs: mustprogress nofree norecurse nosync nounwind willreturn memory(read, argmem: readwrite, inaccessiblemem: none) uwtable
define dso_local noundef i32 @freqmod_modulate(ptr nocapture noundef %0, float noundef %1, ptr nocapture noundef writeonly %2) local_unnamed_addr #1 {
  %4 = getelementptr inbounds i8, ptr %0, i64 12
  %5 = load i16, ptr %4, align 4, !tbaa !5
  %6 = getelementptr inbounds i8, ptr %0, i64 4
  %7 = load float, ptr %6, align 4, !tbaa !13
  %8 = fmul float %7, %1
  %9 = tail call float @llvm.round.f32(float %8)
  %10 = fptosi float %9 to i32
  %.tr = trunc i32 %10 to i16
  %.narrow = add i16 %5, %.tr
  store i16 %.narrow, ptr %4, align 4, !tbaa !5
  %11 = zext i16 %.narrow to i64
  %12 = add nuw nsw i64 %11, 32
  %13 = lshr i64 %12, 6
  %14 = and i64 %13, 1023
  %15 = getelementptr inbounds i8, ptr %0, i64 16
  %16 = load ptr, ptr %15, align 8, !tbaa !14
  %17 = getelementptr inbounds { float, float }, ptr %16, i64 %14
  %18 = load <2 x float>, ptr %17, align 4
  store <2 x float> %18, ptr %2, align 4
  ret i32 0
}

attributes #0 = { mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #1 = { mustprogress nofree norecurse nosync nounwind willreturn memory(read, argmem: readwrite, inaccessiblemem: none) 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" }

!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 12}
!6 = !{!"freqmod_s", !7, i64 0, !7, i64 4, !10, i64 8, !11, i64 12, !12, i64 16}
!7 = !{!"float", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"int", !8, i64 0}
!11 = !{!"short", !8, i64 0}
!12 = !{!"any pointer", !8, i64 0}
!13 = !{!6, !7, i64 4}
!14 = !{!6, !12, i64 16}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,PostOrderFunctionAttrsPass,ReassociatePass,SLPVectorizerPass,SROAPass,TailCallElimPass