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

; 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_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 }
%struct._IP6_CONFIG_INSTANCE = type { i32, i8, %struct._LIST_ENTRY, i16, %struct.EFI_IP6_CONFIG_INTERFACE_INFO, %struct.EFI_IP6_CONFIG_INTERFACE_ID, i32, %struct.EFI_IP6_CONFIG_DUP_ADDR_DETECT_TRANSMITS, [7 x %struct.IP6_CONFIG_DATA_ITEM], %struct.NET_MAP, %struct.NET_MAP, %struct._EFI_IP6_CONFIG_PROTOCOL, ptr, ptr, ptr, ptr, i8, i32, ptr, i32, ptr, i32, %struct._IP6_FORM_CALLBACK_INFO, %struct.IP6_CONFIG_NVDATA }
%struct._LIST_ENTRY = type { ptr, ptr }
%struct.EFI_IP6_CONFIG_INTERFACE_INFO = type { [32 x i16], i8, i32, %struct.EFI_MAC_ADDRESS, i32, ptr, i32, ptr }
%struct.EFI_MAC_ADDRESS = type { [32 x i8] }
%struct.EFI_IP6_CONFIG_INTERFACE_ID = type { [8 x i8] }
%struct.EFI_IP6_CONFIG_DUP_ADDR_DETECT_TRANSMITS = type { i32 }
%struct.IP6_CONFIG_DATA_ITEM = type { ptr, ptr, i64, i8, %struct.NET_MAP, %union.IP6_CONFIG_DATA, i64 }
%union.IP6_CONFIG_DATA = type { ptr }
%struct.NET_MAP = type { %struct._LIST_ENTRY, %struct._LIST_ENTRY, i64 }
%struct._EFI_IP6_CONFIG_PROTOCOL = type { ptr, ptr, ptr, ptr }
%struct._IP6_FORM_CALLBACK_INFO = type { i32, ptr, %struct._EFI_HII_CONFIG_ACCESS_PROTOCOL, ptr, ptr }
%struct._EFI_HII_CONFIG_ACCESS_PROTOCOL = type { ptr, ptr, ptr }
%struct.IP6_CONFIG_NVDATA = type { i32, %struct.EFI_IP6_CONFIG_DUP_ADDR_DETECT_TRANSMITS, %struct.EFI_IP6_CONFIG_INTERFACE_ID, %struct._LIST_ENTRY, i32, %struct._LIST_ENTRY, i32, %struct._LIST_ENTRY, i32 }

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

; 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

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

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

; Function Attrs: nounwind uwtable
define dso_local i64 @EfiIp6ConfigRegisterDataNotify(ptr noundef %0, i32 noundef %1, ptr noundef %2) #2 {
  %4 = alloca i64, align 8
  %5 = alloca ptr, align 8
  %6 = alloca i32, align 4
  %7 = alloca ptr, align 8
  %8 = alloca i64, align 8
  %9 = alloca i64, align 8
  %10 = alloca ptr, align 8
  %11 = alloca ptr, align 8
  %12 = alloca ptr, align 8
  %13 = alloca i32, align 4
  store ptr %0, ptr %5, align 8, !tbaa !5
  store i32 %1, ptr %6, align 4, !tbaa !9
  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 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
  %14 = load ptr, ptr %5, align 8, !tbaa !5
  %15 = icmp eq ptr %14, null
  br i1 %15, label %19, label %16

16:                                               ; preds = %3
  %17 = load ptr, ptr %7, align 8, !tbaa !5
  %18 = icmp eq ptr %17, null
  br i1 %18, label %19, label %20

19:                                               ; preds = %16, %3
  store i64 -9223372036854775806, ptr %4, align 8
  store i32 1, ptr %13, align 4
  br label %75

20:                                               ; preds = %16
  %21 = load i32, ptr %6, align 4, !tbaa !9
  %22 = icmp uge i32 %21, 7
  br i1 %22, label %23, label %24

23:                                               ; preds = %20
  store i64 -9223372036854775805, ptr %4, align 8
  store i32 1, ptr %13, align 4
  br label %75

24:                                               ; preds = %20
  %25 = load ptr, ptr @gBS, align 8, !tbaa !5
  %26 = getelementptr inbounds %struct.EFI_BOOT_SERVICES, ptr %25, i32 0, i32 1
  %27 = load ptr, ptr %26, align 8, !tbaa !11
  %28 = call i64 %27(i64 noundef 8)
  store i64 %28, ptr %8, align 8, !tbaa !15
  %29 = call zeroext i8 @DebugAssertEnabled()
  %30 = zext i8 %29 to i32
  %31 = icmp ne i32 %30, 0
  br i1 %31, label %32, label %42

32:                                               ; preds = %24
  %33 = load ptr, ptr %5, align 8, !tbaa !5
  %34 = ptrtoint ptr %33 to i64
  %35 = sub i64 %34, ptrtoint (ptr getelementptr inbounds (%struct._IP6_CONFIG_INSTANCE, ptr null, i32 0, i32 11) to i64)
  %36 = inttoptr i64 %35 to ptr
  %37 = getelementptr inbounds %struct._IP6_CONFIG_INSTANCE, ptr %36, i32 0, i32 0
  %38 = load i32, ptr %37, align 8, !tbaa !16
  %39 = icmp ne i32 %38, 1127632969
  br i1 %39, label %40, label %42

40:                                               ; preds = %32
  call void @DebugAssert(ptr noundef @.str, i64 noundef 2031, ptr noundef @.str.1)
  %41 = load ptr, ptr %5, align 8, !tbaa !5
  br label %47

42:                                               ; preds = %32, %24
  %43 = load ptr, ptr %5, align 8, !tbaa !5
  %44 = ptrtoint ptr %43 to i64
  %45 = sub i64 %44, ptrtoint (ptr getelementptr inbounds (%struct._IP6_CONFIG_INSTANCE, ptr null, i32 0, i32 11) to i64)
  %46 = inttoptr i64 %45 to ptr
  br label %47

47:                                               ; preds = %42, %40
  %48 = phi ptr [ %41, %40 ], [ %46, %42 ]
  store ptr %48, ptr %10, align 8, !tbaa !5
  %49 = load ptr, ptr %10, align 8, !tbaa !5
  %50 = getelementptr inbounds %struct._IP6_CONFIG_INSTANCE, ptr %49, i32 0, i32 8
  %51 = load i32, ptr %6, align 4, !tbaa !9
  %52 = zext i32 %51 to i64
  %53 = getelementptr inbounds [7 x %struct.IP6_CONFIG_DATA_ITEM], ptr %50, i64 0, i64 %52
  %54 = getelementptr inbounds %struct.IP6_CONFIG_DATA_ITEM, ptr %53, i32 0, i32 4
  store ptr %54, ptr %11, align 8, !tbaa !5
  %55 = load ptr, ptr %11, align 8, !tbaa !5
  %56 = load ptr, ptr %7, align 8, !tbaa !5
  %57 = call ptr @NetMapFindKey(ptr noundef %55, ptr noundef %56)
  store ptr %57, ptr %12, align 8, !tbaa !5
  %58 = load ptr, ptr %12, align 8, !tbaa !5
  %59 = icmp eq ptr %58, null
  br i1 %59, label %60, label %68

60:                                               ; preds = %47
  %61 = load ptr, ptr %11, align 8, !tbaa !5
  %62 = load ptr, ptr %7, align 8, !tbaa !5
  %63 = call i64 @NetMapInsertTail(ptr noundef %61, ptr noundef %62, ptr noundef null)
  store i64 %63, ptr %9, align 8, !tbaa !15
  %64 = load i64, ptr %9, align 8, !tbaa !15
  %65 = icmp slt i64 %64, 0
  br i1 %65, label %66, label %67

66:                                               ; preds = %60
  store i64 -9223372036854775799, ptr %9, align 8, !tbaa !15
  br label %67

67:                                               ; preds = %66, %60
  br label %69

68:                                               ; preds = %47
  store i64 -9223372036854775793, ptr %9, align 8, !tbaa !15
  br label %69

69:                                               ; preds = %68, %67
  %70 = load ptr, ptr @gBS, align 8, !tbaa !5
  %71 = getelementptr inbounds %struct.EFI_BOOT_SERVICES, ptr %70, i32 0, i32 2
  %72 = load ptr, ptr %71, align 8, !tbaa !28
  %73 = load i64, ptr %8, align 8, !tbaa !15
  call void %72(i64 noundef %73)
  %74 = load i64, ptr %9, align 8, !tbaa !15
  store i64 %74, ptr %4, align 8
  store i32 1, ptr %13, align 4
  br label %75

