; LLVM IR from Overload-Technologies/Overload :: Dependencies/soloud/src/audiosource/speech/klatt.ll (ZN5klatt14natural_sourceEi)

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

%class.klatt = type <{ %class.resonator, %class.resonator, %class.resonator, %class.resonator, %class.resonator, %class.resonator, %class.resonator, %class.resonator, %class.resonator, %class.resonator, %class.resonator, %class.resonator, i32, float, float, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, float, float, float, float, float, i32, float, float, float, float, float, i32, i32, ptr, i32, %class.klatt_frame, [4 x i8], ptr, i32, i32, %class.Slope, %class.Slope, float, [4 x i8] }>
%class.resonator = type { float, float, float, float, float }
%class.klatt_frame = type { i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32 }
%class.Slope = type { float, i32 }

; Function Attrs: nounwind
declare double @sin(double noundef) #0

; Function Attrs: mustprogress nounwind uwtable
define dso_local noundef float @_ZN5klatt14natural_sourceEi(ptr noundef nonnull align 8 dereferenceable(564) %0, i32 noundef %1) #1 align 2 {
  %3 = alloca float, align 4
  %4 = alloca ptr, align 8
  %5 = alloca i32, align 4
  store ptr %0, ptr %4, align 8, !tbaa !5
  store i32 %1, ptr %5, align 4, !tbaa !9
  %6 = load ptr, ptr %4, align 8
  %7 = load i32, ptr %5, align 4, !tbaa !9
  %8 = getelementptr inbounds %class.klatt, ptr %6, i32 0, i32 25
  %9 = load i32, ptr %8, align 4, !tbaa !11
  %10 = icmp slt i32 %7, %9
  br i1 %10, label %11, label %66

11:                                               ; preds = %2
  %12 = getelementptr inbounds %class.klatt, ptr %6, i32 0, i32 15
  %13 = load i32, ptr %12, align 4, !tbaa !17
  switch i32 %13, label %58 [
    i32 1, label %14
    i32 2, label %20
    i32 3, label %27
    i32 4, label %34
    i32 5, label %41
    i32 6, label %49
    i32 0, label %57
  ]

14:                                               ; preds = %11
  %15 = load i32, ptr %5, align 4, !tbaa !9
  %16 = srem i32 %15, 200
  %17 = sub nsw i32 %16, 100
  %18 = sitofp i32 %17 to float
  %19 = fmul float %18, 0x40547AE140000000
  store float %19, ptr %3, align 4
  br label %67

20:                                               ; preds = %11
  %21 = load i32, ptr %5, align 4, !tbaa !9
  %22 = sitofp i32 %21 to double
  %23 = fmul double %22, 3.140000e-02
  %24 = call double @sin(double noundef %23) #3
  %25 = fmul double %24, 8.192000e+03
  %26 = fptrunc double %25 to float
  store float %26, ptr %3, align 4
  br label %67

27:                                               ; preds = %11
  %28 = load i32, ptr %5, align 4, !tbaa !9
  %29 = srem i32 %28, 200
  %30 = sub nsw i32 %29, 100
  %31 = icmp sgt i32 %30, 0
  %32 = zext i1 %31 to i64
  %33 = select i1 %31, float 8.192000e+03, float -8.192000e+03
  store float %33, ptr %3, align 4
  br label %67

34:                                               ; preds = %11
  %35 = load i32, ptr %5, align 4, !tbaa !9
  %36 = srem i32 %35, 200
  %37 = sub nsw i32 %36, 100
  %38 = icmp sgt i32 %37, 50
  %39 = zext i1 %38 to i64
  %40 = select i1 %38, float 8.192000e+03, float -8.192000e+03
  store float %40, ptr %3, align 4
  br label %67

41:                                               ; preds = %11
  %42 = getelementptr inbounds %class.klatt, ptr %6, i32 0, i32 34
  %43 = load float, ptr %42, align 8, !tbaa !18
  %44 = fptosi float %43 to i32
  %45 = and i32 %44, 1
  %46 = icmp ne i32 %45, 0
  %47 = zext i1 %46 to i64
  %48 = select i1 %46, float -8.192000e+03, float 8.192000e+03
  store float %48, ptr %3, align 4
  br label %67

49:                                               ; preds = %11
  %50 = getelementptr inbounds %class.klatt, ptr %6, i32 0, i32 34
  %51 = load float, ptr %50, align 8, !tbaa !18
  %52 = fptosi float %51 to i32
  %53 = and i32 %52, 7
  %54 = icmp ne i32 %53, 0
  %55 = zext i1 %54 to i64
  %56 = select i1 %54, float -8.192000e+03, float 8.192000e+03
  store float %56, ptr %3, align 4
  br label %67

57:                                               ; preds = %11
  br label %58

58:                                               ; preds = %57, %11
  %59 = load i32, ptr %5, align 4, !tbaa !9
  %60 = srem i32 %59, 200
  %61 = sub nsw i32 %60, 100
  %62 = call i32 @llvm.abs.i32(i32 %61, i1 true)
  %63 = sub nsw i32 %62, 50
  %64 = sitofp i32 %63 to float
  %65 = fmul float %64, 0x40647AE140000000
  store float %65, ptr %3, align 4
  br label %67

66:                                               ; preds = %2
  store float 0.000000e+00, ptr %3, align 4
  br label %67

67:                                               ; preds = %66, %58, %49, %41, %34, %27, %20, %14
  %68 = load float, ptr %3, align 4
  ret float %68
}

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i32 @llvm.abs.i32(i32, i1 immarg) #2

attributes #0 = { 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 #1 = { mustprogress 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++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = !{!12, !10, i64 292}
!12 = !{!"_ZTS5klatt", !13, i64 0, !13, i64 20, !13, i64 40, !13, i64 60, !13, i64 80, !13, i64 100, !13, i64 120, !13, i64 140, !13, i64 160, !13, i64 180, !13, i64 200, !13, i64 220, !10, i64 240, !14, i64 244, !14, i64 248, !10, i64 252, !10, i64 256, !10, i64 260, !10, i64 264, !10, i64 268, !10, i64 272, !10, i64 276, !10, i64 280, !10, i64 284, !10, i64 288, !10, i64 292, !10, i64 296, !14, i64 300, !14, i64 304, !14, i64 308, !14, i64 312, !14, i64 316, !10, i64 320, !14, i64 324, !14, i64 328, !14, i64 332, !14, i64 336, !14, i64 340, !10, i64 344, !10, i64 348, !6, i64 352, !10, i64 360, !15, i64 364, !6, i64 528, !10, i64 536, !10, i64 540, !16, i64 544, !16, i64 552, !14, i64 560}
!13 = !{!"_ZTS9resonator", !14, i64 0, !14, i64 4, !14, i64 8, !14, i64 12, !14, i64 16}
!14 = !{!"float", !7, i64 0}
!15 = !{!"_ZTS11klatt_frame", !10, i64 0, !10, i64 4, !10, i64 8, !10, i64 12, !10, i64 16, !10, i64 20, !10, i64 24, !10, i64 28, !10, i64 32, !10, i64 36, !10, i64 40, !10, i64 44, !10, i64 48, !10, i64 52, !10, i64 56, !10, i64 60, !10, i64 64, !10, i64 68, !10, i64 72, !10, i64 76, !10, i64 80, !10, i64 84, !10, i64 88, !10, i64 92, !10, i64 96, !10, i64 100, !10, i64 104, !10, i64 108, !10, i64 112, !10, i64 116, !10, i64 120, !10, i64 124, !10, i64 128, !10, i64 132, !10, i64 136, !10, i64 140, !10, i64 144, !10, i64 148, !10, i64 152, !10, i64 156}
!16 = !{!"_ZTS5Slope", !14, i64 0, !10, i64 4}
!17 = !{!12, !10, i64 252}
!18 = !{!12, !14, i64 328}


; 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: mustprogress nofree nounwind willreturn memory(write)
declare double @sin(double noundef) local_unnamed_addr #0

; Function Attrs: mustprogress nofree nounwind willreturn memory(write, argmem: readwrite) uwtable
define dso_local noundef float @_ZN5klatt14natural_sourceEi(ptr nocapture noundef nonnull readonly align 8 dereferenceable(564) %0, i32 noundef %1) local_unnamed_addr #1 align 2 {
  %3 = getelementptr inbounds i8, ptr %0, i64 292
  %4 = load i32, ptr %3, align 4, !tbaa !5
  %5 = icmp sgt i32 %4, %1
  br i1 %5, label %6, label %47

6:                                                ; preds = %2
  %7 = getelementptr inbounds i8, ptr %0, i64 252
  %8 = load i32, ptr %7, align 4, !tbaa !15
  switch i32 %8, label %40 [
    i32 1, label %9
    i32 2, label %14
    i32 3, label %20
    i32 4, label %24
    i32 5, label %28
    i32 6, label %34
  ]

9:                                                ; preds = %6
  %10 = srem i32 %1, 200
  %11 = add nsw i32 %10, -100
  %12 = sitofp i32 %11 to float
  %13 = fmul float %12, 0x40547AE140000000
  br label %47

14:                                               ; preds = %6
  %15 = sitofp i32 %1 to double
  %16 = fmul double %15, 3.140000e-02
  %17 = tail call double @sin(double noundef %16) #3
  %18 = fmul double %17, 8.192000e+03
  %19 = fptrunc double %18 to float
  br label %47

