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

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

; Function Attrs: nounwind uwtable
declare dso_local void @WebRtc_FreeDelayEstimatorFarend(ptr noundef) #0

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

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

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

9:                                                ; preds = %2
  %10 = call noalias ptr @malloc(i64 noundef 24) #5
  store ptr %10, ptr %5, align 8, !tbaa !9
  br label %11

11:                                               ; preds = %9, %2
  %12 = load ptr, ptr %5, align 8, !tbaa !9
  %13 = icmp ne ptr %12, null
  br i1 %13, label %14, label %47

14:                                               ; preds = %11
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #4
  store i32 0, ptr %6, align 4, !tbaa !5
  %15 = load i32, ptr %4, align 4, !tbaa !5
  %16 = call ptr @WebRtc_CreateBinaryDelayEstimatorFarend(i32 noundef %15)
  %17 = load ptr, ptr %5, align 8, !tbaa !9
  %18 = getelementptr inbounds %struct.DelayEstimatorFarend, ptr %17, i32 0, i32 3
  store ptr %16, ptr %18, align 8, !tbaa !11
  %19 = load ptr, ptr %5, align 8, !tbaa !9
  %20 = getelementptr inbounds %struct.DelayEstimatorFarend, ptr %19, i32 0, i32 3
  %21 = load ptr, ptr %20, align 8, !tbaa !11
  %22 = icmp eq ptr %21, null
  %23 = zext i1 %22 to i32
  %24 = load i32, ptr %6, align 4, !tbaa !5
  %25 = or i32 %24, %23
  store i32 %25, ptr %6, align 4, !tbaa !5
  %26 = load i32, ptr %3, align 4, !tbaa !5
  %27 = sext i32 %26 to i64
  %28 = mul i64 %27, 4
  %29 = call noalias ptr @malloc(i64 noundef %28) #5
  %30 = load ptr, ptr %5, align 8, !tbaa !9
  %31 = getelementptr inbounds %struct.DelayEstimatorFarend, ptr %30, i32 0, i32 0
  store ptr %29, ptr %31, align 8, !tbaa !13
  %32 = load ptr, ptr %5, align 8, !tbaa !9
  %33 = getelementptr inbounds %struct.DelayEstimatorFarend, ptr %32, i32 0, i32 0
  %34 = load ptr, ptr %33, align 8, !tbaa !13
  %35 = icmp eq ptr %34, null
  %36 = zext i1 %35 to i32
  %37 = load i32, ptr %6, align 4, !tbaa !5
  %38 = or i32 %37, %36
  store i32 %38, ptr %6, align 4, !tbaa !5
  %39 = load i32, ptr %3, align 4, !tbaa !5
  %40 = load ptr, ptr %5, align 8, !tbaa !9
  %41 = getelementptr inbounds %struct.DelayEstimatorFarend, ptr %40, i32 0, i32 2
  store i32 %39, ptr %41, align 4, !tbaa !14
  %42 = load i32, ptr %6, align 4, !tbaa !5
  %43 = icmp ne i32 %42, 0
  br i1 %43, label %44, label %46

44:                                               ; preds = %14
  %45 = load ptr, ptr %5, align 8, !tbaa !9
  call void @WebRtc_FreeDelayEstimatorFarend(ptr noundef %45)
  store ptr null, ptr %5, align 8, !tbaa !9
  br label %46

46:                                               ; preds = %44, %14
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #4
  br label %47

47:                                               ; preds = %46, %11
  %48 = load ptr, ptr %5, align 8, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #4
  ret ptr %48
}

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

declare ptr @WebRtc_CreateBinaryDelayEstimatorFarend(i32 noundef) #3

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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"any pointer", !7, i64 0}
!11 = !{!12, !10, i64 16}
!12 = !{!"", !10, i64 0, !6, i64 8, !6, i64 12, !10, i64 16}
!13 = !{!12, !10, i64 0}
!14 = !{!12, !6, i64 12}


; 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
declare dso_local void @WebRtc_FreeDelayEstimatorFarend(ptr noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local noundef ptr @WebRtc_CreateDelayEstimatorFarend(i32 noundef %0, i32 noundef %1) local_unnamed_addr #0 {
  %3 = icmp sgt i32 %0, 42
  br i1 %3, label %4, label %.thread

4:                                                ; preds = %2
  %5 = tail call noalias dereferenceable_or_null(24) ptr @malloc(i64 noundef 24) #3
  %.not = icmp eq ptr %5, null
  br i1 %.not, label %.thread, label %6

6:                                                ; preds = %4
  %7 = tail call ptr @WebRtc_CreateBinaryDelayEstimatorFarend(i32 noundef %1) #4
  %8 = getelementptr inbounds i8, ptr %5, i64 16
  store ptr %7, ptr %8, align 8, !tbaa !5
  %9 = icmp eq ptr %7, null
  %10 = zext nneg i32 %0 to i64
  %11 = shl nuw nsw i64 %10, 2
  %12 = tail call noalias ptr @malloc(i64 noundef %11) #3
  store ptr %12, ptr %5, align 8, !tbaa !11
  %13 = icmp eq ptr %12, null
  %14 = or i1 %9, %13
  %15 = getelementptr inbounds i8, ptr %5, i64 12
  store i32 %0, ptr %15, align 4, !tbaa !12
  br i1 %14, label %16, label %.thread

16:                                               ; preds = %6
  tail call void @WebRtc_FreeDelayEstimatorFarend(ptr noundef nonnull %5)
  br label %.thread

.thread:                                          ; preds = %2, %6, %16, %4
  %.2 = phi ptr [ null, %4 ], [ null, %16 ], [ %5, %6 ], [ null, %2 ]
  ret ptr %.2
}

; 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 ptr @WebRtc_CreateBinaryDelayEstimatorFarend(i32 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, !7, i64 16}
!6 = !{!"", !7, i64 0, !10, i64 8, !10, i64 12, !7, i64 16}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"int", !8, i64 0}
!11 = !{!6, !7, i64 0}
!12 = !{!6, !10, i64 12}


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