; LLVM IR from thalium/icebox :: third_party/virtualbox/src/VBox/Devices/EFI/Firmware/IntelFrameworkModulePkg (Undi16GetMCastFilters)

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

%struct.EFI_SIMPLE_NETWORK_MODE = type { i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, [16 x %struct.EFI_MAC_ADDRESS], %struct.EFI_MAC_ADDRESS, %struct.EFI_MAC_ADDRESS, %struct.EFI_MAC_ADDRESS, i8, i8, i8, i8, i8 }
%struct.EFI_MAC_ADDRESS = type { [32 x i8] }
%struct.PXENV_UNDI_MCAST_ADDR_T = type { i16, [8 x [16 x i8]] }

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

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

declare ptr @ZeroMem(ptr noundef, i64 noundef) #1

declare ptr @CopyMem(ptr noundef, ptr noundef, i64 noundef) #1

; Function Attrs: nounwind uwtable
define dso_local void @Undi16GetMCastFilters(ptr noundef %0, ptr noundef %1, i64 noundef %2) #2 {
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca i64, align 8
  %7 = alloca i64, align 8
  store ptr %0, ptr %4, align 8, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !5
  store i64 %2, ptr %6, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #3
  %8 = load ptr, ptr %4, align 8, !tbaa !5
  %9 = getelementptr inbounds %struct.EFI_SIMPLE_NETWORK_MODE, ptr %8, i32 0, i32 9
  %10 = load i32, ptr %9, align 4, !tbaa !11
  %11 = trunc i32 %10 to i16
  %12 = load ptr, ptr %5, align 8, !tbaa !5
  %13 = getelementptr inbounds %struct.PXENV_UNDI_MCAST_ADDR_T, ptr %12, i32 0, i32 0
  store i16 %11, ptr %13, align 1, !tbaa !15
  store i64 0, ptr %7, align 8, !tbaa !9
  br label %14

14:                                               ; preds = %43, %3
  %15 = load i64, ptr %7, align 8, !tbaa !9
  %16 = icmp ult i64 %15, 8
  br i1 %16, label %17, label %46

17:                                               ; preds = %14
  %18 = load i64, ptr %7, align 8, !tbaa !9
  %19 = load ptr, ptr %5, align 8, !tbaa !5
  %20 = getelementptr inbounds %struct.PXENV_UNDI_MCAST_ADDR_T, ptr %19, i32 0, i32 0
  %21 = load i16, ptr %20, align 1, !tbaa !15
  %22 = zext i16 %21 to i64
  %23 = icmp ult i64 %18, %22
  br i1 %23, label %24, label %35

24:                                               ; preds = %17
  %25 = load ptr, ptr %5, align 8, !tbaa !5
  %26 = getelementptr inbounds %struct.PXENV_UNDI_MCAST_ADDR_T, ptr %25, i32 0, i32 1
  %27 = load i64, ptr %7, align 8, !tbaa !9
  %28 = getelementptr inbounds [8 x [16 x i8]], ptr %26, i64 0, i64 %27
  %29 = load ptr, ptr %4, align 8, !tbaa !5
  %30 = getelementptr inbounds %struct.EFI_SIMPLE_NETWORK_MODE, ptr %29, i32 0, i32 10
  %31 = load i64, ptr %7, align 8, !tbaa !9
  %32 = getelementptr inbounds [16 x %struct.EFI_MAC_ADDRESS], ptr %30, i64 0, i64 %31
  %33 = load i64, ptr %6, align 8, !tbaa !9
  %34 = call ptr @CopyMem(ptr noundef %28, ptr noundef %32, i64 noundef %33)
  br label %42

35:                                               ; preds = %17
  %36 = load ptr, ptr %5, align 8, !tbaa !5
  %37 = getelementptr inbounds %struct.PXENV_UNDI_MCAST_ADDR_T, ptr %36, i32 0, i32 1
  %38 = load i64, ptr %7, align 8, !tbaa !9
  %39 = getelementptr inbounds [8 x [16 x i8]], ptr %37, i64 0, i64 %38
  %40 = load i64, ptr %6, align 8, !tbaa !9
  %41 = call ptr @ZeroMem(ptr noundef %39, i64 noundef %40)
  br label %42

42:                                               ; preds = %35, %24
  br label %43

43:                                               ; preds = %42
  %44 = load i64, ptr %7, align 8, !tbaa !9
  %45 = add i64 %44, 1
  store i64 %45, ptr %7, align 8, !tbaa !9
  br label %14, !llvm.loop !18

46:                                               ; preds = %14
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #3
  ret void
}

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 = !{!"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, !13, i64 36}
!12 = !{!"", !13, i64 0, !13, i64 4, !13, i64 8, !13, i64 12, !13, i64 16, !13, i64 20, !13, i64 24, !13, i64 28, !13, i64 32, !13, i64 36, !7, i64 40, !14, i64 552, !14, i64 584, !14, i64 616, !7, i64 648, !7, i64 649, !7, i64 650, !7, i64 651, !7, i64 652}
!13 = !{!"int", !7, i64 0}
!14 = !{!"", !7, i64 0}
!15 = !{!16, !17, i64 0}
!16 = !{!"", !17, i64 0, !7, i64 2}
!17 = !{!"short", !7, i64 0}
!18 = distinct !{!18, !19}
!19 = !{!"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"

declare ptr @ZeroMem(ptr noundef, i64 noundef) local_unnamed_addr #0

declare ptr @CopyMem(ptr noundef, ptr noundef, i64 noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local void @Undi16GetMCastFilters(ptr noundef %0, ptr noundef %1, i64 noundef %2) local_unnamed_addr #1 {
  %4 = getelementptr inbounds i8, ptr %0, i64 36
  %5 = load i32, ptr %4, align 4, !tbaa !5
  %6 = trunc i32 %5 to i16
  store i16 %6, ptr %1, align 1, !tbaa !11
  %7 = getelementptr inbounds i8, ptr %1, i64 2
  %.mask = and i32 %5, 65535
  %.not = icmp eq i32 %.mask, 0
  br i1 %.not, label %11, label %8

8:                                                ; preds = %3
  %9 = getelementptr inbounds i8, ptr %0, i64 40
  %10 = tail call ptr @CopyMem(ptr noundef nonnull %7, ptr noundef nonnull %9, i64 noundef %2) #2
  br label %13

11:                                               ; preds = %3
  %12 = tail call ptr @ZeroMem(ptr noundef nonnull %7, i64 noundef %2) #2
  br label %13

13:                                               ; preds = %8, %11
  %14 = load i16, ptr %1, align 1, !tbaa !11
  %15 = icmp ugt i16 %14, 1
  %16 = getelementptr inbounds i8, ptr %1, i64 18
  br i1 %15, label %19, label %17

17:                                               ; preds = %13
  %18 = tail call ptr @ZeroMem(ptr noundef nonnull %16, i64 noundef %2) #2
  br label %22

19:                                               ; preds = %13
  %20 = getelementptr inbounds i8, ptr %0, i64 72
  %21 = tail call ptr @CopyMem(ptr noundef nonnull %16, ptr noundef nonnull %20, i64 noundef %2) #2
  br label %22

22:                                               ; preds = %19, %17
  %23 = load i16, ptr %1, align 1, !tbaa !11
  %24 = icmp ugt i16 %23, 2
  %25 = getelementptr inbounds i8, ptr %1, i64 34
  br i1 %24, label %28, label %26

26:                                               ; preds = %22
  %27 = tail call ptr @ZeroMem(ptr noundef nonnull %25, i64 noundef %2) #2
  br label %31

28:                                               ; preds = %22
  %29 = getelementptr inbounds i8, ptr %0, i64 104
  %30 = tail call ptr @CopyMem(ptr noundef nonnull %25, ptr noundef nonnull %29, i64 noundef %2) #2
  br label %31

31:                                               ; preds = %28, %26
  %32 = load i16, ptr %1, align 1, !tbaa !11
  %33 = icmp ugt i16 %32, 3
  %34 = getelementptr inbounds i8, ptr %1, i64 50
  br i1 %33, label %37, label %35

35:                                               ; preds = %31
  %36 = tail call ptr @ZeroMem(ptr noundef nonnull %34, i64 noundef %2) #2
  br label %40

37:                                               ; preds = %31
  %38 = getelementptr inbounds i8, ptr %0, i64 136
  %39 = tail call ptr @CopyMem(ptr noundef nonnull %34, ptr noundef nonnull %38, i64 noundef %2) #2
  br label %40

40:                                               ; preds = %37, %35
  %41 = load i16, ptr %1, align 1, !tbaa !11
  %42 = icmp ugt i16 %41, 4
  %43 = getelementptr inbounds i8, ptr %1, i64 66
  br i1 %42, label %46, label %44

44:                                               ; preds = %40
  %45 = tail call ptr @ZeroMem(ptr noundef nonnull %43, i64 noundef %2) #2
  br label %49

46:                                               ; preds = %40
  %47 = getelementptr inbounds i8, ptr %0, i64 168
  %48 = tail call ptr @CopyMem(ptr noundef nonnull %43, ptr noundef nonnull %47, i64 noundef %2) #2
  br label %49

49:                                               ; preds = %46, %44
  %50 = load i16, ptr %1, align 1, !tbaa !11
  %51 = icmp ugt i16 %50, 5
  %52 = getelementptr inbounds i8, ptr %1, i64 82
  br i1 %51, label %55, label %53

53:                                               ; preds = %49
  %54 = tail call ptr @ZeroMem(ptr noundef nonnull %52, i64 noundef %2) #2
  br label %58

55:                                               ; preds = %49
  %56 = getelementptr inbounds i8, ptr %0, i64 200
  %57 = tail call ptr @CopyMem(ptr noundef nonnull %52, ptr noundef nonnull %56, i64 noundef %2) #2
  br label %58

58:                                               ; preds = %55, %53
  %59 = load i16, ptr %1, align 1, !tbaa !11
  %60 = icmp ugt i16 %59, 6
  %61 = getelementptr inbounds i8, ptr %1, i64 98
  br i1 %60, label %64, label %62

62:                                               ; preds = %58
  %63 = tail call ptr @ZeroMem(ptr noundef nonnull %61, i64 noundef %2) #2
  br label %67

64:                                               ; preds = %58
  %65 = getelementptr inbounds i8, ptr %0, i64 232
  %66 = tail call ptr @CopyMem(ptr noundef nonnull %61, ptr noundef nonnull %65, i64 noundef %2) #2
  br label %67

67:                                               ; preds = %64, %62
  %68 = load i16, ptr %1, align 1, !tbaa !11
  %69 = icmp ugt i16 %68, 7
  %70 = getelementptr inbounds i8, ptr %1, i64 114
  br i1 %69, label %73, label %71

71:                                               ; preds = %67
  %72 = tail call ptr @ZeroMem(ptr noundef nonnull %70, i64 noundef %2) #2
  br label %76

73:                                               ; preds = %67
  %74 = getelementptr inbounds i8, ptr %0, i64 264
  %75 = tail call ptr @CopyMem(ptr noundef nonnull %70, ptr noundef nonnull %74, i64 noundef %2) #2
  br label %76

76:                                               ; preds = %73, %71
  ret void
}

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, !7, i64 36}
!6 = !{!"", !7, i64 0, !7, i64 4, !7, i64 8, !7, i64 12, !7, i64 16, !7, i64 20, !7, i64 24, !7, i64 28, !7, i64 32, !7, i64 36, !8, i64 40, !10, i64 552, !10, i64 584, !10, i64 616, !8, i64 648, !8, i64 649, !8, i64 650, !8, i64 651, !8, i64 652}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"", !8, i64 0}
!11 = !{!12, !13, i64 0}
!12 = !{!"", !13, i64 0, !8, i64 2}
!13 = !{!"short", !8, i64 0}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,LICMPass,LoopRotatePass,SROAPass,SimplifyCFGPass,TailCallElimPass