; LLVM IR from lichen-community-systems/signaletic :: libsignaletic/src (libsignaletic)

; 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_dsp_ToggleGate = type { %struct.sig_dsp_Signal, %struct.sig_dsp_ToggleGate_Inputs, %struct.sig_dsp_Signal_SingleMonoOutput, i8, float }
%struct.sig_dsp_Signal = type { ptr, ptr }
%struct.sig_dsp_ToggleGate_Inputs = type { ptr }
%struct.sig_dsp_Signal_SingleMonoOutput = type { 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: nounwind uwtable
define dso_local void @sig_dsp_ToggleGate_generate(ptr noundef %0) #1 {
  %2 = alloca ptr, align 8
  %3 = alloca ptr, align 8
  %4 = alloca i64, align 8
  %5 = alloca float, align 4
  store ptr %0, ptr %2, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %3) #2
  %6 = load ptr, ptr %2, align 8, !tbaa !5
  store ptr %6, 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 %7

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

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

17:                                               ; preds = %7
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #2
  %18 = load ptr, ptr %3, align 8, !tbaa !5
  %19 = getelementptr inbounds %struct.sig_dsp_ToggleGate, ptr %18, i32 0, i32 1
  %20 = getelementptr inbounds %struct.sig_dsp_ToggleGate_Inputs, ptr %19, i32 0, i32 0
  %21 = load ptr, ptr %20, align 8, !tbaa !20
  %22 = load i64, ptr %4, align 8, !tbaa !9
  %23 = getelementptr inbounds float, ptr %21, i64 %22
  %24 = load float, ptr %23, align 4, !tbaa !21
  store float %24, ptr %5, align 4, !tbaa !21
  %25 = load float, ptr %5, align 4, !tbaa !21
  %26 = fcmp ogt float %25, 0.000000e+00
  br i1 %26, label %27, label %41

27:                                               ; preds = %17
  %28 = load ptr, ptr %3, align 8, !tbaa !5
  %29 = getelementptr inbounds %struct.sig_dsp_ToggleGate, ptr %28, i32 0, i32 4
  %30 = load float, ptr %29, align 4, !tbaa !22
  %31 = fcmp ole float %30, 0.000000e+00
  br i1 %31, label %32, label %41

32:                                               ; preds = %27
  %33 = load ptr, ptr %3, align 8, !tbaa !5
  %34 = getelementptr inbounds %struct.sig_dsp_ToggleGate, ptr %33, i32 0, i32 3
  %35 = load i8, ptr %34, align 8, !tbaa !23, !range !24, !noundef !25
  %36 = trunc i8 %35 to i1
  %37 = xor i1 %36, true
  %38 = load ptr, ptr %3, align 8, !tbaa !5
  %39 = getelementptr inbounds %struct.sig_dsp_ToggleGate, ptr %38, i32 0, i32 3
  %40 = zext i1 %37 to i8
  store i8 %40, ptr %39, align 8, !tbaa !23
  br label %41

41:                                               ; preds = %32, %27, %17
  %42 = load ptr, ptr %3, align 8, !tbaa !5
  %43 = getelementptr inbounds %struct.sig_dsp_ToggleGate, ptr %42, i32 0, i32 3
  %44 = load i8, ptr %43, align 8, !tbaa !23, !range !24, !noundef !25
  %45 = trunc i8 %44 to i1
  %46 = uitofp i1 %45 to float
  %47 = load ptr, ptr %3, align 8, !tbaa !5
  %48 = getelementptr inbounds %struct.sig_dsp_ToggleGate, ptr %47, i32 0, i32 2
  %49 = getelementptr inbounds %struct.sig_dsp_Signal_SingleMonoOutput, ptr %48, i32 0, i32 0
  %50 = load ptr, ptr %49, align 8, !tbaa !26
  %51 = load i64, ptr %4, align 8, !tbaa !9
  %52 = getelementptr inbounds float, ptr %50, i64 %51
  store float %46, ptr %52, align 4, !tbaa !21
  %53 = load float, ptr %5, align 4, !tbaa !21
  %54 = load ptr, ptr %3, align 8, !tbaa !5
  %55 = getelementptr inbounds %struct.sig_dsp_ToggleGate, ptr %54, i32 0, i32 4
  store float %53, ptr %55, align 4, !tbaa !22
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #2
  br label %56

56:                                               ; preds = %41
  %57 = load i64, ptr %4, align 8, !tbaa !9
  %58 = add i64 %57, 1
  store i64 %58, ptr %4, align 8, !tbaa !9
  br label %7, !llvm.loop !27

59:                                               ; preds = %16
  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_dsp_ToggleGate", !13, i64 0, !14, i64 16, !15, i64 24, !16, i64 32, !17, i64 36}
!13 = !{!"sig_dsp_Signal", !6, i64 0, !6, i64 8}
!14 = !{!"sig_dsp_ToggleGate_Inputs", !6, i64 0}
!15 = !{!"sig_dsp_Signal_SingleMonoOutput", !6, i64 0}
!16 = !{!"_Bool", !7, i64 0}
!17 = !{!"float", !7, i64 0}
!18 = !{!19, !10, i64 16}
!19 = !{!"sig_AudioSettings", !17, i64 0, !10, i64 8, !10, i64 16}
!20 = !{!12, !6, i64 16}
!21 = !{!17, !17, i64 0}
!22 = !{!12, !17, i64 36}
!23 = !{!12, !16, i64 32}
!24 = !{i8 0, i8 2}
!25 = !{}
!26 = !{!12, !6, i64 24}
!27 = distinct !{!27, !28}
!28 = !{!"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_dsp_ToggleGate_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 !15
  %.not = icmp eq i64 %4, 0
  br i1 %.not, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %1
  %5 = getelementptr inbounds i8, ptr %0, i64 16
  %6 = load ptr, ptr %5, align 8, !tbaa !18
  %7 = getelementptr inbounds i8, ptr %0, i64 36
  %8 = getelementptr inbounds i8, ptr %0, i64 32
  %9 = getelementptr inbounds i8, ptr %0, i64 24
  %10 = load ptr, ptr %9, align 8, !tbaa !19
  %.promoted = load i8, ptr %8, align 8, !tbaa !20
  br label %11

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

11:                                               ; preds = %.lr.ph, %21
  %12 = phi i8 [ %.promoted, %.lr.ph ], [ %22, %21 ]
  %.014 = phi i64 [ 0, %.lr.ph ], [ %26, %21 ]
  %13 = getelementptr inbounds float, ptr %6, i64 %.014
  %14 = load float, ptr %13, align 4, !tbaa !21
  %15 = fcmp ogt float %14, 0.000000e+00
  br i1 %15, label %16, label %21

16:                                               ; preds = %11
  %17 = load float, ptr %7, align 4, !tbaa !22
  %18 = fcmp ugt float %17, 0.000000e+00
  br i1 %18, label %21, label %19

19:                                               ; preds = %16
  %20 = xor i8 %12, 1
  store i8 %20, ptr %8, align 8, !tbaa !20
  br label %21

21:                                               ; preds = %19, %16, %11
  %22 = phi i8 [ %20, %19 ], [ %12, %16 ], [ %12, %11 ]
  %23 = trunc nuw i8 %22 to i1
  %24 = uitofp i1 %23 to float
  %25 = getelementptr inbounds float, ptr %10, i64 %.014
  store float %24, ptr %25, align 4, !tbaa !21
  store float %14, ptr %7, align 4, !tbaa !22
  %26 = add nuw i64 %.014, 1
  %exitcond.not = icmp eq i64 %26, %4
  br i1 %exitcond.not, label %._crit_edge, label %11, !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_dsp_ToggleGate", !7, i64 0, !11, i64 16, !12, i64 24, !13, i64 32, !14, i64 36}
!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_ToggleGate_Inputs", !8, i64 0}
!12 = !{!"sig_dsp_Signal_SingleMonoOutput", !8, i64 0}
!13 = !{!"_Bool", !9, i64 0}
!14 = !{!"float", !9, i64 0}
!15 = !{!16, !17, i64 16}
!16 = !{!"sig_AudioSettings", !14, i64 0, !17, i64 8, !17, i64 16}
!17 = !{!"long", !9, i64 0}
!18 = !{!6, !8, i64 16}
!19 = !{!6, !8, i64 24}
!20 = !{!6, !13, i64 32}
!21 = !{!14, !14, i64 0}
!22 = !{!6, !14, i64 36}
!23 = distinct !{!23, !24}
!24 = !{!"llvm.loop.mustprogress"}


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