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

@.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.4 = external hidden unnamed_addr constant [25 x i8], align 1
@.str.5 = external hidden unnamed_addr constant [24 x i8], align 1

; 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

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

; Function Attrs: nounwind
declare double @sin(double noundef) #2

; Function Attrs: nounwind uwtable
define dso_local double @PaQa_CorrelateSine(ptr noundef %0, double noundef %1, double noundef %2, i32 noundef %3, i32 noundef %4, ptr noundef %5) #3 {
  %7 = alloca double, align 8
  %8 = alloca ptr, align 8
  %9 = alloca double, align 8
  %10 = alloca double, align 8
  %11 = alloca i32, align 4
  %12 = alloca i32, align 4
  %13 = alloca ptr, align 8
  %14 = alloca double, align 8
  %15 = alloca i32, align 4
  %16 = alloca double, align 8
  %17 = alloca double, align 8
  %18 = alloca double, align 8
  %19 = alloca double, align 8
  %20 = alloca ptr, align 8
  %21 = alloca double, align 8
  %22 = alloca double, align 8
  %23 = alloca i32, align 4
  store ptr %0, ptr %8, align 8, !tbaa !5
  store double %1, ptr %9, align 8, !tbaa !9
  store double %2, ptr %10, align 8, !tbaa !9
  store i32 %3, ptr %11, align 4, !tbaa !11
  store i32 %4, ptr %12, align 4, !tbaa !11
  store ptr %5, ptr %13, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %14) #5
  store double 0.000000e+00, ptr %14, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %15) #5
  %24 = load i32, ptr %12, align 4, !tbaa !11
  store i32 %24, ptr %15, align 4, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 8, ptr %16) #5
  store double 0.000000e+00, ptr %16, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %17) #5
  %25 = load double, ptr %9, align 8, !tbaa !9
  %26 = fmul double 0x401921FB54442D18, %25
  %27 = load double, ptr %10, align 8, !tbaa !9
  %28 = fdiv double %26, %27
  store double %28, ptr %17, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %18) #5
  store double 0.000000e+00, ptr %18, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %19) #5
  store double 0.000000e+00, ptr %19, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %20) #5
  %29 = load ptr, ptr %8, align 8, !tbaa !5
  %30 = getelementptr inbounds %struct.PaQaRecording_s, ptr %29, i32 0, i32 1
  %31 = load ptr, ptr %30, align 8, !tbaa !13
  %32 = load i32, ptr %11, align 4, !tbaa !11
  %33 = sext i32 %32 to i64
  %34 = getelementptr inbounds float, ptr %31, i64 %33
  store ptr %34, ptr %20, align 8, !tbaa !5
  %35 = load i32, ptr %11, align 4, !tbaa !11
  %36 = load ptr, ptr %8, align 8, !tbaa !5
  %37 = getelementptr inbounds %struct.PaQaRecording_s, ptr %36, i32 0, i32 2
  %38 = load i32, ptr %37, align 8, !tbaa !15
  %39 = icmp slt i32 %35, %38
  br i1 %39, label %44, label %40

40:                                               ; preds = %6
  %41 = call i32 (ptr, ...) @printf(ptr noundef @.str, ptr noundef @.str.1, i32 noundef 310, ptr noundef @.str.4)
  %42 = load i32, ptr @g_testsFailed, align 4, !tbaa !11
  %43 = add nsw i32 %42, 1
  store i32 %43, ptr @g_testsFailed, align 4, !tbaa !11
  br label %119

44:                                               ; preds = %6
  %45 = load i32, ptr @g_testsPassed, align 4, !tbaa !11
  %46 = add nsw i32 %45, 1
  store i32 %46, ptr @g_testsPassed, align 4, !tbaa !11
  br label %47

47:                                               ; preds = %44
  %48 = load i32, ptr %11, align 4, !tbaa !11
  %49 = load i32, ptr %12, align 4, !tbaa !11
  %50 = add nsw i32 %48, %49
  %51 = load ptr, ptr %8, align 8, !tbaa !5
  %52 = getelementptr inbounds %struct.PaQaRecording_s, ptr %51, i32 0, i32 2
  %53 = load i32, ptr %52, align 8, !tbaa !15
  %54 = icmp sle i32 %50, %53
  br i1 %54, label %59, label %55

