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

; 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._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_IA = type { %struct.EFI_DHCP6_IA_DESCRIPTOR, i32, ptr, i32, [1 x %struct.EFI_DHCP6_IA_ADDRESS] }
%struct.EFI_DHCP6_IA_DESCRIPTOR = type { i16, i32 }
%struct.EFI_DHCP6_IA_ADDRESS = type { %struct.EFI_IPv6_ADDRESS, i32, i32 }
%struct.EFI_IPv6_ADDRESS = type { [16 x i8] }

@gBS = external global ptr, align 8

declare void @FreePool(ptr noundef) #0

; Function Attrs: nounwind uwtable
define dso_local void @Dhcp6DestroyInstance(ptr noundef %0) #1 {
  %2 = alloca ptr, align 8
  store ptr %0, ptr %2, align 8, !tbaa !5
  %3 = load ptr, ptr %2, align 8, !tbaa !5
  call void @Dhcp6CleanupRetry(ptr noundef %3, i32 noundef 0)
  %4 = load ptr, ptr @gBS, align 8, !tbaa !5
  %5 = getelementptr inbounds %struct.EFI_BOOT_SERVICES, ptr %4, i32 0, i32 12
  %6 = load ptr, ptr %5, align 8, !tbaa !9
  %7 = load ptr, ptr %2, align 8, !tbaa !5
  %8 = getelementptr inbounds %struct._DHCP6_INSTANCE, ptr %7, i32 0, i32 5
  %9 = load ptr, ptr %8, align 8, !tbaa !14
  %10 = call i64 %6(ptr noundef %9)
  %11 = load ptr, ptr %2, align 8, !tbaa !5
  %12 = getelementptr inbounds %struct._DHCP6_INSTANCE, ptr %11, i32 0, i32 6
  %13 = load ptr, ptr %12, align 8, !tbaa !19
  %14 = icmp ne ptr %13, null
  br i1 %14, label %15, label %22

15:                                               ; preds = %1
  %16 = load ptr, ptr %2, align 8, !tbaa !5
  %17 = getelementptr inbounds %struct._DHCP6_INSTANCE, ptr %16, i32 0, i32 6
  %18 = load ptr, ptr %17, align 8, !tbaa !19
  call void @Dhcp6CleanupConfigData(ptr noundef %18)
  %19 = load ptr, ptr %2, align 8, !tbaa !5
  %20 = getelementptr inbounds %struct._DHCP6_INSTANCE, ptr %19, i32 0, i32 6
  %21 = load ptr, ptr %20, align 8, !tbaa !19
  call void @FreePool(ptr noundef %21)
  br label %22

22:                                               ; preds = %15, %1
  %23 = load ptr, ptr %2, align 8, !tbaa !5
  %24 = getelementptr inbounds %struct._DHCP6_INSTANCE, ptr %23, i32 0, i32 8
  %25 = getelementptr inbounds %struct._DHCP6_IA_CB, ptr %24, i32 0, i32 0
  %26 = load ptr, ptr %25, align 8, !tbaa !20
  %27 = icmp ne ptr %26, null
  br i1 %27, label %28, label %48

28:                                               ; preds = %22
  %29 = load ptr, ptr %2, align 8, !tbaa !5
  %30 = getelementptr inbounds %struct._DHCP6_INSTANCE, ptr %29, i32 0, i32 8
  %31 = getelementptr inbounds %struct._DHCP6_IA_CB, ptr %30, i32 0, i32 0
  %32 = load ptr, ptr %31, align 8, !tbaa !20
  %33 = getelementptr inbounds %struct.EFI_DHCP6_IA, ptr %32, i32 0, i32 2
  %34 = load ptr, ptr %33, align 8, !tbaa !21
  %35 = icmp ne ptr %34, null
  br i1 %35, label %36, label %43

36:                                               ; preds = %28
  %37 = load ptr, ptr %2, align 8, !tbaa !5
  %38 = getelementptr inbounds %struct._DHCP6_INSTANCE, ptr %37, i32 0, i32 8
  %39 = getelementptr inbounds %struct._DHCP6_IA_CB, ptr %38, i32 0, i32 0
  %40 = load ptr, ptr %39, align 8, !tbaa !20
  %41 = getelementptr inbounds %struct.EFI_DHCP6_IA, ptr %40, i32 0, i32 2
  %42 = load ptr, ptr %41, align 8, !tbaa !21
  call void @FreePool(ptr noundef %42)
  br label %43

43:                                               ; preds = %36, %28
  %44 = load ptr, ptr %2, align 8, !tbaa !5
  %45 = getelementptr inbounds %struct._DHCP6_INSTANCE, ptr %44, i32 0, i32 8
  %46 = getelementptr inbounds %struct._DHCP6_IA_CB, ptr %45, i32 0, i32 0
  %47 = load ptr, ptr %46, align 8, !tbaa !20
  call void @FreePool(ptr noundef %47)
  br label %48

48:                                               ; preds = %43, %22
  %49 = load ptr, ptr %2, align 8, !tbaa !5
  %50 = getelementptr inbounds %struct._DHCP6_INSTANCE, ptr %49, i32 0, i32 13
  %51 = load ptr, ptr %50, align 8, !tbaa !25
  %52 = icmp ne ptr %51, null
  br i1 %52, label %53, label %57

53:                                               ; preds = %48
  %54 = load ptr, ptr %2, align 8, !tbaa !5
  %55 = getelementptr inbounds %struct._DHCP6_INSTANCE, ptr %54, i32 0, i32 13
  %56 = load ptr, ptr %55, align 8, !tbaa !25
  call void @FreePool(ptr noundef %56)
  br label %57

