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

; 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_BUF_QUEUE = type { i32, i64, %struct._LIST_ENTRY, %struct._LIST_ENTRY, i32, i32 }
%struct._LIST_ENTRY = type { ptr, ptr }
%struct.NET_BUF = type { i32, i64, %struct._LIST_ENTRY, %union.NET_IP_HEAD, ptr, ptr, [64 x i8], ptr, i32, i32, [1 x %struct.NET_BLOCK_OP] }
%union.NET_IP_HEAD = type { ptr }
%struct.NET_BLOCK_OP = type { ptr, ptr, ptr, ptr, i32 }

@.str = external hidden unnamed_addr constant [144 x i8], align 1
@.str.20 = external hidden unnamed_addr constant [113 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

; Function Attrs: nounwind uwtable
declare dso_local void @NetbufFree(ptr noundef) #2

declare ptr @RemoveEntryList(ptr noundef) #1

; Function Attrs: nounwind uwtable
declare dso_local i32 @NetbufTrim(ptr noundef, i32 noundef, i8 noundef zeroext) #2

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

11:                                               ; preds = %2
  %12 = call zeroext i8 @DebugAssertEnabled()
  %13 = icmp ne i8 %12, 0
  br i1 %13, label %14, label %24

14:                                               ; preds = %11
  %15 = load ptr, ptr %4, align 8, !tbaa !5
  %16 = icmp ne ptr %15, null
  br i1 %16, label %17, label %22

17:                                               ; preds = %14
  %18 = load ptr, ptr %4, align 8, !tbaa !5
  %19 = getelementptr inbounds %struct.NET_BUF_QUEUE, ptr %18, i32 0, i32 0
  %20 = load i32, ptr %19, align 8, !tbaa !11
  %21 = icmp eq i32 %20, 1970365038
  br i1 %21, label %23, label %22

22:                                               ; preds = %17, %14
  call void @DebugAssert(ptr noundef @.str, i64 noundef 1584, ptr noundef @.str.20)
  br label %23

23:                                               ; preds = %22, %17
  br label %24

24:                                               ; preds = %23, %11
  br label %25

25:                                               ; preds = %24
  br label %26

26:                                               ; preds = %25
  %27 = load i32, ptr %5, align 4, !tbaa !9
  %28 = icmp eq i32 %27, 0
  br i1 %28, label %29, label %30

29:                                               ; preds = %26
  store i32 0, ptr %3, align 4
  store i32 1, ptr %10, align 4
  br label %104

30:                                               ; preds = %26
  %31 = load i32, ptr %5, align 4, !tbaa !9
  %32 = load ptr, ptr %4, align 8, !tbaa !5
  %33 = getelementptr inbounds %struct.NET_BUF_QUEUE, ptr %32, i32 0, i32 4
  %34 = load i32, ptr %33, align 8, !tbaa !15
  %35 = icmp ugt i32 %31, %34
  br i1 %35, label %36, label %40

36:                                               ; preds = %30
  %37 = load ptr, ptr %4, align 8, !tbaa !5
  %38 = getelementptr inbounds %struct.NET_BUF_QUEUE, ptr %37, i32 0, i32 4
  %39 = load i32, ptr %38, align 8, !tbaa !15
  store i32 %39, ptr %5, align 4, !tbaa !9
  br label %40

40:                                               ; preds = %36, %30
  %41 = load i32, ptr %5, align 4, !tbaa !9
  %42 = load ptr, ptr %4, align 8, !tbaa !5
  %43 = getelementptr inbounds %struct.NET_BUF_QUEUE, ptr %42, i32 0, i32 4
  %44 = load i32, ptr %43, align 8, !tbaa !15
  %45 = sub i32 %44, %41
  store i32 %45, ptr %43, align 8, !tbaa !15
  store i32 0, ptr %9, align 4, !tbaa !9
  %46 = load ptr, ptr %4, align 8, !tbaa !5
  %47 = getelementptr inbounds %struct.NET_BUF_QUEUE, ptr %46, i32 0, i32 3
  %48 = getelementptr inbounds %struct._LIST_ENTRY, ptr %47, i32 0, i32 0
  %49 = load ptr, ptr %48, align 8, !tbaa !16
  store ptr %49, ptr %6, align 8, !tbaa !5
  %50 = load ptr, ptr %6, align 8, !tbaa !5
  %51 = getelementptr inbounds %struct._LIST_ENTRY, ptr %50, i32 0, i32 0
  %52 = load ptr, ptr %51, align 8, !tbaa !17
  store ptr %52, ptr %7, align 8, !tbaa !5
  br label %53

53:                                               ; preds = %97, %40
  %54 = load ptr, ptr %6, align 8, !tbaa !5
  %55 = load ptr, ptr %4, align 8, !tbaa !5
  %56 = getelementptr inbounds %struct.NET_BUF_QUEUE, ptr %55, i32 0, i32 3
  %57 = icmp ne ptr %54, %56
  br i1 %57, label %58, label %102

58:                                               ; preds = %53
  %59 = load ptr, ptr %6, align 8, !tbaa !5
  %60 = ptrtoint ptr %59 to i64
  %61 = sub i64 %60, ptrtoint (ptr getelementptr inbounds (%struct.NET_BUF, ptr null, i32 0, i32 2) to i64)
  %62 = inttoptr i64 %61 to ptr
  store ptr %62, ptr %8, align 8, !tbaa !5
  %63 = load i32, ptr %5, align 4, !tbaa !9
  %64 = load ptr, ptr %8, align 8, !tbaa !5
  %65 = getelementptr inbounds %struct.NET_BUF, ptr %64, i32 0, i32 9
  %66 = load i32, ptr %65, align 4, !tbaa !18
  %67 = icmp uge i32 %63, %66
  br i1 %67, label %68, label %90

68:                                               ; preds = %58
  %69 = load ptr, ptr %8, align 8, !tbaa !5
  %70 = getelementptr inbounds %struct.NET_BUF, ptr %69, i32 0, i32 9
  %71 = load i32, ptr %70, align 4, !tbaa !18
  %72 = load i32, ptr %9, align 4, !tbaa !9
  %73 = add i32 %72, %71
  store i32 %73, ptr %9, align 4, !tbaa !9
  %74 = load ptr, ptr %8, align 8, !tbaa !5
  %75 = getelementptr inbounds %struct.NET_BUF, ptr %74, i32 0, i32 9
  %76 = load i32, ptr %75, align 4, !tbaa !18
  %77 = load i32, ptr %5, align 4, !tbaa !9
  %78 = sub i32 %77, %76
  store i32 %78, ptr %5, align 4, !tbaa !9
  %79 = load ptr, ptr %6, align 8, !tbaa !5
  %80 = call ptr @RemoveEntryList(ptr noundef %79)
  %81 = load ptr, ptr %8, align 8, !tbaa !5
  call void @NetbufFree(ptr noundef %81)
  %82 = load ptr, ptr %4, align 8, !tbaa !5
  %83 = getelementptr inbounds %struct.NET_BUF_QUEUE, ptr %82, i32 0, i32 5
  %84 = load i32, ptr %83, align 4, !tbaa !20
  %85 = add i32 %84, -1
  store i32 %85, ptr %83, align 4, !tbaa !20
  %86 = load i32, ptr %5, align 4, !tbaa !9
  %87 = icmp eq i32 %86, 0
  br i1 %87, label %88, label %89

88:                                               ; preds = %68
  br label %102

89:                                               ; preds = %68
  br label %96

90:                                               ; preds = %58
  %91 = load ptr, ptr %8, align 8, !tbaa !5
  %92 = load i32, ptr %5, align 4, !tbaa !9
  %93 = call i32 @NetbufTrim(ptr noundef %91, i32 noundef %92, i8 noundef zeroext 1)
  %94 = load i32, ptr %9, align 4, !tbaa !9
  %95 = add i32 %94, %93
  store i32 %95, ptr %9, align 4, !tbaa !9
  br label %102

96:                                               ; preds = %89
  br label %97

97:                                               ; preds = %96
  %98 = load ptr, ptr %7, align 8, !tbaa !5
  store ptr %98, ptr %6, align 8, !tbaa !5
  %99 = load ptr, ptr %6, align 8, !tbaa !5
  %100 = getelementptr inbounds %struct._LIST_ENTRY, ptr %99, i32 0, i32 0
  %101 = load ptr, ptr %100, align 8, !tbaa !17
  store ptr %101, ptr %7, align 8, !tbaa !5
  br label %53, !llvm.loop !21

102:                                              ; preds = %90, %88, %53
  %103 = load i32, ptr %9, align 4, !tbaa !9
  store i32 %103, ptr %3, align 4
  store i32 1, ptr %10, align 4
  br label %104

104:                                              ; preds = %102, %29
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #3
  %105 = load i32, ptr %3, align 4
  ret i32 %105
}

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, !10, i64 0}
!12 = !{!"", !10, i64 0, !13, i64 8, !14, i64 16, !14, i64 32, !10, i64 48, !10, i64 52}
!13 = !{!"long long", !7, i64 0}
!14 = !{!"_LIST_ENTRY", !6, i64 0, !6, i64 8}
!15 = !{!12, !10, i64 48}
!16 = !{!12, !6, i64 32}
!17 = !{!14, !6, i64 0}
!18 = !{!19, !10, i64 132}
!19 = !{!"", !10, i64 0, !13, i64 8, !14, i64 16, !7, i64 32, !6, i64 40, !6, i64 48, !7, i64 56, !6, i64 120, !10, i64 128, !10, i64 132, !7, i64 136}
!20 = !{!12, !10, i64 52}
!21 = distinct !{!21, !22}
!22 = !{!"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"

@.str = external hidden unnamed_addr constant [144 x i8], align 1
@.str.20 = external hidden unnamed_addr constant [113 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

; Function Attrs: nounwind uwtable
declare dso_local void @NetbufFree(ptr noundef) local_unnamed_addr #1

declare ptr @RemoveEntryList(ptr noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
declare dso_local i32 @NetbufTrim(ptr noundef, i32 noundef, i8 noundef zeroext) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
define dso_local i32 @NetbufQueTrim(ptr noundef %0, i32 noundef %1) local_unnamed_addr #1 {
  %3 = tail call zeroext i8 @DebugAssertEnabled() #3
  %.not = icmp eq i8 %3, 0
  br i1 %.not, label %9, label %4

4:                                                ; preds = %2
  %.not39 = icmp eq ptr %0, null
  br i1 %.not39, label %8, label %5

5:                                                ; preds = %4
  %6 = load i32, ptr %0, align 8, !tbaa !5
  %7 = icmp eq i32 %6, 1970365038
  br i1 %7, label %9, label %8

8:                                                ; preds = %5, %4
  tail call void @DebugAssert(ptr noundef nonnull @.str, i64 noundef 1584, ptr noundef nonnull @.str.20) #3
  br label %9

9:                                                ; preds = %5, %8, %2
  %10 = icmp eq i32 %1, 0
  br i1 %10, label %.loopexit, label %11

11:                                               ; preds = %9
  %12 = getelementptr inbounds i8, ptr %0, i64 48
  %13 = load i32, ptr %12, align 8, !tbaa !13
  %spec.select = tail call i32 @llvm.umin.i32(i32 %13, i32 %1)
  %14 = sub i32 %13, %spec.select
  store i32 %14, ptr %12, align 8, !tbaa !13
  %15 = getelementptr inbounds i8, ptr %0, i64 32
  %16 = load ptr, ptr %15, align 8, !tbaa !14
  %17 = getelementptr inbounds i8, ptr %0, i64 52
  br label %18

18:                                               ; preds = %25, %11
  %.133 = phi i32 [ %spec.select, %11 ], [ %27, %25 ]
  %.031 = phi ptr [ %16, %11 ], [ %.030, %25 ]
  %.0 = phi i32 [ 0, %11 ], [ %26, %25 ]
  %.030 = load ptr, ptr %.031, align 8, !tbaa !15
  %.not40 = icmp eq ptr %.031, %15
  br i1 %.not40, label %.loopexit, label %19

19:                                               ; preds = %18
  %20 = ptrtoint ptr %.031 to i64
  %21 = add i64 %20, -16
  %22 = inttoptr i64 %21 to ptr
  %23 = getelementptr inbounds i8, ptr %22, i64 132
  %24 = load i32, ptr %23, align 4, !tbaa !16
  %.not41 = icmp ult i32 %.133, %24
  br i1 %.not41, label %32, label %25

25:                                               ; preds = %19
  %26 = add i32 %24, %.0
  %27 = sub i32 %.133, %24
  %28 = tail call ptr @RemoveEntryList(ptr noundef nonnull %.031) #3
  tail call void @NetbufFree(ptr noundef nonnull %22)
  %29 = load i32, ptr %17, align 4, !tbaa !18
  %30 = add i32 %29, -1
  store i32 %30, ptr %17, align 4, !tbaa !18
  %31 = icmp eq i32 %27, 0
  br i1 %31, label %.loopexit, label %18, !llvm.loop !19

32:                                               ; preds = %19
  %33 = tail call i32 @NetbufTrim(ptr noundef nonnull %22, i32 noundef %.133, i8 noundef zeroext 1)
  %34 = add i32 %33, %.0
  br label %.loopexit

.loopexit:                                        ; preds = %18, %25, %32, %9
  %.029 = phi i32 [ 0, %9 ], [ %34, %32 ], [ %.0, %18 ], [ %26, %25 ]
  ret i32 %.029
}

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i32 @llvm.umin.i32(i32, i32) #2

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 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
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, !7, i64 0}
!6 = !{!"", !7, i64 0, !10, i64 8, !11, i64 16, !11, i64 32, !7, i64 48, !7, i64 52}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"long long", !8, i64 0}
!11 = !{!"_LIST_ENTRY", !12, i64 0, !12, i64 8}
!12 = !{!"any pointer", !8, i64 0}
!13 = !{!6, !7, i64 48}
!14 = !{!6, !12, i64 32}
!15 = !{!11, !12, i64 0}
!16 = !{!17, !7, i64 132}
!17 = !{!"", !7, i64 0, !10, i64 8, !11, i64 16, !8, i64 32, !12, i64 40, !12, i64 48, !8, i64 56, !12, i64 120, !7, i64 128, !7, i64 132, !8, i64 136}
!18 = !{!6, !7, i64 52}
!19 = distinct !{!19, !20}
!20 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GVNPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LICMPass,LoopSimplifyPass,LoopUnrollPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass