; LLVM IR from thalium/icebox :: third_party/virtualbox/src/VBox/Devices/EFI/Firmware/MdeModulePkg/Bus/Ufs (UfsWaitMemSet)

; 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"

; Function Attrs: nounwind uwtable
define dso_local i64 @UfsWaitMemSet(i64 noundef %0, i32 noundef %1, i32 noundef %2, i64 noundef %3) #0 {
  %5 = alloca i64, align 8
  %6 = alloca i64, align 8
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  %9 = alloca i64, align 8
  %10 = alloca i32, align 4
  %11 = alloca i64, align 8
  %12 = alloca i8, align 1
  %13 = alloca i32, align 4
  store i64 %0, ptr %6, align 8, !tbaa !5
  store i32 %1, ptr %7, align 4, !tbaa !9
  store i32 %2, ptr %8, align 4, !tbaa !9
  store i64 %3, ptr %9, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #3
  call void @llvm.lifetime.start.p0(i64 1, ptr %12) #3
  %14 = load i64, ptr %9, align 8, !tbaa !5
  %15 = icmp eq i64 %14, 0
  br i1 %15, label %16, label %17

16:                                               ; preds = %4
  store i8 1, ptr %12, align 1, !tbaa !11
  br label %18

17:                                               ; preds = %4
  store i8 0, ptr %12, align 1, !tbaa !11
  br label %18

18:                                               ; preds = %17, %16
  %19 = load i64, ptr %9, align 8, !tbaa !5
  %20 = call i64 @DivU64x32(i64 noundef %19, i32 noundef 10)
  %21 = add i64 %20, 1
  store i64 %21, ptr %11, align 8, !tbaa !5
  br label %22

22:                                               ; preds = %42, %18
  %23 = load i64, ptr %6, align 8, !tbaa !5
  %24 = call i32 @MmioRead32(i64 noundef %23)
  %25 = load i32, ptr %7, align 4, !tbaa !9
  %26 = and i32 %24, %25
  store i32 %26, ptr %10, align 4, !tbaa !9
  %27 = load i32, ptr %10, align 4, !tbaa !9
  %28 = load i32, ptr %8, align 4, !tbaa !9
  %29 = icmp eq i32 %27, %28
  br i1 %29, label %30, label %31

30:                                               ; preds = %22
  store i64 0, ptr %5, align 8
  store i32 1, ptr %13, align 4
  br label %45

31:                                               ; preds = %22
  %32 = call i64 @MicroSecondDelay(i64 noundef 1)
  %33 = load i64, ptr %11, align 8, !tbaa !5
  %34 = add i64 %33, -1
  store i64 %34, ptr %11, align 8, !tbaa !5
  br label %35

35:                                               ; preds = %31
  %36 = load i8, ptr %12, align 1, !tbaa !11
  %37 = zext i8 %36 to i32
  %38 = icmp ne i32 %37, 0
  br i1 %38, label %42, label %39

39:                                               ; preds = %35
  %40 = load i64, ptr %11, align 8, !tbaa !5
  %41 = icmp ugt i64 %40, 0
  br label %42

42:                                               ; preds = %39, %35
  %43 = phi i1 [ true, %35 ], [ %41, %39 ]
  br i1 %43, label %22, label %44, !llvm.loop !12

44:                                               ; preds = %42
  store i64 -9223372036854775790, ptr %5, align 8
  store i32 1, ptr %13, align 4
  br label %45

45:                                               ; preds = %44, %30
  call void @llvm.lifetime.end.p0(i64 1, ptr %12) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #3
  %46 = load i64, ptr %5, align 8
  ret i64 %46
}

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

declare i64 @DivU64x32(i64 noundef, i32 noundef) #2

declare i32 @MmioRead32(i64 noundef) #2

declare i64 @MicroSecondDelay(i64 noundef) #2

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

attributes #0 = { 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 #1 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { "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 #3 = { 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 = !{!"long long", !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 = !{!7, !7, i64 0}
!12 = distinct !{!12, !13}
!13 = !{!"llvm.loop.mustprogress"}


; 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: nounwind uwtable
define dso_local range(i64 -9223372036854775790, 1) i64 @UfsWaitMemSet(i64 noundef %0, i32 noundef %1, i32 noundef %2, i64 noundef %3) local_unnamed_addr #0 {
  %5 = icmp eq i64 %3, 0
  %6 = tail call i64 @DivU64x32(i64 noundef %3, i32 noundef 10) #2
  br i1 %5, label %.split.us, label %.split.preheader

.split.preheader:                                 ; preds = %4
  %7 = add i64 %6, 1
  br label %.split

.split.us:                                        ; preds = %4
  %8 = tail call i32 @MmioRead32(i64 noundef %0) #2
  %9 = and i32 %8, %1
  %10 = icmp eq i32 %9, %2
  br i1 %10, label %.split13.us, label %.lr.ph

.lr.ph:                                           ; preds = %.split.us, %.lr.ph
  %11 = tail call i64 @MicroSecondDelay(i64 noundef 1) #2
  %12 = tail call i32 @MmioRead32(i64 noundef %0) #2
  %13 = and i32 %12, %1
  %14 = icmp eq i32 %13, %2
  br i1 %14, label %.split13.us, label %.lr.ph

.split:                                           ; preds = %.split.preheader, %18
  %.010 = phi i64 [ %20, %18 ], [ %7, %.split.preheader ]
  %15 = tail call i32 @MmioRead32(i64 noundef %0) #2
  %16 = and i32 %15, %1
  %17 = icmp eq i32 %16, %2
  br i1 %17, label %.split13.us, label %18

18:                                               ; preds = %.split
  %19 = tail call i64 @MicroSecondDelay(i64 noundef 1) #2
  %20 = add i64 %.010, -1
  %.not = icmp eq i64 %20, 0
  br i1 %.not, label %.split13.us, label %.split, !llvm.loop !5

.split13.us:                                      ; preds = %.split, %18, %.lr.ph, %.split.us
  %.us-phi = phi i64 [ 0, %.split.us ], [ 0, %.lr.ph ], [ 0, %.split ], [ -9223372036854775790, %18 ]
  ret i64 %.us-phi
}

declare i64 @DivU64x32(i64 noundef, i32 noundef) local_unnamed_addr #1

declare i32 @MmioRead32(i64 noundef) local_unnamed_addr #1

declare i64 @MicroSecondDelay(i64 noundef) local_unnamed_addr #1

attributes #0 = { 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 #1 = { "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 = distinct !{!5, !6}
!6 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LoopInstSimplifyPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,SROAPass,SimplifyCFGPass,TailCallElimPass