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

; 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

; Function Attrs: nounwind uwtable
define dso_local double @PaQa_MeasureCrossingSlope(ptr noundef %0, i32 noundef %1) #1 {
  %3 = alloca ptr, align 8
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  %6 = alloca double, align 8
  %7 = alloca i32, align 4
  %8 = alloca float, align 4
  %9 = alloca double, align 8
  %10 = alloca float, align 4
  %11 = alloca double, align 8
  store ptr %0, ptr %3, align 8, !tbaa !5
  store i32 %1, ptr %4, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #2
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #2
  store double 0.000000e+00, ptr %6, align 8, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #2
  store i32 0, ptr %7, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #2
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #2
  store double 0.000000e+00, ptr %9, align 8, !tbaa !11
  %12 = load ptr, ptr %3, align 8, !tbaa !5
  %13 = getelementptr inbounds float, ptr %12, i64 0
  %14 = load float, ptr %13, align 4, !tbaa !13
  store float %14, ptr %8, align 4, !tbaa !13
  store i32 1, ptr %5, align 4, !tbaa !9
  br label %15

15:                                               ; preds = %44, %2
  %16 = load i32, ptr %5, align 4, !tbaa !9
  %17 = load i32, ptr %4, align 4, !tbaa !9
  %18 = icmp slt i32 %16, %17
  br i1 %18, label %19, label %47

19:                                               ; preds = %15
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #2
  %20 = load ptr, ptr %3, align 8, !tbaa !5
  %21 = load i32, ptr %5, align 4, !tbaa !9
  %22 = sext i32 %21 to i64
  %23 = getelementptr inbounds float, ptr %20, i64 %22
  %24 = load float, ptr %23, align 4, !tbaa !13
  store float %24, ptr %10, align 4, !tbaa !13
  %25 = load float, ptr %10, align 4, !tbaa !13
  %26 = fpext float %25 to double
  %27 = fcmp ogt double %26, 0.000000e+00
  br i1 %27, label %28, label %42

28:                                               ; preds = %19
  %29 = load float, ptr %8, align 4, !tbaa !13
  %30 = fpext float %29 to double
  %31 = fcmp olt double %30, 0.000000e+00
  br i1 %31, label %32, label %42

32:                                               ; preds = %28
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #2
  %33 = load float, ptr %10, align 4, !tbaa !13
  %34 = load float, ptr %8, align 4, !tbaa !13
  %35 = fsub float %33, %34
  %36 = fpext float %35 to double
  store double %36, ptr %11, align 8, !tbaa !11
  %37 = load double, ptr %11, align 8, !tbaa !11
  %38 = load double, ptr %6, align 8, !tbaa !11
  %39 = fadd double %38, %37
  store double %39, ptr %6, align 8, !tbaa !11
  %40 = load i32, ptr %7, align 4, !tbaa !9
  %41 = add nsw i32 %40, 1
  store i32 %41, ptr %7, align 4, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #2
  br label %42

42:                                               ; preds = %32, %28, %19
  %43 = load float, ptr %10, align 4, !tbaa !13
  store float %43, ptr %8, align 4, !tbaa !13
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #2
  br label %44

44:                                               ; preds = %42
  %45 = load i32, ptr %5, align 4, !tbaa !9
  %46 = add nsw i32 %45, 1
  store i32 %46, ptr %5, align 4, !tbaa !9
  br label %15, !llvm.loop !15

47:                                               ; preds = %15
  %48 = load i32, ptr %7, align 4, !tbaa !9
  %49 = icmp sgt i32 %48, 0
  br i1 %49, label %50, label %55

50:                                               ; preds = %47
  %51 = load double, ptr %6, align 8, !tbaa !11
  %52 = load i32, ptr %7, align 4, !tbaa !9
  %53 = sitofp i32 %52 to double
  %54 = fdiv double %51, %53
  store double %54, ptr %9, align 8, !tbaa !11
  br label %55

55:                                               ; preds = %50, %47
  %56 = load double, ptr %9, align 8, !tbaa !11
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #2
  ret double %56
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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" }
attributes #2 = { 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, !12, i64 0}
!12 = !{!"double", !7, i64 0}
!13 = !{!14, !14, i64 0}
!14 = !{!"float", !7, i64 0}
!15 = distinct !{!15, !16}
!16 = !{!"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"

; Function Attrs: nofree norecurse nosync nounwind memory(argmem: read) uwtable
define dso_local double @PaQa_MeasureCrossingSlope(ptr nocapture noundef readonly %0, i32 noundef %1) local_unnamed_addr #0 {
  %3 = icmp sgt i32 %1, 1
  br i1 %3, label %.lr.ph.preheader, label %._crit_edge.thread

.lr.ph.preheader:                                 ; preds = %2
  %4 = load float, ptr %0, align 4, !tbaa !5
  %wide.trip.count = zext nneg i32 %1 to i64
  %5 = add nsw i64 %wide.trip.count, -1
  %xtraiter = and i64 %5, 1
  %6 = icmp eq i32 %1, 2
  br i1 %6, label %._crit_edge.unr-lcssa, label %.lr.ph.preheader.new

.lr.ph.preheader.new:                             ; preds = %.lr.ph.preheader
  %unroll_iter = and i64 %5, -2
  %invariant.gep = getelementptr inbounds i8, ptr %0, i64 4
  br label %.lr.ph

.lr.ph:                                           ; preds = %.lr.ph, %.lr.ph.preheader.new
  %indvars.iv = phi i64 [ 1, %.lr.ph.preheader.new ], [ %indvars.iv.next.1, %.lr.ph ]
  %.01724 = phi double [ 0.000000e+00, %.lr.ph.preheader.new ], [ %.1.1, %.lr.ph ]
  %.01923 = phi float [ %4, %.lr.ph.preheader.new ], [ %15, %.lr.ph ]
  %.02022 = phi i32 [ 0, %.lr.ph.preheader.new ], [ %.121.1, %.lr.ph ]
  %niter = phi i64 [ 0, %.lr.ph.preheader.new ], [ %niter.next.1, %.lr.ph ]
  %7 = getelementptr inbounds float, ptr %0, i64 %indvars.iv
  %8 = load float, ptr %7, align 4, !tbaa !5
  %9 = fcmp ogt float %8, 0.000000e+00
  %10 = fcmp olt float %.01923, 0.000000e+00
  %or.cond = select i1 %9, i1 %10, i1 false
  %or.cond.fr = freeze i1 %or.cond
  %11 = fsub float %8, %.01923
  %12 = fpext float %11 to double
  %13 = fadd double %.01724, %12
  %14 = zext i1 %or.cond.fr to i32
  %.121 = add i32 %.02022, %14
  %.1 = select i1 %or.cond.fr, double %13, double %.01724
  %gep = getelementptr inbounds float, ptr %invariant.gep, i64 %indvars.iv
  %15 = load float, ptr %gep, align 4, !tbaa !5
  %16 = fcmp ogt float %15, 0.000000e+00
  %17 = fcmp olt float %8, 0.000000e+00
  %or.cond.1 = select i1 %16, i1 %17, i1 false
  %or.cond.fr.1 = freeze i1 %or.cond.1
  %18 = fsub float %15, %8
  %19 = fpext float %18 to double
  %20 = fadd double %.1, %19
  %21 = zext i1 %or.cond.fr.1 to i32
  %.121.1 = add i32 %.121, %21
  %.1.1 = select i1 %or.cond.fr.1, double %20, double %.1
  %indvars.iv.next.1 = add nuw nsw i64 %indvars.iv, 2
  %niter.next.1 = add i64 %niter, 2
  %niter.ncmp.1 = icmp eq i64 %niter.next.1, %unroll_iter
  br i1 %niter.ncmp.1, label %._crit_edge.unr-lcssa, label %.lr.ph, !llvm.loop !9

._crit_edge.unr-lcssa:                            ; preds = %.lr.ph, %.lr.ph.preheader
  %.121.lcssa.ph = phi i32 [ poison, %.lr.ph.preheader ], [ %.121.1, %.lr.ph ]
  %.1.lcssa.ph = phi double [ poison, %.lr.ph.preheader ], [ %.1.1, %.lr.ph ]
  %indvars.iv.unr = phi i64 [ 1, %.lr.ph.preheader ], [ %indvars.iv.next.1, %.lr.ph ]
  %.01724.unr = phi double [ 0.000000e+00, %.lr.ph.preheader ], [ %.1.1, %.lr.ph ]
  %.01923.unr = phi float [ %4, %.lr.ph.preheader ], [ %15, %.lr.ph ]
  %.02022.unr = phi i32 [ 0, %.lr.ph.preheader ], [ %.121.1, %.lr.ph ]
  %lcmp.mod.not = icmp eq i64 %xtraiter, 0
  br i1 %lcmp.mod.not, label %._crit_edge, label %.lr.ph.epil

.lr.ph.epil:                                      ; preds = %._crit_edge.unr-lcssa
  %22 = getelementptr inbounds float, ptr %0, i64 %indvars.iv.unr
  %23 = load float, ptr %22, align 4, !tbaa !5
  %24 = fcmp ogt float %23, 0.000000e+00
  %25 = fcmp olt float %.01923.unr, 0.000000e+00
  %or.cond.epil = select i1 %24, i1 %25, i1 false
  %or.cond.fr.epil = freeze i1 %or.cond.epil
  %26 = fsub float %23, %.01923.unr
  %27 = fpext float %26 to double
  %28 = fadd double %.01724.unr, %27
  %29 = zext i1 %or.cond.fr.epil to i32
  %.121.epil = add i32 %.02022.unr, %29
  %.1.epil = select i1 %or.cond.fr.epil, double %28, double %.01724.unr
  br label %._crit_edge

._crit_edge:                                      ; preds = %._crit_edge.unr-lcssa, %.lr.ph.epil
  %.121.lcssa = phi i32 [ %.121.lcssa.ph, %._crit_edge.unr-lcssa ], [ %.121.epil, %.lr.ph.epil ]
  %.1.lcssa = phi double [ %.1.lcssa.ph, %._crit_edge.unr-lcssa ], [ %.1.epil, %.lr.ph.epil ]
  %.not = icmp eq i32 %.121.lcssa, 0
  br i1 %.not, label %._crit_edge.thread, label %30

30:                                               ; preds = %._crit_edge
  %31 = uitofp nneg i32 %.121.lcssa to double
  %32 = fdiv double %.1.lcssa, %31
  br label %._crit_edge.thread

._crit_edge.thread:                               ; preds = %2, %._crit_edge, %30
  %33 = phi double [ %32, %30 ], [ 0.000000e+00, %._crit_edge ], [ 0.000000e+00, %2 ]
  ret double %33
}

attributes #0 = { nofree norecurse nosync nounwind memory(argmem: read) 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, !6, i64 0}
!6 = !{!"float", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}


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