; LLVM IR from Ryuk17/SpeechAlgorithms :: WebRTC_AEC/src (echo_cancellation)

; 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.aecpc_t = type { i32, i32, i32, i32, float, i16, i32, i32, i32, i16, i16, i32, i16, i16, i16, i16, i32, i32, i32, i16, ptr, i32, i32, i32, float, ptr, i32, i32, ptr }

; Function Attrs: nounwind uwtable
define dso_local i32 @WebRtcAec_Create(ptr noundef %0) #0 {
  %2 = alloca i32, align 4
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca i32, align 4
  store ptr %0, ptr %3, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #4
  %6 = load ptr, ptr %3, align 8, !tbaa !5
  %7 = icmp eq ptr %6, null
  br i1 %7, label %8, label %9

8:                                                ; preds = %1
  store i32 -1, ptr %2, align 4
  store i32 1, ptr %5, align 4
  br label %48

9:                                                ; preds = %1
  %10 = call noalias ptr @malloc(i64 noundef 120) #5
  store ptr %10, ptr %4, align 8, !tbaa !5
  %11 = load ptr, ptr %4, align 8, !tbaa !5
  %12 = load ptr, ptr %3, align 8, !tbaa !5
  store ptr %11, ptr %12, align 8, !tbaa !5
  %13 = load ptr, ptr %4, align 8, !tbaa !5
  %14 = icmp eq ptr %13, null
  br i1 %14, label %15, label %16

15:                                               ; preds = %9
  store i32 -1, ptr %2, align 4
  store i32 1, ptr %5, align 4
  br label %48

16:                                               ; preds = %9
  %17 = load ptr, ptr %4, align 8, !tbaa !5
  %18 = getelementptr inbounds %struct.aecpc_t, ptr %17, i32 0, i32 28
  %19 = call i32 @WebRtcAec_CreateAec(ptr noundef %18)
  %20 = icmp eq i32 %19, -1
  br i1 %20, label %21, label %24

21:                                               ; preds = %16
  %22 = load ptr, ptr %4, align 8, !tbaa !5
  %23 = call i32 @WebRtcAec_Free(ptr noundef %22)
  store ptr null, ptr %4, align 8, !tbaa !5
  store i32 -1, ptr %2, align 4
  store i32 1, ptr %5, align 4
  br label %48

24:                                               ; preds = %16
  %25 = load ptr, ptr %4, align 8, !tbaa !5
  %26 = getelementptr inbounds %struct.aecpc_t, ptr %25, i32 0, i32 20
  %27 = call i32 @WebRtcAec_CreateResampler(ptr noundef %26)
  %28 = icmp eq i32 %27, -1
  br i1 %28, label %29, label %32

29:                                               ; preds = %24
  %30 = load ptr, ptr %4, align 8, !tbaa !5
  %31 = call i32 @WebRtcAec_Free(ptr noundef %30)
  store ptr null, ptr %4, align 8, !tbaa !5
  store i32 -1, ptr %2, align 4
  store i32 1, ptr %5, align 4
  br label %48

32:                                               ; preds = %24
  %33 = call ptr @WebRtc_CreateBuffer(i64 noundef 448, i64 noundef 4)
  %34 = load ptr, ptr %4, align 8, !tbaa !5
  %35 = getelementptr inbounds %struct.aecpc_t, ptr %34, i32 0, i32 25
  store ptr %33, ptr %35, align 8, !tbaa !9
  %36 = load ptr, ptr %4, align 8, !tbaa !5
  %37 = getelementptr inbounds %struct.aecpc_t, ptr %36, i32 0, i32 25
  %38 = load ptr, ptr %37, align 8, !tbaa !9
  %39 = icmp ne ptr %38, null
  br i1 %39, label %43, label %40

40:                                               ; preds = %32
  %41 = load ptr, ptr %4, align 8, !tbaa !5
  %42 = call i32 @WebRtcAec_Free(ptr noundef %41)
  store ptr null, ptr %4, align 8, !tbaa !5
  store i32 -1, ptr %2, align 4
  store i32 1, ptr %5, align 4
  br label %48

43:                                               ; preds = %32
  %44 = load ptr, ptr %4, align 8, !tbaa !5
  %45 = getelementptr inbounds %struct.aecpc_t, ptr %44, i32 0, i32 9
  store i16 0, ptr %45, align 4, !tbaa !14
  %46 = load ptr, ptr %4, align 8, !tbaa !5
  %47 = getelementptr inbounds %struct.aecpc_t, ptr %46, i32 0, i32 26
  store i32 0, ptr %47, align 8, !tbaa !15
  store i32 0, ptr %2, align 4
  store i32 1, ptr %5, align 4
  br label %48

48:                                               ; preds = %43, %40, %29, %21, %15, %8
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #4
  %49 = load i32, ptr %2, align 4
  ret i32 %49
}

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #1

; Function Attrs: nounwind allocsize(0)
declare noalias ptr @malloc(i64 noundef) #2

declare i32 @WebRtcAec_CreateAec(ptr noundef) #3

; Function Attrs: nounwind uwtable
declare dso_local i32 @WebRtcAec_Free(ptr noundef) #0

declare i32 @WebRtcAec_CreateResampler(ptr noundef) #3

declare ptr @WebRtc_CreateBuffer(i64 noundef, i64 noundef) #3

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #1

