; LLVM IR from Ryuk17/SpeechAlgorithms :: WebRTC_VAD/src (vad_core)

; 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.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], i32 }
%struct.WebRtcSpl_State48khzTo8khz = type { [8 x i32], [16 x i32], [8 x i32], [8 x i32] }

@kOverHangMax1Q = external hidden constant [3 x i16], align 2
@kOverHangMax2Q = external hidden constant [3 x i16], align 2
@kLocalThresholdQ = external hidden constant [3 x i16], align 2
@kGlobalThresholdQ = external hidden constant [3 x i16], align 2
@kOverHangMax1LBR = external hidden constant [3 x i16], align 2
@kOverHangMax2LBR = external hidden constant [3 x i16], align 2
@kLocalThresholdLBR = external hidden constant [3 x i16], align 2
@kGlobalThresholdLBR = external hidden constant [3 x i16], align 2
@kOverHangMax1AGG = external hidden constant [3 x i16], align 2
@kOverHangMax2AGG = external hidden constant [3 x i16], align 2
@kLocalThresholdAGG = external hidden constant [3 x i16], align 2
@kGlobalThresholdAGG = external hidden constant [3 x i16], align 2
@kOverHangMax1VAG = external hidden constant [3 x i16], align 2
@kOverHangMax2VAG = external hidden constant [3 x i16], align 2
@kLocalThresholdVAG = external hidden constant [3 x i16], align 2
@kGlobalThresholdVAG = external hidden constant [3 x i16], align 2

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #0

; Function Attrs: nounwind uwtable
define dso_local i32 @WebRtcVad_set_mode_core(ptr noundef %0, i32 noundef %1) #1 {
  %3 = alloca ptr, align 8
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  store ptr %0, ptr %3, align 8, !tbaa !5
  store i32 %1, ptr %4, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #3
  store i32 0, ptr %5, align 4, !tbaa !9
  %6 = load i32, ptr %4, align 4, !tbaa !9
  switch i32 %6, label %59 [
    i32 0, label %7
    i32 1, label %20
    i32 2, label %33
    i32 3, label %46
  ]

7:                                                ; preds = %2
  %8 = load ptr, ptr %3, align 8, !tbaa !5
  %9 = getelementptr inbounds %struct.VadInstT_, ptr %8, i32 0, i32 16
  %10 = getelementptr inbounds [3 x i16], ptr %9, i64 0, i64 0
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %10, ptr align 2 @kOverHangMax1Q, i64 6, i1 false)
  %11 = load ptr, ptr %3, align 8, !tbaa !5
  %12 = getelementptr inbounds %struct.VadInstT_, ptr %11, i32 0, i32 17
  %13 = getelementptr inbounds [3 x i16], ptr %12, i64 0, i64 0
  call void @llvm.memcpy.p0.p0.i64(ptr align 2 %13, ptr align 2 @kOverHangMax2Q, i64 6, i1 false)
  %14 = load ptr, ptr %3, align 8, !tbaa !5
  %15 = getelementptr inbounds %struct.VadInstT_, ptr %14, i32 0, i32 18
  %16 = getelementptr inbounds [3 x i16], ptr %15, i64 0, i64 0
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %16, ptr align 2 @kLocalThresholdQ, i64 6, i1 false)
  %17 = load ptr, ptr %3, align 8, !tbaa !5
  %18 = getelementptr inbounds %struct.VadInstT_, ptr %17, i32 0, i32 19
  %19 = getelementptr inbounds [3 x i16], ptr %18, i64 0, i64 0
  call void @llvm.memcpy.p0.p0.i64(ptr align 2 %19, ptr align 2 @kGlobalThresholdQ, i64 6, i1 false)
  br label %60

20:                                               ; preds = %2
  %21 = load ptr, ptr %3, align 8, !tbaa !5
  %22 = getelementptr inbounds %struct.VadInstT_, ptr %21, i32 0, i32 16
  %23 = getelementptr inbounds [3 x i16], ptr %22, i64 0, i64 0
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %23, ptr align 2 @kOverHangMax1LBR, i64 6, i1 false)
  %24 = load ptr, ptr %3, align 8, !tbaa !5
  %25 = getelementptr inbounds %struct.VadInstT_, ptr %24, i32 0, i32 17
  %26 = getelementptr inbounds [3 x i16], ptr %25, i64 0, i64 0
  call void @llvm.memcpy.p0.p0.i64(ptr align 2 %26, ptr align 2 @kOverHangMax2LBR, i64 6, i1 false)
  %27 = load ptr, ptr %3, align 8, !tbaa !5
  %28 = getelementptr inbounds %struct.VadInstT_, ptr %27, i32 0, i32 18
  %29 = getelementptr inbounds [3 x i16], ptr %28, i64 0, i64 0
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %29, ptr align 2 @kLocalThresholdLBR, i64 6, i1 false)
  %30 = load ptr, ptr %3, align 8, !tbaa !5
  %31 = getelementptr inbounds %struct.VadInstT_, ptr %30, i32 0, i32 19
  %32 = getelementptr inbounds [3 x i16], ptr %31, i64 0, i64 0
  call void @llvm.memcpy.p0.p0.i64(ptr align 2 %32, ptr align 2 @kGlobalThresholdLBR, i64 6, i1 false)
  br label %60

33:                                               ; preds = %2
  %34 = load ptr, ptr %3, align 8, !tbaa !5
  %35 = getelementptr inbounds %struct.VadInstT_, ptr %34, i32 0, i32 16
  %36 = getelementptr inbounds [3 x i16], ptr %35, i64 0, i64 0
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %36, ptr align 2 @kOverHangMax1AGG, i64 6, i1 false)
  %37 = load ptr, ptr %3, align 8, !tbaa !5
  %38 = getelementptr inbounds %struct.VadInstT_, ptr %37, i32 0, i32 17
  %39 = getelementptr inbounds [3 x i16], ptr %38, i64 0, i64 0
  call void @llvm.memcpy.p0.p0.i64(ptr align 2 %39, ptr align 2 @kOverHangMax2AGG, i64 6, i1 false)
  %40 = load ptr, ptr %3, align 8, !tbaa !5
  %41 = getelementptr inbounds %struct.VadInstT_, ptr %40, i32 0, i32 18
  %42 = getelementptr inbounds [3 x i16], ptr %41, i64 0, i64 0
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %42, ptr align 2 @kLocalThresholdAGG, i64 6, i1 false)
  %43 = load ptr, ptr %3, align 8, !tbaa !5
  %44 = getelementptr inbounds %struct.VadInstT_, ptr %43, i32 0, i32 19
  %45 = getelementptr inbounds [3 x i16], ptr %44, i64 0, i64 0
  call void @llvm.memcpy.p0.p0.i64(ptr align 2 %45, ptr align 2 @kGlobalThresholdAGG, i64 6, i1 false)
  br label %60

46:                                               ; preds = %2
  %47 = load ptr, ptr %3, align 8, !tbaa !5
  %48 = getelementptr inbounds %struct.VadInstT_, ptr %47, i32 0, i32 16
  %49 = getelementptr inbounds [3 x i16], ptr %48, i64 0, i64 0
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %49, ptr align 2 @kOverHangMax1VAG, i64 6, i1 false)
  %50 = load ptr, ptr %3, align 8, !tbaa !5
  %51 = getelementptr inbounds %struct.VadInstT_, ptr %50, i32 0, i32 17
  %52 = getelementptr inbounds [3 x i16], ptr %51, i64 0, i64 0
  call void @llvm.memcpy.p0.p0.i64(ptr align 2 %52, ptr align 2 @kOverHangMax2VAG, i64 6, i1 false)
  %53 = load ptr, ptr %3, align 8, !tbaa !5
  %54 = getelementptr inbounds %struct.VadInstT_, ptr %53, i32 0, i32 18
  %55 = getelementptr inbounds [3 x i16], ptr %54, i64 0, i64 0
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %55, ptr align 2 @kLocalThresholdVAG, i64 6, i1 false)
  %56 = load ptr, ptr %3, align 8, !tbaa !5
  %57 = getelementptr inbounds %struct.VadInstT_, ptr %56, i32 0, i32 19
  %58 = getelementptr inbounds [3 x i16], ptr %57, i64 0, i64 0
  call void @llvm.memcpy.p0.p0.i64(ptr align 2 %58, ptr align 2 @kGlobalThresholdVAG, i64 6, i1 false)
  br label %60

59:                                               ; preds = %2
  store i32 -1, ptr %5, align 4, !tbaa !9
  br label %60

60:                                               ; preds = %59, %46, %33, %20, %7
  %61 = load i32, ptr %5, align 4, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #3
  ret i32 %61
}

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #0

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #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 nounwind willreturn memory(argmem: readwrite) }
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 = !{!"int", !7, i64 0}


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

@kOverHangMax1Q = external hidden local_unnamed_addr constant [3 x i16], align 2
@kOverHangMax2Q = external hidden local_unnamed_addr constant [3 x i16], align 2
@kLocalThresholdQ = external hidden local_unnamed_addr constant [3 x i16], align 2
@kGlobalThresholdQ = external hidden local_unnamed_addr constant [3 x i16], align 2
@kOverHangMax1LBR = external hidden local_unnamed_addr constant [3 x i16], align 2
@kOverHangMax2LBR = external hidden local_unnamed_addr constant [3 x i16], align 2
@kLocalThresholdLBR = external hidden local_unnamed_addr constant [3 x i16], align 2
@kGlobalThresholdLBR = external hidden local_unnamed_addr constant [3 x i16], align 2
@kOverHangMax1AGG = external hidden local_unnamed_addr constant [3 x i16], align 2
@kOverHangMax2AGG = external hidden local_unnamed_addr constant [3 x i16], align 2
@kLocalThresholdAGG = external hidden local_unnamed_addr constant [3 x i16], align 2
@kGlobalThresholdAGG = external hidden local_unnamed_addr constant [3 x i16], align 2
@kOverHangMax1VAG = external hidden local_unnamed_addr constant [3 x i16], align 2
@kOverHangMax2VAG = external hidden local_unnamed_addr constant [3 x i16], align 2
@kLocalThresholdVAG = external hidden local_unnamed_addr constant [3 x i16], align 2
@kGlobalThresholdVAG = external hidden local_unnamed_addr constant [3 x i16], align 2

