; LLVM IR from TobiasKozel/VAE :: external/portaudio/qa/loopback/src (audio_analyzer)

; 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.PaQaSineGenerator_s = type { double, double, double, double }
%struct.PaQaTestTone_s = type { i32, i32, double, double, double }
%struct.PaQaAnalysisResult_s = type { i32, double, double, double, double, double, double, double, double }

@.str = external hidden unnamed_addr constant [20 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [101 x i8], align 1
@g_testsFailed = external global i32, align 4
@g_testsPassed = external global i32, align 4
@.str.7 = external hidden unnamed_addr constant [24 x i8], align 1
@.str.8 = external hidden unnamed_addr constant [40 x i8], align 1

; Function Attrs: nounwind uwtable
declare dso_local void @PaQa_EraseBuffer(ptr noundef, i32 noundef, i32 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
declare dso_local void @PaQa_SetupSineGenerator(ptr noundef, double noundef, double noundef, double noundef) #0

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

declare i32 @printf(ptr noundef, ...) #2

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

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

; Function Attrs: nounwind uwtable
define dso_local i32 @PaQa_MeasureLatency(ptr noundef %0, ptr noundef %1, ptr noundef %2) #0 {
  %4 = alloca i32, align 4
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca double, align 8
  %9 = alloca %struct.PaQaSineGenerator_s, align 8
  %10 = alloca [2048 x float], align 16
  %11 = alloca double, align 8
  %12 = alloca i32, align 4
  %13 = alloca i32, align 4
  store ptr %0, ptr %5, align 8, !tbaa !5
  store ptr %1, ptr %6, align 8, !tbaa !5
  store ptr %2, ptr %7, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #3
  call void @llvm.lifetime.start.p0(i64 32, ptr %9) #3
  call void @llvm.lifetime.start.p0(i64 8192, ptr %10) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #3
  %14 = load ptr, ptr %6, align 8, !tbaa !5
  %15 = getelementptr inbounds %struct.PaQaTestTone_s, ptr %14, i32 0, i32 2
  %16 = load double, ptr %15, align 8, !tbaa !9
  %17 = load ptr, ptr %6, align 8, !tbaa !5
  %18 = getelementptr inbounds %struct.PaQaTestTone_s, ptr %17, i32 0, i32 3
  %19 = load double, ptr %18, align 8, !tbaa !13
  %20 = fdiv double %16, %19
  store double %20, ptr %11, align 8, !tbaa !14
  call void @llvm.lifetime.start.p0(i64 4, ptr %12) #3
  %21 = load double, ptr %11, align 8, !tbaa !14
  %22 = fadd double %21, 5.000000e-01
  %23 = fptosi double %22 to i32
  store i32 %23, ptr %12, align 4, !tbaa !15
  %24 = load ptr, ptr %7, align 8, !tbaa !5
  %25 = getelementptr inbounds %struct.PaQaAnalysisResult_s, ptr %24, i32 0, i32 1
  store double -1.000000e+00, ptr %25, align 8, !tbaa !16
  %26 = load ptr, ptr %7, align 8, !tbaa !5
  %27 = getelementptr inbounds %struct.PaQaAnalysisResult_s, ptr %26, i32 0, i32 0
  store i32 0, ptr %27, align 8, !tbaa !18
  %28 = load i32, ptr %12, align 4, !tbaa !15
  %29 = icmp slt i32 %28, 2048
  br i1 %29, label %34, label %30

30:                                               ; preds = %3
  %31 = call i32 (ptr, ...) @printf(ptr noundef @.str, ptr noundef @.str.1, i32 noundef 492, ptr noundef @.str.7)
  %32 = load i32, ptr @g_testsFailed, align 4, !tbaa !15
  %33 = add nsw i32 %32, 1
  store i32 %33, ptr @g_testsFailed, align 4, !tbaa !15
  br label %89

34:                                               ; preds = %3
  %35 = load i32, ptr @g_testsPassed, align 4, !tbaa !15
  %36 = add nsw i32 %35, 1
  store i32 %36, ptr @g_testsPassed, align 4, !tbaa !15
  br label %37

37:                                               ; preds = %34
  %38 = load ptr, ptr %6, align 8, !tbaa !5
  %39 = getelementptr inbounds %struct.PaQaTestTone_s, ptr %38, i32 0, i32 3
  %40 = load double, ptr %39, align 8, !tbaa !13
  %41 = load ptr, ptr %6, align 8, !tbaa !5
  %42 = getelementptr inbounds %struct.PaQaTestTone_s, ptr %41, i32 0, i32 4
  %43 = load double, ptr %42, align 8, !tbaa !19
  %44 = load ptr, ptr %6, align 8, !tbaa !5
  %45 = getelementptr inbounds %struct.PaQaTestTone_s, ptr %44, i32 0, i32 2
  %46 = load double, ptr %45, align 8, !tbaa !9
  call void @PaQa_SetupSineGenerator(ptr noundef %9, double noundef %40, double noundef %43, double noundef %46)
  %47 = getelementptr inbounds [2048 x float], ptr %10, i64 0, i64 0
  %48 = load i32, ptr %12, align 4, !tbaa !15
  %49 = load ptr, ptr %6, align 8, !tbaa !5
  %50 = getelementptr inbounds %struct.PaQaTestTone_s, ptr %49, i32 0, i32 0
  %51 = load i32, ptr %50, align 8, !tbaa !20
  call void @PaQa_EraseBuffer(ptr noundef %47, i32 noundef %48, i32 noundef %51)
  %52 = getelementptr inbounds [2048 x float], ptr %10, i64 0, i64 0
  %53 = load i32, ptr %12, align 4, !tbaa !15
  %54 = load ptr, ptr %6, align 8, !tbaa !5
  %55 = getelementptr inbounds %struct.PaQaTestTone_s, ptr %54, i32 0, i32 0
  %56 = load i32, ptr %55, align 8, !tbaa !20
  call void @PaQa_MixSine(ptr noundef %9, ptr noundef %52, i32 noundef %53, i32 noundef %56)
  %57 = load i32, ptr %12, align 4, !tbaa !15
  %58 = sitofp i32 %57 to double
  %59 = fmul double %58, 2.000000e-02
  store double %59, ptr %8, align 8, !tbaa !14
  %60 = load ptr, ptr %5, align 8, !tbaa !5
  %61 = getelementptr inbounds [2048 x float], ptr %10, i64 0, i64 0
  %62 = load i32, ptr %12, align 4, !tbaa !15
  %63 = load double, ptr %8, align 8, !tbaa !14
  %64 = call double @PaQa_FindFirstMatch(ptr noundef %60, ptr noundef %61, i32 noundef %62, double noundef %63)
  %65 = load ptr, ptr %7, align 8, !tbaa !5
  %66 = getelementptr inbounds %struct.PaQaAnalysisResult_s, ptr %65, i32 0, i32 1
  store double %64, ptr %66, align 8, !tbaa !16
  %67 = load ptr, ptr %7, align 8, !tbaa !5
  %68 = getelementptr inbounds %struct.PaQaAnalysisResult_s, ptr %67, i32 0, i32 1
  %69 = load double, ptr %68, align 8, !tbaa !16
  %70 = fcmp oge double %69, 0.000000e+00
  br i1 %70, label %75, label %71

71:                                               ; preds = %37
  %72 = call i32 (ptr, ...) @printf(ptr noundef @.str, ptr noundef @.str.1, i32 noundef 499, ptr noundef @.str.8)
  %73 = load i32, ptr @g_testsFailed, align 4, !tbaa !15
  %74 = add nsw i32 %73, 1
  store i32 %74, ptr @g_testsFailed, align 4, !tbaa !15
  br label %89

75:                                               ; preds = %37
  %76 = load i32, ptr @g_testsPassed, align 4, !tbaa !15
  %77 = add nsw i32 %76, 1
  store i32 %77, ptr @g_testsPassed, align 4, !tbaa !15
  br label %78

78:                                               ; preds = %75
  %79 = load ptr, ptr %5, align 8, !tbaa !5
  %80 = load ptr, ptr %7, align 8, !tbaa !5
  %81 = getelementptr inbounds %struct.PaQaAnalysisResult_s, ptr %80, i32 0, i32 1
  %82 = load double, ptr %81, align 8, !tbaa !16
  %83 = fptosi double %82 to i32
  %84 = getelementptr inbounds [2048 x float], ptr %10, i64 0, i64 0
  %85 = load i32, ptr %12, align 4, !tbaa !15
  %86 = call double @PaQa_CompareAmplitudes(ptr noundef %79, i32 noundef %83, ptr noundef %84, i32 noundef %85)
  %87 = load ptr, ptr %7, align 8, !tbaa !5
  %88 = getelementptr inbounds %struct.PaQaAnalysisResult_s, ptr %87, i32 0, i32 2
  store double %86, ptr %88, align 8, !tbaa !21
  store i32 0, ptr %4, align 4
  store i32 1, ptr %13, align 4
  br label %90

89:                                               ; preds = %71, %30
  store i32 -1, ptr %4, align 4
  store i32 1, ptr %13, align 4
  br label %90

90:                                               ; preds = %89, %78
  call void @llvm.lifetime.end.p0(i64 4, ptr %12) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #3
  call void @llvm.lifetime.end.p0(i64 8192, ptr %10) #3
  call void @llvm.lifetime.end.p0(i64 32, ptr %9) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #3
  %91 = load i32, ptr %4, align 4
  ret i32 %91
}

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 = { "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 }

!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 8}
!10 = !{!"PaQaTestTone_s", !11, i64 0, !11, i64 4, !12, i64 8, !12, i64 16, !12, i64 24}
!11 = !{!"int", !7, i64 0}
!12 = !{!"double", !7, i64 0}
!13 = !{!10, !12, i64 16}
!14 = !{!12, !12, i64 0}
!15 = !{!11, !11, i64 0}
!16 = !{!17, !12, i64 8}
!17 = !{!"PaQaAnalysisResult_s", !11, i64 0, !12, i64 8, !12, i64 16, !12, i64 24, !12, i64 32, !12, i64 40, !12, i64 48, !12, i64 56, !12, i64 64}
!18 = !{!17, !11, i64 0}
!19 = !{!10, !12, i64 24}
!20 = !{!10, !11, i64 0}
!21 = !{!17, !12, i64 16}


; 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"

%struct.PaQaSineGenerator_s = type { double, double, double, double }

@.str = external hidden unnamed_addr constant [20 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [101 x i8], align 1
@g_testsFailed = external local_unnamed_addr global i32, align 4
@g_testsPassed = external local_unnamed_addr global i32, align 4
@.str.7 = external hidden unnamed_addr constant [24 x i8], align 1
@.str.8 = external hidden unnamed_addr constant [40 x i8], align 1

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

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

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

; Function Attrs: nounwind uwtable
declare dso_local void @PaQa_SetupSineGenerator(ptr noundef, double noundef, double noundef, double noundef) local_unnamed_addr #0

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

; Function Attrs: nofree nounwind
declare noundef i32 @printf(ptr nocapture noundef readonly, ...) local_unnamed_addr #2

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

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

; Function Attrs: nounwind uwtable
define dso_local range(i32 -1, 1) i32 @PaQa_MeasureLatency(ptr noundef %0, ptr nocapture noundef readonly %1, ptr nocapture noundef writeonly %2) local_unnamed_addr #0 {
  %4 = alloca %struct.PaQaSineGenerator_s, align 8
  %5 = alloca [2048 x float], align 16
  call void @llvm.lifetime.start.p0(i64 32, ptr nonnull %4) #3
  call void @llvm.lifetime.start.p0(i64 8192, ptr nonnull %5) #3
  %6 = getelementptr inbounds i8, ptr %1, i64 8
  %7 = load double, ptr %6, align 8, !tbaa !5
  %8 = getelementptr inbounds i8, ptr %1, i64 16
  %9 = load double, ptr %8, align 8, !tbaa !11
  %10 = fdiv double %7, %9
  %11 = fadd double %10, 5.000000e-01
  %12 = fptosi double %11 to i32
  %13 = getelementptr inbounds i8, ptr %2, i64 8
  store double -1.000000e+00, ptr %13, align 8, !tbaa !12
  store i32 0, ptr %2, align 8, !tbaa !14
  %14 = icmp slt i32 %12, 2048
  br i1 %14, label %17, label %15

15:                                               ; preds = %3
  %16 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str, ptr noundef nonnull @.str.1, i32 noundef 492, ptr noundef nonnull @.str.7)
  br label %36

17:                                               ; preds = %3
  %18 = load i32, ptr @g_testsPassed, align 4, !tbaa !15
  %19 = add nsw i32 %18, 1
  store i32 %19, ptr @g_testsPassed, align 4, !tbaa !15
  %20 = getelementptr inbounds i8, ptr %1, i64 24
  %21 = load double, ptr %20, align 8, !tbaa !16
  call void @PaQa_SetupSineGenerator(ptr noundef nonnull %4, double noundef %9, double noundef %21, double noundef %7)
  %22 = load i32, ptr %1, align 8, !tbaa !17
  call void @PaQa_EraseBuffer(ptr noundef nonnull %5, i32 noundef %12, i32 noundef %22)
  %23 = load i32, ptr %1, align 8, !tbaa !17
  call void @PaQa_MixSine(ptr noundef nonnull %4, ptr noundef nonnull %5, i32 noundef %12, i32 noundef %23)
  %24 = sitofp i32 %12 to double
  %25 = fmul double %24, 2.000000e-02
  %26 = call double @PaQa_FindFirstMatch(ptr noundef %0, ptr noundef nonnull %5, i32 noundef %12, double noundef %25)
  store double %26, ptr %13, align 8, !tbaa !12
  %27 = fcmp ult double %26, 0.000000e+00
  br i1 %27, label %28, label %30

28:                                               ; preds = %17
  %29 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str, ptr noundef nonnull @.str.1, i32 noundef 499, ptr noundef nonnull @.str.8)
  br label %36

