; LLVM IR from jgaeddert/liquid-dsp :: src/framing/src (framing_crcf)

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

declare i32 @bsequence_push(ptr noundef, i32 noundef) #1

; 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 @bsync_crcf_correlate(ptr noundef %0, <2 x float> noundef %1, ptr noundef %2) #2 {
  %4 = alloca { float, float }, align 4
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca float, align 4
  %8 = alloca float, align 4
  store <2 x float> %1, ptr %4, align 4
  store ptr %0, ptr %5, align 8, !tbaa !5
  store ptr %2, ptr %6, align 8, !tbaa !5
  %9 = load ptr, ptr %5, align 8, !tbaa !5
  %10 = getelementptr inbounds %struct.bsync_crcf_s, ptr %9, i32 0, i32 2
  %11 = load ptr, ptr %10, align 8, !tbaa !9
  %12 = getelementptr inbounds { float, float }, ptr %4, i32 0, i32 0
  %13 = load float, ptr %12, align 4
  %14 = getelementptr inbounds { float, float }, ptr %4, i32 0, i32 1
  %15 = load float, ptr %14, align 4
  %16 = fpext float %13 to double
  %17 = fcmp ogt double %16, 0.000000e+00
  %18 = zext i1 %17 to i64
  %19 = select i1 %17, i32 1, i32 0
  %20 = call i32 @bsequence_push(ptr noundef %11, i32 noundef %19)
  %21 = load ptr, ptr %5, align 8, !tbaa !5
  %22 = getelementptr inbounds %struct.bsync_crcf_s, ptr %21, i32 0, i32 4
  %23 = load ptr, ptr %22, align 8, !tbaa !12
  %24 = getelementptr inbounds { float, float }, ptr %4, i32 0, i32 0
  %25 = load float, ptr %24, align 4
  %26 = getelementptr inbounds { float, float }, ptr %4, i32 0, i32 1
  %27 = load float, ptr %26, align 4
  %28 = fpext float %27 to double
  %29 = fcmp ogt double %28, 0.000000e+00
  %30 = zext i1 %29 to i64
  %31 = select i1 %29, i32 1, i32 0
  %32 = call i32 @bsequence_push(ptr noundef %23, i32 noundef %31)
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #4
  %33 = load ptr, ptr %5, align 8, !tbaa !5
  %34 = getelementptr inbounds %struct.bsync_crcf_s, ptr %33, i32 0, i32 1
  %35 = load ptr, ptr %34, align 8, !tbaa !13
  %36 = load ptr, ptr %5, align 8, !tbaa !5
  %37 = getelementptr inbounds %struct.bsync_crcf_s, ptr %36, i32 0, i32 2
  %38 = load ptr, ptr %37, align 8, !tbaa !9
  %39 = call i32 @bsequence_correlate(ptr noundef %35, ptr noundef %38)
  %40 = sitofp i32 %39 to double
  %41 = load ptr, ptr %5, align 8, !tbaa !5
  %42 = getelementptr inbounds %struct.bsync_crcf_s, ptr %41, i32 0, i32 0
  %43 = load i32, ptr %42, align 8, !tbaa !14
  %44 = uitofp i32 %43 to float
  %45 = fpext float %44 to double
  %46 = fneg double %45
  %47 = call double @llvm.fmuladd.f64(double 2.000000e+00, double %40, double %46)
  %48 = fptrunc double %47 to float
  store float %48, ptr %7, align 4, !tbaa !15
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #4
  %49 = load ptr, ptr %5, align 8, !tbaa !5
  %50 = getelementptr inbounds %struct.bsync_crcf_s, ptr %49, i32 0, i32 1
  %51 = load ptr, ptr %50, align 8, !tbaa !13
  %52 = load ptr, ptr %5, align 8, !tbaa !5
  %53 = getelementptr inbounds %struct.bsync_crcf_s, ptr %52, i32 0, i32 4
  %54 = load ptr, ptr %53, align 8, !tbaa !12
  %55 = call i32 @bsequence_correlate(ptr noundef %51, ptr noundef %54)
  %56 = sitofp i32 %55 to double
  %57 = load ptr, ptr %5, align 8, !tbaa !5
  %58 = getelementptr inbounds %struct.bsync_crcf_s, ptr %57, i32 0, i32 0
  %59 = load i32, ptr %58, align 8, !tbaa !14
  %60 = uitofp i32 %59 to float
  %61 = fpext float %60 to double
  %62 = fneg double %61
  %63 = call double @llvm.fmuladd.f64(double 2.000000e+00, double %56, double %62)
  %64 = fptrunc double %63 to float
  store float %64, ptr %8, align 4, !tbaa !15
  %65 = load float, ptr %7, align 4, !tbaa !15
  %66 = load float, ptr %8, align 4, !tbaa !15
  %67 = fmul float 0.000000e+00, %66
  %68 = fmul float 1.000000e+00, %66
  %69 = fadd float %65, %67
  %70 = load ptr, ptr %5, align 8, !tbaa !5
  %71 = getelementptr inbounds %struct.bsync_crcf_s, ptr %70, i32 0, i32 5
  %72 = getelementptr inbounds { float, float }, ptr %71, i32 0, i32 0
  %73 = getelementptr inbounds { float, float }, ptr %71, i32 0, i32 1
  store float %69, ptr %72, align 8
  store float %68, ptr %73, align 4
  %74 = load ptr, ptr %5, align 8, !tbaa !5
  %75 = getelementptr inbounds %struct.bsync_crcf_s, ptr %74, i32 0, i32 5
  %76 = getelementptr inbounds { float, float }, ptr %75, i32 0, i32 0
  %77 = load float, ptr %76, align 8
  %78 = getelementptr inbounds { float, float }, ptr %75, i32 0, i32 1
  %79 = load float, ptr %78, align 4
  %80 = load ptr, ptr %5, align 8, !tbaa !5
  %81 = getelementptr inbounds %struct.bsync_crcf_s, ptr %80, i32 0, i32 0
  %82 = load i32, ptr %81, align 8, !tbaa !14
  %83 = uitofp i32 %82 to float
  %84 = fdiv float %77, %83
  %85 = fdiv float %79, %83
  %86 = load ptr, ptr %6, align 8, !tbaa !5
  %87 = getelementptr inbounds { float, float }, ptr %86, i32 0, i32 0
  %88 = getelementptr inbounds { float, float }, ptr %86, i32 0, i32 1
  store float %84, ptr %87, align 4
  store float %85, ptr %88, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #4
  ret i32 0
}

