; LLVM IR from Ryuk17/SpeechAlgorithms :: WebRTC_AGC/src (agc)

; 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.LegacyAgc = type { i32, i16, i16, i16, i8, %struct.WebRtcAgcConfig, %struct.WebRtcAgcConfig, i16, i16, i32, i32, i32, i32, i32, i32, i32, i16, i16, [8 x i32], i32, i32, i32, i32, i32, i32, [10 x i32], [2 x [5 x i32]], [2 x [10 x i32]], i16, i16, i16, i16, i16, i16, i16, i16, i16, i16, i16, i16, i16, i16, i32, i16, i32, i32, i32, i32, i32, i32, i32, i32, i32, i16, %struct.AgcVad, %struct.DigitalAgc, i16 }
%struct.WebRtcAgcConfig = type { i16, i16, i8 }
%struct.AgcVad = type { [8 x i32], i16, i16, i16, i16, i32, i16, i16, i32, i16 }
%struct.DigitalAgc = type { i32, i32, i32, [32 x i32], i16, i16, %struct.AgcVad, %struct.AgcVad }

@kTargetLevelTable = external hidden constant [64 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: inlinehint nounwind uwtable
declare hidden signext i16 @DivW32W16ResW16(i32 noundef, i16 noundef signext) #1

; Function Attrs: nounwind uwtable
define dso_local void @WebRtcAgc_UpdateAgcThresholds(ptr noundef %0) #2 {
  %2 = alloca ptr, align 8
  %3 = alloca i16, align 2
  store ptr %0, ptr %2, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 2, ptr %3) #3
  %4 = load ptr, ptr %2, align 8, !tbaa !5
  %5 = getelementptr inbounds %struct.LegacyAgc, ptr %4, i32 0, i32 1
  %6 = load i16, ptr %5, align 4, !tbaa !9
  %7 = sext i16 %6 to i32
  %8 = mul nsw i32 5, %7
  %9 = add nsw i32 %8, 5
  %10 = trunc i32 %9 to i16
  store i16 %10, ptr %3, align 2, !tbaa !16
  %11 = load i16, ptr %3, align 2, !tbaa !16
  %12 = sext i16 %11 to i32
  %13 = call signext i16 @DivW32W16ResW16(i32 noundef %12, i16 noundef signext 11)
  store i16 %13, ptr %3, align 2, !tbaa !16
  %14 = load i16, ptr %3, align 2, !tbaa !16
  %15 = sext i16 %14 to i32
  %16 = add nsw i32 4, %15
  %17 = trunc i32 %16 to i16
  %18 = load ptr, ptr %2, align 8, !tbaa !5
  %19 = getelementptr inbounds %struct.LegacyAgc, ptr %18, i32 0, i32 17
  store i16 %17, ptr %19, align 2, !tbaa !17
  %20 = load ptr, ptr %2, align 8, !tbaa !5
  %21 = getelementptr inbounds %struct.LegacyAgc, ptr %20, i32 0, i32 17
  %22 = load i16, ptr %21, align 2, !tbaa !17
  %23 = sext i16 %22 to i32
  %24 = icmp slt i32 %23, 4
  br i1 %24, label %25, label %28

25:                                               ; preds = %1
  %26 = load ptr, ptr %2, align 8, !tbaa !5
  %27 = getelementptr inbounds %struct.LegacyAgc, ptr %26, i32 0, i32 17
  store i16 4, ptr %27, align 2, !tbaa !17
  br label %28

28:                                               ; preds = %25, %1
  %29 = load ptr, ptr %2, align 8, !tbaa !5
  %30 = getelementptr inbounds %struct.LegacyAgc, ptr %29, i32 0, i32 3
  %31 = load i16, ptr %30, align 4, !tbaa !18
  %32 = sext i16 %31 to i32
  %33 = icmp eq i32 %32, 3
  br i1 %33, label %34, label %40

34:                                               ; preds = %28
  %35 = load ptr, ptr %2, align 8, !tbaa !5
  %36 = getelementptr inbounds %struct.LegacyAgc, ptr %35, i32 0, i32 1
  %37 = load i16, ptr %36, align 4, !tbaa !9
  %38 = load ptr, ptr %2, align 8, !tbaa !5
  %39 = getelementptr inbounds %struct.LegacyAgc, ptr %38, i32 0, i32 17
  store i16 %37, ptr %39, align 2, !tbaa !17
  br label %40

40:                                               ; preds = %34, %28
  %41 = load ptr, ptr %2, align 8, !tbaa !5
  %42 = getelementptr inbounds %struct.LegacyAgc, ptr %41, i32 0, i32 16
  store i16 20, ptr %42, align 4, !tbaa !19
  %43 = load ptr, ptr %2, align 8, !tbaa !5
  %44 = getelementptr inbounds %struct.LegacyAgc, ptr %43, i32 0, i32 16
  %45 = load i16, ptr %44, align 4, !tbaa !19
  %46 = zext i16 %45 to i64
  %47 = getelementptr inbounds [64 x i32], ptr @kTargetLevelTable, i64 0, i64 %46
  %48 = load i32, ptr %47, align 4, !tbaa !20
  %49 = mul nsw i32 10, %48
  %50 = load ptr, ptr %2, align 8, !tbaa !5
  %51 = getelementptr inbounds %struct.LegacyAgc, ptr %50, i32 0, i32 9
  store i32 %49, ptr %51, align 4, !tbaa !21
  %52 = load ptr, ptr %2, align 8, !tbaa !5
  %53 = getelementptr inbounds %struct.LegacyAgc, ptr %52, i32 0, i32 16
  %54 = load i16, ptr %53, align 4, !tbaa !19
  %55 = zext i16 %54 to i32
  %56 = sub nsw i32 %55, 1
  %57 = sext i32 %56 to i64
  %58 = getelementptr inbounds [64 x i32], ptr @kTargetLevelTable, i64 0, i64 %57
  %59 = load i32, ptr %58, align 4, !tbaa !20
  %60 = mul nsw i32 10, %59
  %61 = load ptr, ptr %2, align 8, !tbaa !5
  %62 = getelementptr inbounds %struct.LegacyAgc, ptr %61, i32 0, i32 10
  store i32 %60, ptr %62, align 4, !tbaa !22
  %63 = load ptr, ptr %2, align 8, !tbaa !5
  %64 = getelementptr inbounds %struct.LegacyAgc, ptr %63, i32 0, i32 16
  %65 = load i16, ptr %64, align 4, !tbaa !19
  %66 = zext i16 %65 to i32
  %67 = add nsw i32 %66, 1
  %68 = sext i32 %67 to i64
  %69 = getelementptr inbounds [64 x i32], ptr @kTargetLevelTable, i64 0, i64 %68
  %70 = load i32, ptr %69, align 4, !tbaa !20
  %71 = mul nsw i32 10, %70
  %72 = load ptr, ptr %2, align 8, !tbaa !5
  %73 = getelementptr inbounds %struct.LegacyAgc, ptr %72, i32 0, i32 11
  store i32 %71, ptr %73, align 4, !tbaa !23
  %74 = load ptr, ptr %2, align 8, !tbaa !5
  %75 = getelementptr inbounds %struct.LegacyAgc, ptr %74, i32 0, i32 16
  %76 = load i16, ptr %75, align 4, !tbaa !19
  %77 = zext i16 %76 to i32
  %78 = sub nsw i32 %77, 2
  %79 = sext i32 %78 to i64
  %80 = getelementptr inbounds [64 x i32], ptr @kTargetLevelTable, i64 0, i64 %79
  %81 = load i32, ptr %80, align 4, !tbaa !20
  %82 = mul nsw i32 10, %81
  %83 = load ptr, ptr %2, align 8, !tbaa !5
  %84 = getelementptr inbounds %struct.LegacyAgc, ptr %83, i32 0, i32 12
  store i32 %82, ptr %84, align 4, !tbaa !24
  %85 = load ptr, ptr %2, align 8, !tbaa !5
  %86 = getelementptr inbounds %struct.LegacyAgc, ptr %85, i32 0, i32 16
  %87 = load i16, ptr %86, align 4, !tbaa !19
  %88 = zext i16 %87 to i32
  %89 = add nsw i32 %88, 2
  %90 = sext i32 %89 to i64
  %91 = getelementptr inbounds [64 x i32], ptr @kTargetLevelTable, i64 0, i64 %90
  %92 = load i32, ptr %91, align 4, !tbaa !20
  %93 = mul nsw i32 10, %92
  %94 = load ptr, ptr %2, align 8, !tbaa !5
  %95 = getelementptr inbounds %struct.LegacyAgc, ptr %94, i32 0, i32 13
  store i32 %93, ptr %95, align 4, !tbaa !25
  %96 = load ptr, ptr %2, align 8, !tbaa !5
  %97 = getelementptr inbounds %struct.LegacyAgc, ptr %96, i32 0, i32 16
  %98 = load i16, ptr %97, align 4, !tbaa !19
  %99 = zext i16 %98 to i32
  %100 = sub nsw i32 %99, 5
  %101 = sext i32 %100 to i64
  %102 = getelementptr inbounds [64 x i32], ptr @kTargetLevelTable, i64 0, i64 %101
  %103 = load i32, ptr %102, align 4, !tbaa !20
  %104 = mul nsw i32 10, %103
  %105 = load ptr, ptr %2, align 8, !tbaa !5
  %106 = getelementptr inbounds %struct.LegacyAgc, ptr %105, i32 0, i32 14
  store i32 %104, ptr %106, align 4, !tbaa !26
  %107 = load ptr, ptr %2, align 8, !tbaa !5
  %108 = getelementptr inbounds %struct.LegacyAgc, ptr %107, i32 0, i32 16
  %109 = load i16, ptr %108, align 4, !tbaa !19
  %110 = zext i16 %109 to i32
  %111 = add nsw i32 %110, 5
  %112 = sext i32 %111 to i64
  %113 = getelementptr inbounds [64 x i32], ptr @kTargetLevelTable, i64 0, i64 %112
  %114 = load i32, ptr %113, align 4, !tbaa !20
  %115 = mul nsw i32 10, %114
  %116 = load ptr, ptr %2, align 8, !tbaa !5
  %117 = getelementptr inbounds %struct.LegacyAgc, ptr %116, i32 0, i32 15
  store i32 %115, ptr %117, align 4, !tbaa !27
  %118 = load ptr, ptr %2, align 8, !tbaa !5
  %119 = getelementptr inbounds %struct.LegacyAgc, ptr %118, i32 0, i32 10
  %120 = load i32, ptr %119, align 4, !tbaa !22
  %121 = load ptr, ptr %2, align 8, !tbaa !5
  %122 = getelementptr inbounds %struct.LegacyAgc, ptr %121, i32 0, i32 19
  store i32 %120, ptr %122, align 4, !tbaa !28
  %123 = load ptr, ptr %2, align 8, !tbaa !5
  %124 = getelementptr inbounds %struct.LegacyAgc, ptr %123, i32 0, i32 11
  %125 = load i32, ptr %124, align 4, !tbaa !23
  %126 = load ptr, ptr %2, align 8, !tbaa !5
  %127 = getelementptr inbounds %struct.LegacyAgc, ptr %126, i32 0, i32 20
  store i32 %125, ptr %127, align 4, !tbaa !29
  call void @llvm.lifetime.end.p0(i64 2, ptr %3) #3
  ret void
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { inlinehint 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 = { 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 = { 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, !12, i64 4}
!10 = !{!"", !11, i64 0, !12, i64 4, !12, i64 6, !12, i64 8, !7, i64 10, !13, i64 12, !13, i64 18, !12, i64 24, !12, i64 26, !11, i64 28, !11, i64 32, !11, i64 36, !11, i64 40, !11, i64 44, !11, i64 48, !11, i64 52, !12, i64 56, !12, i64 58, !7, i64 60, !11, i64 92, !11, i64 96, !11, i64 100, !11, i64 104, !11, i64 108, !11, i64 112, !7, i64 116, !7, i64 156, !7, i64 196, !12, i64 276, !12, i64 278, !12, i64 280, !12, i64 282, !12, i64 284, !12, i64 286, !12, i64 288, !12, i64 290, !12, i64 292, !12, i64 294, !12, i64 296, !12, i64 298, !12, i64 300, !12, i64 302, !11, i64 304, !12, i64 308, !11, i64 312, !11, i64 316, !11, i64 320, !11, i64 324, !11, i64 328, !11, i64 332, !11, i64 336, !11, i64 340, !11, i64 344, !12, i64 348, !14, i64 352, !15, i64 408, !12, i64 664}
!11 = !{!"int", !7, i64 0}
!12 = !{!"short", !7, i64 0}
!13 = !{!"", !12, i64 0, !12, i64 2, !7, i64 4}
!14 = !{!"", !7, i64 0, !12, i64 32, !12, i64 34, !12, i64 36, !12, i64 38, !11, i64 40, !12, i64 44, !12, i64 46, !11, i64 48, !12, i64 52}
!15 = !{!"", !11, i64 0, !11, i64 4, !11, i64 8, !7, i64 12, !12, i64 140, !12, i64 142, !14, i64 144, !14, i64 200}
!16 = !{!12, !12, i64 0}
!17 = !{!10, !12, i64 58}
!18 = !{!10, !12, i64 8}
!19 = !{!10, !12, i64 56}
!20 = !{!11, !11, i64 0}
!21 = !{!10, !11, i64 28}
!22 = !{!10, !11, i64 32}
!23 = !{!10, !11, i64 36}
!24 = !{!10, !11, i64 40}
!25 = !{!10, !11, i64 44}
!26 = !{!10, !11, i64 48}
!27 = !{!10, !11, i64 52}
!28 = !{!10, !11, i64 92}
!29 = !{!10, !11, i64 96}


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

@kTargetLevelTable = external hidden local_unnamed_addr constant [64 x i32], align 16

; Function Attrs: inlinehint nounwind uwtable
declare hidden signext i16 @DivW32W16ResW16(i32 noundef, i16 noundef signext) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local void @WebRtcAgc_UpdateAgcThresholds(ptr nocapture noundef %0) local_unnamed_addr #1 {
  %2 = getelementptr inbounds i8, ptr %0, i64 4
  %3 = load i16, ptr %2, align 4, !tbaa !5
  %4 = mul i16 %3, 5
  %5 = add i16 %4, 5
  %6 = sext i16 %5 to i32
  %7 = tail call signext i16 @DivW32W16ResW16(i32 noundef %6, i16 noundef signext 11)
  %8 = add i16 %7, 4
  %9 = getelementptr inbounds i8, ptr %0, i64 58
  %10 = icmp ugt i16 %7, 32763
  %spec.select = select i1 %10, i16 4, i16 %8
  store i16 %spec.select, ptr %9, align 2, !tbaa !14
  %11 = getelementptr inbounds i8, ptr %0, i64 8
  %12 = load i16, ptr %11, align 4, !tbaa !15
  %13 = icmp eq i16 %12, 3
  br i1 %13, label %14, label %16

14:                                               ; preds = %1
  %15 = load i16, ptr %2, align 4, !tbaa !5
  store i16 %15, ptr %9, align 2, !tbaa !14
  br label %16

16:                                               ; preds = %14, %1
  %17 = getelementptr inbounds i8, ptr %0, i64 56
  store i16 20, ptr %17, align 4, !tbaa !16
  %18 = load i32, ptr getelementptr inbounds (i8, ptr @kTargetLevelTable, i64 80), align 16, !tbaa !17
  %19 = mul nsw i32 %18, 10
  %20 = getelementptr inbounds i8, ptr %0, i64 28
  store i32 %19, ptr %20, align 4, !tbaa !18
  %21 = load i32, ptr getelementptr inbounds (i8, ptr @kTargetLevelTable, i64 76), align 4, !tbaa !17
  %22 = mul nsw i32 %21, 10
  %23 = getelementptr inbounds i8, ptr %0, i64 32
  store i32 %22, ptr %23, align 4, !tbaa !19
  %24 = load i32, ptr getelementptr inbounds (i8, ptr @kTargetLevelTable, i64 84), align 4, !tbaa !17
  %25 = mul nsw i32 %24, 10
  %26 = getelementptr inbounds i8, ptr %0, i64 36
  store i32 %25, ptr %26, align 4, !tbaa !20
  %27 = load i32, ptr getelementptr inbounds (i8, ptr @kTargetLevelTable, i64 72), align 8, !tbaa !17
  %28 = mul nsw i32 %27, 10
  %29 = getelementptr inbounds i8, ptr %0, i64 40
  store i32 %28, ptr %29, align 4, !tbaa !21
  %30 = load i32, ptr getelementptr inbounds (i8, ptr @kTargetLevelTable, i64 88), align 8, !tbaa !17
  %31 = mul nsw i32 %30, 10
  %32 = getelementptr inbounds i8, ptr %0, i64 44
  store i32 %31, ptr %32, align 4, !tbaa !22
  %33 = load i32, ptr getelementptr inbounds (i8, ptr @kTargetLevelTable, i64 60), align 4, !tbaa !17
  %34 = mul nsw i32 %33, 10
  %35 = getelementptr inbounds i8, ptr %0, i64 48
  store i32 %34, ptr %35, align 4, !tbaa !23
  %36 = load i32, ptr getelementptr inbounds (i8, ptr @kTargetLevelTable, i64 100), align 4, !tbaa !17
  %37 = mul nsw i32 %36, 10
  %38 = getelementptr inbounds i8, ptr %0, i64 52
  store i32 %37, ptr %38, align 4, !tbaa !24
  %39 = getelementptr inbounds i8, ptr %0, i64 92
  store i32 %22, ptr %39, align 4, !tbaa !25
  %40 = getelementptr inbounds i8, ptr %0, i64 96
  store i32 %25, ptr %40, align 4, !tbaa !26
  ret void
}

attributes #0 = { inlinehint 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 = { 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" }

!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, !10, i64 4}
!6 = !{!"", !7, i64 0, !10, i64 4, !10, i64 6, !10, i64 8, !8, i64 10, !11, i64 12, !11, i64 18, !10, i64 24, !10, i64 26, !7, i64 28, !7, i64 32, !7, i64 36, !7, i64 40, !7, i64 44, !7, i64 48, !7, i64 52, !10, i64 56, !10, i64 58, !8, i64 60, !7, i64 92, !7, i64 96, !7, i64 100, !7, i64 104, !7, i64 108, !7, i64 112, !8, i64 116, !8, i64 156, !8, i64 196, !10, i64 276, !10, i64 278, !10, i64 280, !10, i64 282, !10, i64 284, !10, i64 286, !10, i64 288, !10, i64 290, !10, i64 292, !10, i64 294, !10, i64 296, !10, i64 298, !10, i64 300, !10, i64 302, !7, i64 304, !10, i64 308, !7, i64 312, !7, i64 316, !7, i64 320, !7, i64 324, !7, i64 328, !7, i64 332, !7, i64 336, !7, i64 340, !7, i64 344, !10, i64 348, !12, i64 352, !13, i64 408, !10, i64 664}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"short", !8, i64 0}
!11 = !{!"", !10, i64 0, !10, i64 2, !8, i64 4}
!12 = !{!"", !8, i64 0, !10, i64 32, !10, i64 34, !10, i64 36, !10, i64 38, !7, i64 40, !10, i64 44, !10, i64 46, !7, i64 48, !10, i64 52}
!13 = !{!"", !7, i64 0, !7, i64 4, !7, i64 8, !8, i64 12, !10, i64 140, !10, i64 142, !12, i64 144, !12, i64 200}
!14 = !{!6, !10, i64 58}
!15 = !{!6, !10, i64 8}
!16 = !{!6, !10, i64 56}
!17 = !{!7, !7, i64 0}
!18 = !{!6, !7, i64 28}
!19 = !{!6, !7, i64 32}
!20 = !{!6, !7, i64 36}
!21 = !{!6, !7, i64 40}
!22 = !{!6, !7, i64 44}
!23 = !{!6, !7, i64 48}
!24 = !{!6, !7, i64 52}
!25 = !{!6, !7, i64 92}
!26 = !{!6, !7, i64 96}


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