55:                                               ; preds = %47
  %56 = call i32 (ptr, ...) @printf(ptr noundef @.str, ptr noundef @.str.1, i32 noundef 311, ptr noundef @.str.5)
  %57 = load i32, ptr @g_testsFailed, align 4, !tbaa !11
  %58 = add nsw i32 %57, 1
  store i32 %58, ptr @g_testsFailed, align 4, !tbaa !11
  br label %119

59:                                               ; preds = %47
  %60 = load i32, ptr @g_testsPassed, align 4, !tbaa !11
  %61 = add nsw i32 %60, 1
  store i32 %61, ptr @g_testsPassed, align 4, !tbaa !11
  br label %62

62:                                               ; preds = %59
  br label %63

63:                                               ; preds = %89, %62
  %64 = load i32, ptr %15, align 4, !tbaa !11
  %65 = icmp sgt i32 %64, 0
  br i1 %65, label %66, label %92

66:                                               ; preds = %63
  call void @llvm.lifetime.start.p0(i64 8, ptr %21) #5
  %67 = load ptr, ptr %20, align 8, !tbaa !5
  %68 = getelementptr inbounds float, ptr %67, i32 1
  store ptr %68, ptr %20, align 8, !tbaa !5
  %69 = load float, ptr %67, align 4, !tbaa !16
  %70 = fpext float %69 to double
  store double %70, ptr %21, align 8, !tbaa !9
  %71 = load double, ptr %21, align 8, !tbaa !9
  %72 = load double, ptr %16, align 8, !tbaa !9
  %73 = call double @sin(double noundef %72) #5
  %74 = load double, ptr %18, align 8, !tbaa !9
  %75 = call double @llvm.fmuladd.f64(double %71, double %73, double %74)
  store double %75, ptr %18, align 8, !tbaa !9
  %76 = load double, ptr %21, align 8, !tbaa !9
  %77 = load double, ptr %16, align 8, !tbaa !9
  %78 = call double @cos(double noundef %77) #5
  %79 = load double, ptr %19, align 8, !tbaa !9
  %80 = call double @llvm.fmuladd.f64(double %76, double %78, double %79)
  store double %80, ptr %19, align 8, !tbaa !9
  %81 = load double, ptr %17, align 8, !tbaa !9
  %82 = load double, ptr %16, align 8, !tbaa !9
  %83 = fadd double %82, %81
  store double %83, ptr %16, align 8, !tbaa !9
  %84 = load double, ptr %16, align 8, !tbaa !9
  %85 = fcmp ogt double %84, 0x401921FB54442D18
  br i1 %85, label %86, label %89

86:                                               ; preds = %66
  %87 = load double, ptr %16, align 8, !tbaa !9
  %88 = fsub double %87, 0x401921FB54442D18
  store double %88, ptr %16, align 8, !tbaa !9
  br label %89

89:                                               ; preds = %86, %66
  %90 = load i32, ptr %15, align 4, !tbaa !11
  %91 = sub nsw i32 %90, 1
  store i32 %91, ptr %15, align 4, !tbaa !11
  call void @llvm.lifetime.end.p0(i64 8, ptr %21) #5
  br label %63, !llvm.loop !18

92:                                               ; preds = %63
  %93 = load double, ptr %18, align 8, !tbaa !9
  %94 = load i32, ptr %12, align 4, !tbaa !11
  %95 = sitofp i32 %94 to double
  %96 = fdiv double %93, %95
  store double %96, ptr %18, align 8, !tbaa !9
  %97 = load double, ptr %19, align 8, !tbaa !9
  %98 = load i32, ptr %12, align 4, !tbaa !11
  %99 = sitofp i32 %98 to double
  %100 = fdiv double %97, %99
  store double %100, ptr %19, align 8, !tbaa !9
  %101 = load double, ptr %18, align 8, !tbaa !9
  %102 = load double, ptr %18, align 8, !tbaa !9
  %103 = load double, ptr %19, align 8, !tbaa !9
  %104 = load double, ptr %19, align 8, !tbaa !9
  %105 = fmul double %103, %104
  %106 = call double @llvm.fmuladd.f64(double %101, double %102, double %105)
  %107 = call double @sqrt(double noundef %106) #5
  %108 = fmul double 2.000000e+00, %107
  store double %108, ptr %14, align 8, !tbaa !9
  %109 = load ptr, ptr %13, align 8, !tbaa !5
  %110 = icmp ne ptr %109, null
  br i1 %110, label %111, label %117

111:                                              ; preds = %92
  call void @llvm.lifetime.start.p0(i64 8, ptr %22) #5
  %112 = load double, ptr %19, align 8, !tbaa !9
  %113 = load double, ptr %18, align 8, !tbaa !9
  %114 = call double @atan2(double noundef %112, double noundef %113) #5
  store double %114, ptr %22, align 8, !tbaa !9
  %115 = load double, ptr %22, align 8, !tbaa !9
  %116 = load ptr, ptr %13, align 8, !tbaa !5
  store double %115, ptr %116, align 8, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 8, ptr %22) #5
  br label %117

117:                                              ; preds = %111, %92
  %118 = load double, ptr %14, align 8, !tbaa !9
  store double %118, ptr %7, align 8
  store i32 1, ptr %23, align 4
  br label %120

119:                                              ; preds = %55, %40
  store double -1.000000e+00, ptr %7, align 8
  store i32 1, ptr %23, align 4
  br label %120

120:                                              ; preds = %119, %117
  call void @llvm.lifetime.end.p0(i64 8, ptr %20) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %19) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %18) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %17) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %16) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %15) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %14) #5
  %121 = load double, ptr %7, align 8
  ret double %121
}

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare double @llvm.fmuladd.f64(double, double, double) #4

; Function Attrs: nounwind
declare double @cos(double noundef) #2

; Function Attrs: nounwind
declare double @sqrt(double noundef) #2

; Function Attrs: nounwind
declare double @atan2(double noundef, double noundef) #2

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { "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 "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 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 #4 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #5 = { 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, !10, i64 0}
!10 = !{!"double", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"int", !7, i64 0}
!13 = !{!14, !6, i64 8}
!14 = !{!"PaQaRecording_s", !12, i64 0, !6, i64 8, !12, i64 16, !12, i64 20}
!15 = !{!14, !12, i64 16}
!16 = !{!17, !17, i64 0}
!17 = !{!"float", !7, i64 0}
!18 = distinct !{!18, !19}
!19 = !{!"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"

@.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.4 = external hidden unnamed_addr constant [25 x i8], align 1
@.str.5 = external hidden unnamed_addr constant [24 x i8], align 1

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

; Function Attrs: mustprogress nofree nounwind willreturn memory(write)
declare double @sin(double noundef) local_unnamed_addr #1

; Function Attrs: nofree nounwind uwtable
define dso_local double @PaQa_CorrelateSine(ptr nocapture noundef readonly %0, double noundef %1, double noundef %2, i32 noundef %3, i32 noundef %4, ptr noundef writeonly %5) local_unnamed_addr #2 {
  %7 = fmul double %1, 0x401921FB54442D18
  %8 = fdiv double %7, %2
  %9 = getelementptr inbounds i8, ptr %0, i64 8
  %10 = load ptr, ptr %9, align 8, !tbaa !5
  %11 = sext i32 %3 to i64
  %12 = getelementptr inbounds float, ptr %10, i64 %11
  %13 = getelementptr inbounds i8, ptr %0, i64 16
  %14 = load i32, ptr %13, align 8, !tbaa !11
  %15 = icmp sgt i32 %14, %3
  br i1 %15, label %18, label %16

16:                                               ; preds = %6
  %17 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str, ptr noundef nonnull @.str.1, i32 noundef 310, ptr noundef nonnull @.str.4)
  br label %54

18:                                               ; preds = %6
  %19 = load i32, ptr @g_testsPassed, align 4, !tbaa !12
  %20 = add nsw i32 %19, 1
  store i32 %20, ptr @g_testsPassed, align 4, !tbaa !12
  %21 = add nsw i32 %4, %3
  %.not = icmp sgt i32 %21, %14
  br i1 %.not, label %22, label %24

22:                                               ; preds = %18
  %23 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str, ptr noundef nonnull @.str.1, i32 noundef 311, ptr noundef nonnull @.str.5)
  br label %54

24:                                               ; preds = %18
  %25 = add nsw i32 %19, 2
  store i32 %25, ptr @g_testsPassed, align 4, !tbaa !12
  %26 = icmp sgt i32 %4, 0
  br i1 %26, label %.lr.ph, label %._crit_edge

.lr.ph:                                           ; preds = %24, %.lr.ph
  %.03751 = phi ptr [ %28, %.lr.ph ], [ %12, %24 ]
  %.04048 = phi i32 [ %41, %.lr.ph ], [ %4, %24 ]
  %.04147 = phi double [ %.1, %.lr.ph ], [ 0.000000e+00, %24 ]
  %27 = phi <2 x double> [ %37, %.lr.ph ], [ zeroinitializer, %24 ]
  %28 = getelementptr inbounds i8, ptr %.03751, i64 4
  %29 = load float, ptr %.03751, align 4, !tbaa !13
  %30 = fpext float %29 to double
  %31 = tail call double @sin(double noundef %.04147) #5
  %32 = tail call double @cos(double noundef %.04147) #5
  %33 = insertelement <2 x double> poison, double %30, i64 0
  %34 = shufflevector <2 x double> %33, <2 x double> poison, <2 x i32> zeroinitializer
  %35 = insertelement <2 x double> poison, double %31, i64 0
  %36 = insertelement <2 x double> %35, double %32, i64 1
  %37 = tail call <2 x double> @llvm.fmuladd.v2f64(<2 x double> %34, <2 x double> %36, <2 x double> %27)
  %38 = fadd double %8, %.04147
  %39 = fcmp ogt double %38, 0x401921FB54442D18
  %40 = fadd double %38, 0xC01921FB54442D18
  %.1 = select i1 %39, double %40, double %38
  %41 = add nsw i32 %.04048, -1
  %42 = icmp ugt i32 %.04048, 1
  br i1 %42, label %.lr.ph, label %._crit_edge, !llvm.loop !15

._crit_edge:                                      ; preds = %.lr.ph, %24
  %43 = phi <2 x double> [ zeroinitializer, %24 ], [ %37, %.lr.ph ]
  %44 = sitofp i32 %4 to double
  %45 = extractelement <2 x double> %43, i64 0
  %46 = fdiv double %45, %44
  %47 = extractelement <2 x double> %43, i64 1
  %48 = fdiv double %47, %44
  %49 = fmul double %48, %48
  %50 = tail call double @llvm.fmuladd.f64(double %46, double %46, double %49)
  %sqrt = tail call double @llvm.sqrt.f64(double %50)
  %51 = fmul double %sqrt, 2.000000e+00
  %.not46 = icmp eq ptr %5, null
  br i1 %.not46, label %55, label %52

52:                                               ; preds = %._crit_edge
  %53 = tail call double @atan2(double noundef %48, double noundef %46) #5
  store double %53, ptr %5, align 8, !tbaa !17
  br label %55

54:                                               ; preds = %22, %16
  %storemerge.in = load i32, ptr @g_testsFailed, align 4, !tbaa !12
  %storemerge = add nsw i32 %storemerge.in, 1
  store i32 %storemerge, ptr @g_testsFailed, align 4, !tbaa !12
  br label %55

55:                                               ; preds = %._crit_edge, %52, %54
  %.0 = phi double [ -1.000000e+00, %54 ], [ %51, %52 ], [ %51, %._crit_edge ]
  ret double %.0
}

; Function Attrs: mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare double @llvm.fmuladd.f64(double, double, double) #3

; Function Attrs: mustprogress nofree nounwind willreturn memory(write)
declare double @cos(double noundef) local_unnamed_addr #1

; Function Attrs: mustprogress nofree nounwind willreturn memory(write)
declare double @atan2(double noundef, double noundef) local_unnamed_addr #1

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare double @llvm.sqrt.f64(double) #4

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare <2 x double> @llvm.fmuladd.v2f64(<2 x double>, <2 x double>, <2 x double>) #4

attributes #0 = { 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 #1 = { mustprogress nofree nounwind willreturn memory(write) "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 = { nofree 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 #3 = { mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #4 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #5 = { 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 = !{!"PaQaRecording_s", !7, i64 0, !10, i64 8, !7, i64 16, !7, i64 20}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"any pointer", !8, i64 0}
!11 = !{!6, !7, i64 16}
!12 = !{!7, !7, i64 0}
!13 = !{!14, !14, i64 0}
!14 = !{!"float", !8, i64 0}
!15 = distinct !{!15, !16}
!16 = !{!"llvm.loop.mustprogress"}
!17 = !{!18, !18, i64 0}
!18 = !{!"double", !8, i64 0}


; Effective O3 passes: AggressiveInstCombinePass,CorrelatedValuePropagationPass,EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,ReassociatePass,SLPVectorizerPass,SROAPass,SimplifyCFGPass,TailCallElimPass