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

; 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.gmskmod_s = type { i32, i32, float, i32, ptr, ptr, float, float }

; 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 @gmskmod_modulate(ptr noundef %0, i32 noundef %1, ptr noundef %2) #1 {
  %4 = alloca ptr, align 8
  %5 = alloca i32, align 4
  %6 = alloca ptr, align 8
  %7 = alloca float, align 4
  %8 = alloca ptr, align 8
  %9 = alloca i64, align 8
  %10 = alloca i32, align 4
  store ptr %0, ptr %4, align 8, !tbaa !5
  store i32 %1, ptr %5, align 4, !tbaa !9
  store ptr %2, ptr %6, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #5
  %11 = load i32, ptr %5, align 4, !tbaa !9
  %12 = icmp eq i32 %11, 0
  br i1 %12, label %13, label %18

13:                                               ; preds = %3
  %14 = load ptr, ptr %4, align 8, !tbaa !5
  %15 = getelementptr inbounds %struct.gmskmod_s, ptr %14, i32 0, i32 7
  %16 = load float, ptr %15, align 4, !tbaa !11
  %17 = fneg float %16
  br label %22

18:                                               ; preds = %3
  %19 = load ptr, ptr %4, align 8, !tbaa !5
  %20 = getelementptr inbounds %struct.gmskmod_s, ptr %19, i32 0, i32 7
  %21 = load float, ptr %20, align 4, !tbaa !11
  br label %22

22:                                               ; preds = %18, %13
  %23 = phi float [ %17, %13 ], [ %21, %18 ]
  store float %23, ptr %7, align 4, !tbaa !14
  %24 = load ptr, ptr %4, align 8, !tbaa !5
  %25 = getelementptr inbounds %struct.gmskmod_s, ptr %24, i32 0, i32 0
  %26 = load i32, ptr %25, align 8, !tbaa !15
  %27 = zext i32 %26 to i64
  %28 = call ptr @llvm.stacksave.p0()
  store ptr %28, ptr %8, align 8
  %29 = alloca float, i64 %27, align 16
  store i64 %27, ptr %9, align 8
  %30 = load ptr, ptr %4, align 8, !tbaa !5
  %31 = getelementptr inbounds %struct.gmskmod_s, ptr %30, i32 0, i32 5
  %32 = load ptr, ptr %31, align 8, !tbaa !16
  %33 = load float, ptr %7, align 4, !tbaa !14
  %34 = call i32 @firinterp_rrrf_execute(ptr noundef %32, float noundef %33, ptr noundef %29)
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #5
  store i32 0, ptr %10, align 4, !tbaa !9
  br label %35

35:                                               ; preds = %93, %22
  %36 = load i32, ptr %10, align 4, !tbaa !9
  %37 = load ptr, ptr %4, align 8, !tbaa !5
  %38 = getelementptr inbounds %struct.gmskmod_s, ptr %37, i32 0, i32 0
  %39 = load i32, ptr %38, align 8, !tbaa !15
  %40 = icmp ult i32 %36, %39
  br i1 %40, label %41, label %96

41:                                               ; preds = %35
  %42 = load i32, ptr %10, align 4, !tbaa !9
  %43 = zext i32 %42 to i64
  %44 = getelementptr inbounds float, ptr %29, i64 %43
  %45 = load float, ptr %44, align 4, !tbaa !14
  %46 = load ptr, ptr %4, align 8, !tbaa !5
  %47 = getelementptr inbounds %struct.gmskmod_s, ptr %46, i32 0, i32 6
  %48 = load float, ptr %47, align 8, !tbaa !17
  %49 = fadd float %48, %45
  store float %49, ptr %47, align 8, !tbaa !17
  %50 = load ptr, ptr %4, align 8, !tbaa !5
  %51 = getelementptr inbounds %struct.gmskmod_s, ptr %50, i32 0, i32 6
  %52 = load float, ptr %51, align 8, !tbaa !17
  %53 = fpext float %52 to double
  %54 = fcmp ogt double %53, 0x400921FB54442D18
  br i1 %54, label %55, label %62

