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

; 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._UDP4_SERVICE_DATA_ = type { i32, %struct._EFI_SERVICE_BINDING_PROTOCOL, ptr, ptr, %struct._LIST_ENTRY, i64, ptr, ptr }
%struct._EFI_SERVICE_BINDING_PROTOCOL = type { ptr, ptr }
%struct._LIST_ENTRY = type { ptr, ptr }
%struct._UDP4_INSTANCE_DATA_ = type { i32, %struct._LIST_ENTRY, ptr, %struct._EFI_UDP4_PROTOCOL, %struct.EFI_UDP4_CONFIG_DATA, ptr, i8, i8, %struct.NET_MAP, %struct.NET_MAP, %struct.NET_MAP, %struct._LIST_ENTRY, %struct._LIST_ENTRY, i16, i64, ptr, i8 }
%struct._EFI_UDP4_PROTOCOL = type { ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr }
%struct.EFI_UDP4_CONFIG_DATA = type { i8, i8, i8, i8, i8, i8, i8, i32, i32, i8, %struct.EFI_IPv4_ADDRESS, %struct.EFI_IPv4_ADDRESS, i16, %struct.EFI_IPv4_ADDRESS, i16 }
%struct.EFI_IPv4_ADDRESS = type { [4 x i8] }
%struct.NET_MAP = type { %struct._LIST_ENTRY, %struct._LIST_ENTRY, i64 }
%struct.EFI_UDP4_RECEIVE_DATA = type { %struct.EFI_TIME, ptr, %struct.EFI_UDP4_SESSION_DATA, i32, i32, [1 x %struct.EFI_UDP4_FRAGMENT_DATA] }
%struct.EFI_TIME = type { i16, i8, i8, i8, i8, i8, i8, i32, i16, i8, i8 }
%struct.EFI_UDP4_SESSION_DATA = type { %struct.EFI_IPv4_ADDRESS, i16, %struct.EFI_IPv4_ADDRESS, i16 }
%struct.EFI_UDP4_FRAGMENT_DATA = type { i32, ptr }
%struct.NET_BUF = type { i32, i64, %struct._LIST_ENTRY, %union.NET_IP_HEAD, ptr, ptr, [64 x i8], ptr, i32, i32, [1 x %struct.NET_BLOCK_OP] }
%union.NET_IP_HEAD = type { ptr }
%struct.NET_BLOCK_OP = type { ptr, ptr, ptr, ptr, i32 }
%struct._UDP4_RXDATA_WRAP_ = type { %struct._LIST_ENTRY, ptr, i32, %struct.EFI_UDP4_RECEIVE_DATA }

; 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

; Function Attrs: nounwind uwtable
declare dso_local zeroext i8 @Udp4MatchDgram(ptr noundef, ptr noundef) #1

; Function Attrs: nounwind uwtable
declare dso_local ptr @Udp4WrapRxData(ptr noundef, ptr noundef, ptr noundef) #1

; Function Attrs: nounwind uwtable
define dso_local i64 @Udp4EnqueueDgram(ptr noundef %0, ptr noundef %1, ptr noundef %2) #1 {
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca ptr, align 8
  %9 = alloca ptr, align 8
  %10 = alloca i64, align 8
  store ptr %0, ptr %4, align 8, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !5
  store ptr %2, ptr %6, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #3
  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 8, ptr %10) #3
  store i64 0, ptr %10, align 8, !tbaa !9
  %11 = load ptr, ptr %4, align 8, !tbaa !5
  %12 = getelementptr inbounds %struct._UDP4_SERVICE_DATA_, ptr %11, i32 0, i32 4
  %13 = getelementptr inbounds %struct._LIST_ENTRY, ptr %12, i32 0, i32 0
  %14 = load ptr, ptr %13, align 8, !tbaa !11
  store ptr %14, ptr %7, align 8, !tbaa !5
  br label %15

15:                                               ; preds = %57, %3
  %16 = load ptr, ptr %7, align 8, !tbaa !5
  %17 = load ptr, ptr %4, align 8, !tbaa !5
  %18 = getelementptr inbounds %struct._UDP4_SERVICE_DATA_, ptr %17, i32 0, i32 4
  %19 = icmp ne ptr %16, %18
  br i1 %19, label %20, label %61

20:                                               ; preds = %15
  %21 = load ptr, ptr %7, align 8, !tbaa !5
  %22 = ptrtoint ptr %21 to i64
  %23 = sub i64 %22, ptrtoint (ptr getelementptr inbounds (%struct._UDP4_INSTANCE_DATA_, ptr null, i32 0, i32 1) to i64)
  %24 = inttoptr i64 %23 to ptr
  store ptr %24, ptr %8, align 8, !tbaa !5
  %25 = load ptr, ptr %8, align 8, !tbaa !5
  %26 = getelementptr inbounds %struct._UDP4_INSTANCE_DATA_, ptr %25, i32 0, i32 6
  %27 = load i8, ptr %26, align 8, !tbaa !16
  %28 = icmp ne i8 %27, 0
  br i1 %28, label %30, label %29

