; LLVM IR from lichen-community-systems/signaletic :: hosts/daisy/vendor/libDaisy/Middlewares/ST/STM32_USB_Device_Library/Class (TransmitPacket)

; 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._USBD_HandleTypeDef = type { i8, i32, i32, i32, i32, [15 x %struct.USBD_EndpointTypeDef], [15 x %struct.USBD_EndpointTypeDef], i32, i32, i8, i8, i8, i8, i8, i32, %struct.usb_setup_req, ptr, ptr, ptr, ptr, ptr }
%struct.USBD_EndpointTypeDef = type { i32, i32, i32, i32, i32 }
%struct.usb_setup_req = type { i8, i8, i16, i16, i16 }
%struct.USBD_CDC_HandleTypeDef = type { [128 x i32], i8, i8, ptr, ptr, i32, i32, i32, i32 }

; 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 zeroext i8 @USBD_CDC_TransmitPacket(ptr noundef %0) #1 {
  %2 = alloca i8, align 1
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca i32, align 4
  store ptr %0, ptr %3, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #3
  %6 = load ptr, ptr %3, align 8, !tbaa !5
  %7 = getelementptr inbounds %struct._USBD_HandleTypeDef, ptr %6, i32 0, i32 18
  %8 = load ptr, ptr %7, align 8, !tbaa !9
  store ptr %8, ptr %4, align 8, !tbaa !5
  %9 = load ptr, ptr %3, align 8, !tbaa !5
  %10 = getelementptr inbounds %struct._USBD_HandleTypeDef, ptr %9, i32 0, i32 18
  %11 = load ptr, ptr %10, align 8, !tbaa !9
  %12 = icmp ne ptr %11, null
  br i1 %12, label %13, label %38

13:                                               ; preds = %1
  %14 = load ptr, ptr %4, align 8, !tbaa !5
  %15 = getelementptr inbounds %struct.USBD_CDC_HandleTypeDef, ptr %14, i32 0, i32 7
  %16 = load volatile i32, ptr %15, align 8, !tbaa !14
  %17 = icmp eq i32 %16, 0
  br i1 %17, label %18, label %37

18:                                               ; preds = %13
  %19 = load ptr, ptr %4, align 8, !tbaa !5
  %20 = getelementptr inbounds %struct.USBD_CDC_HandleTypeDef, ptr %19, i32 0, i32 7
  store volatile i32 1, ptr %20, align 8, !tbaa !14
  %21 = load ptr, ptr %4, align 8, !tbaa !5
  %22 = getelementptr inbounds %struct.USBD_CDC_HandleTypeDef, ptr %21, i32 0, i32 6
  %23 = load i32, ptr %22, align 4, !tbaa !16
  %24 = load ptr, ptr %3, align 8, !tbaa !5
  %25 = getelementptr inbounds %struct._USBD_HandleTypeDef, ptr %24, i32 0, i32 5
  %26 = getelementptr inbounds [15 x %struct.USBD_EndpointTypeDef], ptr %25, i64 0, i64 1
  %27 = getelementptr inbounds %struct.USBD_EndpointTypeDef, ptr %26, i32 0, i32 2
  store i32 %23, ptr %27, align 4, !tbaa !17
  %28 = load ptr, ptr %3, align 8, !tbaa !5
  %29 = load ptr, ptr %4, align 8, !tbaa !5
  %30 = getelementptr inbounds %struct.USBD_CDC_HandleTypeDef, ptr %29, i32 0, i32 4
  %31 = load ptr, ptr %30, align 8, !tbaa !19
  %32 = load ptr, ptr %4, align 8, !tbaa !5
  %33 = getelementptr inbounds %struct.USBD_CDC_HandleTypeDef, ptr %32, i32 0, i32 6
  %34 = load i32, ptr %33, align 4, !tbaa !16
  %35 = trunc i32 %34 to i16
  %36 = call i32 @USBD_LL_Transmit(ptr noundef %28, i8 noundef zeroext -127, ptr noundef %31, i16 noundef zeroext %35)
  store i8 0, ptr %2, align 1
  store i32 1, ptr %5, align 4
  br label %39

37:                                               ; preds = %13
  store i8 1, ptr %2, align 1
  store i32 1, ptr %5, align 4
  br label %39

38:                                               ; preds = %1
  store i8 2, ptr %2, align 1
  store i32 1, ptr %5, align 4
  br label %39

39:                                               ; preds = %38, %37, %18
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #3
  %40 = load i8, ptr %2, align 1
  ret i8 %40
}

