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

; 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_TCP4_RECEIVE_DATA = type { i8, i32, i32, [1 x %struct.EFI_TCP4_FRAGMENT_DATA] }
%struct.EFI_TCP4_FRAGMENT_DATA = type { i32, ptr }
%struct._SOCKET = type { i32, ptr, ptr, ptr, ptr, %struct._LIST_ENTRY, i8, i32, i8, i16, %struct.EFI_LOCK, %struct._SOCK_BUFFER, %struct._SOCK_BUFFER, i64, i8, i32, i32, ptr, %struct._LIST_ENTRY, %struct._LIST_ENTRY, %struct._LIST_ENTRY, %struct._LIST_ENTRY, %struct._LIST_ENTRY, ptr, ptr, ptr, [20 x i8], %union._NET_PROTOCOL, ptr, ptr, ptr }
%struct.EFI_LOCK = type { i64, i64, i32 }
%struct._SOCK_BUFFER = type { i32, i32, ptr }
%struct._LIST_ENTRY = type { ptr, ptr }
%union._NET_PROTOCOL = type { %struct._EFI_TCP4_PROTOCOL }
%struct._EFI_TCP4_PROTOCOL = type { ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr }

@.str = external hidden unnamed_addr constant [151 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [32 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
define dso_local void @SockSetTcpRxData(ptr noundef %0, ptr noundef %1, i32 noundef %2, i8 noundef zeroext %3) #2 {
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca i32, align 4
  %8 = alloca i8, align 1
  %9 = alloca i32, align 4
  %10 = alloca i32, align 4
  %11 = alloca i32, align 4
  %12 = alloca ptr, align 8
  %13 = alloca ptr, align 8
  store ptr %0, ptr %5, align 8, !tbaa !5
  store ptr %1, ptr %6, align 8, !tbaa !5
  store i32 %2, ptr %7, align 4, !tbaa !9
  store i8 %3, ptr %8, align 1, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %12) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %13) #3
  %14 = load ptr, ptr %6, align 8, !tbaa !5
  store ptr %14, ptr %12, align 8, !tbaa !5
  store i32 0, ptr %11, align 4, !tbaa !9
  br label %15

15:                                               ; preds = %4
  %16 = call zeroext i8 @DebugAssertEnabled()
  %17 = icmp ne i8 %16, 0
  br i1 %17, label %18, label %26

18:                                               ; preds = %15
  %19 = load ptr, ptr %12, align 8, !tbaa !5
  %20 = getelementptr inbounds %struct.EFI_TCP4_RECEIVE_DATA, ptr %19, i32 0, i32 1
  %21 = load i32, ptr %20, align 4, !tbaa !12
  %22 = load i32, ptr %7, align 4, !tbaa !9
  %23 = icmp uge i32 %21, %22
  br i1 %23, label %25, label %24

24:                                               ; preds = %18
  call void @DebugAssert(ptr noundef @.str, i64 noundef 174, ptr noundef @.str.3)
  br label %25

25:                                               ; preds = %24, %18
  br label %26

26:                                               ; preds = %25, %15
  br label %27

27:                                               ; preds = %26
  br label %28

28:                                               ; preds = %27
  %29 = load i32, ptr %7, align 4, !tbaa !9
  %30 = load ptr, ptr %12, align 8, !tbaa !5
  %31 = getelementptr inbounds %struct.EFI_TCP4_RECEIVE_DATA, ptr %30, i32 0, i32 1
  store i32 %29, ptr %31, align 4, !tbaa !12
  %32 = load i8, ptr %8, align 1, !tbaa !11
  %33 = load ptr, ptr %12, align 8, !tbaa !5
  %34 = getelementptr inbounds %struct.EFI_TCP4_RECEIVE_DATA, ptr %33, i32 0, i32 0
  store i8 %32, ptr %34, align 8, !tbaa !14
  store i32 0, ptr %9, align 4, !tbaa !9
  br label %35

35:                                               ; preds = %84, %28
  %36 = load i32, ptr %9, align 4, !tbaa !9
  %37 = load ptr, ptr %12, align 8, !tbaa !5
  %38 = getelementptr inbounds %struct.EFI_TCP4_RECEIVE_DATA, ptr %37, i32 0, i32 2
  %39 = load i32, ptr %38, align 8, !tbaa !15
  %40 = icmp ult i32 %36, %39
  br i1 %40, label %41, label %44

41:                                               ; preds = %35
  %42 = load i32, ptr %7, align 4, !tbaa !9
  %43 = icmp ugt i32 %42, 0
  br label %44

44:                                               ; preds = %41, %35
  %45 = phi i1 [ false, %35 ], [ %43, %41 ]
  br i1 %45, label %46, label %87

