; LLVM IR from thalium/icebox :: third_party/virtualbox/src/VBox/Devices/EFI/Firmware/NetworkPkg/Ip6Dxe (Ip6InterfaceEnquePacket)

; 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.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] }
%struct._LIST_ENTRY = type { ptr, ptr }
%union.NET_IP_HEAD = type { ptr }
%struct.NET_BLOCK_OP = type { ptr, ptr, ptr, ptr, i32 }
%struct._IP6_INTERFACE = type { i32, %struct._LIST_ENTRY, i64, %struct._LIST_ENTRY, i32, i8, ptr, ptr, ptr, %struct._LIST_ENTRY, %struct._LIST_ENTRY, i32, %struct._LIST_ENTRY, %struct._LIST_ENTRY, %struct._LIST_ENTRY, i8 }
%struct.IP6_CLIP_INFO = type { i32, i32, i32, i32, i32, i32, i64, i32, i16, i8, i8, i32 }
%struct._IP6_PROTOCOL = type { i32, %struct._EFI_IP6_PROTOCOL, ptr, i64, ptr, %struct._LIST_ENTRY, i8, %struct.NET_MAP, %struct.NET_MAP, %struct._LIST_ENTRY, %struct._LIST_ENTRY, %struct.EFI_LOCK, ptr, %struct._LIST_ENTRY, ptr, i32, %struct.EFI_IP6_CONFIG_DATA, i8 }
%struct._EFI_IP6_PROTOCOL = type { ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr }
%struct.NET_MAP = type { %struct._LIST_ENTRY, %struct._LIST_ENTRY, i64 }
%struct.EFI_LOCK = type { i64, i64, i32 }
%struct.EFI_IP6_CONFIG_DATA = type { i8, i8, i8, i8, %struct.EFI_IPv6_ADDRESS, %struct.EFI_IPv6_ADDRESS, i8, i8, i32, i32, i32 }
%struct.EFI_IPv6_ADDRESS = type { [16 x i8] }

