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

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

@.str = external hidden unnamed_addr constant [131 x i8], align 1
@.str.18 = external hidden unnamed_addr constant [25 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

declare zeroext i8 @DebugAssertEnabled() #1

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

declare ptr @AllocateZeroPool(i64 noundef) #1

; 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) #2

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

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

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

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

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

; Function Attrs: nounwind uwtable
define dso_local i64 @Dhcp6SelectAdvertiseMsg(ptr noundef %0, ptr noundef %1) #2 {
  %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 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
  br label %9

9:                                                ; preds = %2
  %10 = call zeroext i8 @DebugAssertEnabled()
  %11 = icmp ne i8 %10, 0
  br i1 %11, label %12, label %17

12:                                               ; preds = %9
  %13 = load ptr, ptr %5, align 8, !tbaa !5
  %14 = icmp ne ptr %13, null
  br i1 %14, label %16, label %15

15:                                               ; preds = %12
  call void @DebugAssert(ptr noundef @.str, i64 noundef 2347, ptr noundef @.str.18)
  br label %16

16:                                               ; preds = %15, %12
  br label %17

17:                                               ; preds = %16, %9
  br label %18

18:                                               ; preds = %17
  br label %19

19:                                               ; preds = %18
  %20 = load ptr, ptr %4, align 8, !tbaa !5
  %21 = call i64 @Dhcp6CallbackUser(ptr noundef %20, i32 noundef 2, ptr noundef %5)
  store i64 %21, ptr %6, align 8, !tbaa !9
  %22 = load i64, ptr %6, align 8, !tbaa !9
  %23 = icmp slt i64 %22, 0
  br i1 %23, label %24, label %26

24:                                               ; preds = %19
  %25 = load i64, ptr %6, align 8, !tbaa !9
  store i64 %25, ptr %3, align 8
  store i32 1, ptr %8, align 4
  br label %80

26:                                               ; preds = %19
  %27 = load ptr, ptr %5, align 8, !tbaa !5
  %28 = load ptr, ptr %4, align 8, !tbaa !5
  %29 = getelementptr inbounds %struct._DHCP6_INSTANCE, ptr %28, i32 0, i32 11
  store ptr %27, ptr %29, align 8, !tbaa !11
  %30 = load ptr, ptr %4, align 8, !tbaa !5
  %31 = load ptr, ptr %5, align 8, !tbaa !5
  %32 = getelementptr inbounds %struct.EFI_DHCP6_PACKET, ptr %31, i32 0, i32 2
  %33 = getelementptr inbounds %struct.anon, ptr %32, i32 0, i32 0
  %34 = load i32, ptr %33, align 1
  %35 = lshr i32 %34, 8
  %36 = call i64 @Dhcp6DequeueRetry(ptr noundef %30, i32 noundef %35, i8 noundef zeroext 0)
  store i64 %36, ptr %6, align 8, !tbaa !9
  %37 = load i64, ptr %6, align 8, !tbaa !9
  %38 = icmp slt i64 %37, 0
  br i1 %38, label %39, label %41

39:                                               ; preds = %26
  %40 = load i64, ptr %6, align 8, !tbaa !9
  store i64 %40, ptr %3, align 8
  store i32 1, ptr %8, align 4
  br label %80

41:                                               ; preds = %26
  %42 = load ptr, ptr %5, align 8, !tbaa !5
  %43 = getelementptr inbounds %struct.EFI_DHCP6_PACKET, ptr %42, i32 0, i32 2
  %44 = getelementptr inbounds %struct.anon, ptr %43, i32 0, i32 1
  %45 = getelementptr inbounds [1 x i8], ptr %44, i64 0, i64 0
  %46 = load ptr, ptr %5, align 8, !tbaa !5
  %47 = getelementptr inbounds %struct.EFI_DHCP6_PACKET, ptr %46, i32 0, i32 1
  %48 = load i32, ptr %47, align 1, !tbaa !17
  %49 = sub i32 %48, 4
  %50 = call ptr @Dhcp6SeekOption(ptr noundef %45, i32 noundef %49, i16 noundef zeroext 12)
  store ptr %50, ptr %7, align 8, !tbaa !5
  %51 = load ptr, ptr %7, align 8, !tbaa !5
  %52 = icmp ne ptr %51, null
  br i1 %52, label %53, label %69

53:                                               ; preds = %41
  %54 = call ptr @AllocateZeroPool(i64 noundef 16)
  %55 = load ptr, ptr %4, align 8, !tbaa !5
  %56 = getelementptr inbounds %struct._DHCP6_INSTANCE, ptr %55, i32 0, i32 13
  store ptr %54, ptr %56, align 8, !tbaa !21
  %57 = load ptr, ptr %4, align 8, !tbaa !5
  %58 = getelementptr inbounds %struct._DHCP6_INSTANCE, ptr %57, i32 0, i32 13
  %59 = load ptr, ptr %58, align 8, !tbaa !21
  %60 = icmp eq ptr %59, null
  br i1 %60, label %61, label %62

61:                                               ; preds = %53
  store i64 -9223372036854775799, ptr %3, align 8
  store i32 1, ptr %8, align 4
  br label %80

62:                                               ; preds = %53
  %63 = load ptr, ptr %4, align 8, !tbaa !5
  %64 = getelementptr inbounds %struct._DHCP6_INSTANCE, ptr %63, i32 0, i32 13
  %65 = load ptr, ptr %64, align 8, !tbaa !21
  %66 = load ptr, ptr %7, align 8, !tbaa !5
  %67 = getelementptr inbounds i8, ptr %66, i64 4
  %68 = call ptr @CopyMem(ptr noundef %65, ptr noundef %67, i64 noundef 16)
  br label %69

