; 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_ZeroCtrl(ptr noundef %0, ptr noundef %1, ptr noundef %2) #1 {
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca i16, align 2
  %8 = alloca i64, align 8
  %9 = alloca i32, align 4
  store ptr %0, ptr %4, align 8, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !5
  store ptr %2, ptr %6, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 2, ptr %7) #2
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #2
  store i64 0, ptr %8, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #2
  store i16 0, ptr %7, align 2, !tbaa !11
  br label %10

10:                                               ; preds = %23, %3
  %11 = load i16, ptr %7, align 2, !tbaa !11
  %12 = sext i16 %11 to i32
  %13 = icmp slt i32 %12, 10
  br i1 %13, label %14, label %26

14:                                               ; preds = %10
  %15 = load ptr, ptr %6, align 8, !tbaa !5
  %16 = load i16, ptr %7, align 2, !tbaa !11
  %17 = sext i16 %16 to i64
  %18 = getelementptr inbounds i32, ptr %15, i64 %17
  %19 = load i32, ptr %18, align 4, !tbaa !13
  %20 = sext i32 %19 to i64
  %21 = load i64, ptr %8, align 8, !tbaa !9
  %22 = add nsw i64 %21, %20
  store i64 %22, ptr %8, align 8, !tbaa !9
  br label %23

23:                                               ; preds = %14
  %24 = load i16, ptr %7, align 2, !tbaa !11
  %25 = add i16 %24, 1
  store i16 %25, ptr %7, align 2, !tbaa !11
  br label %10, !llvm.loop !15

26:                                               ; preds = %10
  %27 = load i64, ptr %8, align 8, !tbaa !9
  %28 = icmp slt i64 %27, 500
  br i1 %28, label %29, label %36

29:                                               ; preds = %26
  %30 = load ptr, ptr %4, align 8, !tbaa !5
  %31 = getelementptr inbounds %struct.LegacyAgc, ptr %30, i32 0, i32 36
  %32 = load i16, ptr %31, align 4, !tbaa !17
  %33 = sext i16 %32 to i32
  %34 = add nsw i32 %33, 10
  %35 = trunc i32 %34 to i16
  store i16 %35, ptr %31, align 4, !tbaa !17
  br label %39

36:                                               ; preds = %26
  %37 = load ptr, ptr %4, align 8, !tbaa !5
  %38 = getelementptr inbounds %struct.LegacyAgc, ptr %37, i32 0, i32 36
  store i16 0, ptr %38, align 4, !tbaa !17
  br label %39

39:                                               ; preds = %36, %29
  %40 = load ptr, ptr %4, align 8, !tbaa !5
  %41 = getelementptr inbounds %struct.LegacyAgc, ptr %40, i32 0, i32 40
  %42 = load i16, ptr %41, align 4, !tbaa !22
  %43 = sext i16 %42 to i32
  %44 = icmp sgt i32 %43, 0
  br i1 %44, label %45, label %52

45:                                               ; preds = %39
  %46 = load ptr, ptr %4, align 8, !tbaa !5
  %47 = getelementptr inbounds %struct.LegacyAgc, ptr %46, i32 0, i32 40
  %48 = load i16, ptr %47, align 4, !tbaa !22
  %49 = sext i16 %48 to i32
  %50 = sub nsw i32 %49, 10
  %51 = trunc i32 %50 to i16
  store i16 %51, ptr %47, align 4, !tbaa !22
  br label %52

52:                                               ; preds = %45, %39
  %53 = load ptr, ptr %4, align 8, !tbaa !5
  %54 = getelementptr inbounds %struct.LegacyAgc, ptr %53, i32 0, i32 36
  %55 = load i16, ptr %54, align 4, !tbaa !17
  %56 = sext i16 %55 to i32
  %57 = icmp sgt i32 %56, 500
  br i1 %57, label %58, label %107

58:                                               ; preds = %52
  %59 = load ptr, ptr %4, align 8, !tbaa !5
  %60 = getelementptr inbounds %struct.LegacyAgc, ptr %59, i32 0, i32 36
  store i16 0, ptr %60, align 4, !tbaa !17
  %61 = load ptr, ptr %4, align 8, !tbaa !5
  %62 = getelementptr inbounds %struct.LegacyAgc, ptr %61, i32 0, i32 47
  %63 = load i32, ptr %62, align 4, !tbaa !23
  %64 = load ptr, ptr %4, align 8, !tbaa !5
  %65 = getelementptr inbounds %struct.LegacyAgc, ptr %64, i32 0, i32 49
  %66 = load i32, ptr %65, align 4, !tbaa !24
  %67 = add nsw i32 %63, %66
  %68 = add nsw i32 %67, 1
  %69 = sdiv i32 %68, 2
  store i32 %69, ptr %9, align 4, !tbaa !13
  %70 = load ptr, ptr %5, align 8, !tbaa !5
  %71 = load i32, ptr %70, align 4, !tbaa !13
  %72 = load i32, ptr %9, align 4, !tbaa !13
  %73 = icmp slt i32 %71, %72
  br i1 %73, label %74, label %100

74:                                               ; preds = %58
  %75 = load ptr, ptr %5, align 8, !tbaa !5
  %76 = load i32, ptr %75, align 4, !tbaa !13
  %77 = mul nsw i32 1126, %76
  %78 = ashr i32 %77, 10
  %79 = load ptr, ptr %5, align 8, !tbaa !5
  store i32 %78, ptr %79, align 4, !tbaa !13
  %80 = load ptr, ptr %5, align 8, !tbaa !5
  %81 = load i32, ptr %80, align 4, !tbaa !13
  %82 = load ptr, ptr %4, align 8, !tbaa !5
  %83 = getelementptr inbounds %struct.LegacyAgc, ptr %82, i32 0, i32 51
  %84 = load i32, ptr %83, align 4, !tbaa !25
  %85 = icmp slt i32 %81, %84
  br i1 %85, label %86, label %89

86:                                               ; preds = %74
  %87 = load ptr, ptr %5, align 8, !tbaa !5
  %88 = load i32, ptr %87, align 4, !tbaa !13
  br label %93

89:                                               ; preds = %74
  %90 = load ptr, ptr %4, align 8, !tbaa !5
  %91 = getelementptr inbounds %struct.LegacyAgc, ptr %90, i32 0, i32 51
  %92 = load i32, ptr %91, align 4, !tbaa !25
  br label %93

93:                                               ; preds = %89, %86
  %94 = phi i32 [ %88, %86 ], [ %92, %89 ]
  %95 = load ptr, ptr %5, align 8, !tbaa !5
  store i32 %94, ptr %95, align 4, !tbaa !13
  %96 = load ptr, ptr %5, align 8, !tbaa !5
  %97 = load i32, ptr %96, align 4, !tbaa !13
  %98 = load ptr, ptr %4, align 8, !tbaa !5
  %99 = getelementptr inbounds %struct.LegacyAgc, ptr %98, i32 0, i32 45
  store i32 %97, ptr %99, align 4, !tbaa !26
  br label %100

100:                                              ; preds = %93, %58
  %101 = load ptr, ptr %4, align 8, !tbaa !5
  %102 = getelementptr inbounds %struct.LegacyAgc, ptr %101, i32 0, i32 39
  store i16 0, ptr %102, align 2, !tbaa !27
  %103 = load ptr, ptr %4, align 8, !tbaa !5
  %104 = getelementptr inbounds %struct.LegacyAgc, ptr %103, i32 0, i32 24
  store i32 0, ptr %104, align 4, !tbaa !28
  %105 = load ptr, ptr %4, align 8, !tbaa !5
  %106 = getelementptr inbounds %struct.LegacyAgc, ptr %105, i32 0, i32 40
  store i16 8000, ptr %106, align 4, !tbaa !22
  br label %107

107:                                              ; preds = %100, %52
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #2
  call void @llvm.lifetime.end.p0(i64 2, ptr %7) #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, !10, i64 0}
!10 = !{!"long", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"short", !7, i64 0}
!13 = !{!14, !14, i64 0}
!14 = !{!"int", !7, i64 0}
!15 = distinct !{!15, !16}
!16 = !{!"llvm.loop.mustprogress"}
!17 = !{!18, !12, i64 292}
!18 = !{!"", !14, i64 0, !12, i64 4, !12, i64 6, !12, i64 8, !7, i64 10, !19, i64 12, !19, i64 18, !12, i64 24, !12, i64 26, !14, i64 28, !14, i64 32, !14, i64 36, !14, i64 40, !14, i64 44, !14, i64 48, !14, i64 52, !12, i64 56, !12, i64 58, !7, i64 60, !14, i64 92, !14, i64 96, !14, i64 100, !14, i64 104, !14, i64 108, !14, 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, !14, i64 304, !12, i64 308, !14, i64 312, !14, i64 316, !14, i64 320, !14, i64 324, !14, i64 328, !14, i64 332, !14, i64 336, !14, i64 340, !14, i64 344, !12, i64 348, !20, i64 352, !21, i64 408, !12, i64 664}
!19 = !{!"", !12, i64 0, !12, i64 2, !7, i64 4}
!20 = !{!"", !7, i64 0, !12, i64 32, !12, i64 34, !12, i64 36, !12, i64 38, !14, i64 40, !12, i64 44, !12, i64 46, !14, i64 48, !12, i64 52}
!21 = !{!"", !14, i64 0, !14, i64 4, !14, i64 8, !7, i64 12, !12, i64 140, !12, i64 142, !20, i64 144, !20, i64 200}
!22 = !{!18, !12, i64 300}
!23 = !{!18, !14, i64 324}
!24 = !{!18, !14, i64 332}
!25 = !{!18, !14, i64 340}
!26 = !{!18, !14, i64 316}
!27 = !{!18, !12, i64 298}
!28 = !{!18, !14, i64 112}


; 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_ZeroCtrl(ptr nocapture noundef %0, ptr nocapture noundef %1, ptr nocapture noundef readonly %2) local_unnamed_addr #0 {
  %4 = load i32, ptr %2, align 4, !tbaa !5
  %5 = sext i32 %4 to i64
  %6 = getelementptr inbounds i8, ptr %2, i64 4
  %7 = load i32, ptr %6, align 4, !tbaa !5
  %8 = sext i32 %7 to i64
  %9 = add nsw i64 %5, %8
  %10 = getelementptr inbounds i8, ptr %2, i64 8
  %11 = load i32, ptr %10, align 4, !tbaa !5
  %12 = sext i32 %11 to i64
  %13 = add nsw i64 %9, %12
  %14 = getelementptr inbounds i8, ptr %2, i64 12
  %15 = load i32, ptr %14, align 4, !tbaa !5
  %16 = sext i32 %15 to i64
  %17 = add nsw i64 %13, %16
  %18 = getelementptr inbounds i8, ptr %2, i64 16
  %19 = load i32, ptr %18, align 4, !tbaa !5
  %20 = sext i32 %19 to i64
  %21 = add nsw i64 %17, %20
  %22 = getelementptr inbounds i8, ptr %2, i64 20
  %23 = load i32, ptr %22, align 4, !tbaa !5
  %24 = sext i32 %23 to i64
  %25 = add nsw i64 %21, %24
  %26 = getelementptr inbounds i8, ptr %2, i64 24
  %27 = load i32, ptr %26, align 4, !tbaa !5
  %28 = sext i32 %27 to i64
  %29 = add nsw i64 %25, %28
  %30 = getelementptr inbounds i8, ptr %2, i64 28
  %31 = load i32, ptr %30, align 4, !tbaa !5
  %32 = sext i32 %31 to i64
  %33 = add nsw i64 %29, %32
  %34 = getelementptr inbounds i8, ptr %2, i64 32
  %35 = load i32, ptr %34, align 4, !tbaa !5
  %36 = sext i32 %35 to i64
  %37 = add nsw i64 %33, %36
  %38 = getelementptr inbounds i8, ptr %2, i64 36
  %39 = load i32, ptr %38, align 4, !tbaa !5
  %40 = sext i32 %39 to i64
  %41 = add nsw i64 %37, %40
  %42 = icmp slt i64 %41, 500
  %43 = getelementptr inbounds i8, ptr %0, i64 292
  br i1 %42, label %44, label %48

44:                                               ; preds = %3
  %45 = load i16, ptr %43, align 4, !tbaa !9
  %46 = add i16 %45, 10
  store i16 %46, ptr %43, align 4, !tbaa !9
  %47 = icmp sgt i16 %46, 500
  br label %49

48:                                               ; preds = %3
  store i16 0, ptr %43, align 4, !tbaa !9
  br label %49

49:                                               ; preds = %48, %44
  %50 = phi i1 [ false, %48 ], [ %47, %44 ]
  %51 = getelementptr inbounds i8, ptr %0, i64 300
  %52 = load i16, ptr %51, align 4, !tbaa !15
  %53 = icmp sgt i16 %52, 0
  br i1 %53, label %54, label %56

54:                                               ; preds = %49
  %55 = add nsw i16 %52, -10
  store i16 %55, ptr %51, align 4, !tbaa !15
  br label %56

56:                                               ; preds = %54, %49
  br i1 %50, label %57, label %77

57:                                               ; preds = %56
  %58 = getelementptr inbounds i8, ptr %0, i64 292
  store i16 0, ptr %58, align 4, !tbaa !9
  %59 = getelementptr inbounds i8, ptr %0, i64 324
  %60 = load i32, ptr %59, align 4, !tbaa !16
  %61 = getelementptr inbounds i8, ptr %0, i64 332
  %62 = load i32, ptr %61, align 4, !tbaa !17
  %63 = add i32 %60, 1
  %64 = add i32 %63, %62
  %65 = sdiv i32 %64, 2
  %66 = load i32, ptr %1, align 4, !tbaa !5
  %67 = icmp slt i32 %66, %65
  br i1 %67, label %68, label %74

68:                                               ; preds = %57
  %69 = mul nsw i32 %66, 1126
  %70 = ashr i32 %69, 10
  store i32 %70, ptr %1, align 4, !tbaa !5
  %71 = getelementptr inbounds i8, ptr %0, i64 340
  %72 = load i32, ptr %71, align 4, !tbaa !18
  %. = tail call i32 @llvm.smin.i32(i32 %70, i32 %72)
  store i32 %., ptr %1, align 4, !tbaa !5
  %73 = getelementptr inbounds i8, ptr %0, i64 316
  store i32 %., ptr %73, align 4, !tbaa !19
  br label %74

74:                                               ; preds = %68, %57
  %75 = getelementptr inbounds i8, ptr %0, i64 298
  store i16 0, ptr %75, align 2, !tbaa !20
  %76 = getelementptr inbounds i8, ptr %0, i64 112
  store i32 0, ptr %76, align 4, !tbaa !21
  store i16 8000, ptr %51, align 4, !tbaa !15
  br label %77

77:                                               ; preds = %74, %56
  ret void
}

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


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,LCSSAPass,LoopRotatePass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass