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

; 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._TCP_CB = type { %struct._LIST_ENTRY, ptr, ptr, %struct._TCP_PEER, %struct._TCP_PEER, %struct._LIST_ENTRY, %struct._LIST_ENTRY, i32, i32, i8, i8, i16, i32, i32, i32, i32, i32, i32, i32, i32, i32, i16, i32, i32, i32, i32, i32, i16, i16, [6 x i32], i32, i32, i32, i8, i8, i8, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i16, i8, i8, i32, i32, i32, i8, i8, i16, i32, i32, i32, i8, i8, i8, %struct.EFI_IPv4_ADDRESS, ptr }
%struct._TCP_PEER = type { i32, i16 }
%struct._LIST_ENTRY = type { ptr, ptr }
%struct.EFI_IPv4_ADDRESS = type { [4 x i8] }
%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 }
%struct._TCP_SEG = type { i32, i32, i32, i8, i16, i32 }

; 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

; Function Attrs: nounwind uwtable
declare dso_local void @TcpTrimSegment(ptr noundef, i32 noundef, i32 noundef) #1

declare ptr @RemoveEntryList(ptr noundef) #2

declare void @NetbufFree(ptr noundef) #2

; Function Attrs: nounwind uwtable
define dso_local void @TcpAdjustSndQue(ptr noundef %0, i32 noundef %1) #1 {
  %3 = alloca ptr, align 8
  %4 = alloca i32, align 4
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca ptr, align 8
  store ptr %0, ptr %3, align 8, !tbaa !5
  store i32 %1, ptr %4, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #3
  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
  %9 = load ptr, ptr %3, align 8, !tbaa !5
  %10 = getelementptr inbounds %struct._TCP_CB, ptr %9, i32 0, i32 5
  store ptr %10, ptr %5, align 8, !tbaa !5
  %11 = load ptr, ptr %5, align 8, !tbaa !5
  %12 = getelementptr inbounds %struct._LIST_ENTRY, ptr %11, i32 0, i32 0
  %13 = load ptr, ptr %12, align 8, !tbaa !11
  store ptr %13, ptr %6, align 8, !tbaa !5
  br label %14

14:                                               ; preds = %40, %2
  %15 = load ptr, ptr %6, align 8, !tbaa !5
  %16 = load ptr, ptr %5, align 8, !tbaa !5
  %17 = icmp ne ptr %15, %16
  br i1 %17, label %18, label %54

18:                                               ; preds = %14
  %19 = load ptr, ptr %6, align 8, !tbaa !5
  %20 = ptrtoint ptr %19 to i64
  %21 = sub i64 %20, ptrtoint (ptr getelementptr inbounds (%struct.NET_BUF, ptr null, i32 0, i32 2) to i64)
  %22 = inttoptr i64 %21 to ptr
  store ptr %22, ptr %7, align 8, !tbaa !5
  %23 = load ptr, ptr %7, align 8, !tbaa !5
  %24 = getelementptr inbounds %struct.NET_BUF, ptr %23, i32 0, i32 6
  %25 = getelementptr inbounds [64 x i8], ptr %24, i64 0, i64 0
  store ptr %25, ptr %8, align 8, !tbaa !5
  %26 = load i32, ptr %4, align 4, !tbaa !9
  %27 = load ptr, ptr %8, align 8, !tbaa !5
  %28 = getelementptr inbounds %struct._TCP_SEG, ptr %27, i32 0, i32 0
  %29 = load i32, ptr %28, align 4, !tbaa !13
  %30 = sub i32 %26, %29
  %31 = icmp sle i32 %30, 0
  br i1 %31, label %32, label %33

32:                                               ; preds = %18
  br label %54

33:                                               ; preds = %18
  %34 = load ptr, ptr %8, align 8, !tbaa !5
  %35 = getelementptr inbounds %struct._TCP_SEG, ptr %34, i32 0, i32 1
  %36 = load i32, ptr %35, align 4, !tbaa !16
  %37 = load i32, ptr %4, align 4, !tbaa !9
  %38 = sub i32 %36, %37
  %39 = icmp sle i32 %38, 0
  br i1 %39, label %40, label %48

40:                                               ; preds = %33
  %41 = load ptr, ptr %6, align 8, !tbaa !5
  %42 = getelementptr inbounds %struct._LIST_ENTRY, ptr %41, i32 0, i32 0
  %43 = load ptr, ptr %42, align 8, !tbaa !11
  store ptr %43, ptr %6, align 8, !tbaa !5
  %44 = load ptr, ptr %7, align 8, !tbaa !5
  %45 = getelementptr inbounds %struct.NET_BUF, ptr %44, i32 0, i32 2
  %46 = call ptr @RemoveEntryList(ptr noundef %45)
  %47 = load ptr, ptr %7, align 8, !tbaa !5
  call void @NetbufFree(ptr noundef %47)
  br label %14, !llvm.loop !17

48:                                               ; preds = %33
  %49 = load ptr, ptr %7, align 8, !tbaa !5
  %50 = load i32, ptr %4, align 4, !tbaa !9
  %51 = load ptr, ptr %8, align 8, !tbaa !5
  %52 = getelementptr inbounds %struct._TCP_SEG, ptr %51, i32 0, i32 1
  %53 = load i32, ptr %52, align 4, !tbaa !16
  call void @TcpTrimSegment(ptr noundef %49, i32 noundef %50, i32 noundef %53)
  br label %54

54:                                               ; preds = %48, %32, %14
  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
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #3
  ret void
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = { "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, !6, i64 0}
!12 = !{!"_LIST_ENTRY", !6, i64 0, !6, i64 8}
!13 = !{!14, !10, i64 0}
!14 = !{!"_TCP_SEG", !10, i64 0, !10, i64 4, !10, i64 8, !7, i64 12, !15, i64 14, !10, i64 16}
!15 = !{!"short", !7, i64 0}
!16 = !{!14, !10, i64 4}
!17 = distinct !{!17, !18}
!18 = !{!"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"

; Function Attrs: nounwind uwtable
declare dso_local void @TcpTrimSegment(ptr noundef, i32 noundef, i32 noundef) local_unnamed_addr #0

declare ptr @RemoveEntryList(ptr noundef) local_unnamed_addr #1

declare void @NetbufFree(ptr noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
define dso_local void @TcpAdjustSndQue(ptr noundef readonly %0, i32 noundef %1) local_unnamed_addr #0 {
  %3 = getelementptr inbounds i8, ptr %0, i64 48
  %4 = load ptr, ptr %3, align 8, !tbaa !5
  %.not16 = icmp eq ptr %4, %3
  br i1 %.not16, label %.loopexit, label %.lr.ph

.lr.ph:                                           ; preds = %2, %17
  %.017 = phi ptr [ %18, %17 ], [ %4, %2 ]
  %5 = ptrtoint ptr %.017 to i64
  %6 = add i64 %5, -16
  %7 = inttoptr i64 %6 to ptr
  %8 = getelementptr inbounds i8, ptr %7, i64 56
  %9 = load i32, ptr %8, align 4, !tbaa !10
  %10 = sub i32 %1, %9
  %11 = icmp slt i32 %10, 1
  br i1 %11, label %.loopexit, label %12

12:                                               ; preds = %.lr.ph
  %13 = getelementptr inbounds i8, ptr %7, i64 60
  %14 = load i32, ptr %13, align 4, !tbaa !14
  %15 = sub i32 %14, %1
  %16 = icmp slt i32 %15, 1
  br i1 %16, label %17, label %21

17:                                               ; preds = %12
  %18 = load ptr, ptr %.017, align 8, !tbaa !5
  %19 = getelementptr inbounds i8, ptr %7, i64 16
  %20 = tail call ptr @RemoveEntryList(ptr noundef nonnull %19) #2
  tail call void @NetbufFree(ptr noundef nonnull %7) #2
  %.not = icmp eq ptr %18, %3
  br i1 %.not, label %.loopexit, label %.lr.ph, !llvm.loop !15

21:                                               ; preds = %12
  tail call void @TcpTrimSegment(ptr noundef nonnull %7, i32 noundef %1, i32 noundef %14)
  br label %.loopexit

.loopexit:                                        ; preds = %17, %.lr.ph, %2, %21
  ret void
}

attributes #0 = { 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 #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 }

!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 = !{!"_LIST_ENTRY", !7, i64 0, !7, i64 8}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!11, !12, i64 0}
!11 = !{!"_TCP_SEG", !12, i64 0, !12, i64 4, !12, i64 8, !8, i64 12, !13, i64 14, !12, i64 16}
!12 = !{!"int", !8, i64 0}
!13 = !{!"short", !8, i64 0}
!14 = !{!11, !12, i64 4}
!15 = distinct !{!15, !16}
!16 = !{!"llvm.loop.mustprogress"}


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