; LLVM IR from thalium/icebox :: third_party/virtualbox/src/VBox/Devices/EFI/Firmware/MdeModulePkg/Universal (MnpInsertVlanTag)

; 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.MNP_SERVICE_DATA = type { i32, %struct._LIST_ENTRY, ptr, ptr, %struct._EFI_SERVICE_BINDING_PROTOCOL, ptr, %struct._LIST_ENTRY, i64, i32, i16, i8 }
%struct._EFI_SERVICE_BINDING_PROTOCOL = type { ptr, ptr }
%struct._LIST_ENTRY = type { ptr, ptr }
%struct.MNP_DEVICE_DATA = type { i32, ptr, ptr, %struct._EFI_VLAN_CONFIG_PROTOCOL, i64, ptr, ptr, %struct._LIST_ENTRY, i64, %struct._LIST_ENTRY, i32, ptr, %struct.NET_BUF_QUEUE, i64, ptr, i8, ptr, ptr, i32, i32, i32, i32, i32, i32, ptr, ptr }
%struct._EFI_VLAN_CONFIG_PROTOCOL = type { ptr, ptr, ptr }
%struct.NET_BUF_QUEUE = type { i32, i64, %struct._LIST_ENTRY, %struct._LIST_ENTRY, i32, i32 }
%struct._EFI_SIMPLE_NETWORK_PROTOCOL = type { i64, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr }
%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.EFI_MANAGED_NETWORK_TRANSMIT_DATA = type { ptr, ptr, i16, i32, i16, i16, [1 x %struct.EFI_MANAGED_NETWORK_FRAGMENT_DATA] }
%struct.EFI_MANAGED_NETWORK_FRAGMENT_DATA = type { i32, ptr }
%union.VLAN_TCI = type { %struct.anon }
%struct.anon = type { i16 }

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

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

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

declare zeroext i16 @SwapBytes16(i16 noundef zeroext) #1

; Function Attrs: nounwind uwtable
define dso_local void @MnpInsertVlanTag(ptr noundef %0, ptr noundef %1, ptr noundef %2, ptr noundef %3, ptr noundef %4) #2 {
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca ptr, align 8
  %9 = alloca ptr, align 8
  %10 = alloca ptr, align 8
  %11 = alloca ptr, align 8
  %12 = alloca ptr, align 8
  %13 = alloca ptr, align 8
  %14 = alloca ptr, align 8
  %15 = alloca ptr, align 8
  store ptr %0, ptr %6, align 8, !tbaa !5
  store ptr %1, ptr %7, align 8, !tbaa !5
  store ptr %2, ptr %8, align 8, !tbaa !5
  store ptr %3, ptr %9, align 8, !tbaa !5
  store ptr %4, ptr %10, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %12) #3
  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
  %16 = load ptr, ptr %6, align 8, !tbaa !5
  %17 = getelementptr inbounds %struct.MNP_SERVICE_DATA, ptr %16, i32 0, i32 2
  %18 = load ptr, ptr %17, align 8, !tbaa !9
  store ptr %18, ptr %14, align 8, !tbaa !5
  %19 = load ptr, ptr %14, align 8, !tbaa !5
  %20 = getelementptr inbounds %struct.MNP_DEVICE_DATA, ptr %19, i32 0, i32 6
  %21 = load ptr, ptr %20, align 8, !tbaa !16
  %22 = getelementptr inbounds %struct._EFI_SIMPLE_NETWORK_PROTOCOL, ptr %21, i32 0, i32 15
  %23 = load ptr, ptr %22, align 8, !tbaa !20
  store ptr %23, ptr %15, align 8, !tbaa !5
  %24 = load ptr, ptr %8, align 8, !tbaa !5
  store i16 -32512, ptr %24, align 2, !tbaa !22
  %25 = load ptr, ptr %10, align 8, !tbaa !5
  %26 = load i32, ptr %25, align 4, !tbaa !23
  %27 = add i32 %26, 4
  %28 = load ptr, ptr %10, align 8, !tbaa !5
  store i32 %27, ptr %28, align 4, !tbaa !23
  %29 = load ptr, ptr %9, align 8, !tbaa !5
  %30 = load ptr, ptr %29, align 8, !tbaa !5
  %31 = getelementptr inbounds i8, ptr %30, i64 -4
  %32 = load ptr, ptr %9, align 8, !tbaa !5
  store ptr %31, ptr %32, align 8, !tbaa !5
  %33 = load ptr, ptr %9, align 8, !tbaa !5
  %34 = load ptr, ptr %33, align 8, !tbaa !5
  %35 = load ptr, ptr %15, align 8, !tbaa !5
  %36 = getelementptr inbounds %struct.EFI_SIMPLE_NETWORK_MODE, ptr %35, i32 0, i32 2
  %37 = load i32, ptr %36, align 4, !tbaa !24
  %38 = zext i32 %37 to i64
  %39 = getelementptr inbounds i8, ptr %34, i64 %38
  %40 = getelementptr inbounds i8, ptr %39, i64 -2
  store ptr %40, ptr %12, align 8, !tbaa !5
  %41 = load ptr, ptr %12, align 8, !tbaa !5
  %42 = getelementptr inbounds i16, ptr %41, i64 1
  %43 = ptrtoint ptr %42 to i64
  %44 = inttoptr i64 %43 to ptr
  store ptr %44, ptr %11, align 8, !tbaa !5
  %45 = load ptr, ptr %7, align 8, !tbaa !5
  %46 = getelementptr inbounds %struct.EFI_MANAGED_NETWORK_TRANSMIT_DATA, ptr %45, i32 0, i32 4
  %47 = load i16, ptr %46, align 8, !tbaa !27
  %48 = zext i16 %47 to i32
  %49 = icmp ne i32 %48, 0
  br i1 %49, label %50, label %64

