; LLVM IR from glaretechnologies/substrata :: opus/opus-1.3.1/silk (control_SNR)

; 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.silk_encoder_state = type { [2 x i32], i32, i32, %struct.silk_LP_state, %struct.silk_VAD_state, %struct.silk_nsq_state, [16 x i16], i32, i32, i8, i8, 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, ptr, ptr, ptr, [4 x i32], i32, i32, [3 x i8], i8, [3 x i32], %struct.SideInfoIndices, [320 x i8], i32, [322 x i16], i32, i32, i32, i32, i32, i32, i32, i32, i16, %struct._silk_resampler_state_struct, i32, i32, i32, i32, i32, i32, [3 x %struct.SideInfoIndices], [3 x [320 x i8]] }
%struct.silk_LP_state = type { [2 x i32], i32, i32, i32 }
%struct.silk_VAD_state = type { [2 x i32], [2 x i32], [2 x i32], [4 x i32], [4 x i32], i16, [4 x i32], [4 x i32], [4 x i32], i32 }
%struct.silk_nsq_state = type { [640 x i16], [640 x i32], [96 x i32], [24 x i32], i32, i32, i32, i32, i32, i32, i32, i32 }
%struct.SideInfoIndices = type { [4 x i8], [4 x i8], [17 x i8], i16, i8, i8, i8, i8, i8, i8, i8 }
%struct._silk_resampler_state_struct = type { [6 x i32], %union.anon, [48 x i16], i32, i32, i32, i32, i32, i32, i32, i32, ptr }
%union.anon = type { [36 x i32] }

@silk_TargetRate_NB_21 = external hidden constant [107 x i8], align 16
@silk_TargetRate_MB_21 = external hidden constant [155 x i8], align 16
@silk_TargetRate_WB_21 = external hidden constant [191 x i8], align 16

; Function Attrs: nounwind uwtable
define dso_local i32 @silk_control_SNR(ptr noundef %0, i32 noundef %1) #0 {
  %3 = alloca ptr, align 8
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  %7 = alloca ptr, align 8
  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) #2
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #2
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #2
  %8 = load i32, ptr %4, align 4, !tbaa !9
  %9 = load ptr, ptr %3, align 8, !tbaa !5
  %10 = getelementptr inbounds %struct.silk_encoder_state, ptr %9, i32 0, i32 27
  store i32 %8, ptr %10, align 8, !tbaa !11
  %11 = load ptr, ptr %3, align 8, !tbaa !5
  %12 = getelementptr inbounds %struct.silk_encoder_state, ptr %11, i32 0, i32 20
  %13 = load i32, ptr %12, align 4, !tbaa !19
  %14 = icmp eq i32 %13, 2
  br i1 %14, label %15, label %23

15:                                               ; preds = %2
  %16 = load ptr, ptr %3, align 8, !tbaa !5
  %17 = getelementptr inbounds %struct.silk_encoder_state, ptr %16, i32 0, i32 19
  %18 = load i32, ptr %17, align 8, !tbaa !20
  %19 = sdiv i32 %18, 16
  %20 = add nsw i32 2000, %19
  %21 = load i32, ptr %4, align 4, !tbaa !9
  %22 = sub nsw i32 %21, %20
  store i32 %22, ptr %4, align 4, !tbaa !9
  br label %23

23:                                               ; preds = %15, %2
  %24 = load ptr, ptr %3, align 8, !tbaa !5
  %25 = getelementptr inbounds %struct.silk_encoder_state, ptr %24, i32 0, i32 19
  %26 = load i32, ptr %25, align 8, !tbaa !20
  %27 = icmp eq i32 %26, 8
  br i1 %27, label %28, label %29

28:                                               ; preds = %23
  store i32 107, ptr %6, align 4, !tbaa !9
  store ptr @silk_TargetRate_NB_21, ptr %7, align 8, !tbaa !5
  br label %37

29:                                               ; preds = %23
  %30 = load ptr, ptr %3, align 8, !tbaa !5
  %31 = getelementptr inbounds %struct.silk_encoder_state, ptr %30, i32 0, i32 19
  %32 = load i32, ptr %31, align 8, !tbaa !20
  %33 = icmp eq i32 %32, 12
  br i1 %33, label %34, label %35