75:                                               ; preds = %69, %23, %19
  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
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #3
  %76 = load i64, ptr %4, align 8
  ret i64 %76
}

declare ptr @NetMapFindKey(ptr noundef, ptr noundef) #1

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 = !{!"int", !7, i64 0}
!11 = !{!12, !6, i64 24}
!12 = !{!"", !13, 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}
!13 = !{!"", !14, i64 0, !10, i64 8, !10, i64 12, !10, i64 16, !10, i64 20}
!14 = !{!"long long", !7, i64 0}
!15 = !{!14, !14, i64 0}
!16 = !{!17, !10, i64 0}
!17 = !{!"_IP6_CONFIG_INSTANCE", !10, i64 0, !7, i64 4, !18, i64 8, !19, i64 24, !20, i64 32, !21, i64 168, !10, i64 176, !22, i64 180, !7, i64 184, !23, i64 800, !23, i64 840, !24, i64 880, !6, i64 912, !6, i64 920, !6, i64 928, !6, i64 936, !7, i64 944, !10, i64 948, !6, i64 952, !10, i64 960, !6, i64 968, !10, i64 976, !25, i64 984, !27, i64 1040}
!18 = !{!"_LIST_ENTRY", !6, i64 0, !6, i64 8}
!19 = !{!"short", !7, i64 0}
!20 = !{!"", !7, i64 0, !7, i64 64, !10, i64 68, !21, i64 72, !10, i64 104, !6, i64 112, !10, i64 120, !6, i64 128}
!21 = !{!"", !7, i64 0}
!22 = !{!"", !10, i64 0}
!23 = !{!"", !18, i64 0, !18, i64 16, !14, i64 32}
!24 = !{!"_EFI_IP6_CONFIG_PROTOCOL", !6, i64 0, !6, i64 8, !6, i64 16, !6, i64 24}
!25 = !{!"_IP6_FORM_CALLBACK_INFO", !10, i64 0, !6, i64 8, !26, i64 16, !6, i64 40, !6, i64 48}
!26 = !{!"_EFI_HII_CONFIG_ACCESS_PROTOCOL", !6, i64 0, !6, i64 8, !6, i64 16}
!27 = !{!"", !10, i64 0, !22, i64 4, !21, i64 8, !18, i64 16, !10, i64 32, !18, i64 40, !10, i64 56, !18, i64 64, !10, i64 80}
!28 = !{!12, !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"

%struct.IP6_CONFIG_DATA_ITEM = type { ptr, ptr, i64, i8, %struct.NET_MAP, %union.IP6_CONFIG_DATA, i64 }
%struct.NET_MAP = type { %struct._LIST_ENTRY, %struct._LIST_ENTRY, i64 }
%struct._LIST_ENTRY = type { ptr, ptr }
%union.IP6_CONFIG_DATA = type { ptr }

@.str = external hidden unnamed_addr constant [135 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

declare zeroext i8 @DebugAssertEnabled() local_unnamed_addr #0

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

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

; Function Attrs: nounwind uwtable
define dso_local i64 @EfiIp6ConfigRegisterDataNotify(ptr noundef %0, i32 noundef %1, ptr noundef %2) local_unnamed_addr #1 {
  %4 = icmp eq ptr %0, null
  %5 = icmp eq ptr %2, null
  %or.cond = or i1 %4, %5
  br i1 %or.cond, label %30, label %6

6:                                                ; preds = %3
  %7 = icmp ugt i32 %1, 6
  br i1 %7, label %30, label %8

8:                                                ; preds = %6
  %9 = load ptr, ptr @gBS, align 8, !tbaa !5
  %10 = getelementptr inbounds i8, ptr %9, i64 24
  %11 = load ptr, ptr %10, align 8, !tbaa !9
  %12 = tail call i64 %11(i64 noundef 8) #2
  %13 = tail call zeroext i8 @DebugAssertEnabled() #2
  %.not = icmp eq i8 %13, 0
  %.pre = ptrtoint ptr %0 to i64
  %.pre22 = add i64 %.pre, -880
  %.pre24 = inttoptr i64 %.pre22 to ptr
  br i1 %.not, label %._crit_edge, label %14

14:                                               ; preds = %8
  %15 = load i32, ptr %.pre24, align 8, !tbaa !14
  %.not21 = icmp eq i32 %15, 1127632969
  br i1 %.not21, label %._crit_edge, label %16

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

._crit_edge:                                      ; preds = %8, %14, %16
  %17 = phi ptr [ %0, %16 ], [ %.pre24, %14 ], [ %.pre24, %8 ]
  %18 = getelementptr inbounds i8, ptr %17, i64 184
  %19 = zext nneg i32 %1 to i64
  %20 = getelementptr inbounds [7 x %struct.IP6_CONFIG_DATA_ITEM], ptr %18, i64 0, i64 %19, i32 4
  %21 = tail call ptr @NetMapFindKey(ptr noundef nonnull %20, ptr noundef nonnull %2) #2
  %22 = icmp eq ptr %21, null
  br i1 %22, label %23, label %26

23:                                               ; preds = %._crit_edge
  %24 = tail call i64 @NetMapInsertTail(ptr noundef nonnull %20, ptr noundef nonnull %2, ptr noundef null) #2
  %25 = icmp slt i64 %24, 0
  %spec.store.select = select i1 %25, i64 -9223372036854775799, i64 %24
  br label %26

26:                                               ; preds = %._crit_edge, %23
  %.017 = phi i64 [ %spec.store.select, %23 ], [ -9223372036854775793, %._crit_edge ]
  %27 = load ptr, ptr @gBS, align 8, !tbaa !5
  %28 = getelementptr inbounds i8, ptr %27, i64 32
  %29 = load ptr, ptr %28, align 8, !tbaa !26
  tail call void %29(i64 noundef %12) #2
  br label %30

30:                                               ; preds = %6, %3, %26
  %.0 = phi i64 [ %.017, %26 ], [ -9223372036854775806, %3 ], [ -9223372036854775805, %6 ]
  ret i64 %.0
}

declare ptr @NetMapFindKey(ptr noundef, ptr noundef) local_unnamed_addr #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 24}
!10 = !{!"", !11, 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}
!11 = !{!"", !12, i64 0, !13, i64 8, !13, i64 12, !13, i64 16, !13, i64 20}
!12 = !{!"long long", !7, i64 0}
!13 = !{!"int", !7, i64 0}
!14 = !{!15, !13, i64 0}
!15 = !{!"_IP6_CONFIG_INSTANCE", !13, i64 0, !7, i64 4, !16, i64 8, !17, i64 24, !18, i64 32, !19, i64 168, !13, i64 176, !20, i64 180, !7, i64 184, !21, i64 800, !21, i64 840, !22, i64 880, !6, i64 912, !6, i64 920, !6, i64 928, !6, i64 936, !7, i64 944, !13, i64 948, !6, i64 952, !13, i64 960, !6, i64 968, !13, i64 976, !23, i64 984, !25, i64 1040}
!16 = !{!"_LIST_ENTRY", !6, i64 0, !6, i64 8}
!17 = !{!"short", !7, i64 0}
!18 = !{!"", !7, i64 0, !7, i64 64, !13, i64 68, !19, i64 72, !13, i64 104, !6, i64 112, !13, i64 120, !6, i64 128}
!19 = !{!"", !7, i64 0}
!20 = !{!"", !13, i64 0}
!21 = !{!"", !16, i64 0, !16, i64 16, !12, i64 32}
!22 = !{!"_EFI_IP6_CONFIG_PROTOCOL", !6, i64 0, !6, i64 8, !6, i64 16, !6, i64 24}
!23 = !{!"_IP6_FORM_CALLBACK_INFO", !13, i64 0, !6, i64 8, !24, i64 16, !6, i64 40, !6, i64 48}
!24 = !{!"_EFI_HII_CONFIG_ACCESS_PROTOCOL", !6, i64 0, !6, i64 8, !6, i64 16}
!25 = !{!"", !13, i64 0, !20, i64 4, !19, i64 8, !16, i64 16, !13, i64 32, !16, i64 40, !13, i64 56, !16, i64 64, !13, i64 80}
!26 = !{!10, !6, i64 32}


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