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

; 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 [23 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [44 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [53 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [37 x i8], align 1

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

10:                                               ; preds = %3
  store ptr null, ptr %4, align 8
  br label %64

11:                                               ; preds = %3
  br label %12

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

15:                                               ; preds = %12
  %16 = load ptr, ptr %5, align 8, !tbaa !5
  %17 = icmp ne ptr %16, null
  br i1 %17, label %19, label %18

18:                                               ; preds = %15
  call void @DebugAssert(ptr noundef @.str, i64 noundef 61, ptr noundef @.str.1)
  br label %19

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

20:                                               ; preds = %19, %12
  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 %32

25:                                               ; preds = %22
  %26 = load ptr, ptr %5, align 8, !tbaa !5
  %27 = ptrtoint ptr %26 to i64
  %28 = and i64 %27, 1
  %29 = icmp eq i64 %28, 0
  br i1 %29, label %31, label %30

30:                                               ; preds = %25
  call void @DebugAssert(ptr noundef @.str, i64 noundef 62, ptr noundef @.str.2)
  br label %31

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

32:                                               ; preds = %31, %22
  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 %6, align 8, !tbaa !9
  %39 = sub i64 %38, 1
  %40 = load ptr, ptr %5, align 8, !tbaa !5
  %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 63, ptr noundef @.str.3)
  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
  %49 = call zeroext i8 @DebugAssertEnabled()
  %50 = icmp ne i8 %49, 0
  br i1 %50, label %51, label %57

51:                                               ; preds = %48
  %52 = load i64, ptr %6, align 8, !tbaa !9
  %53 = and i64 %52, 1
  %54 = icmp eq i64 %53, 0
  br i1 %54, label %56, label %55

55:                                               ; preds = %51
  call void @DebugAssert(ptr noundef @.str, i64 noundef 64, ptr noundef @.str.4)
  br label %56

56:                                               ; preds = %55, %51
  br label %57

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

58:                                               ; preds = %57
  %59 = load ptr, ptr %5, align 8, !tbaa !5
  %60 = load i64, ptr %6, align 8, !tbaa !9
  %61 = udiv i64 %60, 2
  %62 = load i16, ptr %7, align 2, !tbaa !11
  %63 = call ptr @InternalMemScanMem16(ptr noundef %59, i64 noundef %61, i16 noundef zeroext %62)
  store ptr %63, ptr %4, align 8
  br label %64

64:                                               ; preds = %58, %10
  %65 = load ptr, ptr %4, align 8
  ret ptr %65
}

declare zeroext i8 @DebugAssertEnabled() #1

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

declare ptr @InternalMemScanMem16(ptr noundef, i64 noundef, i16 noundef zeroext) #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}
!11 = !{!12, !12, i64 0}
!12 = !{!"short", !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 [153 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [23 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [44 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [53 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [37 x i8], align 1

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

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

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

10:                                               ; preds = %9, %5
  %11 = tail call zeroext i8 @DebugAssertEnabled() #2
  %.not = icmp eq i8 %11, 0
  %12 = ptrtoint ptr %0 to i64
  %13 = and i64 %12, 1
  %14 = icmp eq i64 %13, 0
  %or.cond16 = or i1 %14, %.not
  br i1 %or.cond16, label %16, label %15

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

16:                                               ; preds = %15, %10
  %17 = tail call zeroext i8 @DebugAssertEnabled() #2
  %.not11 = icmp ne i8 %17, 0
  %18 = sub i64 0, %1
  %.not12 = icmp ult i64 %18, %12
  %or.cond18 = and i1 %.not12, %.not11
  br i1 %or.cond18, label %19, label %20

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

20:                                               ; preds = %19, %16
  %21 = tail call zeroext i8 @DebugAssertEnabled() #2
  %.not13 = icmp eq i8 %21, 0
  %22 = and i64 %1, 1
  %23 = icmp eq i64 %22, 0
  %or.cond20 = or i1 %23, %.not13
  br i1 %or.cond20, label %25, label %24

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

25:                                               ; preds = %20, %24
  %26 = lshr i64 %1, 1
  %27 = tail call ptr @InternalMemScanMem16(ptr noundef %0, i64 noundef %26, i16 noundef zeroext %2) #2
  br label %28

28:                                               ; preds = %3, %25
  %.0 = phi ptr [ %27, %25 ], [ null, %3 ]
  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 @InternalMemScanMem16(ptr noundef, i64 noundef, i16 noundef zeroext) 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