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

; 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 void @PaQa_MixSine(ptr noundef %0, ptr noundef %1, i32 noundef %2, i32 noundef %3) #1 {
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  %10 = alloca float, align 4
  store ptr %0, ptr %5, align 8, !tbaa !5
  store ptr %1, ptr %6, align 8, !tbaa !5
  store i32 %2, ptr %7, align 4, !tbaa !9
  store i32 %3, ptr %8, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #3
  store i32 0, ptr %9, align 4, !tbaa !9
  br label %11

11:                                               ; preds = %52, %4
  %12 = load i32, ptr %9, align 4, !tbaa !9
  %13 = load i32, ptr %7, align 4, !tbaa !9
  %14 = icmp slt i32 %12, %13
  br i1 %14, label %15, label %55

15:                                               ; preds = %11
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #3
  %16 = load ptr, ptr %5, align 8, !tbaa !5
  %17 = getelementptr inbounds %struct.PaQaSineGenerator_s, ptr %16, i32 0, i32 0
  %18 = load double, ptr %17, align 8, !tbaa !11
  %19 = fptrunc double %18 to float
  %20 = call float @sinf(float noundef %19) #3
  %21 = fpext float %20 to double
  %22 = load ptr, ptr %5, align 8, !tbaa !5
  %23 = getelementptr inbounds %struct.PaQaSineGenerator_s, ptr %22, i32 0, i32 3
  %24 = load double, ptr %23, align 8, !tbaa !14
  %25 = fmul double %21, %24
  %26 = fptrunc double %25 to float
  store float %26, ptr %10, align 4, !tbaa !15
  %27 = load float, ptr %10, align 4, !tbaa !15
  %28 = load ptr, ptr %6, align 8, !tbaa !5
  %29 = load float, ptr %28, align 4, !tbaa !15
  %30 = fadd float %29, %27
  store float %30, ptr %28, align 4, !tbaa !15
  %31 = load i32, ptr %8, align 4, !tbaa !9
  %32 = load ptr, ptr %6, align 8, !tbaa !5
  %33 = sext i32 %31 to i64
  %34 = getelementptr inbounds float, ptr %32, i64 %33
  store ptr %34, ptr %6, align 8, !tbaa !5
  %35 = load ptr, ptr %5, align 8, !tbaa !5
  %36 = getelementptr inbounds %struct.PaQaSineGenerator_s, ptr %35, i32 0, i32 1
  %37 = load double, ptr %36, align 8, !tbaa !17
  %38 = load ptr, ptr %5, align 8, !tbaa !5
  %39 = getelementptr inbounds %struct.PaQaSineGenerator_s, ptr %38, i32 0, i32 0
  %40 = load double, ptr %39, align 8, !tbaa !11
  %41 = fadd double %40, %37
  store double %41, ptr %39, align 8, !tbaa !11
  %42 = load ptr, ptr %5, align 8, !tbaa !5
  %43 = getelementptr inbounds %struct.PaQaSineGenerator_s, ptr %42, i32 0, i32 0
  %44 = load double, ptr %43, align 8, !tbaa !11
  %45 = fcmp ogt double %44, 0x401921FB54442D18
  br i1 %45, label %46, label %51

46:                                               ; preds = %15
  %47 = load ptr, ptr %5, align 8, !tbaa !5
  %48 = getelementptr inbounds %struct.PaQaSineGenerator_s, ptr %47, i32 0, i32 0
  %49 = load double, ptr %48, align 8, !tbaa !11
  %50 = fsub double %49, 0x401921FB54442D18
  store double %50, ptr %48, align 8, !tbaa !11
  br label %51

51:                                               ; preds = %46, %15
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #3
  br label %52

52:                                               ; preds = %51
  %53 = load i32, ptr %9, align 4, !tbaa !9
  %54 = add nsw i32 %53, 1
  store i32 %54, ptr %9, align 4, !tbaa !9
  br label %11, !llvm.loop !18

55:                                               ; preds = %11
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #3
  ret void
}

; Function Attrs: nounwind
declare float @sinf(float noundef) #2

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 "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, !13, i64 0}
!12 = !{!"PaQaSineGenerator_s", !13, i64 0, !13, i64 8, !13, i64 16, !13, i64 24}
!13 = !{!"double", !7, i64 0}
!14 = !{!12, !13, i64 24}
!15 = !{!16, !16, i64 0}
!16 = !{!"float", !7, i64 0}
!17 = !{!12, !13, i64 8}
!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"

; Function Attrs: nofree nounwind memory(readwrite, inaccessiblemem: write) uwtable
define dso_local void @PaQa_MixSine(ptr nocapture noundef %0, ptr nocapture noundef %1, i32 noundef %2, i32 noundef %3) local_unnamed_addr #0 {
  %5 = icmp sgt i32 %2, 0
  br i1 %5, label %.lr.ph, label %._crit_edge

.lr.ph:                                           ; preds = %4
  %6 = getelementptr inbounds i8, ptr %0, i64 24
  %7 = sext i32 %3 to i64
  %8 = getelementptr inbounds i8, ptr %0, i64 8
  %.pre = load double, ptr %0, align 8, !tbaa !5
  br label %9

9:                                                ; preds = %.lr.ph, %9
  %10 = phi double [ %.pre, %.lr.ph ], [ %storemerge, %9 ]
  %.015 = phi ptr [ %1, %.lr.ph ], [ %19, %9 ]
  %.01214 = phi i32 [ 0, %.lr.ph ], [ %25, %9 ]
  %11 = fptrunc double %10 to float
  %12 = tail call float @sinf(float noundef %11) #2
  %13 = fpext float %12 to double
  %14 = load double, ptr %6, align 8, !tbaa !10
  %15 = fmul double %14, %13
  %16 = fptrunc double %15 to float
  %17 = load float, ptr %.015, align 4, !tbaa !11
  %18 = fadd float %17, %16
  store float %18, ptr %.015, align 4, !tbaa !11
  %19 = getelementptr inbounds float, ptr %.015, i64 %7
  %20 = load double, ptr %8, align 8, !tbaa !13
  %21 = load double, ptr %0, align 8, !tbaa !5
  %22 = fadd double %20, %21
  %23 = fcmp ogt double %22, 0x401921FB54442D18
  %24 = fadd double %22, 0xC01921FB54442D18
  %storemerge = select i1 %23, double %24, double %22
  store double %storemerge, ptr %0, align 8, !tbaa !5
  %25 = add nuw nsw i32 %.01214, 1
  %exitcond.not = icmp eq i32 %25, %2
  br i1 %exitcond.not, label %._crit_edge, label %9, !llvm.loop !14

._crit_edge:                                      ; preds = %9, %4
  ret void
}

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

attributes #0 = { nofree nounwind memory(readwrite, inaccessiblemem: write) 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 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 = { 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 0}
!6 = !{!"PaQaSineGenerator_s", !7, i64 0, !7, i64 8, !7, i64 16, !7, i64 24}
!7 = !{!"double", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!6, !7, i64 24}
!11 = !{!12, !12, i64 0}
!12 = !{!"float", !8, i64 0}
!13 = !{!6, !7, i64 8}
!14 = distinct !{!14, !15}
!15 = !{!"llvm.loop.mustprogress"}


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