55:                                               ; preds = %41
  %56 = load ptr, ptr %4, align 8, !tbaa !5
  %57 = getelementptr inbounds %struct.gmskmod_s, ptr %56, i32 0, i32 6
  %58 = load float, ptr %57, align 8, !tbaa !17
  %59 = fpext float %58 to double
  %60 = fsub double %59, 0x401921FB54442D18
  %61 = fptrunc double %60 to float
  store float %61, ptr %57, align 8, !tbaa !17
  br label %62

62:                                               ; preds = %55, %41
  %63 = load ptr, ptr %4, align 8, !tbaa !5
  %64 = getelementptr inbounds %struct.gmskmod_s, ptr %63, i32 0, i32 6
  %65 = load float, ptr %64, align 8, !tbaa !17
  %66 = fpext float %65 to double
  %67 = fcmp olt double %66, 0xC00921FB54442D18
  br i1 %67, label %68, label %75

68:                                               ; preds = %62
  %69 = load ptr, ptr %4, align 8, !tbaa !5
  %70 = getelementptr inbounds %struct.gmskmod_s, ptr %69, i32 0, i32 6
  %71 = load float, ptr %70, align 8, !tbaa !17
  %72 = fpext float %71 to double
  %73 = fadd double %72, 0x401921FB54442D18
  %74 = fptrunc double %73 to float
  store float %74, ptr %70, align 8, !tbaa !17
  br label %75

75:                                               ; preds = %68, %62
  %76 = load ptr, ptr %4, align 8, !tbaa !5
  %77 = getelementptr inbounds %struct.gmskmod_s, ptr %76, i32 0, i32 6
  %78 = load float, ptr %77, align 8, !tbaa !17
  %79 = call float @cosf(float noundef %78) #5
  %80 = load ptr, ptr %4, align 8, !tbaa !5
  %81 = getelementptr inbounds %struct.gmskmod_s, ptr %80, i32 0, i32 6
  %82 = load float, ptr %81, align 8, !tbaa !17
  %83 = call float @sinf(float noundef %82) #5
  %84 = fmul float 0.000000e+00, %83
  %85 = fmul float 1.000000e+00, %83
  %86 = fadd float %79, %84
  %87 = load ptr, ptr %6, align 8, !tbaa !5
  %88 = load i32, ptr %10, align 4, !tbaa !9
  %89 = zext i32 %88 to i64
  %90 = getelementptr inbounds { float, float }, ptr %87, i64 %89
  %91 = getelementptr inbounds { float, float }, ptr %90, i32 0, i32 0
  %92 = getelementptr inbounds { float, float }, ptr %90, i32 0, i32 1
  store float %86, ptr %91, align 4
  store float %85, ptr %92, align 4
  br label %93

93:                                               ; preds = %75
  %94 = load i32, ptr %10, align 4, !tbaa !9
  %95 = add i32 %94, 1
  store i32 %95, ptr %10, align 4, !tbaa !9
  br label %35, !llvm.loop !18

96:                                               ; preds = %35
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #5
  %97 = load ptr, ptr %8, align 8
  call void @llvm.stackrestore.p0(ptr %97)
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #5
  ret i32 0
}

; Function Attrs: nocallback nofree nosync nounwind willreturn
declare ptr @llvm.stacksave.p0() #2

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

; Function Attrs: nounwind
declare float @cosf(float noundef) #4

; Function Attrs: nounwind
declare float @sinf(float noundef) #4

