; LLVM IR from gtreshchev/RuntimeAudioImporter :: Source/ThirdParty/libfvad/src (fvad)

; 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.Fvad = type { %struct.VadInstT_, i64 }
%struct.VadInstT_ = type { i32, [4 x i32], %struct.WebRtcSpl_State48khzTo8khz, [12 x i16], [12 x i16], [12 x i16], [12 x i16], i32, i16, i16, [96 x i16], [96 x i16], [6 x i16], [5 x i16], [5 x i16], [4 x i16], [3 x i16], [3 x i16], [3 x i16], [3 x i16], [6 x i16], i16, i32 }
%struct.WebRtcSpl_State48khzTo8khz = type { [8 x i32], [16 x i32], [8 x i32], [8 x i32] }

@.str = external hidden unnamed_addr constant [5 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [102 x i8], align 1
@__PRETTY_FUNCTION__.fvad_set_sample_rate = external hidden unnamed_addr constant [38 x i8], align 1
@valid_rates = external hidden constant [4 x i32], align 16

; 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: noreturn nounwind
declare void @__assert_fail(ptr noundef, ptr noundef, i32 noundef, ptr noundef) #1

; Function Attrs: nounwind uwtable
define dso_local i32 @fvad_set_sample_rate(ptr noundef %0, i32 noundef %1) #2 {
  %3 = alloca i32, align 4
  %4 = alloca ptr, align 8
  %5 = alloca i32, align 4
  %6 = alloca i64, align 8
  %7 = alloca i32, align 4
  store ptr %0, ptr %4, align 8, !tbaa !5
  store i32 %1, ptr %5, align 4, !tbaa !9
  %8 = load ptr, ptr %4, align 8, !tbaa !5
  %9 = icmp ne ptr %8, null
  br i1 %9, label %10, label %11

10:                                               ; preds = %2
  br label %12

11:                                               ; preds = %2
  call void @__assert_fail(ptr noundef @.str, ptr noundef @.str.1, i32 noundef 74, ptr noundef @__PRETTY_FUNCTION__.fvad_set_sample_rate) #3
  unreachable

12:                                               ; preds = %10
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #4
  store i64 0, ptr %6, align 8, !tbaa !11
  br label %13

13:                                               ; preds = %29, %12
  %14 = load i64, ptr %6, align 8, !tbaa !11
  %15 = icmp ult i64 %14, 4
  br i1 %15, label %17, label %16

16:                                               ; preds = %13
  store i32 2, ptr %7, align 4
  br label %32

17:                                               ; preds = %13
  %18 = load i64, ptr %6, align 8, !tbaa !11
  %19 = getelementptr inbounds [4 x i32], ptr @valid_rates, i64 0, i64 %18
  %20 = load i32, ptr %19, align 4, !tbaa !9
  %21 = mul nsw i32 %20, 1000
  %22 = load i32, ptr %5, align 4, !tbaa !9
  %23 = icmp eq i32 %21, %22
  br i1 %23, label %24, label %28

24:                                               ; preds = %17
  %25 = load i64, ptr %6, align 8, !tbaa !11
  %26 = load ptr, ptr %4, align 8, !tbaa !5
  %27 = getelementptr inbounds %struct.Fvad, ptr %26, i32 0, i32 1
  store i64 %25, ptr %27, align 8, !tbaa !13
  store i32 0, ptr %3, align 4
  store i32 1, ptr %7, align 4
  br label %32

28:                                               ; preds = %17
  br label %29

29:                                               ; preds = %28
  %30 = load i64, ptr %6, align 8, !tbaa !11
  %31 = add i64 %30, 1
  store i64 %31, ptr %6, align 8, !tbaa !11
  br label %13, !llvm.loop !18

32:                                               ; preds = %24, %16
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #4
  %33 = load i32, ptr %7, align 4
  switch i32 %33, label %37 [
    i32 2, label %34
    i32 1, label %35
  ]

34:                                               ; preds = %32
  store i32 -1, ptr %3, align 4
  br label %35

35:                                               ; preds = %34, %32
  %36 = load i32, ptr %3, align 4
  ret i32 %36

37:                                               ; preds = %32
  unreachable
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { noreturn 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 #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 = { noreturn nounwind }
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, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"long", !7, i64 0}
!13 = !{!14, !12, i64 752}
!14 = !{!"Fvad", !15, i64 0, !12, i64 752}
!15 = !{!"VadInstT_", !10, i64 0, !7, i64 4, !16, i64 20, !7, i64 180, !7, i64 204, !7, i64 228, !7, i64 252, !10, i64 276, !17, i64 280, !17, i64 282, !7, i64 284, !7, i64 476, !7, i64 668, !7, i64 680, !7, i64 690, !7, i64 700, !7, i64 708, !7, i64 714, !7, i64 720, !7, i64 726, !7, i64 732, !17, i64 744, !10, i64 748}
!16 = !{!"", !7, i64 0, !7, i64 32, !7, i64 96, !7, i64 128}
!17 = !{!"short", !7, i64 0}
!18 = distinct !{!18, !19}
!19 = !{!"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 [5 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [102 x i8], align 1
@__PRETTY_FUNCTION__.fvad_set_sample_rate = external hidden unnamed_addr constant [38 x i8], align 1
@valid_rates = external hidden local_unnamed_addr constant [4 x i32], align 16

; Function Attrs: noreturn nounwind
declare void @__assert_fail(ptr noundef, ptr noundef, i32 noundef, ptr noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local range(i32 -1, 1) i32 @fvad_set_sample_rate(ptr noundef writeonly %0, i32 noundef %1) local_unnamed_addr #1 {
  %.not = icmp eq ptr %0, null
  br i1 %.not, label %6, label %.preheader.preheader

.preheader.preheader:                             ; preds = %2
  %3 = load i32, ptr @valid_rates, align 16, !tbaa !5
  %4 = mul nsw i32 %3, 1000
  %5 = icmp eq i32 %4, %1
  br i1 %5, label %7, label %.preheader.1

6:                                                ; preds = %2
  tail call void @__assert_fail(ptr noundef nonnull @.str, ptr noundef nonnull @.str.1, i32 noundef 74, ptr noundef nonnull @__PRETTY_FUNCTION__.fvad_set_sample_rate) #2
  unreachable

7:                                                ; preds = %.preheader.3, %.preheader.2, %.preheader.1, %.preheader.preheader
  %.0813.lcssa = phi i64 [ 0, %.preheader.preheader ], [ 1, %.preheader.1 ], [ 2, %.preheader.2 ], [ 3, %.preheader.3 ]
  %8 = getelementptr inbounds i8, ptr %0, i64 752
  store i64 %.0813.lcssa, ptr %8, align 8, !tbaa !9
  br label %.loopexit

.preheader.1:                                     ; preds = %.preheader.preheader
  %9 = load i32, ptr getelementptr inbounds (i8, ptr @valid_rates, i64 4), align 4, !tbaa !5
  %10 = mul nsw i32 %9, 1000
  %11 = icmp eq i32 %10, %1
  br i1 %11, label %7, label %.preheader.2

.preheader.2:                                     ; preds = %.preheader.1
  %12 = load i32, ptr getelementptr inbounds (i8, ptr @valid_rates, i64 8), align 8, !tbaa !5
  %13 = mul nsw i32 %12, 1000
  %14 = icmp eq i32 %13, %1
  br i1 %14, label %7, label %.preheader.3

.preheader.3:                                     ; preds = %.preheader.2
  %15 = load i32, ptr getelementptr inbounds (i8, ptr @valid_rates, i64 12), align 4, !tbaa !5
  %16 = mul nsw i32 %15, 1000
  %17 = icmp eq i32 %16, %1
  br i1 %17, label %7, label %.loopexit

.loopexit:                                        ; preds = %.preheader.3, %7
  %spec.select = phi i32 [ 0, %7 ], [ -1, %.preheader.3 ]
  ret i32 %spec.select
}

attributes #0 = { noreturn 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 = { 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 = { noreturn 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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !14, i64 752}
!10 = !{!"Fvad", !11, i64 0, !14, i64 752}
!11 = !{!"VadInstT_", !6, i64 0, !7, i64 4, !12, i64 20, !7, i64 180, !7, i64 204, !7, i64 228, !7, i64 252, !6, i64 276, !13, i64 280, !13, i64 282, !7, i64 284, !7, i64 476, !7, i64 668, !7, i64 680, !7, i64 690, !7, i64 700, !7, i64 708, !7, i64 714, !7, i64 720, !7, i64 726, !7, i64 732, !13, i64 744, !6, i64 748}
!12 = !{!"", !7, i64 0, !7, i64 32, !7, i64 96, !7, i64 128}
!13 = !{!"short", !7, i64 0}
!14 = !{!"long", !7, i64 0}


; Effective O3 passes: CorrelatedValuePropagationPass,GVNPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferAlignmentPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LCSSAPass,LoopRotatePass,LoopSimplifyPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass