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

; 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._MTFTP6_INSTANCE = type { i32, ptr, %struct._LIST_ENTRY, %struct._EFI_MTFTP6_PROTOCOL, ptr, ptr, ptr, %struct.MTFTP6_EXT_OPTION_INFO, i16, i16, %struct._LIST_ENTRY, %struct.EFI_IPv6_ADDRESS, i16, i16, ptr, %struct.EFI_IPv6_ADDRESS, i16, ptr, ptr, i32, i32, i32, i32, i64, i8, i8, i8 }
%struct._EFI_MTFTP6_PROTOCOL = type { ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr }
%struct.MTFTP6_EXT_OPTION_INFO = type { i16, i8, i32, %struct.EFI_IPv6_ADDRESS, i16, i8, i32 }
%struct._LIST_ENTRY = type { ptr, ptr }
%struct.EFI_IPv6_ADDRESS = type { [16 x i8] }
%struct._EFI_MTFTP6_TOKEN = type { i64, ptr, ptr, ptr, ptr, i32, ptr, i64, ptr, ptr, ptr, ptr, ptr }
%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 }

@gBS = external global ptr, align 8

declare i64 @UdpIoFreeIo(ptr noundef) #0

declare void @FreePool(ptr noundef) #0

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

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

; Function Attrs: nounwind uwtable
define dso_local void @Mtftp6DestroyInstance(ptr noundef %0) #2 {
  %2 = alloca ptr, align 8
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  store ptr %0, ptr %2, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %3) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #3
  %6 = load ptr, ptr %2, align 8, !tbaa !5
  %7 = getelementptr inbounds %struct._MTFTP6_INSTANCE, ptr %6, i32 0, i32 5
  %8 = load ptr, ptr %7, align 8, !tbaa !9
  %9 = icmp ne ptr %8, null
  br i1 %9, label %10, label %14

10:                                               ; preds = %1
  %11 = load ptr, ptr %2, align 8, !tbaa !5
  %12 = getelementptr inbounds %struct._MTFTP6_INSTANCE, ptr %11, i32 0, i32 5
  %13 = load ptr, ptr %12, align 8, !tbaa !9
  call void @FreePool(ptr noundef %13)
  br label %14

14:                                               ; preds = %10, %1
  %15 = load ptr, ptr %2, align 8, !tbaa !5
  %16 = getelementptr inbounds %struct._MTFTP6_INSTANCE, ptr %15, i32 0, i32 6
  %17 = load ptr, ptr %16, align 8, !tbaa !18
  %18 = icmp ne ptr %17, null
  br i1 %18, label %19, label %36

19:                                               ; preds = %14
  %20 = load ptr, ptr %2, align 8, !tbaa !5
  %21 = getelementptr inbounds %struct._MTFTP6_INSTANCE, ptr %20, i32 0, i32 6
  %22 = load ptr, ptr %21, align 8, !tbaa !18
  %23 = getelementptr inbounds %struct._EFI_MTFTP6_TOKEN, ptr %22, i32 0, i32 1
  %24 = load ptr, ptr %23, align 8, !tbaa !19
  %25 = icmp ne ptr %24, null
  br i1 %25, label %26, label %36

26:                                               ; preds = %19
  %27 = load ptr, ptr @gBS, align 8, !tbaa !5
  %28 = getelementptr inbounds %struct.EFI_BOOT_SERVICES, ptr %27, i32 0, i32 11
  %29 = load ptr, ptr %28, align 8, !tbaa !21
  %30 = load ptr, ptr %2, align 8, !tbaa !5
  %31 = getelementptr inbounds %struct._MTFTP6_INSTANCE, ptr %30, i32 0, i32 6
  %32 = load ptr, ptr %31, align 8, !tbaa !18
  %33 = getelementptr inbounds %struct._EFI_MTFTP6_TOKEN, ptr %32, i32 0, i32 1
  %34 = load ptr, ptr %33, align 8, !tbaa !19
  %35 = call i64 %29(ptr noundef %34)
  br label %36

36:                                               ; preds = %26, %19, %14
  %37 = load ptr, ptr %2, align 8, !tbaa !5
  %38 = getelementptr inbounds %struct._MTFTP6_INSTANCE, ptr %37, i32 0, i32 18
  %39 = load ptr, ptr %38, align 8, !tbaa !24
  %40 = icmp ne ptr %39, null
  br i1 %40, label %41, label %45

41:                                               ; preds = %36
  %42 = load ptr, ptr %2, align 8, !tbaa !5
  %43 = getelementptr inbounds %struct._MTFTP6_INSTANCE, ptr %42, i32 0, i32 18
  %44 = load ptr, ptr %43, align 8, !tbaa !24
  call void @NetbufFree(ptr noundef %44)
  br label %45

45:                                               ; preds = %41, %36
  %46 = load ptr, ptr %2, align 8, !tbaa !5
  %47 = getelementptr inbounds %struct._MTFTP6_INSTANCE, ptr %46, i32 0, i32 14
  %48 = load ptr, ptr %47, align 8, !tbaa !25
  %49 = icmp ne ptr %48, null
  br i1 %49, label %50, label %55

50:                                               ; preds = %45
  %51 = load ptr, ptr %2, align 8, !tbaa !5
  %52 = getelementptr inbounds %struct._MTFTP6_INSTANCE, ptr %51, i32 0, i32 14
  %53 = load ptr, ptr %52, align 8, !tbaa !25
  %54 = call i64 @UdpIoFreeIo(ptr noundef %53)
  br label %55

55:                                               ; preds = %50, %45
  %56 = load ptr, ptr %2, align 8, !tbaa !5
  %57 = getelementptr inbounds %struct._MTFTP6_INSTANCE, ptr %56, i32 0, i32 17
  %58 = load ptr, ptr %57, align 8, !tbaa !26
  %59 = icmp ne ptr %58, null
  br i1 %59, label %60, label %65

60:                                               ; preds = %55
  %61 = load ptr, ptr %2, align 8, !tbaa !5
  %62 = getelementptr inbounds %struct._MTFTP6_INSTANCE, ptr %61, i32 0, i32 17
  %63 = load ptr, ptr %62, align 8, !tbaa !26
  %64 = call i64 @UdpIoFreeIo(ptr noundef %63)
  br label %65

65:                                               ; preds = %60, %55
  %66 = load ptr, ptr %2, align 8, !tbaa !5
  %67 = getelementptr inbounds %struct._MTFTP6_INSTANCE, ptr %66, i32 0, i32 10
  %68 = getelementptr inbounds %struct._LIST_ENTRY, ptr %67, i32 0, i32 0
  %69 = load ptr, ptr %68, align 8, !tbaa !27
  store ptr %69, ptr %3, align 8, !tbaa !5
  %70 = load ptr, ptr %3, align 8, !tbaa !5
  %71 = getelementptr inbounds %struct._LIST_ENTRY, ptr %70, i32 0, i32 0
  %72 = load ptr, ptr %71, align 8, !tbaa !28
  store ptr %72, ptr %4, align 8, !tbaa !5
  br label %73

73:                                               ; preds = %86, %65
  %74 = load ptr, ptr %3, align 8, !tbaa !5
  %75 = load ptr, ptr %2, align 8, !tbaa !5
  %76 = getelementptr inbounds %struct._MTFTP6_INSTANCE, ptr %75, i32 0, i32 10
  %77 = icmp ne ptr %74, %76
  br i1 %77, label %78, label %91

78:                                               ; preds = %73
  %79 = load ptr, ptr %3, align 8, !tbaa !5
  %80 = ptrtoint ptr %79 to i64
  %81 = sub i64 %80, 0
  %82 = inttoptr i64 %81 to ptr
  store ptr %82, ptr %5, align 8, !tbaa !5
  %83 = load ptr, ptr %3, align 8, !tbaa !5
  %84 = call ptr @RemoveEntryList(ptr noundef %83)
  %85 = load ptr, ptr %5, align 8, !tbaa !5
  call void @FreePool(ptr noundef %85)
  br label %86

86:                                               ; preds = %78
  %87 = load ptr, ptr %4, align 8, !tbaa !5
  store ptr %87, ptr %3, align 8, !tbaa !5
  %88 = load ptr, ptr %3, align 8, !tbaa !5
  %89 = getelementptr inbounds %struct._LIST_ENTRY, ptr %88, i32 0, i32 0
  %90 = load ptr, ptr %89, align 8, !tbaa !28
  store ptr %90, ptr %4, align 8, !tbaa !5
  br label %73, !llvm.loop !29

91:                                               ; preds = %73
  %92 = load ptr, ptr %2, align 8, !tbaa !5
  call void @FreePool(ptr noundef %92)
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #3
  ret void
}

declare void @NetbufFree(ptr noundef) #0

declare ptr @RemoveEntryList(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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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, !6, i64 104}
!10 = !{!"_MTFTP6_INSTANCE", !11, i64 0, !6, i64 8, !12, i64 16, !13, i64 32, !6, i64 96, !6, i64 104, !6, i64 112, !14, i64 120, !15, i64 152, !15, i64 154, !12, i64 160, !16, i64 176, !15, i64 192, !15, i64 194, !6, i64 200, !16, i64 208, !15, i64 224, !6, i64 232, !6, i64 240, !11, i64 248, !11, i64 252, !11, i64 256, !11, i64 260, !17, i64 264, !7, i64 272, !7, i64 273, !7, i64 274}
!11 = !{!"int", !7, i64 0}
!12 = !{!"_LIST_ENTRY", !6, i64 0, !6, i64 8}
!13 = !{!"_EFI_MTFTP6_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}
!14 = !{!"", !15, i64 0, !7, i64 2, !11, i64 4, !16, i64 8, !15, i64 24, !7, i64 26, !11, i64 28}
!15 = !{!"short", !7, i64 0}
!16 = !{!"", !7, i64 0}
!17 = !{!"long long", !7, i64 0}
!18 = !{!10, !6, i64 112}
!19 = !{!20, !6, i64 8}
!20 = !{!"_EFI_MTFTP6_TOKEN", !17, i64 0, !6, i64 8, !6, i64 16, !6, i64 24, !6, i64 32, !11, i64 40, !6, i64 48, !17, i64 56, !6, i64 64, !6, i64 72, !6, i64 80, !6, i64 88, !6, i64 96}
!21 = !{!22, !6, i64 104}
!22 = !{!"", !23, 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}
!23 = !{!"", !17, i64 0, !11, i64 8, !11, i64 12, !11, i64 16, !11, i64 20}
!24 = !{!10, !6, i64 240}
!25 = !{!10, !6, i64 200}
!26 = !{!10, !6, i64 232}
!27 = !{!10, !6, i64 160}
!28 = !{!12, !6, i64 0}
!29 = distinct !{!29, !30}
!30 = !{!"llvm.loop.mustprogress"}


; 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 i64 @UdpIoFreeIo(ptr noundef) local_unnamed_addr #0

declare void @FreePool(ptr noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local void @Mtftp6DestroyInstance(ptr noundef %0) local_unnamed_addr #1 {
  %2 = getelementptr inbounds i8, ptr %0, i64 104
  %3 = load ptr, ptr %2, align 8, !tbaa !5
  %.not = icmp eq ptr %3, null
  br i1 %.not, label %5, label %4

4:                                                ; preds = %1
  tail call void @FreePool(ptr noundef nonnull %3) #2
  br label %5

5:                                                ; preds = %4, %1
  %6 = getelementptr inbounds i8, ptr %0, i64 112
  %7 = load ptr, ptr %6, align 8, !tbaa !17
  %.not28 = icmp eq ptr %7, null
  br i1 %.not28, label %16, label %8

8:                                                ; preds = %5
  %9 = getelementptr inbounds i8, ptr %7, i64 8
  %10 = load ptr, ptr %9, align 8, !tbaa !18
  %.not29 = icmp eq ptr %10, null
  br i1 %.not29, label %16, label %11

11:                                               ; preds = %8
  %12 = load ptr, ptr @gBS, align 8, !tbaa !20
  %13 = getelementptr inbounds i8, ptr %12, i64 104
  %14 = load ptr, ptr %13, align 8, !tbaa !21
  %15 = tail call i64 %14(ptr noundef nonnull %10) #2
  br label %16

16:                                               ; preds = %11, %8, %5
  %17 = getelementptr inbounds i8, ptr %0, i64 240
  %18 = load ptr, ptr %17, align 8, !tbaa !24
  %.not30 = icmp eq ptr %18, null
  br i1 %.not30, label %20, label %19

19:                                               ; preds = %16
  tail call void @NetbufFree(ptr noundef nonnull %18) #2
  br label %20

20:                                               ; preds = %19, %16
  %21 = getelementptr inbounds i8, ptr %0, i64 200
  %22 = load ptr, ptr %21, align 8, !tbaa !25
  %.not31 = icmp eq ptr %22, null
  br i1 %.not31, label %25, label %23

23:                                               ; preds = %20
  %24 = tail call i64 @UdpIoFreeIo(ptr noundef nonnull %22) #2
  br label %25

25:                                               ; preds = %23, %20
  %26 = getelementptr inbounds i8, ptr %0, i64 232
  %27 = load ptr, ptr %26, align 8, !tbaa !26
  %.not32 = icmp eq ptr %27, null
  br i1 %.not32, label %30, label %28

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

30:                                               ; preds = %28, %25
  %31 = getelementptr inbounds i8, ptr %0, i64 160
  %32 = load ptr, ptr %31, align 8, !tbaa !27
  %.not3334 = icmp eq ptr %32, %31
  br i1 %.not3334, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %30, %.lr.ph
  %.035 = phi ptr [ %.021, %.lr.ph ], [ %32, %30 ]
  %.021 = load ptr, ptr %.035, align 8, !tbaa !28
  %33 = tail call ptr @RemoveEntryList(ptr noundef nonnull %.035) #2
  tail call void @FreePool(ptr noundef nonnull %.035) #2
  %.not33 = icmp eq ptr %.021, %31
  br i1 %.not33, label %._crit_edge, label %.lr.ph, !llvm.loop !29

._crit_edge:                                      ; preds = %.lr.ph, %30
  tail call void @FreePool(ptr noundef %0) #2
  ret void
}

declare void @NetbufFree(ptr noundef) local_unnamed_addr #0

declare ptr @RemoveEntryList(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, !10, i64 104}
!6 = !{!"_MTFTP6_INSTANCE", !7, i64 0, !10, i64 8, !11, i64 16, !12, i64 32, !10, i64 96, !10, i64 104, !10, i64 112, !13, i64 120, !14, i64 152, !14, i64 154, !11, i64 160, !15, i64 176, !14, i64 192, !14, i64 194, !10, i64 200, !15, i64 208, !14, i64 224, !10, i64 232, !10, i64 240, !7, i64 248, !7, i64 252, !7, i64 256, !7, i64 260, !16, i64 264, !8, i64 272, !8, i64 273, !8, i64 274}
!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_MTFTP6_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}
!13 = !{!"", !14, i64 0, !8, i64 2, !7, i64 4, !15, i64 8, !14, i64 24, !8, i64 26, !7, i64 28}
!14 = !{!"short", !8, i64 0}
!15 = !{!"", !8, i64 0}
!16 = !{!"long long", !8, i64 0}
!17 = !{!6, !10, i64 112}
!18 = !{!19, !10, i64 8}
!19 = !{!"_EFI_MTFTP6_TOKEN", !16, i64 0, !10, i64 8, !10, i64 16, !10, i64 24, !10, i64 32, !7, i64 40, !10, i64 48, !16, i64 56, !10, i64 64, !10, i64 72, !10, i64 80, !10, i64 88, !10, i64 96}
!20 = !{!10, !10, i64 0}
!21 = !{!22, !10, i64 104}
!22 = !{!"", !23, i64 0, !10, i64 24, !10, i64 32, !10, i64 40, !10, i64 48, !10, i64 56, !10, i64 64, !10, i64 72, !10, i64 80, !10, i64 88, !10, i64 96, !10, i64 104, !10, i64 112, !10, i64 120, !10, i64 128, !10, i64 136, !10, i64 144, !10, i64 152, !10, i64 160, !10, i64 168, !10, i64 176, !10, i64 184, !10, i64 192, !10, i64 200, !10, i64 208, !10, i64 216, !10, i64 224, !10, i64 232, !10, i64 240, !10, i64 248, !10, i64 256, !10, i64 264, !10, i64 272, !10, i64 280, !10, i64 288, !10, i64 296, !10, i64 304, !10, i64 312, !10, i64 320, !10, i64 328, !10, i64 336, !10, i64 344, !10, i64 352, !10, i64 360, !10, i64 368}
!23 = !{!"", !16, i64 0, !7, i64 8, !7, i64 12, !7, i64 16, !7, i64 20}
!24 = !{!6, !10, i64 240}
!25 = !{!6, !10, i64 200}
!26 = !{!6, !10, i64 232}
!27 = !{!6, !10, i64 160}
!28 = !{!11, !10, i64 0}
!29 = distinct !{!29, !30}
!30 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,SROAPass,SimplifyCFGPass,TailCallElimPass