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

; 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_IPv6_ADDRESS = type { [16 x i8] }
%struct.NET_FRAGMENT = type { i32, ptr }
%struct.UDP_END_POINT = type { %union.EFI_IP_ADDRESS, i16, %union.EFI_IP_ADDRESS, i16 }
%union.EFI_IP_ADDRESS = type { [4 x i32] }
%struct._DHCP6_INSTANCE = type { i32, ptr, ptr, %struct._LIST_ENTRY, %struct._EFI_DHCP6_PROTOCOL, ptr, ptr, ptr, %struct._DHCP6_IA_CB, %struct._LIST_ENTRY, %struct._LIST_ENTRY, ptr, i8, ptr, i64, i8, i8, i64 }
%struct._EFI_DHCP6_PROTOCOL = type { ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr }
%struct._DHCP6_IA_CB = type { ptr, i32, i32, i32, i32 }
%struct._LIST_ENTRY = type { ptr, ptr }
%struct.EFI_DHCP6_PACKET = type <{ i32, i32, %struct.anon }>
%struct.anon = type <{ %struct.EFI_DHCP6_HEADER, [1 x i8] }>
%struct.EFI_DHCP6_HEADER = type { i32 }
%struct._DHCP6_SERVICE = type { i32, ptr, ptr, %struct._EFI_SERVICE_BINDING_PROTOCOL, ptr, ptr, ptr, ptr, i32, %struct._LIST_ENTRY, i64 }
%struct._EFI_SERVICE_BINDING_PROTOCOL = type { ptr, ptr }

@mAllDhcpRelayAndServersAddress = external global %struct.EFI_IPv6_ADDRESS, 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

; Function Attrs: nounwind uwtable
define dso_local i64 @Dhcp6TransmitPacket(ptr noundef %0, ptr noundef %1, ptr noundef %2) #1 {
  %4 = alloca i64, align 8
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca i64, align 8
  %9 = alloca ptr, align 8
  %10 = alloca %struct.NET_FRAGMENT, align 8
  %11 = alloca %struct.UDP_END_POINT, align 4
  %12 = alloca ptr, align 8
  %13 = alloca i32, align 4
  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
  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 16, ptr %10) #3
  call void @llvm.lifetime.start.p0(i64 40, ptr %11) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %12) #3
  %14 = load ptr, ptr %5, align 8, !tbaa !5
  %15 = getelementptr inbounds %struct._DHCP6_INSTANCE, ptr %14, i32 0, i32 2
  %16 = load ptr, ptr %15, align 8, !tbaa !9
  store ptr %16, ptr %12, align 8, !tbaa !5
  %17 = load ptr, ptr %6, align 8, !tbaa !5
  %18 = getelementptr inbounds %struct.EFI_DHCP6_PACKET, ptr %17, i32 0, i32 2
  %19 = getelementptr inbounds %struct.anon, ptr %18, i32 0, i32 0
  %20 = getelementptr inbounds %struct.NET_FRAGMENT, ptr %10, i32 0, i32 1
  store ptr %19, ptr %20, align 8, !tbaa !16
  %21 = load ptr, ptr %6, align 8, !tbaa !5
  %22 = getelementptr inbounds %struct.EFI_DHCP6_PACKET, ptr %21, i32 0, i32 1
  %23 = load i32, ptr %22, align 1, !tbaa !18
  %24 = getelementptr inbounds %struct.NET_FRAGMENT, ptr %10, i32 0, i32 0
  store i32 %23, ptr %24, align 8, !tbaa !22
  %25 = call ptr @NetbufFromExt(ptr noundef %10, i32 noundef 1, i32 noundef 0, i32 noundef 0, ptr noundef @Dhcp6DummyExtFree, ptr noundef null)
  store ptr %25, ptr %9, align 8, !tbaa !5
  %26 = load ptr, ptr %9, align 8, !tbaa !5
  %27 = icmp eq ptr %26, null
  br i1 %27, label %28, label %29

28:                                               ; preds = %3
  store i64 -9223372036854775799, ptr %4, align 8
  store i32 1, ptr %13, align 4
  br label %64

29:                                               ; preds = %3
  %30 = call ptr @ZeroMem(ptr noundef %11, i64 noundef 40)
  %31 = load ptr, ptr %5, align 8, !tbaa !5
  %32 = getelementptr inbounds %struct._DHCP6_INSTANCE, ptr %31, i32 0, i32 13
  %33 = load ptr, ptr %32, align 8, !tbaa !23
  %34 = icmp ne ptr %33, null
  br i1 %34, label %35, label %41

