; LLVM IR from reazon-research/OpenArm :: control/canfd_control/Drivers/STM32H7xx_HAL_Driver/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_EPTypeDef = type { i8, i8, i8, i8, i8, i8, i32, ptr, i32, i32, i8, i16, 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_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 %87

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_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 %86

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_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_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 = %69, %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 = load volatile i32, ptr %5, align 4, !tbaa !9
  %66 = icmp ugt i32 %65, 10000
  br i1 %66, label %67, label %68

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

68:                                               ; preds = %62
  br label %69

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

85:                                               ; preds = %69, %67
  br label %86

86:                                               ; preds = %85, %15
  br label %159

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

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

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

139:                                              ; preds = %134
  store i32 1, ptr %6, align 4, !tbaa !9
  br label %157

140:                                              ; preds = %134
  br label %141

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

157:                                              ; preds = %141, %139
  br label %158

158:                                              ; preds = %157, %87
  br label %159

159:                                              ; preds = %158, %86
  %160 = 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 %160
}

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, !10, i64 8, !6, i64 16, !10, i64 24, !10, i64 28, !7, i64 32, !13, i64 34, !10, i64 36, !10, i64 40}
!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
  %.not23 = icmp sgt i32 %16, -1
  br i1 %.not23, 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
  %.0..0..0..0.9 = load volatile i32, ptr %3, align 4, !tbaa !5
  %24 = icmp ugt i32 %.0..0..0..0.9, 10000
  br i1 %24, label %.loopexit, label %25

25:                                               ; preds = %22
  %26 = load volatile i32, ptr %15, align 4, !tbaa !14
  %.not24 = icmp sgt i32 %26, -1
  br i1 %.not24, 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.10 = load volatile i32, ptr %3, align 4, !tbaa !5
  %38 = add i32 %.0..0..0..0.10, 1
  store volatile i32 %38, ptr %3, align 4, !tbaa !5
  %.0..0..0..0.11 = load volatile i32, ptr %3, align 4, !tbaa !5
  %39 = icmp ugt i32 %.0..0..0..0.11, 10000
  br i1 %39, label %.loopexit, label %40

40:                                               ; preds = %37
  %41 = load volatile i32, ptr %30, align 4, !tbaa !18
  %.not22 = icmp sgt i32 %41, -1
  br i1 %.not22, 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, !6, i64 8, !11, i64 16, !6, i64 24, !6, i64 28, !7, i64 32, !12, i64 34, !6, i64 36, !6, i64 40}
!11 = !{!"any pointer", !7, i64 0}
!12 = !{!"short", !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