; LLVM IR from thalium/icebox :: third_party/virtualbox/src/VBox/Devices/EFI/Firmware/OptionRomPkg/Bus/Usb (ReceiveFilters)

; 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_PROTOCOL = type { i64, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr }
%struct.EFI_MAC_ADDRESS = type { [32 x i8] }
%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 }

; Function Attrs: nounwind uwtable
declare dso_local i64 @ReceiveFilterUpdate(ptr noundef) #0

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

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

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

; Function Attrs: nounwind uwtable
define dso_local i64 @SN_ReceiveFilters(ptr noundef %0, i32 noundef %1, i32 noundef %2, i8 noundef zeroext %3, i64 noundef %4, ptr noundef %5) #0 {
  %7 = alloca ptr, align 8
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  %10 = alloca i8, align 1
  %11 = alloca i64, align 8
  %12 = alloca ptr, align 8
  %13 = alloca ptr, align 8
  %14 = alloca ptr, align 8
  %15 = alloca ptr, align 8
  %16 = alloca i64, align 8
  store ptr %0, ptr %7, align 8, !tbaa !5
  store i32 %1, ptr %8, align 4, !tbaa !9
  store i32 %2, ptr %9, align 4, !tbaa !9
  store i8 %3, ptr %10, align 1, !tbaa !11
  store i64 %4, ptr %11, align 8, !tbaa !12
  store ptr %5, ptr %12, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %13) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %14) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %15) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %16) #3
  store i64 -9223372036854775806, ptr %16, align 8, !tbaa !12
  %17 = load ptr, ptr %7, align 8, !tbaa !5
  %18 = icmp ne ptr null, %17
  br i1 %18, label %19, label %99

19:                                               ; preds = %6
  %20 = load ptr, ptr %7, align 8, !tbaa !5
  %21 = getelementptr inbounds %struct._EFI_SIMPLE_NETWORK_PROTOCOL, ptr %20, i32 0, i32 15
  %22 = load ptr, ptr %21, align 8, !tbaa !14
  %23 = icmp ne ptr null, %22
  br i1 %23, label %24, label %99

24:                                               ; preds = %19
  %25 = load ptr, ptr %7, align 8, !tbaa !5
  %26 = getelementptr inbounds %struct._EFI_SIMPLE_NETWORK_PROTOCOL, ptr %25, i32 0, i32 15
  %27 = load ptr, ptr %26, align 8, !tbaa !14
  store ptr %27, ptr %13, align 8, !tbaa !5
  %28 = load i8, ptr %10, align 1, !tbaa !11
  %29 = icmp ne i8 %28, 0
  br i1 %29, label %76, label %30

30:                                               ; preds = %24
  %31 = load i64, ptr %11, align 8, !tbaa !12
  %32 = icmp ne i64 0, %31
  br i1 %32, label %33, label %74

33:                                               ; preds = %30
  %34 = load i64, ptr %11, align 8, !tbaa !12
  %35 = icmp uge i64 16, %34
  br i1 %35, label %36, label %73

36:                                               ; preds = %33
  %37 = load ptr, ptr %12, align 8, !tbaa !5
  %38 = icmp ne ptr null, %37
  br i1 %38, label %39, label %73

39:                                               ; preds = %36
  %40 = load ptr, ptr %12, align 8, !tbaa !5
  store ptr %40, ptr %14, align 8, !tbaa !5
  %41 = load ptr, ptr %14, align 8, !tbaa !5
  %42 = load i64, ptr %11, align 8, !tbaa !12
  %43 = getelementptr inbounds %struct.EFI_MAC_ADDRESS, ptr %41, i64 %42
  store ptr %43, ptr %15, align 8, !tbaa !5
  br label %44

44:                                               ; preds = %57, %39
  %45 = load ptr, ptr %15, align 8, !tbaa !5
  %46 = load ptr, ptr %14, align 8, !tbaa !5
  %47 = icmp ugt ptr %45, %46
  br i1 %47, label %48, label %60

48:                                               ; preds = %44
  %49 = load ptr, ptr %14, align 8, !tbaa !5
  %50 = getelementptr inbounds %struct.EFI_MAC_ADDRESS, ptr %49, i32 0, i32 0
  %51 = getelementptr inbounds [32 x i8], ptr %50, i64 0, i64 0
  %52 = load i8, ptr %51, align 1, !tbaa !11
  %53 = zext i8 %52 to i32
  %54 = and i32 %53, 1
  %55 = icmp eq i32 0, %54
  br i1 %55, label %56, label %57

56:                                               ; preds = %48
  br label %60

57:                                               ; preds = %48
  %58 = load ptr, ptr %14, align 8, !tbaa !5
  %59 = getelementptr inbounds %struct.EFI_MAC_ADDRESS, ptr %58, i64 1
  store ptr %59, ptr %14, align 8, !tbaa !5
  br label %44, !llvm.loop !16

60:                                               ; preds = %56, %44
  %61 = load ptr, ptr %15, align 8, !tbaa !5
  %62 = load ptr, ptr %14, align 8, !tbaa !5
  %63 = icmp eq ptr %61, %62
  br i1 %63, label %64, label %72

64:                                               ; preds = %60
  %65 = load ptr, ptr %13, align 8, !tbaa !5
  %66 = getelementptr inbounds %struct.EFI_SIMPLE_NETWORK_MODE, ptr %65, i32 0, i32 10
  %67 = getelementptr inbounds [16 x %struct.EFI_MAC_ADDRESS], ptr %66, i64 0, i64 0
  %68 = load ptr, ptr %12, align 8, !tbaa !5
  %69 = load i64, ptr %11, align 8, !tbaa !12
  %70 = mul i64 %69, 32
  %71 = call ptr @CopyMem(ptr noundef %67, ptr noundef %68, i64 noundef %70)
  store i64 0, ptr %16, align 8, !tbaa !12
  br label %72

72:                                               ; preds = %64, %60
  br label %73

73:                                               ; preds = %72, %36, %33
  br label %75

74:                                               ; preds = %30
  store i64 0, ptr %16, align 8, !tbaa !12
  br label %75

75:                                               ; preds = %74, %73
  br label %77

76:                                               ; preds = %24
  store i64 0, ptr %11, align 8, !tbaa !12
  store i64 0, ptr %16, align 8, !tbaa !12
  br label %77

77:                                               ; preds = %76, %75
  %78 = load i64, ptr %16, align 8, !tbaa !12
  %79 = icmp slt i64 %78, 0
  br i1 %79, label %98, label %80

80:                                               ; preds = %77
  %81 = load i32, ptr %8, align 4, !tbaa !9
  %82 = load ptr, ptr %13, align 8, !tbaa !5
  %83 = getelementptr inbounds %struct.EFI_SIMPLE_NETWORK_MODE, ptr %82, i32 0, i32 7
  %84 = load i32, ptr %83, align 4, !tbaa !18
  %85 = or i32 %84, %81
  store i32 %85, ptr %83, align 4, !tbaa !18
  %86 = load i32, ptr %9, align 4, !tbaa !9
  %87 = xor i32 %86, -1
  %88 = load ptr, ptr %13, align 8, !tbaa !5
  %89 = getelementptr inbounds %struct.EFI_SIMPLE_NETWORK_MODE, ptr %88, i32 0, i32 7
  %90 = load i32, ptr %89, align 4, !tbaa !18
  %91 = and i32 %90, %87
  store i32 %91, ptr %89, align 4, !tbaa !18
  %92 = load i64, ptr %11, align 8, !tbaa !12
  %93 = trunc i64 %92 to i32
  %94 = load ptr, ptr %13, align 8, !tbaa !5
  %95 = getelementptr inbounds %struct.EFI_SIMPLE_NETWORK_MODE, ptr %94, i32 0, i32 9
  store i32 %93, ptr %95, align 4, !tbaa !21
  %96 = load ptr, ptr %7, align 8, !tbaa !5
  %97 = call i64 @ReceiveFilterUpdate(ptr noundef %96)
  store i64 %97, ptr %16, align 8, !tbaa !12
  br label %98

98:                                               ; preds = %80, %77
  br label %99

99:                                               ; preds = %98, %19, %6
  %100 = load i64, ptr %16, align 8, !tbaa !12
  call void @llvm.lifetime.end.p0(i64 8, ptr %16) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %15) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %14) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %13) #3
  ret i64 %100
}

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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { "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 = !{!"int", !7, i64 0}
!11 = !{!7, !7, i64 0}
!12 = !{!13, !13, i64 0}
!13 = !{!"long long", !7, i64 0}
!14 = !{!15, !6, i64 120}
!15 = !{!"_EFI_SIMPLE_NETWORK_PROTOCOL", !13, i64 0, !6, i64 8, !6, i64 16, !6, i64 24, !6, i64 32, !6, i64 40, !6, i64 48, !6, i64 56, !6, i64 64, !6, i64 72, !6, i64 80, !6, i64 88, !6, i64 96, !6, i64 104, !6, i64 112, !6, i64 120}
!16 = distinct !{!16, !17}
!17 = !{!"llvm.loop.mustprogress"}
!18 = !{!19, !10, i64 28}
!19 = !{!"", !10, i64 0, !10, i64 4, !10, i64 8, !10, i64 12, !10, i64 16, !10, i64 20, !10, i64 24, !10, i64 28, !10, i64 32, !10, i64 36, !7, i64 40, !20, i64 552, !20, i64 584, !20, i64 616, !7, i64 648, !7, i64 649, !7, i64 650, !7, i64 651, !7, i64 652}
!20 = !{!"", !7, i64 0}
!21 = !{!19, !10, i64 36}


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

%struct.EFI_MAC_ADDRESS = type { [32 x i8] }

; Function Attrs: nounwind uwtable
declare dso_local i64 @ReceiveFilterUpdate(ptr noundef) local_unnamed_addr #0

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

; Function Attrs: nounwind uwtable
define dso_local i64 @SN_ReceiveFilters(ptr noundef %0, i32 noundef %1, i32 noundef %2, i8 noundef zeroext %3, i64 noundef %4, ptr noundef %5) local_unnamed_addr #0 {
  %.not = icmp eq ptr %0, null
  br i1 %.not, label %.thread, label %7

7:                                                ; preds = %6
  %8 = getelementptr inbounds i8, ptr %0, i64 120
  %9 = load ptr, ptr %8, align 8, !tbaa !5
  %.not34 = icmp eq ptr %9, null
  br i1 %.not34, label %.thread, label %10

10:                                               ; preds = %7
  %.not35 = icmp ne i8 %3, 0
  %.not36 = icmp eq i64 %4, 0
  %or.cond37 = or i1 %.not35, %.not36
  br i1 %or.cond37, label %27, label %11

11:                                               ; preds = %10
  %12 = icmp ult i64 %4, 17
  %13 = icmp ne ptr %5, null
  %or.cond = and i1 %12, %13
  br i1 %or.cond, label %.lr.ph.preheader, label %.thread

.lr.ph.preheader:                                 ; preds = %11
  %14 = getelementptr inbounds %struct.EFI_MAC_ADDRESS, ptr %5, i64 %4
  br label %.lr.ph

.lr.ph:                                           ; preds = %.lr.ph.preheader, %18
  %.02940 = phi ptr [ %19, %18 ], [ %5, %.lr.ph.preheader ]
  %15 = load i8, ptr %.02940, align 1, !tbaa !11
  %16 = and i8 %15, 1
  %17 = icmp eq i8 %16, 0
  br i1 %17, label %._crit_edge, label %18

18:                                               ; preds = %.lr.ph
  %19 = getelementptr inbounds i8, ptr %.02940, i64 32
  %20 = icmp ugt ptr %14, %19
  br i1 %20, label %.lr.ph, label %._crit_edge, !llvm.loop !12

._crit_edge:                                      ; preds = %18, %.lr.ph
  %.029.lcssa.ph = phi ptr [ %19, %18 ], [ %.02940, %.lr.ph ]
  %21 = icmp eq ptr %14, %.029.lcssa.ph
  br i1 %21, label %22, label %.thread

22:                                               ; preds = %._crit_edge
  %23 = getelementptr inbounds i8, ptr %9, i64 40
  %24 = shl nuw nsw i64 %4, 5
  %25 = tail call ptr @CopyMem(ptr noundef nonnull %23, ptr noundef nonnull %5, i64 noundef %24) #2
  %26 = trunc nuw i64 %4 to i32
  br label %27

27:                                               ; preds = %22, %10
  %.028 = phi i32 [ %26, %22 ], [ 0, %10 ]
  %28 = getelementptr inbounds i8, ptr %9, i64 28
  %29 = load i32, ptr %28, align 4, !tbaa !14
  %30 = or i32 %29, %1
  %31 = xor i32 %2, -1
  %32 = and i32 %30, %31
  store i32 %32, ptr %28, align 4, !tbaa !14
  %33 = getelementptr inbounds i8, ptr %9, i64 36
  store i32 %.028, ptr %33, align 4, !tbaa !18
  %34 = tail call i64 @ReceiveFilterUpdate(ptr noundef nonnull %0)
  br label %.thread

.thread:                                          ; preds = %11, %._crit_edge, %27, %7, %6
  %.1 = phi i64 [ %34, %27 ], [ -9223372036854775806, %7 ], [ -9223372036854775806, %6 ], [ -9223372036854775806, %._crit_edge ], [ -9223372036854775806, %11 ]
  ret i64 %.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)"}
!5 = !{!6, !10, i64 120}
!6 = !{!"_EFI_SIMPLE_NETWORK_PROTOCOL", !7, i64 0, !10, i64 8, !10, i64 16, !10, i64 24, !10, i64 32, !10, i64 40, !10, i64 48, !10, i64 56, !10, i64 64, !10, i64 72, !10, i64 80, !10, i64 88, !10, i64 96, !10, i64 104, !10, i64 112, !10, i64 120}
!7 = !{!"long long", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"any pointer", !8, i64 0}
!11 = !{!8, !8, i64 0}
!12 = distinct !{!12, !13}
!13 = !{!"llvm.loop.mustprogress"}
!14 = !{!15, !16, i64 28}
!15 = !{!"", !16, i64 0, !16, i64 4, !16, i64 8, !16, i64 12, !16, i64 16, !16, i64 20, !16, i64 24, !16, i64 28, !16, i64 32, !16, i64 36, !8, i64 40, !17, i64 552, !17, i64 584, !17, i64 616, !8, i64 648, !8, i64 649, !8, i64 650, !8, i64 651, !8, i64 652}
!16 = !{!"int", !8, i64 0}
!17 = !{!"", !8, i64 0}
!18 = !{!15, !16, i64 36}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LCSSAPass,LoopRotatePass,LoopSimplifyPass,SCCPPass,SROAPass,SimplifyCFGPass,TailCallElimPass