30:                                               ; preds = %17
  %31 = load i32, ptr @g_testsPassed, align 4, !tbaa !15
  %32 = add nsw i32 %31, 1
  store i32 %32, ptr @g_testsPassed, align 4, !tbaa !15
  %33 = fptosi double %26 to i32
  %34 = call double @PaQa_CompareAmplitudes(ptr noundef %0, i32 noundef %33, ptr noundef nonnull %5, i32 noundef %12)
  %35 = getelementptr inbounds i8, ptr %2, i64 16
  store double %34, ptr %35, align 8, !tbaa !18
  br label %37

36:                                               ; preds = %28, %15
  %storemerge.in = load i32, ptr @g_testsFailed, align 4, !tbaa !15
  %storemerge = add nsw i32 %storemerge.in, 1
  store i32 %storemerge, ptr @g_testsFailed, align 4, !tbaa !15
  br label %37

37:                                               ; preds = %36, %30
  %.0 = phi i32 [ 0, %30 ], [ -1, %36 ]
  call void @llvm.lifetime.end.p0(i64 8192, ptr nonnull %5) #3
  call void @llvm.lifetime.end.p0(i64 32, ptr nonnull %4) #3
  ret i32 %.0
}

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

!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 8}
!6 = !{!"PaQaTestTone_s", !7, i64 0, !7, i64 4, !10, i64 8, !10, i64 16, !10, i64 24}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"double", !8, i64 0}
!11 = !{!6, !10, i64 16}
!12 = !{!13, !10, i64 8}
!13 = !{!"PaQaAnalysisResult_s", !7, i64 0, !10, i64 8, !10, i64 16, !10, i64 24, !10, i64 32, !10, i64 40, !10, i64 48, !10, i64 56, !10, i64 64}
!14 = !{!13, !7, i64 0}
!15 = !{!7, !7, i64 0}
!16 = !{!6, !10, i64 24}
!17 = !{!6, !7, i64 0}
!18 = !{!13, !10, i64 16}


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