46:                                               ; preds = %44
  %47 = load ptr, ptr %12, align 8, !tbaa !5
  %48 = getelementptr inbounds %struct.EFI_TCP4_RECEIVE_DATA, ptr %47, i32 0, i32 3
  %49 = load i32, ptr %9, align 4, !tbaa !9
  %50 = zext i32 %49 to i64
  %51 = getelementptr inbounds [1 x %struct.EFI_TCP4_FRAGMENT_DATA], ptr %48, i64 0, i64 %50
  store ptr %51, ptr %13, align 8, !tbaa !5
  %52 = load ptr, ptr %13, align 8, !tbaa !5
  %53 = getelementptr inbounds %struct.EFI_TCP4_FRAGMENT_DATA, ptr %52, i32 0, i32 0
  %54 = load i32, ptr %53, align 8, !tbaa !16
  %55 = load i32, ptr %7, align 4, !tbaa !9
  %56 = icmp ult i32 %54, %55
  br i1 %56, label %57, label %61

57:                                               ; preds = %46
  %58 = load ptr, ptr %13, align 8, !tbaa !5
  %59 = getelementptr inbounds %struct.EFI_TCP4_FRAGMENT_DATA, ptr %58, i32 0, i32 0
  %60 = load i32, ptr %59, align 8, !tbaa !16
  br label %63

61:                                               ; preds = %46
  %62 = load i32, ptr %7, align 4, !tbaa !9
  br label %63

63:                                               ; preds = %61, %57
  %64 = phi i32 [ %60, %57 ], [ %62, %61 ]
  store i32 %64, ptr %10, align 4, !tbaa !9
  %65 = load ptr, ptr %5, align 8, !tbaa !5
  %66 = getelementptr inbounds %struct._SOCKET, ptr %65, i32 0, i32 12
  %67 = getelementptr inbounds %struct._SOCK_BUFFER, ptr %66, i32 0, i32 2
  %68 = load ptr, ptr %67, align 8, !tbaa !18
  %69 = load i32, ptr %11, align 4, !tbaa !9
  %70 = load i32, ptr %10, align 4, !tbaa !9
  %71 = load ptr, ptr %13, align 8, !tbaa !5
  %72 = getelementptr inbounds %struct.EFI_TCP4_FRAGMENT_DATA, ptr %71, i32 0, i32 1
  %73 = load ptr, ptr %72, align 8, !tbaa !25
  %74 = call i32 @NetbufQueCopy(ptr noundef %68, i32 noundef %69, i32 noundef %70, ptr noundef %73)
  %75 = load i32, ptr %10, align 4, !tbaa !9
  %76 = load ptr, ptr %13, align 8, !tbaa !5
  %77 = getelementptr inbounds %struct.EFI_TCP4_FRAGMENT_DATA, ptr %76, i32 0, i32 0
  store i32 %75, ptr %77, align 8, !tbaa !16
  %78 = load i32, ptr %10, align 4, !tbaa !9
  %79 = load i32, ptr %7, align 4, !tbaa !9
  %80 = sub i32 %79, %78
  store i32 %80, ptr %7, align 4, !tbaa !9
  %81 = load i32, ptr %10, align 4, !tbaa !9
  %82 = load i32, ptr %11, align 4, !tbaa !9
  %83 = add i32 %82, %81
  store i32 %83, ptr %11, align 4, !tbaa !9
  br label %84

84:                                               ; preds = %63
  %85 = load i32, ptr %9, align 4, !tbaa !9
  %86 = add i32 %85, 1
  store i32 %86, ptr %9, align 4, !tbaa !9
  br label %35, !llvm.loop !26

87:                                               ; preds = %44
  call void @llvm.lifetime.end.p0(i64 8, ptr %13) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #3
  ret void
}

