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

; 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._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 }
%struct.EFI_IPv6_ADDRESS = type { [16 x i8] }
%struct._EFI_DHCP6_PROTOCOL = type { ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr }

@.str = external hidden unnamed_addr constant [135 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [115 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

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

declare void @FreePool(ptr noundef) #1

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

; Function Attrs: nounwind uwtable
define dso_local void @Ip6ConfigSetStatefulAddrCallback(i8 noundef zeroext %0, ptr noundef %1, ptr noundef %2) #2 {
  %4 = alloca i8, align 1
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  store i8 %0, ptr %4, align 1, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !8
  store ptr %2, ptr %6, align 8, !tbaa !8
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #3
  %8 = load ptr, ptr %6, align 8, !tbaa !8
  store ptr %8, ptr %7, align 8, !tbaa !8
  br label %9

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

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

15:                                               ; preds = %12
  %16 = load ptr, ptr %7, align 8, !tbaa !8
  %17 = getelementptr inbounds %struct._IP6_CONFIG_INSTANCE, ptr %16, i32 0, i32 0
  %18 = load i32, ptr %17, align 8, !tbaa !10
  %19 = icmp eq i32 %18, 1127632969
  br i1 %19, label %21, label %20

20:                                               ; preds = %15, %12
  call void @DebugAssert(ptr noundef @.str, i64 noundef 1569, ptr noundef @.str.4)
  br label %21

21:                                               ; preds = %20, %15
  br label %22

22:                                               ; preds = %21, %9
  br label %23

23:                                               ; preds = %22
  br label %24

24:                                               ; preds = %23
  %25 = load i8, ptr %4, align 1, !tbaa !5
  %26 = icmp ne i8 %25, 0
  br i1 %26, label %27, label %38

27:                                               ; preds = %24
  %28 = load ptr, ptr %7, align 8, !tbaa !8
  %29 = getelementptr inbounds %struct._IP6_CONFIG_INSTANCE, ptr %28, i32 0, i32 19
  %30 = load i32, ptr %29, align 8, !tbaa !24
  %31 = icmp ugt i32 %30, 0
  br i1 %31, label %32, label %37

32:                                               ; preds = %27
  %33 = load ptr, ptr %7, align 8, !tbaa !8
  %34 = getelementptr inbounds %struct._IP6_CONFIG_INSTANCE, ptr %33, i32 0, i32 19
  %35 = load i32, ptr %34, align 8, !tbaa !24
  %36 = add i32 %35, -1
  store i32 %36, ptr %34, align 8, !tbaa !24
  br label %37

37:                                               ; preds = %32, %27
  br label %53

38:                                               ; preds = %24
  %39 = load ptr, ptr %7, align 8, !tbaa !8
  %40 = getelementptr inbounds %struct._IP6_CONFIG_INSTANCE, ptr %39, i32 0, i32 20
  %41 = load ptr, ptr %40, align 8, !tbaa !25
  %42 = load ptr, ptr %7, align 8, !tbaa !8
  %43 = getelementptr inbounds %struct._IP6_CONFIG_INSTANCE, ptr %42, i32 0, i32 21
  %44 = load i32, ptr %43, align 8, !tbaa !26
  %45 = zext i32 %44 to i64
  %46 = getelementptr inbounds %struct.EFI_IPv6_ADDRESS, ptr %41, i64 %45
  %47 = load ptr, ptr %5, align 8, !tbaa !8
  %48 = call ptr @CopyMem(ptr noundef %46, ptr noundef %47, i64 noundef 16)
  %49 = load ptr, ptr %7, align 8, !tbaa !8
  %50 = getelementptr inbounds %struct._IP6_CONFIG_INSTANCE, ptr %49, i32 0, i32 21
  %51 = load i32, ptr %50, align 8, !tbaa !26
  %52 = add i32 %51, 1
  store i32 %52, ptr %50, align 8, !tbaa !26
  br label %53

53:                                               ; preds = %38, %37
  %54 = load ptr, ptr %7, align 8, !tbaa !8
  %55 = getelementptr inbounds %struct._IP6_CONFIG_INSTANCE, ptr %54, i32 0, i32 19
  %56 = load i32, ptr %55, align 8, !tbaa !24
  %57 = load ptr, ptr %7, align 8, !tbaa !8
  %58 = getelementptr inbounds %struct._IP6_CONFIG_INSTANCE, ptr %57, i32 0, i32 21
  %59 = load i32, ptr %58, align 8, !tbaa !26
  %60 = icmp eq i32 %56, %59
  br i1 %60, label %61, label %96

61:                                               ; preds = %53
  %62 = load ptr, ptr %7, align 8, !tbaa !8
  %63 = getelementptr inbounds %struct._IP6_CONFIG_INSTANCE, ptr %62, i32 0, i32 21
  %64 = load i32, ptr %63, align 8, !tbaa !26
  %65 = icmp ne i32 %64, 0
  br i1 %65, label %66, label %82

66:                                               ; preds = %61
  %67 = load ptr, ptr %7, align 8, !tbaa !8
  %68 = getelementptr inbounds %struct._IP6_CONFIG_INSTANCE, ptr %67, i32 0, i32 15
  %69 = load ptr, ptr %68, align 8, !tbaa !27
  %70 = getelementptr inbounds %struct._EFI_DHCP6_PROTOCOL, ptr %69, i32 0, i32 5
  %71 = load ptr, ptr %70, align 8, !tbaa !28
  %72 = load ptr, ptr %7, align 8, !tbaa !8
  %73 = getelementptr inbounds %struct._IP6_CONFIG_INSTANCE, ptr %72, i32 0, i32 15
  %74 = load ptr, ptr %73, align 8, !tbaa !27
  %75 = load ptr, ptr %7, align 8, !tbaa !8
  %76 = getelementptr inbounds %struct._IP6_CONFIG_INSTANCE, ptr %75, i32 0, i32 21
  %77 = load i32, ptr %76, align 8, !tbaa !26
  %78 = load ptr, ptr %7, align 8, !tbaa !8
  %79 = getelementptr inbounds %struct._IP6_CONFIG_INSTANCE, ptr %78, i32 0, i32 20
  %80 = load ptr, ptr %79, align 8, !tbaa !25
  %81 = call i64 %71(ptr noundef %74, i32 noundef %77, ptr noundef %80)
  br label %82

82:                                               ; preds = %66, %61
  %83 = load ptr, ptr %7, align 8, !tbaa !8
  %84 = getelementptr inbounds %struct._IP6_CONFIG_INSTANCE, ptr %83, i32 0, i32 20
  %85 = load ptr, ptr %84, align 8, !tbaa !25
  %86 = icmp ne ptr %85, null
  br i1 %86, label %87, label %91

87:                                               ; preds = %82
  %88 = load ptr, ptr %7, align 8, !tbaa !8
  %89 = getelementptr inbounds %struct._IP6_CONFIG_INSTANCE, ptr %88, i32 0, i32 20
  %90 = load ptr, ptr %89, align 8, !tbaa !25
  call void @FreePool(ptr noundef %90)
  br label %91

91:                                               ; preds = %87, %82
  %92 = load ptr, ptr %7, align 8, !tbaa !8
  %93 = getelementptr inbounds %struct._IP6_CONFIG_INSTANCE, ptr %92, i32 0, i32 20
  store ptr null, ptr %93, align 8, !tbaa !25
  %94 = load ptr, ptr %7, align 8, !tbaa !8
  %95 = getelementptr inbounds %struct._IP6_CONFIG_INSTANCE, ptr %94, i32 0, i32 21
  store i32 0, ptr %95, align 8, !tbaa !26
  br label %96

96:                                               ; preds = %91, %53
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #3
  ret void
}

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


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

@.str = external hidden unnamed_addr constant [135 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [115 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 void @FreePool(ptr noundef) local_unnamed_addr #0

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

; Function Attrs: nounwind uwtable
define dso_local void @Ip6ConfigSetStatefulAddrCallback(i8 noundef zeroext %0, ptr noundef %1, ptr noundef %2) local_unnamed_addr #1 {
  %4 = tail call zeroext i8 @DebugAssertEnabled() #2
  %.not = icmp eq i8 %4, 0
  br i1 %.not, label %10, label %5

5:                                                ; preds = %3
  %.not23 = icmp eq ptr %2, null
  br i1 %.not23, label %9, label %6

6:                                                ; preds = %5
  %7 = load i32, ptr %2, align 8, !tbaa !5
  %8 = icmp eq i32 %7, 1127632969
  br i1 %8, label %10, label %9

9:                                                ; preds = %6, %5
  tail call void @DebugAssert(ptr noundef nonnull @.str, i64 noundef 1569, ptr noundef nonnull @.str.4) #2
  br label %10

10:                                               ; preds = %6, %9, %3
  %.not24 = icmp eq i8 %0, 0
  br i1 %.not24, label %16, label %11

11:                                               ; preds = %10
  %12 = getelementptr inbounds i8, ptr %2, i64 960
  %13 = load i32, ptr %12, align 8, !tbaa !22
  %.not25 = icmp eq i32 %13, 0
  br i1 %.not25, label %.thread, label %14

14:                                               ; preds = %11
  %15 = add i32 %13, -1
  store i32 %15, ptr %12, align 8, !tbaa !22
  br label %26

16:                                               ; preds = %10
  %17 = getelementptr inbounds i8, ptr %2, i64 968
  %18 = load ptr, ptr %17, align 8, !tbaa !23
  %19 = getelementptr inbounds i8, ptr %2, i64 976
  %20 = load i32, ptr %19, align 8, !tbaa !24
  %21 = zext i32 %20 to i64
  %22 = getelementptr inbounds %struct.EFI_IPv6_ADDRESS, ptr %18, i64 %21
  %23 = tail call ptr @CopyMem(ptr noundef %22, ptr noundef %1, i64 noundef 16) #2
  %24 = load i32, ptr %19, align 8, !tbaa !24
  %25 = add i32 %24, 1
  store i32 %25, ptr %19, align 8, !tbaa !24
  %.phi.trans.insert = getelementptr inbounds i8, ptr %2, i64 960
  %.pre = load i32, ptr %.phi.trans.insert, align 8, !tbaa !22
  br label %26

26:                                               ; preds = %14, %16
  %27 = phi i32 [ %15, %14 ], [ %.pre, %16 ]
  %28 = getelementptr inbounds i8, ptr %2, i64 976
  %29 = load i32, ptr %28, align 8, !tbaa !24
  %30 = icmp eq i32 %27, %29
  br i1 %30, label %34, label %48

.thread:                                          ; preds = %11
  %31 = getelementptr inbounds i8, ptr %2, i64 976
  %32 = load i32, ptr %31, align 8, !tbaa !24
  %33 = icmp eq i32 %32, 0
  br i1 %33, label %.thread28, label %48

34:                                               ; preds = %26
  %.not26 = icmp eq i32 %27, 0
  br i1 %.not26, label %.thread28, label %35

35:                                               ; preds = %34
  %36 = getelementptr inbounds i8, ptr %2, i64 936
  %37 = load ptr, ptr %36, align 8, !tbaa !25
  %38 = getelementptr inbounds i8, ptr %37, i64 40
  %39 = load ptr, ptr %38, align 8, !tbaa !26
  %40 = getelementptr inbounds i8, ptr %2, i64 968
  %41 = load ptr, ptr %40, align 8, !tbaa !23
  %42 = tail call i64 %39(ptr noundef %37, i32 noundef %27, ptr noundef %41) #2
  br label %.thread28

.thread28:                                        ; preds = %.thread, %35, %34
  %43 = phi ptr [ %28, %35 ], [ %28, %34 ], [ %31, %.thread ]
  %44 = getelementptr inbounds i8, ptr %2, i64 968
  %45 = load ptr, ptr %44, align 8, !tbaa !23
  %.not27 = icmp eq ptr %45, null
  br i1 %.not27, label %47, label %46

46:                                               ; preds = %.thread28
  tail call void @FreePool(ptr noundef nonnull %45) #2
  br label %47

47:                                               ; preds = %46, %.thread28
  store ptr null, ptr %44, align 8, !tbaa !23
  store i32 0, ptr %43, align 8, !tbaa !24
  br label %48

48:                                               ; preds = %.thread, %47, %26
  ret void
}

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


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