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

; 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 [147 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [64 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [59 x i8], align 1

; Function Attrs: nounwind uwtable
define dso_local ptr @CopyMem(ptr noundef %0, ptr noundef %1, i64 noundef %2) #0 {
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca i64, align 8
  store ptr %0, ptr %5, align 8, !tbaa !5
  store ptr %1, ptr %6, align 8, !tbaa !5
  store i64 %2, ptr %7, align 8, !tbaa !9
  %8 = load i64, ptr %7, align 8, !tbaa !9
  %9 = icmp eq i64 %8, 0
  br i1 %9, label %10, label %12

10:                                               ; preds = %3
  %11 = load ptr, ptr %5, align 8, !tbaa !5
  store ptr %11, ptr %4, align 8
  br label %51

12:                                               ; preds = %3
  br label %13

13:                                               ; preds = %12
  %14 = call zeroext i8 @DebugAssertEnabled()
  %15 = icmp ne i8 %14, 0
  br i1 %15, label %16, label %25

16:                                               ; preds = %13
  %17 = load i64, ptr %7, align 8, !tbaa !9
  %18 = sub i64 %17, 1
  %19 = load ptr, ptr %5, align 8, !tbaa !5
  %20 = ptrtoint ptr %19 to i64
  %21 = sub i64 -1, %20
  %22 = icmp ule i64 %18, %21
  br i1 %22, label %24, label %23

23:                                               ; preds = %16
  call void @DebugAssert(ptr noundef @.str, i64 noundef 56, ptr noundef @.str.1)
  br label %24

24:                                               ; preds = %23, %16
  br label %25

25:                                               ; preds = %24, %13
  br label %26

26:                                               ; preds = %25
  br label %27

27:                                               ; preds = %26
  %28 = call zeroext i8 @DebugAssertEnabled()
  %29 = icmp ne i8 %28, 0
  br i1 %29, label %30, label %39

30:                                               ; preds = %27
  %31 = load i64, ptr %7, align 8, !tbaa !9
  %32 = sub i64 %31, 1
  %33 = load ptr, ptr %6, align 8, !tbaa !5
  %34 = ptrtoint ptr %33 to i64
  %35 = sub i64 -1, %34
  %36 = icmp ule i64 %32, %35
  br i1 %36, label %38, label %37

37:                                               ; preds = %30
  call void @DebugAssert(ptr noundef @.str, i64 noundef 57, ptr noundef @.str.2)
  br label %38

38:                                               ; preds = %37, %30
  br label %39

39:                                               ; preds = %38, %27
  br label %40

40:                                               ; preds = %39
  %41 = load ptr, ptr %5, align 8, !tbaa !5
  %42 = load ptr, ptr %6, align 8, !tbaa !5
  %43 = icmp eq ptr %41, %42
  br i1 %43, label %44, label %46

44:                                               ; preds = %40
  %45 = load ptr, ptr %5, align 8, !tbaa !5
  store ptr %45, ptr %4, align 8
  br label %51

46:                                               ; preds = %40
  %47 = load ptr, ptr %5, align 8, !tbaa !5
  %48 = load ptr, ptr %6, align 8, !tbaa !5
  %49 = load i64, ptr %7, align 8, !tbaa !9
  %50 = call ptr @InternalMemCopyMem(ptr noundef %47, ptr noundef %48, i64 noundef %49)
  store ptr %50, ptr %4, align 8
  br label %51

51:                                               ; preds = %46, %44, %10
  %52 = load ptr, ptr %4, align 8
  ret ptr %52
}

declare zeroext i8 @DebugAssertEnabled() #1

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

declare ptr @InternalMemCopyMem(ptr noundef, ptr noundef, i64 noundef) #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" }

!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 = !{!"long long", !7, i64 0}


; 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 [147 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [64 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [59 x i8], align 1

; Function Attrs: nounwind uwtable
define dso_local ptr @CopyMem(ptr noundef %0, ptr noundef %1, i64 noundef %2) local_unnamed_addr #0 {
  %4 = icmp eq i64 %2, 0
  br i1 %4, label %18, label %5

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

9:                                                ; preds = %5
  tail call void @DebugAssert(ptr noundef nonnull @.str, i64 noundef 56, ptr noundef nonnull @.str.1) #2
  br label %10

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

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

14:                                               ; preds = %10, %13
  %15 = icmp eq ptr %0, %1
  br i1 %15, label %18, label %16

16:                                               ; preds = %14
  %17 = tail call ptr @InternalMemCopyMem(ptr noundef %0, ptr noundef %1, i64 noundef %2) #2
  br label %18

18:                                               ; preds = %14, %3, %16
  %.0 = phi ptr [ %17, %16 ], [ %0, %3 ], [ %0, %14 ]
  ret ptr %.0
}

declare zeroext i8 @DebugAssertEnabled() local_unnamed_addr #1

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

declare ptr @InternalMemCopyMem(ptr noundef, ptr noundef, 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)"}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,IPSCCPPass,InstCombinePass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass