; LLVM IR from lichen-community-systems/signaletic :: hosts/daisy/vendor/libDaisy/src/hid (audio)

; 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.daisy::AudioHandle::Config" = type <{ i64, i32, float, float, [4 x i8] }>
%"class.daisy::SaiHandle" = type { ptr }
%"class.daisy::AudioHandle::Impl" = type { ptr, ptr, %"struct.daisy::AudioHandle::Config", %"class.daisy::SaiHandle", %"class.daisy::SaiHandle", [2 x ptr], [2 x ptr], float, float }
%"struct.daisy::SaiHandle::Config" = type { i32, %struct.anon, i32, i32, i32, i32, i32, i32 }
%struct.anon = type { %struct.dsy_gpio_pin, %struct.dsy_gpio_pin, %struct.dsy_gpio_pin, %struct.dsy_gpio_pin, %struct.dsy_gpio_pin }
%struct.dsy_gpio_pin = type { i32, i8 }

@_ZN5daisyL19dsy_audio_rx_bufferE = external hidden global [2 x [1024 x i32]], section ".sram1_bss", align 16
@_ZN5daisyL19dsy_audio_tx_bufferE = external hidden global [2 x [1024 x i32]], section ".sram1_bss", align 16

; Function Attrs: mustprogress uwtable
define dso_local noundef i32 @_ZN5daisy11AudioHandle4Impl4InitENS0_6ConfigENS_9SaiHandleE(ptr noundef nonnull align 8 dereferenceable(96) %0, ptr noundef byval(%"struct.daisy::AudioHandle::Config") align 8 %1, ptr %2) #0 align 2 {
  %4 = alloca i32, align 4
  %5 = alloca %"class.daisy::SaiHandle", align 8
  %6 = alloca ptr, align 8
  %7 = getelementptr inbounds %"class.daisy::SaiHandle", ptr %5, i32 0, i32 0
  store ptr %2, ptr %7, align 8
  store ptr %0, ptr %6, align 8, !tbaa !5
  %8 = load ptr, ptr %6, align 8
  %9 = getelementptr inbounds %"class.daisy::AudioHandle::Impl", ptr %8, i32 0, i32 2
  call void @llvm.memcpy.p0.p0.i64(ptr align 8 %9, ptr align 8 %1, i64 20, i1 false), !tbaa.struct !9
  %10 = getelementptr inbounds %"class.daisy::AudioHandle::Impl", ptr %8, i32 0, i32 2
  %11 = getelementptr inbounds %"struct.daisy::AudioHandle::Config", ptr %10, i32 0, i32 2
  %12 = load float, ptr %11, align 4, !tbaa !16
  %13 = fcmp ogt float %12, 0.000000e+00
  br i1 %13, label %14, label %20

14:                                               ; preds = %3
  %15 = getelementptr inbounds %"class.daisy::AudioHandle::Impl", ptr %8, i32 0, i32 2
  %16 = getelementptr inbounds %"struct.daisy::AudioHandle::Config", ptr %15, i32 0, i32 2
  %17 = load float, ptr %16, align 4, !tbaa !16
  %18 = fdiv float 1.000000e+00, %17
  %19 = getelementptr inbounds %"class.daisy::AudioHandle::Impl", ptr %8, i32 0, i32 7
  store float %18, ptr %19, align 8, !tbaa !20
  br label %21

20:                                               ; preds = %3
  store i32 1, ptr %4, align 4
  br label %45

21:                                               ; preds = %14
  %22 = getelementptr inbounds %"class.daisy::AudioHandle::Impl", ptr %8, i32 0, i32 2
  %23 = getelementptr inbounds %"struct.daisy::AudioHandle::Config", ptr %22, i32 0, i32 2
  %24 = load float, ptr %23, align 4, !tbaa !16
  %25 = getelementptr inbounds %"class.daisy::AudioHandle::Impl", ptr %8, i32 0, i32 2
  %26 = getelementptr inbounds %"struct.daisy::AudioHandle::Config", ptr %25, i32 0, i32 3
  %27 = load float, ptr %26, align 8, !tbaa !21
  %28 = fmul float %24, %27
  %29 = getelementptr inbounds %"class.daisy::AudioHandle::Impl", ptr %8, i32 0, i32 8
  store float %28, ptr %29, align 4, !tbaa !22
  %30 = call noundef zeroext i1 @_ZNK5daisy9SaiHandle13IsInitializedEv(ptr noundef nonnull align 8 dereferenceable(8) %5)
  br i1 %30, label %31, label %39

31:                                               ; preds = %21
  %32 = getelementptr inbounds %"class.daisy::AudioHandle::Impl", ptr %8, i32 0, i32 3
  call void @llvm.memcpy.p0.p0.i64(ptr align 8 %32, ptr align 8 %5, i64 8, i1 false), !tbaa.struct !23
  %33 = getelementptr inbounds %"class.daisy::AudioHandle::Impl", ptr %8, i32 0, i32 3
  %34 = call noundef nonnull align 4 dereferenceable(68) ptr @_ZNK5daisy9SaiHandle9GetConfigEv(ptr noundef nonnull align 8 dereferenceable(8) %33)
  %35 = getelementptr inbounds %"struct.daisy::SaiHandle::Config", ptr %34, i32 0, i32 2
  %36 = load i32, ptr %35, align 4, !tbaa !24
  %37 = getelementptr inbounds %"class.daisy::AudioHandle::Impl", ptr %8, i32 0, i32 2
  %38 = getelementptr inbounds %"struct.daisy::AudioHandle::Config", ptr %37, i32 0, i32 1
  store i32 %36, ptr %38, align 8, !tbaa !33
  br label %40

39:                                               ; preds = %21
  store i32 1, ptr %4, align 4
  br label %45

40:                                               ; preds = %31
  %41 = getelementptr inbounds %"class.daisy::AudioHandle::Impl", ptr %8, i32 0, i32 5
  %42 = getelementptr inbounds [2 x ptr], ptr %41, i64 0, i64 0
  store ptr @_ZN5daisyL19dsy_audio_rx_bufferE, ptr %42, align 8, !tbaa !5
  %43 = getelementptr inbounds %"class.daisy::AudioHandle::Impl", ptr %8, i32 0, i32 6
  %44 = getelementptr inbounds [2 x ptr], ptr %43, i64 0, i64 0
  store ptr @_ZN5daisyL19dsy_audio_tx_bufferE, ptr %44, align 8, !tbaa !5
  store i32 0, ptr %4, align 4
  br label %45

45:                                               ; preds = %40, %39, %20
  %46 = load i32, ptr %4, align 4
  ret i32 %46
}

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #1

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef zeroext i1 @_ZNK5daisy9SaiHandle13IsInitializedEv(ptr noundef nonnull align 8 dereferenceable(8)) #2 align 2

declare noundef nonnull align 4 dereferenceable(68) ptr @_ZNK5daisy9SaiHandle9GetConfigEv(ptr noundef nonnull align 8 dereferenceable(8)) #3

attributes #0 = { mustprogress 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 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { inlinehint mustprogress 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 = { "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 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{i64 0, i64 8, !10, i64 8, i64 4, !12, i64 12, i64 4, !14, i64 16, i64 4, !14}
!10 = !{!11, !11, i64 0}
!11 = !{!"long", !7, i64 0}
!12 = !{!13, !13, i64 0}
!13 = !{!"_ZTSN5daisy9SaiHandle6Config10SampleRateE", !7, i64 0}
!14 = !{!15, !15, i64 0}
!15 = !{!"float", !7, i64 0}
!16 = !{!17, !15, i64 28}
!17 = !{!"_ZTSN5daisy11AudioHandle4ImplE", !6, i64 0, !6, i64 8, !18, i64 16, !19, i64 40, !19, i64 48, !7, i64 56, !7, i64 72, !15, i64 88, !15, i64 92}
!18 = !{!"_ZTSN5daisy11AudioHandle6ConfigE", !11, i64 0, !13, i64 8, !15, i64 12, !15, i64 16}
!19 = !{!"_ZTSN5daisy9SaiHandleE", !6, i64 0}
!20 = !{!17, !15, i64 88}
!21 = !{!17, !15, i64 32}
!22 = !{!17, !15, i64 92}
!23 = !{i64 0, i64 8, !5}
!24 = !{!25, !13, i64 44}
!25 = !{!"_ZTSN5daisy9SaiHandle6ConfigE", !26, i64 0, !27, i64 4, !13, i64 44, !30, i64 48, !31, i64 52, !31, i64 56, !32, i64 60, !32, i64 64}
!26 = !{!"_ZTSN5daisy9SaiHandle6Config10PeripheralE", !7, i64 0}
!27 = !{!"_ZTSN5daisy9SaiHandle6ConfigUt_E", !28, i64 0, !28, i64 8, !28, i64 16, !28, i64 24, !28, i64 32}
!28 = !{!"_ZTS12dsy_gpio_pin", !29, i64 0, !7, i64 4}
!29 = !{!"_ZTS13dsy_gpio_port", !7, i64 0}
!30 = !{!"_ZTSN5daisy9SaiHandle6Config8BitDepthE", !7, i64 0}
!31 = !{!"_ZTSN5daisy9SaiHandle6Config4SyncE", !7, i64 0}
!32 = !{!"_ZTSN5daisy9SaiHandle6Config9DirectionE", !7, i64 0}
!33 = !{!17, !13, i64 24}


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

%"struct.daisy::AudioHandle::Config" = type <{ i64, i32, float, float, [4 x i8] }>
%"class.daisy::SaiHandle" = type { ptr }

@_ZN5daisyL19dsy_audio_rx_bufferE = external hidden global [2 x [1024 x i32]], section ".sram1_bss", align 16
@_ZN5daisyL19dsy_audio_tx_bufferE = external hidden global [2 x [1024 x i32]], section ".sram1_bss", align 16

; Function Attrs: mustprogress uwtable
define dso_local noundef range(i32 0, 2) i32 @_ZN5daisy11AudioHandle4Impl4InitENS0_6ConfigENS_9SaiHandleE(ptr noundef nonnull align 8 dereferenceable(96) %0, ptr nocapture noundef readonly byval(%"struct.daisy::AudioHandle::Config") align 8 %1, ptr %2) local_unnamed_addr #0 align 2 {
  %4 = alloca %"class.daisy::SaiHandle", align 8
  store ptr %2, ptr %4, align 8
  %5 = getelementptr inbounds i8, ptr %0, i64 16
  call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 8 dereferenceable(20) %5, ptr noundef nonnull align 8 dereferenceable(20) %1, i64 20, i1 false), !tbaa.struct !5
  %6 = getelementptr inbounds i8, ptr %0, i64 28
  %7 = load float, ptr %6, align 4, !tbaa !14
  %8 = fcmp ogt float %7, 0.000000e+00
  br i1 %8, label %9, label %26

9:                                                ; preds = %3
  %10 = fdiv float 1.000000e+00, %7
  %11 = getelementptr inbounds i8, ptr %0, i64 88
  store float %10, ptr %11, align 8, !tbaa !19
  %12 = getelementptr inbounds i8, ptr %0, i64 32
  %13 = load float, ptr %12, align 8, !tbaa !20
  %14 = fmul float %7, %13
  %15 = getelementptr inbounds i8, ptr %0, i64 92
  store float %14, ptr %15, align 4, !tbaa !21
  %16 = call noundef zeroext i1 @_ZNK5daisy9SaiHandle13IsInitializedEv(ptr noundef nonnull align 8 dereferenceable(8) %4)
  br i1 %16, label %17, label %26

17:                                               ; preds = %9
  %18 = getelementptr inbounds i8, ptr %0, i64 40
  %19 = load i64, ptr %4, align 8, !tbaa !22
  store i64 %19, ptr %18, align 8, !tbaa !22
  %20 = call noundef nonnull align 4 dereferenceable(68) ptr @_ZNK5daisy9SaiHandle9GetConfigEv(ptr noundef nonnull align 8 dereferenceable(8) %18)
  %21 = getelementptr inbounds i8, ptr %20, i64 44
  %22 = load i32, ptr %21, align 4, !tbaa !23
  %23 = getelementptr inbounds i8, ptr %0, i64 24
  store i32 %22, ptr %23, align 8, !tbaa !32
  %24 = getelementptr inbounds i8, ptr %0, i64 56
  store ptr @_ZN5daisyL19dsy_audio_rx_bufferE, ptr %24, align 8, !tbaa !22
  %25 = getelementptr inbounds i8, ptr %0, i64 72
  store ptr @_ZN5daisyL19dsy_audio_tx_bufferE, ptr %25, align 8, !tbaa !22
  br label %26

26:                                               ; preds = %9, %3, %17
  %.0 = phi i32 [ 0, %17 ], [ 1, %3 ], [ 1, %9 ]
  ret i32 %.0
}

; Function Attrs: mustprogress nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #1

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef zeroext i1 @_ZNK5daisy9SaiHandle13IsInitializedEv(ptr noundef nonnull align 8 dereferenceable(8)) local_unnamed_addr #2 align 2

declare noundef nonnull align 4 dereferenceable(68) ptr @_ZNK5daisy9SaiHandle9GetConfigEv(ptr noundef nonnull align 8 dereferenceable(8)) local_unnamed_addr #3

attributes #0 = { mustprogress 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 nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { inlinehint mustprogress 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 = { "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 = !{i64 0, i64 8, !6, i64 8, i64 4, !10, i64 12, i64 4, !12, i64 16, i64 4, !12}
!6 = !{!7, !7, i64 0}
!7 = !{!"long", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}
!10 = !{!11, !11, i64 0}
!11 = !{!"_ZTSN5daisy9SaiHandle6Config10SampleRateE", !8, i64 0}
!12 = !{!13, !13, i64 0}
!13 = !{!"float", !8, i64 0}
!14 = !{!15, !13, i64 28}
!15 = !{!"_ZTSN5daisy11AudioHandle4ImplE", !16, i64 0, !16, i64 8, !17, i64 16, !18, i64 40, !18, i64 48, !8, i64 56, !8, i64 72, !13, i64 88, !13, i64 92}
!16 = !{!"any pointer", !8, i64 0}
!17 = !{!"_ZTSN5daisy11AudioHandle6ConfigE", !7, i64 0, !11, i64 8, !13, i64 12, !13, i64 16}
!18 = !{!"_ZTSN5daisy9SaiHandleE", !16, i64 0}
!19 = !{!15, !13, i64 88}
!20 = !{!15, !13, i64 32}
!21 = !{!15, !13, i64 92}
!22 = !{!16, !16, i64 0}
!23 = !{!24, !11, i64 44}
!24 = !{!"_ZTSN5daisy9SaiHandle6ConfigE", !25, i64 0, !26, i64 4, !11, i64 44, !29, i64 48, !30, i64 52, !30, i64 56, !31, i64 60, !31, i64 64}
!25 = !{!"_ZTSN5daisy9SaiHandle6Config10PeripheralE", !8, i64 0}
!26 = !{!"_ZTSN5daisy9SaiHandle6ConfigUt_E", !27, i64 0, !27, i64 8, !27, i64 16, !27, i64 24, !27, i64 32}
!27 = !{!"_ZTS12dsy_gpio_pin", !28, i64 0, !8, i64 4}
!28 = !{!"_ZTS13dsy_gpio_port", !8, i64 0}
!29 = !{!"_ZTSN5daisy9SaiHandle6Config8BitDepthE", !8, i64 0}
!30 = !{!"_ZTSN5daisy9SaiHandle6Config4SyncE", !8, i64 0}
!31 = !{!"_ZTSN5daisy9SaiHandle6Config9DirectionE", !8, i64 0}
!32 = !{!15, !11, i64 24}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass