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

; 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.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] }
%struct._LIST_ENTRY = type { ptr, ptr }
%union.NET_IP_HEAD = type { ptr }
%struct.NET_BLOCK_OP = type { ptr, ptr, ptr, ptr, i32 }
%struct._TCP4_IO = type { ptr, ptr, ptr, ptr, %struct.EFI_TCP4_CONNECTION_TOKEN, %struct.EFI_TCP4_IO_TOKEN, %struct.EFI_TCP4_IO_TOKEN, %struct.EFI_TCP4_CLOSE_TOKEN, i8, i8, i8, i8 }
%struct.EFI_TCP4_CONNECTION_TOKEN = type { %struct.EFI_TCP4_COMPLETION_TOKEN }
%struct.EFI_TCP4_COMPLETION_TOKEN = type { ptr, i64 }
%struct.EFI_TCP4_IO_TOKEN = type { %struct.EFI_TCP4_COMPLETION_TOKEN, %union.anon }
%union.anon = type { ptr }
%struct.EFI_TCP4_CLOSE_TOKEN = type { %struct.EFI_TCP4_COMPLETION_TOKEN, i8 }
%struct.NET_FRAGMENT = type { i32, ptr }
%struct._EFI_TCP4_PROTOCOL = type { ptr, ptr, ptr, ptr, ptr, 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

; 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 ptr @AllocatePool(i64 noundef) #1

declare i64 @NetbufBuildExt(ptr noundef, ptr noundef, ptr noundef) #1

declare void @FreePool(ptr noundef) #1

; Function Attrs: nounwind uwtable
define dso_local i64 @Tcp4IoReceive(ptr noundef %0, ptr noundef %1, i8 noundef zeroext %2, ptr noundef %3) #2 {
  %5 = alloca i64, align 8
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca i8, align 1
  %9 = alloca ptr, align 8
  %10 = alloca ptr, align 8
  %11 = alloca %struct.EFI_TCP4_RECEIVE_DATA, align 8
  %12 = alloca i64, align 8
  %13 = alloca ptr, align 8
  %14 = alloca i32, align 4
  %15 = alloca i32, align 4
  %16 = alloca i32, align 4
  store ptr %0, ptr %6, align 8, !tbaa !5
  store ptr %1, ptr %7, align 8, !tbaa !5
  store i8 %2, ptr %8, align 1, !tbaa !9
  store ptr %3, ptr %9, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #3
  call void @llvm.lifetime.start.p0(i64 32, 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
  call void @llvm.lifetime.start.p0(i64 4, ptr %14) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %15) #3
  %17 = load ptr, ptr %7, align 8, !tbaa !5
  %18 = getelementptr inbounds %struct.NET_BUF, ptr %17, i32 0, i32 8
  %19 = load i32, ptr %18, align 8, !tbaa !10
  store i32 %19, ptr %14, align 4, !tbaa !15
  %20 = load i32, ptr %14, align 4, !tbaa !15
  %21 = zext i32 %20 to i64
  %22 = mul i64 %21, 16
  %23 = call ptr @AllocatePool(i64 noundef %22)
  store ptr %23, ptr %13, align 8, !tbaa !5
  %24 = load ptr, ptr %13, align 8, !tbaa !5
  %25 = icmp eq ptr %24, null
  br i1 %25, label %26, label %27

26:                                               ; preds = %4
  store i64 -9223372036854775799, ptr %5, align 8
  store i32 1, ptr %16, align 4
  br label %177

27:                                               ; preds = %4
  %28 = load ptr, ptr %7, align 8, !tbaa !5
  %29 = load ptr, ptr %13, align 8, !tbaa !5
  %30 = call i64 @NetbufBuildExt(ptr noundef %28, ptr noundef %29, ptr noundef %14)
  %31 = getelementptr inbounds %struct.EFI_TCP4_RECEIVE_DATA, ptr %11, i32 0, i32 2
  store i32 1, ptr %31, align 8, !tbaa !16
  %32 = load ptr, ptr %6, align 8, !tbaa !5
  %33 = getelementptr inbounds %struct._TCP4_IO, ptr %32, i32 0, i32 6
  %34 = getelementptr inbounds %struct.EFI_TCP4_IO_TOKEN, ptr %33, i32 0, i32 1
  store ptr %11, ptr %34, align 8, !tbaa !9
  store i32 0, ptr %15, align 4, !tbaa !15
  %35 = load ptr, ptr %6, align 8, !tbaa !5
  %36 = getelementptr inbounds %struct._TCP4_IO, ptr %35, i32 0, i32 3
  %37 = load ptr, ptr %36, align 8, !tbaa !18
  store ptr %37, ptr %10, align 8, !tbaa !5
  store i64 0, ptr %12, align 8, !tbaa !23
  br label %38

38:                                               ; preds = %169, %27
  %39 = load i32, ptr %15, align 4, !tbaa !15
  %40 = load i32, ptr %14, align 4, !tbaa !15
  %41 = icmp ult i32 %39, %40
  br i1 %41, label %42, label %170

42:                                               ; preds = %38
  %43 = load ptr, ptr %13, align 8, !tbaa !5
  %44 = load i32, ptr %15, align 4, !tbaa !15
  %45 = zext i32 %44 to i64
  %46 = getelementptr inbounds %struct.NET_FRAGMENT, ptr %43, i64 %45
  %47 = getelementptr inbounds %struct.NET_FRAGMENT, ptr %46, i32 0, i32 0
  %48 = load i32, ptr %47, align 8, !tbaa !24
  %49 = getelementptr inbounds %struct.EFI_TCP4_RECEIVE_DATA, ptr %11, i32 0, i32 1
  store i32 %48, ptr %49, align 4, !tbaa !26
  %50 = load ptr, ptr %13, align 8, !tbaa !5
  %51 = load i32, ptr %15, align 4, !tbaa !15
  %52 = zext i32 %51 to i64
  %53 = getelementptr inbounds %struct.NET_FRAGMENT, ptr %50, i64 %52
  %54 = getelementptr inbounds %struct.NET_FRAGMENT, ptr %53, i32 0, i32 0
  %55 = load i32, ptr %54, align 8, !tbaa !24
  %56 = getelementptr inbounds %struct.EFI_TCP4_RECEIVE_DATA, ptr %11, i32 0, i32 3
  %57 = getelementptr inbounds [1 x %struct.EFI_TCP4_FRAGMENT_DATA], ptr %56, i64 0, i64 0
  %58 = getelementptr inbounds %struct.EFI_TCP4_FRAGMENT_DATA, ptr %57, i32 0, i32 0
  store i32 %55, ptr %58, align 8, !tbaa !24
  %59 = load ptr, ptr %13, align 8, !tbaa !5
  %60 = load i32, ptr %15, align 4, !tbaa !15
  %61 = zext i32 %60 to i64
  %62 = getelementptr inbounds %struct.NET_FRAGMENT, ptr %59, i64 %61
  %63 = getelementptr inbounds %struct.NET_FRAGMENT, ptr %62, i32 0, i32 1
  %64 = load ptr, ptr %63, align 8, !tbaa !27
  %65 = getelementptr inbounds %struct.EFI_TCP4_RECEIVE_DATA, ptr %11, i32 0, i32 3
  %66 = getelementptr inbounds [1 x %struct.EFI_TCP4_FRAGMENT_DATA], ptr %65, i64 0, i64 0
  %67 = getelementptr inbounds %struct.EFI_TCP4_FRAGMENT_DATA, ptr %66, i32 0, i32 1
  store ptr %64, ptr %67, align 8, !tbaa !27
  %68 = load ptr, ptr %10, align 8, !tbaa !5
  %69 = getelementptr inbounds %struct._EFI_TCP4_PROTOCOL, ptr %68, i32 0, i32 6
  %70 = load ptr, ptr %69, align 8, !tbaa !28
  %71 = load ptr, ptr %10, align 8, !tbaa !5
  %72 = load ptr, ptr %6, align 8, !tbaa !5
  %73 = getelementptr inbounds %struct._TCP4_IO, ptr %72, i32 0, i32 6
  %74 = call i64 %70(ptr noundef %71, ptr noundef %73)
  store i64 %74, ptr %12, align 8, !tbaa !23
  %75 = load i64, ptr %12, align 8, !tbaa !23
  %76 = icmp slt i64 %75, 0
  br i1 %76, label %77, label %78

77:                                               ; preds = %42
  br label %171

78:                                               ; preds = %42
  br label %79

79:                                               ; preds = %98, %78
  %80 = load ptr, ptr %6, align 8, !tbaa !5
  %81 = getelementptr inbounds %struct._TCP4_IO, ptr %80, i32 0, i32 10
  %82 = load i8, ptr %81, align 2, !tbaa !30
  %83 = icmp ne i8 %82, 0
  br i1 %83, label %96, label %84

84:                                               ; preds = %79
  %85 = load ptr, ptr %9, align 8, !tbaa !5
  %86 = icmp eq ptr %85, null
  br i1 %86, label %94, label %87

87:                                               ; preds = %84
  %88 = load ptr, ptr @gBS, align 8, !tbaa !5
  %89 = getelementptr inbounds %struct.EFI_BOOT_SERVICES, ptr %88, i32 0, i32 13
  %90 = load ptr, ptr %89, align 8, !tbaa !31
  %91 = load ptr, ptr %9, align 8, !tbaa !5
  %92 = call i64 %90(ptr noundef %91)
  %93 = icmp slt i64 %92, 0
  br label %94

94:                                               ; preds = %87, %84
  %95 = phi i1 [ true, %84 ], [ %93, %87 ]
  br label %96

96:                                               ; preds = %94, %79
  %97 = phi i1 [ false, %79 ], [ %95, %94 ]
  br i1 %97, label %98, label %104

98:                                               ; preds = %96
  %99 = load ptr, ptr %10, align 8, !tbaa !5
  %100 = getelementptr inbounds %struct._EFI_TCP4_PROTOCOL, ptr %99, i32 0, i32 9
  %101 = load ptr, ptr %100, align 8, !tbaa !34
  %102 = load ptr, ptr %10, align 8, !tbaa !5
  %103 = call i64 %101(ptr noundef %102)
  br label %79, !llvm.loop !35

104:                                              ; preds = %96
  %105 = load ptr, ptr %6, align 8, !tbaa !5
  %106 = getelementptr inbounds %struct._TCP4_IO, ptr %105, i32 0, i32 10
  %107 = load i8, ptr %106, align 2, !tbaa !30
  %108 = icmp ne i8 %107, 0
  br i1 %108, label %118, label %109

109:                                              ; preds = %104
  %110 = load ptr, ptr %10, align 8, !tbaa !5
  %111 = getelementptr inbounds %struct._EFI_TCP4_PROTOCOL, ptr %110, i32 0, i32 8
  %112 = load ptr, ptr %111, align 8, !tbaa !37
  %113 = load ptr, ptr %10, align 8, !tbaa !5
  %114 = load ptr, ptr %6, align 8, !tbaa !5
  %115 = getelementptr inbounds %struct._TCP4_IO, ptr %114, i32 0, i32 6
  %116 = getelementptr inbounds %struct.EFI_TCP4_IO_TOKEN, ptr %115, i32 0, i32 0
  %117 = call i64 %112(ptr noundef %113, ptr noundef %116)
  store i64 -9223372036854775790, ptr %12, align 8, !tbaa !23
  br label %171

118:                                              ; preds = %104
  %119 = load ptr, ptr %6, align 8, !tbaa !5
  %120 = getelementptr inbounds %struct._TCP4_IO, ptr %119, i32 0, i32 10
  store i8 0, ptr %120, align 2, !tbaa !30
  br label %121

121:                                              ; preds = %118
  %122 = load ptr, ptr %6, align 8, !tbaa !5
  %123 = getelementptr inbounds %struct._TCP4_IO, ptr %122, i32 0, i32 6
  %124 = getelementptr inbounds %struct.EFI_TCP4_IO_TOKEN, ptr %123, i32 0, i32 0
  %125 = getelementptr inbounds %struct.EFI_TCP4_COMPLETION_TOKEN, ptr %124, i32 0, i32 1
  %126 = load i64, ptr %125, align 8, !tbaa !38
  %127 = icmp slt i64 %126, 0
  br i1 %127, label %128, label %134

128:                                              ; preds = %121
  %129 = load ptr, ptr %6, align 8, !tbaa !5
  %130 = getelementptr inbounds %struct._TCP4_IO, ptr %129, i32 0, i32 6
  %131 = getelementptr inbounds %struct.EFI_TCP4_IO_TOKEN, ptr %130, i32 0, i32 0
  %132 = getelementptr inbounds %struct.EFI_TCP4_COMPLETION_TOKEN, ptr %131, i32 0, i32 1
  %133 = load i64, ptr %132, align 8, !tbaa !38
  store i64 %133, ptr %12, align 8, !tbaa !23
  br label %171

134:                                              ; preds = %121
  %135 = getelementptr inbounds %struct.EFI_TCP4_RECEIVE_DATA, ptr %11, i32 0, i32 3
  %136 = getelementptr inbounds [1 x %struct.EFI_TCP4_FRAGMENT_DATA], ptr %135, i64 0, i64 0
  %137 = getelementptr inbounds %struct.EFI_TCP4_FRAGMENT_DATA, ptr %136, i32 0, i32 0
  %138 = load i32, ptr %137, align 8, !tbaa !24
  %139 = load ptr, ptr %13, align 8, !tbaa !5
  %140 = load i32, ptr %15, align 4, !tbaa !15
  %141 = zext i32 %140 to i64
  %142 = getelementptr inbounds %struct.NET_FRAGMENT, ptr %139, i64 %141
  %143 = getelementptr inbounds %struct.NET_FRAGMENT, ptr %142, i32 0, i32 0
  %144 = load i32, ptr %143, align 8, !tbaa !24
  %145 = sub i32 %144, %138
  store i32 %145, ptr %143, align 8, !tbaa !24
  %146 = load ptr, ptr %13, align 8, !tbaa !5
  %147 = load i32, ptr %15, align 4, !tbaa !15
  %148 = zext i32 %147 to i64
  %149 = getelementptr inbounds %struct.NET_FRAGMENT, ptr %146, i64 %148
  %150 = getelementptr inbounds %struct.NET_FRAGMENT, ptr %149, i32 0, i32 0
  %151 = load i32, ptr %150, align 8, !tbaa !24
  %152 = icmp eq i32 %151, 0
  br i1 %152, label %153, label %156

153:                                              ; preds = %134
  %154 = load i32, ptr %15, align 4, !tbaa !15
  %155 = add i32 %154, 1
  store i32 %155, ptr %15, align 4, !tbaa !15
  br label %169

156:                                              ; preds = %134
  %157 = getelementptr inbounds %struct.EFI_TCP4_RECEIVE_DATA, ptr %11, i32 0, i32 3
  %158 = getelementptr inbounds [1 x %struct.EFI_TCP4_FRAGMENT_DATA], ptr %157, i64 0, i64 0
  %159 = getelementptr inbounds %struct.EFI_TCP4_FRAGMENT_DATA, ptr %158, i32 0, i32 0
  %160 = load i32, ptr %159, align 8, !tbaa !24
  %161 = load ptr, ptr %13, align 8, !tbaa !5
  %162 = load i32, ptr %15, align 4, !tbaa !15
  %163 = zext i32 %162 to i64
  %164 = getelementptr inbounds %struct.NET_FRAGMENT, ptr %161, i64 %163
  %165 = getelementptr inbounds %struct.NET_FRAGMENT, ptr %164, i32 0, i32 1
  %166 = load ptr, ptr %165, align 8, !tbaa !27
  %167 = zext i32 %160 to i64
  %168 = getelementptr inbounds i8, ptr %166, i64 %167
  store ptr %168, ptr %165, align 8, !tbaa !27
  br label %169

169:                                              ; preds = %156, %153
  br label %38, !llvm.loop !39

170:                                              ; preds = %38
  br label %171

171:                                              ; preds = %170, %128, %109, %77
  %172 = load ptr, ptr %6, align 8, !tbaa !5
  %173 = getelementptr inbounds %struct._TCP4_IO, ptr %172, i32 0, i32 6
  %174 = getelementptr inbounds %struct.EFI_TCP4_IO_TOKEN, ptr %173, i32 0, i32 1
  store ptr null, ptr %174, align 8, !tbaa !9
  %175 = load ptr, ptr %13, align 8, !tbaa !5
  call void @FreePool(ptr noundef %175)
  %176 = load i64, ptr %12, align 8, !tbaa !23
  store i64 %176, ptr %5, align 8
  store i32 1, ptr %16, align 4
  br label %177

177:                                              ; preds = %171, %26
  call void @llvm.lifetime.end.p0(i64 4, ptr %15) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %14) #3
  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 32, ptr %11) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #3
  %178 = load i64, ptr %5, align 8
  ret i64 %178
}

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 = !{!7, !7, i64 0}
!10 = !{!11, !12, i64 128}
!11 = !{!"", !12, i64 0, !13, i64 8, !14, i64 16, !7, i64 32, !6, i64 40, !6, i64 48, !7, i64 56, !6, i64 120, !12, i64 128, !12, i64 132, !7, i64 136}
!12 = !{!"int", !7, i64 0}
!13 = !{!"long long", !7, i64 0}
!14 = !{!"_LIST_ENTRY", !6, i64 0, !6, i64 8}
!15 = !{!12, !12, i64 0}
!16 = !{!17, !12, i64 8}
!17 = !{!"", !7, i64 0, !12, i64 4, !12, i64 8, !7, i64 16}
!18 = !{!19, !6, i64 24}
!19 = !{!"_TCP4_IO", !6, i64 0, !6, i64 8, !6, i64 16, !6, i64 24, !20, i64 32, !22, i64 48, !22, i64 72, !22, i64 96, !7, i64 120, !7, i64 121, !7, i64 122, !7, i64 123}
!20 = !{!"", !21, i64 0}
!21 = !{!"", !6, i64 0, !13, i64 8}
!22 = !{!"", !21, i64 0, !7, i64 16}
!23 = !{!13, !13, i64 0}
!24 = !{!25, !12, i64 0}
!25 = !{!"", !12, i64 0, !6, i64 8}
!26 = !{!17, !12, i64 4}
!27 = !{!25, !6, i64 8}
!28 = !{!29, !6, i64 48}
!29 = !{!"_EFI_TCP4_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, !6, i64 64, !6, i64 72}
!30 = !{!19, !7, i64 122}
!31 = !{!32, !6, i64 120}
!32 = !{!"", !33, 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}
!33 = !{!"", !13, i64 0, !12, i64 8, !12, i64 12, !12, i64 16, !12, i64 20}
!34 = !{!29, !6, i64 72}
!35 = distinct !{!35, !36}
!36 = !{!"llvm.loop.mustprogress"}
!37 = !{!29, !6, i64 64}
!38 = !{!19, !13, i64 80}
!39 = distinct !{!39, !36}


; 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_RECEIVE_DATA = type { i8, i32, i32, [1 x %struct.EFI_TCP4_FRAGMENT_DATA] }
%struct.EFI_TCP4_FRAGMENT_DATA = type { i32, ptr }
%struct.NET_FRAGMENT = type { i32, ptr }

@gBS = external local_unnamed_addr global ptr, align 8

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

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

declare ptr @AllocatePool(i64 noundef) local_unnamed_addr #1

declare i64 @NetbufBuildExt(ptr noundef, ptr noundef, ptr noundef) local_unnamed_addr #1

declare void @FreePool(ptr noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
define dso_local i64 @Tcp4IoReceive(ptr noundef %0, ptr noundef %1, i8 noundef zeroext %2, ptr noundef %3) local_unnamed_addr #2 {
  %5 = alloca %struct.EFI_TCP4_RECEIVE_DATA, align 8
  %6 = alloca i32, align 4
  call void @llvm.lifetime.start.p0(i64 32, ptr nonnull %5) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %6) #3
  %7 = getelementptr inbounds i8, ptr %1, i64 128
  %8 = load i32, ptr %7, align 8, !tbaa !5
  store i32 %8, ptr %6, align 4, !tbaa !13
  %9 = zext i32 %8 to i64
  %10 = shl nuw nsw i64 %9, 4
  %11 = tail call ptr @AllocatePool(i64 noundef %10) #3
  %12 = icmp eq ptr %11, null
  br i1 %12, label %94, label %13

13:                                               ; preds = %4
  %14 = call i64 @NetbufBuildExt(ptr noundef nonnull %1, ptr noundef nonnull %11, ptr noundef nonnull %6) #3
  %15 = getelementptr inbounds i8, ptr %5, i64 8
  store i32 1, ptr %15, align 8, !tbaa !14
  %16 = getelementptr inbounds i8, ptr %0, i64 72
  %17 = getelementptr inbounds i8, ptr %0, i64 88
  store ptr %5, ptr %17, align 8, !tbaa !16
  %18 = getelementptr inbounds i8, ptr %0, i64 24
  %19 = load ptr, ptr %18, align 8, !tbaa !17
  %20 = load i32, ptr %6, align 4, !tbaa !13
  %.not59 = icmp eq i32 %20, 0
  br i1 %.not59, label %.loopexit, label %.lr.ph53

.lr.ph53:                                         ; preds = %13
  %21 = getelementptr inbounds i8, ptr %5, i64 4
  %22 = getelementptr inbounds i8, ptr %5, i64 16
  %23 = getelementptr inbounds i8, ptr %5, i64 24
  %24 = getelementptr inbounds i8, ptr %19, i64 48
  %25 = getelementptr inbounds i8, ptr %0, i64 122
  %26 = icmp eq ptr %3, null
  %27 = getelementptr inbounds i8, ptr %19, i64 72
  %28 = getelementptr inbounds i8, ptr %0, i64 80
  br i1 %26, label %.lr.ph53.split.us, label %.lr.ph53.split

.lr.ph53.split.us:                                ; preds = %.lr.ph53, %48
  %.052.us = phi i32 [ %.1.us, %48 ], [ 0, %.lr.ph53 ]
  %29 = zext i32 %.052.us to i64
  %30 = getelementptr inbounds %struct.NET_FRAGMENT, ptr %11, i64 %29
  %31 = load i32, ptr %30, align 8, !tbaa !22
  store i32 %31, ptr %21, align 4, !tbaa !24
  store i32 %31, ptr %22, align 8, !tbaa !22
  %32 = getelementptr inbounds i8, ptr %30, i64 8
  %33 = load ptr, ptr %32, align 8, !tbaa !25
  store ptr %33, ptr %23, align 8, !tbaa !25
  %34 = load ptr, ptr %24, align 8, !tbaa !26
  %35 = call i64 %34(ptr noundef %19, ptr noundef nonnull %16) #3
  %36 = icmp slt i64 %35, 0
  br i1 %36, label %.loopexit, label %.preheader.us

37:                                               ; preds = %.critedge.thread.loopexit.us
  %38 = load i32, ptr %22, align 8, !tbaa !22
  %39 = load i32, ptr %30, align 8, !tbaa !22
  %40 = sub i32 %39, %38
  store i32 %40, ptr %30, align 8, !tbaa !22
  %41 = icmp eq i32 %39, %38
  br i1 %41, label %46, label %42

42:                                               ; preds = %37
  %43 = load ptr, ptr %32, align 8, !tbaa !25
  %44 = zext i32 %38 to i64
  %45 = getelementptr inbounds i8, ptr %43, i64 %44
  store ptr %45, ptr %32, align 8, !tbaa !25
  br label %48

46:                                               ; preds = %37
  %47 = add i32 %.052.us, 1
  br label %48

48:                                               ; preds = %46, %42
  %.1.us = phi i32 [ %47, %46 ], [ %.052.us, %42 ]
  %49 = load i32, ptr %6, align 4, !tbaa !13
  %50 = icmp ult i32 %.1.us, %49
  br i1 %50, label %.lr.ph53.split.us, label %.loopexit, !llvm.loop !28

.preheader.us:                                    ; preds = %.lr.ph53.split.us
  %51 = load i8, ptr %25, align 2, !tbaa !30
  %.not51.us = icmp eq i8 %51, 0
  br i1 %.not51.us, label %.critedge2.us.us, label %.critedge.thread.loopexit.us

.critedge.thread.loopexit.us:                     ; preds = %.critedge2.us.us, %.preheader.us
  store i8 0, ptr %25, align 2, !tbaa !30
  %52 = load i64, ptr %28, align 8, !tbaa !31
  %53 = icmp slt i64 %52, 0
  br i1 %53, label %.loopexit, label %37

.critedge2.us.us:                                 ; preds = %.preheader.us, %.critedge2.us.us
  %54 = load ptr, ptr %27, align 8, !tbaa !32
  %55 = call i64 %54(ptr noundef nonnull %19) #3
  %56 = load i8, ptr %25, align 2, !tbaa !30
  %.not.us.us = icmp eq i8 %56, 0
  br i1 %.not.us.us, label %.critedge2.us.us, label %.critedge.thread.loopexit.us, !llvm.loop !33

.lr.ph53.split:                                   ; preds = %.lr.ph53, %91
  %.052 = phi i32 [ %.1, %91 ], [ 0, %.lr.ph53 ]
  %57 = zext i32 %.052 to i64
  %58 = getelementptr inbounds %struct.NET_FRAGMENT, ptr %11, i64 %57
  %59 = load i32, ptr %58, align 8, !tbaa !22
  store i32 %59, ptr %21, align 4, !tbaa !24
  store i32 %59, ptr %22, align 8, !tbaa !22
  %60 = getelementptr inbounds i8, ptr %58, i64 8
  %61 = load ptr, ptr %60, align 8, !tbaa !25
  store ptr %61, ptr %23, align 8, !tbaa !25
  %62 = load ptr, ptr %24, align 8, !tbaa !26
  %63 = call i64 %62(ptr noundef %19, ptr noundef nonnull %16) #3
  %64 = icmp slt i64 %63, 0
  br i1 %64, label %.loopexit, label %.preheader

.preheader:                                       ; preds = %.lr.ph53.split
  %65 = load i8, ptr %25, align 2, !tbaa !30
  %.not51 = icmp eq i8 %65, 0
  br i1 %.not51, label %.lr.ph, label %.critedge.thread

.lr.ph:                                           ; preds = %.preheader, %.critedge2
  %66 = load ptr, ptr @gBS, align 8, !tbaa !34
  %67 = getelementptr inbounds i8, ptr %66, i64 120
  %68 = load ptr, ptr %67, align 8, !tbaa !35
  %69 = call i64 %68(ptr noundef nonnull %3) #3
  %70 = icmp slt i64 %69, 0
  br i1 %70, label %.critedge2, label %.critedge

.critedge2:                                       ; preds = %.lr.ph
  %71 = load ptr, ptr %27, align 8, !tbaa !32
  %72 = call i64 %71(ptr noundef nonnull %19) #3
  %73 = load i8, ptr %25, align 2, !tbaa !30
  %.not = icmp eq i8 %73, 0
  br i1 %.not, label %.lr.ph, label %.critedge.thread, !llvm.loop !33

.critedge:                                        ; preds = %.lr.ph
  %.pr = load i8, ptr %25, align 2, !tbaa !30
  %.not48 = icmp eq i8 %.pr, 0
  br i1 %.not48, label %74, label %.critedge.thread

74:                                               ; preds = %.critedge
  %75 = getelementptr inbounds i8, ptr %19, i64 64
  %76 = load ptr, ptr %75, align 8, !tbaa !38
  %77 = call i64 %76(ptr noundef nonnull %19, ptr noundef nonnull %16) #3
  br label %.loopexit

.critedge.thread:                                 ; preds = %.critedge2, %.preheader, %.critedge
  store i8 0, ptr %25, align 2, !tbaa !30
  %78 = load i64, ptr %28, align 8, !tbaa !31
  %79 = icmp slt i64 %78, 0
  br i1 %79, label %.loopexit, label %80

80:                                               ; preds = %.critedge.thread
  %81 = load i32, ptr %22, align 8, !tbaa !22
  %82 = load i32, ptr %58, align 8, !tbaa !22
  %83 = sub i32 %82, %81
  store i32 %83, ptr %58, align 8, !tbaa !22
  %84 = icmp eq i32 %82, %81
  br i1 %84, label %85, label %87

85:                                               ; preds = %80
  %86 = add i32 %.052, 1
  br label %91

87:                                               ; preds = %80
  %88 = load ptr, ptr %60, align 8, !tbaa !25
  %89 = zext i32 %81 to i64
  %90 = getelementptr inbounds i8, ptr %88, i64 %89
  store ptr %90, ptr %60, align 8, !tbaa !25
  br label %91

91:                                               ; preds = %87, %85
  %.1 = phi i32 [ %86, %85 ], [ %.052, %87 ]
  %92 = load i32, ptr %6, align 4, !tbaa !13
  %93 = icmp ult i32 %.1, %92
  br i1 %93, label %.lr.ph53.split, label %.loopexit, !llvm.loop !28

.loopexit:                                        ; preds = %.lr.ph53.split, %91, %.critedge.thread, %.lr.ph53.split.us, %48, %.critedge.thread.loopexit.us, %13, %74
  %.143 = phi i64 [ -9223372036854775790, %74 ], [ 0, %13 ], [ %35, %.lr.ph53.split.us ], [ %35, %48 ], [ %52, %.critedge.thread.loopexit.us ], [ %63, %.lr.ph53.split ], [ %63, %91 ], [ %78, %.critedge.thread ]
  store ptr null, ptr %17, align 8, !tbaa !16
  call void @FreePool(ptr noundef nonnull %11) #3
  br label %94

94:                                               ; preds = %4, %.loopexit
  %.041 = phi i64 [ %.143, %.loopexit ], [ -9223372036854775799, %4 ]
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %6) #3
  call void @llvm.lifetime.end.p0(i64 32, ptr nonnull %5) #3
  ret i64 %.041
}

attributes #0 = { mustprogress 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, !7, i64 128}
!6 = !{!"", !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}
!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 = !{!7, !7, i64 0}
!14 = !{!15, !7, i64 8}
!15 = !{!"", !8, i64 0, !7, i64 4, !7, i64 8, !8, i64 16}
!16 = !{!8, !8, i64 0}
!17 = !{!18, !12, i64 24}
!18 = !{!"_TCP4_IO", !12, i64 0, !12, i64 8, !12, i64 16, !12, i64 24, !19, i64 32, !21, i64 48, !21, i64 72, !21, i64 96, !8, i64 120, !8, i64 121, !8, i64 122, !8, i64 123}
!19 = !{!"", !20, i64 0}
!20 = !{!"", !12, i64 0, !10, i64 8}
!21 = !{!"", !20, i64 0, !8, i64 16}
!22 = !{!23, !7, i64 0}
!23 = !{!"", !7, i64 0, !12, i64 8}
!24 = !{!15, !7, i64 4}
!25 = !{!23, !12, i64 8}
!26 = !{!27, !12, i64 48}
!27 = !{!"_EFI_TCP4_PROTOCOL", !12, i64 0, !12, i64 8, !12, i64 16, !12, i64 24, !12, i64 32, !12, i64 40, !12, i64 48, !12, i64 56, !12, i64 64, !12, i64 72}
!28 = distinct !{!28, !29}
!29 = !{!"llvm.loop.mustprogress"}
!30 = !{!18, !8, i64 122}
!31 = !{!18, !10, i64 80}
!32 = !{!27, !12, i64 72}
!33 = distinct !{!33, !29}
!34 = !{!12, !12, i64 0}
!35 = !{!36, !12, i64 120}
!36 = !{!"", !37, i64 0, !12, i64 24, !12, i64 32, !12, i64 40, !12, i64 48, !12, i64 56, !12, i64 64, !12, i64 72, !12, i64 80, !12, i64 88, !12, i64 96, !12, i64 104, !12, i64 112, !12, i64 120, !12, i64 128, !12, i64 136, !12, i64 144, !12, i64 152, !12, i64 160, !12, i64 168, !12, i64 176, !12, i64 184, !12, i64 192, !12, i64 200, !12, i64 208, !12, i64 216, !12, i64 224, !12, i64 232, !12, i64 240, !12, i64 248, !12, i64 256, !12, i64 264, !12, i64 272, !12, i64 280, !12, i64 288, !12, i64 296, !12, i64 304, !12, i64 312, !12, i64 320, !12, i64 328, !12, i64 336, !12, i64 344, !12, i64 352, !12, i64 360, !12, i64 368}
!37 = !{!"", !10, i64 0, !7, i64 8, !7, i64 12, !7, i64 16, !7, i64 20}
!38 = !{!27, !12, i64 64}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LCSSAPass,LICMPass,LoopInstSimplifyPass,LoopRotatePass,LoopSimplifyCFGPass,LoopSimplifyPass,LoopUnrollPass,SROAPass,SimplifyCFGPass,TailCallElimPass