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

; 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._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_INF_CB = type { %struct._LIST_ENTRY, i32, ptr, ptr, ptr }
%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 }

; 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 i64 @Dhcp6DequeueRetry(ptr noundef, i32 noundef, i8 noundef zeroext) #1

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

declare ptr @Dhcp6SeekOption(ptr noundef, i32 noundef, i16 noundef zeroext) #2

declare i64 @UdpIoRecvDatagram(ptr noundef, ptr noundef, ptr noundef, i32 noundef) #2

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

; Function Attrs: nounwind uwtable
define dso_local void @Dhcp6HandleStateless(ptr noundef %0, ptr noundef %1) #1 {
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca i64, align 8
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca ptr, align 8
  %9 = alloca i8, align 1
  store ptr %0, ptr %3, align 8, !tbaa !5
  store ptr %1, ptr %4, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #3
  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
  call void @llvm.lifetime.start.p0(i64 1, ptr %9) #3
  %10 = load ptr, ptr %3, align 8, !tbaa !5
  %11 = getelementptr inbounds %struct._DHCP6_INSTANCE, ptr %10, i32 0, i32 2
  %12 = load ptr, ptr %11, align 8, !tbaa !9
  store ptr %12, ptr %6, align 8, !tbaa !5
  store i64 0, ptr %5, align 8, !tbaa !16
  store i8 0, ptr %9, align 1, !tbaa !17
  store ptr null, ptr %7, align 8, !tbaa !5
  %13 = load ptr, ptr %4, align 8, !tbaa !5
  %14 = getelementptr inbounds %struct.EFI_DHCP6_PACKET, ptr %13, i32 0, i32 2
  %15 = getelementptr inbounds %struct.anon, ptr %14, i32 0, i32 0
  %16 = load i32, ptr %15, align 1
  %17 = and i32 %16, 255
  %18 = icmp ne i32 %17, 7
  br i1 %18, label %19, label %20

19:                                               ; preds = %2
  br label %88

20:                                               ; preds = %2
  br label %21

21:                                               ; preds = %45, %20
  %22 = load ptr, ptr %3, align 8, !tbaa !5
  %23 = getelementptr inbounds %struct._DHCP6_INSTANCE, ptr %22, i32 0, i32 10
  %24 = call zeroext i8 @IsListEmpty(ptr noundef %23)
  %25 = icmp ne i8 %24, 0
  %26 = xor i1 %25, true
  br i1 %26, label %27, label %46

27:                                               ; preds = %21
  %28 = load ptr, ptr %3, align 8, !tbaa !5
  %29 = getelementptr inbounds %struct._DHCP6_INSTANCE, ptr %28, i32 0, i32 10
  %30 = getelementptr inbounds %struct._LIST_ENTRY, ptr %29, i32 0, i32 0
  %31 = load ptr, ptr %30, align 8, !tbaa !18
  %32 = ptrtoint ptr %31 to i64
  %33 = sub i64 %32, 0
  %34 = inttoptr i64 %33 to ptr
  store ptr %34, ptr %7, align 8, !tbaa !5
  %35 = load ptr, ptr %7, align 8, !tbaa !5
  %36 = getelementptr inbounds %struct._DHCP6_INF_CB, ptr %35, i32 0, i32 1
  %37 = load i32, ptr %36, align 8, !tbaa !19
  %38 = load ptr, ptr %4, align 8, !tbaa !5
  %39 = getelementptr inbounds %struct.EFI_DHCP6_PACKET, ptr %38, i32 0, i32 2
  %40 = getelementptr inbounds %struct.anon, ptr %39, i32 0, i32 0
  %41 = load i32, ptr %40, align 1
  %42 = lshr i32 %41, 8
  %43 = icmp eq i32 %37, %42
  br i1 %43, label %44, label %45

44:                                               ; preds = %27
  store i8 1, ptr %9, align 1, !tbaa !17
  br label %46

45:                                               ; preds = %27
  br label %21, !llvm.loop !21

46:                                               ; preds = %44, %21
  %47 = load i8, ptr %9, align 1, !tbaa !17
  %48 = icmp ne i8 %47, 0
  br i1 %48, label %50, label %49

49:                                               ; preds = %46
  br label %88

50:                                               ; preds = %46
  %51 = load ptr, ptr %4, align 8, !tbaa !5
  %52 = getelementptr inbounds %struct.EFI_DHCP6_PACKET, ptr %51, i32 0, i32 2
  %53 = getelementptr inbounds %struct.anon, ptr %52, i32 0, i32 1
  %54 = getelementptr inbounds [1 x i8], ptr %53, i64 0, i64 0
  %55 = load ptr, ptr %4, align 8, !tbaa !5
  %56 = getelementptr inbounds %struct.EFI_DHCP6_PACKET, ptr %55, i32 0, i32 1
  %57 = load i32, ptr %56, align 1, !tbaa !23
  %58 = sub i32 %57, 4
  %59 = call ptr @Dhcp6SeekOption(ptr noundef %54, i32 noundef %58, i16 noundef zeroext 2)
  store ptr %59, ptr %8, align 8, !tbaa !5
  %60 = load ptr, ptr %8, align 8, !tbaa !5
  %61 = icmp eq ptr %60, null
  br i1 %61, label %62, label %63

