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

; 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._IP4_SERVICE = type { i32, %struct._EFI_SERVICE_BINDING_PROTOCOL, i64, i64, %struct._LIST_ENTRY, %struct._LIST_ENTRY, ptr, ptr, %struct.IP4_ASSEMBLE_TABLE, %struct.IGMP_SERVICE_DATA, ptr, ptr, ptr, ptr, %struct.EFI_MANAGED_NETWORK_CONFIG_DATA, %struct.EFI_SIMPLE_NETWORK_MODE, ptr, ptr, ptr, ptr, ptr, i32, i32 }
%struct._EFI_SERVICE_BINDING_PROTOCOL = type { ptr, ptr }
%struct._LIST_ENTRY = type { ptr, ptr }
%struct.IP4_ASSEMBLE_TABLE = type { [31 x %struct._LIST_ENTRY] }
%struct.IGMP_SERVICE_DATA = type { i64, %struct._LIST_ENTRY }
%struct.EFI_MANAGED_NETWORK_CONFIG_DATA = type { i32, i32, i16, i8, i8, i8, i8, i8, i8, 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 }
%struct.EFI_MAC_ADDRESS = type { [32 x i8] }
%struct._IP4_INTERFACE = type { i32, %struct._LIST_ENTRY, i64, i32, i32, i32, i32, i8, ptr, ptr, ptr, ptr, ptr, %struct._LIST_ENTRY, %struct._LIST_ENTRY, ptr, %struct.EFI_MAC_ADDRESS, %struct.EFI_MAC_ADDRESS, i32, %struct._LIST_ENTRY, i8 }

; 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

declare void @NetbufFree(ptr noundef) #1

; Function Attrs: nounwind uwtable
define dso_local i64 @Ip4Demultiplex(ptr noundef %0, ptr noundef %1, ptr noundef %2, ptr noundef %3, i32 noundef %4) #2 {
  %6 = alloca i64, align 8
  %7 = alloca ptr, align 8
  %8 = alloca ptr, align 8
  %9 = alloca ptr, align 8
  %10 = alloca ptr, align 8
  %11 = alloca i32, align 4
  %12 = alloca ptr, align 8
  %13 = alloca ptr, align 8
  %14 = alloca i64, align 8
  %15 = alloca i32, align 4
  store ptr %0, ptr %7, align 8, !tbaa !5
  store ptr %1, ptr %8, align 8, !tbaa !5
  store ptr %2, ptr %9, align 8, !tbaa !5
  store ptr %3, ptr %10, align 8, !tbaa !5
  store i32 %4, ptr %11, align 4, !tbaa !9
  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
  store i64 0, ptr %14, align 8, !tbaa !11
  %16 = load ptr, ptr %7, align 8, !tbaa !5
  %17 = getelementptr inbounds %struct._IP4_SERVICE, ptr %16, i32 0, i32 5
  %18 = getelementptr inbounds %struct._LIST_ENTRY, ptr %17, i32 0, i32 0
  %19 = load ptr, ptr %18, align 8, !tbaa !13
  store ptr %19, ptr %12, align 8, !tbaa !5
  br label %20

20:                                               ; preds = %45, %5
  %21 = load ptr, ptr %12, align 8, !tbaa !5
  %22 = load ptr, ptr %7, align 8, !tbaa !5
  %23 = getelementptr inbounds %struct._IP4_SERVICE, ptr %22, i32 0, i32 5
  %24 = icmp ne ptr %21, %23
  br i1 %24, label %25, label %49

25:                                               ; preds = %20
  %26 = load ptr, ptr %12, align 8, !tbaa !5
  %27 = ptrtoint ptr %26 to i64
  %28 = sub i64 %27, ptrtoint (ptr getelementptr inbounds (%struct._IP4_INTERFACE, ptr null, i32 0, i32 1) to i64)
  %29 = inttoptr i64 %28 to ptr
  store ptr %29, ptr %13, align 8, !tbaa !5
  %30 = load ptr, ptr %13, align 8, !tbaa !5
  %31 = getelementptr inbounds %struct._IP4_INTERFACE, ptr %30, i32 0, i32 7
  %32 = load i8, ptr %31, align 8, !tbaa !22
  %33 = icmp ne i8 %32, 0
  br i1 %33, label %34, label %44

34:                                               ; preds = %25
  %35 = load ptr, ptr %7, align 8, !tbaa !5
  %36 = load ptr, ptr %8, align 8, !tbaa !5
  %37 = load ptr, ptr %9, align 8, !tbaa !5
  %38 = load ptr, ptr %10, align 8, !tbaa !5
  %39 = load i32, ptr %11, align 4, !tbaa !9
  %40 = load ptr, ptr %13, align 8, !tbaa !5
  %41 = call i64 @Ip4InterfaceEnquePacket(ptr noundef %35, ptr noundef %36, ptr noundef %37, ptr noundef %38, i32 noundef %39, ptr noundef %40)
  %42 = load i64, ptr %14, align 8, !tbaa !11
  %43 = add nsw i64 %42, %41
  store i64 %43, ptr %14, align 8, !tbaa !11
  br label %44

44:                                               ; preds = %34, %25
  br label %45

45:                                               ; preds = %44
  %46 = load ptr, ptr %12, align 8, !tbaa !5
  %47 = getelementptr inbounds %struct._LIST_ENTRY, ptr %46, i32 0, i32 0
  %48 = load ptr, ptr %47, align 8, !tbaa !24
  store ptr %48, ptr %12, align 8, !tbaa !5
  br label %20, !llvm.loop !25

49:                                               ; preds = %20
  %50 = load ptr, ptr %9, align 8, !tbaa !5
  call void @NetbufFree(ptr noundef %50)
  %51 = load i64, ptr %14, align 8, !tbaa !11
  %52 = icmp eq i64 %51, 0
  br i1 %52, label %53, label %54

53:                                               ; preds = %49
  store i64 -9223372036854775794, ptr %6, align 8
  store i32 1, ptr %15, align 4
  br label %83

54:                                               ; preds = %49
  %55 = load ptr, ptr %7, align 8, !tbaa !5
  %56 = getelementptr inbounds %struct._IP4_SERVICE, ptr %55, i32 0, i32 5
  %57 = getelementptr inbounds %struct._LIST_ENTRY, ptr %56, i32 0, i32 0
  %58 = load ptr, ptr %57, align 8, !tbaa !13
  store ptr %58, ptr %12, align 8, !tbaa !5
  br label %59

59:                                               ; preds = %78, %54
  %60 = load ptr, ptr %12, align 8, !tbaa !5
  %61 = load ptr, ptr %7, align 8, !tbaa !5
  %62 = getelementptr inbounds %struct._IP4_SERVICE, ptr %61, i32 0, i32 5
  %63 = icmp ne ptr %60, %62
  br i1 %63, label %64, label %82

64:                                               ; preds = %59
  %65 = load ptr, ptr %12, align 8, !tbaa !5
  %66 = ptrtoint ptr %65 to i64
  %67 = sub i64 %66, ptrtoint (ptr getelementptr inbounds (%struct._IP4_INTERFACE, ptr null, i32 0, i32 1) to i64)
  %68 = inttoptr i64 %67 to ptr
  store ptr %68, ptr %13, align 8, !tbaa !5
  %69 = load ptr, ptr %13, align 8, !tbaa !5
  %70 = getelementptr inbounds %struct._IP4_INTERFACE, ptr %69, i32 0, i32 7
  %71 = load i8, ptr %70, align 8, !tbaa !22
  %72 = icmp ne i8 %71, 0
  br i1 %72, label %73, label %77

73:                                               ; preds = %64
  %74 = load ptr, ptr %7, align 8, !tbaa !5
  %75 = load ptr, ptr %13, align 8, !tbaa !5
  %76 = call i64 @Ip4InterfaceDeliverPacket(ptr noundef %74, ptr noundef %75)
  br label %77

