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

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

11:                                               ; preds = %6
  store i32 3, ptr %2, align 4
  store i32 1, ptr %5, align 4
  br label %38

12:                                               ; preds = %6
  br label %13

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

20:                                               ; preds = %13
  store volatile i32 0, ptr %4, align 4, !tbaa !9
  %21 = load ptr, ptr %3, align 8, !tbaa !5
  %22 = getelementptr inbounds %struct.USB_OTG_GlobalTypeDef, ptr %21, i32 0, i32 4
  store volatile i32 16, ptr %22, align 4, !tbaa !11
  br label %23

23:                                               ; preds = %30, %20
  %24 = load volatile i32, ptr %4, align 4, !tbaa !9
  %25 = add i32 %24, 1
  store volatile i32 %25, ptr %4, align 4, !tbaa !9
  %26 = load volatile i32, ptr %4, align 4, !tbaa !9
  %27 = icmp ugt i32 %26, 200000
  br i1 %27, label %28, label %29

28:                                               ; preds = %23
  store i32 3, ptr %2, align 4
  store i32 1, ptr %5, align 4
  br label %38

29:                                               ; preds = %23
  br label %30

30:                                               ; preds = %29
  %31 = load ptr, ptr %3, align 8, !tbaa !5
  %32 = getelementptr inbounds %struct.USB_OTG_GlobalTypeDef, ptr %31, i32 0, i32 4
  %33 = load volatile i32, ptr %32, align 4, !tbaa !11
  %34 = zext i32 %33 to i64
  %35 = and i64 %34, 16
  %36 = icmp eq i64 %35, 16
  br i1 %36, label %23, label %37, !llvm.loop !15

37:                                               ; preds = %30
  store i32 0, ptr %2, align 4
  store i32 1, ptr %5, align 4
  br label %38

38:                                               ; preds = %37, %28, %11
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #2
  %39 = load i32, ptr %2, align 4
  ret i32 %39
}

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_FlushRxFifo(ptr noundef %0) local_unnamed_addr #1 {
  %2 = alloca i32, align 4
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %2)
  store volatile i32 0, ptr %2, align 4, !tbaa !5
  %3 = getelementptr inbounds i8, ptr %0, i64 16
  br label %4

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

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

10:                                               ; preds = %7
  store volatile i32 0, ptr %2, align 4, !tbaa !5
  store volatile i32 16, ptr %3, align 4, !tbaa !9
  br label %11

11:                                               ; preds = %14, %10
  %.0..0..0..0.2 = load volatile i32, ptr %2, align 4, !tbaa !5
  %12 = add i32 %.0..0..0..0.2, 1
  store volatile i32 %12, ptr %2, align 4, !tbaa !5
  %.0..0..0..0.3 = load volatile i32, ptr %2, align 4, !tbaa !5
  %13 = icmp ugt i32 %.0..0..0..0.3, 200000
  br i1 %13, label %.loopexit, label %14

14:                                               ; preds = %11
  %15 = load volatile i32, ptr %3, align 4, !tbaa !9
  %16 = and i32 %15, 16
  %.not = icmp eq i32 %16, 0
  br i1 %.not, label %.loopexit, label %11, !llvm.loop !13

.loopexit:                                        ; preds = %4, %14, %11
  %.0 = phi i32 [ 0, %14 ], [ 3, %11 ], [ 3, %4 ]
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %2)
  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,SROAPass,SimplifyCFGPass