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

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

; Function Attrs: nounwind uwtable
define dso_local i64 @CompareMem(ptr noundef %0, ptr noundef %1, i64 noundef %2) #0 {
  %4 = alloca i64, 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 %14, label %10

10:                                               ; preds = %3
  %11 = load ptr, ptr %5, align 8, !tbaa !5
  %12 = load ptr, ptr %6, align 8, !tbaa !5
  %13 = icmp eq ptr %11, %12
  br i1 %13, label %14, label %15

14:                                               ; preds = %10, %3
  store i64 0, ptr %4, align 8
  br label %68

15:                                               ; preds = %10
  br label %16

16:                                               ; preds = %15
  %17 = call zeroext i8 @DebugAssertEnabled()
  %18 = icmp ne i8 %17, 0
  br i1 %18, label %19, label %24

19:                                               ; preds = %16
  %20 = load ptr, ptr %5, align 8, !tbaa !5
  %21 = icmp ne ptr %20, null
  br i1 %21, label %23, label %22

22:                                               ; preds = %19
  call void @DebugAssert(ptr noundef @.str, i64 noundef 60, ptr noundef @.str.1)
  br label %23

23:                                               ; preds = %22, %19
  br label %24

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

25:                                               ; preds = %24
  br label %26

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

29:                                               ; preds = %26
  %30 = load ptr, ptr %6, align 8, !tbaa !5
  %31 = icmp ne ptr %30, null
  br i1 %31, label %33, label %32

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

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

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

35:                                               ; preds = %34
  br label %36

36:                                               ; preds = %35
  %37 = call zeroext i8 @DebugAssertEnabled()
  %38 = icmp ne i8 %37, 0
  br i1 %38, label %39, label %48

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

46:                                               ; preds = %39
  call void @DebugAssert(ptr noundef @.str, i64 noundef 62, ptr noundef @.str.3)
  br label %47

47:                                               ; preds = %46, %39
  br label %48

48:                                               ; preds = %47, %36
  br label %49

49:                                               ; preds = %48
  br label %50

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

53:                                               ; preds = %50
  %54 = load i64, ptr %7, align 8, !tbaa !9
  %55 = sub i64 %54, 1
  %56 = load ptr, ptr %6, align 8, !tbaa !5
  %57 = ptrtoint ptr %56 to i64
  %58 = sub i64 -1, %57
  %59 = icmp ule i64 %55, %58
  br i1 %59, label %61, label %60

60:                                               ; preds = %53
  call void @DebugAssert(ptr noundef @.str, i64 noundef 63, ptr noundef @.str.4)
  br label %61

61:                                               ; preds = %60, %53
  br label %62

62:                                               ; preds = %61, %50
  br label %63

63:                                               ; preds = %62
  %64 = load ptr, ptr %5, align 8, !tbaa !5
  %65 = load ptr, ptr %6, align 8, !tbaa !5
  %66 = load i64, ptr %7, align 8, !tbaa !9
  %67 = call i64 @InternalMemCompareMem(ptr noundef %64, ptr noundef %65, i64 noundef %66)
  store i64 %67, ptr %4, align 8
  br label %68

68:                                               ; preds = %63, %14
  %69 = load i64, ptr %4, align 8
  ret i64 %69
}

declare zeroext i8 @DebugAssertEnabled() #1

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

declare i64 @InternalMemCompareMem(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 [150 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [34 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [29 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [64 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [59 x i8], align 1

; Function Attrs: nounwind uwtable
define dso_local i64 @CompareMem(ptr noundef %0, ptr noundef %1, i64 noundef %2) local_unnamed_addr #0 {
  %4 = icmp eq i64 %2, 0
  %5 = icmp eq ptr %0, %1
  %or.cond21 = or i1 %5, %4
  br i1 %or.cond21, label %27, label %6

6:                                                ; preds = %3
  %7 = tail call zeroext i8 @DebugAssertEnabled() #2
  %8 = icmp eq i8 %7, 0
  %9 = icmp ne ptr %0, null
  %or.cond = or i1 %9, %8
  br i1 %or.cond, label %11, label %10

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

11:                                               ; preds = %10, %6
  %12 = tail call zeroext i8 @DebugAssertEnabled() #2
  %13 = icmp eq i8 %12, 0
  %14 = icmp ne ptr %1, null
  %or.cond3 = or i1 %14, %13
  br i1 %or.cond3, label %16, label %15

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

16:                                               ; preds = %15, %11
  %17 = tail call zeroext i8 @DebugAssertEnabled() #2
  %.not = icmp ne i8 %17, 0
  %18 = ptrtoint ptr %0 to i64
  %19 = sub i64 0, %2
  %.not18 = icmp ult i64 %19, %18
  %or.cond23 = and i1 %.not18, %.not
  br i1 %or.cond23, label %20, label %21

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

21:                                               ; preds = %20, %16
  %22 = tail call zeroext i8 @DebugAssertEnabled() #2
  %.not19 = icmp ne i8 %22, 0
  %23 = ptrtoint ptr %1 to i64
  %.not20 = icmp ult i64 %19, %23
  %or.cond25 = and i1 %.not20, %.not19
  br i1 %or.cond25, label %24, label %25

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

25:                                               ; preds = %21, %24
  %26 = tail call i64 @InternalMemCompareMem(ptr noundef %0, ptr noundef %1, i64 noundef %2) #2
  br label %27

27:                                               ; preds = %3, %25
  %.0 = phi i64 [ %26, %25 ], [ 0, %3 ]
  ret i64 %.0
}

declare zeroext i8 @DebugAssertEnabled() local_unnamed_addr #1

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

declare i64 @InternalMemCompareMem(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