20:                                               ; preds = %6
  %21 = srem i32 %1, 200
  %22 = icmp sgt i32 %21, 100
  %23 = select i1 %22, float 8.192000e+03, float -8.192000e+03
  br label %47

24:                                               ; preds = %6
  %25 = srem i32 %1, 200
  %26 = icmp sgt i32 %25, 150
  %27 = select i1 %26, float 8.192000e+03, float -8.192000e+03
  br label %47

28:                                               ; preds = %6
  %29 = getelementptr inbounds i8, ptr %0, i64 328
  %30 = load float, ptr %29, align 8, !tbaa !16
  %31 = fptosi float %30 to i32
  %32 = and i32 %31, 1
  %.not8 = icmp eq i32 %32, 0
  %33 = select i1 %.not8, float 8.192000e+03, float -8.192000e+03
  br label %47

34:                                               ; preds = %6
  %35 = getelementptr inbounds i8, ptr %0, i64 328
  %36 = load float, ptr %35, align 8, !tbaa !16
  %37 = fptosi float %36 to i32
  %38 = and i32 %37, 7
  %.not = icmp eq i32 %38, 0
  %39 = select i1 %.not, float 8.192000e+03, float -8.192000e+03
  br label %47

40:                                               ; preds = %6
  %41 = srem i32 %1, 200
  %42 = add nsw i32 %41, -100
  %43 = tail call i32 @llvm.abs.i32(i32 %42, i1 true)
  %44 = add nsw i32 %43, -50
  %45 = sitofp i32 %44 to float
  %46 = fmul float %45, 0x40647AE140000000
  br label %47

47:                                               ; preds = %2, %40, %34, %28, %24, %20, %14, %9
  %.0 = phi float [ %46, %40 ], [ %39, %34 ], [ %33, %28 ], [ %27, %24 ], [ %23, %20 ], [ %19, %14 ], [ %13, %9 ], [ 0.000000e+00, %2 ]
  ret float %.0
}

; Function Attrs: mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i32 @llvm.abs.i32(i32, i1 immarg) #2

attributes #0 = { 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 #1 = { mustprogress nofree nounwind willreturn memory(write, argmem: readwrite) 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 = { 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, !11, i64 292}
!6 = !{!"_ZTS5klatt", !7, i64 0, !7, i64 20, !7, i64 40, !7, i64 60, !7, i64 80, !7, i64 100, !7, i64 120, !7, i64 140, !7, i64 160, !7, i64 180, !7, i64 200, !7, i64 220, !11, i64 240, !8, i64 244, !8, i64 248, !11, i64 252, !11, i64 256, !11, i64 260, !11, i64 264, !11, i64 268, !11, i64 272, !11, i64 276, !11, i64 280, !11, i64 284, !11, i64 288, !11, i64 292, !11, i64 296, !8, i64 300, !8, i64 304, !8, i64 308, !8, i64 312, !8, i64 316, !11, i64 320, !8, i64 324, !8, i64 328, !8, i64 332, !8, i64 336, !8, i64 340, !11, i64 344, !11, i64 348, !12, i64 352, !11, i64 360, !13, i64 364, !12, i64 528, !11, i64 536, !11, i64 540, !14, i64 544, !14, i64 552, !8, i64 560}
!7 = !{!"_ZTS9resonator", !8, i64 0, !8, i64 4, !8, i64 8, !8, i64 12, !8, i64 16}
!8 = !{!"float", !9, i64 0}
!9 = !{!"omnipotent char", !10, i64 0}
!10 = !{!"Simple C++ TBAA"}
!11 = !{!"int", !9, i64 0}
!12 = !{!"any pointer", !9, i64 0}
!13 = !{!"_ZTS11klatt_frame", !11, i64 0, !11, i64 4, !11, i64 8, !11, i64 12, !11, i64 16, !11, i64 20, !11, i64 24, !11, i64 28, !11, i64 32, !11, i64 36, !11, i64 40, !11, i64 44, !11, i64 48, !11, i64 52, !11, i64 56, !11, i64 60, !11, i64 64, !11, i64 68, !11, i64 72, !11, i64 76, !11, i64 80, !11, i64 84, !11, i64 88, !11, i64 92, !11, i64 96, !11, i64 100, !11, i64 104, !11, i64 108, !11, i64 112, !11, i64 116, !11, i64 120, !11, i64 124, !11, i64 128, !11, i64 132, !11, i64 136, !11, i64 140, !11, i64 144, !11, i64 148, !11, i64 152, !11, i64 156}
!14 = !{!"_ZTS5Slope", !8, i64 0, !11, i64 4}
!15 = !{!6, !11, i64 252}
!16 = !{!6, !8, i64 328}


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