declare i32 @NetbufQueCopy(ptr noundef, i32 noundef, i32 noundef, 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, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = !{!7, !7, i64 0}
!12 = !{!13, !10, i64 4}
!13 = !{!"", !7, i64 0, !10, i64 4, !10, i64 8, !7, i64 16}
!14 = !{!13, !7, i64 0}
!15 = !{!13, !10, i64 8}
!16 = !{!17, !10, i64 0}
!17 = !{!"", !10, i64 0, !6, i64 8}
!18 = !{!19, !6, i64 120}
!19 = !{!"_SOCKET", !10, i64 0, !6, i64 8, !6, i64 16, !6, i64 24, !6, i64 32, !20, i64 40, !7, i64 56, !10, i64 60, !7, i64 64, !21, i64 66, !22, i64 72, !24, i64 96, !24, i64 112, !23, i64 128, !7, i64 136, !10, i64 140, !10, i64 144, !6, i64 152, !20, i64 160, !20, i64 176, !20, i64 192, !20, i64 208, !20, i64 224, !6, i64 240, !6, i64 248, !6, i64 256, !7, i64 264, !7, i64 288, !6, i64 368, !6, i64 376, !6, i64 384}
!20 = !{!"_LIST_ENTRY", !6, i64 0, !6, i64 8}
!21 = !{!"short", !7, i64 0}
!22 = !{!"", !23, i64 0, !23, i64 8, !10, i64 16}
!23 = !{!"long long", !7, i64 0}
!24 = !{!"_SOCK_BUFFER", !10, i64 0, !10, i64 4, !6, i64 8}
!25 = !{!17, !6, i64 8}
!26 = distinct !{!26, !27}
!27 = !{!"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"

%struct.EFI_TCP4_FRAGMENT_DATA = type { i32, ptr }

@.str = external hidden unnamed_addr constant [151 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [32 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
define dso_local void @SockSetTcpRxData(ptr nocapture noundef readonly %0, ptr nocapture noundef %1, i32 noundef %2, i8 noundef zeroext %3) local_unnamed_addr #1 {
  %5 = tail call zeroext i8 @DebugAssertEnabled() #3
  %.not = icmp eq i8 %5, 0
  br i1 %.not, label %10, label %6

6:                                                ; preds = %4
  %7 = getelementptr inbounds i8, ptr %1, i64 4
  %8 = load i32, ptr %7, align 4, !tbaa !5
  %.not29 = icmp ult i32 %8, %2
  br i1 %.not29, label %9, label %10

9:                                                ; preds = %6
  tail call void @DebugAssert(ptr noundef nonnull @.str, i64 noundef 174, ptr noundef nonnull @.str.3) #3
  br label %10

10:                                               ; preds = %6, %9, %4
  %11 = getelementptr inbounds i8, ptr %1, i64 4
  store i32 %2, ptr %11, align 4, !tbaa !5
  store i8 %3, ptr %1, align 8, !tbaa !10
  %12 = getelementptr inbounds i8, ptr %1, i64 8
  %13 = load i32, ptr %12, align 8, !tbaa !11
  %14 = icmp ne i32 %13, 0
  %15 = icmp ne i32 %2, 0
  %16 = and i1 %14, %15
  br i1 %16, label %.lr.ph, label %._crit_edge

.lr.ph:                                           ; preds = %10
  %17 = getelementptr inbounds i8, ptr %1, i64 16
  %18 = getelementptr inbounds i8, ptr %0, i64 120
  br label %19

19:                                               ; preds = %.lr.ph, %19
  %indvars.iv = phi i64 [ 0, %.lr.ph ], [ %indvars.iv.next, %19 ]
  %.032 = phi i32 [ %2, %.lr.ph ], [ %26, %19 ]
  %.02730 = phi i32 [ 0, %.lr.ph ], [ %27, %19 ]
  %20 = getelementptr inbounds [1 x %struct.EFI_TCP4_FRAGMENT_DATA], ptr %17, i64 0, i64 %indvars.iv
  %21 = load i32, ptr %20, align 8, !tbaa !12
  %..0 = tail call i32 @llvm.umin.i32(i32 %21, i32 %.032)
  %22 = load ptr, ptr %18, align 8, !tbaa !15
  %23 = getelementptr inbounds i8, ptr %20, i64 8
  %24 = load ptr, ptr %23, align 8, !tbaa !22
  %25 = tail call i32 @NetbufQueCopy(ptr noundef %22, i32 noundef %.02730, i32 noundef %..0, ptr noundef %24) #3
  store i32 %..0, ptr %20, align 8, !tbaa !12
  %26 = sub i32 %.032, %..0
  %27 = add i32 %..0, %.02730
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %28 = load i32, ptr %12, align 8, !tbaa !11
  %29 = zext i32 %28 to i64
  %30 = icmp ult i64 %indvars.iv.next, %29
  %31 = icmp ne i32 %26, 0
  %32 = and i1 %30, %31
  br i1 %32, label %19, label %._crit_edge, !llvm.loop !23

._crit_edge:                                      ; preds = %19, %10
  ret void
}

declare i32 @NetbufQueCopy(ptr noundef, i32 noundef, i32 noundef, ptr noundef) local_unnamed_addr #0

; 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, !9, i64 4}
!6 = !{!"", !7, i64 0, !9, i64 4, !9, i64 8, !7, i64 16}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!"int", !7, i64 0}
!10 = !{!6, !7, i64 0}
!11 = !{!6, !9, i64 8}
!12 = !{!13, !9, i64 0}
!13 = !{!"", !9, i64 0, !14, i64 8}
!14 = !{!"any pointer", !7, i64 0}
!15 = !{!16, !14, i64 120}
!16 = !{!"_SOCKET", !9, i64 0, !14, i64 8, !14, i64 16, !14, i64 24, !14, i64 32, !17, i64 40, !7, i64 56, !9, i64 60, !7, i64 64, !18, i64 66, !19, i64 72, !21, i64 96, !21, i64 112, !20, i64 128, !7, i64 136, !9, i64 140, !9, i64 144, !14, i64 152, !17, i64 160, !17, i64 176, !17, i64 192, !17, i64 208, !17, i64 224, !14, i64 240, !14, i64 248, !14, i64 256, !7, i64 264, !7, i64 288, !14, i64 368, !14, i64 376, !14, i64 384}
!17 = !{!"_LIST_ENTRY", !14, i64 0, !14, i64 8}
!18 = !{!"short", !7, i64 0}
!19 = !{!"", !20, i64 0, !20, i64 8, !9, i64 16}
!20 = !{!"long long", !7, i64 0}
!21 = !{!"_SOCK_BUFFER", !9, i64 0, !9, i64 4, !14, i64 8}
!22 = !{!13, !14, i64 8}
!23 = distinct !{!23, !24}
!24 = !{!"llvm.loop.mustprogress"}


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