; LLVM IR from thalium/icebox :: third_party/virtualbox/src/VBox/Devices/EFI/Firmware/MdePkg/Library (MmioReadBuffer8)

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

@.str = external hidden unnamed_addr constant [153 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [52 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [54 x i8], align 1

; Function Attrs: nounwind uwtable
define dso_local ptr @MmioReadBuffer8(i64 noundef %0, i64 noundef %1, ptr noundef %2) #0 {
  %4 = alloca i64, align 8
  %5 = alloca i64, align 8
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  store i64 %0, ptr %4, align 8, !tbaa !5
  store i64 %1, ptr %5, align 8, !tbaa !5
  store ptr %2, ptr %6, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #3
  br label %8

8:                                                ; preds = %3
  %9 = call zeroext i8 @DebugAssertEnabled()
  %10 = icmp ne i8 %9, 0
  br i1 %10, label %11, label %19

11:                                               ; preds = %8
  %12 = load i64, ptr %5, align 8, !tbaa !5
  %13 = sub i64 %12, 1
  %14 = load i64, ptr %4, align 8, !tbaa !5
  %15 = sub i64 -1, %14
  %16 = icmp ule i64 %13, %15
  br i1 %16, label %18, label %17

17:                                               ; preds = %11
  call void @DebugAssert(ptr noundef @.str, i64 noundef 45, ptr noundef @.str.1)
  br label %18

18:                                               ; preds = %17, %11
  br label %19

19:                                               ; preds = %18, %8
  br label %20

20:                                               ; preds = %19
  br label %21

21:                                               ; preds = %20
  br label %22

22:                                               ; preds = %21
  %23 = call zeroext i8 @DebugAssertEnabled()
  %24 = icmp ne i8 %23, 0
  br i1 %24, label %25, label %34

25:                                               ; preds = %22
  %26 = load i64, ptr %5, align 8, !tbaa !5
  %27 = sub i64 %26, 1
  %28 = load ptr, ptr %6, align 8, !tbaa !9
  %29 = ptrtoint ptr %28 to i64
  %30 = sub i64 -1, %29
  %31 = icmp ule i64 %27, %30
  br i1 %31, label %33, label %32

32:                                               ; preds = %25
  call void @DebugAssert(ptr noundef @.str, i64 noundef 46, ptr noundef @.str.2)
  br label %33

33:                                               ; preds = %32, %25
  br label %34

34:                                               ; preds = %33, %22
  br label %35

35:                                               ; preds = %34
  br label %36

36:                                               ; preds = %35
  %37 = load ptr, ptr %6, align 8, !tbaa !9
  store ptr %37, ptr %7, align 8, !tbaa !9
  br label %38

38:                                               ; preds = %42, %36
  %39 = load i64, ptr %5, align 8, !tbaa !5
  %40 = add i64 %39, -1
  store i64 %40, ptr %5, align 8, !tbaa !5
  %41 = icmp ne i64 %39, 0
  br i1 %41, label %42, label %48

42:                                               ; preds = %38
  %43 = load i64, ptr %4, align 8, !tbaa !5
  %44 = add i64 %43, 1
  store i64 %44, ptr %4, align 8, !tbaa !5
  %45 = call zeroext i8 @MmioRead8(i64 noundef %43)
  %46 = load ptr, ptr %6, align 8, !tbaa !9
  %47 = getelementptr inbounds i8, ptr %46, i32 1
  store ptr %47, ptr %6, align 8, !tbaa !9
  store i8 %45, ptr %46, align 1, !tbaa !11
  br label %38, !llvm.loop !12

48:                                               ; preds = %38
  %49 = load ptr, ptr %7, align 8, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #3
  ret ptr %49
}

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

declare zeroext i8 @DebugAssertEnabled() #2

declare void @DebugAssert(ptr noundef, i64 noundef, ptr noundef) #2

declare zeroext i8 @MmioRead8(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 = !{!"any pointer", !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"

@.str = external hidden unnamed_addr constant [153 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [52 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [54 x i8], align 1

; Function Attrs: nounwind uwtable
define dso_local noundef ptr @MmioReadBuffer8(i64 noundef %0, i64 noundef %1, ptr noundef returned %2) local_unnamed_addr #0 {
  %4 = tail call zeroext i8 @DebugAssertEnabled() #2
  %.not = icmp ne i8 %4, 0
  %5 = sub i64 0, %1
  %.not10 = icmp ult i64 %5, %0
  %or.cond = and i1 %.not10, %.not
  br i1 %or.cond, label %6, label %7

6:                                                ; preds = %3
  tail call void @DebugAssert(ptr noundef nonnull @.str, i64 noundef 45, ptr noundef nonnull @.str.1) #2
  br label %7

7:                                                ; preds = %3, %6
  %8 = tail call zeroext i8 @DebugAssertEnabled() #2
  %.not11 = icmp ne i8 %8, 0
  %9 = ptrtoint ptr %2 to i64
  %.not12 = icmp ult i64 %5, %9
  %or.cond15 = and i1 %.not12, %.not11
  br i1 %or.cond15, label %10, label %11

10:                                               ; preds = %7
  tail call void @DebugAssert(ptr noundef nonnull @.str, i64 noundef 46, ptr noundef nonnull @.str.2) #2
  br label %11

11:                                               ; preds = %10, %7
  %.not1316 = icmp eq i64 %1, 0
  br i1 %.not1316, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %11, %.lr.ph
  %.019 = phi i64 [ %13, %.lr.ph ], [ %0, %11 ]
  %.0818 = phi ptr [ %15, %.lr.ph ], [ %2, %11 ]
  %.0917 = phi i64 [ %12, %.lr.ph ], [ %1, %11 ]
  %12 = add i64 %.0917, -1
  %13 = add i64 %.019, 1
  %14 = tail call zeroext i8 @MmioRead8(i64 noundef %.019) #2
  %15 = getelementptr inbounds i8, ptr %.0818, i64 1
  store i8 %14, ptr %.0818, align 1, !tbaa !5
  %.not13 = icmp eq i64 %12, 0
  br i1 %.not13, label %._crit_edge, label %.lr.ph, !llvm.loop !8

._crit_edge:                                      ; preds = %.lr.ph, %11
  ret ptr %2
}

declare zeroext i8 @DebugAssertEnabled() local_unnamed_addr #1

declare void @DebugAssert(ptr noundef, i64 noundef, ptr noundef) local_unnamed_addr #1

declare zeroext i8 @MmioRead8(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 = !{!6, !6, i64 0}
!6 = !{!"omnipotent char", !7, i64 0}
!7 = !{!"Simple C/C++ TBAA"}
!8 = distinct !{!8, !9}
!9 = !{!"llvm.loop.mustprogress"}


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