; LLVM IR from jgaeddert/liquid-dsp :: src/filter/src (bessel)

; 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"

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

13:                                               ; preds = %55, %2
  %14 = load i32, ptr %5, align 4, !tbaa !5
  %15 = load i32, ptr %3, align 4, !tbaa !5
  %16 = icmp ult i32 %14, %15
  br i1 %16, label %17, label %58

17:                                               ; preds = %13
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #4
  %18 = load i32, ptr %6, align 4, !tbaa !5
  %19 = mul i32 2, %18
  %20 = load i32, ptr %5, align 4, !tbaa !5
  %21 = sub i32 %19, %20
  %22 = uitofp i32 %21 to float
  %23 = fadd float %22, 1.000000e+00
  %24 = call float @lgammaf(float noundef %23) #4
  store float %24, ptr %7, align 4, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #4
  %25 = load i32, ptr %6, align 4, !tbaa !5
  %26 = load i32, ptr %5, align 4, !tbaa !5
  %27 = sub i32 %25, %26
  %28 = uitofp i32 %27 to float
  %29 = fadd float %28, 1.000000e+00
  %30 = call float @lgammaf(float noundef %29) #4
  store float %30, ptr %8, align 4, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #4
  %31 = load i32, ptr %5, align 4, !tbaa !5
  %32 = uitofp i32 %31 to float
  %33 = fadd float %32, 1.000000e+00
  %34 = call float @lgammaf(float noundef %33) #4
  store float %34, ptr %9, align 4, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #4
  %35 = load i32, ptr %6, align 4, !tbaa !5
  %36 = load i32, ptr %5, align 4, !tbaa !5
  %37 = sub i32 %35, %36
  %38 = uitofp i32 %37 to float
  %39 = fpext float %38 to double
  %40 = fmul double 0x3FE62E42FEFA39EF, %39
  %41 = fptrunc double %40 to float
  store float %41, ptr %10, align 4, !tbaa !11
  %42 = load float, ptr %7, align 4, !tbaa !11
  %43 = load float, ptr %8, align 4, !tbaa !11
  %44 = fsub float %42, %43
  %45 = load float, ptr %9, align 4, !tbaa !11
  %46 = fsub float %44, %45
  %47 = load float, ptr %10, align 4, !tbaa !11
  %48 = fsub float %46, %47
  %49 = call float @expf(float noundef %48) #4, !tbaa !5
  %50 = call float @llvm.round.f32(float %49)
  %51 = load ptr, ptr %4, align 8, !tbaa !9
  %52 = load i32, ptr %5, align 4, !tbaa !5
  %53 = zext i32 %52 to i64
  %54 = getelementptr inbounds float, ptr %51, i64 %53
  store float %50, ptr %54, align 4, !tbaa !11
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #4
  br label %55

55:                                               ; preds = %17
  %56 = load i32, ptr %5, align 4, !tbaa !5
  %57 = add i32 %56, 1
  store i32 %57, ptr %5, align 4, !tbaa !5
  br label %13, !llvm.loop !13

58:                                               ; preds = %13
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #4
  ret i32 0
}

; Function Attrs: nounwind
declare float @lgammaf(float noundef) #2

; Function Attrs: nounwind
declare float @expf(float noundef) #2

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

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 = { 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 #3 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"any pointer", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"float", !7, i64 0}
!13 = distinct !{!13, !14}
!14 = !{!"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 @fpoly_bessel(i32 noundef %0, ptr nocapture noundef writeonly %1) local_unnamed_addr #0 {
  %3 = add i32 %0, -1
  %.not = icmp eq i32 %0, 0
  br i1 %.not, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %2
  %4 = shl i32 %3, 1
  %wide.trip.count = zext i32 %0 to i64
  br label %5

5:                                                ; preds = %.lr.ph, %5
  %indvars.iv = phi i64 [ 0, %.lr.ph ], [ %indvars.iv.next, %5 ]
  %6 = trunc nuw i64 %indvars.iv to i32
  %7 = sub i32 %4, %6
  %8 = uitofp i32 %7 to float
  %9 = fadd float %8, 1.000000e+00
  %10 = tail call float @lgammaf(float noundef %9) #4
  %11 = sub i32 %3, %6
  %12 = uitofp i32 %11 to float
  %13 = fadd float %12, 1.000000e+00
  %14 = tail call float @lgammaf(float noundef %13) #4
  %15 = uitofp i32 %6 to float
  %16 = fadd float %15, 1.000000e+00
  %17 = tail call float @lgammaf(float noundef %16) #4
  %18 = fpext float %12 to double
  %19 = fmul double %18, 0x3FE62E42FEFA39EF
  %20 = fptrunc double %19 to float
  %21 = fsub float %10, %14
  %22 = fsub float %21, %17
  %23 = fsub float %22, %20
  %24 = tail call float @expf(float noundef %23) #4, !tbaa !5
  %25 = tail call float @llvm.round.f32(float %24)
  %26 = getelementptr inbounds float, ptr %1, i64 %indvars.iv
  store float %25, ptr %26, align 4, !tbaa !9
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %exitcond.not = icmp eq i64 %indvars.iv.next, %wide.trip.count
  br i1 %exitcond.not, label %._crit_edge, label %5, !llvm.loop !11

._crit_edge:                                      ; preds = %5, %2
  ret i32 0
}

; Function Attrs: nounwind
declare float @lgammaf(float noundef) local_unnamed_addr #1

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

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

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 = { 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 #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 = { mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none) }
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 = !{!"int", !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 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}


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