attributes #0 = { 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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { nounwind allocsize(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 = { "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 #4 = { nounwind }
attributes #5 = { nounwind allocsize(0) }

!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, !6, i64 96}
!10 = !{!"", !11, i64 0, !11, i64 4, !11, i64 8, !11, i64 12, !12, i64 16, !13, i64 20, !11, i64 24, !11, i64 28, !11, i64 32, !13, i64 36, !13, i64 38, !11, i64 40, !13, i64 44, !13, i64 46, !13, i64 48, !13, i64 50, !11, i64 52, !11, i64 56, !11, i64 60, !13, i64 64, !6, i64 72, !11, i64 80, !11, i64 84, !11, i64 88, !12, i64 92, !6, i64 96, !11, i64 104, !11, i64 108, !6, i64 112}
!11 = !{!"int", !7, i64 0}
!12 = !{!"float", !7, i64 0}
!13 = !{!"short", !7, i64 0}
!14 = !{!10, !13, i64 36}
!15 = !{!10, !11, i64 104}


; 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: nounwind uwtable
define dso_local range(i32 -1, 1) i32 @WebRtcAec_Create(ptr noundef writeonly %0) local_unnamed_addr #0 {
  %2 = icmp eq ptr %0, null
  br i1 %2, label %26, label %3

3:                                                ; preds = %1
  %4 = tail call noalias dereferenceable_or_null(120) ptr @malloc(i64 noundef 120) #3
  store ptr %4, ptr %0, align 8, !tbaa !5
  %5 = icmp eq ptr %4, null
  br i1 %5, label %26, label %6

6:                                                ; preds = %3
  %7 = getelementptr inbounds i8, ptr %4, i64 112
  %8 = tail call i32 @WebRtcAec_CreateAec(ptr noundef nonnull %7) #4
  %9 = icmp eq i32 %8, -1
  br i1 %9, label %10, label %12

10:                                               ; preds = %6
  %11 = tail call i32 @WebRtcAec_Free(ptr noundef nonnull %4)
  br label %26

12:                                               ; preds = %6
  %13 = getelementptr inbounds i8, ptr %4, i64 72
  %14 = tail call i32 @WebRtcAec_CreateResampler(ptr noundef nonnull %13) #4
  %15 = icmp eq i32 %14, -1
  br i1 %15, label %16, label %18

16:                                               ; preds = %12
  %17 = tail call i32 @WebRtcAec_Free(ptr noundef nonnull %4)
  br label %26

18:                                               ; preds = %12
  %19 = tail call ptr @WebRtc_CreateBuffer(i64 noundef 448, i64 noundef 4) #4
  %20 = getelementptr inbounds i8, ptr %4, i64 96
  store ptr %19, ptr %20, align 8, !tbaa !9
  %.not = icmp eq ptr %19, null
  br i1 %.not, label %21, label %23

21:                                               ; preds = %18
  %22 = tail call i32 @WebRtcAec_Free(ptr noundef nonnull %4)
  br label %26

23:                                               ; preds = %18
  %24 = getelementptr inbounds i8, ptr %4, i64 36
  store i16 0, ptr %24, align 4, !tbaa !14
  %25 = getelementptr inbounds i8, ptr %4, i64 104
  store i32 0, ptr %25, align 8, !tbaa !15
  br label %26

26:                                               ; preds = %3, %1, %23, %21, %16, %10
  %.0 = phi i32 [ -1, %10 ], [ -1, %16 ], [ 0, %23 ], [ -1, %21 ], [ -1, %1 ], [ -1, %3 ]
  ret i32 %.0
}

; Function Attrs: mustprogress nofree nounwind willreturn allockind("alloc,uninitialized") allocsize(0) memory(inaccessiblemem: readwrite)
declare noalias noundef ptr @malloc(i64 noundef) local_unnamed_addr #1

declare i32 @WebRtcAec_CreateAec(ptr noundef) local_unnamed_addr #2

; Function Attrs: nounwind uwtable
declare dso_local i32 @WebRtcAec_Free(ptr noundef) local_unnamed_addr #0

declare i32 @WebRtcAec_CreateResampler(ptr noundef) local_unnamed_addr #2

declare ptr @WebRtc_CreateBuffer(i64 noundef, i64 noundef) local_unnamed_addr #2

attributes #0 = { 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 = { mustprogress nofree nounwind willreturn allockind("alloc,uninitialized") allocsize(0) memory(inaccessiblemem: readwrite) "alloc-family"="malloc" "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 = { "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 allocsize(0) }
attributes #4 = { 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, !6, i64 96}
!10 = !{!"", !11, i64 0, !11, i64 4, !11, i64 8, !11, i64 12, !12, i64 16, !13, i64 20, !11, i64 24, !11, i64 28, !11, i64 32, !13, i64 36, !13, i64 38, !11, i64 40, !13, i64 44, !13, i64 46, !13, i64 48, !13, i64 50, !11, i64 52, !11, i64 56, !11, i64 60, !13, i64 64, !6, i64 72, !11, i64 80, !11, i64 84, !11, i64 88, !12, i64 92, !6, i64 96, !11, i64 104, !11, i64 108, !6, i64 112}
!11 = !{!"int", !7, i64 0}
!12 = !{!"float", !7, i64 0}
!13 = !{!"short", !7, i64 0}
!14 = !{!10, !13, i64 36}
!15 = !{!10, !11, i64 104}


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