declare i32 @bsequence_correlate(ptr noundef, ptr noundef) #1

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

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 uwtable "min-legal-vector-width"="64" "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 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !6, i64 16}
!10 = !{!"bsync_crcf_s", !11, i64 0, !6, i64 8, !6, i64 16, !6, i64 24, !6, i64 32, !7, i64 40}
!11 = !{!"int", !7, i64 0}
!12 = !{!10, !6, i64 32}
!13 = !{!10, !6, i64 8}
!14 = !{!10, !11, i64 0}
!15 = !{!16, !16, i64 0}
!16 = !{!"float", !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"

declare i32 @bsequence_push(ptr noundef, i32 noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local noundef i32 @bsync_crcf_correlate(ptr nocapture noundef %0, <2 x float> noundef %1, ptr nocapture noundef writeonly %2) local_unnamed_addr #1 {
  %4 = getelementptr inbounds i8, ptr %0, i64 16
  %5 = load ptr, ptr %4, align 8, !tbaa !5
  %.sroa.0.0.vec.extract = extractelement <2 x float> %1, i64 0
  %6 = fcmp ogt float %.sroa.0.0.vec.extract, 0.000000e+00
  %7 = zext i1 %6 to i32
  %8 = tail call i32 @bsequence_push(ptr noundef %5, i32 noundef %7) #3
  %9 = getelementptr inbounds i8, ptr %0, i64 32
  %10 = load ptr, ptr %9, align 8, !tbaa !11
  %.sroa.0.4.vec.extract17 = extractelement <2 x float> %1, i64 1
  %11 = fcmp ogt float %.sroa.0.4.vec.extract17, 0.000000e+00
  %12 = zext i1 %11 to i32
  %13 = tail call i32 @bsequence_push(ptr noundef %10, i32 noundef %12) #3
  %14 = getelementptr inbounds i8, ptr %0, i64 8
  %15 = load ptr, ptr %14, align 8, !tbaa !12
  %16 = load ptr, ptr %4, align 8, !tbaa !5
  %17 = tail call i32 @bsequence_correlate(ptr noundef %15, ptr noundef %16) #3
  %18 = sitofp i32 %17 to double
  %19 = load i32, ptr %0, align 8, !tbaa !13
  %20 = uitofp i32 %19 to float
  %21 = fpext float %20 to double
  %22 = fneg double %21
  %23 = tail call double @llvm.fmuladd.f64(double %18, double 2.000000e+00, double %22)
  %24 = fptrunc double %23 to float
  %25 = load ptr, ptr %14, align 8, !tbaa !12
  %26 = load ptr, ptr %9, align 8, !tbaa !11
  %27 = tail call i32 @bsequence_correlate(ptr noundef %25, ptr noundef %26) #3
  %28 = sitofp i32 %27 to double
  %29 = load i32, ptr %0, align 8, !tbaa !13
  %30 = uitofp i32 %29 to float
  %31 = fpext float %30 to double
  %32 = fneg double %31
  %33 = tail call double @llvm.fmuladd.f64(double %28, double 2.000000e+00, double %32)
  %34 = fptrunc double %33 to float
  %35 = fmul float %34, 0.000000e+00
  %36 = fadd float %35, %24
  %37 = getelementptr inbounds i8, ptr %0, i64 40
  %38 = getelementptr inbounds i8, ptr %0, i64 44
  store float %36, ptr %37, align 8
  store float %34, ptr %38, align 4
  %39 = insertelement <2 x float> poison, float %36, i64 0
  %40 = insertelement <2 x float> %39, float %34, i64 1
  %41 = insertelement <2 x float> poison, float %30, i64 0
  %42 = shufflevector <2 x float> %41, <2 x float> poison, <2 x i32> zeroinitializer
  %43 = fdiv <2 x float> %40, %42
  store <2 x float> %43, ptr %2, align 4
  ret i32 0
}

declare i32 @bsequence_correlate(ptr noundef, ptr noundef) local_unnamed_addr #0

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

attributes #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 uwtable "min-legal-vector-width"="64" "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 = { 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 16}
!6 = !{!"bsync_crcf_s", !7, i64 0, !10, i64 8, !10, i64 16, !10, i64 24, !10, i64 32, !8, i64 40}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"any pointer", !8, i64 0}
!11 = !{!6, !10, i64 32}
!12 = !{!6, !10, i64 8}
!13 = !{!6, !7, i64 0}


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