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

; 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
@.str.9 = external hidden unnamed_addr constant [44 x i8], align 1
@.str.10 = external hidden unnamed_addr constant [38 x i8], align 1
@.str.11 = external hidden unnamed_addr constant [46 x i8], align 1

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

declare zeroext i8 @DebugAssertEnabled() #1

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

; 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 ptr @MmioReadBuffer64(i64 noundef %0, i64 noundef %1, ptr noundef %2) #2 {
  %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 %17

11:                                               ; preds = %8
  %12 = load i64, ptr %4, align 8, !tbaa !5
  %13 = and i64 %12, 7
  %14 = icmp eq i64 %13, 0
  br i1 %14, label %16, label %15

15:                                               ; preds = %11
  call void @DebugAssert(ptr noundef @.str, i64 noundef 191, ptr noundef @.str.9)
  br label %16

16:                                               ; preds = %15, %11
  br label %17

17:                                               ; preds = %16, %8
  br label %18

18:                                               ; preds = %17
  br label %19

19:                                               ; preds = %18
  br label %20

20:                                               ; preds = %19
  %21 = call zeroext i8 @DebugAssertEnabled()
  %22 = icmp ne i8 %21, 0
  br i1 %22, label %23, label %31

23:                                               ; preds = %20
  %24 = load i64, ptr %5, align 8, !tbaa !5
  %25 = sub i64 %24, 1
  %26 = load i64, ptr %4, align 8, !tbaa !5
  %27 = sub i64 -1, %26
  %28 = icmp ule i64 %25, %27
  br i1 %28, label %30, label %29

29:                                               ; preds = %23
  call void @DebugAssert(ptr noundef @.str, i64 noundef 193, ptr noundef @.str.1)
  br label %30

30:                                               ; preds = %29, %23
  br label %31

31:                                               ; preds = %30, %20
  br label %32

32:                                               ; preds = %31
  br label %33

33:                                               ; preds = %32
  br label %34

34:                                               ; preds = %33
  %35 = call zeroext i8 @DebugAssertEnabled()
  %36 = icmp ne i8 %35, 0
  br i1 %36, label %37, label %46

37:                                               ; preds = %34
  %38 = load i64, ptr %5, align 8, !tbaa !5
  %39 = sub i64 %38, 1
  %40 = load ptr, ptr %6, align 8, !tbaa !9
  %41 = ptrtoint ptr %40 to i64
  %42 = sub i64 -1, %41
  %43 = icmp ule i64 %39, %42
  br i1 %43, label %45, label %44

44:                                               ; preds = %37
  call void @DebugAssert(ptr noundef @.str, i64 noundef 194, ptr noundef @.str.2)
  br label %45

45:                                               ; preds = %44, %37
  br label %46

46:                                               ; preds = %45, %34
  br label %47

47:                                               ; preds = %46
  br label %48

48:                                               ; preds = %47
  br label %49

49:                                               ; preds = %48
  %50 = call zeroext i8 @DebugAssertEnabled()
  %51 = icmp ne i8 %50, 0
  br i1 %51, label %52, label %58

52:                                               ; preds = %49
  %53 = load i64, ptr %5, align 8, !tbaa !5
  %54 = and i64 %53, 7
  %55 = icmp eq i64 %54, 0
  br i1 %55, label %57, label %56

56:                                               ; preds = %52
  call void @DebugAssert(ptr noundef @.str, i64 noundef 196, ptr noundef @.str.10)
  br label %57

57:                                               ; preds = %56, %52
  br label %58

58:                                               ; preds = %57, %49
  br label %59

59:                                               ; preds = %58
  br label %60

60:                                               ; preds = %59
  br label %61

61:                                               ; preds = %60
  %62 = call zeroext i8 @DebugAssertEnabled()
  %63 = icmp ne i8 %62, 0
  br i1 %63, label %64, label %71

64:                                               ; preds = %61
  %65 = load ptr, ptr %6, align 8, !tbaa !9
  %66 = ptrtoint ptr %65 to i64
  %67 = and i64 %66, 7
  %68 = icmp eq i64 %67, 0
  br i1 %68, label %70, label %69

69:                                               ; preds = %64
  call void @DebugAssert(ptr noundef @.str, i64 noundef 197, ptr noundef @.str.11)
  br label %70

70:                                               ; preds = %69, %64
  br label %71

71:                                               ; preds = %70, %61
  br label %72

72:                                               ; preds = %71
  br label %73

73:                                               ; preds = %72
  %74 = load ptr, ptr %6, align 8, !tbaa !9
  store ptr %74, ptr %7, align 8, !tbaa !9
  br label %75

75:                                               ; preds = %78, %73
  %76 = load i64, ptr %5, align 8, !tbaa !5
  %77 = icmp ne i64 %76, 0
  br i1 %77, label %78, label %87

78:                                               ; preds = %75
  %79 = load i64, ptr %4, align 8, !tbaa !5
  %80 = call i64 @MmioRead64(i64 noundef %79)
  %81 = load ptr, ptr %6, align 8, !tbaa !9
  %82 = getelementptr inbounds i64, ptr %81, i32 1
  store ptr %82, ptr %6, align 8, !tbaa !9
  store i64 %80, ptr %81, align 8, !tbaa !5
  %83 = load i64, ptr %4, align 8, !tbaa !5
  %84 = add i64 %83, 8
  store i64 %84, ptr %4, align 8, !tbaa !5
  %85 = load i64, ptr %5, align 8, !tbaa !5
  %86 = sub i64 %85, 8
  store i64 %86, ptr %5, align 8, !tbaa !5
  br label %75, !llvm.loop !11

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

declare i64 @MmioRead64(i64 noundef) #1

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 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 #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 = distinct !{!11, !12}
!12 = !{!"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
@.str.9 = external hidden unnamed_addr constant [44 x i8], align 1
@.str.10 = external hidden unnamed_addr constant [38 x i8], align 1
@.str.11 = external hidden unnamed_addr constant [46 x i8], align 1

declare zeroext i8 @DebugAssertEnabled() local_unnamed_addr #0

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

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

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

8:                                                ; preds = %3, %7
  %9 = tail call zeroext i8 @DebugAssertEnabled() #2
  %.not15 = icmp ne i8 %9, 0
  %10 = sub i64 0, %1
  %.not16 = icmp ult i64 %10, %0
  %or.cond23 = and i1 %.not16, %.not15
  br i1 %or.cond23, label %11, label %12

11:                                               ; preds = %8
  tail call void @DebugAssert(ptr noundef nonnull @.str, i64 noundef 193, ptr noundef nonnull @.str.1) #2
  br label %12

12:                                               ; preds = %8, %11
  %13 = tail call zeroext i8 @DebugAssertEnabled() #2
  %.not17 = icmp ne i8 %13, 0
  %14 = ptrtoint ptr %2 to i64
  %.not18 = icmp ult i64 %10, %14
  %or.cond25 = and i1 %.not18, %.not17
  br i1 %or.cond25, label %15, label %16

15:                                               ; preds = %12
  tail call void @DebugAssert(ptr noundef nonnull @.str, i64 noundef 194, ptr noundef nonnull @.str.2) #2
  br label %16

16:                                               ; preds = %12, %15
  %17 = tail call zeroext i8 @DebugAssertEnabled() #2
  %.not19 = icmp eq i8 %17, 0
  %18 = and i64 %1, 7
  %19 = icmp eq i64 %18, 0
  %or.cond27 = or i1 %19, %.not19
  br i1 %or.cond27, label %21, label %20

20:                                               ; preds = %16
  tail call void @DebugAssert(ptr noundef nonnull @.str, i64 noundef 196, ptr noundef nonnull @.str.10) #2
  br label %21

21:                                               ; preds = %16, %20
  %22 = tail call zeroext i8 @DebugAssertEnabled() #2
  %.not20 = icmp eq i8 %22, 0
  %23 = and i64 %14, 7
  %24 = icmp eq i64 %23, 0
  %or.cond30 = or i1 %24, %.not20
  br i1 %or.cond30, label %26, label %25

25:                                               ; preds = %21
  tail call void @DebugAssert(ptr noundef nonnull @.str, i64 noundef 197, ptr noundef nonnull @.str.11) #2
  br label %26

26:                                               ; preds = %25, %21
  %.not2131 = icmp eq i64 %1, 0
  br i1 %.not2131, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %26, %.lr.ph
  %.034 = phi i64 [ %29, %.lr.ph ], [ %0, %26 ]
  %.01333 = phi ptr [ %28, %.lr.ph ], [ %2, %26 ]
  %.01432 = phi i64 [ %30, %.lr.ph ], [ %1, %26 ]
  %27 = tail call i64 @MmioRead64(i64 noundef %.034) #2
  %28 = getelementptr inbounds i8, ptr %.01333, i64 8
  store i64 %27, ptr %.01333, align 8, !tbaa !5
  %29 = add i64 %.034, 8
  %30 = add i64 %.01432, -8
  %.not21 = icmp eq i64 %30, 0
  br i1 %.not21, label %._crit_edge, label %.lr.ph, !llvm.loop !9

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

declare i64 @MmioRead64(i64 noundef) local_unnamed_addr #0

attributes #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 = { 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 = !{!"long long", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}


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