29:                                               ; preds = %20
  br label %57

30:                                               ; preds = %20
  %31 = load ptr, ptr %8, align 8, !tbaa !5
  %32 = load ptr, ptr %6, align 8, !tbaa !5
  %33 = getelementptr inbounds %struct.EFI_UDP4_RECEIVE_DATA, ptr %32, i32 0, i32 2
  %34 = call zeroext i8 @Udp4MatchDgram(ptr noundef %31, ptr noundef %33)
  %35 = icmp ne i8 %34, 0
  br i1 %35, label %36, label %56

36:                                               ; preds = %30
  %37 = load ptr, ptr %8, align 8, !tbaa !5
  %38 = load ptr, ptr %5, align 8, !tbaa !5
  %39 = load ptr, ptr %6, align 8, !tbaa !5
  %40 = call ptr @Udp4WrapRxData(ptr noundef %37, ptr noundef %38, ptr noundef %39)
  store ptr %40, ptr %9, align 8, !tbaa !5
  %41 = load ptr, ptr %9, align 8, !tbaa !5
  %42 = icmp eq ptr %41, null
  br i1 %42, label %43, label %44

43:                                               ; preds = %36
  br label %57

44:                                               ; preds = %36
  %45 = load ptr, ptr %5, align 8, !tbaa !5
  %46 = getelementptr inbounds %struct.NET_BUF, ptr %45, i32 0, i32 1
  %47 = load i64, ptr %46, align 8, !tbaa !23
  %48 = add nsw i64 %47, 1
  store i64 %48, ptr %46, align 8, !tbaa !23
  %49 = load ptr, ptr %8, align 8, !tbaa !5
  %50 = getelementptr inbounds %struct._UDP4_INSTANCE_DATA_, ptr %49, i32 0, i32 11
  %51 = load ptr, ptr %9, align 8, !tbaa !5
  %52 = getelementptr inbounds %struct._UDP4_RXDATA_WRAP_, ptr %51, i32 0, i32 0
  %53 = call ptr @InsertTailList(ptr noundef %50, ptr noundef %52)
  %54 = load i64, ptr %10, align 8, !tbaa !9
  %55 = add i64 %54, 1
  store i64 %55, ptr %10, align 8, !tbaa !9
  br label %56

56:                                               ; preds = %44, %30
  br label %57

57:                                               ; preds = %56, %43, %29
  %58 = load ptr, ptr %7, align 8, !tbaa !5
  %59 = getelementptr inbounds %struct._LIST_ENTRY, ptr %58, i32 0, i32 0
  %60 = load ptr, ptr %59, align 8, !tbaa !25
  store ptr %60, ptr %7, align 8, !tbaa !5
  br label %15, !llvm.loop !26

61:                                               ; preds = %15
  %62 = load i64, ptr %10, align 8, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 8, 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
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #3
  ret i64 %62
}

declare ptr @InsertTailList(ptr noundef, ptr noundef) #2

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = { "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, !6, i64 40}
!12 = !{!"_UDP4_SERVICE_DATA_", !13, i64 0, !14, i64 8, !6, i64 24, !6, i64 32, !15, i64 40, !10, i64 56, !6, i64 64, !6, i64 72}
!13 = !{!"int", !7, i64 0}
!14 = !{!"_EFI_SERVICE_BINDING_PROTOCOL", !6, i64 0, !6, i64 8}
!15 = !{!"_LIST_ENTRY", !6, i64 0, !6, i64 8}
!16 = !{!17, !7, i64 144}
!17 = !{!"_UDP4_INSTANCE_DATA_", !13, i64 0, !15, i64 8, !6, i64 24, !18, i64 32, !19, i64 96, !6, i64 136, !7, i64 144, !7, i64 145, !22, i64 152, !22, i64 192, !22, i64 232, !15, i64 272, !15, i64 288, !21, i64 304, !10, i64 312, !6, i64 320, !7, i64 328}
!18 = !{!"_EFI_UDP4_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}
!19 = !{!"", !7, i64 0, !7, i64 1, !7, i64 2, !7, i64 3, !7, i64 4, !7, i64 5, !7, i64 6, !13, i64 8, !13, i64 12, !7, i64 16, !20, i64 17, !20, i64 21, !21, i64 26, !20, i64 28, !21, i64 32}
!20 = !{!"", !7, i64 0}
!21 = !{!"short", !7, i64 0}
!22 = !{!"", !15, i64 0, !15, i64 16, !10, i64 32}
!23 = !{!24, !10, i64 8}
!24 = !{!"", !13, i64 0, !10, i64 8, !15, i64 16, !7, i64 32, !6, i64 40, !6, i64 48, !7, i64 56, !6, i64 120, !13, i64 128, !13, i64 132, !7, i64 136}
!25 = !{!15, !6, i64 0}
!26 = distinct !{!26, !27}
!27 = !{!"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"

; Function Attrs: nounwind uwtable
declare dso_local zeroext i8 @Udp4MatchDgram(ptr noundef, ptr noundef) local_unnamed_addr #0

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

; Function Attrs: nounwind uwtable
define dso_local i64 @Udp4EnqueueDgram(ptr noundef readonly %0, ptr noundef %1, ptr noundef %2) local_unnamed_addr #0 {
  %4 = getelementptr inbounds i8, ptr %0, i64 40
  %.01620 = load ptr, ptr %4, align 8, !tbaa !5
  %.not21 = icmp eq ptr %.01620, %4
  br i1 %.not21, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %3
  %5 = getelementptr inbounds i8, ptr %2, i64 24
  %6 = getelementptr inbounds i8, ptr %1, i64 8
  br label %7

7:                                                ; preds = %.lr.ph, %24
  %.01623 = phi ptr [ %.01620, %.lr.ph ], [ %.016, %24 ]
  %.022 = phi i64 [ 0, %.lr.ph ], [ %.1, %24 ]
  %8 = ptrtoint ptr %.01623 to i64
  %9 = add i64 %8, -8
  %10 = inttoptr i64 %9 to ptr
  %11 = getelementptr inbounds i8, ptr %10, i64 144
  %12 = load i8, ptr %11, align 8, !tbaa !10
  %.not18 = icmp eq i8 %12, 0
  br i1 %.not18, label %24, label %13

13:                                               ; preds = %7
  %14 = tail call zeroext i8 @Udp4MatchDgram(ptr noundef nonnull %10, ptr noundef nonnull %5)
  %.not19 = icmp eq i8 %14, 0
  br i1 %.not19, label %24, label %15

15:                                               ; preds = %13
  %16 = tail call ptr @Udp4WrapRxData(ptr noundef nonnull %10, ptr noundef %1, ptr noundef %2)
  %17 = icmp eq ptr %16, null
  br i1 %17, label %24, label %18

18:                                               ; preds = %15
  %19 = load i64, ptr %6, align 8, !tbaa !19
  %20 = add nsw i64 %19, 1
  store i64 %20, ptr %6, align 8, !tbaa !19
  %21 = getelementptr inbounds i8, ptr %10, i64 272
  %22 = tail call ptr @InsertTailList(ptr noundef nonnull %21, ptr noundef nonnull %16) #2
  %23 = add i64 %.022, 1
  br label %24

24:                                               ; preds = %13, %18, %15, %7
  %.1 = phi i64 [ %.022, %15 ], [ %23, %18 ], [ %.022, %13 ], [ %.022, %7 ]
  %.016 = load ptr, ptr %.01623, align 8, !tbaa !5
  %.not = icmp eq ptr %.016, %4
  br i1 %.not, label %._crit_edge, label %7, !llvm.loop !21

._crit_edge:                                      ; preds = %24, %3
  %.0.lcssa = phi i64 [ 0, %3 ], [ %.1, %24 ]
  ret i64 %.0.lcssa
}

declare ptr @InsertTailList(ptr noundef, ptr noundef) local_unnamed_addr #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, !7, i64 0}
!6 = !{!"_LIST_ENTRY", !7, i64 0, !7, i64 8}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!11, !8, i64 144}
!11 = !{!"_UDP4_INSTANCE_DATA_", !12, i64 0, !6, i64 8, !7, i64 24, !13, i64 32, !14, i64 96, !7, i64 136, !8, i64 144, !8, i64 145, !17, i64 152, !17, i64 192, !17, i64 232, !6, i64 272, !6, i64 288, !16, i64 304, !18, i64 312, !7, i64 320, !8, i64 328}
!12 = !{!"int", !8, i64 0}
!13 = !{!"_EFI_UDP4_PROTOCOL", !7, i64 0, !7, i64 8, !7, i64 16, !7, i64 24, !7, i64 32, !7, i64 40, !7, i64 48, !7, i64 56}
!14 = !{!"", !8, i64 0, !8, i64 1, !8, i64 2, !8, i64 3, !8, i64 4, !8, i64 5, !8, i64 6, !12, i64 8, !12, i64 12, !8, i64 16, !15, i64 17, !15, i64 21, !16, i64 26, !15, i64 28, !16, i64 32}
!15 = !{!"", !8, i64 0}
!16 = !{!"short", !8, i64 0}
!17 = !{!"", !6, i64 0, !6, i64 16, !18, i64 32}
!18 = !{!"long long", !8, i64 0}
!19 = !{!20, !18, i64 8}
!20 = !{!"", !12, i64 0, !18, i64 8, !6, i64 16, !8, i64 32, !7, i64 40, !7, i64 48, !8, i64 56, !7, i64 120, !12, i64 128, !12, i64 132, !8, i64 136}
!21 = distinct !{!21, !22}
!22 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GVNPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LICMPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass