; LLVM IR from lichen-community-systems/signaletic :: libsignaletic/tests/util (buffer-test-utils)

; 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.sig_test_BufferPlayer = type { %struct.sig_dsp_Signal, %struct.sig_dsp_Signal_SingleMonoOutput, ptr, i64 }
%struct.sig_dsp_Signal = type { ptr, ptr }
%struct.sig_dsp_Signal_SingleMonoOutput = type { ptr }
%struct.sig_AudioSettings = type { float, i64, i64 }
%struct.sig_Buffer = type { i64, ptr }

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

6:                                                ; preds = %50, %1
  %7 = load i64, ptr %4, align 8, !tbaa !9
  %8 = load ptr, ptr %3, align 8, !tbaa !5
  %9 = getelementptr inbounds %struct.sig_test_BufferPlayer, ptr %8, i32 0, i32 0
  %10 = getelementptr inbounds %struct.sig_dsp_Signal, ptr %9, i32 0, i32 0
  %11 = load ptr, ptr %10, align 8, !tbaa !11
  %12 = getelementptr inbounds %struct.sig_AudioSettings, ptr %11, i32 0, i32 2
  %13 = load i64, ptr %12, align 8, !tbaa !15
  %14 = icmp ult i64 %7, %13
  br i1 %14, label %16, label %15

15:                                               ; preds = %6
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #2
  br label %53

16:                                               ; preds = %6
  %17 = load ptr, ptr %3, align 8, !tbaa !5
  %18 = getelementptr inbounds %struct.sig_test_BufferPlayer, ptr %17, i32 0, i32 3
  %19 = load i64, ptr %18, align 8, !tbaa !18
  %20 = load ptr, ptr %3, align 8, !tbaa !5
  %21 = getelementptr inbounds %struct.sig_test_BufferPlayer, ptr %20, i32 0, i32 2
  %22 = load ptr, ptr %21, align 8, !tbaa !19
  %23 = getelementptr inbounds %struct.sig_Buffer, ptr %22, i32 0, i32 0
  %24 = load i64, ptr %23, align 8, !tbaa !20
  %25 = icmp uge i64 %19, %24
  br i1 %25, label %26, label %29

26:                                               ; preds = %16
  %27 = load ptr, ptr %3, align 8, !tbaa !5
  %28 = getelementptr inbounds %struct.sig_test_BufferPlayer, ptr %27, i32 0, i32 3
  store i64 0, ptr %28, align 8, !tbaa !18
  br label %29

29:                                               ; preds = %26, %16
  %30 = load ptr, ptr %3, align 8, !tbaa !5
  %31 = getelementptr inbounds %struct.sig_test_BufferPlayer, ptr %30, i32 0, i32 2
  %32 = load ptr, ptr %31, align 8, !tbaa !19
  %33 = getelementptr inbounds %struct.sig_Buffer, ptr %32, i32 0, i32 1
  %34 = load ptr, ptr %33, align 8, !tbaa !22
  %35 = load ptr, ptr %3, align 8, !tbaa !5
  %36 = getelementptr inbounds %struct.sig_test_BufferPlayer, ptr %35, i32 0, i32 3
  %37 = load i64, ptr %36, align 8, !tbaa !18
  %38 = getelementptr inbounds float, ptr %34, i64 %37
  %39 = load float, ptr %38, align 4, !tbaa !23
  %40 = load ptr, ptr %3, align 8, !tbaa !5
  %41 = getelementptr inbounds %struct.sig_test_BufferPlayer, ptr %40, i32 0, i32 1
  %42 = getelementptr inbounds %struct.sig_dsp_Signal_SingleMonoOutput, ptr %41, i32 0, i32 0
  %43 = load ptr, ptr %42, align 8, !tbaa !24
  %44 = load i64, ptr %4, align 8, !tbaa !9
  %45 = getelementptr inbounds float, ptr %43, i64 %44
  store float %39, ptr %45, align 4, !tbaa !23
  %46 = load ptr, ptr %3, align 8, !tbaa !5
  %47 = getelementptr inbounds %struct.sig_test_BufferPlayer, ptr %46, i32 0, i32 3
  %48 = load i64, ptr %47, align 8, !tbaa !18
  %49 = add i64 %48, 1
  store i64 %49, ptr %47, align 8, !tbaa !18
  br label %50

50:                                               ; preds = %29
  %51 = load i64, ptr %4, align 8, !tbaa !9
  %52 = add i64 %51, 1
  store i64 %52, ptr %4, align 8, !tbaa !9
  br label %6, !llvm.loop !25

53:                                               ; preds = %15
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #2
  ret void
}

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 = !{!"long", !7, i64 0}
!11 = !{!12, !6, i64 0}
!12 = !{!"sig_test_BufferPlayer", !13, i64 0, !14, i64 16, !6, i64 24, !10, i64 32}
!13 = !{!"sig_dsp_Signal", !6, i64 0, !6, i64 8}
!14 = !{!"sig_dsp_Signal_SingleMonoOutput", !6, i64 0}
!15 = !{!16, !10, i64 16}
!16 = !{!"sig_AudioSettings", !17, i64 0, !10, i64 8, !10, i64 16}
!17 = !{!"float", !7, i64 0}
!18 = !{!12, !10, i64 32}
!19 = !{!12, !6, i64 24}
!20 = !{!21, !10, i64 0}
!21 = !{!"sig_Buffer", !10, i64 0, !6, i64 8}
!22 = !{!21, !6, i64 8}
!23 = !{!17, !17, i64 0}
!24 = !{!12, !6, i64 16}
!25 = distinct !{!25, !26}
!26 = !{!"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(readwrite, inaccessiblemem: none) uwtable
define dso_local void @sig_test_BufferPlayer_generate(ptr nocapture noundef %0) local_unnamed_addr #0 {
  %2 = load ptr, ptr %0, align 8, !tbaa !5
  %3 = getelementptr inbounds i8, ptr %2, i64 16
  %4 = load i64, ptr %3, align 8, !tbaa !13
  %.not12 = icmp eq i64 %4, 0
  br i1 %.not12, label %18, label %.lr.ph

.lr.ph:                                           ; preds = %1
  %5 = getelementptr inbounds i8, ptr %0, i64 32
  %6 = getelementptr inbounds i8, ptr %0, i64 24
  %7 = load ptr, ptr %6, align 8, !tbaa !16
  %8 = load i64, ptr %7, align 8, !tbaa !17
  %9 = getelementptr inbounds i8, ptr %7, i64 8
  %10 = load ptr, ptr %9, align 8, !tbaa !19
  %11 = getelementptr inbounds i8, ptr %0, i64 16
  %12 = load ptr, ptr %11, align 8, !tbaa !20
  %.promoted = load i64, ptr %5, align 8, !tbaa !21
  %xtraiter = and i64 %4, 1
  %13 = icmp eq i64 %4, 1
  br i1 %13, label %._crit_edge.unr-lcssa, label %.lr.ph.new

.lr.ph.new:                                       ; preds = %.lr.ph
  %unroll_iter = and i64 %4, -2
  br label %19

._crit_edge.unr-lcssa:                            ; preds = %19, %.lr.ph
  %.lcssa.ph = phi i64 [ poison, %.lr.ph ], [ %29, %19 ]
  %.unr = phi i64 [ %.promoted, %.lr.ph ], [ %29, %19 ]
  %.011.unr = phi i64 [ 0, %.lr.ph ], [ %30, %19 ]
  %lcmp.mod.not = icmp eq i64 %xtraiter, 0
  br i1 %lcmp.mod.not, label %._crit_edge, label %._crit_edge.epilog-lcssa

._crit_edge.epilog-lcssa:                         ; preds = %._crit_edge.unr-lcssa
  %.not.epil = icmp ult i64 %.unr, %8
  %spec.select.epil = select i1 %.not.epil, i64 %.unr, i64 0
  %14 = getelementptr inbounds float, ptr %10, i64 %spec.select.epil
  %15 = load float, ptr %14, align 4, !tbaa !22
  %16 = getelementptr inbounds float, ptr %12, i64 %.011.unr
  store float %15, ptr %16, align 4, !tbaa !22
  %17 = add i64 %spec.select.epil, 1
  br label %._crit_edge

._crit_edge:                                      ; preds = %._crit_edge.unr-lcssa, %._crit_edge.epilog-lcssa
  %.lcssa = phi i64 [ %.lcssa.ph, %._crit_edge.unr-lcssa ], [ %17, %._crit_edge.epilog-lcssa ]
  store i64 %.lcssa, ptr %5, align 8, !tbaa !21
  br label %18

18:                                               ; preds = %._crit_edge, %1
  ret void

19:                                               ; preds = %19, %.lr.ph.new
  %20 = phi i64 [ %.promoted, %.lr.ph.new ], [ %29, %19 ]
  %.011 = phi i64 [ 0, %.lr.ph.new ], [ %30, %19 ]
  %niter = phi i64 [ 0, %.lr.ph.new ], [ %niter.next.1, %19 ]
  %.not = icmp ult i64 %20, %8
  %spec.select = select i1 %.not, i64 %20, i64 0
  %21 = getelementptr inbounds float, ptr %10, i64 %spec.select
  %22 = load float, ptr %21, align 4, !tbaa !22
  %23 = getelementptr inbounds float, ptr %12, i64 %.011
  store float %22, ptr %23, align 4, !tbaa !22
  %24 = add i64 %spec.select, 1
  %25 = or disjoint i64 %.011, 1
  %.not.1 = icmp ult i64 %24, %8
  %spec.select.1 = select i1 %.not.1, i64 %24, i64 0
  %26 = getelementptr inbounds float, ptr %10, i64 %spec.select.1
  %27 = load float, ptr %26, align 4, !tbaa !22
  %28 = getelementptr inbounds float, ptr %12, i64 %25
  store float %27, ptr %28, align 4, !tbaa !22
  %29 = add i64 %spec.select.1, 1
  %30 = add nuw i64 %.011, 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 %19, !llvm.loop !23
}

attributes #0 = { nofree norecurse nosync nounwind memory(readwrite, inaccessiblemem: none) 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, !8, i64 0}
!6 = !{!"sig_test_BufferPlayer", !7, i64 0, !11, i64 16, !8, i64 24, !12, i64 32}
!7 = !{!"sig_dsp_Signal", !8, i64 0, !8, i64 8}
!8 = !{!"any pointer", !9, i64 0}
!9 = !{!"omnipotent char", !10, i64 0}
!10 = !{!"Simple C/C++ TBAA"}
!11 = !{!"sig_dsp_Signal_SingleMonoOutput", !8, i64 0}
!12 = !{!"long", !9, i64 0}
!13 = !{!14, !12, i64 16}
!14 = !{!"sig_AudioSettings", !15, i64 0, !12, i64 8, !12, i64 16}
!15 = !{!"float", !9, i64 0}
!16 = !{!6, !8, i64 24}
!17 = !{!18, !12, i64 0}
!18 = !{!"sig_Buffer", !12, i64 0, !8, i64 8}
!19 = !{!18, !8, i64 8}
!20 = !{!6, !8, i64 16}
!21 = !{!6, !12, i64 32}
!22 = !{!15, !15, i64 0}
!23 = distinct !{!23, !24}
!24 = !{!"llvm.loop.mustprogress"}


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