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

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

%union.VLAN_TCI = type { %struct.anon }
%struct.anon = type { i16 }
%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._LIST_ENTRY = type { 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] }

@.str = external hidden unnamed_addr constant [149 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [23 x i8], align 1

; 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

; Function Attrs: nounwind uwtable
define dso_local zeroext i8 @MnpRemoveVlanTag(ptr noundef %0, ptr noundef %1, ptr noundef %2) #2 {
  %4 = alloca i8, align 1
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca ptr, align 8
  %9 = alloca i64, align 8
  %10 = alloca i16, align 2
  %11 = alloca %union.VLAN_TCI, align 1
  %12 = alloca i32, align 4
  store ptr %0, ptr %5, align 8, !tbaa !5
  store ptr %1, ptr %6, align 8, !tbaa !5
  store ptr %2, ptr %7, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #3
  call void @llvm.lifetime.start.p0(i64 2, ptr %10) #3
  call void @llvm.lifetime.start.p0(i64 2, ptr %11) #3
  %13 = load ptr, ptr %5, align 8, !tbaa !5
  %14 = getelementptr inbounds %struct.MNP_DEVICE_DATA, ptr %13, i32 0, i32 6
  %15 = load ptr, ptr %14, align 8, !tbaa !9
  %16 = getelementptr inbounds %struct._EFI_SIMPLE_NETWORK_PROTOCOL, ptr %15, i32 0, i32 15
  %17 = load ptr, ptr %16, align 8, !tbaa !16
  %18 = getelementptr inbounds %struct.EFI_SIMPLE_NETWORK_MODE, ptr %17, i32 0, i32 1
  %19 = load i32, ptr %18, align 4, !tbaa !18
  %20 = mul i32 %19, 2
  %21 = zext i32 %20 to i64
  store i64 %21, ptr %9, align 8, !tbaa !21
  %22 = load ptr, ptr %6, align 8, !tbaa !5
  %23 = call ptr @NetbufGetByte(ptr noundef %22, i32 noundef 0, ptr noundef null)
  store ptr %23, ptr %8, align 8, !tbaa !5
  br label %24

24:                                               ; preds = %3
  %25 = call zeroext i8 @DebugAssertEnabled()
  %26 = icmp ne i8 %25, 0
  br i1 %26, label %27, label %32

27:                                               ; preds = %24
  %28 = load ptr, ptr %8, align 8, !tbaa !5
  %29 = icmp ne ptr %28, null
  br i1 %29, label %31, label %30

30:                                               ; preds = %27
  call void @DebugAssert(ptr noundef @.str, i64 noundef 142, ptr noundef @.str.1)
  br label %31

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

32:                                               ; preds = %31, %24
  br label %33

33:                                               ; preds = %32
  br label %34

34:                                               ; preds = %33
  %35 = load ptr, ptr %7, align 8, !tbaa !5
  store i16 0, ptr %35, align 2, !tbaa !22
  %36 = load ptr, ptr %8, align 8, !tbaa !5
  %37 = load i64, ptr %9, align 8, !tbaa !21
  %38 = getelementptr inbounds i8, ptr %36, i64 %37
  %39 = load i16, ptr %38, align 2, !tbaa !22
  %40 = call zeroext i16 @SwapBytes16(i16 noundef zeroext %39)
  store i16 %40, ptr %10, align 2, !tbaa !22
  %41 = load i16, ptr %10, align 2, !tbaa !22
  %42 = zext i16 %41 to i32
  %43 = icmp ne i32 %42, 33024
  br i1 %43, label %44, label %45

44:                                               ; preds = %34
  store i8 0, ptr %4, align 1
  store i32 1, ptr %12, align 4
  br label %62

45:                                               ; preds = %34
  %46 = load ptr, ptr %8, align 8, !tbaa !5
  %47 = load i64, ptr %9, align 8, !tbaa !21
  %48 = getelementptr inbounds i8, ptr %46, i64 %47
  %49 = getelementptr inbounds i8, ptr %48, i64 2
  %50 = load i16, ptr %49, align 2, !tbaa !22
  %51 = call zeroext i16 @SwapBytes16(i16 noundef zeroext %50)
  store i16 %51, ptr %11, align 1, !tbaa !24
  %52 = load i16, ptr %11, align 1
  %53 = and i16 %52, 4095
  %54 = load ptr, ptr %7, align 8, !tbaa !5
  store i16 %53, ptr %54, align 2, !tbaa !22
  %55 = load ptr, ptr %8, align 8, !tbaa !5
  %56 = getelementptr inbounds i8, ptr %55, i64 4
  %57 = load ptr, ptr %8, align 8, !tbaa !5
  %58 = load i64, ptr %9, align 8, !tbaa !21
  %59 = call ptr @CopyMem(ptr noundef %56, ptr noundef %57, i64 noundef %58)
  %60 = load ptr, ptr %6, align 8, !tbaa !5
  %61 = call i32 @NetbufTrim(ptr noundef %60, i32 noundef 4, i8 noundef zeroext 1)
  store i8 1, ptr %4, align 1
  store i32 1, ptr %12, align 4
  br label %62

62:                                               ; preds = %45, %44
  call void @llvm.lifetime.end.p0(i64 2, ptr %11) #3
  call void @llvm.lifetime.end.p0(i64 2, ptr %10) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #3
  %63 = load i8, ptr %4, align 1
  ret i8 %63
}

declare ptr @NetbufGetByte(ptr noundef, i32 noundef, ptr noundef) #1

declare zeroext i8 @DebugAssertEnabled() #1

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

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

declare i32 @NetbufTrim(ptr noundef, i32 noundef, i8 noundef zeroext) #1

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 64}
!10 = !{!"", !11, i64 0, !6, i64 8, !6, i64 16, !12, i64 24, !13, i64 48, !6, i64 56, !6, i64 64, !14, i64 72, !13, i64 88, !14, i64 96, !11, i64 112, !6, i64 120, !15, i64 128, !13, 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}
!11 = !{!"int", !7, i64 0}
!12 = !{!"_EFI_VLAN_CONFIG_PROTOCOL", !6, i64 0, !6, i64 8, !6, i64 16}
!13 = !{!"long long", !7, i64 0}
!14 = !{!"_LIST_ENTRY", !6, i64 0, !6, i64 8}
!15 = !{!"", !11, i64 0, !13, i64 8, !14, i64 16, !14, i64 32, !11, i64 48, !11, i64 52}
!16 = !{!17, !6, i64 120}
!17 = !{!"_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}
!18 = !{!19, !11, i64 4}
!19 = !{!"", !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, !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 = !{!13, !13, i64 0}
!22 = !{!23, !23, i64 0}
!23 = !{!"short", !7, i64 0}
!24 = !{!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"

@.str = external hidden unnamed_addr constant [149 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [23 x i8], align 1

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

; Function Attrs: nounwind uwtable
define dso_local zeroext range(i8 0, 2) i8 @MnpRemoveVlanTag(ptr nocapture noundef readonly %0, ptr noundef %1, ptr nocapture noundef writeonly %2) local_unnamed_addr #1 {
  %4 = getelementptr inbounds i8, ptr %0, i64 64
  %5 = load ptr, ptr %4, align 8, !tbaa !5
  %6 = getelementptr inbounds i8, ptr %5, i64 120
  %7 = load ptr, ptr %6, align 8, !tbaa !15
  %8 = getelementptr inbounds i8, ptr %7, i64 4
  %9 = load i32, ptr %8, align 4, !tbaa !17
  %10 = shl i32 %9, 1
  %11 = zext i32 %10 to i64
  %12 = tail call ptr @NetbufGetByte(ptr noundef %1, i32 noundef 0, ptr noundef null) #2
  %13 = tail call zeroext i8 @DebugAssertEnabled() #2
  %14 = icmp eq i8 %13, 0
  %15 = icmp ne ptr %12, null
  %or.cond = select i1 %14, i1 true, i1 %15
  br i1 %or.cond, label %17, label %16

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

17:                                               ; preds = %16, %3
  store i16 0, ptr %2, align 2, !tbaa !20
  %18 = getelementptr inbounds i8, ptr %12, i64 %11
  %19 = load i16, ptr %18, align 2, !tbaa !20
  %20 = tail call zeroext i16 @SwapBytes16(i16 noundef zeroext %19) #2
  %.not = icmp eq i16 %20, -32512
  br i1 %.not, label %21, label %29

21:                                               ; preds = %17
  %22 = getelementptr inbounds i8, ptr %18, i64 2
  %23 = load i16, ptr %22, align 2, !tbaa !20
  %24 = tail call zeroext i16 @SwapBytes16(i16 noundef zeroext %23) #2
  %25 = and i16 %24, 4095
  store i16 %25, ptr %2, align 2, !tbaa !20
  %26 = getelementptr inbounds i8, ptr %12, i64 4
  %27 = tail call ptr @CopyMem(ptr noundef nonnull %26, ptr noundef nonnull %12, i64 noundef %11) #2
  %28 = tail call i32 @NetbufTrim(ptr noundef %1, i32 noundef 4, i8 noundef zeroext 1) #2
  br label %29

29:                                               ; preds = %17, %21
  %.0 = phi i8 [ 1, %21 ], [ 0, %17 ]
  ret i8 %.0
}

declare ptr @NetbufGetByte(ptr noundef, i32 noundef, ptr noundef) local_unnamed_addr #0

declare zeroext i8 @DebugAssertEnabled() local_unnamed_addr #0

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

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

declare i32 @NetbufTrim(ptr noundef, i32 noundef, i8 noundef zeroext) local_unnamed_addr #0

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, !10, i64 64}
!6 = !{!"", !7, i64 0, !10, i64 8, !10, i64 16, !11, i64 24, !12, i64 48, !10, i64 56, !10, i64 64, !13, i64 72, !12, i64 88, !13, i64 96, !7, i64 112, !10, i64 120, !14, i64 128, !12, i64 184, !10, i64 192, !8, i64 200, !10, i64 208, !10, i64 216, !7, i64 224, !7, i64 228, !7, i64 232, !7, i64 236, !7, i64 240, !7, i64 244, !10, i64 248, !10, i64 256}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"any pointer", !8, i64 0}
!11 = !{!"_EFI_VLAN_CONFIG_PROTOCOL", !10, i64 0, !10, i64 8, !10, i64 16}
!12 = !{!"long long", !8, i64 0}
!13 = !{!"_LIST_ENTRY", !10, i64 0, !10, i64 8}
!14 = !{!"", !7, i64 0, !12, i64 8, !13, i64 16, !13, i64 32, !7, i64 48, !7, i64 52}
!15 = !{!16, !10, i64 120}
!16 = !{!"_EFI_SIMPLE_NETWORK_PROTOCOL", !12, 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}
!17 = !{!18, !7, i64 4}
!18 = !{!"", !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, !19, i64 552, !19, i64 584, !19, i64 616, !8, i64 648, !8, i64 649, !8, i64 650, !8, i64 651, !8, i64 652}
!19 = !{!"", !8, i64 0}
!20 = !{!21, !21, i64 0}
!21 = !{!"short", !8, i64 0}


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