; 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.6 = external hidden unnamed_addr constant [32 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 uwtable
declare dso_local double @PaQa_MeasureArea(ptr noundef, i32 noundef, i32 noundef) #2

; Function Attrs: nounwind uwtable
define dso_local double @PaQa_CompareAmplitudes(ptr noundef %0, i32 noundef %1, ptr noundef %2, i32 noundef %3) #2 {
  %5 = alloca double, align 8
  %6 = alloca ptr, align 8
  %7 = alloca i32, align 4
  %8 = alloca ptr, align 8
  %9 = alloca i32, align 4
  %10 = alloca double, align 8
  %11 = alloca double, align 8
  %12 = alloca i32, align 4
  store ptr %0, ptr %6, align 8, !tbaa !5
  store i32 %1, ptr %7, align 4, !tbaa !9
  store ptr %2, ptr %8, align 8, !tbaa !5
  store i32 %3, ptr %9, align 4, !tbaa !9
  %13 = load i32, ptr %7, align 4, !tbaa !9
  %14 = load i32, ptr %9, align 4, !tbaa !9
  %15 = add nsw i32 %13, %14
  %16 = load ptr, ptr %6, align 8, !tbaa !5
  %17 = getelementptr inbounds %struct.PaQaRecording_s, ptr %16, i32 0, i32 2
  %18 = load i32, ptr %17, align 8, !tbaa !11
  %19 = icmp slt i32 %15, %18
  br i1 %19, label %24, label %20

20:                                               ; preds = %4
  %21 = call i32 (ptr, ...) @printf(ptr noundef @.str, ptr noundef @.str.1, i32 noundef 449, ptr noundef @.str.6)
  %22 = load i32, ptr @g_testsFailed, align 4, !tbaa !9
  %23 = add nsw i32 %22, 1
  store i32 %23, ptr @g_testsFailed, align 4, !tbaa !9
  br label %47

24:                                               ; preds = %4
  %25 = load i32, ptr @g_testsPassed, align 4, !tbaa !9
  %26 = add nsw i32 %25, 1
  store i32 %26, ptr @g_testsPassed, align 4, !tbaa !9
  br label %27

27:                                               ; preds = %24
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #3
  %28 = load ptr, ptr %6, align 8, !tbaa !5
  %29 = getelementptr inbounds %struct.PaQaRecording_s, ptr %28, i32 0, i32 1
  %30 = load ptr, ptr %29, align 8, !tbaa !13
  %31 = load i32, ptr %7, align 4, !tbaa !9
  %32 = sext i32 %31 to i64
  %33 = getelementptr inbounds float, ptr %30, i64 %32
  %34 = load i32, ptr %9, align 4, !tbaa !9
  %35 = call double @PaQa_MeasureArea(ptr noundef %33, i32 noundef %34, i32 noundef 1)
  store double %35, ptr %10, align 8, !tbaa !14
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #3
  %36 = load ptr, ptr %8, align 8, !tbaa !5
  %37 = load i32, ptr %9, align 4, !tbaa !9
  %38 = call double @PaQa_MeasureArea(ptr noundef %36, i32 noundef %37, i32 noundef 1)
  store double %38, ptr %11, align 8, !tbaa !14
  %39 = load double, ptr %11, align 8, !tbaa !14
  %40 = fcmp oeq double %39, 0.000000e+00
  br i1 %40, label %41, label %42

41:                                               ; preds = %27
  store double 1.000000e+08, ptr %5, align 8
  store i32 1, ptr %12, align 4
  br label %46

42:                                               ; preds = %27
  %43 = load double, ptr %10, align 8, !tbaa !14
  %44 = load double, ptr %11, align 8, !tbaa !14
  %45 = fdiv double %43, %44
  store double %45, ptr %5, align 8
  store i32 1, ptr %12, align 4
  br label %46

46:                                               ; preds = %42, %41
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #3
  br label %48

47:                                               ; preds = %20
  store double -1.000000e+00, ptr %5, align 8
  br label %48

48:                                               ; preds = %47, %46
  %49 = load double, ptr %5, align 8
  ret double %49
}

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 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 = { 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 = !{!"int", !7, i64 0}
!11 = !{!12, !10, i64 16}
!12 = !{!"PaQaRecording_s", !10, i64 0, !6, i64 8, !10, i64 16, !10, i64 20}
!13 = !{!12, !6, i64 8}
!14 = !{!15, !15, i64 0}
!15 = !{!"double", !7, i64 0}


; 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.6 = external hidden unnamed_addr constant [32 x i8], align 1

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

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

; Function Attrs: nounwind uwtable
define dso_local double @PaQa_CompareAmplitudes(ptr nocapture noundef readonly %0, i32 noundef %1, ptr noundef %2, i32 noundef %3) local_unnamed_addr #1 {
  %5 = add nsw i32 %3, %1
  %6 = getelementptr inbounds i8, ptr %0, i64 16
  %7 = load i32, ptr %6, align 8, !tbaa !5
  %8 = icmp slt i32 %5, %7
  br i1 %8, label %13, label %9

9:                                                ; preds = %4
  %10 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str, ptr noundef nonnull @.str.1, i32 noundef 449, ptr noundef nonnull @.str.6)
  %11 = load i32, ptr @g_testsFailed, align 4, !tbaa !11
  %12 = add nsw i32 %11, 1
  store i32 %12, ptr @g_testsFailed, align 4, !tbaa !11
  br label %24

13:                                               ; preds = %4
  %14 = load i32, ptr @g_testsPassed, align 4, !tbaa !11
  %15 = add nsw i32 %14, 1
  store i32 %15, ptr @g_testsPassed, align 4, !tbaa !11
  %16 = getelementptr inbounds i8, ptr %0, i64 8
  %17 = load ptr, ptr %16, align 8, !tbaa !12
  %18 = sext i32 %1 to i64
  %19 = getelementptr inbounds float, ptr %17, i64 %18
  %20 = tail call double @PaQa_MeasureArea(ptr noundef %19, i32 noundef %3, i32 noundef 1)
  %21 = tail call double @PaQa_MeasureArea(ptr noundef %2, i32 noundef %3, i32 noundef 1)
  %22 = fcmp oeq double %21, 0.000000e+00
  %23 = fdiv double %20, %21
  %.0 = select i1 %22, double 1.000000e+08, double %23
  br label %24

24:                                               ; preds = %9, %13
  %.1 = phi double [ %.0, %13 ], [ -1.000000e+00, %9 ]
  ret double %.1
}

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

!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 = !{!"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 = !{!7, !7, i64 0}
!12 = !{!6, !10, i64 8}


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