@.str = external hidden unnamed_addr constant [130 x i8], align 1
@.str.10 = external hidden unnamed_addr constant [119 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

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

declare zeroext i8 @DebugAssertEnabled() #1

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

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

; Function Attrs: nounwind uwtable
define dso_local i64 @Ip6InterfaceEnquePacket(ptr noundef %0, ptr noundef %1, ptr noundef %2, ptr noundef %3) #2 {
  %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 ptr, align 8
  %11 = alloca ptr, align 8
  %12 = alloca i64, align 8
  %13 = alloca i64, align 8
  %14 = alloca i64, align 8
  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
  store ptr %3, ptr %8, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #3
  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
  store i64 0, ptr %13, align 8, !tbaa !9
  %15 = load ptr, ptr %7, align 8, !tbaa !5
  %16 = getelementptr inbounds %struct.NET_BUF, ptr %15, i32 0, i32 6
  %17 = getelementptr inbounds [64 x i8], ptr %16, i64 0, i64 0
  store ptr %17, ptr %10, align 8, !tbaa !5
  %18 = load ptr, ptr %8, align 8, !tbaa !5
  %19 = getelementptr inbounds %struct._IP6_INTERFACE, ptr %18, i32 0, i32 15
  %20 = load i8, ptr %19, align 8, !tbaa !11
  %21 = icmp ne i8 %20, 0
  br i1 %21, label %22, label %23

22:                                               ; preds = %4
  store i64 1, ptr %13, align 8, !tbaa !9
  br label %28

23:                                               ; preds = %4
  %24 = load ptr, ptr %10, align 8, !tbaa !5
  %25 = getelementptr inbounds %struct.IP6_CLIP_INFO, ptr %24, i32 0, i32 1
  %26 = load i32, ptr %25, align 4, !tbaa !15
  %27 = sext i32 %26 to i64
  store i64 %27, ptr %13, align 8, !tbaa !9
  br label %28

28:                                               ; preds = %23, %22
  %29 = load ptr, ptr %10, align 8, !tbaa !5
  %30 = getelementptr inbounds %struct.IP6_CLIP_INFO, ptr %29, i32 0, i32 1
  %31 = load i32, ptr %30, align 4, !tbaa !15
  %32 = sext i32 %31 to i64
  store i64 %32, ptr %14, align 8, !tbaa !9
  %33 = load i64, ptr %13, align 8, !tbaa !9
  %34 = trunc i64 %33 to i32
  %35 = load ptr, ptr %10, align 8, !tbaa !5
  %36 = getelementptr inbounds %struct.IP6_CLIP_INFO, ptr %35, i32 0, i32 1
  store i32 %34, ptr %36, align 4, !tbaa !15
  store i64 0, ptr %12, align 8, !tbaa !9
  %37 = load ptr, ptr %8, align 8, !tbaa !5
  %38 = getelementptr inbounds %struct._IP6_INTERFACE, ptr %37, i32 0, i32 14
  %39 = getelementptr inbounds %struct._LIST_ENTRY, ptr %38, i32 0, i32 0
  %40 = load ptr, ptr %39, align 8, !tbaa !18
  store ptr %40, ptr %11, align 8, !tbaa !5
  br label %41

41:                                               ; preds = %76, %28
  %42 = load ptr, ptr %11, align 8, !tbaa !5
  %43 = load ptr, ptr %8, align 8, !tbaa !5
  %44 = getelementptr inbounds %struct._IP6_INTERFACE, ptr %43, i32 0, i32 14
  %45 = icmp ne ptr %42, %44
  br i1 %45, label %46, label %80

46:                                               ; preds = %41
  %47 = load ptr, ptr %11, align 8, !tbaa !5
  %48 = ptrtoint ptr %47 to i64
  %49 = sub i64 %48, ptrtoint (ptr getelementptr inbounds (%struct._IP6_PROTOCOL, ptr null, i32 0, i32 13) to i64)
  %50 = inttoptr i64 %49 to ptr
  store ptr %50, ptr %9, align 8, !tbaa !5
  br label %51

51:                                               ; preds = %46
  %52 = call zeroext i8 @DebugAssertEnabled()
  %53 = icmp ne i8 %52, 0
  br i1 %53, label %54, label %64

54:                                               ; preds = %51
  %55 = load ptr, ptr %9, align 8, !tbaa !5
  %56 = icmp ne ptr %55, null
  br i1 %56, label %57, label %62

57:                                               ; preds = %54
  %58 = load ptr, ptr %9, align 8, !tbaa !5
  %59 = getelementptr inbounds %struct._IP6_PROTOCOL, ptr %58, i32 0, i32 0
  %60 = load i32, ptr %59, align 8, !tbaa !19
  %61 = icmp eq i32 %60, 1345736777
  br i1 %61, label %63, label %62

62:                                               ; preds = %57, %54
  call void @DebugAssert(ptr noundef @.str, i64 noundef 1610, ptr noundef @.str.10)
  br label %63

63:                                               ; preds = %62, %57
  br label %64

64:                                               ; preds = %63, %51
  br label %65

65:                                               ; preds = %64
  br label %66

66:                                               ; preds = %65
  %67 = load ptr, ptr %9, align 8, !tbaa !5
  %68 = load ptr, ptr %6, align 8, !tbaa !5
  %69 = load ptr, ptr %7, align 8, !tbaa !5
  %70 = call i64 @Ip6InstanceEnquePacket(ptr noundef %67, ptr noundef %68, ptr noundef %69)
  %71 = icmp eq i64 %70, 0
  br i1 %71, label %72, label %75

72:                                               ; preds = %66
  %73 = load i64, ptr %12, align 8, !tbaa !9
  %74 = add nsw i64 %73, 1
  store i64 %74, ptr %12, align 8, !tbaa !9
  br label %75

75:                                               ; preds = %72, %66
  br label %76

76:                                               ; preds = %75
  %77 = load ptr, ptr %11, align 8, !tbaa !5
  %78 = getelementptr inbounds %struct._LIST_ENTRY, ptr %77, i32 0, i32 0
  %79 = load ptr, ptr %78, align 8, !tbaa !26
  store ptr %79, ptr %11, align 8, !tbaa !5
  br label %41, !llvm.loop !27

80:                                               ; preds = %41
  %81 = load i64, ptr %14, align 8, !tbaa !9
  %82 = trunc i64 %81 to i32
  %83 = load ptr, ptr %10, align 8, !tbaa !5
  %84 = getelementptr inbounds %struct.IP6_CLIP_INFO, ptr %83, i32 0, i32 1
  store i32 %82, ptr %84, align 4, !tbaa !15
  %85 = load i64, ptr %12, align 8, !tbaa !9
  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
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #3
  ret i64 %85
}

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 = !{!"long long", !7, i64 0}
!11 = !{!12, !7, i64 168}
!12 = !{!"_IP6_INTERFACE", !13, i64 0, !14, i64 8, !10, i64 24, !14, i64 32, !13, i64 48, !7, i64 52, !6, i64 56, !6, i64 64, !6, i64 72, !14, i64 80, !14, i64 96, !13, i64 112, !14, i64 120, !14, i64 136, !14, i64 152, !7, i64 168}
!13 = !{!"int", !7, i64 0}
!14 = !{!"_LIST_ENTRY", !6, i64 0, !6, i64 8}
!15 = !{!16, !13, i64 4}
!16 = !{!"", !13, i64 0, !13, i64 4, !13, i64 8, !13, i64 12, !13, i64 16, !13, i64 20, !10, i64 24, !13, i64 32, !17, i64 36, !7, i64 38, !7, i64 39, !13, i64 40}
!17 = !{!"short", !7, i64 0}
!18 = !{!12, !6, i64 152}
!19 = !{!20, !13, i64 0}
!20 = !{!"_IP6_PROTOCOL", !13, i64 0, !21, i64 8, !6, i64 80, !10, i64 88, !6, i64 96, !14, i64 104, !7, i64 120, !22, i64 128, !22, i64 168, !14, i64 208, !14, i64 224, !23, i64 240, !6, i64 264, !14, i64 272, !6, i64 288, !13, i64 296, !24, i64 300, !7, i64 352}
!21 = !{!"_EFI_IP6_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, !6, i64 64}
!22 = !{!"", !14, i64 0, !14, i64 16, !10, i64 32}
!23 = !{!"", !10, i64 0, !10, i64 8, !13, i64 16}
!24 = !{!"", !7, i64 0, !7, i64 1, !7, i64 2, !7, i64 3, !25, i64 4, !25, i64 20, !7, i64 36, !7, i64 37, !13, i64 40, !13, i64 44, !13, i64 48}
!25 = !{!"", !7, i64 0}
!26 = !{!14, !6, i64 0}
!27 = distinct !{!27, !28}
!28 = !{!"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 [130 x i8], align 1
@.str.10 = external hidden unnamed_addr constant [119 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 @Ip6InstanceEnquePacket(ptr noundef, ptr noundef, ptr noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
define dso_local i64 @Ip6InterfaceEnquePacket(ptr nocapture noundef readnone %0, ptr noundef %1, ptr noundef %2, ptr noundef readonly %3) local_unnamed_addr #1 {
  %5 = getelementptr inbounds i8, ptr %3, i64 168
  %6 = load i8, ptr %5, align 8, !tbaa !5
  %.not = icmp eq i8 %6, 0
  %7 = getelementptr inbounds i8, ptr %2, i64 60
  %8 = load i32, ptr %7, align 4, !tbaa !13
  %. = select i1 %.not, i32 %8, i32 1
  %9 = getelementptr inbounds i8, ptr %2, i64 60
  store i32 %., ptr %9, align 4, !tbaa !13
  %10 = getelementptr inbounds i8, ptr %3, i64 152
  %.025 = load ptr, ptr %10, align 8, !tbaa !16
  %.not2226 = icmp eq ptr %.025, %10
  br i1 %.not2226, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %4, %20
  %.028 = phi ptr [ %.0, %20 ], [ %.025, %4 ]
  %.02027 = phi i64 [ %spec.select, %20 ], [ 0, %4 ]
  %11 = ptrtoint ptr %.028 to i64
  %12 = add i64 %11, -272
  %13 = inttoptr i64 %12 to ptr
  %14 = tail call zeroext i8 @DebugAssertEnabled() #2
  %.not23 = icmp eq i8 %14, 0
  br i1 %.not23, label %20, label %15

15:                                               ; preds = %.lr.ph
  %.not24 = icmp eq i64 %12, 0
  br i1 %.not24, label %19, label %16

16:                                               ; preds = %15
  %17 = load i32, ptr %13, align 8, !tbaa !17
  %18 = icmp eq i32 %17, 1345736777
  br i1 %18, label %20, label %19

19:                                               ; preds = %16, %15
  tail call void @DebugAssert(ptr noundef nonnull @.str, i64 noundef 1610, ptr noundef nonnull @.str.10) #2
  br label %20

20:                                               ; preds = %16, %19, %.lr.ph
  %21 = tail call i64 @Ip6InstanceEnquePacket(ptr noundef %13, ptr noundef %1, ptr noundef %2)
  %22 = icmp eq i64 %21, 0
  %23 = zext i1 %22 to i64
  %spec.select = add nuw nsw i64 %.02027, %23
  %.0 = load ptr, ptr %.028, align 8, !tbaa !16
  %.not22 = icmp eq ptr %.0, %10
  br i1 %.not22, label %._crit_edge, label %.lr.ph, !llvm.loop !24

._crit_edge:                                      ; preds = %20, %4
  %.020.lcssa = phi i64 [ 0, %4 ], [ %spec.select, %20 ]
  store i32 %8, ptr %9, align 4, !tbaa !13
  ret i64 %.020.lcssa
}

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, !8, i64 168}
!6 = !{!"_IP6_INTERFACE", !7, i64 0, !10, i64 8, !12, i64 24, !10, i64 32, !7, i64 48, !8, i64 52, !11, i64 56, !11, i64 64, !11, i64 72, !10, i64 80, !10, i64 96, !7, i64 112, !10, i64 120, !10, i64 136, !10, i64 152, !8, i64 168}
!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 = !{!"long long", !8, i64 0}
!13 = !{!14, !7, i64 4}
!14 = !{!"", !7, i64 0, !7, i64 4, !7, i64 8, !7, i64 12, !7, i64 16, !7, i64 20, !12, i64 24, !7, i64 32, !15, i64 36, !8, i64 38, !8, i64 39, !7, i64 40}
!15 = !{!"short", !8, i64 0}
!16 = !{!10, !11, i64 0}
!17 = !{!18, !7, i64 0}
!18 = !{!"_IP6_PROTOCOL", !7, i64 0, !19, i64 8, !11, i64 80, !12, i64 88, !11, i64 96, !10, i64 104, !8, i64 120, !20, i64 128, !20, i64 168, !10, i64 208, !10, i64 224, !21, i64 240, !11, i64 264, !10, i64 272, !11, i64 288, !7, i64 296, !22, i64 300, !8, i64 352}
!19 = !{!"_EFI_IP6_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, !11, i64 64}
!20 = !{!"", !10, i64 0, !10, i64 16, !12, i64 32}
!21 = !{!"", !12, i64 0, !12, i64 8, !7, i64 16}
!22 = !{!"", !8, i64 0, !8, i64 1, !8, i64 2, !8, i64 3, !23, i64 4, !23, i64 20, !8, i64 36, !8, i64 37, !7, i64 40, !7, i64 44, !7, i64 48}
!23 = !{!"", !8, i64 0}
!24 = distinct !{!24, !25}
!25 = !{!"llvm.loop.mustprogress"}


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