77:                                               ; preds = %73, %64
  br label %78

78:                                               ; preds = %77
  %79 = load ptr, ptr %12, align 8, !tbaa !5
  %80 = getelementptr inbounds %struct._LIST_ENTRY, ptr %79, i32 0, i32 0
  %81 = load ptr, ptr %80, align 8, !tbaa !24
  store ptr %81, ptr %12, align 8, !tbaa !5
  br label %59, !llvm.loop !27

82:                                               ; preds = %59
  store i64 0, ptr %6, align 8
  store i32 1, ptr %15, align 4
  br label %83

83:                                               ; preds = %82, %53
  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
  %84 = load i64, ptr %6, align 8
  ret i64 %84
}

; Function Attrs: nounwind uwtable
declare dso_local i64 @Ip4InterfaceEnquePacket(ptr noundef, ptr noundef, ptr noundef, ptr noundef, i32 noundef, ptr noundef) #2

; Function Attrs: nounwind uwtable
declare dso_local i64 @Ip4InterfaceDeliverPacket(ptr noundef, ptr noundef) #2

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, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"long long", !7, i64 0}
!13 = !{!14, !6, i64 56}
!14 = !{!"_IP4_SERVICE", !10, i64 0, !15, i64 8, !12, i64 24, !12, i64 32, !16, i64 40, !16, i64 56, !6, i64 72, !6, i64 80, !17, i64 88, !18, i64 584, !6, i64 608, !6, i64 616, !6, i64 624, !6, i64 632, !19, i64 640, !21, i64 660, !6, i64 1320, !6, i64 1328, !6, i64 1336, !6, i64 1344, !6, i64 1352, !10, i64 1360, !10, i64 1364}
!15 = !{!"_EFI_SERVICE_BINDING_PROTOCOL", !6, i64 0, !6, i64 8}
!16 = !{!"_LIST_ENTRY", !6, i64 0, !6, i64 8}
!17 = !{!"", !7, i64 0}
!18 = !{!"", !12, i64 0, !16, i64 8}
!19 = !{!"", !10, i64 0, !10, i64 4, !20, i64 8, !7, i64 10, !7, i64 11, !7, i64 12, !7, i64 13, !7, i64 14, !7, i64 15, !7, i64 16}
!20 = !{!"short", !7, i64 0}
!21 = !{!"", !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, !17, i64 552, !17, i64 584, !17, i64 616, !7, i64 648, !7, i64 649, !7, i64 650, !7, i64 651, !7, i64 652}
!22 = !{!23, !7, i64 48}
!23 = !{!"_IP4_INTERFACE", !10, i64 0, !16, i64 8, !12, i64 24, !10, i64 32, !10, i64 36, !10, i64 40, !10, i64 44, !7, i64 48, !6, i64 56, !6, i64 64, !6, i64 72, !6, i64 80, !6, i64 88, !16, i64 96, !16, i64 112, !6, i64 128, !17, i64 136, !17, i64 168, !10, i64 200, !16, i64 208, !7, i64 224}
!24 = !{!16, !6, i64 0}
!25 = distinct !{!25, !26}
!26 = !{!"llvm.loop.mustprogress"}
!27 = distinct !{!27, !26}


