; LLVM IR from ctlst-tech/catpilot :: bsp/mcu/periph/usb/stm32/STM32_USB_Device_Library/Class/CDC/Src (usbd_cdc)

; 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, [16 x %struct.USBD_EndpointTypeDef], [16 x %struct.USBD_EndpointTypeDef], i32, i32, i8, i8, i8, i8, i8, i32, i8, %struct.usb_setup_req, ptr, ptr, ptr, ptr, ptr, ptr, ptr }
%struct.USBD_EndpointTypeDef = type { i32, i32, i32, i32, i16, i16 }
%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
  %6 = alloca i32, align 4
  store ptr %0, ptr %3, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #3
  %7 = load ptr, ptr %3, align 8, !tbaa !5
  %8 = getelementptr inbounds %struct._USBD_HandleTypeDef, ptr %7, i32 0, i32 19
  %9 = load ptr, ptr %8, align 8, !tbaa !9
  store ptr %9, ptr %4, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #3
  store i32 1, ptr %5, align 4, !tbaa !14
  %10 = load ptr, ptr %3, align 8, !tbaa !5
  %11 = getelementptr inbounds %struct._USBD_HandleTypeDef, ptr %10, i32 0, i32 19
  %12 = load ptr, ptr %11, align 8, !tbaa !9
  %13 = icmp eq ptr %12, null
  br i1 %13, label %14, label %15

14:                                               ; preds = %1
  store i8 3, ptr %2, align 1
  store i32 1, ptr %6, align 4
  br label %41

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

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

38:                                               ; preds = %20, %15
  %39 = load i32, ptr %5, align 4, !tbaa !14
  %40 = trunc i32 %39 to i8
  store i8 %40, ptr %2, align 1
  store i32 1, ptr %6, align 4
  br label %41

41:                                               ; preds = %38, %14
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #3
  %42 = load i8, ptr %2, align 1
  ret i8 %42
}

declare i32 @USBD_LL_Transmit(ptr noundef, i8 noundef zeroext, ptr noundef, i32 noundef) #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 712}
!10 = !{!"_USBD_HandleTypeDef", !7, i64 0, !11, i64 4, !11, i64 8, !11, i64 12, !11, i64 16, !7, i64 20, !7, i64 340, !11, i64 660, !11, i64 664, !7, i64 668, !7, i64 669, !7, i64 670, !7, i64 671, !7, i64 672, !11, i64 676, !7, i64 680, !12, i64 682, !6, i64 696, !6, i64 704, !6, i64 712, !6, i64 720, !6, i64 728, !6, i64 736, !6, i64 744}
!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 = !{!11, !11, i64 0}
!15 = !{!16, !11, i64 544}
!16 = !{!"", !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}
!17 = !{!16, !11, i64 540}
!18 = !{!19, !11, i64 4}
!19 = !{!"", !11, i64 0, !11, i64 4, !11, i64 8, !11, i64 12, !13, i64 16, !13, i64 18}
!20 = !{!16, !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, 4) i8 @USBD_CDC_TransmitPacket(ptr noundef %0) local_unnamed_addr #0 {
  %2 = getelementptr inbounds i8, ptr %0, i64 712
  %3 = load ptr, ptr %2, align 8, !tbaa !5
  %4 = icmp eq ptr %3, null
  br i1 %4, label %16, label %5

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

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

16:                                               ; preds = %5, %9, %1
  %.010 = phi i8 [ 3, %1 ], [ 0, %9 ], [ 1, %5 ]
  ret i8 %.010
}

declare i32 @USBD_LL_Transmit(ptr noundef, i8 noundef zeroext, ptr noundef, i32 noundef) 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 712}
!6 = !{!"_USBD_HandleTypeDef", !7, i64 0, !9, i64 4, !9, i64 8, !9, i64 12, !9, i64 16, !7, i64 20, !7, i64 340, !9, i64 660, !9, i64 664, !7, i64 668, !7, i64 669, !7, i64 670, !7, i64 671, !7, i64 672, !9, i64 676, !7, i64 680, !10, i64 682, !12, i64 696, !12, i64 704, !12, i64 712, !12, i64 720, !12, i64 728, !12, i64 736, !12, i64 744}
!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 4}
!17 = !{!"", !9, i64 0, !9, i64 4, !9, i64 8, !9, i64 12, !11, i64 16, !11, i64 18}
!18 = !{!14, !12, i64 528}


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