34:                                               ; preds = %29
  store i32 155, ptr %6, align 4, !tbaa !9
  store ptr @silk_TargetRate_MB_21, ptr %7, align 8, !tbaa !5
  br label %36

35:                                               ; preds = %29
  store i32 191, ptr %6, align 4, !tbaa !9
  store ptr @silk_TargetRate_WB_21, ptr %7, align 8, !tbaa !5
  br label %36

36:                                               ; preds = %35, %34
  br label %37

37:                                               ; preds = %36, %28
  %38 = load i32, ptr %4, align 4, !tbaa !9
  %39 = add nsw i32 %38, 200
  %40 = sdiv i32 %39, 400
  store i32 %40, ptr %5, align 4, !tbaa !9
  %41 = load i32, ptr %5, align 4, !tbaa !9
  %42 = sub nsw i32 %41, 10
  %43 = load i32, ptr %6, align 4, !tbaa !9
  %44 = sub nsw i32 %43, 1
  %45 = icmp slt i32 %42, %44
  br i1 %45, label %46, label %49

46:                                               ; preds = %37
  %47 = load i32, ptr %5, align 4, !tbaa !9
  %48 = sub nsw i32 %47, 10
  br label %52

49:                                               ; preds = %37
  %50 = load i32, ptr %6, align 4, !tbaa !9
  %51 = sub nsw i32 %50, 1
  br label %52

52:                                               ; preds = %49, %46
  %53 = phi i32 [ %48, %46 ], [ %51, %49 ]
  store i32 %53, ptr %5, align 4, !tbaa !9
  %54 = load i32, ptr %5, align 4, !tbaa !9
  %55 = icmp sle i32 %54, 0
  br i1 %55, label %56, label %59

56:                                               ; preds = %52
  %57 = load ptr, ptr %3, align 8, !tbaa !5
  %58 = getelementptr inbounds %struct.silk_encoder_state, ptr %57, i32 0, i32 51
  store i32 0, ptr %58, align 4, !tbaa !21
  br label %69

59:                                               ; preds = %52
  %60 = load ptr, ptr %7, align 8, !tbaa !5
  %61 = load i32, ptr %5, align 4, !tbaa !9
  %62 = sext i32 %61 to i64
  %63 = getelementptr inbounds i8, ptr %60, i64 %62
  %64 = load i8, ptr %63, align 1, !tbaa !22
  %65 = zext i8 %64 to i32
  %66 = mul nsw i32 %65, 21
  %67 = load ptr, ptr %3, align 8, !tbaa !5
  %68 = getelementptr inbounds %struct.silk_encoder_state, ptr %67, i32 0, i32 51
  store i32 %66, ptr %68, align 4, !tbaa !21
  br label %69

69:                                               ; preds = %59, %56
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #2
  ret i32 0
}

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

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { 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, !10, i64 4608}
!12 = !{!"", !7, i64 0, !10, i64 8, !10, i64 12, !13, i64 16, !14, i64 36, !16, i64 148, !7, i64 4500, !10, i64 4532, !10, i64 4536, !7, i64 4540, !7, i64 4541, !10, i64 4544, !10, i64 4548, !10, i64 4552, !10, i64 4556, !10, i64 4560, !10, i64 4564, !10, i64 4568, !10, i64 4572, !10, i64 4576, !10, i64 4580, !10, i64 4584, !10, i64 4588, !10, i64 4592, !10, i64 4596, !10, i64 4600, !10, i64 4604, !10, i64 4608, !10, i64 4612, !10, i64 4616, !10, i64 4620, !10, i64 4624, !10, i64 4628, !10, i64 4632, !10, i64 4636, !10, i64 4640, !10, i64 4644, !10, i64 4648, !10, i64 4652, !10, i64 4656, !10, i64 4660, !10, i64 4664, !10, i64 4668, !10, i64 4672, !10, i64 4676, !10, i64 4680, !6, i64 4688, !6, i64 4696, !6, i64 4704, !7, i64 4712, !10, i64 4728, !10, i64 4732, !7, i64 4736, !7, i64 4739, !7, i64 4740, !17, i64 4752, !7, i64 4788, !10, i64 5108, !7, i64 5112, !10, i64 5756, !10, i64 5760, !10, i64 5764, !10, i64 5768, !10, i64 5772, !10, i64 5776, !10, i64 5780, !10, i64 5784, !15, i64 5788, !18, i64 5792, !10, i64 6096, !10, i64 6100, !10, i64 6104, !10, i64 6108, !10, i64 6112, !10, i64 6116, !7, i64 6120, !7, i64 6228}
!13 = !{!"", !7, i64 0, !10, i64 8, !10, i64 12, !10, i64 16}
!14 = !{!"", !7, i64 0, !7, i64 8, !7, i64 16, !7, i64 24, !7, i64 40, !15, i64 56, !7, i64 60, !7, i64 76, !7, i64 92, !10, i64 108}
!15 = !{!"short", !7, i64 0}
!16 = !{!"", !7, i64 0, !7, i64 1280, !7, i64 3840, !7, i64 4224, !10, i64 4320, !10, i64 4324, !10, i64 4328, !10, i64 4332, !10, i64 4336, !10, i64 4340, !10, i64 4344, !10, i64 4348}
!17 = !{!"", !7, i64 0, !7, i64 4, !7, i64 8, !15, i64 26, !7, i64 28, !7, i64 29, !7, i64 30, !7, i64 31, !7, i64 32, !7, i64 33, !7, i64 34}
!18 = !{!"_silk_resampler_state_struct", !7, i64 0, !7, i64 24, !7, i64 168, !10, i64 264, !10, i64 268, !10, i64 272, !10, i64 276, !10, i64 280, !10, i64 284, !10, i64 288, !10, i64 292, !6, i64 296}
!19 = !{!12, !10, i64 4580}
!20 = !{!12, !10, i64 4576}
!21 = !{!12, !10, i64 4732}
!22 = !{!7, !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"

@silk_TargetRate_NB_21 = external hidden local_unnamed_addr constant [107 x i8], align 16
@silk_TargetRate_MB_21 = external hidden local_unnamed_addr constant [155 x i8], align 16
@silk_TargetRate_WB_21 = external hidden local_unnamed_addr constant [191 x i8], align 16

; Function Attrs: mustprogress nofree norecurse nosync nounwind willreturn memory(argmem: readwrite) uwtable
define dso_local noundef i32 @silk_control_SNR(ptr nocapture noundef %0, i32 noundef %1) local_unnamed_addr #0 {
  %3 = getelementptr inbounds i8, ptr %0, i64 4608
  store i32 %1, ptr %3, align 8, !tbaa !5
  %4 = getelementptr inbounds i8, ptr %0, i64 4580
  %5 = load i32, ptr %4, align 4, !tbaa !17
  %6 = icmp eq i32 %5, 2
  %7 = getelementptr inbounds i8, ptr %0, i64 4576
  %8 = load i32, ptr %7, align 8, !tbaa !18
  br i1 %6, label %9, label %._crit_edge

9:                                                ; preds = %2
  %.neg = sdiv i32 %8, -16
  %.neg20 = add i32 %1, -2000
  %10 = add i32 %.neg20, %.neg
  br label %._crit_edge

._crit_edge:                                      ; preds = %2, %9
  %.017 = phi i32 [ %10, %9 ], [ %1, %2 ]
  switch i32 %8, label %12 [
    i32 8, label %13
    i32 12, label %11
  ]

11:                                               ; preds = %._crit_edge
  br label %13

12:                                               ; preds = %._crit_edge
  br label %13

13:                                               ; preds = %._crit_edge, %11, %12
  %.016 = phi i32 [ 154, %11 ], [ 190, %12 ], [ 106, %._crit_edge ]
  %.0 = phi ptr [ @silk_TargetRate_MB_21, %11 ], [ @silk_TargetRate_WB_21, %12 ], [ @silk_TargetRate_NB_21, %._crit_edge ]
  %14 = icmp slt i32 %.017, 4200
  br i1 %14, label %25, label %15

15:                                               ; preds = %13
  %16 = add nuw nsw i32 %.017, 200
  %17 = udiv i32 %16, 400
  %18 = add nsw i32 %17, -10
  %19 = tail call i32 @llvm.umin.i32(i32 %18, i32 %.016)
  %20 = zext nneg i32 %19 to i64
  %21 = getelementptr inbounds i8, ptr %.0, i64 %20
  %22 = load i8, ptr %21, align 1, !tbaa !19
  %23 = zext i8 %22 to i32
  %24 = mul nuw nsw i32 %23, 21
  br label %25

25:                                               ; preds = %13, %15
  %.sink = phi i32 [ %24, %15 ], [ 0, %13 ]
  %26 = getelementptr inbounds i8, ptr %0, i64 4732
  store i32 %.sink, ptr %26, align 4
  ret i32 0
}

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i32 @llvm.umin.i32(i32, i32) #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 = { 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, !9, i64 4608}
!6 = !{!"", !7, i64 0, !9, i64 8, !9, i64 12, !10, i64 16, !11, i64 36, !13, i64 148, !7, i64 4500, !9, i64 4532, !9, i64 4536, !7, i64 4540, !7, i64 4541, !9, i64 4544, !9, i64 4548, !9, i64 4552, !9, i64 4556, !9, i64 4560, !9, i64 4564, !9, i64 4568, !9, i64 4572, !9, i64 4576, !9, i64 4580, !9, i64 4584, !9, i64 4588, !9, i64 4592, !9, i64 4596, !9, i64 4600, !9, i64 4604, !9, i64 4608, !9, i64 4612, !9, i64 4616, !9, i64 4620, !9, i64 4624, !9, i64 4628, !9, i64 4632, !9, i64 4636, !9, i64 4640, !9, i64 4644, !9, i64 4648, !9, i64 4652, !9, i64 4656, !9, i64 4660, !9, i64 4664, !9, i64 4668, !9, i64 4672, !9, i64 4676, !9, i64 4680, !14, i64 4688, !14, i64 4696, !14, i64 4704, !7, i64 4712, !9, i64 4728, !9, i64 4732, !7, i64 4736, !7, i64 4739, !7, i64 4740, !15, i64 4752, !7, i64 4788, !9, i64 5108, !7, i64 5112, !9, i64 5756, !9, i64 5760, !9, i64 5764, !9, i64 5768, !9, i64 5772, !9, i64 5776, !9, i64 5780, !9, i64 5784, !12, i64 5788, !16, i64 5792, !9, i64 6096, !9, i64 6100, !9, i64 6104, !9, i64 6108, !9, i64 6112, !9, i64 6116, !7, i64 6120, !7, i64 6228}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!"int", !7, i64 0}
!10 = !{!"", !7, i64 0, !9, i64 8, !9, i64 12, !9, i64 16}
!11 = !{!"", !7, i64 0, !7, i64 8, !7, i64 16, !7, i64 24, !7, i64 40, !12, i64 56, !7, i64 60, !7, i64 76, !7, i64 92, !9, i64 108}
!12 = !{!"short", !7, i64 0}
!13 = !{!"", !7, i64 0, !7, i64 1280, !7, i64 3840, !7, i64 4224, !9, i64 4320, !9, i64 4324, !9, i64 4328, !9, i64 4332, !9, i64 4336, !9, i64 4340, !9, i64 4344, !9, i64 4348}
!14 = !{!"any pointer", !7, i64 0}
!15 = !{!"", !7, i64 0, !7, i64 4, !7, i64 8, !12, i64 26, !7, i64 28, !7, i64 29, !7, i64 30, !7, i64 31, !7, i64 32, !7, i64 33, !7, i64 34}
!16 = !{!"_silk_resampler_state_struct", !7, i64 0, !7, i64 24, !7, i64 168, !9, i64 264, !9, i64 268, !9, i64 272, !9, i64 276, !9, i64 280, !9, i64 284, !9, i64 288, !9, i64 292, !14, i64 296}
!17 = !{!6, !9, i64 4580}
!18 = !{!6, !9, i64 4576}
!19 = !{!7, !7, i64 0}


; Effective O3 passes: BDCEPass,CorrelatedValuePropagationPass,EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,MergedLoadStoreMotionPass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass