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

; 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_INSTANCE_DATA = type { i32, ptr, ptr, %struct._LIST_ENTRY, %struct._EFI_MANAGED_NETWORK_PROTOCOL, i8, i8, %struct._LIST_ENTRY, %struct.NET_MAP, %struct._LIST_ENTRY, %struct._LIST_ENTRY, i64, %struct.EFI_MANAGED_NETWORK_CONFIG_DATA, i8 }
%struct._EFI_MANAGED_NETWORK_PROTOCOL = type { ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr }
%struct.NET_MAP = type { %struct._LIST_ENTRY, %struct._LIST_ENTRY, i64 }
%struct.EFI_MANAGED_NETWORK_CONFIG_DATA = type { i32, i32, i16, i8, i8, i8, i8, i8, i8, i8 }

@.str = external hidden unnamed_addr constant [147 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [127 x i8], align 1
@.str.11 = external hidden unnamed_addr constant [115 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 zeroext i8 @DebugAssertEnabled() #1

declare void @DebugAssert(ptr noundef, i64 noundef, ptr 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
declare dso_local i64 @MnpInstanceDeliverPacket(ptr noundef) #2

; Function Attrs: nounwind uwtable
define dso_local void @MnpDeliverPacket(ptr noundef %0) #2 {
  %2 = alloca ptr, align 8
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  store ptr %0, ptr %2, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %3) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #3
  br label %5

5:                                                ; preds = %1
  %6 = call zeroext i8 @DebugAssertEnabled()
  %7 = icmp ne i8 %6, 0
  br i1 %7, label %8, label %18

8:                                                ; preds = %5
  %9 = load ptr, ptr %2, align 8, !tbaa !5
  %10 = icmp ne ptr %9, null
  br i1 %10, label %11, label %16

11:                                               ; preds = %8
  %12 = load ptr, ptr %2, align 8, !tbaa !5
  %13 = getelementptr inbounds %struct.MNP_SERVICE_DATA, ptr %12, i32 0, i32 0
  %14 = load i32, ptr %13, align 8, !tbaa !9
  %15 = icmp eq i32 %14, 1399877197
  br i1 %15, label %17, label %16

16:                                               ; preds = %11, %8
  call void @DebugAssert(ptr noundef @.str, i64 noundef 430, ptr noundef @.str.1)
  br label %17

17:                                               ; preds = %16, %11
  br label %18

18:                                               ; preds = %17, %5
  br label %19

19:                                               ; preds = %18
  br label %20

20:                                               ; preds = %19
  %21 = load ptr, ptr %2, align 8, !tbaa !5
  %22 = getelementptr inbounds %struct.MNP_SERVICE_DATA, ptr %21, i32 0, i32 6
  %23 = getelementptr inbounds %struct._LIST_ENTRY, ptr %22, i32 0, i32 0
  %24 = load ptr, ptr %23, align 8, !tbaa !16
  store ptr %24, ptr %3, align 8, !tbaa !5
  br label %25

25:                                               ; preds = %53, %20
  %26 = load ptr, ptr %3, align 8, !tbaa !5
  %27 = load ptr, ptr %2, align 8, !tbaa !5
  %28 = getelementptr inbounds %struct.MNP_SERVICE_DATA, ptr %27, i32 0, i32 6
  %29 = icmp ne ptr %26, %28
  br i1 %29, label %30, label %57

30:                                               ; preds = %25
  %31 = load ptr, ptr %3, align 8, !tbaa !5
  %32 = ptrtoint ptr %31 to i64
  %33 = sub i64 %32, ptrtoint (ptr getelementptr inbounds (%struct.MNP_INSTANCE_DATA, ptr null, i32 0, i32 3) to i64)
  %34 = inttoptr i64 %33 to ptr
  store ptr %34, ptr %4, align 8, !tbaa !5
  br label %35

35:                                               ; preds = %30
  %36 = call zeroext i8 @DebugAssertEnabled()
  %37 = icmp ne i8 %36, 0
  br i1 %37, label %38, label %48

38:                                               ; preds = %35
  %39 = load ptr, ptr %4, align 8, !tbaa !5
  %40 = icmp ne ptr %39, null
  br i1 %40, label %41, label %46

41:                                               ; preds = %38
  %42 = load ptr, ptr %4, align 8, !tbaa !5
  %43 = getelementptr inbounds %struct.MNP_INSTANCE_DATA, ptr %42, i32 0, i32 0
  %44 = load i32, ptr %43, align 8, !tbaa !17
  %45 = icmp eq i32 %44, 1232105037
  br i1 %45, label %47, label %46

46:                                               ; preds = %41, %38
  call void @DebugAssert(ptr noundef @.str, i64 noundef 434, ptr noundef @.str.11)
  br label %47

47:                                               ; preds = %46, %41
  br label %48

48:                                               ; preds = %47, %35
  br label %49

49:                                               ; preds = %48
  br label %50

50:                                               ; preds = %49
  %51 = load ptr, ptr %4, align 8, !tbaa !5
  %52 = call i64 @MnpInstanceDeliverPacket(ptr noundef %51)
  br label %53

53:                                               ; preds = %50
  %54 = load ptr, ptr %3, align 8, !tbaa !5
  %55 = getelementptr inbounds %struct._LIST_ENTRY, ptr %54, i32 0, i32 0
  %56 = load ptr, ptr %55, align 8, !tbaa !22
  store ptr %56, ptr %3, align 8, !tbaa !5
  br label %25, !llvm.loop !23

57:                                               ; preds = %25
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #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, !11, i64 0}
!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 = !{!10, !6, i64 64}
!17 = !{!18, !11, i64 0}
!18 = !{!"", !11, i64 0, !6, i64 8, !6, i64 16, !12, i64 24, !19, i64 40, !7, i64 104, !7, i64 105, !12, i64 112, !20, i64 128, !12, i64 168, !12, i64 184, !14, i64 200, !21, i64 208, !7, i64 228}
!19 = !{!"_EFI_MANAGED_NETWORK_PROTOCOL", !6, i64 0, !6, i64 8, !6, i64 16, !6, i64 24, !6, i64 32, !6, i64 40, !6, i64 48, !6, i64 56}
!20 = !{!"", !12, i64 0, !12, i64 16, !14, i64 32}
!21 = !{!"", !11, i64 0, !11, i64 4, !15, i64 8, !7, i64 10, !7, i64 11, !7, i64 12, !7, i64 13, !7, i64 14, !7, i64 15, !7, i64 16}
!22 = !{!12, !6, i64 0}
!23 = distinct !{!23, !24}
!24 = !{!"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"

@.str = external hidden unnamed_addr constant [147 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [127 x i8], align 1
@.str.11 = external hidden unnamed_addr constant [115 x i8], align 1

declare zeroext i8 @DebugAssertEnabled() local_unnamed_addr #0

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

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

; Function Attrs: nounwind uwtable
define dso_local void @MnpDeliverPacket(ptr noundef readonly %0) local_unnamed_addr #1 {
  %2 = tail call zeroext i8 @DebugAssertEnabled() #2
  %.not = icmp eq i8 %2, 0
  br i1 %.not, label %8, label %3

3:                                                ; preds = %1
  %.not12 = icmp eq ptr %0, null
  br i1 %.not12, label %7, label %4

4:                                                ; preds = %3
  %5 = load i32, ptr %0, align 8, !tbaa !5
  %6 = icmp eq i32 %5, 1399877197
  br i1 %6, label %8, label %7

7:                                                ; preds = %4, %3
  tail call void @DebugAssert(ptr noundef nonnull @.str, i64 noundef 430, ptr noundef nonnull @.str.1) #2
  br label %8

8:                                                ; preds = %4, %7, %1
  %9 = getelementptr inbounds i8, ptr %0, i64 64
  %.016 = load ptr, ptr %9, align 8, !tbaa !15
  %.not1317 = icmp eq ptr %.016, %9
  br i1 %.not1317, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %8, %19
  %.018 = phi ptr [ %.0, %19 ], [ %.016, %8 ]
  %10 = ptrtoint ptr %.018 to i64
  %11 = add i64 %10, -24
  %12 = inttoptr i64 %11 to ptr
  %13 = tail call zeroext i8 @DebugAssertEnabled() #2
  %.not14 = icmp eq i8 %13, 0
  br i1 %.not14, label %19, label %14

14:                                               ; preds = %.lr.ph
  %.not15 = icmp eq i64 %11, 0
  br i1 %.not15, label %18, label %15

15:                                               ; preds = %14
  %16 = load i32, ptr %12, align 8, !tbaa !16
  %17 = icmp eq i32 %16, 1232105037
  br i1 %17, label %19, label %18

18:                                               ; preds = %15, %14
  tail call void @DebugAssert(ptr noundef nonnull @.str, i64 noundef 434, ptr noundef nonnull @.str.11) #2
  br label %19

19:                                               ; preds = %15, %18, %.lr.ph
  %20 = tail call i64 @MnpInstanceDeliverPacket(ptr noundef %12)
  %.0 = load ptr, ptr %.018, align 8, !tbaa !15
  %.not13 = icmp eq ptr %.0, %9
  br i1 %.not13, label %._crit_edge, label %.lr.ph, !llvm.loop !21

._crit_edge:                                      ; preds = %19, %8
  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 0}
!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 = !{!10, !11, i64 0}
!16 = !{!17, !7, i64 0}
!17 = !{!"", !7, i64 0, !11, i64 8, !11, i64 16, !10, i64 24, !18, i64 40, !8, i64 104, !8, i64 105, !10, i64 112, !19, i64 128, !10, i64 168, !10, i64 184, !13, i64 200, !20, i64 208, !8, i64 228}
!18 = !{!"_EFI_MANAGED_NETWORK_PROTOCOL", !11, i64 0, !11, i64 8, !11, i64 16, !11, i64 24, !11, i64 32, !11, i64 40, !11, i64 48, !11, i64 56}
!19 = !{!"", !10, i64 0, !10, i64 16, !13, i64 32}
!20 = !{!"", !7, i64 0, !7, i64 4, !14, i64 8, !8, i64 10, !8, i64 11, !8, i64 12, !8, i64 13, !8, i64 14, !8, i64 15, !8, i64 16}
!21 = distinct !{!21, !22}
!22 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass