; 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_GlobalTypeDef = type { i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, [2 x i32], i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, [39 x i32], i32, [15 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_FlushTxFifo(ptr noundef %0, i32 noundef %1) #1 {
  %3 = alloca i32, align 4
  %4 = alloca ptr, align 8
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  store ptr %0, ptr %4, align 8, !tbaa !5
  store i32 %1, ptr %5, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #2
  store volatile i32 0, ptr %6, align 4, !tbaa !9
  br label %8

8:                                                ; preds = %14, %2
  %9 = load volatile i32, ptr %6, align 4, !tbaa !9
  %10 = add i32 %9, 1
  store volatile i32 %10, ptr %6, align 4, !tbaa !9
  %11 = icmp ugt i32 %10, 200000
  br i1 %11, label %12, label %13

12:                                               ; preds = %8
  store i32 3, ptr %3, align 4
  store i32 1, ptr %7, align 4
  br label %43

13:                                               ; preds = %8
  br label %14

14:                                               ; preds = %13
  %15 = load ptr, ptr %4, align 8, !tbaa !5
  %16 = getelementptr inbounds %struct.USB_OTG_GlobalTypeDef, ptr %15, i32 0, i32 4
  %17 = load volatile i32, ptr %16, align 4, !tbaa !11
  %18 = zext i32 %17 to i64
  %19 = and i64 %18, 2147483648
  %20 = icmp eq i64 %19, 0
  br i1 %20, label %8, label %21, !llvm.loop !13

21:                                               ; preds = %14
  store volatile i32 0, ptr %6, align 4, !tbaa !9
  %22 = load i32, ptr %5, align 4, !tbaa !9
  %23 = shl i32 %22, 6
  %24 = zext i32 %23 to i64
  %25 = or i64 32, %24
  %26 = trunc i64 %25 to i32
  %27 = load ptr, ptr %4, align 8, !tbaa !5
  %28 = getelementptr inbounds %struct.USB_OTG_GlobalTypeDef, ptr %27, i32 0, i32 4
  store volatile i32 %26, ptr %28, align 4, !tbaa !11
  br label %29

29:                                               ; preds = %35, %21
  %30 = load volatile i32, ptr %6, align 4, !tbaa !9
  %31 = add i32 %30, 1
  store volatile i32 %31, ptr %6, align 4, !tbaa !9
  %32 = icmp ugt i32 %31, 200000
  br i1 %32, label %33, label %34

33:                                               ; preds = %29
  store i32 3, ptr %3, align 4
  store i32 1, ptr %7, align 4
  br label %43

34:                                               ; preds = %29
  br label %35

35:                                               ; preds = %34
  %36 = load ptr, ptr %4, align 8, !tbaa !5
  %37 = getelementptr inbounds %struct.USB_OTG_GlobalTypeDef, ptr %36, i32 0, i32 4
  %38 = load volatile i32, ptr %37, align 4, !tbaa !11
  %39 = zext i32 %38 to i64
  %40 = and i64 %39, 32
  %41 = icmp eq i64 %40, 32
  br i1 %41, label %29, label %42, !llvm.loop !15

42:                                               ; preds = %35
  store i32 0, ptr %3, align 4
  store i32 1, ptr %7, align 4
  br label %43

43:                                               ; preds = %42, %33, %12
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #2
  %44 = load i32, ptr %3, align 4
  ret i32 %44
}

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, !10, i64 16}
!12 = !{!"", !10, i64 0, !10, i64 4, !10, i64 8, !10, i64 12, !10, i64 16, !10, i64 20, !10, i64 24, !10, i64 28, !10, i64 32, !10, i64 36, !10, i64 40, !10, i64 44, !7, i64 48, !10, i64 56, !10, i64 60, !10, i64 64, !10, i64 68, !10, i64 72, !10, i64 76, !10, i64 80, !10, i64 84, !10, i64 88, !10, i64 92, !10, i64 96, !7, i64 100, !10, i64 256, !7, i64 260}
!13 = distinct !{!13, !14}
!14 = !{!"llvm.loop.mustprogress"}
!15 = distinct !{!15, !14}


; 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 memory(argmem: readwrite, inaccessiblemem: readwrite) uwtable
define dso_local range(i32 0, 4) i32 @USB_FlushTxFifo(ptr noundef %0, i32 noundef %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 = getelementptr inbounds i8, ptr %0, i64 16
  br label %5

5:                                                ; preds = %8, %2
  %.0..0..0..0. = load volatile i32, ptr %3, align 4, !tbaa !5
  %6 = add i32 %.0..0..0..0., 1
  store volatile i32 %6, ptr %3, align 4, !tbaa !5
  %7 = icmp ugt i32 %6, 200000
  br i1 %7, label %.loopexit, label %8

8:                                                ; preds = %5
  %9 = load volatile i32, ptr %4, align 4, !tbaa !9
  %10 = icmp sgt i32 %9, -1
  br i1 %10, label %5, label %11, !llvm.loop !11

11:                                               ; preds = %8
  store volatile i32 0, ptr %3, align 4, !tbaa !5
  %12 = shl i32 %1, 6
  %13 = or disjoint i32 %12, 32
  store volatile i32 %13, ptr %4, align 4, !tbaa !9
  br label %14

14:                                               ; preds = %17, %11
  %.0..0..0..0.1 = load volatile i32, ptr %3, align 4, !tbaa !5
  %15 = add i32 %.0..0..0..0.1, 1
  store volatile i32 %15, ptr %3, align 4, !tbaa !5
  %16 = icmp ugt i32 %15, 200000
  br i1 %16, label %.loopexit, label %17

17:                                               ; preds = %14
  %18 = load volatile i32, ptr %4, align 4, !tbaa !9
  %19 = and i32 %18, 32
  %.not = icmp eq i32 %19, 0
  br i1 %.not, label %.loopexit, label %14, !llvm.loop !13

.loopexit:                                        ; preds = %5, %17, %14
  %.0 = phi i32 [ 0, %17 ], [ 3, %14 ], [ 3, %5 ]
  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 memory(argmem: readwrite, inaccessiblemem: readwrite) 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, !6, i64 16}
!10 = !{!"", !6, i64 0, !6, i64 4, !6, i64 8, !6, i64 12, !6, i64 16, !6, i64 20, !6, i64 24, !6, i64 28, !6, i64 32, !6, i64 36, !6, i64 40, !6, i64 44, !7, i64 48, !6, i64 56, !6, i64 60, !6, i64 64, !6, i64 68, !6, i64 72, !6, i64 76, !6, i64 80, !6, i64 84, !6, i64 88, !6, i64 92, !6, i64 96, !7, i64 100, !6, i64 256, !7, i64 260}
!11 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}
!13 = distinct !{!13, !12}


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