; LLVM IR from thalium/icebox :: third_party/virtualbox/src/VBox/Devices/EFI/Firmware/MdeModulePkg/Library (NetMapClean)

; 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.NET_MAP = type { %struct._LIST_ENTRY, %struct._LIST_ENTRY, i64 }
%struct._LIST_ENTRY = type { ptr, ptr }
%struct.NET_MAP_ITEM = type { %struct._LIST_ENTRY, 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
@.str.12 = external hidden unnamed_addr constant [144 x i8], align 1
@.str.20 = external hidden unnamed_addr constant [20 x i8], align 1
@.str.21 = external hidden unnamed_addr constant [46 x i8], align 1
@.str.22 = external hidden unnamed_addr constant [29 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

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

declare zeroext i8 @DebugAssertEnabled() #1

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

declare zeroext i8 @IsListEmpty(ptr noundef) #1

; Function Attrs: nounwind uwtable
define dso_local void @NetMapClean(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
  br label %6

6:                                                ; preds = %1
  %7 = call zeroext i8 @DebugAssertEnabled()
  %8 = icmp ne i8 %7, 0
  br i1 %8, label %9, label %14

9:                                                ; preds = %6
  %10 = load ptr, ptr %2, align 8, !tbaa !5
  %11 = icmp ne ptr %10, null
  br i1 %11, label %13, label %12

12:                                               ; preds = %9
  call void @DebugAssert(ptr noundef @.str.12, i64 noundef 1230, ptr noundef @.str.20)
  br label %13

13:                                               ; preds = %12, %9
  br label %14

14:                                               ; preds = %13, %6
  br label %15

15:                                               ; preds = %14
  br label %16

16:                                               ; preds = %15
  %17 = load ptr, ptr %2, align 8, !tbaa !5
  %18 = getelementptr inbounds %struct.NET_MAP, ptr %17, i32 0, i32 0
  %19 = getelementptr inbounds %struct._LIST_ENTRY, ptr %18, i32 0, i32 0
  %20 = load ptr, ptr %19, align 8, !tbaa !9
  store ptr %20, ptr %4, align 8, !tbaa !5
  %21 = load ptr, ptr %4, align 8, !tbaa !5
  %22 = getelementptr inbounds %struct._LIST_ENTRY, ptr %21, i32 0, i32 0
  %23 = load ptr, ptr %22, align 8, !tbaa !13
  store ptr %23, ptr %5, align 8, !tbaa !5
  br label %24

24:                                               ; preds = %46, %16
  %25 = load ptr, ptr %4, align 8, !tbaa !5
  %26 = load ptr, ptr %2, align 8, !tbaa !5
  %27 = getelementptr inbounds %struct.NET_MAP, ptr %26, i32 0, i32 0
  %28 = icmp ne ptr %25, %27
  br i1 %28, label %29, label %51

29:                                               ; preds = %24
  %30 = load ptr, ptr %4, align 8, !tbaa !5
  %31 = ptrtoint ptr %30 to i64
  %32 = sub i64 %31, 0
  %33 = inttoptr i64 %32 to ptr
  store ptr %33, ptr %3, align 8, !tbaa !5
  %34 = load ptr, ptr %3, align 8, !tbaa !5
  %35 = getelementptr inbounds %struct.NET_MAP_ITEM, ptr %34, i32 0, i32 0
  %36 = call ptr @RemoveEntryList(ptr noundef %35)
  %37 = load ptr, ptr %2, align 8, !tbaa !5
  %38 = getelementptr inbounds %struct.NET_MAP, ptr %37, i32 0, i32 2
  %39 = load i64, ptr %38, align 8, !tbaa !14
  %40 = add i64 %39, -1
  store i64 %40, ptr %38, align 8, !tbaa !14
  %41 = load ptr, ptr @gBS, align 8, !tbaa !5
  %42 = getelementptr inbounds %struct.EFI_BOOT_SERVICES, ptr %41, i32 0, i32 7
  %43 = load ptr, ptr %42, align 8, !tbaa !15
  %44 = load ptr, ptr %3, align 8, !tbaa !5
  %45 = call i64 %43(ptr noundef %44)
  br label %46

46:                                               ; preds = %29
  %47 = load ptr, ptr %5, align 8, !tbaa !5
  store ptr %47, ptr %4, align 8, !tbaa !5
  %48 = load ptr, ptr %4, align 8, !tbaa !5
  %49 = getelementptr inbounds %struct._LIST_ENTRY, ptr %48, i32 0, i32 0
  %50 = load ptr, ptr %49, align 8, !tbaa !13
  store ptr %50, ptr %5, align 8, !tbaa !5
  br label %24, !llvm.loop !19

51:                                               ; preds = %24
  br label %52

52:                                               ; preds = %51
  %53 = call zeroext i8 @DebugAssertEnabled()
  %54 = icmp ne i8 %53, 0
  br i1 %54, label %55, label %68

55:                                               ; preds = %52
  %56 = load ptr, ptr %2, align 8, !tbaa !5
  %57 = getelementptr inbounds %struct.NET_MAP, ptr %56, i32 0, i32 2
  %58 = load i64, ptr %57, align 8, !tbaa !14
  %59 = icmp eq i64 %58, 0
  br i1 %59, label %60, label %66

60:                                               ; preds = %55
  %61 = load ptr, ptr %2, align 8, !tbaa !5
  %62 = getelementptr inbounds %struct.NET_MAP, ptr %61, i32 0, i32 0
  %63 = call zeroext i8 @IsListEmpty(ptr noundef %62)
  %64 = zext i8 %63 to i32
  %65 = icmp ne i32 %64, 0
  br i1 %65, label %67, label %66

66:                                               ; preds = %60, %55
  call void @DebugAssert(ptr noundef @.str.12, i64 noundef 1241, ptr noundef @.str.21)
  br label %67

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

68:                                               ; preds = %67, %52
  br label %69

69:                                               ; preds = %68
  br label %70

70:                                               ; preds = %69
  %71 = load ptr, ptr %2, align 8, !tbaa !5
  %72 = getelementptr inbounds %struct.NET_MAP, ptr %71, i32 0, i32 1
  %73 = getelementptr inbounds %struct._LIST_ENTRY, ptr %72, i32 0, i32 0
  %74 = load ptr, ptr %73, align 8, !tbaa !21
  store ptr %74, ptr %4, align 8, !tbaa !5
  %75 = load ptr, ptr %4, align 8, !tbaa !5
  %76 = getelementptr inbounds %struct._LIST_ENTRY, ptr %75, i32 0, i32 0
  %77 = load ptr, ptr %76, align 8, !tbaa !13
  store ptr %77, ptr %5, align 8, !tbaa !5
  br label %78

78:                                               ; preds = %96, %70
  %79 = load ptr, ptr %4, align 8, !tbaa !5
  %80 = load ptr, ptr %2, align 8, !tbaa !5
  %81 = getelementptr inbounds %struct.NET_MAP, ptr %80, i32 0, i32 1
  %82 = icmp ne ptr %79, %81
  br i1 %82, label %83, label %101

83:                                               ; preds = %78
  %84 = load ptr, ptr %4, align 8, !tbaa !5
  %85 = ptrtoint ptr %84 to i64
  %86 = sub i64 %85, 0
  %87 = inttoptr i64 %86 to ptr
  store ptr %87, ptr %3, align 8, !tbaa !5
  %88 = load ptr, ptr %3, align 8, !tbaa !5
  %89 = getelementptr inbounds %struct.NET_MAP_ITEM, ptr %88, i32 0, i32 0
  %90 = call ptr @RemoveEntryList(ptr noundef %89)
  %91 = load ptr, ptr @gBS, align 8, !tbaa !5
  %92 = getelementptr inbounds %struct.EFI_BOOT_SERVICES, ptr %91, i32 0, i32 7
  %93 = load ptr, ptr %92, align 8, !tbaa !15
  %94 = load ptr, ptr %3, align 8, !tbaa !5
  %95 = call i64 %93(ptr noundef %94)
  br label %96

96:                                               ; preds = %83
  %97 = load ptr, ptr %5, align 8, !tbaa !5
  store ptr %97, ptr %4, align 8, !tbaa !5
  %98 = load ptr, ptr %4, align 8, !tbaa !5
  %99 = getelementptr inbounds %struct._LIST_ENTRY, ptr %98, i32 0, i32 0
  %100 = load ptr, ptr %99, align 8, !tbaa !13
  store ptr %100, ptr %5, align 8, !tbaa !5
  br label %78, !llvm.loop !22

101:                                              ; preds = %78
  br label %102

102:                                              ; preds = %101
  %103 = call zeroext i8 @DebugAssertEnabled()
  %104 = icmp ne i8 %103, 0
  br i1 %104, label %105, label %112

105:                                              ; preds = %102
  %106 = load ptr, ptr %2, align 8, !tbaa !5
  %107 = getelementptr inbounds %struct.NET_MAP, ptr %106, i32 0, i32 1
  %108 = call zeroext i8 @IsListEmpty(ptr noundef %107)
  %109 = icmp ne i8 %108, 0
  br i1 %109, label %111, label %110

110:                                              ; preds = %105
  call void @DebugAssert(ptr noundef @.str.12, i64 noundef 1250, ptr noundef @.str.22)
  br label %111

111:                                              ; preds = %110, %105
  br label %112

112:                                              ; preds = %111, %102
  br label %113

113:                                              ; preds = %112
  br label %114

114:                                              ; preds = %113
  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 ptr @RemoveEntryList(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, !6, i64 0}
!10 = !{!"", !11, i64 0, !11, i64 16, !12, i64 32}
!11 = !{!"_LIST_ENTRY", !6, i64 0, !6, i64 8}
!12 = !{!"long long", !7, i64 0}
!13 = !{!11, !6, i64 0}
!14 = !{!10, !12, i64 32}
!15 = !{!16, !6, i64 72}
!16 = !{!"", !17, 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}
!17 = !{!"", !12, i64 0, !18, i64 8, !18, i64 12, !18, i64 16, !18, i64 20}
!18 = !{!"int", !7, i64 0}
!19 = distinct !{!19, !20}
!20 = !{!"llvm.loop.mustprogress"}
!21 = !{!10, !6, i64 16}
!22 = distinct !{!22, !20}


; 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
@.str.12 = external hidden unnamed_addr constant [144 x i8], align 1
@.str.20 = external hidden unnamed_addr constant [20 x i8], align 1
@.str.21 = external hidden unnamed_addr constant [46 x i8], align 1
@.str.22 = external hidden unnamed_addr constant [29 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 zeroext i8 @IsListEmpty(ptr noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local void @NetMapClean(ptr noundef %0) local_unnamed_addr #1 {
  %2 = tail call zeroext i8 @DebugAssertEnabled() #2
  %3 = icmp eq i8 %2, 0
  %4 = icmp ne ptr %0, null
  %or.cond = or i1 %4, %3
  br i1 %or.cond, label %6, label %5

5:                                                ; preds = %1
  tail call void @DebugAssert(ptr noundef nonnull @.str.12, i64 noundef 1230, ptr noundef nonnull @.str.20) #2
  br label %6

6:                                                ; preds = %5, %1
  %7 = load ptr, ptr %0, align 8, !tbaa !5
  %.not34 = icmp eq ptr %7, %0
  br i1 %.not34, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %6
  %8 = getelementptr inbounds i8, ptr %0, i64 32
  br label %9

9:                                                ; preds = %.lr.ph, %9
  %.02435 = phi ptr [ %7, %.lr.ph ], [ %.0, %9 ]
  %.0 = load ptr, ptr %.02435, align 8, !tbaa !12
  %10 = tail call ptr @RemoveEntryList(ptr noundef nonnull %.02435) #2
  %11 = load i64, ptr %8, align 8, !tbaa !13
  %12 = add i64 %11, -1
  store i64 %12, ptr %8, align 8, !tbaa !13
  %13 = load ptr, ptr @gBS, align 8, !tbaa !14
  %14 = getelementptr inbounds i8, ptr %13, i64 72
  %15 = load ptr, ptr %14, align 8, !tbaa !15
  %16 = tail call i64 %15(ptr noundef nonnull %.02435) #2
  %.not = icmp eq ptr %.0, %0
  br i1 %.not, label %._crit_edge, label %9, !llvm.loop !19

._crit_edge:                                      ; preds = %9, %6
  %17 = tail call zeroext i8 @DebugAssertEnabled() #2
  %.not29 = icmp eq i8 %17, 0
  br i1 %.not29, label %25, label %18

18:                                               ; preds = %._crit_edge
  %19 = getelementptr inbounds i8, ptr %0, i64 32
  %20 = load i64, ptr %19, align 8, !tbaa !13
  %21 = icmp eq i64 %20, 0
  br i1 %21, label %22, label %24

22:                                               ; preds = %18
  %23 = tail call zeroext i8 @IsListEmpty(ptr noundef nonnull %0) #2
  %.not30 = icmp eq i8 %23, 0
  br i1 %.not30, label %24, label %25

24:                                               ; preds = %22, %18
  tail call void @DebugAssert(ptr noundef nonnull @.str.12, i64 noundef 1241, ptr noundef nonnull @.str.21) #2
  br label %25

25:                                               ; preds = %22, %24, %._crit_edge
  %26 = getelementptr inbounds i8, ptr %0, i64 16
  %27 = load ptr, ptr %26, align 8, !tbaa !21
  %.not3136 = icmp eq ptr %27, %26
  br i1 %.not3136, label %._crit_edge40, label %.lr.ph39

.lr.ph39:                                         ; preds = %25, %.lr.ph39
  %.12537 = phi ptr [ %.1, %.lr.ph39 ], [ %27, %25 ]
  %.1 = load ptr, ptr %.12537, align 8, !tbaa !12
  %28 = tail call ptr @RemoveEntryList(ptr noundef nonnull %.12537) #2
  %29 = load ptr, ptr @gBS, align 8, !tbaa !14
  %30 = getelementptr inbounds i8, ptr %29, i64 72
  %31 = load ptr, ptr %30, align 8, !tbaa !15
  %32 = tail call i64 %31(ptr noundef nonnull %.12537) #2
  %.not31 = icmp eq ptr %.1, %26
  br i1 %.not31, label %._crit_edge40, label %.lr.ph39, !llvm.loop !22

._crit_edge40:                                    ; preds = %.lr.ph39, %25
  %33 = tail call zeroext i8 @DebugAssertEnabled() #2
  %.not32 = icmp eq i8 %33, 0
  br i1 %.not32, label %37, label %34

34:                                               ; preds = %._crit_edge40
  %35 = tail call zeroext i8 @IsListEmpty(ptr noundef nonnull %26) #2
  %.not33 = icmp eq i8 %35, 0
  br i1 %.not33, label %36, label %37

36:                                               ; preds = %34
  tail call void @DebugAssert(ptr noundef nonnull @.str.12, i64 noundef 1250, ptr noundef nonnull @.str.22) #2
  br label %37

37:                                               ; preds = %34, %36, %._crit_edge40
  ret void
}

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, !8, i64 0}
!6 = !{!"", !7, i64 0, !7, i64 16, !11, i64 32}
!7 = !{!"_LIST_ENTRY", !8, i64 0, !8, i64 8}
!8 = !{!"any pointer", !9, i64 0}
!9 = !{!"omnipotent char", !10, i64 0}
!10 = !{!"Simple C/C++ TBAA"}
!11 = !{!"long long", !9, i64 0}
!12 = !{!7, !8, i64 0}
!13 = !{!6, !11, i64 32}
!14 = !{!8, !8, i64 0}
!15 = !{!16, !8, i64 72}
!16 = !{!"", !17, i64 0, !8, i64 24, !8, i64 32, !8, i64 40, !8, i64 48, !8, i64 56, !8, i64 64, !8, i64 72, !8, i64 80, !8, i64 88, !8, i64 96, !8, i64 104, !8, i64 112, !8, i64 120, !8, i64 128, !8, i64 136, !8, i64 144, !8, i64 152, !8, i64 160, !8, i64 168, !8, i64 176, !8, i64 184, !8, i64 192, !8, i64 200, !8, i64 208, !8, i64 216, !8, i64 224, !8, i64 232, !8, i64 240, !8, i64 248, !8, i64 256, !8, i64 264, !8, i64 272, !8, i64 280, !8, i64 288, !8, i64 296, !8, i64 304, !8, i64 312, !8, i64 320, !8, i64 328, !8, i64 336, !8, i64 344, !8, i64 352, !8, i64 360, !8, i64 368}
!17 = !{!"", !11, i64 0, !18, i64 8, !18, i64 12, !18, i64 16, !18, i64 20}
!18 = !{!"int", !9, i64 0}
!19 = distinct !{!19, !20}
!20 = !{!"llvm.loop.mustprogress"}
!21 = !{!6, !8, i64 16}
!22 = distinct !{!22, !20}


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