; Function Attrs: mustprogress nofree norecurse nosync nounwind willreturn memory(argmem: readwrite) uwtable
define dso_local range(i32 -1, 1) i32 @WebRtcVad_set_mode_core(ptr nocapture noundef writeonly %0, i32 noundef %1) local_unnamed_addr #0 {
  switch i32 %1, label %23 [
    i32 0, label %3
    i32 1, label %8
    i32 2, label %13
    i32 3, label %18
  ]

3:                                                ; preds = %2
  %4 = getelementptr inbounds i8, ptr %0, i64 708
  tail call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 4 dereferenceable(6) %4, ptr noundef nonnull align 2 dereferenceable(6) @kOverHangMax1Q, i64 6, i1 false)
  %5 = getelementptr inbounds i8, ptr %0, i64 714
  tail call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 2 dereferenceable(6) %5, ptr noundef nonnull align 2 dereferenceable(6) @kOverHangMax2Q, i64 6, i1 false)
  %6 = getelementptr inbounds i8, ptr %0, i64 720
  tail call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 4 dereferenceable(6) %6, ptr noundef nonnull align 2 dereferenceable(6) @kLocalThresholdQ, i64 6, i1 false)
  %7 = getelementptr inbounds i8, ptr %0, i64 726
  tail call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 2 dereferenceable(6) %7, ptr noundef nonnull align 2 dereferenceable(6) @kGlobalThresholdQ, i64 6, i1 false)
  br label %23

8:                                                ; preds = %2
  %9 = getelementptr inbounds i8, ptr %0, i64 708
  tail call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 4 dereferenceable(6) %9, ptr noundef nonnull align 2 dereferenceable(6) @kOverHangMax1LBR, i64 6, i1 false)
  %10 = getelementptr inbounds i8, ptr %0, i64 714
  tail call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 2 dereferenceable(6) %10, ptr noundef nonnull align 2 dereferenceable(6) @kOverHangMax2LBR, i64 6, i1 false)
  %11 = getelementptr inbounds i8, ptr %0, i64 720
  tail call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 4 dereferenceable(6) %11, ptr noundef nonnull align 2 dereferenceable(6) @kLocalThresholdLBR, i64 6, i1 false)
  %12 = getelementptr inbounds i8, ptr %0, i64 726
  tail call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 2 dereferenceable(6) %12, ptr noundef nonnull align 2 dereferenceable(6) @kGlobalThresholdLBR, i64 6, i1 false)
  br label %23

13:                                               ; preds = %2
  %14 = getelementptr inbounds i8, ptr %0, i64 708
  tail call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 4 dereferenceable(6) %14, ptr noundef nonnull align 2 dereferenceable(6) @kOverHangMax1AGG, i64 6, i1 false)
  %15 = getelementptr inbounds i8, ptr %0, i64 714
  tail call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 2 dereferenceable(6) %15, ptr noundef nonnull align 2 dereferenceable(6) @kOverHangMax2AGG, i64 6, i1 false)
  %16 = getelementptr inbounds i8, ptr %0, i64 720
  tail call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 4 dereferenceable(6) %16, ptr noundef nonnull align 2 dereferenceable(6) @kLocalThresholdAGG, i64 6, i1 false)
  %17 = getelementptr inbounds i8, ptr %0, i64 726
  tail call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 2 dereferenceable(6) %17, ptr noundef nonnull align 2 dereferenceable(6) @kGlobalThresholdAGG, i64 6, i1 false)
  br label %23

18:                                               ; preds = %2
  %19 = getelementptr inbounds i8, ptr %0, i64 708
  tail call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 4 dereferenceable(6) %19, ptr noundef nonnull align 2 dereferenceable(6) @kOverHangMax1VAG, i64 6, i1 false)
  %20 = getelementptr inbounds i8, ptr %0, i64 714
  tail call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 2 dereferenceable(6) %20, ptr noundef nonnull align 2 dereferenceable(6) @kOverHangMax2VAG, i64 6, i1 false)
  %21 = getelementptr inbounds i8, ptr %0, i64 720
  tail call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 4 dereferenceable(6) %21, ptr noundef nonnull align 2 dereferenceable(6) @kLocalThresholdVAG, i64 6, i1 false)
  %22 = getelementptr inbounds i8, ptr %0, i64 726
  tail call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 2 dereferenceable(6) %22, ptr noundef nonnull align 2 dereferenceable(6) @kGlobalThresholdVAG, i64 6, i1 false)
  br label %23

23:                                               ; preds = %2, %18, %13, %8, %3
  %.0 = phi i32 [ 0, %18 ], [ 0, %13 ], [ 0, %8 ], [ 0, %3 ], [ -1, %2 ]
  ret i32 %.0
}

; Function Attrs: mustprogress nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #1

attributes #0 = { mustprogress nofree norecurse nosync nounwind willreturn memory(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 #1 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: readwrite) }

!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)"}


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