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

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

@.str = external hidden unnamed_addr constant [77 x i8], align 1
@.str.10 = external hidden unnamed_addr constant [58 x i8], align 1

; 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 @fskmod_modulate(ptr noundef %0, i32 noundef %1, ptr noundef %2) #1 {
  %4 = alloca i32, align 4
  %5 = alloca ptr, align 8
  %6 = alloca i32, align 4
  %7 = alloca ptr, align 8
  %8 = alloca float, align 4
  %9 = alloca i32, align 4
  store ptr %0, ptr %5, align 8, !tbaa !5
  store i32 %1, ptr %6, align 4, !tbaa !9
  store ptr %2, ptr %7, align 8, !tbaa !5
  %10 = load i32, ptr %6, align 4, !tbaa !9
  %11 = load ptr, ptr %5, align 8, !tbaa !5
  %12 = getelementptr inbounds %struct.fskmod_s, ptr %11, i32 0, i32 3
  %13 = load i32, ptr %12, align 4, !tbaa !11
  %14 = icmp uge i32 %10, %13
  br i1 %14, label %15, label %21

15:                                               ; preds = %3
  %16 = load i32, ptr %6, align 4, !tbaa !9
  %17 = load ptr, ptr %5, align 8, !tbaa !5
  %18 = getelementptr inbounds %struct.fskmod_s, ptr %17, i32 0, i32 3
  %19 = load i32, ptr %18, align 4, !tbaa !11
  %20 = call i32 (i32, ptr, i32, ptr, ...) @liquid_error_fl(i32 noundef 5, ptr noundef @.str, i32 noundef 139, ptr noundef @.str.10, i32 noundef %16, i32 noundef %19)
  store i32 %20, ptr %4, align 4
  br label %70

21:                                               ; preds = %3
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #3
  %22 = load i32, ptr %6, align 4, !tbaa !9
  %23 = uitofp i32 %22 to float
  %24 = load ptr, ptr %5, align 8, !tbaa !5
  %25 = getelementptr inbounds %struct.fskmod_s, ptr %24, i32 0, i32 4
  %26 = load float, ptr %25, align 8, !tbaa !14
  %27 = fsub float %23, %26
  %28 = fmul float %27, 2.000000e+00
  %29 = fpext float %28 to double
  %30 = fmul double %29, 0x400921FB54442D18
  %31 = load ptr, ptr %5, align 8, !tbaa !5
  %32 = getelementptr inbounds %struct.fskmod_s, ptr %31, i32 0, i32 2
  %33 = load float, ptr %32, align 8, !tbaa !15
  %34 = fpext float %33 to double
  %35 = fmul double %30, %34
  %36 = load ptr, ptr %5, align 8, !tbaa !5
  %37 = getelementptr inbounds %struct.fskmod_s, ptr %36, i32 0, i32 4
  %38 = load float, ptr %37, align 8, !tbaa !14
  %39 = fpext float %38 to double
  %40 = fdiv double %35, %39
  %41 = fptrunc double %40 to float
  store float %41, ptr %8, align 4, !tbaa !16
  %42 = load ptr, ptr %5, align 8, !tbaa !5
  %43 = getelementptr inbounds %struct.fskmod_s, ptr %42, i32 0, i32 5
  %44 = load ptr, ptr %43, align 8, !tbaa !17
  %45 = load float, ptr %8, align 4, !tbaa !16
  %46 = call i32 @nco_crcf_set_frequency(ptr noundef %44, float noundef %45)
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #3
  store i32 0, ptr %9, align 4, !tbaa !9
  br label %47

47:                                               ; preds = %66, %21
  %48 = load i32, ptr %9, align 4, !tbaa !9
  %49 = load ptr, ptr %5, align 8, !tbaa !5
  %50 = getelementptr inbounds %struct.fskmod_s, ptr %49, i32 0, i32 1
  %51 = load i32, ptr %50, align 4, !tbaa !18
  %52 = icmp ult i32 %48, %51
  br i1 %52, label %53, label %69

53:                                               ; preds = %47
  %54 = load ptr, ptr %5, align 8, !tbaa !5
  %55 = getelementptr inbounds %struct.fskmod_s, ptr %54, i32 0, i32 5
  %56 = load ptr, ptr %55, align 8, !tbaa !17
  %57 = load ptr, ptr %7, align 8, !tbaa !5
  %58 = load i32, ptr %9, align 4, !tbaa !9
  %59 = zext i32 %58 to i64
  %60 = getelementptr inbounds { float, float }, ptr %57, i64 %59
  %61 = call i32 @nco_crcf_cexpf(ptr noundef %56, ptr noundef %60)
  %62 = load ptr, ptr %5, align 8, !tbaa !5
  %63 = getelementptr inbounds %struct.fskmod_s, ptr %62, i32 0, i32 5
  %64 = load ptr, ptr %63, align 8, !tbaa !17
  %65 = call i32 @nco_crcf_step(ptr noundef %64)
  br label %66

66:                                               ; preds = %53
  %67 = load i32, ptr %9, align 4, !tbaa !9
  %68 = add i32 %67, 1
  store i32 %68, ptr %9, align 4, !tbaa !9
  br label %47, !llvm.loop !19

69:                                               ; preds = %47
  store i32 0, ptr %4, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #3
  br label %70

70:                                               ; preds = %69, %15
  %71 = load i32, ptr %4, align 4
  ret i32 %71
}

declare i32 @liquid_error_fl(i32 noundef, ptr noundef, i32 noundef, ptr noundef, ...) #2

declare i32 @nco_crcf_set_frequency(ptr noundef, float noundef) #2

declare i32 @nco_crcf_cexpf(ptr noundef, ptr noundef) #2

declare i32 @nco_crcf_step(ptr noundef) #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 = { "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 = !{!"int", !7, i64 0}
!11 = !{!12, !10, i64 12}
!12 = !{!"fskmod_s", !10, i64 0, !10, i64 4, !13, i64 8, !10, i64 12, !13, i64 16, !6, i64 24}
!13 = !{!"float", !7, i64 0}
!14 = !{!12, !13, i64 16}
!15 = !{!12, !13, i64 8}
!16 = !{!13, !13, i64 0}
!17 = !{!12, !6, i64 24}
!18 = !{!12, !10, i64 4}
!19 = distinct !{!19, !20}
!20 = !{!"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"

@.str = external hidden unnamed_addr constant [77 x i8], align 1
@.str.10 = external hidden unnamed_addr constant [58 x i8], align 1

; Function Attrs: nounwind uwtable
define dso_local i32 @fskmod_modulate(ptr nocapture noundef readonly %0, i32 noundef %1, ptr noundef %2) local_unnamed_addr #0 {
  %4 = getelementptr inbounds i8, ptr %0, i64 12
  %5 = load i32, ptr %4, align 4, !tbaa !5
  %.not = icmp ugt i32 %5, %1
  br i1 %.not, label %8, label %6

6:                                                ; preds = %3
  %7 = tail call i32 (i32, ptr, i32, ptr, ...) @liquid_error_fl(i32 noundef 5, ptr noundef nonnull @.str, i32 noundef 139, ptr noundef nonnull @.str.10, i32 noundef %1, i32 noundef %5) #2
  br label %.loopexit

8:                                                ; preds = %3
  %9 = uitofp i32 %1 to float
  %10 = getelementptr inbounds i8, ptr %0, i64 16
  %11 = load float, ptr %10, align 8, !tbaa !12
  %12 = fsub float %9, %11
  %13 = fmul float %12, 2.000000e+00
  %14 = fpext float %13 to double
  %15 = fmul double %14, 0x400921FB54442D18
  %16 = getelementptr inbounds i8, ptr %0, i64 8
  %17 = load float, ptr %16, align 8, !tbaa !13
  %18 = fpext float %17 to double
  %19 = fmul double %15, %18
  %20 = fpext float %11 to double
  %21 = fdiv double %19, %20
  %22 = fptrunc double %21 to float
  %23 = getelementptr inbounds i8, ptr %0, i64 24
  %24 = load ptr, ptr %23, align 8, !tbaa !14
  %25 = tail call i32 @nco_crcf_set_frequency(ptr noundef %24, float noundef %22) #2
  %26 = getelementptr inbounds i8, ptr %0, i64 4
  %27 = load i32, ptr %26, align 4, !tbaa !15
  %.not21 = icmp eq i32 %27, 0
  br i1 %.not21, label %.loopexit, label %.lr.ph

.lr.ph:                                           ; preds = %8, %.lr.ph
  %indvars.iv = phi i64 [ %indvars.iv.next, %.lr.ph ], [ 0, %8 ]
  %28 = load ptr, ptr %23, align 8, !tbaa !14
  %29 = getelementptr inbounds { float, float }, ptr %2, i64 %indvars.iv
  %30 = tail call i32 @nco_crcf_cexpf(ptr noundef %28, ptr noundef %29) #2
  %31 = load ptr, ptr %23, align 8, !tbaa !14
  %32 = tail call i32 @nco_crcf_step(ptr noundef %31) #2
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %33 = load i32, ptr %26, align 4, !tbaa !15
  %34 = zext i32 %33 to i64
  %35 = icmp ult i64 %indvars.iv.next, %34
  br i1 %35, label %.lr.ph, label %.loopexit, !llvm.loop !16

.loopexit:                                        ; preds = %.lr.ph, %8, %6
  %.017 = phi i32 [ %7, %6 ], [ 0, %8 ], [ 0, %.lr.ph ]
  ret i32 %.017
}

declare i32 @liquid_error_fl(i32 noundef, ptr noundef, i32 noundef, ptr noundef, ...) local_unnamed_addr #1

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

declare i32 @nco_crcf_cexpf(ptr noundef, ptr noundef) local_unnamed_addr #1

declare i32 @nco_crcf_step(ptr noundef) local_unnamed_addr #1

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 = { 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 12}
!6 = !{!"fskmod_s", !7, i64 0, !7, i64 4, !10, i64 8, !7, i64 12, !10, i64 16, !11, i64 24}
!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, !10, i64 16}
!13 = !{!6, !10, i64 8}
!14 = !{!6, !11, i64 24}
!15 = !{!6, !7, i64 4}
!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,TailCallElimPass