; 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
define dso_local float @nco_crcf_sin(ptr noundef %0) #1 {
  %2 = alloca ptr, align 8
  %3 = alloca float, align 4
  %4 = 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 0.000000e+00, ptr %3, align 4, !tbaa !9
  %5 = load ptr, ptr %2, align 8, !tbaa !5
  %6 = getelementptr inbounds %struct.nco_crcf_s, ptr %5, i32 0, i32 0
  %7 = load i32, ptr %6, align 8, !tbaa !11
  %8 = icmp eq i32 %7, 0
  br i1 %8, label %14, label %9

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

14:                                               ; preds = %9, %1
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #3
  %15 = load ptr, ptr %2, align 8, !tbaa !5
  %16 = call i32 @nco_crcf_static_index(ptr noundef %15)
  store i32 %16, ptr %4, align 4, !tbaa !14
  %17 = load ptr, ptr %2, align 8, !tbaa !5
  %18 = getelementptr inbounds %struct.nco_crcf_s, ptr %17, i32 0, i32 0
  %19 = load i32, ptr %18, align 8, !tbaa !11
  %20 = icmp eq i32 %19, 0
  br i1 %20, label %21, label %29

21:                                               ; preds = %14
  %22 = load ptr, ptr %2, align 8, !tbaa !5
  %23 = getelementptr inbounds %struct.nco_crcf_s, ptr %22, i32 0, i32 3
  %24 = load ptr, ptr %23, align 8, !tbaa !15
  %25 = load i32, ptr %4, align 4, !tbaa !14
  %26 = zext i32 %25 to i64
  %27 = getelementptr inbounds float, ptr %24, i64 %26
  %28 = load float, ptr %27, align 4, !tbaa !9
  store float %28, ptr %3, align 4, !tbaa !9
  br label %54

29:                                               ; preds = %14
  %30 = load ptr, ptr %2, align 8, !tbaa !5
  %31 = getelementptr inbounds %struct.nco_crcf_s, ptr %30, i32 0, i32 4
  %32 = load ptr, ptr %31, align 8, !tbaa !16
  %33 = load i32, ptr %4, align 4, !tbaa !14
  %34 = zext i32 %33 to i64
  %35 = getelementptr inbounds %struct.vco_tab_e_s, ptr %32, i64 %34
  %36 = getelementptr inbounds %struct.vco_tab_e_s, ptr %35, i32 0, i32 0
  %37 = load float, ptr %36, align 4, !tbaa !17
  %38 = load ptr, ptr %2, align 8, !tbaa !5
  %39 = getelementptr inbounds %struct.nco_crcf_s, ptr %38, i32 0, i32 1
  %40 = load i32, ptr %39, align 4, !tbaa !19
  %41 = zext i32 %40 to i64
  %42 = and i64 %41, 4194303
  %43 = trunc i64 %42 to i32
  %44 = uitofp i32 %43 to float
  %45 = load ptr, ptr %2, align 8, !tbaa !5
  %46 = getelementptr inbounds %struct.nco_crcf_s, ptr %45, i32 0, i32 4
  %47 = load ptr, ptr %46, align 8, !tbaa !16
  %48 = load i32, ptr %4, align 4, !tbaa !14
  %49 = zext i32 %48 to i64
  %50 = getelementptr inbounds %struct.vco_tab_e_s, ptr %47, i64 %49
  %51 = getelementptr inbounds %struct.vco_tab_e_s, ptr %50, i32 0, i32 1
  %52 = load float, ptr %51, align 4, !tbaa !20
  %53 = call float @llvm.fmuladd.f32(float %44, float %52, float %37)
  store float %53, ptr %3, align 4, !tbaa !9
  br label %54

54:                                               ; preds = %29, %21
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #3
  br label %71

55:                                               ; preds = %9
  %56 = load ptr, ptr %2, align 8, !tbaa !5
  %57 = getelementptr inbounds %struct.nco_crcf_s, ptr %56, i32 0, i32 0
  %58 = load i32, ptr %57, align 8, !tbaa !11
  %59 = icmp eq i32 %58, 2
  br i1 %59, label %60, label %70

60:                                               ; preds = %55
  %61 = load ptr, ptr %2, align 8, !tbaa !5
  %62 = getelementptr inbounds %struct.nco_crcf_s, ptr %61, i32 0, i32 7
  %63 = load ptr, ptr %62, align 8, !tbaa !21
  %64 = load ptr, ptr %2, align 8, !tbaa !5
  %65 = getelementptr inbounds %struct.nco_crcf_s, ptr %64, i32 0, i32 9
  %66 = load i32, ptr %65, align 8, !tbaa !22
  %67 = zext i32 %66 to i64
  %68 = getelementptr inbounds float, ptr %63, i64 %67
  %69 = load float, ptr %68, align 4, !tbaa !9
  store float %69, ptr %3, align 4, !tbaa !9
  br label %70

70:                                               ; preds = %60, %55
  br label %71

71:                                               ; preds = %70, %54
  %72 = load float, ptr %3, align 4, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #3
  ret float %72
}

; 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

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, !6, i64 24}
!17 = !{!18, !10, i64 0}
!18 = !{!"vco_tab_e_s", !10, i64 0, !10, i64 4}
!19 = !{!12, !13, i64 4}
!20 = !{!18, !10, i64 4}
!21 = !{!12, !6, i64 40}
!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
define dso_local float @nco_crcf_sin(ptr noundef %0) local_unnamed_addr #0 {
  %2 = load i32, ptr %0, align 8, !tbaa !5
  switch i32 %2, label %33 [
    i32 0, label %3
    i32 1, label %3
    i32 2, label %25
  ]

3:                                                ; preds = %1, %1
  %4 = tail call i32 @nco_crcf_static_index(ptr noundef nonnull %0)
  %5 = load i32, ptr %0, align 8, !tbaa !5
  %6 = icmp eq i32 %5, 0
  %7 = zext i32 %4 to i64
  br i1 %6, label %8, label %13

8:                                                ; preds = %3
  %9 = getelementptr inbounds i8, ptr %0, i64 16
  %10 = load ptr, ptr %9, align 8, !tbaa !12
  %11 = getelementptr inbounds float, ptr %10, i64 %7
  %12 = load float, ptr %11, align 4, !tbaa !13
  br label %33

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

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

33:                                               ; preds = %1, %8, %13, %25
  %.1 = phi float [ %32, %25 ], [ %12, %8 ], [ %24, %13 ], [ 0.000000e+00, %1 ]
  ret float %.1
}

; 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

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, !10, i64 24}
!15 = !{!16, !11, i64 0}
!16 = !{!"vco_tab_e_s", !11, i64 0, !11, i64 4}
!17 = !{!6, !7, i64 4}
!18 = !{!16, !11, i64 4}
!19 = !{!6, !10, i64 40}
!20 = !{!6, !7, i64 56}


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