50:                                               ; preds = %5
  %51 = load ptr, ptr %9, align 8, !tbaa !5
  %52 = load ptr, ptr %51, align 8, !tbaa !5
  %53 = load ptr, ptr %9, align 8, !tbaa !5
  %54 = load ptr, ptr %53, align 8, !tbaa !5
  %55 = getelementptr inbounds i8, ptr %54, i64 4
  %56 = load ptr, ptr %15, align 8, !tbaa !5
  %57 = getelementptr inbounds %struct.EFI_SIMPLE_NETWORK_MODE, ptr %56, i32 0, i32 2
  %58 = load i32, ptr %57, align 4, !tbaa !24
  %59 = zext i32 %58 to i64
  %60 = sub i64 %59, 2
  %61 = call ptr @CopyMem(ptr noundef %52, ptr noundef %55, i64 noundef %60)
  %62 = call zeroext i16 @SwapBytes16(i16 noundef zeroext -32512)
  %63 = load ptr, ptr %12, align 8, !tbaa !5
  store i16 %62, ptr %63, align 2, !tbaa !22
  br label %74

64:                                               ; preds = %5
  %65 = load ptr, ptr %11, align 8, !tbaa !5
  %66 = getelementptr inbounds %union.VLAN_TCI, ptr %65, i64 1
  %67 = ptrtoint ptr %66 to i64
  %68 = inttoptr i64 %67 to ptr
  store ptr %68, ptr %13, align 8, !tbaa !5
  %69 = load ptr, ptr %7, align 8, !tbaa !5
  %70 = getelementptr inbounds %struct.EFI_MANAGED_NETWORK_TRANSMIT_DATA, ptr %69, i32 0, i32 2
  %71 = load i16, ptr %70, align 8, !tbaa !29
  %72 = call zeroext i16 @SwapBytes16(i16 noundef zeroext %71)
  %73 = load ptr, ptr %13, align 8, !tbaa !5
  store i16 %72, ptr %73, align 2, !tbaa !22
  br label %74

74:                                               ; preds = %64, %50
  %75 = load ptr, ptr %6, align 8, !tbaa !5
  %76 = getelementptr inbounds %struct.MNP_SERVICE_DATA, ptr %75, i32 0, i32 9
  %77 = load i16, ptr %76, align 4, !tbaa !30
  %78 = load ptr, ptr %11, align 8, !tbaa !5
  %79 = load i16, ptr %78, align 1
  %80 = and i16 %77, 4095
  %81 = and i16 %79, -4096
  %82 = or i16 %81, %80
  store i16 %82, ptr %78, align 1
  %83 = load ptr, ptr %11, align 8, !tbaa !5
  %84 = load i16, ptr %83, align 1
  %85 = and i16 %84, -4097
  %86 = or i16 %85, 0
  store i16 %86, ptr %83, align 1
  %87 = load ptr, ptr %6, align 8, !tbaa !5
  %88 = getelementptr inbounds %struct.MNP_SERVICE_DATA, ptr %87, i32 0, i32 10
  %89 = load i8, ptr %88, align 2, !tbaa !31
  %90 = zext i8 %89 to i16
  %91 = load ptr, ptr %11, align 8, !tbaa !5
  %92 = load i16, ptr %91, align 1
  %93 = and i16 %90, 7
  %94 = shl i16 %93, 13
  %95 = and i16 %92, 8191
  %96 = or i16 %95, %94
  store i16 %96, ptr %91, align 1
  %97 = load ptr, ptr %11, align 8, !tbaa !5
  %98 = load i16, ptr %97, align 1, !tbaa !32
  %99 = call zeroext i16 @SwapBytes16(i16 noundef zeroext %98)
  %100 = load ptr, ptr %11, align 8, !tbaa !5
  store i16 %99, ptr %100, align 1, !tbaa !32
  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
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #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, !6, i64 24}
!10 = !{!"", !11, i64 0, !12, i64 8, !6, i64 24, !6, i64 32, !13, i64 40, !6, i64 56, !12, i64 64, !14, i64 80, !11, i64 88, !15, i64 92, !7, i64 94}
!11 = !{!"int", !7, i64 0}
!12 = !{!"_LIST_ENTRY", !6, i64 0, !6, i64 8}
!13 = !{!"_EFI_SERVICE_BINDING_PROTOCOL", !6, i64 0, !6, i64 8}
!14 = !{!"long long", !7, i64 0}
!15 = !{!"short", !7, i64 0}
!16 = !{!17, !6, i64 64}
!17 = !{!"", !11, i64 0, !6, i64 8, !6, i64 16, !18, i64 24, !14, i64 48, !6, i64 56, !6, i64 64, !12, i64 72, !14, i64 88, !12, i64 96, !11, i64 112, !6, i64 120, !19, i64 128, !14, i64 184, !6, i64 192, !7, i64 200, !6, i64 208, !6, i64 216, !11, i64 224, !11, i64 228, !11, i64 232, !11, i64 236, !11, i64 240, !11, i64 244, !6, i64 248, !6, i64 256}
!18 = !{!"_EFI_VLAN_CONFIG_PROTOCOL", !6, i64 0, !6, i64 8, !6, i64 16}
!19 = !{!"", !11, i64 0, !14, i64 8, !12, i64 16, !12, i64 32, !11, i64 48, !11, i64 52}
!20 = !{!21, !6, i64 120}
!21 = !{!"_EFI_SIMPLE_NETWORK_PROTOCOL", !14, 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}
!22 = !{!15, !15, i64 0}
!23 = !{!11, !11, i64 0}
!24 = !{!25, !11, i64 8}
!25 = !{!"", !11, i64 0, !11, i64 4, !11, i64 8, !11, i64 12, !11, i64 16, !11, i64 20, !11, i64 24, !11, i64 28, !11, i64 32, !11, i64 36, !7, i64 40, !26, i64 552, !26, i64 584, !26, i64 616, !7, i64 648, !7, i64 649, !7, i64 650, !7, i64 651, !7, i64 652}
!26 = !{!"", !7, i64 0}
!27 = !{!28, !15, i64 24}
!28 = !{!"", !6, i64 0, !6, i64 8, !15, i64 16, !11, i64 20, !15, i64 24, !15, i64 26, !7, i64 32}
!29 = !{!28, !15, i64 16}
!30 = !{!10, !15, i64 92}
!31 = !{!10, !7, i64 94}
!32 = !{!7, !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"

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

declare zeroext i16 @SwapBytes16(i16 noundef zeroext) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local void @MnpInsertVlanTag(ptr nocapture noundef readonly %0, ptr nocapture noundef readonly %1, ptr nocapture noundef writeonly %2, ptr nocapture noundef %3, ptr nocapture noundef %4) local_unnamed_addr #1 {
  %6 = getelementptr inbounds i8, ptr %0, i64 24
  %7 = load ptr, ptr %6, align 8, !tbaa !5
  %8 = getelementptr inbounds i8, ptr %7, i64 64
  %9 = load ptr, ptr %8, align 8, !tbaa !15
  %10 = getelementptr inbounds i8, ptr %9, i64 120
  %11 = load ptr, ptr %10, align 8, !tbaa !19
  store i16 -32512, ptr %2, align 2, !tbaa !21
  %12 = load i32, ptr %4, align 4, !tbaa !22
  %13 = add i32 %12, 4
  store i32 %13, ptr %4, align 4, !tbaa !22
  %14 = load ptr, ptr %3, align 8, !tbaa !23
  %15 = getelementptr inbounds i8, ptr %14, i64 -4
  store ptr %15, ptr %3, align 8, !tbaa !23
  %16 = getelementptr inbounds i8, ptr %11, i64 8
  %17 = load i32, ptr %16, align 4, !tbaa !24
  %18 = zext i32 %17 to i64
  %19 = getelementptr inbounds i8, ptr %15, i64 %18
  %20 = getelementptr inbounds i8, ptr %1, i64 24
  %21 = load i16, ptr %20, align 8, !tbaa !27
  %.not = icmp eq i16 %21, 0
  br i1 %.not, label %26, label %22

22:                                               ; preds = %5
  %23 = getelementptr inbounds i8, ptr %19, i64 -2
  %24 = add nsw i64 %18, -2
  %25 = tail call ptr @CopyMem(ptr noundef nonnull %15, ptr noundef %14, i64 noundef %24) #2
  br label %30

26:                                               ; preds = %5
  %27 = getelementptr inbounds i8, ptr %19, i64 2
  %28 = getelementptr inbounds i8, ptr %1, i64 16
  %29 = load i16, ptr %28, align 8, !tbaa !29
  br label %30

30:                                               ; preds = %26, %22
  %.sink26 = phi i16 [ %29, %26 ], [ -32512, %22 ]
  %.sink25 = phi ptr [ %27, %26 ], [ %23, %22 ]
  %31 = tail call zeroext i16 @SwapBytes16(i16 noundef zeroext %.sink26) #2
  store i16 %31, ptr %.sink25, align 2, !tbaa !21
  %32 = getelementptr inbounds i8, ptr %0, i64 92
  %33 = load i16, ptr %32, align 4, !tbaa !30
  %34 = load i16, ptr %19, align 1
  %35 = and i16 %33, 4095
  %36 = and i16 %34, -8192
  %37 = or disjoint i16 %36, %35
  store i16 %37, ptr %19, align 1
  %38 = getelementptr inbounds i8, ptr %0, i64 94
  %39 = load i8, ptr %38, align 2, !tbaa !31
  %40 = and i8 %39, 7
  %41 = zext nneg i8 %40 to i16
  %42 = shl nuw i16 %41, 13
  %43 = or disjoint i16 %42, %35
  store i16 %43, ptr %19, align 1
  %44 = tail call zeroext i16 @SwapBytes16(i16 noundef zeroext %43) #2
  store i16 %44, ptr %19, align 1, !tbaa !32
  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, !11, i64 24}
!6 = !{!"", !7, i64 0, !10, i64 8, !11, i64 24, !11, i64 32, !12, i64 40, !11, i64 56, !10, i64 64, !13, i64 80, !7, i64 88, !14, i64 92, !8, i64 94}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"_LIST_ENTRY", !11, i64 0, !11, i64 8}
!11 = !{!"any pointer", !8, i64 0}
!12 = !{!"_EFI_SERVICE_BINDING_PROTOCOL", !11, i64 0, !11, i64 8}
!13 = !{!"long long", !8, i64 0}
!14 = !{!"short", !8, i64 0}
!15 = !{!16, !11, i64 64}
!16 = !{!"", !7, i64 0, !11, i64 8, !11, i64 16, !17, i64 24, !13, i64 48, !11, i64 56, !11, i64 64, !10, i64 72, !13, i64 88, !10, i64 96, !7, i64 112, !11, i64 120, !18, i64 128, !13, i64 184, !11, i64 192, !8, i64 200, !11, i64 208, !11, i64 216, !7, i64 224, !7, i64 228, !7, i64 232, !7, i64 236, !7, i64 240, !7, i64 244, !11, i64 248, !11, i64 256}
!17 = !{!"_EFI_VLAN_CONFIG_PROTOCOL", !11, i64 0, !11, i64 8, !11, i64 16}
!18 = !{!"", !7, i64 0, !13, i64 8, !10, i64 16, !10, i64 32, !7, i64 48, !7, i64 52}
!19 = !{!20, !11, i64 120}
!20 = !{!"_EFI_SIMPLE_NETWORK_PROTOCOL", !13, i64 0, !11, i64 8, !11, i64 16, !11, i64 24, !11, i64 32, !11, i64 40, !11, i64 48, !11, i64 56, !11, i64 64, !11, i64 72, !11, i64 80, !11, i64 88, !11, i64 96, !11, i64 104, !11, i64 112, !11, i64 120}
!21 = !{!14, !14, i64 0}
!22 = !{!7, !7, i64 0}
!23 = !{!11, !11, i64 0}
!24 = !{!25, !7, i64 8}
!25 = !{!"", !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, !26, i64 552, !26, i64 584, !26, i64 616, !8, i64 648, !8, i64 649, !8, i64 650, !8, i64 651, !8, i64 652}
!26 = !{!"", !8, i64 0}
!27 = !{!28, !14, i64 24}
!28 = !{!"", !11, i64 0, !11, i64 8, !14, i64 16, !7, i64 20, !14, i64 24, !14, i64 26, !8, i64 32}
!29 = !{!28, !14, i64 16}
!30 = !{!6, !14, i64 92}
!31 = !{!6, !8, i64 94}
!32 = !{!8, !8, i64 0}


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