; Function Attrs: nocallback nofree nosync nounwind willreturn
declare void @llvm.stackrestore.p0(ptr) #2

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 #2 = { nocallback nofree nosync nounwind willreturn }
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, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = !{!12, !13, i64 36}
!12 = !{!"gmskmod_s", !10, i64 0, !10, i64 4, !13, i64 8, !10, i64 12, !6, i64 16, !6, i64 24, !13, i64 32, !13, i64 36}
!13 = !{!"float", !7, i64 0}
!14 = !{!13, !13, i64 0}
!15 = !{!12, !10, i64 0}
!16 = !{!12, !6, i64 24}
!17 = !{!12, !13, i64 32}
!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: nounwind uwtable
define dso_local noundef i32 @gmskmod_modulate(ptr nocapture noundef %0, i32 noundef %1, ptr nocapture noundef writeonly %2) local_unnamed_addr #0 {
  %4 = icmp eq i32 %1, 0
  %5 = getelementptr inbounds i8, ptr %0, i64 36
  %6 = load float, ptr %5, align 4, !tbaa !5
  %7 = fneg float %6
  %8 = select i1 %4, float %7, float %6
  %9 = load i32, ptr %0, align 8, !tbaa !12
  %10 = zext i32 %9 to i64
  %11 = alloca float, i64 %10, align 16
  %12 = getelementptr inbounds i8, ptr %0, i64 24
  %13 = load ptr, ptr %12, align 8, !tbaa !13
  %14 = call i32 @firinterp_rrrf_execute(ptr noundef %13, float noundef %8, ptr noundef nonnull %11) #3
  %15 = load i32, ptr %0, align 8, !tbaa !12
  %.not = icmp eq i32 %15, 0
  br i1 %.not, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %3
  %16 = getelementptr inbounds i8, ptr %0, i64 32
  br label %17

17:                                               ; preds = %.lr.ph, %17
  %indvars.iv = phi i64 [ 0, %.lr.ph ], [ %indvars.iv.next, %17 ]
  %18 = getelementptr inbounds float, ptr %11, i64 %indvars.iv
  %19 = load float, ptr %18, align 4, !tbaa !14
  %20 = load float, ptr %16, align 8, !tbaa !15
  %21 = fadd float %19, %20
  %22 = fpext float %21 to double
  %23 = fcmp ogt double %22, 0x400921FB54442D18
  %24 = fadd double %22, 0xC01921FB54442D18
  %25 = fptrunc double %24 to float
  %storemerge = select i1 %23, float %25, float %21
  %26 = fpext float %storemerge to double
  %27 = fcmp olt double %26, 0xC00921FB54442D18
  %28 = fadd double %26, 0x401921FB54442D18
  %29 = fptrunc double %28 to float
  %storemerge21 = select i1 %27, float %29, float %storemerge
  store float %storemerge21, ptr %16, align 8, !tbaa !15
  %30 = call float @cosf(float noundef %storemerge21) #3
  %31 = load float, ptr %16, align 8, !tbaa !15
  %32 = call float @sinf(float noundef %31) #3
  %33 = fmul float %32, 0.000000e+00
  %34 = fadd float %30, %33
  %35 = getelementptr inbounds { float, float }, ptr %2, i64 %indvars.iv
  %36 = getelementptr inbounds i8, ptr %35, i64 4
  store float %34, ptr %35, align 4
  store float %32, ptr %36, align 4
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %37 = load i32, ptr %0, align 8, !tbaa !12
  %38 = zext i32 %37 to i64
  %39 = icmp ult i64 %indvars.iv.next, %38
  br i1 %39, label %17, label %._crit_edge, !llvm.loop !16

._crit_edge:                                      ; preds = %17, %3
  ret i32 0
}

declare i32 @firinterp_rrrf_execute(ptr noundef, float noundef, ptr noundef) local_unnamed_addr #1

; Function Attrs: mustprogress nofree nounwind willreturn memory(write)
declare float @cosf(float noundef) local_unnamed_addr #2

; Function Attrs: mustprogress nofree nounwind willreturn memory(write)
declare float @sinf(float noundef) local_unnamed_addr #2

attributes #0 = { 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 #1 = { "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 = { mustprogress nofree nounwind willreturn memory(write) "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, !10, i64 36}
!6 = !{!"gmskmod_s", !7, i64 0, !7, i64 4, !10, i64 8, !7, i64 12, !11, i64 16, !11, i64 24, !10, i64 32, !10, i64 36}
!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 = !{!6, !11, i64 24}
!14 = !{!10, !10, i64 0}
!15 = !{!6, !10, i64 32}
!16 = distinct !{!16, !17}
!17 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GlobalOptPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LICMPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass