; LLVM IR from ctlst-tech/catpilot :: bsp/mcu/core/stm32/h753/hal/src (stm32h7xx_ll_usb)

; 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.USB_OTG_EPTypeDef = type { i8, i8, i8, i8, i8, i8, i16, i32, ptr, i32, i32, i32 }
%struct.USB_OTG_INEndpointTypeDef = type { i32, i32, i32, i32, i32, i32, i32, i32 }
%struct.USB_OTG_OUTEndpointTypeDef = type { i32, i32, i32, i32, i32, i32, [2 x 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 i32 @USB_EPStopXfer(ptr noundef %0, ptr noundef %1) #1 {
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  store ptr %0, ptr %3, align 8, !tbaa !5
  store ptr %1, ptr %4, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #2
  store volatile i32 0, ptr %5, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #2
  store i32 0, ptr %6, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #2
  %8 = load ptr, ptr %3, align 8, !tbaa !5
  %9 = ptrtoint ptr %8 to i32
  store i32 %9, ptr %7, align 4, !tbaa !9
  %10 = load ptr, ptr %4, align 8, !tbaa !5
  %11 = getelementptr inbounds %struct.USB_OTG_EPTypeDef, ptr %10, i32 0, i32 1
  %12 = load i8, ptr %11, align 1, !tbaa !11
  %13 = zext i8 %12 to i32
  %14 = icmp eq i32 %13, 1
  br i1 %14, label %15, label %86

15:                                               ; preds = %2
  %16 = load i32, ptr %7, align 4, !tbaa !9
  %17 = zext i32 %16 to i64
  %18 = add i64 %17, 2304
  %19 = load ptr, ptr %4, align 8, !tbaa !5
  %20 = getelementptr inbounds %struct.USB_OTG_EPTypeDef, ptr %19, i32 0, i32 0
  %21 = load i8, ptr %20, align 8, !tbaa !14
  %22 = zext i8 %21 to i64
  %23 = mul i64 %22, 32
  %24 = add i64 %18, %23
  %25 = inttoptr i64 %24 to ptr
  %26 = getelementptr inbounds %struct.USB_OTG_INEndpointTypeDef, ptr %25, i32 0, i32 0
  %27 = load volatile i32, ptr %26, align 4, !tbaa !15
  %28 = zext i32 %27 to i64
  %29 = and i64 %28, 2147483648
  %30 = icmp eq i64 %29, 2147483648
  br i1 %30, label %31, label %85

31:                                               ; preds = %15
  %32 = load i32, ptr %7, align 4, !tbaa !9
  %33 = zext i32 %32 to i64
  %34 = add i64 %33, 2304
  %35 = load ptr, ptr %4, align 8, !tbaa !5
  %36 = getelementptr inbounds %struct.USB_OTG_EPTypeDef, ptr %35, i32 0, i32 0
  %37 = load i8, ptr %36, align 8, !tbaa !14
  %38 = zext i8 %37 to i64
  %39 = mul i64 %38, 32
  %40 = add i64 %34, %39
  %41 = inttoptr i64 %40 to ptr
  %42 = getelementptr inbounds %struct.USB_OTG_INEndpointTypeDef, ptr %41, i32 0, i32 0
  %43 = load volatile i32, ptr %42, align 4, !tbaa !15
  %44 = zext i32 %43 to i64
  %45 = or i64 %44, 134217728
  %46 = trunc i64 %45 to i32
  store volatile i32 %46, ptr %42, align 4, !tbaa !15
  %47 = load i32, ptr %7, align 4, !tbaa !9
  %48 = zext i32 %47 to i64
  %49 = add i64 %48, 2304
  %50 = load ptr, ptr %4, align 8, !tbaa !5
  %51 = getelementptr inbounds %struct.USB_OTG_EPTypeDef, ptr %50, i32 0, i32 0
  %52 = load i8, ptr %51, align 8, !tbaa !14
  %53 = zext i8 %52 to i64
  %54 = mul i64 %53, 32
  %55 = add i64 %49, %54
  %56 = inttoptr i64 %55 to ptr
  %57 = getelementptr inbounds %struct.USB_OTG_INEndpointTypeDef, ptr %56, i32 0, i32 0
  %58 = load volatile i32, ptr %57, align 4, !tbaa !15
  %59 = zext i32 %58 to i64
  %60 = or i64 %59, 1073741824
  %61 = trunc i64 %60 to i32
  store volatile i32 %61, ptr %57, align 4, !tbaa !15
  br label %62

62:                                               ; preds = %68, %31
  %63 = load volatile i32, ptr %5, align 4, !tbaa !9
  %64 = add i32 %63, 1
  store volatile i32 %64, ptr %5, align 4, !tbaa !9
  %65 = icmp ugt i32 %64, 10000
  br i1 %65, label %66, label %67

66:                                               ; preds = %62
  store i32 1, ptr %6, align 4, !tbaa !9
  br label %84

67:                                               ; preds = %62
  br label %68

68:                                               ; preds = %67
  %69 = load i32, ptr %7, align 4, !tbaa !9
  %70 = zext i32 %69 to i64
  %71 = add i64 %70, 2304
  %72 = load ptr, ptr %4, align 8, !tbaa !5
  %73 = getelementptr inbounds %struct.USB_OTG_EPTypeDef, ptr %72, i32 0, i32 0
  %74 = load i8, ptr %73, align 8, !tbaa !14
  %75 = zext i8 %74 to i64
  %76 = mul i64 %75, 32
  %77 = add i64 %71, %76
  %78 = inttoptr i64 %77 to ptr
  %79 = getelementptr inbounds %struct.USB_OTG_INEndpointTypeDef, ptr %78, i32 0, i32 0
  %80 = load volatile i32, ptr %79, align 4, !tbaa !15
  %81 = zext i32 %80 to i64
  %82 = and i64 %81, 2147483648
  %83 = icmp eq i64 %82, 2147483648
  br i1 %83, label %62, label %84, !llvm.loop !17

84:                                               ; preds = %68, %66
  br label %85

85:                                               ; preds = %84, %15
  br label %157

86:                                               ; preds = %2
  %87 = load i32, ptr %7, align 4, !tbaa !9
  %88 = zext i32 %87 to i64
  %89 = add i64 %88, 2816
  %90 = load ptr, ptr %4, align 8, !tbaa !5
  %91 = getelementptr inbounds %struct.USB_OTG_EPTypeDef, ptr %90, i32 0, i32 0
  %92 = load i8, ptr %91, align 8, !tbaa !14
  %93 = zext i8 %92 to i64
  %94 = mul i64 %93, 32
  %95 = add i64 %89, %94
  %96 = inttoptr i64 %95 to ptr
  %97 = getelementptr inbounds %struct.USB_OTG_OUTEndpointTypeDef, ptr %96, i32 0, i32 0
  %98 = load volatile i32, ptr %97, align 4, !tbaa !19
  %99 = zext i32 %98 to i64
  %100 = and i64 %99, 2147483648
  %101 = icmp eq i64 %100, 2147483648
  br i1 %101, label %102, label %156

102:                                              ; preds = %86
  %103 = load i32, ptr %7, align 4, !tbaa !9
  %104 = zext i32 %103 to i64
  %105 = add i64 %104, 2816
  %106 = load ptr, ptr %4, align 8, !tbaa !5
  %107 = getelementptr inbounds %struct.USB_OTG_EPTypeDef, ptr %106, i32 0, i32 0
  %108 = load i8, ptr %107, align 8, !tbaa !14
  %109 = zext i8 %108 to i64
  %110 = mul i64 %109, 32
  %111 = add i64 %105, %110
  %112 = inttoptr i64 %111 to ptr
  %113 = getelementptr inbounds %struct.USB_OTG_OUTEndpointTypeDef, ptr %112, i32 0, i32 0
  %114 = load volatile i32, ptr %113, align 4, !tbaa !19
  %115 = zext i32 %114 to i64
  %116 = or i64 %115, 134217728
  %117 = trunc i64 %116 to i32
  store volatile i32 %117, ptr %113, align 4, !tbaa !19
  %118 = load i32, ptr %7, align 4, !tbaa !9
  %119 = zext i32 %118 to i64
  %120 = add i64 %119, 2816
  %121 = load ptr, ptr %4, align 8, !tbaa !5
  %122 = getelementptr inbounds %struct.USB_OTG_EPTypeDef, ptr %121, i32 0, i32 0
  %123 = load i8, ptr %122, align 8, !tbaa !14
  %124 = zext i8 %123 to i64
  %125 = mul i64 %124, 32
  %126 = add i64 %120, %125
  %127 = inttoptr i64 %126 to ptr
  %128 = getelementptr inbounds %struct.USB_OTG_OUTEndpointTypeDef, ptr %127, i32 0, i32 0
  %129 = load volatile i32, ptr %128, align 4, !tbaa !19
  %130 = zext i32 %129 to i64
  %131 = or i64 %130, 1073741824
  %132 = trunc i64 %131 to i32
  store volatile i32 %132, ptr %128, align 4, !tbaa !19
  br label %133

133:                                              ; preds = %139, %102
  %134 = load volatile i32, ptr %5, align 4, !tbaa !9
  %135 = add i32 %134, 1
  store volatile i32 %135, ptr %5, align 4, !tbaa !9
  %136 = icmp ugt i32 %135, 10000
  br i1 %136, label %137, label %138

137:                                              ; preds = %133
  store i32 1, ptr %6, align 4, !tbaa !9
  br label %155

138:                                              ; preds = %133
  br label %139

139:                                              ; preds = %138
  %140 = load i32, ptr %7, align 4, !tbaa !9
  %141 = zext i32 %140 to i64
  %142 = add i64 %141, 2816
  %143 = load ptr, ptr %4, align 8, !tbaa !5
  %144 = getelementptr inbounds %struct.USB_OTG_EPTypeDef, ptr %143, i32 0, i32 0
  %145 = load i8, ptr %144, align 8, !tbaa !14
  %146 = zext i8 %145 to i64
  %147 = mul i64 %146, 32
  %148 = add i64 %142, %147
  %149 = inttoptr i64 %148 to ptr
  %150 = getelementptr inbounds %struct.USB_OTG_OUTEndpointTypeDef, ptr %149, i32 0, i32 0
  %151 = load volatile i32, ptr %150, align 4, !tbaa !19
  %152 = zext i32 %151 to i64
  %153 = and i64 %152, 2147483648
  %154 = icmp eq i64 %153, 2147483648
  br i1 %154, label %133, label %155, !llvm.loop !21

155:                                              ; preds = %139, %137
  br label %156

156:                                              ; preds = %155, %86
  br label %157

157:                                              ; preds = %156, %85
  %158 = load i32, ptr %6, align 4, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #2
  ret i32 %158
}

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 = { 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, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = !{!12, !7, i64 1}
!12 = !{!"", !7, i64 0, !7, i64 1, !7, i64 2, !7, i64 3, !7, i64 4, !7, i64 5, !13, i64 6, !10, i64 8, !6, i64 16, !10, i64 24, !10, i64 28, !10, i64 32}
!13 = !{!"short", !7, i64 0}
!14 = !{!12, !7, i64 0}
!15 = !{!16, !10, i64 0}
!16 = !{!"", !10, i64 0, !10, i64 4, !10, i64 8, !10, i64 12, !10, i64 16, !10, i64 20, !10, i64 24, !10, i64 28}
!17 = distinct !{!17, !18}
!18 = !{!"llvm.loop.mustprogress"}
!19 = !{!20, !10, i64 0}
!20 = !{!"", !10, i64 0, !10, i64 4, !10, i64 8, !10, i64 12, !10, i64 16, !10, i64 20, !7, i64 24}
!21 = distinct !{!21, !18}


; 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 nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #0

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

; Function Attrs: nofree norecurse nounwind uwtable
define dso_local range(i32 0, 2) i32 @USB_EPStopXfer(ptr noundef %0, ptr nocapture noundef readonly %1) local_unnamed_addr #1 {
  %3 = alloca i32, align 4
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %3)
  store volatile i32 0, ptr %3, align 4, !tbaa !5
  %4 = ptrtoint ptr %0 to i64
  %5 = getelementptr inbounds i8, ptr %1, i64 1
  %6 = load i8, ptr %5, align 1, !tbaa !9
  %7 = icmp eq i8 %6, 1
  %8 = and i64 %4, 4294967295
  %9 = load i8, ptr %1, align 8, !tbaa !13
  %10 = zext i8 %9 to i64
  %11 = shl nuw nsw i64 %10, 5
  br i1 %7, label %12, label %27

12:                                               ; preds = %2
  %13 = add nuw nsw i64 %8, 2304
  %14 = add nuw nsw i64 %13, %11
  %15 = inttoptr i64 %14 to ptr
  %16 = load volatile i32, ptr %15, align 4, !tbaa !14
  %.not21 = icmp sgt i32 %16, -1
  br i1 %.not21, label %.loopexit, label %17

17:                                               ; preds = %12
  %18 = load volatile i32, ptr %15, align 4, !tbaa !14
  %19 = or i32 %18, 134217728
  store volatile i32 %19, ptr %15, align 4, !tbaa !14
  %20 = load volatile i32, ptr %15, align 4, !tbaa !14
  %21 = or i32 %20, 1073741824
  store volatile i32 %21, ptr %15, align 4, !tbaa !14
  br label %22

22:                                               ; preds = %25, %17
  %.0..0..0..0. = load volatile i32, ptr %3, align 4, !tbaa !5
  %23 = add i32 %.0..0..0..0., 1
  store volatile i32 %23, ptr %3, align 4, !tbaa !5
  %24 = icmp ugt i32 %23, 10000
  br i1 %24, label %.loopexit, label %25

25:                                               ; preds = %22
  %26 = load volatile i32, ptr %15, align 4, !tbaa !14
  %.not22 = icmp sgt i32 %26, -1
  br i1 %.not22, label %.loopexit, label %22, !llvm.loop !16

27:                                               ; preds = %2
  %28 = add nuw nsw i64 %8, 2816
  %29 = add nuw nsw i64 %28, %11
  %30 = inttoptr i64 %29 to ptr
  %31 = load volatile i32, ptr %30, align 4, !tbaa !18
  %.not = icmp sgt i32 %31, -1
  br i1 %.not, label %.loopexit, label %32

32:                                               ; preds = %27
  %33 = load volatile i32, ptr %30, align 4, !tbaa !18
  %34 = or i32 %33, 134217728
  store volatile i32 %34, ptr %30, align 4, !tbaa !18
  %35 = load volatile i32, ptr %30, align 4, !tbaa !18
  %36 = or i32 %35, 1073741824
  store volatile i32 %36, ptr %30, align 4, !tbaa !18
  br label %37

37:                                               ; preds = %40, %32
  %.0..0..0..0.9 = load volatile i32, ptr %3, align 4, !tbaa !5
  %38 = add i32 %.0..0..0..0.9, 1
  store volatile i32 %38, ptr %3, align 4, !tbaa !5
  %39 = icmp ugt i32 %38, 10000
  br i1 %39, label %.loopexit, label %40

40:                                               ; preds = %37
  %41 = load volatile i32, ptr %30, align 4, !tbaa !18
  %.not20 = icmp sgt i32 %41, -1
  br i1 %.not20, label %.loopexit, label %37, !llvm.loop !20

.loopexit:                                        ; preds = %37, %40, %22, %25, %27, %12
  %.0 = phi i32 [ 0, %12 ], [ 0, %27 ], [ 1, %22 ], [ 0, %25 ], [ 1, %37 ], [ 0, %40 ]
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %3)
  ret i32 %.0
}

attributes #0 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { nofree norecurse 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" }

!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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !7, i64 1}
!10 = !{!"", !7, i64 0, !7, i64 1, !7, i64 2, !7, i64 3, !7, i64 4, !7, i64 5, !11, i64 6, !6, i64 8, !12, i64 16, !6, i64 24, !6, i64 28, !6, i64 32}
!11 = !{!"short", !7, i64 0}
!12 = !{!"any pointer", !7, i64 0}
!13 = !{!10, !7, i64 0}
!14 = !{!15, !6, i64 0}
!15 = !{!"", !6, i64 0, !6, i64 4, !6, i64 8, !6, i64 12, !6, i64 16, !6, i64 20, !6, i64 24, !6, i64 28}
!16 = distinct !{!16, !17}
!17 = !{!"llvm.loop.mustprogress"}
!18 = !{!19, !6, i64 0}
!19 = !{!"", !6, i64 0, !6, i64 4, !6, i64 8, !6, i64 12, !6, i64 16, !6, i64 20, !7, i64 24}
!20 = distinct !{!20, !17}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass