; LLVM IR from jgaeddert/liquid-dsp :: src/nco/src (nco_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.nco_crcf_s = type { i32, i32, i32, ptr, ptr, i32, i32, ptr, ptr, i32, float, float }
%struct.vco_tab_e_s = type { float, float }

; 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
declare dso_local i32 @nco_crcf_static_index(ptr noundef) #1

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

; Function Attrs: nounwind uwtable
define dso_local float @nco_crcf_cos(ptr noundef %0) #1 {
  %2 = alloca ptr, align 8
  %3 = alloca float, align 4
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  store ptr %0, ptr %2, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #3
  store float 1.000000e+00, ptr %3, align 4, !tbaa !9
  %6 = load ptr, ptr %2, align 8, !tbaa !5
  %7 = getelementptr inbounds %struct.nco_crcf_s, ptr %6, i32 0, i32 0
  %8 = load i32, ptr %7, align 8, !tbaa !11
  %9 = icmp eq i32 %8, 0
  br i1 %9, label %15, label %10

10:                                               ; preds = %1
  %11 = load ptr, ptr %2, align 8, !tbaa !5
  %12 = getelementptr inbounds %struct.nco_crcf_s, ptr %11, i32 0, i32 0
  %13 = load i32, ptr %12, align 8, !tbaa !11
  %14 = icmp eq i32 %13, 1
  br i1 %14, label %15, label %65

15:                                               ; preds = %10, %1
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #3
  %16 = load ptr, ptr %2, align 8, !tbaa !5
  %17 = call i32 @nco_crcf_static_index(ptr noundef %16)
  store i32 %17, ptr %4, align 4, !tbaa !14
  %18 = load i32, ptr %4, align 4, !tbaa !14
  %19 = zext i32 %18 to i64
  %20 = add i64 %19, 256
  %21 = and i64 %20, 1023
  %22 = trunc i64 %21 to i32
  store i32 %22, ptr %4, align 4, !tbaa !14
  %23 = load ptr, ptr %2, align 8, !tbaa !5
  %24 = getelementptr inbounds %struct.nco_crcf_s, ptr %23, i32 0, i32 0
  %25 = load i32, ptr %24, align 8, !tbaa !11
  %26 = icmp eq i32 %25, 0
  br i1 %26, label %27, label %35

27:                                               ; preds = %15
  %28 = load ptr, ptr %2, align 8, !tbaa !5
  %29 = getelementptr inbounds %struct.nco_crcf_s, ptr %28, i32 0, i32 3
  %30 = load ptr, ptr %29, align 8, !tbaa !15
  %31 = load i32, ptr %4, align 4, !tbaa !14
  %32 = zext i32 %31 to i64
  %33 = getelementptr inbounds float, ptr %30, i64 %32
  %34 = load float, ptr %33, align 4, !tbaa !9
  store float %34, ptr %3, align 4, !tbaa !9
  br label %64

35:                                               ; preds = %15
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #3
  %36 = load ptr, ptr %2, align 8, !tbaa !5
  %37 = getelementptr inbounds %struct.nco_crcf_s, ptr %36, i32 0, i32 1
  %38 = load i32, ptr %37, align 4, !tbaa !16
  %39 = zext i32 %38 to i64
  %40 = add i64 %39, 1073741824
  %41 = trunc i64 %40 to i32
  store i32 %41, ptr %5, align 4, !tbaa !14
  %42 = load ptr, ptr %2, align 8, !tbaa !5
  %43 = getelementptr inbounds %struct.nco_crcf_s, ptr %42, i32 0, i32 4
  %44 = load ptr, ptr %43, align 8, !tbaa !17
  %45 = load i32, ptr %4, align 4, !tbaa !14
  %46 = zext i32 %45 to i64
  %47 = getelementptr inbounds %struct.vco_tab_e_s, ptr %44, i64 %46
  %48 = getelementptr inbounds %struct.vco_tab_e_s, ptr %47, i32 0, i32 0
  %49 = load float, ptr %48, align 4, !tbaa !18
  %50 = load i32, ptr %5, align 4, !tbaa !14
  %51 = zext i32 %50 to i64
  %52 = and i64 %51, 4194303
  %53 = trunc i64 %52 to i32
  %54 = uitofp i32 %53 to float
  %55 = load ptr, ptr %2, align 8, !tbaa !5
  %56 = getelementptr inbounds %struct.nco_crcf_s, ptr %55, i32 0, i32 4
  %57 = load ptr, ptr %56, align 8, !tbaa !17
  %58 = load i32, ptr %4, align 4, !tbaa !14
  %59 = zext i32 %58 to i64
  %60 = getelementptr inbounds %struct.vco_tab_e_s, ptr %57, i64 %59
  %61 = getelementptr inbounds %struct.vco_tab_e_s, ptr %60, i32 0, i32 1
  %62 = load float, ptr %61, align 4, !tbaa !20
  %63 = call float @llvm.fmuladd.f32(float %54, float %62, float %49)
  store float %63, ptr %3, align 4, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #3
  br label %64

64:                                               ; preds = %35, %27
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #3
  br label %81

65:                                               ; preds = %10
  %66 = load ptr, ptr %2, align 8, !tbaa !5
  %67 = getelementptr inbounds %struct.nco_crcf_s, ptr %66, i32 0, i32 0
  %68 = load i32, ptr %67, align 8, !tbaa !11
  %69 = icmp eq i32 %68, 2
  br i1 %69, label %70, label %80

70:                                               ; preds = %65
  %71 = load ptr, ptr %2, align 8, !tbaa !5
  %72 = getelementptr inbounds %struct.nco_crcf_s, ptr %71, i32 0, i32 8
  %73 = load ptr, ptr %72, align 8, !tbaa !21
  %74 = load ptr, ptr %2, align 8, !tbaa !5
  %75 = getelementptr inbounds %struct.nco_crcf_s, ptr %74, i32 0, i32 9
  %76 = load i32, ptr %75, align 8, !tbaa !22
  %77 = zext i32 %76 to i64
  %78 = getelementptr inbounds float, ptr %73, i64 %77
  %79 = load float, ptr %78, align 4, !tbaa !9
  store float %79, ptr %3, align 4, !tbaa !9
  br label %80

80:                                               ; preds = %70, %65
  br label %81

81:                                               ; preds = %80, %64
  %82 = load float, ptr %3, align 4, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #3
  ret float %82
}

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 = { 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, !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 = !{!"float", !7, i64 0}
!11 = !{!12, !13, i64 0}
!12 = !{!"nco_crcf_s", !13, i64 0, !13, i64 4, !13, i64 8, !6, i64 16, !6, i64 24, !13, i64 32, !13, i64 36, !6, i64 40, !6, i64 48, !13, i64 56, !10, i64 60, !10, i64 64}
!13 = !{!"int", !7, i64 0}
!14 = !{!13, !13, i64 0}
!15 = !{!12, !6, i64 16}
!16 = !{!12, !13, i64 4}
!17 = !{!12, !6, i64 24}
!18 = !{!19, !10, i64 0}
!19 = !{!"vco_tab_e_s", !10, i64 0, !10, i64 4}
!20 = !{!19, !10, i64 4}
!21 = !{!12, !6, i64 48}
!22 = !{!12, !13, i64 56}


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

%struct.vco_tab_e_s = type { float, float }

; Function Attrs: nounwind uwtable
declare dso_local i32 @nco_crcf_static_index(ptr noundef) local_unnamed_addr #0

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

; Function Attrs: nounwind uwtable
define dso_local float @nco_crcf_cos(ptr noundef %0) local_unnamed_addr #0 {
  %2 = load i32, ptr %0, align 8, !tbaa !5
  switch i32 %2, label %36 [
    i32 0, label %3
    i32 1, label %3
    i32 2, label %28
  ]

3:                                                ; preds = %1, %1
  %4 = tail call i32 @nco_crcf_static_index(ptr noundef nonnull %0)
  %5 = add i32 %4, 256
  %6 = and i32 %5, 1023
  %7 = load i32, ptr %0, align 8, !tbaa !5
  %8 = icmp eq i32 %7, 0
  br i1 %8, label %9, label %15

9:                                                ; preds = %3
  %10 = getelementptr inbounds i8, ptr %0, i64 16
  %11 = load ptr, ptr %10, align 8, !tbaa !12
  %12 = zext nneg i32 %6 to i64
  %13 = getelementptr inbounds float, ptr %11, i64 %12
  %14 = load float, ptr %13, align 4, !tbaa !13
  br label %36

15:                                               ; preds = %3
  %16 = getelementptr inbounds i8, ptr %0, i64 4
  %17 = load i32, ptr %16, align 4, !tbaa !14
  %18 = getelementptr inbounds i8, ptr %0, i64 24
  %19 = load ptr, ptr %18, align 8, !tbaa !15
  %20 = zext nneg i32 %6 to i64
  %21 = getelementptr inbounds %struct.vco_tab_e_s, ptr %19, i64 %20
  %22 = load float, ptr %21, align 4, !tbaa !16
  %23 = and i32 %17, 4194303
  %24 = uitofp nneg i32 %23 to float
  %25 = getelementptr inbounds i8, ptr %21, i64 4
  %26 = load float, ptr %25, align 4, !tbaa !18
  %27 = tail call float @llvm.fmuladd.f32(float %24, float %26, float %22)
  br label %36

28:                                               ; preds = %1
  %29 = getelementptr inbounds i8, ptr %0, i64 48
  %30 = load ptr, ptr %29, align 8, !tbaa !19
  %31 = getelementptr inbounds i8, ptr %0, i64 56
  %32 = load i32, ptr %31, align 8, !tbaa !20
  %33 = zext i32 %32 to i64
  %34 = getelementptr inbounds float, ptr %30, i64 %33
  %35 = load float, ptr %34, align 4, !tbaa !13
  br label %36

36:                                               ; preds = %1, %9, %15, %28
  %.1 = phi float [ %35, %28 ], [ %14, %9 ], [ %27, %15 ], [ 1.000000e+00, %1 ]
  ret float %.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 = { mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none) }

!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 0}
!6 = !{!"nco_crcf_s", !7, i64 0, !7, i64 4, !7, i64 8, !10, i64 16, !10, i64 24, !7, i64 32, !7, i64 36, !10, i64 40, !10, i64 48, !7, i64 56, !11, i64 60, !11, i64 64}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"any pointer", !8, i64 0}
!11 = !{!"float", !8, i64 0}
!12 = !{!6, !10, i64 16}
!13 = !{!11, !11, i64 0}
!14 = !{!6, !7, i64 4}
!15 = !{!6, !10, i64 24}
!16 = !{!17, !11, i64 0}
!17 = !{!"vco_tab_e_s", !11, i64 0, !11, i64 4}
!18 = !{!17, !11, i64 4}
!19 = !{!6, !10, i64 48}
!20 = !{!6, !7, i64 56}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,SROAPass,SimplifyCFGPass,TailCallElimPass