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

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

%"class.daisy::MultiSlaveSpiHandle" = type { %"struct.daisy::MultiSlaveSpiHandle::Config", %"class.daisy::SpiHandle", [4 x %struct.dsy_gpio], %"struct.daisy::MultiSlaveSpiHandle::DmaTransfer" }
%"struct.daisy::MultiSlaveSpiHandle::Config" = type { %struct.anon, i32, i32, i64, i32, i32, i32, i64 }
%struct.anon = type { %struct.dsy_gpio_pin, %struct.dsy_gpio_pin, %struct.dsy_gpio_pin, [4 x %struct.dsy_gpio_pin] }
%struct.dsy_gpio_pin = type { i32, i8 }
%"class.daisy::SpiHandle" = type { ptr }
%struct.dsy_gpio = type { %struct.dsy_gpio_pin, i32, i32 }
%"struct.daisy::MultiSlaveSpiHandle::DmaTransfer" = type { i8, ptr, ptr, ptr }

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #0

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN5daisy19MultiSlaveSpiHandle13DisableDeviceEm(ptr noundef nonnull align 8 dereferenceable(200), i64 noundef) #1 align 2

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #0

; Function Attrs: mustprogress uwtable
define dso_local noundef i32 @_ZN5daisy19MultiSlaveSpiHandle16BlockingTransmitEmPhmj(ptr noundef nonnull align 8 dereferenceable(200) %0, i64 noundef %1, ptr noundef %2, i64 noundef %3, i32 noundef %4) #1 align 2 {
  %6 = alloca i32, align 4
  %7 = alloca ptr, align 8
  %8 = alloca i64, align 8
  %9 = alloca ptr, align 8
  %10 = alloca i64, align 8
  %11 = alloca i32, align 4
  %12 = alloca i32, align 4
  store ptr %0, ptr %7, align 8, !tbaa !5
  store i64 %1, ptr %8, align 8, !tbaa !9
  store ptr %2, ptr %9, align 8, !tbaa !5
  store i64 %3, ptr %10, align 8, !tbaa !9
  store i32 %4, ptr %11, align 4, !tbaa !11
  %13 = load ptr, ptr %7, align 8
  %14 = load i64, ptr %8, align 8, !tbaa !9
  %15 = getelementptr inbounds %"class.daisy::MultiSlaveSpiHandle", ptr %13, i32 0, i32 0
  %16 = getelementptr inbounds %"struct.daisy::MultiSlaveSpiHandle::Config", ptr %15, i32 0, i32 7
  %17 = load i64, ptr %16, align 8, !tbaa !13
  %18 = icmp uge i64 %14, %17
  br i1 %18, label %19, label %20

19:                                               ; preds = %5
  store i32 1, ptr %6, align 4
  br label %34

20:                                               ; preds = %5
  br label %21

21:                                               ; preds = %24, %20
  %22 = getelementptr inbounds %"class.daisy::MultiSlaveSpiHandle", ptr %13, i32 0, i32 3
  %23 = call noundef zeroext i1 @_ZNK5daisy19MultiSlaveSpiHandle11DmaTransfer7IsValidEv(ptr noundef nonnull align 8 dereferenceable(32) %22)
  br i1 %23, label %24, label %25

24:                                               ; preds = %21
  br label %21, !llvm.loop !26

25:                                               ; preds = %21
  %26 = load i64, ptr %8, align 8, !tbaa !9
  call void @_ZN5daisy19MultiSlaveSpiHandle12EnableDeviceEm(ptr noundef nonnull align 8 dereferenceable(200) %13, i64 noundef %26)
  call void @llvm.lifetime.start.p0(i64 4, ptr %12) #4
  %27 = getelementptr inbounds %"class.daisy::MultiSlaveSpiHandle", ptr %13, i32 0, i32 1
  %28 = load ptr, ptr %9, align 8, !tbaa !5
  %29 = load i64, ptr %10, align 8, !tbaa !9
  %30 = load i32, ptr %11, align 4, !tbaa !11
  %31 = call noundef i32 @_ZN5daisy9SpiHandle16BlockingTransmitEPhmj(ptr noundef nonnull align 8 dereferenceable(8) %27, ptr noundef %28, i64 noundef %29, i32 noundef %30)
  store i32 %31, ptr %12, align 4, !tbaa !28
  %32 = load i64, ptr %8, align 8, !tbaa !9
  call void @_ZN5daisy19MultiSlaveSpiHandle13DisableDeviceEm(ptr noundef nonnull align 8 dereferenceable(200) %13, i64 noundef %32)
  %33 = load i32, ptr %12, align 4, !tbaa !28
  store i32 %33, ptr %6, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %12) #4
  br label %34

34:                                               ; preds = %25, %19
  %35 = load i32, ptr %6, align 4
  ret i32 %35
}

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

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN5daisy19MultiSlaveSpiHandle12EnableDeviceEm(ptr noundef nonnull align 8 dereferenceable(200), i64 noundef) #1 align 2

declare noundef i32 @_ZN5daisy9SpiHandle16BlockingTransmitEPhmj(ptr noundef nonnull align 8 dereferenceable(8), ptr noundef, i64 noundef, i32 noundef) #3

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 #2 = { 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" }
attributes #4 = { 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++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"long", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"int", !7, i64 0}
!13 = !{!14, !10, i64 88}
!14 = !{!"_ZTSN5daisy19MultiSlaveSpiHandleE", !15, i64 0, !24, i64 96, !7, i64 104, !25, i64 168}
!15 = !{!"_ZTSN5daisy19MultiSlaveSpiHandle6ConfigE", !16, i64 0, !19, i64 56, !20, i64 60, !10, i64 64, !21, i64 72, !22, i64 76, !23, i64 80, !10, i64 88}
!16 = !{!"_ZTSN5daisy19MultiSlaveSpiHandle6ConfigUt_E", !17, i64 0, !17, i64 8, !17, i64 16, !7, i64 24}
!17 = !{!"_ZTS12dsy_gpio_pin", !18, i64 0, !7, i64 4}
!18 = !{!"_ZTS13dsy_gpio_port", !7, i64 0}
!19 = !{!"_ZTSN5daisy9SpiHandle6Config10PeripheralE", !7, i64 0}
!20 = !{!"_ZTSN5daisy9SpiHandle6Config9DirectionE", !7, i64 0}
!21 = !{!"_ZTSN5daisy9SpiHandle6Config13ClockPolarityE", !7, i64 0}
!22 = !{!"_ZTSN5daisy9SpiHandle6Config10ClockPhaseE", !7, i64 0}
!23 = !{!"_ZTSN5daisy9SpiHandle6Config13BaudPrescalerE", !7, i64 0}
!24 = !{!"_ZTSN5daisy9SpiHandleE", !6, i64 0}
!25 = !{!"_ZTSN5daisy19MultiSlaveSpiHandle11DmaTransferE", !7, i64 0, !6, i64 8, !6, i64 16, !6, i64 24}
!26 = distinct !{!26, !27}
!27 = !{!"llvm.loop.mustprogress"}
!28 = !{!29, !29, i64 0}
!29 = !{!"_ZTSN5daisy9SpiHandle6ResultE", !7, i64 0}


; 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 uwtable
declare dso_local void @_ZN5daisy19MultiSlaveSpiHandle13DisableDeviceEm(ptr noundef nonnull align 8 dereferenceable(200), i64 noundef) local_unnamed_addr #0 align 2

; Function Attrs: mustprogress uwtable
define dso_local noundef i32 @_ZN5daisy19MultiSlaveSpiHandle16BlockingTransmitEmPhmj(ptr noundef nonnull align 8 dereferenceable(200) %0, i64 noundef %1, ptr noundef %2, i64 noundef %3, i32 noundef %4) local_unnamed_addr #0 align 2 {
  %6 = getelementptr inbounds i8, ptr %0, i64 88
  %7 = load i64, ptr %6, align 8, !tbaa !5
  %.not = icmp ugt i64 %7, %1
  br i1 %.not, label %.preheader, label %14

.preheader:                                       ; preds = %5
  %8 = getelementptr inbounds i8, ptr %0, i64 168
  br label %9

9:                                                ; preds = %.preheader, %9
  %10 = tail call noundef zeroext i1 @_ZNK5daisy19MultiSlaveSpiHandle11DmaTransfer7IsValidEv(ptr noundef nonnull align 8 dereferenceable(32) %8)
  br i1 %10, label %9, label %11, !llvm.loop !22

11:                                               ; preds = %9
  tail call void @_ZN5daisy19MultiSlaveSpiHandle12EnableDeviceEm(ptr noundef nonnull align 8 dereferenceable(200) %0, i64 noundef %1)
  %12 = getelementptr inbounds i8, ptr %0, i64 96
  %13 = tail call noundef i32 @_ZN5daisy9SpiHandle16BlockingTransmitEPhmj(ptr noundef nonnull align 8 dereferenceable(8) %12, ptr noundef %2, i64 noundef %3, i32 noundef %4)
  tail call void @_ZN5daisy19MultiSlaveSpiHandle13DisableDeviceEm(ptr noundef nonnull align 8 dereferenceable(200) %0, i64 noundef %1)
  br label %14

14:                                               ; preds = %5, %11
  %.0 = phi i32 [ %13, %11 ], [ 1, %5 ]
  ret i32 %.0
}

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

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN5daisy19MultiSlaveSpiHandle12EnableDeviceEm(ptr noundef nonnull align 8 dereferenceable(200), i64 noundef) local_unnamed_addr #0 align 2

declare noundef i32 @_ZN5daisy9SpiHandle16BlockingTransmitEPhmj(ptr noundef nonnull align 8 dereferenceable(8), ptr noundef, i64 noundef, i32 noundef) local_unnamed_addr #2

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 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 = { "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, !15, i64 88}
!6 = !{!"_ZTSN5daisy19MultiSlaveSpiHandleE", !7, i64 0, !19, i64 96, !11, i64 104, !21, i64 168}
!7 = !{!"_ZTSN5daisy19MultiSlaveSpiHandle6ConfigE", !8, i64 0, !13, i64 56, !14, i64 60, !15, i64 64, !16, i64 72, !17, i64 76, !18, i64 80, !15, i64 88}
!8 = !{!"_ZTSN5daisy19MultiSlaveSpiHandle6ConfigUt_E", !9, i64 0, !9, i64 8, !9, i64 16, !11, i64 24}
!9 = !{!"_ZTS12dsy_gpio_pin", !10, i64 0, !11, i64 4}
!10 = !{!"_ZTS13dsy_gpio_port", !11, i64 0}
!11 = !{!"omnipotent char", !12, i64 0}
!12 = !{!"Simple C++ TBAA"}
!13 = !{!"_ZTSN5daisy9SpiHandle6Config10PeripheralE", !11, i64 0}
!14 = !{!"_ZTSN5daisy9SpiHandle6Config9DirectionE", !11, i64 0}
!15 = !{!"long", !11, i64 0}
!16 = !{!"_ZTSN5daisy9SpiHandle6Config13ClockPolarityE", !11, i64 0}
!17 = !{!"_ZTSN5daisy9SpiHandle6Config10ClockPhaseE", !11, i64 0}
!18 = !{!"_ZTSN5daisy9SpiHandle6Config13BaudPrescalerE", !11, i64 0}
!19 = !{!"_ZTSN5daisy9SpiHandleE", !20, i64 0}
!20 = !{!"any pointer", !11, i64 0}
!21 = !{!"_ZTSN5daisy19MultiSlaveSpiHandle11DmaTransferE", !11, i64 0, !20, i64 8, !20, i64 16, !20, i64 24}
!22 = distinct !{!22, !23}
!23 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,LICMPass,LoopSimplifyPass,SROAPass,SimplifyCFGPass,TailCallElimPass