; 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.AgcVad = type { [8 x i32], i16, i16, i16, i16, i32, i16, i16, i32, i16 }

; 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_InitVad(ptr noundef %0) #1 {
  %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) #2
  %4 = load ptr, ptr %2, align 8, !tbaa !5
  %5 = getelementptr inbounds %struct.AgcVad, ptr %4, i32 0, i32 1
  store i16 0, ptr %5, align 4, !tbaa !9
  %6 = load ptr, ptr %2, align 8, !tbaa !5
  %7 = getelementptr inbounds %struct.AgcVad, ptr %6, i32 0, i32 3
  store i16 0, ptr %7, align 4, !tbaa !13
  %8 = load ptr, ptr %2, align 8, !tbaa !5
  %9 = getelementptr inbounds %struct.AgcVad, ptr %8, i32 0, i32 4
  store i16 15360, ptr %9, align 2, !tbaa !14
  %10 = load ptr, ptr %2, align 8, !tbaa !5
  %11 = getelementptr inbounds %struct.AgcVad, ptr %10, i32 0, i32 5
  store i32 128000, ptr %11, align 4, !tbaa !15
  %12 = load ptr, ptr %2, align 8, !tbaa !5
  %13 = getelementptr inbounds %struct.AgcVad, ptr %12, i32 0, i32 6
  store i16 0, ptr %13, align 4, !tbaa !16
  %14 = load ptr, ptr %2, align 8, !tbaa !5
  %15 = getelementptr inbounds %struct.AgcVad, ptr %14, i32 0, i32 7
  store i16 15360, ptr %15, align 2, !tbaa !17
  %16 = load ptr, ptr %2, align 8, !tbaa !5
  %17 = getelementptr inbounds %struct.AgcVad, ptr %16, i32 0, i32 8
  store i32 128000, ptr %17, align 4, !tbaa !18
  %18 = load ptr, ptr %2, align 8, !tbaa !5
  %19 = getelementptr inbounds %struct.AgcVad, ptr %18, i32 0, i32 9
  store i16 0, ptr %19, align 4, !tbaa !19
  %20 = load ptr, ptr %2, align 8, !tbaa !5
  %21 = getelementptr inbounds %struct.AgcVad, ptr %20, i32 0, i32 2
  store i16 3, ptr %21, align 2, !tbaa !20
  store i16 0, ptr %3, align 2, !tbaa !21
  br label %22

22:                                               ; preds = %32, %1
  %23 = load i16, ptr %3, align 2, !tbaa !21
  %24 = sext i16 %23 to i32
  %25 = icmp slt i32 %24, 8
  br i1 %25, label %26, label %35

26:                                               ; preds = %22
  %27 = load ptr, ptr %2, align 8, !tbaa !5
  %28 = getelementptr inbounds %struct.AgcVad, ptr %27, i32 0, i32 0
  %29 = load i16, ptr %3, align 2, !tbaa !21
  %30 = sext i16 %29 to i64
  %31 = getelementptr inbounds [8 x i32], ptr %28, i64 0, i64 %30
  store i32 0, ptr %31, align 4, !tbaa !22
  br label %32

32:                                               ; preds = %26
  %33 = load i16, ptr %3, align 2, !tbaa !21
  %34 = add i16 %33, 1
  store i16 %34, ptr %3, align 2, !tbaa !21
  br label %22, !llvm.loop !23

35:                                               ; preds = %22
  call void @llvm.lifetime.end.p0(i64 2, 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, !11, i64 32}
!10 = !{!"", !7, i64 0, !11, i64 32, !11, i64 34, !11, i64 36, !11, i64 38, !12, i64 40, !11, i64 44, !11, i64 46, !12, i64 48, !11, i64 52}
!11 = !{!"short", !7, i64 0}
!12 = !{!"int", !7, i64 0}
!13 = !{!10, !11, i64 36}
!14 = !{!10, !11, i64 38}
!15 = !{!10, !12, i64 40}
!16 = !{!10, !11, i64 44}
!17 = !{!10, !11, i64 46}
!18 = !{!10, !12, i64 48}
!19 = !{!10, !11, i64 52}
!20 = !{!10, !11, i64 34}
!21 = !{!11, !11, i64 0}
!22 = !{!12, !12, i64 0}
!23 = distinct !{!23, !24}
!24 = !{!"llvm.loop.mustprogress"}


; 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: write) uwtable
define dso_local void @WebRtcAgc_InitVad(ptr nocapture noundef writeonly %0) local_unnamed_addr #0 {
  %2 = getelementptr inbounds i8, ptr %0, i64 32
  store i16 0, ptr %2, align 4, !tbaa !5
  %3 = getelementptr inbounds i8, ptr %0, i64 36
  store i16 0, ptr %3, align 4, !tbaa !11
  %4 = getelementptr inbounds i8, ptr %0, i64 38
  store i16 15360, ptr %4, align 2, !tbaa !12
  %5 = getelementptr inbounds i8, ptr %0, i64 40
  store i32 128000, ptr %5, align 4, !tbaa !13
  %6 = getelementptr inbounds i8, ptr %0, i64 44
  store i16 0, ptr %6, align 4, !tbaa !14
  %7 = getelementptr inbounds i8, ptr %0, i64 46
  store i16 15360, ptr %7, align 2, !tbaa !15
  %8 = getelementptr inbounds i8, ptr %0, i64 48
  store i32 128000, ptr %8, align 4, !tbaa !16
  %9 = getelementptr inbounds i8, ptr %0, i64 52
  store i16 0, ptr %9, align 4, !tbaa !17
  %10 = getelementptr inbounds i8, ptr %0, i64 34
  store i16 3, ptr %10, align 2, !tbaa !18
  tail call void @llvm.memset.p0.i64(ptr noundef nonnull align 4 dereferenceable(32) %0, i8 0, i64 32, i1 false), !tbaa !19
  ret void
}

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #1

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

!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 32}
!6 = !{!"", !7, i64 0, !9, i64 32, !9, i64 34, !9, i64 36, !9, i64 38, !10, i64 40, !9, i64 44, !9, i64 46, !10, i64 48, !9, i64 52}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!"short", !7, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = !{!6, !9, i64 36}
!12 = !{!6, !9, i64 38}
!13 = !{!6, !10, i64 40}
!14 = !{!6, !9, i64 44}
!15 = !{!6, !9, i64 46}
!16 = !{!6, !10, i64 48}
!17 = !{!6, !9, i64 52}
!18 = !{!6, !9, i64 34}
!19 = !{!10, !10, i64 0}


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