; LLVM IR from jgaeddert/liquid-dsp :: examples (firdespm_callback_example)

; 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: nounwind uwtable
define dso_local i32 @callback(double noundef %0, ptr noundef %1, ptr noundef %2, ptr noundef %3) #0 {
  %5 = alloca double, align 8
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca ptr, align 8
  %9 = alloca i32, align 4
  %10 = alloca double, align 8
  %11 = alloca double, align 8
  store double %0, ptr %5, align 8, !tbaa !5
  store ptr %1, ptr %6, align 8, !tbaa !9
  store ptr %2, ptr %7, align 8, !tbaa !9
  store ptr %3, ptr %8, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #5
  %12 = load ptr, ptr %6, align 8, !tbaa !9
  %13 = load i32, ptr %12, align 4, !tbaa !11
  store i32 %13, ptr %9, align 4, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #5
  %14 = load i32, ptr %9, align 4, !tbaa !11
  %15 = uitofp i32 %14 to double
  %16 = load double, ptr %5, align 8, !tbaa !5
  %17 = fmul double %15, %16
  %18 = fptrunc double %17 to float
  %19 = call float @sincf(float noundef %18)
  %20 = fpext float %19 to double
  store double %20, ptr %10, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #5
  %21 = load i32, ptr %9, align 4, !tbaa !11
  %22 = uitofp i32 %21 to float
  %23 = fdiv float 1.000000e+00, %22
  %24 = fpext float %23 to double
  store double %24, ptr %11, align 8, !tbaa !5
  %25 = load double, ptr %5, align 8, !tbaa !5
  %26 = load double, ptr %11, align 8, !tbaa !5
  %27 = fcmp olt double %25, %26
  br i1 %27, label %28, label %33

28:                                               ; preds = %4
  %29 = load double, ptr %10, align 8, !tbaa !5
  %30 = fdiv double 1.000000e+00, %29
  %31 = load ptr, ptr %7, align 8, !tbaa !9
  store double %30, ptr %31, align 8, !tbaa !5
  %32 = load ptr, ptr %8, align 8, !tbaa !9
  store double 4.000000e+00, ptr %32, align 8, !tbaa !5
  br label %43

33:                                               ; preds = %4
  %34 = load ptr, ptr %7, align 8, !tbaa !9
  store double 0.000000e+00, ptr %34, align 8, !tbaa !5
  %35 = load double, ptr %10, align 8, !tbaa !5
  %36 = call double @llvm.fabs.f64(double %35)
  %37 = fmul double 1.000000e+01, %36
  %38 = load double, ptr %5, align 8, !tbaa !5
  %39 = fmul double 4.000000e+00, %38
  %40 = call double @exp(double noundef %39) #5
  %41 = fmul double %37, %40
  %42 = load ptr, ptr %8, align 8, !tbaa !9
  store double %41, ptr %42, align 8, !tbaa !5
  br label %43

43:                                               ; preds = %33, %28
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #5
  ret i32 0
}

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #1

declare float @sincf(float noundef) #2

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare double @llvm.fabs.f64(double) #3

; Function Attrs: nounwind
declare double @exp(double noundef) #4

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
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 = !{!"double", !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 = !{!"int", !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 @callback(double noundef %0, ptr nocapture noundef readonly %1, ptr nocapture noundef writeonly %2, ptr nocapture noundef writeonly %3) local_unnamed_addr #0 {
  %5 = load i32, ptr %1, align 4, !tbaa !5
  %6 = uitofp i32 %5 to double
  %7 = fmul double %6, %0
  %8 = fptrunc double %7 to float
  %9 = tail call float @sincf(float noundef %8) #4
  %10 = fpext float %9 to double
  %11 = uitofp i32 %5 to float
  %12 = fdiv float 1.000000e+00, %11
  %13 = fpext float %12 to double
  %14 = fcmp ogt double %13, %0
  br i1 %14, label %15, label %17

15:                                               ; preds = %4
  %16 = fdiv double 1.000000e+00, %10
  store double %16, ptr %2, align 8, !tbaa !9
  br label %23

17:                                               ; preds = %4
  store double 0.000000e+00, ptr %2, align 8, !tbaa !9
  %18 = tail call double @llvm.fabs.f64(double %10)
  %19 = fmul double %18, 1.000000e+01
  %20 = fmul double %0, 4.000000e+00
  %21 = tail call double @exp(double noundef %20) #4
  %22 = fmul double %19, %21
  br label %23

23:                                               ; preds = %17, %15
  %storemerge = phi double [ %22, %17 ], [ 4.000000e+00, %15 ]
  store double %storemerge, ptr %3, align 8, !tbaa !9
  ret i32 0
}

declare float @sincf(float noundef) local_unnamed_addr #1

; Function Attrs: mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare double @llvm.fabs.f64(double) #2

; Function Attrs: mustprogress nofree nounwind willreturn memory(write)
declare double @exp(double noundef) local_unnamed_addr #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 = { "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 nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #3 = { 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 #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 = !{!"double", !7, i64 0}


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