; 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 void @NetbufFree(ptr noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local range(i64 -9223372036854775794, 1) i64 @Ip4Demultiplex(ptr noundef %0, ptr noundef %1, ptr noundef %2, ptr noundef %3, i32 noundef %4) local_unnamed_addr #1 {
  %6 = getelementptr inbounds i8, ptr %0, i64 56
  %.02330 = load ptr, ptr %6, align 8, !tbaa !5
  %.not31 = icmp eq ptr %.02330, %6
  br i1 %.not31, label %._crit_edge.thread, label %.lr.ph

._crit_edge.thread:                               ; preds = %5
  tail call void @NetbufFree(ptr noundef %2) #2
  br label %.loopexit

.lr.ph:                                           ; preds = %5, %15
  %.02333 = phi ptr [ %.023, %15 ], [ %.02330, %5 ]
  %.032 = phi i64 [ %.1, %15 ], [ 0, %5 ]
  %7 = ptrtoint ptr %.02333 to i64
  %8 = add i64 %7, -8
  %9 = inttoptr i64 %8 to ptr
  %10 = getelementptr inbounds i8, ptr %9, i64 48
  %11 = load i8, ptr %10, align 8, !tbaa !10
  %.not29 = icmp eq i8 %11, 0
  br i1 %.not29, label %15, label %12

12:                                               ; preds = %.lr.ph
  %13 = tail call i64 @Ip4InterfaceEnquePacket(ptr noundef %0, ptr noundef %1, ptr noundef %2, ptr noundef %3, i32 noundef %4, ptr noundef nonnull %9)
  %14 = add nsw i64 %13, %.032
  br label %15

15:                                               ; preds = %.lr.ph, %12
  %.1 = phi i64 [ %14, %12 ], [ %.032, %.lr.ph ]
  %.023 = load ptr, ptr %.02333, align 8, !tbaa !5
  %.not = icmp eq ptr %.023, %6
  br i1 %.not, label %._crit_edge, label %.lr.ph, !llvm.loop !15

._crit_edge:                                      ; preds = %15
  %16 = icmp eq i64 %.1, 0
  tail call void @NetbufFree(ptr noundef %2) #2
  br i1 %16, label %.loopexit, label %.preheader

.preheader:                                       ; preds = %._crit_edge
  %.12434 = load ptr, ptr %6, align 8, !tbaa !5
  %.not2735 = icmp eq ptr %.12434, %6
  br i1 %.not2735, label %.loopexit, label %.lr.ph37

.lr.ph37:                                         ; preds = %.preheader, %24
  %.12436 = phi ptr [ %.124, %24 ], [ %.12434, %.preheader ]
  %17 = ptrtoint ptr %.12436 to i64
  %18 = add i64 %17, -8
  %19 = inttoptr i64 %18 to ptr
  %20 = getelementptr inbounds i8, ptr %19, i64 48
  %21 = load i8, ptr %20, align 8, !tbaa !10
  %.not28 = icmp eq i8 %21, 0
  br i1 %.not28, label %24, label %22

22:                                               ; preds = %.lr.ph37
  %23 = tail call i64 @Ip4InterfaceDeliverPacket(ptr noundef %0, ptr noundef nonnull %19)
  br label %24

24:                                               ; preds = %.lr.ph37, %22
  %.124 = load ptr, ptr %.12436, align 8, !tbaa !5
  %.not27 = icmp eq ptr %.124, %6
  br i1 %.not27, label %.loopexit, label %.lr.ph37, !llvm.loop !17

.loopexit:                                        ; preds = %24, %._crit_edge.thread, %.preheader, %._crit_edge
  %.025 = phi i64 [ -9223372036854775794, %._crit_edge ], [ 0, %.preheader ], [ -9223372036854775794, %._crit_edge.thread ], [ 0, %24 ]
  ret i64 %.025
}

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

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

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 = !{!"_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 48}
!11 = !{!"_IP4_INTERFACE", !12, i64 0, !6, i64 8, !13, i64 24, !12, i64 32, !12, i64 36, !12, i64 40, !12, i64 44, !8, i64 48, !7, i64 56, !7, i64 64, !7, i64 72, !7, i64 80, !7, i64 88, !6, i64 96, !6, i64 112, !7, i64 128, !14, i64 136, !14, i64 168, !12, i64 200, !6, i64 208, !8, i64 224}
!12 = !{!"int", !8, i64 0}
!13 = !{!"long long", !8, i64 0}
!14 = !{!"", !8, i64 0}
!15 = distinct !{!15, !16}
!16 = !{!"llvm.loop.mustprogress"}
!17 = distinct !{!17, !16}


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