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

; 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.EFI_UDP6_COMPLETION_TOKEN = type { ptr, i64, %union.anon.1 }
%union.anon.1 = type { ptr }
%struct._UDP6_INSTANCE_DATA = type { i32, %struct._LIST_ENTRY, ptr, %struct._EFI_UDP6_PROTOCOL, %struct.EFI_UDP6_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_UDP6_PROTOCOL = type { ptr, ptr, ptr, ptr, ptr, ptr, ptr }
%struct.EFI_UDP6_CONFIG_DATA = type { i8, i8, i8, i8, i8, i32, i32, %struct.EFI_IPv6_ADDRESS, i16, %struct.EFI_IPv6_ADDRESS, i16 }
%struct.EFI_IPv6_ADDRESS = type { [16 x i8] }
%struct.NET_MAP = type { %struct._LIST_ENTRY, %struct._LIST_ENTRY, i64 }
%struct._LIST_ENTRY = type { ptr, ptr }
%struct.EFI_BOOT_SERVICES = type { %struct.EFI_TABLE_HEADER, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr }
%struct.EFI_TABLE_HEADER = type { i64, i32, i32, i32, i32 }

@.str = external hidden unnamed_addr constant [131 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [21 x i8], align 1
@gBS = external global ptr, align 8

; Function Attrs: nounwind uwtable
define dso_local i64 @Udp6Receive(ptr noundef %0, ptr noundef %1) #0 {
  %3 = alloca i64, align 8
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca i64, align 8
  %7 = alloca ptr, align 8
  %8 = alloca i64, align 8
  %9 = alloca i32, align 4
  store ptr %0, ptr %4, align 8, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #3
  %10 = load ptr, ptr %4, align 8, !tbaa !5
  %11 = icmp eq ptr %10, null
  br i1 %11, label %20, label %12

12:                                               ; preds = %2
  %13 = load ptr, ptr %5, align 8, !tbaa !5
  %14 = icmp eq ptr %13, null
  br i1 %14, label %20, label %15

15:                                               ; preds = %12
  %16 = load ptr, ptr %5, align 8, !tbaa !5
  %17 = getelementptr inbounds %struct.EFI_UDP6_COMPLETION_TOKEN, ptr %16, i32 0, i32 0
  %18 = load ptr, ptr %17, align 8, !tbaa !9
  %19 = icmp eq ptr %18, null
  br i1 %19, label %20, label %21

20:                                               ; preds = %15, %12, %2
  store i64 -9223372036854775806, ptr %3, align 8
  store i32 1, ptr %9, align 4
  br label %84

21:                                               ; preds = %15
  %22 = call zeroext i8 @DebugAssertEnabled()
  %23 = zext i8 %22 to i32
  %24 = icmp ne i32 %23, 0
  br i1 %24, label %25, label %35

25:                                               ; preds = %21
  %26 = load ptr, ptr %4, align 8, !tbaa !5
  %27 = ptrtoint ptr %26 to i64
  %28 = sub i64 %27, ptrtoint (ptr getelementptr inbounds (%struct._UDP6_INSTANCE_DATA, ptr null, i32 0, i32 3) to i64)
  %29 = inttoptr i64 %28 to ptr
  %30 = getelementptr inbounds %struct._UDP6_INSTANCE_DATA, ptr %29, i32 0, i32 0
  %31 = load i32, ptr %30, align 8, !tbaa !12
  %32 = icmp ne i32 %31, 1399874645
  br i1 %32, label %33, label %35

33:                                               ; preds = %25
  call void @DebugAssert(ptr noundef @.str, i64 noundef 705, ptr noundef @.str.1)
  %34 = load ptr, ptr %4, align 8, !tbaa !5
  br label %40

35:                                               ; preds = %25, %21
  %36 = load ptr, ptr %4, align 8, !tbaa !5
  %37 = ptrtoint ptr %36 to i64
  %38 = sub i64 %37, ptrtoint (ptr getelementptr inbounds (%struct._UDP6_INSTANCE_DATA, ptr null, i32 0, i32 3) to i64)
  %39 = inttoptr i64 %38 to ptr
  br label %40

40:                                               ; preds = %35, %33
  %41 = phi ptr [ %34, %33 ], [ %39, %35 ]
  store ptr %41, ptr %7, align 8, !tbaa !5
  %42 = load ptr, ptr %7, align 8, !tbaa !5
  %43 = getelementptr inbounds %struct._UDP6_INSTANCE_DATA, ptr %42, i32 0, i32 6
  %44 = load i8, ptr %43, align 8, !tbaa !21
  %45 = icmp ne i8 %44, 0
  br i1 %45, label %47, label %46

46:                                               ; preds = %40
  store i64 -9223372036854775789, ptr %3, align 8
  store i32 1, ptr %9, align 4
  br label %84

47:                                               ; preds = %40
  %48 = load ptr, ptr @gBS, align 8, !tbaa !5
  %49 = getelementptr inbounds %struct.EFI_BOOT_SERVICES, ptr %48, i32 0, i32 1
  %50 = load ptr, ptr %49, align 8, !tbaa !22
  %51 = call i64 %50(i64 noundef 8)
  store i64 %51, ptr %8, align 8, !tbaa !25
  %52 = load ptr, ptr %7, align 8, !tbaa !5
  %53 = getelementptr inbounds %struct._UDP6_INSTANCE_DATA, ptr %52, i32 0, i32 9
  %54 = load ptr, ptr %5, align 8, !tbaa !5
  %55 = call i64 @NetMapIterate(ptr noundef %53, ptr noundef @Udp6TokenExist, ptr noundef %54)
  %56 = icmp slt i64 %55, 0
  br i1 %56, label %63, label %57

57:                                               ; preds = %47
  %58 = load ptr, ptr %7, align 8, !tbaa !5
  %59 = getelementptr inbounds %struct._UDP6_INSTANCE_DATA, ptr %58, i32 0, i32 8
  %60 = load ptr, ptr %5, align 8, !tbaa !5
  %61 = call i64 @NetMapIterate(ptr noundef %59, ptr noundef @Udp6TokenExist, ptr noundef %60)
  %62 = icmp slt i64 %61, 0
  br i1 %62, label %63, label %64

63:                                               ; preds = %57, %47
  store i64 -9223372036854775793, ptr %6, align 8, !tbaa !25
  br label %78

64:                                               ; preds = %57
  %65 = load ptr, ptr %5, align 8, !tbaa !5
  %66 = getelementptr inbounds %struct.EFI_UDP6_COMPLETION_TOKEN, ptr %65, i32 0, i32 2
  store ptr null, ptr %66, align 8, !tbaa !26
  %67 = load ptr, ptr %7, align 8, !tbaa !5
  %68 = getelementptr inbounds %struct._UDP6_INSTANCE_DATA, ptr %67, i32 0, i32 9
  %69 = load ptr, ptr %5, align 8, !tbaa !5
  %70 = call i64 @NetMapInsertTail(ptr noundef %68, ptr noundef %69, ptr noundef null)
  store i64 %70, ptr %6, align 8, !tbaa !25
  %71 = load i64, ptr %6, align 8, !tbaa !25
  %72 = icmp slt i64 %71, 0
  br i1 %72, label %73, label %74

73:                                               ; preds = %64
  store i64 -9223372036854775802, ptr %6, align 8, !tbaa !25
  br label %78

74:                                               ; preds = %64
  %75 = load ptr, ptr %7, align 8, !tbaa !5
  call void @Udp6ReportIcmpError(ptr noundef %75)
  %76 = load ptr, ptr %7, align 8, !tbaa !5
  call void @Udp6InstanceDeliverDgram(ptr noundef %76)
  %77 = call i64 @DispatchDpc()
  br label %78

78:                                               ; preds = %74, %73, %63
  %79 = load ptr, ptr @gBS, align 8, !tbaa !5
  %80 = getelementptr inbounds %struct.EFI_BOOT_SERVICES, ptr %79, i32 0, i32 2
  %81 = load ptr, ptr %80, align 8, !tbaa !27
  %82 = load i64, ptr %8, align 8, !tbaa !25
  call void %81(i64 noundef %82)
  %83 = load i64, ptr %6, align 8, !tbaa !25
  store i64 %83, ptr %3, align 8
  store i32 1, ptr %9, align 4
  br label %84

84:                                               ; preds = %78, %46, %20
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #3
  %85 = load i64, ptr %3, align 8
  ret i64 %85
}

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

declare zeroext i8 @DebugAssertEnabled() #2

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

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

declare i64 @NetMapInsertTail(ptr noundef, ptr noundef, ptr noundef) #2

declare i64 @NetMapIterate(ptr noundef, ptr noundef, ptr noundef) #2

declare i64 @Udp6TokenExist(ptr noundef, ptr noundef, ptr noundef) #2

declare void @Udp6ReportIcmpError(ptr noundef) #2

declare void @Udp6InstanceDeliverDgram(ptr noundef) #2

declare i64 @DispatchDpc() #2

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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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, !6, i64 0}
!10 = !{!"", !6, i64 0, !11, i64 8, !7, i64 16}
!11 = !{!"long long", !7, i64 0}
!12 = !{!13, !14, i64 0}
!13 = !{!"_UDP6_INSTANCE_DATA", !14, i64 0, !15, i64 8, !6, i64 24, !16, i64 32, !17, i64 88, !6, i64 144, !7, i64 152, !7, i64 153, !20, i64 160, !20, i64 200, !20, i64 240, !15, i64 280, !15, i64 296, !19, i64 312, !11, i64 320, !6, i64 328, !7, i64 336}
!14 = !{!"int", !7, i64 0}
!15 = !{!"_LIST_ENTRY", !6, i64 0, !6, i64 8}
!16 = !{!"_EFI_UDP6_PROTOCOL", !6, i64 0, !6, i64 8, !6, i64 16, !6, i64 24, !6, i64 32, !6, i64 40, !6, i64 48}
!17 = !{!"", !7, i64 0, !7, i64 1, !7, i64 2, !7, i64 3, !7, i64 4, !14, i64 8, !14, i64 12, !18, i64 16, !19, i64 32, !18, i64 34, !19, i64 50}
!18 = !{!"", !7, i64 0}
!19 = !{!"short", !7, i64 0}
!20 = !{!"", !15, i64 0, !15, i64 16, !11, i64 32}
!21 = !{!13, !7, i64 152}
!22 = !{!23, !6, i64 24}
!23 = !{!"", !24, i64 0, !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, !6, i64 128, !6, i64 136, !6, i64 144, !6, i64 152, !6, i64 160, !6, i64 168, !6, i64 176, !6, i64 184, !6, i64 192, !6, i64 200, !6, i64 208, !6, i64 216, !6, i64 224, !6, i64 232, !6, i64 240, !6, i64 248, !6, i64 256, !6, i64 264, !6, i64 272, !6, i64 280, !6, i64 288, !6, i64 296, !6, i64 304, !6, i64 312, !6, i64 320, !6, i64 328, !6, i64 336, !6, i64 344, !6, i64 352, !6, i64 360, !6, i64 368}
!24 = !{!"", !11, i64 0, !14, i64 8, !14, i64 12, !14, i64 16, !14, i64 20}
!25 = !{!11, !11, i64 0}
!26 = !{!7, !7, i64 0}
!27 = !{!23, !6, i64 32}


; 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 [131 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [21 x i8], align 1
@gBS = external local_unnamed_addr global ptr, align 8

; Function Attrs: nounwind uwtable
define dso_local range(i64 0, -9223372036854775788) i64 @Udp6Receive(ptr noundef %0, ptr noundef %1) local_unnamed_addr #0 {
  %3 = icmp eq ptr %0, null
  %4 = icmp eq ptr %1, null
  %or.cond = or i1 %3, %4
  br i1 %or.cond, label %38, label %5

5:                                                ; preds = %2
  %6 = load ptr, ptr %1, align 8, !tbaa !5
  %7 = icmp eq ptr %6, null
  br i1 %7, label %38, label %8

8:                                                ; preds = %5
  %9 = tail call zeroext i8 @DebugAssertEnabled() #2
  %.not = icmp eq i8 %9, 0
  %.pre = ptrtoint ptr %0 to i64
  %.pre26 = add i64 %.pre, -32
  %.pre28 = inttoptr i64 %.pre26 to ptr
  br i1 %.not, label %._crit_edge, label %10

10:                                               ; preds = %8
  %11 = load i32, ptr %.pre28, align 8, !tbaa !11
  %.not24 = icmp eq i32 %11, 1399874645
  br i1 %.not24, label %._crit_edge, label %12

12:                                               ; preds = %10
  tail call void @DebugAssert(ptr noundef nonnull @.str, i64 noundef 705, ptr noundef nonnull @.str.1) #2
  br label %._crit_edge

._crit_edge:                                      ; preds = %8, %10, %12
  %13 = phi ptr [ %0, %12 ], [ %.pre28, %10 ], [ %.pre28, %8 ]
  %14 = getelementptr inbounds i8, ptr %13, i64 152
  %15 = load i8, ptr %14, align 8, !tbaa !20
  %.not25 = icmp eq i8 %15, 0
  br i1 %.not25, label %38, label %16

16:                                               ; preds = %._crit_edge
  %17 = load ptr, ptr @gBS, align 8, !tbaa !21
  %18 = getelementptr inbounds i8, ptr %17, i64 24
  %19 = load ptr, ptr %18, align 8, !tbaa !22
  %20 = tail call i64 %19(i64 noundef 8) #2
  %21 = getelementptr inbounds i8, ptr %13, i64 200
  %22 = tail call i64 @NetMapIterate(ptr noundef nonnull %21, ptr noundef nonnull @Udp6TokenExist, ptr noundef nonnull %1) #2
  %23 = icmp slt i64 %22, 0
  br i1 %23, label %34, label %24

24:                                               ; preds = %16
  %25 = getelementptr inbounds i8, ptr %13, i64 160
  %26 = tail call i64 @NetMapIterate(ptr noundef nonnull %25, ptr noundef nonnull @Udp6TokenExist, ptr noundef nonnull %1) #2
  %27 = icmp slt i64 %26, 0
  br i1 %27, label %34, label %28

28:                                               ; preds = %24
  %29 = getelementptr inbounds i8, ptr %1, i64 16
  store ptr null, ptr %29, align 8, !tbaa !25
  %30 = tail call i64 @NetMapInsertTail(ptr noundef nonnull %21, ptr noundef nonnull %1, ptr noundef null) #2
  %31 = icmp slt i64 %30, 0
  br i1 %31, label %34, label %32

32:                                               ; preds = %28
  tail call void @Udp6ReportIcmpError(ptr noundef nonnull %13) #2
  tail call void @Udp6InstanceDeliverDgram(ptr noundef nonnull %13) #2
  %33 = tail call i64 @DispatchDpc() #2
  br label %34

34:                                               ; preds = %28, %16, %24, %32
  %.020 = phi i64 [ %30, %32 ], [ -9223372036854775793, %24 ], [ -9223372036854775793, %16 ], [ -9223372036854775802, %28 ]
  %35 = load ptr, ptr @gBS, align 8, !tbaa !21
  %36 = getelementptr inbounds i8, ptr %35, i64 32
  %37 = load ptr, ptr %36, align 8, !tbaa !26
  tail call void %37(i64 noundef %20) #2
  br label %38

38:                                               ; preds = %._crit_edge, %2, %5, %34
  %.0 = phi i64 [ %.020, %34 ], [ -9223372036854775806, %5 ], [ -9223372036854775806, %2 ], [ -9223372036854775789, %._crit_edge ]
  ret i64 %.0
}

