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

; 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: nounwind uwtable
define dso_local void @WebRtcAgc_SpeakerInactiveCtrl(ptr noundef %0) #1 {
  %2 = alloca ptr, align 8
  %3 = alloca i32, align 4
  %4 = alloca i16, align 2
  store ptr %0, ptr %2, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #2
  call void @llvm.lifetime.start.p0(i64 2, ptr %4) #2
  %5 = load ptr, ptr %2, align 8, !tbaa !5
  %6 = getelementptr inbounds %struct.LegacyAgc, ptr %5, i32 0, i32 54
  %7 = getelementptr inbounds %struct.AgcVad, ptr %6, i32 0, i32 6
  %8 = load i16, ptr %7, align 4, !tbaa !9
  %9 = sext i16 %8 to i32
  %10 = icmp slt i32 %9, 2500
  br i1 %10, label %11, label %14

11:                                               ; preds = %1
  %12 = load ptr, ptr %2, align 8, !tbaa !5
  %13 = getelementptr inbounds %struct.LegacyAgc, ptr %12, i32 0, i32 30
  store i16 1500, ptr %13, align 4, !tbaa !16
  br label %47

14:                                               ; preds = %1
  store i16 400, ptr %4, align 2, !tbaa !17
  %15 = load ptr, ptr %2, align 8, !tbaa !5
  %16 = getelementptr inbounds %struct.LegacyAgc, ptr %15, i32 0, i32 54
  %17 = getelementptr inbounds %struct.AgcVad, ptr %16, i32 0, i32 6
  %18 = load i16, ptr %17, align 4, !tbaa !9
  %19 = sext i16 %18 to i32
  %20 = icmp slt i32 %19, 4500
  br i1 %20, label %21, label %33

21:                                               ; preds = %14
  %22 = load ptr, ptr %2, align 8, !tbaa !5
  %23 = getelementptr inbounds %struct.LegacyAgc, ptr %22, i32 0, i32 54
  %24 = getelementptr inbounds %struct.AgcVad, ptr %23, i32 0, i32 6
  %25 = load i16, ptr %24, align 4, !tbaa !9
  %26 = sext i16 %25 to i32
  %27 = sub nsw i32 4500, %26
  %28 = sdiv i32 %27, 2
  %29 = load i16, ptr %4, align 2, !tbaa !17
  %30 = sext i16 %29 to i32
  %31 = add nsw i32 %30, %28
  %32 = trunc i32 %31 to i16
  store i16 %32, ptr %4, align 2, !tbaa !17
  br label %33

33:                                               ; preds = %21, %14
  %34 = load i16, ptr %4, align 2, !tbaa !17
  %35 = sext i16 %34 to i32
  %36 = load ptr, ptr %2, align 8, !tbaa !5
  %37 = getelementptr inbounds %struct.LegacyAgc, ptr %36, i32 0, i32 30
  %38 = load i16, ptr %37, align 4, !tbaa !16
  %39 = sext i16 %38 to i32
  %40 = mul nsw i32 31, %39
  %41 = add nsw i32 %35, %40
  store i32 %41, ptr %3, align 4, !tbaa !18
  %42 = load i32, ptr %3, align 4, !tbaa !18
  %43 = ashr i32 %42, 5
  %44 = trunc i32 %43 to i16
  %45 = load ptr, ptr %2, align 8, !tbaa !5
  %46 = getelementptr inbounds %struct.LegacyAgc, ptr %45, i32 0, i32 30
  store i16 %44, ptr %46, align 4, !tbaa !16
  br label %47

47:                                               ; preds = %33, %11
  call void @llvm.lifetime.end.p0(i64 2, ptr %4) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #2
  ret void
}

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 = { 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 396}
!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 = !{!10, !12, i64 280}
!17 = !{!12, !12, i64 0}
!18 = !{!11, !11, 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"

; Function Attrs: mustprogress nofree norecurse nosync nounwind willreturn memory(argmem: readwrite) uwtable
define dso_local void @WebRtcAgc_SpeakerInactiveCtrl(ptr nocapture noundef %0) local_unnamed_addr #0 {
  %2 = getelementptr inbounds i8, ptr %0, i64 396
  %3 = load i16, ptr %2, align 4, !tbaa !5
  %4 = icmp slt i16 %3, 2500
  br i1 %4, label %5, label %7

5:                                                ; preds = %1
  %6 = getelementptr inbounds i8, ptr %0, i64 280
  store i16 1500, ptr %6, align 4, !tbaa !14
  br label %18

7:                                                ; preds = %1
  %8 = icmp ult i16 %3, 4500
  %narrow = sub nsw i16 4500, %3
  %9 = ashr i16 %narrow, 1
  %10 = add nsw i16 %9, 400
  %narrow9 = select i1 %8, i16 %10, i16 400
  %.0 = zext i16 %narrow9 to i32
  %11 = getelementptr inbounds i8, ptr %0, i64 280
  %12 = load i16, ptr %11, align 4, !tbaa !14
  %13 = sext i16 %12 to i32
  %14 = mul nsw i32 %13, 31
  %15 = add nsw i32 %14, %.0
  %16 = lshr i32 %15, 5
  %17 = trunc i32 %16 to i16
  store i16 %17, ptr %11, align 4, !tbaa !14
  br label %18

18:                                               ; preds = %7, %5
  ret void
}

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

!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 396}
!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 280}


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