; 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_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 = %15, %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 = load volatile i32, ptr %6, align 4, !tbaa !9
  %12 = icmp ugt i32 %11, 200000
  br i1 %12, label %13, label %14

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

14:                                               ; preds = %8
  br label %15

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

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

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

35:                                               ; preds = %30
  store i32 3, ptr %3, align 4
  store i32 1, ptr %7, align 4
  br label %45

36:                                               ; preds = %30
  br label %37

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

44:                                               ; preds = %37
  store i32 0, ptr %3, align 4
  store i32 1, ptr %7, align 4
  br label %45

45:                                               ; preds = %44, %35, %13
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #2
  %46 = load i32, ptr %3, align 4
  ret i32 %46
}

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
  %.0..0..0..0.1 = load volatile i32, ptr %3, align 4, !tbaa !5
  %7 = icmp ugt i32 %.0..0..0..0.1, 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.2 = load volatile i32, ptr %3, align 4, !tbaa !5
  %15 = add i32 %.0..0..0..0.2, 1
  store volatile i32 %15, ptr %3, align 4, !tbaa !5
  %.0..0..0..0.3 = load volatile i32, ptr %3, align 4, !tbaa !5
  %16 = icmp ugt i32 %.0..0..0..0.3, 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