69:                                               ; preds = %62, %41
  %70 = load ptr, ptr %4, align 8, !tbaa !5
  %71 = load ptr, ptr %5, align 8, !tbaa !5
  %72 = call i64 @Dhcp6UpdateIaInfo(ptr noundef %70, ptr noundef %71)
  store i64 %72, ptr %6, align 8, !tbaa !9
  %73 = load i64, ptr %6, align 8, !tbaa !9
  %74 = icmp slt i64 %73, 0
  br i1 %74, label %75, label %77

75:                                               ; preds = %69
  %76 = load i64, ptr %6, align 8, !tbaa !9
  store i64 %76, ptr %3, align 8
  store i32 1, ptr %8, align 4
  br label %80

77:                                               ; preds = %69
  %78 = load ptr, ptr %4, align 8, !tbaa !5
  %79 = call i64 @Dhcp6SendRequestMsg(ptr noundef %78)
  store i64 %79, ptr %3, align 8
  store i32 1, ptr %8, align 4
  br label %80

80:                                               ; preds = %77, %75, %61, %39, %24
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #3
  %81 = load i64, ptr %3, align 8
  ret i64 %81
}

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, !6, i64 192}
!12 = !{!"_DHCP6_INSTANCE", !13, i64 0, !6, i64 8, !6, i64 16, !14, i64 24, !15, i64 40, !6, i64 112, !6, i64 120, !6, i64 128, !16, i64 136, !14, i64 160, !14, i64 176, !6, i64 192, !7, i64 200, !6, i64 208, !10, i64 216, !7, i64 224, !7, i64 225, !10, i64 232}
!13 = !{!"int", !7, i64 0}
!14 = !{!"_LIST_ENTRY", !6, i64 0, !6, i64 8}
!15 = !{!"_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}
!16 = !{!"_DHCP6_IA_CB", !6, i64 0, !13, i64 8, !13, i64 12, !13, i64 16, !13, i64 20}
!17 = !{!18, !13, i64 4}
!18 = !{!"", !13, i64 0, !13, i64 4, !19, i64 8}
!19 = !{!"", !20, i64 0, !7, i64 4}
!20 = !{!"", !13, i64 0, !13, i64 1}
!21 = !{!12, !6, i64 208}


; 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.18 = external hidden unnamed_addr constant [25 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

declare ptr @AllocateZeroPool(i64 noundef) local_unnamed_addr #0

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

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

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

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

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

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

; Function Attrs: nounwind uwtable
define dso_local i64 @Dhcp6SelectAdvertiseMsg(ptr noundef %0, ptr noundef %1) local_unnamed_addr #1 {
  %3 = alloca ptr, align 8
  store ptr %1, ptr %3, align 8, !tbaa !5
  %4 = tail call zeroext i8 @DebugAssertEnabled() #2
  %5 = icmp eq i8 %4, 0
  %6 = icmp ne ptr %1, null
  %or.cond = or i1 %5, %6
  br i1 %or.cond, label %8, label %7

7:                                                ; preds = %2
  tail call void @DebugAssert(ptr noundef nonnull @.str, i64 noundef 2347, ptr noundef nonnull @.str.18) #2
  br label %8

8:                                                ; preds = %7, %2
  %9 = call i64 @Dhcp6CallbackUser(ptr noundef %0, i32 noundef 2, ptr noundef nonnull %3)
  %10 = icmp slt i64 %9, 0
  br i1 %10, label %39, label %11

11:                                               ; preds = %8
  %12 = load ptr, ptr %3, align 8, !tbaa !5
  %13 = getelementptr inbounds i8, ptr %0, i64 192
  store ptr %12, ptr %13, align 8, !tbaa !9
  %14 = getelementptr inbounds i8, ptr %12, i64 8
  %15 = load i32, ptr %14, align 1
  %16 = lshr i32 %15, 8
  %17 = call i64 @Dhcp6DequeueRetry(ptr noundef %0, i32 noundef %16, i8 noundef zeroext 0)
  %18 = icmp slt i64 %17, 0
  br i1 %18, label %39, label %19

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

26:                                               ; preds = %19
  %27 = call ptr @AllocateZeroPool(i64 noundef 16) #2
  %28 = getelementptr inbounds i8, ptr %0, i64 208
  store ptr %27, ptr %28, align 8, !tbaa !20
  %29 = icmp eq ptr %27, null
  br i1 %29, label %39, label %30

30:                                               ; preds = %26
  %31 = getelementptr inbounds i8, ptr %25, i64 4
  %32 = call ptr @CopyMem(ptr noundef nonnull %27, ptr noundef nonnull %31, i64 noundef 16) #2
  br label %33

33:                                               ; preds = %30, %19
  %34 = load ptr, ptr %3, align 8, !tbaa !5
  %35 = call i64 @Dhcp6UpdateIaInfo(ptr noundef nonnull %0, ptr noundef %34)
  %36 = icmp slt i64 %35, 0
  br i1 %36, label %39, label %37

37:                                               ; preds = %33
  %38 = call i64 @Dhcp6SendRequestMsg(ptr noundef nonnull %0)
  br label %39

39:                                               ; preds = %33, %26, %11, %8, %37
  %.0 = phi i64 [ %38, %37 ], [ %9, %8 ], [ %17, %11 ], [ -9223372036854775799, %26 ], [ %35, %33 ]
  ret i64 %.0
}

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, !6, i64 0}
!6 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !6, i64 192}
!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, !11, i64 4}
!17 = !{!"", !11, i64 0, !11, i64 4, !18, i64 8}
!18 = !{!"", !19, i64 0, !7, i64 4}
!19 = !{!"", !11, i64 0, !11, i64 1}
!20 = !{!10, !6, i64 208}


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