35:                                               ; preds = %29
  %36 = getelementptr inbounds %struct.UDP_END_POINT, ptr %11, i32 0, i32 2
  %37 = load ptr, ptr %5, align 8, !tbaa !5
  %38 = getelementptr inbounds %struct._DHCP6_INSTANCE, ptr %37, i32 0, i32 13
  %39 = load ptr, ptr %38, align 8, !tbaa !23
  %40 = call ptr @CopyMem(ptr noundef %36, ptr noundef %39, i64 noundef 16)
  br label %44

41:                                               ; preds = %29
  %42 = getelementptr inbounds %struct.UDP_END_POINT, ptr %11, i32 0, i32 2
  %43 = call ptr @CopyMem(ptr noundef %42, ptr noundef @mAllDhcpRelayAndServersAddress, i64 noundef 16)
  br label %44

44:                                               ; preds = %41, %35
  %45 = getelementptr inbounds %struct.UDP_END_POINT, ptr %11, i32 0, i32 3
  store i16 547, ptr %45, align 4, !tbaa !24
  %46 = getelementptr inbounds %struct.UDP_END_POINT, ptr %11, i32 0, i32 1
  store i16 546, ptr %46, align 4, !tbaa !27
  %47 = load ptr, ptr %7, align 8, !tbaa !5
  %48 = icmp ne ptr %47, null
  br i1 %48, label %49, label %52

49:                                               ; preds = %44
  %50 = load ptr, ptr %7, align 8, !tbaa !5
  %51 = load ptr, ptr %5, align 8, !tbaa !5
  call void @SetElapsedTime(ptr noundef %50, ptr noundef %51)
  br label %52

52:                                               ; preds = %49, %44
  %53 = load ptr, ptr %12, align 8, !tbaa !5
  %54 = getelementptr inbounds %struct._DHCP6_SERVICE, ptr %53, i32 0, i32 7
  %55 = load ptr, ptr %54, align 8, !tbaa !28
  %56 = load ptr, ptr %9, align 8, !tbaa !5
  %57 = call i64 @UdpIoSendDatagram(ptr noundef %55, ptr noundef %56, ptr noundef %11, ptr noundef null, ptr noundef @Dhcp6OnTransmitted, ptr noundef null)
  store i64 %57, ptr %8, align 8, !tbaa !31
  %58 = load i64, ptr %8, align 8, !tbaa !31
  %59 = icmp slt i64 %58, 0
  br i1 %59, label %60, label %63

60:                                               ; preds = %52
  %61 = load ptr, ptr %9, align 8, !tbaa !5
  call void @NetbufFree(ptr noundef %61)
  %62 = load i64, ptr %8, align 8, !tbaa !31
  store i64 %62, ptr %4, align 8
  store i32 1, ptr %13, align 4
  br label %64

63:                                               ; preds = %52
  store i64 0, ptr %4, align 8
  store i32 1, ptr %13, align 4
  br label %64

64:                                               ; preds = %63, %60, %28
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #3
  call void @llvm.lifetime.end.p0(i64 40, ptr %11) #3
  call void @llvm.lifetime.end.p0(i64 16, 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
  %65 = load i64, ptr %4, align 8
  ret i64 %65
}

declare ptr @NetbufFromExt(ptr noundef, i32 noundef, i32 noundef, i32 noundef, ptr noundef, ptr noundef) #2

declare void @Dhcp6DummyExtFree(ptr noundef) #2

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

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

declare void @SetElapsedTime(ptr noundef, ptr noundef) #2

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

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

declare void @NetbufFree(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, !6, i64 16}
!10 = !{!"_DHCP6_INSTANCE", !11, i64 0, !6, i64 8, !6, i64 16, !12, i64 24, !13, i64 40, !6, i64 112, !6, i64 120, !6, i64 128, !14, i64 136, !12, i64 160, !12, i64 176, !6, i64 192, !7, i64 200, !6, i64 208, !15, i64 216, !7, i64 224, !7, i64 225, !15, i64 232}
!11 = !{!"int", !7, i64 0}
!12 = !{!"_LIST_ENTRY", !6, i64 0, !6, i64 8}
!13 = !{!"_EFI_DHCP6_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}
!14 = !{!"_DHCP6_IA_CB", !6, i64 0, !11, i64 8, !11, i64 12, !11, i64 16, !11, i64 20}
!15 = !{!"long long", !7, i64 0}
!16 = !{!17, !6, i64 8}
!17 = !{!"", !11, i64 0, !6, i64 8}
!18 = !{!19, !11, i64 4}
!19 = !{!"", !11, i64 0, !11, i64 4, !20, i64 8}
!20 = !{!"", !21, i64 0, !7, i64 4}
!21 = !{!"", !11, i64 0, !11, i64 1}
!22 = !{!17, !11, i64 0}
!23 = !{!10, !6, i64 208}
!24 = !{!25, !26, i64 36}
!25 = !{!"", !7, i64 0, !26, i64 16, !7, i64 20, !26, i64 36}
!26 = !{!"short", !7, i64 0}
!27 = !{!25, !26, i64 16}
!28 = !{!29, !6, i64 64}
!29 = !{!"_DHCP6_SERVICE", !11, i64 0, !6, i64 8, !6, i64 16, !30, i64 24, !6, i64 40, !6, i64 48, !6, i64 56, !6, i64 64, !11, i64 72, !12, i64 80, !15, i64 96}
!30 = !{!"_EFI_SERVICE_BINDING_PROTOCOL", !6, i64 0, !6, i64 8}
!31 = !{!15, !15, i64 0}


; 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"

%struct.EFI_IPv6_ADDRESS = type { [16 x i8] }
%struct.NET_FRAGMENT = type { i32, ptr }
%struct.UDP_END_POINT = type { %union.EFI_IP_ADDRESS, i16, %union.EFI_IP_ADDRESS, i16 }
%union.EFI_IP_ADDRESS = type { [4 x i32] }

@mAllDhcpRelayAndServersAddress = external global %struct.EFI_IPv6_ADDRESS, align 1

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

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

; Function Attrs: nounwind uwtable
define dso_local range(i64 -9223372036854775808, 1) i64 @Dhcp6TransmitPacket(ptr noundef %0, ptr noundef %1, ptr noundef %2) local_unnamed_addr #1 {
  %4 = alloca %struct.NET_FRAGMENT, align 8
  %5 = alloca %struct.UDP_END_POINT, align 4
  call void @llvm.lifetime.start.p0(i64 16, ptr nonnull %4) #3
  call void @llvm.lifetime.start.p0(i64 40, ptr nonnull %5) #3
  %6 = getelementptr inbounds i8, ptr %0, i64 16
  %7 = load ptr, ptr %6, align 8, !tbaa !5
  %8 = getelementptr inbounds i8, ptr %1, i64 8
  %9 = getelementptr inbounds i8, ptr %4, i64 8
  store ptr %8, ptr %9, align 8, !tbaa !15
  %10 = getelementptr inbounds i8, ptr %1, i64 4
  %11 = load i32, ptr %10, align 1, !tbaa !17
  store i32 %11, ptr %4, align 8, !tbaa !21
  %12 = call ptr @NetbufFromExt(ptr noundef nonnull %4, i32 noundef 1, i32 noundef 0, i32 noundef 0, ptr noundef nonnull @Dhcp6DummyExtFree, ptr noundef null) #3
  %13 = icmp eq ptr %12, null
  br i1 %13, label %29, label %14

14:                                               ; preds = %3
  %15 = call ptr @ZeroMem(ptr noundef nonnull %5, i64 noundef 40) #3
  %16 = getelementptr inbounds i8, ptr %0, i64 208
  %17 = load ptr, ptr %16, align 8, !tbaa !22
  %.not = icmp eq ptr %17, null
  %18 = getelementptr inbounds i8, ptr %5, i64 20
  %mAllDhcpRelayAndServersAddress. = select i1 %.not, ptr @mAllDhcpRelayAndServersAddress, ptr %17
  %19 = call ptr @CopyMem(ptr noundef nonnull %18, ptr noundef nonnull %mAllDhcpRelayAndServersAddress., i64 noundef 16) #3
  %20 = getelementptr inbounds i8, ptr %5, i64 36
  store i16 547, ptr %20, align 4, !tbaa !23
  %21 = getelementptr inbounds i8, ptr %5, i64 16
  store i16 546, ptr %21, align 4, !tbaa !26
  %.not18 = icmp eq ptr %2, null
  br i1 %.not18, label %23, label %22

22:                                               ; preds = %14
  call void @SetElapsedTime(ptr noundef nonnull %2, ptr noundef nonnull %0) #3
  br label %23

23:                                               ; preds = %22, %14
  %24 = getelementptr inbounds i8, ptr %7, i64 64
  %25 = load ptr, ptr %24, align 8, !tbaa !27
  %26 = call i64 @UdpIoSendDatagram(ptr noundef %25, ptr noundef nonnull %12, ptr noundef nonnull %5, ptr noundef null, ptr noundef nonnull @Dhcp6OnTransmitted, ptr noundef null) #3
  %27 = icmp slt i64 %26, 0
  br i1 %27, label %28, label %29

28:                                               ; preds = %23
  call void @NetbufFree(ptr noundef nonnull %12) #3
  br label %29

29:                                               ; preds = %23, %3, %28
  %.0 = phi i64 [ %26, %28 ], [ -9223372036854775799, %3 ], [ 0, %23 ]
  call void @llvm.lifetime.end.p0(i64 40, ptr nonnull %5) #3
  call void @llvm.lifetime.end.p0(i64 16, ptr nonnull %4) #3
  ret i64 %.0
}

