; LLVM IR from jgaeddert/liquid-dsp :: src/agc/src (agc_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"

@.str = external hidden unnamed_addr constant [78 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [5 x i8], align 1
@.str.13 = external hidden unnamed_addr constant [66 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

declare <2 x float> @__mulsc3(float, float, float, float)

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

; Function Attrs: nounwind uwtable
declare dso_local i32 @agc_crcf_set_signal_level(ptr noundef, float noundef) #2

; Function Attrs: nounwind uwtable
define dso_local i32 @agc_crcf_init(ptr noundef %0, ptr noundef %1, i32 noundef %2) #3 {
  %4 = alloca i32, align 4
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  %9 = alloca float, align 4
  %10 = alloca { float, float }, align 4
  store ptr %0, ptr %5, align 8, !tbaa !5
  store ptr %1, ptr %6, align 8, !tbaa !5
  store i32 %2, ptr %7, align 4, !tbaa !9
  %11 = load i32, ptr %7, align 4, !tbaa !9
  %12 = icmp eq i32 %11, 0
  br i1 %12, label %13, label %15

13:                                               ; preds = %3
  %14 = call i32 (i32, ptr, i32, ptr, ...) @liquid_error_fl(i32 noundef 3, ptr noundef @.str, i32 noundef 342, ptr noundef @.str.13, ptr noundef @.str.2)
  store i32 %14, ptr %4, align 4
  br label %71

15:                                               ; preds = %3
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #5
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #5
  store float 0.000000e+00, ptr %9, align 4, !tbaa !11
  store i32 0, ptr %8, align 4, !tbaa !9
  br label %16

16:                                               ; preds = %58, %15
  %17 = load i32, ptr %8, align 4, !tbaa !9
  %18 = load i32, ptr %7, align 4, !tbaa !9
  %19 = icmp ult i32 %17, %18
  br i1 %19, label %20, label %61

20:                                               ; preds = %16
  %21 = load ptr, ptr %6, align 8, !tbaa !5
  %22 = load i32, ptr %8, align 4, !tbaa !9
  %23 = zext i32 %22 to i64
  %24 = getelementptr inbounds { float, float }, ptr %21, i64 %23
  %25 = getelementptr inbounds { float, float }, ptr %24, i32 0, i32 0
  %26 = load float, ptr %25, align 4
  %27 = getelementptr inbounds { float, float }, ptr %24, i32 0, i32 1
  %28 = load float, ptr %27, align 4
  %29 = load ptr, ptr %6, align 8, !tbaa !5
  %30 = load i32, ptr %8, align 4, !tbaa !9
  %31 = zext i32 %30 to i64
  %32 = getelementptr inbounds { float, float }, ptr %29, i64 %31
  %33 = getelementptr inbounds { float, float }, ptr %32, i32 0, i32 0
  %34 = load float, ptr %33, align 4
  %35 = getelementptr inbounds { float, float }, ptr %32, i32 0, i32 1
  %36 = load float, ptr %35, align 4
  %37 = fneg float %36
  %38 = fmul float %26, %34
  %39 = fmul float %28, %37
  %40 = fmul float %26, %37
  %41 = fmul float %28, %34
  %42 = fsub float %38, %39
  %43 = fadd float %40, %41
  %44 = fcmp uno float %42, %42
  br i1 %44, label %45, label %53, !prof !13

45:                                               ; preds = %20
  %46 = fcmp uno float %43, %43
  br i1 %46, label %47, label %53, !prof !13

47:                                               ; preds = %45
  %48 = call <2 x float> @__mulsc3(float noundef %26, float noundef %28, float noundef %34, float noundef %37) #5
  store <2 x float> %48, ptr %10, align 4
  %49 = getelementptr inbounds { float, float }, ptr %10, i32 0, i32 0
  %50 = load float, ptr %49, align 4
  %51 = getelementptr inbounds { float, float }, ptr %10, i32 0, i32 1
  %52 = load float, ptr %51, align 4
  br label %53

53:                                               ; preds = %47, %45, %20
  %54 = phi float [ %42, %20 ], [ %42, %45 ], [ %50, %47 ]
  %55 = phi float [ %43, %20 ], [ %43, %45 ], [ %52, %47 ]
  %56 = load float, ptr %9, align 4, !tbaa !11
  %57 = fadd float %56, %54
  store float %57, ptr %9, align 4, !tbaa !11
  br label %58

58:                                               ; preds = %53
  %59 = load i32, ptr %8, align 4, !tbaa !9
  %60 = add i32 %59, 1
  store i32 %60, ptr %8, align 4, !tbaa !9
  br label %16, !llvm.loop !14

61:                                               ; preds = %16
  %62 = load float, ptr %9, align 4, !tbaa !11
  %63 = load i32, ptr %7, align 4, !tbaa !9
  %64 = uitofp i32 %63 to float
  %65 = fdiv float %62, %64
  %66 = call float @sqrtf(float noundef %65) #5
  %67 = fadd float %66, 0x3C9CD2B2A0000000
  store float %67, ptr %9, align 4, !tbaa !11
  %68 = load ptr, ptr %5, align 8, !tbaa !5
  %69 = load float, ptr %9, align 4, !tbaa !11
  %70 = call i32 @agc_crcf_set_signal_level(ptr noundef %68, float noundef %69)
  store i32 0, ptr %4, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #5
  br label %71

71:                                               ; preds = %61, %13
  %72 = load i32, ptr %4, align 4
  ret i32 %72
}

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

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"="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 #3 = { 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 #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, !12, i64 0}
!12 = !{!"float", !7, i64 0}
!13 = !{!"branch_weights", i32 1, i32 1048575}
!14 = distinct !{!14, !15}
!15 = !{!"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 [78 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [5 x i8], align 1
@.str.13 = external hidden unnamed_addr constant [66 x i8], align 1

declare <2 x float> @__mulsc3(float, float, float, float) local_unnamed_addr

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

; Function Attrs: nounwind uwtable
declare dso_local i32 @agc_crcf_set_signal_level(ptr noundef, float noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
define dso_local i32 @agc_crcf_init(ptr noundef %0, ptr nocapture noundef readonly %1, i32 noundef %2) local_unnamed_addr #2 {
  %4 = icmp eq i32 %2, 0
  br i1 %4, label %5, label %.preheader.preheader

.preheader.preheader:                             ; preds = %3
  %wide.trip.count = zext i32 %2 to i64
  br label %.preheader

5:                                                ; preds = %3
  %6 = tail call i32 (i32, ptr, i32, ptr, ...) @liquid_error_fl(i32 noundef 3, ptr noundef nonnull @.str, i32 noundef 342, ptr noundef nonnull @.str.13, ptr noundef nonnull @.str.2) #4
  br label %31

.preheader:                                       ; preds = %.preheader.preheader, %22
  %indvars.iv = phi i64 [ 0, %.preheader.preheader ], [ %indvars.iv.next, %22 ]
  %.01317 = phi float [ 0.000000e+00, %.preheader.preheader ], [ %24, %22 ]
  %7 = getelementptr inbounds { float, float }, ptr %1, i64 %indvars.iv
  %8 = load <2 x float>, ptr %7, align 4
  %9 = extractelement <2 x float> %8, i64 1
  %10 = fneg float %9
  %11 = fmul <2 x float> %8, %8
  %shift = shufflevector <2 x float> %11, <2 x float> poison, <2 x i32> <i32 1, i32 poison>
  %12 = fadd <2 x float> %11, %shift
  %13 = extractelement <2 x float> %12, i64 0
  %14 = fcmp uno float %13, 0.000000e+00
  br i1 %14, label %15, label %22, !prof !5

15:                                               ; preds = %.preheader
  %16 = extractelement <2 x float> %8, i64 0
  %17 = fmul float %16, %9
  %18 = fsub float %17, %17
  %19 = fcmp uno float %18, 0.000000e+00
  br i1 %19, label %20, label %22, !prof !5

20:                                               ; preds = %15
  %21 = tail call <2 x float> @__mulsc3(float noundef %16, float noundef %9, float noundef %16, float noundef %10) #4
  %.sroa.0.0.vec.extract = extractelement <2 x float> %21, i64 0
  br label %22

22:                                               ; preds = %20, %15, %.preheader
  %23 = phi float [ %13, %.preheader ], [ %13, %15 ], [ %.sroa.0.0.vec.extract, %20 ]
  %24 = fadd float %.01317, %23
  %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 %25, label %.preheader, !llvm.loop !6

25:                                               ; preds = %22
  %26 = uitofp i32 %2 to float
  %27 = fdiv float %24, %26
  %28 = tail call float @sqrtf(float noundef %27) #4
  %29 = fadd float %28, 0x3C9CD2B2A0000000
  %30 = tail call i32 @agc_crcf_set_signal_level(ptr noundef %0, float noundef %29)
  br label %31

31:                                               ; preds = %25, %5
  %.0 = phi i32 [ %6, %5 ], [ 0, %25 ]
  ret i32 %.0
}

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

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"="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 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 = { 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 = !{!"branch_weights", i32 1, i32 1048575}
!6 = distinct !{!6, !7}
!7 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,LCSSAPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,ReassociatePass,SLPVectorizerPass,SROAPass,SimplifyCFGPass,TailCallElimPass,VectorCombinePass