57:                                               ; preds = %53, %48
  %58 = load ptr, ptr %2, align 8, !tbaa !5
  %59 = getelementptr inbounds %struct._DHCP6_INSTANCE, ptr %58, i32 0, i32 11
  %60 = load ptr, ptr %59, align 8, !tbaa !26
  %61 = icmp ne ptr %60, null
  br i1 %61, label %62, label %66

62:                                               ; preds = %57
  %63 = load ptr, ptr %2, align 8, !tbaa !5
  %64 = getelementptr inbounds %struct._DHCP6_INSTANCE, ptr %63, i32 0, i32 11
  %65 = load ptr, ptr %64, align 8, !tbaa !26
  call void @FreePool(ptr noundef %65)
  br label %66

66:                                               ; preds = %62, %57
  %67 = load ptr, ptr %2, align 8, !tbaa !5
  call void @FreePool(ptr noundef %67)
  ret void
}

declare void @Dhcp6CleanupRetry(ptr noundef, i32 noundef) #0

declare void @Dhcp6CleanupConfigData(ptr noundef) #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" }

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


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

@gBS = external local_unnamed_addr global ptr, align 8

declare void @FreePool(ptr noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local void @Dhcp6DestroyInstance(ptr noundef %0) local_unnamed_addr #1 {
  tail call void @Dhcp6CleanupRetry(ptr noundef %0, i32 noundef 0) #2
  %2 = load ptr, ptr @gBS, align 8, !tbaa !5
  %3 = getelementptr inbounds i8, ptr %2, i64 112
  %4 = load ptr, ptr %3, align 8, !tbaa !9
  %5 = getelementptr inbounds i8, ptr %0, i64 112
  %6 = load ptr, ptr %5, align 8, !tbaa !14
  %7 = tail call i64 %4(ptr noundef %6) #2
  %8 = getelementptr inbounds i8, ptr %0, i64 120
  %9 = load ptr, ptr %8, align 8, !tbaa !19
  %.not = icmp eq ptr %9, null
  br i1 %.not, label %12, label %10

10:                                               ; preds = %1
  tail call void @Dhcp6CleanupConfigData(ptr noundef nonnull %9) #2
  %11 = load ptr, ptr %8, align 8, !tbaa !19
  tail call void @FreePool(ptr noundef %11) #2
  br label %12

12:                                               ; preds = %10, %1
  %13 = getelementptr inbounds i8, ptr %0, i64 136
  %14 = load ptr, ptr %13, align 8, !tbaa !20
  %.not18 = icmp eq ptr %14, null
  br i1 %.not18, label %21, label %15

15:                                               ; preds = %12
  %16 = getelementptr inbounds i8, ptr %14, i64 16
  %17 = load ptr, ptr %16, align 8, !tbaa !21
  %.not19 = icmp eq ptr %17, null
  br i1 %.not19, label %19, label %18

18:                                               ; preds = %15
  tail call void @FreePool(ptr noundef nonnull %17) #2
  %.pre = load ptr, ptr %13, align 8, !tbaa !20
  br label %19

19:                                               ; preds = %18, %15
  %20 = phi ptr [ %.pre, %18 ], [ %14, %15 ]
  tail call void @FreePool(ptr noundef %20) #2
  br label %21

21:                                               ; preds = %19, %12
  %22 = getelementptr inbounds i8, ptr %0, i64 208
  %23 = load ptr, ptr %22, align 8, !tbaa !25
  %.not20 = icmp eq ptr %23, null
  br i1 %.not20, label %25, label %24

24:                                               ; preds = %21
  tail call void @FreePool(ptr noundef nonnull %23) #2
  br label %25

25:                                               ; preds = %24, %21
  %26 = getelementptr inbounds i8, ptr %0, i64 192
  %27 = load ptr, ptr %26, align 8, !tbaa !26
  %.not21 = icmp eq ptr %27, null
  br i1 %.not21, label %29, label %28

28:                                               ; preds = %25
  tail call void @FreePool(ptr noundef nonnull %27) #2
  br label %29

29:                                               ; preds = %28, %25
  tail call void @FreePool(ptr noundef nonnull %0) #2
  ret void
}

declare void @Dhcp6CleanupRetry(ptr noundef, i32 noundef) local_unnamed_addr #0

declare void @Dhcp6CleanupConfigData(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 112}
!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, !6, i64 112}
!15 = !{!"_DHCP6_INSTANCE", !13, i64 0, !6, i64 8, !6, i64 16, !16, i64 24, !17, i64 40, !6, i64 112, !6, i64 120, !6, i64 128, !18, i64 136, !16, i64 160, !16, i64 176, !6, i64 192, !7, i64 200, !6, i64 208, !12, i64 216, !7, i64 224, !7, i64 225, !12, i64 232}
!16 = !{!"_LIST_ENTRY", !6, i64 0, !6, i64 8}
!17 = !{!"_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}
!18 = !{!"_DHCP6_IA_CB", !6, i64 0, !13, i64 8, !13, i64 12, !13, i64 16, !13, i64 20}
!19 = !{!15, !6, i64 120}
!20 = !{!15, !6, i64 136}
!21 = !{!22, !6, i64 16}
!22 = !{!"", !23, i64 0, !13, i64 8, !6, i64 16, !13, i64 24, !7, i64 28}
!23 = !{!"", !24, i64 0, !13, i64 4}
!24 = !{!"short", !7, i64 0}
!25 = !{!15, !6, i64 208}
!26 = !{!15, !6, i64 192}


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