declare i32 @USBD_LL_Transmit(ptr noundef, i8 noundef zeroext, ptr noundef, i16 noundef zeroext) #2

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 = { "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 664}
!10 = !{!"_USBD_HandleTypeDef", !7, i64 0, !11, i64 4, !11, i64 8, !11, i64 12, !11, i64 16, !7, i64 20, !7, i64 320, !11, i64 620, !11, i64 624, !7, i64 628, !7, i64 629, !7, i64 630, !7, i64 631, !7, i64 632, !11, i64 636, !12, i64 640, !6, i64 648, !6, i64 656, !6, i64 664, !6, i64 672, !6, i64 680}
!11 = !{!"int", !7, i64 0}
!12 = !{!"usb_setup_req", !7, i64 0, !7, i64 1, !13, i64 2, !13, i64 4, !13, i64 6}
!13 = !{!"short", !7, i64 0}
!14 = !{!15, !11, i64 544}
!15 = !{!"", !7, i64 0, !7, i64 512, !7, i64 513, !6, i64 520, !6, i64 528, !11, i64 536, !11, i64 540, !11, i64 544, !11, i64 548}
!16 = !{!15, !11, i64 540}
!17 = !{!18, !11, i64 8}
!18 = !{!"", !11, i64 0, !11, i64 4, !11, i64 8, !11, i64 12, !11, i64 16}
!19 = !{!15, !6, i64 528}


; 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: nounwind uwtable
define dso_local zeroext range(i8 0, 3) i8 @USBD_CDC_TransmitPacket(ptr noundef %0) local_unnamed_addr #0 {
  %2 = getelementptr inbounds i8, ptr %0, i64 664
  %3 = load ptr, ptr %2, align 8, !tbaa !5
  %.not = icmp eq ptr %3, null
  br i1 %.not, label %16, label %4

4:                                                ; preds = %1
  %5 = getelementptr inbounds i8, ptr %3, i64 544
  %6 = load volatile i32, ptr %5, align 8, !tbaa !13
  %7 = icmp eq i32 %6, 0
  br i1 %7, label %8, label %16

8:                                                ; preds = %4
  store volatile i32 1, ptr %5, align 8, !tbaa !13
  %9 = getelementptr inbounds i8, ptr %3, i64 540
  %10 = load i32, ptr %9, align 4, !tbaa !15
  %11 = getelementptr inbounds i8, ptr %0, i64 48
  store i32 %10, ptr %11, align 4, !tbaa !16
  %12 = getelementptr inbounds i8, ptr %3, i64 528
  %13 = load ptr, ptr %12, align 8, !tbaa !18
  %14 = trunc i32 %10 to i16
  %15 = tail call i32 @USBD_LL_Transmit(ptr noundef nonnull %0, i8 noundef zeroext -127, ptr noundef %13, i16 noundef zeroext %14) #2
  br label %16

16:                                               ; preds = %1, %4, %8
  %.0 = phi i8 [ 0, %8 ], [ 1, %4 ], [ 2, %1 ]
  ret i8 %.0
}

declare i32 @USBD_LL_Transmit(ptr noundef, i8 noundef zeroext, ptr noundef, i16 noundef zeroext) local_unnamed_addr #1

attributes #0 = { 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 #1 = { "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, !12, i64 664}
!6 = !{!"_USBD_HandleTypeDef", !7, i64 0, !9, i64 4, !9, i64 8, !9, i64 12, !9, i64 16, !7, i64 20, !7, i64 320, !9, i64 620, !9, i64 624, !7, i64 628, !7, i64 629, !7, i64 630, !7, i64 631, !7, i64 632, !9, i64 636, !10, i64 640, !12, i64 648, !12, i64 656, !12, i64 664, !12, i64 672, !12, i64 680}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!"int", !7, i64 0}
!10 = !{!"usb_setup_req", !7, i64 0, !7, i64 1, !11, i64 2, !11, i64 4, !11, i64 6}
!11 = !{!"short", !7, i64 0}
!12 = !{!"any pointer", !7, i64 0}
!13 = !{!14, !9, i64 544}
!14 = !{!"", !7, i64 0, !7, i64 512, !7, i64 513, !12, i64 520, !12, i64 528, !9, i64 536, !9, i64 540, !9, i64 544, !9, i64 548}
!15 = !{!14, !9, i64 540}
!16 = !{!17, !9, i64 8}
!17 = !{!"", !9, i64 0, !9, i64 4, !9, i64 8, !9, i64 12, !9, i64 16}
!18 = !{!14, !12, i64 528}


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