declare zeroext i8 @DebugAssertEnabled() local_unnamed_addr #1

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

declare i64 @NetMapInsertTail(ptr noundef, ptr noundef, ptr noundef) local_unnamed_addr #1

declare i64 @NetMapIterate(ptr noundef, ptr noundef, ptr noundef) local_unnamed_addr #1

declare i64 @Udp6TokenExist(ptr noundef, ptr noundef, ptr noundef) #1

declare void @Udp6ReportIcmpError(ptr noundef) local_unnamed_addr #1

declare void @Udp6InstanceDeliverDgram(ptr noundef) local_unnamed_addr #1

declare i64 @DispatchDpc() 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 = !{!"", !7, i64 0, !10, i64 8, !8, i64 16}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"long long", !8, i64 0}
!11 = !{!12, !13, i64 0}
!12 = !{!"_UDP6_INSTANCE_DATA", !13, i64 0, !14, i64 8, !7, i64 24, !15, i64 32, !16, i64 88, !7, i64 144, !8, i64 152, !8, i64 153, !19, i64 160, !19, i64 200, !19, i64 240, !14, i64 280, !14, i64 296, !18, i64 312, !10, i64 320, !7, i64 328, !8, i64 336}
!13 = !{!"int", !8, i64 0}
!14 = !{!"_LIST_ENTRY", !7, i64 0, !7, i64 8}
!15 = !{!"_EFI_UDP6_PROTOCOL", !7, i64 0, !7, i64 8, !7, i64 16, !7, i64 24, !7, i64 32, !7, i64 40, !7, i64 48}
!16 = !{!"", !8, i64 0, !8, i64 1, !8, i64 2, !8, i64 3, !8, i64 4, !13, i64 8, !13, i64 12, !17, i64 16, !18, i64 32, !17, i64 34, !18, i64 50}
!17 = !{!"", !8, i64 0}
!18 = !{!"short", !8, i64 0}
!19 = !{!"", !14, i64 0, !14, i64 16, !10, i64 32}
!20 = !{!12, !8, i64 152}
!21 = !{!7, !7, i64 0}
!22 = !{!23, !7, i64 24}
!23 = !{!"", !24, i64 0, !7, i64 24, !7, i64 32, !7, i64 40, !7, i64 48, !7, i64 56, !7, i64 64, !7, i64 72, !7, i64 80, !7, i64 88, !7, i64 96, !7, i64 104, !7, i64 112, !7, i64 120, !7, i64 128, !7, i64 136, !7, i64 144, !7, i64 152, !7, i64 160, !7, i64 168, !7, i64 176, !7, i64 184, !7, i64 192, !7, i64 200, !7, i64 208, !7, i64 216, !7, i64 224, !7, i64 232, !7, i64 240, !7, i64 248, !7, i64 256, !7, i64 264, !7, i64 272, !7, i64 280, !7, i64 288, !7, i64 296, !7, i64 304, !7, i64 312, !7, i64 320, !7, i64 328, !7, i64 336, !7, i64 344, !7, i64 352, !7, i64 360, !7, i64 368}
!24 = !{!"", !10, i64 0, !13, i64 8, !13, i64 12, !13, i64 16, !13, i64 20}
!25 = !{!8, !8, i64 0}
!26 = !{!23, !7, i64 32}


; Effective O3 passes: BDCEPass,CorrelatedValuePropagationPass,EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,SROAPass,SimplifyCFGPass,TailCallElimPass