62:                                               ; preds = %50
  br label %88

63:                                               ; preds = %50
  %64 = load ptr, ptr %7, align 8, !tbaa !5
  %65 = getelementptr inbounds %struct._DHCP6_INF_CB, ptr %64, i32 0, i32 2
  %66 = load ptr, ptr %65, align 8, !tbaa !27
  %67 = load ptr, ptr %3, align 8, !tbaa !5
  %68 = getelementptr inbounds %struct._DHCP6_INSTANCE, ptr %67, i32 0, i32 4
  %69 = load ptr, ptr %7, align 8, !tbaa !5
  %70 = getelementptr inbounds %struct._DHCP6_INF_CB, ptr %69, i32 0, i32 3
  %71 = load ptr, ptr %70, align 8, !tbaa !28
  %72 = load ptr, ptr %4, align 8, !tbaa !5
  %73 = call i64 %66(ptr noundef %68, ptr noundef %71, ptr noundef %72)
  store i64 %73, ptr %5, align 8, !tbaa !16
  %74 = load i64, ptr %5, align 8, !tbaa !16
  %75 = icmp eq i64 %74, -9223372036854775802
  br i1 %75, label %76, label %77

76:                                               ; preds = %63
  br label %88

77:                                               ; preds = %63
  %78 = load ptr, ptr %3, align 8, !tbaa !5
  %79 = load ptr, ptr %4, align 8, !tbaa !5
  %80 = getelementptr inbounds %struct.EFI_DHCP6_PACKET, ptr %79, i32 0, i32 2
  %81 = getelementptr inbounds %struct.anon, ptr %80, i32 0, i32 0
  %82 = load i32, ptr %81, align 1
  %83 = lshr i32 %82, 8
  %84 = call i64 @Dhcp6DequeueRetry(ptr noundef %78, i32 noundef %83, i8 noundef zeroext 0)
  %85 = load i64, ptr %5, align 8, !tbaa !16
  %86 = load ptr, ptr %3, align 8, !tbaa !5
  %87 = getelementptr inbounds %struct._DHCP6_INSTANCE, ptr %86, i32 0, i32 14
  store volatile i64 %85, ptr %87, align 8, !tbaa !29
  br label %88

88:                                               ; preds = %77, %76, %62, %49, %19
  %89 = load ptr, ptr %6, align 8, !tbaa !5
  %90 = getelementptr inbounds %struct._DHCP6_SERVICE, ptr %89, i32 0, i32 7
  %91 = load ptr, ptr %90, align 8, !tbaa !30
  %92 = load ptr, ptr %6, align 8, !tbaa !5
  %93 = call i64 @UdpIoRecvDatagram(ptr noundef %91, ptr noundef @Dhcp6ReceivePacket, ptr noundef %92, i32 noundef 0)
  store i64 %93, ptr %5, align 8, !tbaa !16
  %94 = load i64, ptr %5, align 8, !tbaa !16
  %95 = icmp slt i64 %94, 0
  br i1 %95, label %96, label %98

96:                                               ; preds = %88
  %97 = load ptr, ptr %3, align 8, !tbaa !5
  call void @Dhcp6CleanupRetry(ptr noundef %97, i32 noundef 2)
  br label %98

98:                                               ; preds = %96, %88
  call void @llvm.lifetime.end.p0(i64 1, 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
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #3
  ret void
}

declare zeroext i8 @IsListEmpty(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 = !{!15, !15, i64 0}
!17 = !{!7, !7, i64 0}
!18 = !{!10, !6, i64 176}
!19 = !{!20, !11, i64 16}
!20 = !{!"_DHCP6_INF_CB", !12, i64 0, !11, i64 16, !6, i64 24, !6, i64 32, !6, i64 40}
!21 = distinct !{!21, !22}
!22 = !{!"llvm.loop.mustprogress"}
!23 = !{!24, !11, i64 4}
!24 = !{!"", !11, i64 0, !11, i64 4, !25, i64 8}
!25 = !{!"", !26, i64 0, !7, i64 4}
!26 = !{!"", !11, i64 0, !11, i64 1}
!27 = !{!20, !6, i64 24}
!28 = !{!20, !6, i64 32}
!29 = !{!10, !15, i64 216}
!30 = !{!31, !6, i64 64}
!31 = !{!"_DHCP6_SERVICE", !11, i64 0, !6, i64 8, !6, i64 16, !32, i64 24, !6, i64 40, !6, i64 48, !6, i64 56, !6, i64 64, !11, i64 72, !12, i64 80, !15, i64 96}
!32 = !{!"_EFI_SERVICE_BINDING_PROTOCOL", !6, i64 0, !6, i64 8}


; 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 i64 @Dhcp6DequeueRetry(ptr noundef, i32 noundef, i8 noundef zeroext) local_unnamed_addr #0

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

declare ptr @Dhcp6SeekOption(ptr noundef, i32 noundef, i16 noundef zeroext) local_unnamed_addr #1

declare i64 @UdpIoRecvDatagram(ptr noundef, ptr noundef, ptr noundef, i32 noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
declare dso_local void @Dhcp6ReceivePacket(ptr noundef, ptr noundef, i64 noundef, ptr noundef) #0

; Function Attrs: nounwind uwtable
define dso_local void @Dhcp6HandleStateless(ptr noundef %0, ptr noundef %1) local_unnamed_addr #0 {
  %3 = getelementptr inbounds i8, ptr %0, i64 16
  %4 = load ptr, ptr %3, align 8, !tbaa !5
  %5 = getelementptr inbounds i8, ptr %1, i64 8
  %6 = load i32, ptr %5, align 1
  %7 = and i32 %6, 255
  %.not = icmp eq i32 %7, 7
  br i1 %.not, label %.preheader, label %.loopexit

.preheader:                                       ; preds = %2
  %8 = getelementptr inbounds i8, ptr %0, i64 176
  br label %9

9:                                                ; preds = %.preheader, %11
  %10 = tail call zeroext i8 @IsListEmpty(ptr noundef nonnull %8) #2
  %.not24.not = icmp eq i8 %10, 0
  br i1 %.not24.not, label %11, label %.loopexit

11:                                               ; preds = %9
  %12 = load ptr, ptr %8, align 8, !tbaa !15
  %13 = getelementptr inbounds i8, ptr %12, i64 16
  %14 = load i32, ptr %13, align 8, !tbaa !16
  %15 = load i32, ptr %5, align 1
  %16 = lshr i32 %15, 8
  %17 = icmp eq i32 %14, %16
  br i1 %17, label %18, label %9, !llvm.loop !18

18:                                               ; preds = %11
  %19 = getelementptr inbounds i8, ptr %1, i64 12
  %20 = getelementptr inbounds i8, ptr %1, i64 4
  %21 = load i32, ptr %20, align 1, !tbaa !20
  %22 = add i32 %21, -4
  %23 = tail call ptr @Dhcp6SeekOption(ptr noundef nonnull %19, i32 noundef %22, i16 noundef zeroext 2) #2
  %24 = icmp eq ptr %23, null
  br i1 %24, label %.loopexit, label %25

25:                                               ; preds = %18
  %26 = getelementptr inbounds i8, ptr %12, i64 24
  %27 = load ptr, ptr %26, align 8, !tbaa !24
  %28 = getelementptr inbounds i8, ptr %0, i64 40
  %29 = getelementptr inbounds i8, ptr %12, i64 32
  %30 = load ptr, ptr %29, align 8, !tbaa !25
  %31 = tail call i64 %27(ptr noundef nonnull %28, ptr noundef %30, ptr noundef nonnull %1) #2
  %32 = icmp eq i64 %31, -9223372036854775802
  br i1 %32, label %.loopexit, label %33

33:                                               ; preds = %25
  %34 = load i32, ptr %5, align 1
  %35 = lshr i32 %34, 8
  %36 = tail call i64 @Dhcp6DequeueRetry(ptr noundef nonnull %0, i32 noundef %35, i8 noundef zeroext 0)
  %37 = getelementptr inbounds i8, ptr %0, i64 216
  store volatile i64 %31, ptr %37, align 8, !tbaa !26
  br label %.loopexit

.loopexit:                                        ; preds = %9, %25, %18, %2, %33
  %38 = getelementptr inbounds i8, ptr %4, i64 64
  %39 = load ptr, ptr %38, align 8, !tbaa !27
  %40 = tail call i64 @UdpIoRecvDatagram(ptr noundef %39, ptr noundef nonnull @Dhcp6ReceivePacket, ptr noundef %4, i32 noundef 0) #2
  %41 = icmp slt i64 %40, 0
  br i1 %41, label %42, label %43

42:                                               ; preds = %.loopexit
  tail call void @Dhcp6CleanupRetry(ptr noundef nonnull %0, i32 noundef 2)
  br label %43

43:                                               ; preds = %42, %.loopexit
  ret void
}

declare zeroext i8 @IsListEmpty(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, !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 = !{!6, !10, i64 176}
!16 = !{!17, !7, i64 16}
!17 = !{!"_DHCP6_INF_CB", !11, i64 0, !7, i64 16, !10, i64 24, !10, i64 32, !10, i64 40}
!18 = distinct !{!18, !19}
!19 = !{!"llvm.loop.mustprogress"}
!20 = !{!21, !7, i64 4}
!21 = !{!"", !7, i64 0, !7, i64 4, !22, i64 8}
!22 = !{!"", !23, i64 0, !8, i64 4}
!23 = !{!"", !7, i64 0, !7, i64 1}
!24 = !{!17, !10, i64 24}
!25 = !{!17, !10, i64 32}
!26 = !{!6, !14, i64 216}
!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,GVNPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LICMPass,LoopSimplifyPass,LoopUnrollPass,SROAPass,SimplifyCFGPass,TailCallElimPass