; LLVM IR from ctlst-tech/catpilot :: bsp/mcu/periph/usb/stm32/STM32_USB_Device_Library/Core/Src (usbd_core)

; 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._Device_cb = type { ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr }

; Function Attrs: nounwind uwtable
define dso_local i32 @USBD_LL_Reset(ptr noundef %0) #0 {
  %2 = alloca i32, align 4
  %3 = alloca ptr, align 8
  store ptr %0, ptr %3, align 8, !tbaa !5
  %4 = load ptr, ptr %3, align 8, !tbaa !5
  %5 = getelementptr inbounds %struct._USBD_HandleTypeDef, ptr %4, i32 0, i32 9
  store volatile i8 1, ptr %5, align 4, !tbaa !9
  %6 = load ptr, ptr %3, align 8, !tbaa !5
  %7 = getelementptr inbounds %struct._USBD_HandleTypeDef, ptr %6, i32 0, i32 7
  store volatile i32 0, ptr %7, align 4, !tbaa !14
  %8 = load ptr, ptr %3, align 8, !tbaa !5
  %9 = getelementptr inbounds %struct._USBD_HandleTypeDef, ptr %8, i32 0, i32 1
  store i32 0, ptr %9, align 4, !tbaa !15
  %10 = load ptr, ptr %3, align 8, !tbaa !5
  %11 = getelementptr inbounds %struct._USBD_HandleTypeDef, ptr %10, i32 0, i32 14
  store i32 0, ptr %11, align 4, !tbaa !16
  %12 = load ptr, ptr %3, align 8, !tbaa !5
  %13 = getelementptr inbounds %struct._USBD_HandleTypeDef, ptr %12, i32 0, i32 18
  %14 = load ptr, ptr %13, align 8, !tbaa !17
  %15 = icmp eq ptr %14, null
  br i1 %15, label %16, label %17

16:                                               ; preds = %1
  store i32 3, ptr %2, align 4
  br label %63

17:                                               ; preds = %1
  %18 = load ptr, ptr %3, align 8, !tbaa !5
  %19 = getelementptr inbounds %struct._USBD_HandleTypeDef, ptr %18, i32 0, i32 19
  %20 = load ptr, ptr %19, align 8, !tbaa !18
  %21 = icmp ne ptr %20, null
  br i1 %21, label %22, label %42

22:                                               ; preds = %17
  %23 = load ptr, ptr %3, align 8, !tbaa !5
  %24 = getelementptr inbounds %struct._USBD_HandleTypeDef, ptr %23, i32 0, i32 18
  %25 = load ptr, ptr %24, align 8, !tbaa !17
  %26 = getelementptr inbounds %struct._Device_cb, ptr %25, i32 0, i32 1
  %27 = load ptr, ptr %26, align 8, !tbaa !19
  %28 = icmp ne ptr %27, null
  br i1 %28, label %29, label %41

29:                                               ; preds = %22
  %30 = load ptr, ptr %3, align 8, !tbaa !5
  %31 = getelementptr inbounds %struct._USBD_HandleTypeDef, ptr %30, i32 0, i32 18
  %32 = load ptr, ptr %31, align 8, !tbaa !17
  %33 = getelementptr inbounds %struct._Device_cb, ptr %32, i32 0, i32 1
  %34 = load ptr, ptr %33, align 8, !tbaa !19
  %35 = load ptr, ptr %3, align 8, !tbaa !5
  %36 = load ptr, ptr %3, align 8, !tbaa !5
  %37 = getelementptr inbounds %struct._USBD_HandleTypeDef, ptr %36, i32 0, i32 1
  %38 = load i32, ptr %37, align 4, !tbaa !15
  %39 = trunc i32 %38 to i8
  %40 = call zeroext i8 %34(ptr noundef %35, i8 noundef zeroext %39)
  br label %41

41:                                               ; preds = %29, %22
  br label %42

42:                                               ; preds = %41, %17
  %43 = load ptr, ptr %3, align 8, !tbaa !5
  %44 = call i32 @USBD_LL_OpenEP(ptr noundef %43, i8 noundef zeroext 0, i8 noundef zeroext 0, i16 noundef zeroext 64)
  %45 = load ptr, ptr %3, align 8, !tbaa !5
  %46 = getelementptr inbounds %struct._USBD_HandleTypeDef, ptr %45, i32 0, i32 6
  %47 = getelementptr inbounds [16 x %struct.USBD_EndpointTypeDef], ptr %46, i64 0, i64 0
  %48 = getelementptr inbounds %struct.USBD_EndpointTypeDef, ptr %47, i32 0, i32 4
  store i16 1, ptr %48, align 4, !tbaa !21
  %49 = load ptr, ptr %3, align 8, !tbaa !5
  %50 = getelementptr inbounds %struct._USBD_HandleTypeDef, ptr %49, i32 0, i32 6
  %51 = getelementptr inbounds [16 x %struct.USBD_EndpointTypeDef], ptr %50, i64 0, i64 0
  %52 = getelementptr inbounds %struct.USBD_EndpointTypeDef, ptr %51, i32 0, i32 3
  store i32 64, ptr %52, align 4, !tbaa !23
  %53 = load ptr, ptr %3, align 8, !tbaa !5
  %54 = call i32 @USBD_LL_OpenEP(ptr noundef %53, i8 noundef zeroext -128, i8 noundef zeroext 0, i16 noundef zeroext 64)
  %55 = load ptr, ptr %3, align 8, !tbaa !5
  %56 = getelementptr inbounds %struct._USBD_HandleTypeDef, ptr %55, i32 0, i32 5
  %57 = getelementptr inbounds [16 x %struct.USBD_EndpointTypeDef], ptr %56, i64 0, i64 0
  %58 = getelementptr inbounds %struct.USBD_EndpointTypeDef, ptr %57, i32 0, i32 4
  store i16 1, ptr %58, align 4, !tbaa !21
  %59 = load ptr, ptr %3, align 8, !tbaa !5
  %60 = getelementptr inbounds %struct._USBD_HandleTypeDef, ptr %59, i32 0, i32 5
  %61 = getelementptr inbounds [16 x %struct.USBD_EndpointTypeDef], ptr %60, i64 0, i64 0
  %62 = getelementptr inbounds %struct.USBD_EndpointTypeDef, ptr %61, i32 0, i32 3
  store i32 64, ptr %62, align 4, !tbaa !23
  store i32 0, ptr %2, align 4
  br label %63

63:                                               ; preds = %42, %16
  %64 = load i32, ptr %2, align 4
  ret i32 %64
}

declare i32 @USBD_LL_OpenEP(ptr noundef, i8 noundef zeroext, i8 noundef zeroext, i16 noundef zeroext) #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" }

!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, !7, i64 668}
!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 = !{!10, !11, i64 660}
!15 = !{!10, !11, i64 4}
!16 = !{!10, !11, i64 676}
!17 = !{!10, !6, i64 704}
!18 = !{!10, !6, i64 712}
!19 = !{!20, !6, i64 8}
!20 = !{!"_Device_cb", !6, i64 0, !6, i64 8, !6, i64 16, !6, i64 24, !6, i64 32, !6, i64 40, !6, i64 48, !6, i64 56, !6, i64 64, !6, i64 72, !6, i64 80, !6, i64 88, !6, i64 96, !6, i64 104}
!21 = !{!22, !13, i64 16}
!22 = !{!"", !11, i64 0, !11, i64 4, !11, i64 8, !11, i64 12, !13, i64 16, !13, i64 18}
!23 = !{!22, !11, i64 12}


; 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 range(i32 0, 4) i32 @USBD_LL_Reset(ptr noundef %0) local_unnamed_addr #0 {
  %2 = getelementptr inbounds i8, ptr %0, i64 668
  store volatile i8 1, ptr %2, align 4, !tbaa !5
  %3 = getelementptr inbounds i8, ptr %0, i64 660
  store volatile i32 0, ptr %3, align 4, !tbaa !13
  %4 = getelementptr inbounds i8, ptr %0, i64 4
  store i32 0, ptr %4, align 4, !tbaa !14
  %5 = getelementptr inbounds i8, ptr %0, i64 676
  store i32 0, ptr %5, align 4, !tbaa !15
  %6 = getelementptr inbounds i8, ptr %0, i64 704
  %7 = load ptr, ptr %6, align 8, !tbaa !16
  %8 = icmp eq ptr %7, null
  br i1 %8, label %24, label %9

9:                                                ; preds = %1
  %10 = getelementptr inbounds i8, ptr %0, i64 712
  %11 = load ptr, ptr %10, align 8, !tbaa !17
  %.not = icmp eq ptr %11, null
  br i1 %.not, label %17, label %12

12:                                               ; preds = %9
  %13 = getelementptr inbounds i8, ptr %7, i64 8
  %14 = load ptr, ptr %13, align 8, !tbaa !18
  %.not18 = icmp eq ptr %14, null
  br i1 %.not18, label %17, label %15

15:                                               ; preds = %12
  %16 = tail call zeroext i8 %14(ptr noundef nonnull %0, i8 noundef zeroext 0) #2
  br label %17

17:                                               ; preds = %12, %15, %9
  %18 = tail call i32 @USBD_LL_OpenEP(ptr noundef nonnull %0, i8 noundef zeroext 0, i8 noundef zeroext 0, i16 noundef zeroext 64) #2
  %19 = getelementptr inbounds i8, ptr %0, i64 356
  store i16 1, ptr %19, align 4, !tbaa !20
  %20 = getelementptr inbounds i8, ptr %0, i64 352
  store i32 64, ptr %20, align 4, !tbaa !22
  %21 = tail call i32 @USBD_LL_OpenEP(ptr noundef nonnull %0, i8 noundef zeroext -128, i8 noundef zeroext 0, i16 noundef zeroext 64) #2
  %22 = getelementptr inbounds i8, ptr %0, i64 36
  store i16 1, ptr %22, align 4, !tbaa !20
  %23 = getelementptr inbounds i8, ptr %0, i64 32
  store i32 64, ptr %23, align 4, !tbaa !22
  br label %24

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

declare i32 @USBD_LL_OpenEP(ptr noundef, i8 noundef zeroext, i8 noundef zeroext, 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, !7, i64 668}
!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 = !{!6, !9, i64 660}
!14 = !{!6, !9, i64 4}
!15 = !{!6, !9, i64 676}
!16 = !{!6, !12, i64 704}
!17 = !{!6, !12, i64 712}
!18 = !{!19, !12, i64 8}
!19 = !{!"_Device_cb", !12, i64 0, !12, i64 8, !12, i64 16, !12, i64 24, !12, i64 32, !12, i64 40, !12, i64 48, !12, i64 56, !12, i64 64, !12, i64 72, !12, i64 80, !12, i64 88, !12, i64 96, !12, i64 104}
!20 = !{!21, !11, i64 16}
!21 = !{!"", !9, i64 0, !9, i64 4, !9, i64 8, !9, i64 12, !11, i64 16, !11, i64 18}
!22 = !{!21, !9, i64 12}


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