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

11:                                               ; preds = %2
  store i32 -1, ptr %3, align 4
  store i32 1, ptr %7, align 4
  br label %46

12:                                               ; preds = %2
  %13 = load ptr, ptr %5, align 8, !tbaa !5
  %14 = icmp eq ptr %13, null
  br i1 %14, label %15, label %18

15:                                               ; preds = %12
  %16 = load ptr, ptr %6, align 8, !tbaa !5
  %17 = getelementptr inbounds %struct.LegacyAgc, ptr %16, i32 0, i32 8
  store i16 18003, ptr %17, align 2, !tbaa !9
  store i32 -1, ptr %3, align 4
  store i32 1, ptr %7, align 4
  br label %46

18:                                               ; preds = %12
  %19 = load ptr, ptr %6, align 8, !tbaa !5
  %20 = getelementptr inbounds %struct.LegacyAgc, ptr %19, i32 0, i32 7
  %21 = load i16, ptr %20, align 4, !tbaa !16
  %22 = sext i16 %21 to i32
  %23 = icmp ne i32 %22, 42
  br i1 %23, label %24, label %27

24:                                               ; preds = %18
  %25 = load ptr, ptr %6, align 8, !tbaa !5
  %26 = getelementptr inbounds %struct.LegacyAgc, ptr %25, i32 0, i32 8
  store i16 18002, ptr %26, align 2, !tbaa !9
  store i32 -1, ptr %3, align 4
  store i32 1, ptr %7, align 4
  br label %46

27:                                               ; preds = %18
  %28 = load ptr, ptr %6, align 8, !tbaa !5
  %29 = getelementptr inbounds %struct.LegacyAgc, ptr %28, i32 0, i32 6
  %30 = getelementptr inbounds %struct.WebRtcAgcConfig, ptr %29, i32 0, i32 2
  %31 = load i8, ptr %30, align 2, !tbaa !17
  %32 = load ptr, ptr %5, align 8, !tbaa !5
  %33 = getelementptr inbounds %struct.WebRtcAgcConfig, ptr %32, i32 0, i32 2
  store i8 %31, ptr %33, align 2, !tbaa !18
  %34 = load ptr, ptr %6, align 8, !tbaa !5
  %35 = getelementptr inbounds %struct.LegacyAgc, ptr %34, i32 0, i32 6
  %36 = getelementptr inbounds %struct.WebRtcAgcConfig, ptr %35, i32 0, i32 0
  %37 = load i16, ptr %36, align 2, !tbaa !19
  %38 = load ptr, ptr %5, align 8, !tbaa !5
  %39 = getelementptr inbounds %struct.WebRtcAgcConfig, ptr %38, i32 0, i32 0
  store i16 %37, ptr %39, align 2, !tbaa !20
  %40 = load ptr, ptr %6, align 8, !tbaa !5
  %41 = getelementptr inbounds %struct.LegacyAgc, ptr %40, i32 0, i32 6
  %42 = getelementptr inbounds %struct.WebRtcAgcConfig, ptr %41, i32 0, i32 1
  %43 = load i16, ptr %42, align 2, !tbaa !21
  %44 = load ptr, ptr %5, align 8, !tbaa !5
  %45 = getelementptr inbounds %struct.WebRtcAgcConfig, ptr %44, i32 0, i32 1
  store i16 %43, ptr %45, align 2, !tbaa !22
  store i32 0, ptr %3, align 4
  store i32 1, ptr %7, align 4
  br label %46

46:                                               ; preds = %27, %24, %15, %11
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #2
  %47 = load i32, ptr %3, align 4
  ret i32 %47
}

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 26}
!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 24}
!17 = !{!10, !7, i64 22}
!18 = !{!13, !7, i64 4}
!19 = !{!10, !12, i64 18}
!20 = !{!13, !12, i64 0}
!21 = !{!10, !12, i64 20}
!22 = !{!13, !12, i64 2}


; 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 range(i32 -1, 1) i32 @WebRtcAgc_get_config(ptr noundef %0, ptr noundef writeonly %1) local_unnamed_addr #0 {
  %3 = icmp eq ptr %0, null
  br i1 %3, label %19, label %4

4:                                                ; preds = %2
  %5 = icmp eq ptr %1, null
  br i1 %5, label %6, label %8

6:                                                ; preds = %4
  %7 = getelementptr inbounds i8, ptr %0, i64 26
  store i16 18003, ptr %7, align 2, !tbaa !5
  br label %19

8:                                                ; preds = %4
  %9 = getelementptr inbounds i8, ptr %0, i64 24
  %10 = load i16, ptr %9, align 4, !tbaa !14
  %.not = icmp eq i16 %10, 42
  br i1 %.not, label %13, label %11

11:                                               ; preds = %8
  %12 = getelementptr inbounds i8, ptr %0, i64 26
  store i16 18002, ptr %12, align 2, !tbaa !5
  br label %19

13:                                               ; preds = %8
  %14 = getelementptr inbounds i8, ptr %0, i64 18
  %15 = getelementptr inbounds i8, ptr %0, i64 22
  %16 = load i8, ptr %15, align 2, !tbaa !15
  %17 = getelementptr inbounds i8, ptr %1, i64 4
  store i8 %16, ptr %17, align 2, !tbaa !16
  %18 = load <2 x i16>, ptr %14, align 2, !tbaa !17
  store <2 x i16> %18, ptr %1, align 2, !tbaa !17
  br label %19

19:                                               ; preds = %2, %13, %11, %6
  %.0 = phi i32 [ -1, %6 ], [ -1, %11 ], [ 0, %13 ], [ -1, %2 ]
  ret i32 %.0
}

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 26}
!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 24}
!15 = !{!6, !8, i64 22}
!16 = !{!11, !8, i64 4}
!17 = !{!10, !10, i64 0}


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