; LLVM IR from lichen-community-systems/signaletic :: hosts/daisy/src (signaletic-host)

; 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_host_SwitchIn = type { %struct.sig_dsp_Signal, %struct.sig_host_CV_Parameters, %struct.sig_dsp_Signal_SingleMonoOutput, ptr }
%struct.sig_dsp_Signal = type { ptr, ptr }
%struct.sig_host_CV_Parameters = type { float, float, i32 }
%struct.sig_dsp_Signal_SingleMonoOutput = type { ptr }
%struct.sig_host_HardwareInterface = type { ptr, ptr, ptr, ptr, i64, ptr, i64, ptr, i64, ptr, i64, ptr, i64, ptr, i64, ptr, i64, ptr, i64, ptr, i64, ptr }
%struct.sig_AudioSettings = type { float, i64, i64 }

; 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: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare float @llvm.fmuladd.f32(float, float, float) #1

; Function Attrs: nounwind uwtable
define dso_local void @sig_host_SwitchIn_generate(ptr noundef %0) #2 {
  %2 = alloca ptr, align 8
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca float, align 4
  %6 = alloca float, align 4
  %7 = alloca i32, align 4
  %8 = alloca float, align 4
  %9 = alloca float, align 4
  %10 = alloca i64, align 8
  store ptr %0, ptr %2, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %3) #3
  %11 = load ptr, ptr %2, align 8, !tbaa !5
  store ptr %11, ptr %3, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #3
  %12 = load ptr, ptr %3, align 8, !tbaa !5
  %13 = getelementptr inbounds %struct.sig_host_SwitchIn, ptr %12, i32 0, i32 3
  %14 = load ptr, ptr %13, align 8, !tbaa !9
  store ptr %14, ptr %4, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #3
  %15 = load ptr, ptr %3, align 8, !tbaa !5
  %16 = getelementptr inbounds %struct.sig_host_SwitchIn, ptr %15, i32 0, i32 1
  %17 = getelementptr inbounds %struct.sig_host_CV_Parameters, ptr %16, i32 0, i32 0
  %18 = load float, ptr %17, align 8, !tbaa !16
  store float %18, ptr %5, align 4, !tbaa !17
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #3
  %19 = load ptr, ptr %3, align 8, !tbaa !5
  %20 = getelementptr inbounds %struct.sig_host_SwitchIn, ptr %19, i32 0, i32 1
  %21 = getelementptr inbounds %struct.sig_host_CV_Parameters, ptr %20, i32 0, i32 1
  %22 = load float, ptr %21, align 4, !tbaa !18
  store float %22, ptr %6, align 4, !tbaa !17
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #3
  %23 = load ptr, ptr %3, align 8, !tbaa !5
  %24 = getelementptr inbounds %struct.sig_host_SwitchIn, ptr %23, i32 0, i32 1
  %25 = getelementptr inbounds %struct.sig_host_CV_Parameters, ptr %24, i32 0, i32 2
  %26 = load i32, ptr %25, align 8, !tbaa !19
  store i32 %26, ptr %7, align 4, !tbaa !20
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #3
  %27 = load ptr, ptr %4, align 8, !tbaa !5
  %28 = getelementptr inbounds %struct.sig_host_HardwareInterface, ptr %27, i32 0, i32 17
  %29 = load ptr, ptr %28, align 8, !tbaa !21
  %30 = load i32, ptr %7, align 4, !tbaa !20
  %31 = sext i32 %30 to i64
  %32 = getelementptr inbounds float, ptr %29, i64 %31
  %33 = load float, ptr %32, align 4, !tbaa !17
  store float %33, ptr %8, align 4, !tbaa !17
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #3
  %34 = load float, ptr %8, align 4, !tbaa !17
  %35 = load float, ptr %5, align 4, !tbaa !17
  %36 = load float, ptr %6, align 4, !tbaa !17
  %37 = call float @llvm.fmuladd.f32(float %34, float %35, float %36)
  store float %37, ptr %9, align 4, !tbaa !17
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #3
  store i64 0, ptr %10, align 8, !tbaa !24
  br label %38

38:                                               ; preds = %56, %1
  %39 = load i64, ptr %10, align 8, !tbaa !24
  %40 = load ptr, ptr %3, align 8, !tbaa !5
  %41 = getelementptr inbounds %struct.sig_host_SwitchIn, ptr %40, i32 0, i32 0
  %42 = getelementptr inbounds %struct.sig_dsp_Signal, ptr %41, i32 0, i32 0
  %43 = load ptr, ptr %42, align 8, !tbaa !25
  %44 = getelementptr inbounds %struct.sig_AudioSettings, ptr %43, i32 0, i32 2
  %45 = load i64, ptr %44, align 8, !tbaa !26
  %46 = icmp ult i64 %39, %45
  br i1 %46, label %48, label %47

47:                                               ; preds = %38
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #3
  br label %59

48:                                               ; preds = %38
  %49 = load float, ptr %9, align 4, !tbaa !17
  %50 = load ptr, ptr %3, align 8, !tbaa !5
  %51 = getelementptr inbounds %struct.sig_host_SwitchIn, ptr %50, i32 0, i32 2
  %52 = getelementptr inbounds %struct.sig_dsp_Signal_SingleMonoOutput, ptr %51, i32 0, i32 0
  %53 = load ptr, ptr %52, align 8, !tbaa !28
  %54 = load i64, ptr %10, align 8, !tbaa !24
  %55 = getelementptr inbounds float, ptr %53, i64 %54
  store float %49, ptr %55, align 4, !tbaa !17
  br label %56

56:                                               ; preds = %48
  %57 = load i64, ptr %10, align 8, !tbaa !24
  %58 = add i64 %57, 1
  store i64 %58, ptr %10, align 8, !tbaa !24
  br label %38, !llvm.loop !29

59:                                               ; preds = %47
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #3
  ret void
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
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, !6, i64 40}
!10 = !{!"sig_host_SwitchIn", !11, i64 0, !12, i64 16, !15, i64 32, !6, i64 40}
!11 = !{!"sig_dsp_Signal", !6, i64 0, !6, i64 8}
!12 = !{!"sig_host_CV_Parameters", !13, i64 0, !13, i64 4, !14, i64 8}
!13 = !{!"float", !7, i64 0}
!14 = !{!"int", !7, i64 0}
!15 = !{!"sig_dsp_Signal_SingleMonoOutput", !6, i64 0}
!16 = !{!10, !13, i64 16}
!17 = !{!13, !13, i64 0}
!18 = !{!10, !13, i64 20}
!19 = !{!10, !14, i64 24}
!20 = !{!14, !14, i64 0}
!21 = !{!22, !6, i64 136}
!22 = !{!"sig_host_HardwareInterface", !6, i64 0, !6, i64 8, !6, i64 16, !6, i64 24, !23, i64 32, !6, i64 40, !23, i64 48, !6, i64 56, !23, i64 64, !6, i64 72, !23, i64 80, !6, i64 88, !23, i64 96, !6, i64 104, !23, i64 112, !6, i64 120, !23, i64 128, !6, i64 136, !23, i64 144, !6, i64 152, !23, i64 160, !6, i64 168}
!23 = !{!"long", !7, i64 0}
!24 = !{!23, !23, i64 0}
!25 = !{!10, !6, i64 0}
!26 = !{!27, !23, i64 16}
!27 = !{!"sig_AudioSettings", !13, i64 0, !23, i64 8, !23, i64 16}
!28 = !{!10, !6, i64 32}
!29 = distinct !{!29, !30}
!30 = !{!"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: mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare float @llvm.fmuladd.f32(float, float, float) #0

; Function Attrs: nofree norecurse nosync nounwind memory(readwrite, inaccessiblemem: none) uwtable
define dso_local void @sig_host_SwitchIn_generate(ptr nocapture noundef readonly %0) local_unnamed_addr #1 {
  %2 = getelementptr inbounds i8, ptr %0, i64 40
  %3 = load ptr, ptr %2, align 8, !tbaa !5
  %4 = getelementptr inbounds i8, ptr %0, i64 16
  %5 = load float, ptr %4, align 8, !tbaa !15
  %6 = getelementptr inbounds i8, ptr %0, i64 20
  %7 = load float, ptr %6, align 4, !tbaa !16
  %8 = getelementptr inbounds i8, ptr %0, i64 24
  %9 = load i32, ptr %8, align 8, !tbaa !17
  %10 = getelementptr inbounds i8, ptr %3, i64 136
  %11 = load ptr, ptr %10, align 8, !tbaa !18
  %12 = sext i32 %9 to i64
  %13 = getelementptr inbounds float, ptr %11, i64 %12
  %14 = load float, ptr %13, align 4, !tbaa !21
  %15 = tail call float @llvm.fmuladd.f32(float %14, float %5, float %7)
  %16 = load ptr, ptr %0, align 8, !tbaa !22
  %17 = getelementptr inbounds i8, ptr %16, i64 16
  %18 = load i64, ptr %17, align 8, !tbaa !23
  %.not = icmp eq i64 %18, 0
  br i1 %.not, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %1
  %19 = getelementptr inbounds i8, ptr %0, i64 32
  %20 = load ptr, ptr %19, align 8, !tbaa !25
  %min.iters.check = icmp ult i64 %18, 8
  br i1 %min.iters.check, label %scalar.ph.preheader, label %vector.ph

scalar.ph.preheader:                              ; preds = %middle.block, %.lr.ph
  %.015.ph = phi i64 [ 0, %.lr.ph ], [ %n.vec, %middle.block ]
  br label %scalar.ph

vector.ph:                                        ; preds = %.lr.ph
  %n.vec = and i64 %18, -8
  %broadcast.splatinsert = insertelement <4 x float> poison, float %15, i64 0
  %broadcast.splat = shufflevector <4 x float> %broadcast.splatinsert, <4 x float> poison, <4 x i32> zeroinitializer
  br label %vector.body

vector.body:                                      ; preds = %vector.body, %vector.ph
  %index = phi i64 [ 0, %vector.ph ], [ %index.next, %vector.body ]
  %21 = getelementptr inbounds float, ptr %20, i64 %index
  %22 = getelementptr inbounds i8, ptr %21, i64 16
  store <4 x float> %broadcast.splat, ptr %21, align 4, !tbaa !21
  store <4 x float> %broadcast.splat, ptr %22, align 4, !tbaa !21
  %index.next = add nuw i64 %index, 8
  %23 = icmp eq i64 %index.next, %n.vec
  br i1 %23, label %middle.block, label %vector.body, !llvm.loop !26

middle.block:                                     ; preds = %vector.body
  %cmp.n = icmp eq i64 %18, %n.vec
  br i1 %cmp.n, label %._crit_edge, label %scalar.ph.preheader

._crit_edge:                                      ; preds = %scalar.ph, %middle.block, %1
  ret void

scalar.ph:                                        ; preds = %scalar.ph.preheader, %scalar.ph
  %.015 = phi i64 [ %25, %scalar.ph ], [ %.015.ph, %scalar.ph.preheader ]
  %24 = getelementptr inbounds float, ptr %20, i64 %.015
  store float %15, ptr %24, align 4, !tbaa !21
  %25 = add nuw i64 %.015, 1
  %exitcond.not = icmp eq i64 %25, %18
  br i1 %exitcond.not, label %._crit_edge, label %scalar.ph, !llvm.loop !30
}

attributes #0 = { mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #1 = { 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 40}
!6 = !{!"sig_host_SwitchIn", !7, i64 0, !11, i64 16, !14, i64 32, !8, i64 40}
!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_host_CV_Parameters", !12, i64 0, !12, i64 4, !13, i64 8}
!12 = !{!"float", !9, i64 0}
!13 = !{!"int", !9, i64 0}
!14 = !{!"sig_dsp_Signal_SingleMonoOutput", !8, i64 0}
!15 = !{!6, !12, i64 16}
!16 = !{!6, !12, i64 20}
!17 = !{!6, !13, i64 24}
!18 = !{!19, !8, i64 136}
!19 = !{!"sig_host_HardwareInterface", !8, i64 0, !8, i64 8, !8, i64 16, !8, i64 24, !20, i64 32, !8, i64 40, !20, i64 48, !8, i64 56, !20, i64 64, !8, i64 72, !20, i64 80, !8, i64 88, !20, i64 96, !8, i64 104, !20, i64 112, !8, i64 120, !20, i64 128, !8, i64 136, !20, i64 144, !8, i64 152, !20, i64 160, !8, i64 168}
!20 = !{!"long", !9, i64 0}
!21 = !{!12, !12, i64 0}
!22 = !{!6, !8, i64 0}
!23 = !{!24, !20, i64 16}
!24 = !{!"sig_AudioSettings", !12, i64 0, !20, i64 8, !20, i64 16}
!25 = !{!6, !8, i64 32}
!26 = distinct !{!26, !27, !28, !29}
!27 = !{!"llvm.loop.mustprogress"}
!28 = !{!"llvm.loop.isvectorized", i32 1}
!29 = !{!"llvm.loop.unroll.runtime.disable"}
!30 = distinct !{!30, !27, !29, !28}


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