declare ptr @NetbufFromExt(ptr noundef, i32 noundef, i32 noundef, i32 noundef, ptr noundef, ptr noundef) local_unnamed_addr #2

declare void @Dhcp6DummyExtFree(ptr noundef) #2

declare ptr @ZeroMem(ptr noundef, i64 noundef) local_unnamed_addr #2

declare ptr @CopyMem(ptr noundef, ptr noundef, i64 noundef) local_unnamed_addr #2

declare void @SetElapsedTime(ptr noundef, ptr noundef) local_unnamed_addr #2

declare i64 @UdpIoSendDatagram(ptr noundef, ptr noundef, ptr noundef, ptr noundef, ptr noundef, ptr noundef) local_unnamed_addr #2

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

declare void @NetbufFree(ptr noundef) local_unnamed_addr #2

attributes #0 = { mustprogress 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, !10, i64 16}
!6 = !{!"_DHCP6_INSTANCE", !7, i64 0, !10, i64 8, !10, i64 16, !11, i64 24, !12, i64 40, !10, i64 112, !10, i64 120, !10, i64 128, !13, i64 136, !11, i64 160, !11, i64 176, !10, i64 192, !8, i64 200, !10, i64 208, !14, i64 216, !8, i64 224, !8, i64 225, !14, i64 232}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"any pointer", !8, i64 0}
!11 = !{!"_LIST_ENTRY", !10, i64 0, !10, i64 8}
!12 = !{!"_EFI_DHCP6_PROTOCOL", !10, i64 0, !10, i64 8, !10, i64 16, !10, i64 24, !10, i64 32, !10, i64 40, !10, i64 48, !10, i64 56, !10, i64 64}
!13 = !{!"_DHCP6_IA_CB", !10, i64 0, !7, i64 8, !7, i64 12, !7, i64 16, !7, i64 20}
!14 = !{!"long long", !8, i64 0}
!15 = !{!16, !10, i64 8}
!16 = !{!"", !7, i64 0, !10, i64 8}
!17 = !{!18, !7, i64 4}
!18 = !{!"", !7, i64 0, !7, i64 4, !19, i64 8}
!19 = !{!"", !20, i64 0, !8, i64 4}
!20 = !{!"", !7, i64 0, !7, i64 1}
!21 = !{!16, !7, i64 0}
!22 = !{!6, !10, i64 208}
!23 = !{!24, !25, i64 36}
!24 = !{!"", !8, i64 0, !25, i64 16, !8, i64 20, !25, i64 36}
!25 = !{!"short", !8, i64 0}
!26 = !{!24, !25, i64 16}
!27 = !{!28, !10, i64 64}
!28 = !{!"_DHCP6_SERVICE", !7, i64 0, !10, i64 8, !10, i64 16, !29, i64 24, !10, i64 40, !10, i64 48, !10, i64 56, !10, i64 64, !7, i64 72, !11, i64 80, !14, i64 96}
!29 = !{!"_EFI_SERVICE_BINDING_PROTOCOL", !10, i64 0, !10, i64 8}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,SROAPass,SimplifyCFGPass