; LLVM IR from thalium/icebox :: third_party/virtualbox/src/VBox/Devices/EFI/Firmware/NetworkPkg/Mtftp6Dxe (Mtftp6WrqSendBlock)

; 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._MTFTP6_INSTANCE = type { i32, ptr, %struct._LIST_ENTRY, %struct._EFI_MTFTP6_PROTOCOL, ptr, ptr, ptr, %struct.MTFTP6_EXT_OPTION_INFO, i16, i16, %struct._LIST_ENTRY, %struct.EFI_IPv6_ADDRESS, i16, i16, ptr, %struct.EFI_IPv6_ADDRESS, i16, ptr, ptr, i32, i32, i32, i32, i64, i8, i8, i8 }
%struct._EFI_MTFTP6_PROTOCOL = type { ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr }
%struct.MTFTP6_EXT_OPTION_INFO = type { i16, i8, i32, %struct.EFI_IPv6_ADDRESS, i16, i8, i32 }
%struct._LIST_ENTRY = type { ptr, ptr }
%struct.EFI_IPv6_ADDRESS = type { [16 x i8] }
%struct.EFI_MTFTP6_DATA_HEADER = type <{ i16, i16, [1 x i8] }>
%struct._EFI_MTFTP6_TOKEN = type { i64, ptr, ptr, ptr, ptr, i32, ptr, i64, 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 }

@.str = external hidden unnamed_addr constant [134 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [23 x i8], align 1
@gBS = external global ptr, align 8
@.str.2 = external hidden unnamed_addr constant [26 x i8], align 1

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

22:                                               ; preds = %2
  store i64 -9223372036854775799, ptr %3, align 8
  store i32 1, ptr %13, align 4
  br label %181

23:                                               ; preds = %2
  %24 = load ptr, ptr %8, align 8, !tbaa !5
  %25 = call ptr @NetbufAllocSpace(ptr noundef %24, i32 noundef 4, i8 noundef zeroext 0)
  store ptr %25, ptr %6, align 8, !tbaa !5
  br label %26

26:                                               ; preds = %23
  %27 = call zeroext i8 @DebugAssertEnabled()
  %28 = icmp ne i8 %27, 0
  br i1 %28, label %29, label %34

29:                                               ; preds = %26
  %30 = load ptr, ptr %6, align 8, !tbaa !5
  %31 = icmp ne ptr %30, null
  br i1 %31, label %33, label %32

32:                                               ; preds = %29
  call void @DebugAssert(ptr noundef @.str, i64 noundef 59, ptr noundef @.str.1)
  br label %33

33:                                               ; preds = %32, %29
  br label %34

34:                                               ; preds = %33, %26
  br label %35

35:                                               ; preds = %34
  br label %36

36:                                               ; preds = %35
  %37 = call zeroext i16 @SwapBytes16(i16 noundef zeroext 3)
  %38 = load ptr, ptr %6, align 8, !tbaa !5
  %39 = getelementptr inbounds %struct.EFI_MTFTP6_DATA_HEADER, ptr %38, i32 0, i32 0
  store i16 %37, ptr %39, align 1, !tbaa !19
  %40 = load i16, ptr %5, align 2, !tbaa !9
  %41 = call zeroext i16 @SwapBytes16(i16 noundef zeroext %40)
  %42 = load ptr, ptr %6, align 8, !tbaa !5
  %43 = getelementptr inbounds %struct.EFI_MTFTP6_DATA_HEADER, ptr %42, i32 0, i32 1
  store i16 %41, ptr %43, align 1, !tbaa !19
  %44 = load ptr, ptr %4, align 8, !tbaa !5
  %45 = getelementptr inbounds %struct._MTFTP6_INSTANCE, ptr %44, i32 0, i32 6
  %46 = load ptr, ptr %45, align 8, !tbaa !20
  store ptr %46, ptr %7, align 8, !tbaa !5
  %47 = load ptr, ptr %4, align 8, !tbaa !5
  %48 = getelementptr inbounds %struct._MTFTP6_INSTANCE, ptr %47, i32 0, i32 8
  %49 = load i16, ptr %48, align 8, !tbaa !11
  store i16 %49, ptr %10, align 2, !tbaa !9
  %50 = load ptr, ptr %7, align 8, !tbaa !5
  %51 = getelementptr inbounds %struct._EFI_MTFTP6_TOKEN, ptr %50, i32 0, i32 8
  %52 = load ptr, ptr %51, align 8, !tbaa !21
  %53 = icmp ne ptr %52, null
  br i1 %53, label %54, label %108

54:                                               ; preds = %36
  %55 = load i16, ptr %5, align 2, !tbaa !9
  %56 = zext i16 %55 to i32
  %57 = sub nsw i32 %56, 1
  %58 = sext i32 %57 to i64
  %59 = load ptr, ptr %4, align 8, !tbaa !5
  %60 = getelementptr inbounds %struct._MTFTP6_INSTANCE, ptr %59, i32 0, i32 8
  %61 = load i16, ptr %60, align 8, !tbaa !11
  %62 = zext i16 %61 to i32
  %63 = call i64 @MultU64x32(i64 noundef %58, i32 noundef %62)
  store i64 %63, ptr %12, align 8, !tbaa !23
  %64 = load ptr, ptr %7, align 8, !tbaa !5
  %65 = getelementptr inbounds %struct._EFI_MTFTP6_TOKEN, ptr %64, i32 0, i32 7
  %66 = load i64, ptr %65, align 8, !tbaa !24
  %67 = load i64, ptr %12, align 8, !tbaa !23
  %68 = load ptr, ptr %4, align 8, !tbaa !5
  %69 = getelementptr inbounds %struct._MTFTP6_INSTANCE, ptr %68, i32 0, i32 8
  %70 = load i16, ptr %69, align 8, !tbaa !11
  %71 = zext i16 %70 to i64
  %72 = add i64 %67, %71
  %73 = icmp ult i64 %66, %72
  br i1 %73, label %74, label %87

74:                                               ; preds = %54
  %75 = load ptr, ptr %7, align 8, !tbaa !5
  %76 = getelementptr inbounds %struct._EFI_MTFTP6_TOKEN, ptr %75, i32 0, i32 7
  %77 = load i64, ptr %76, align 8, !tbaa !24
  %78 = load i64, ptr %12, align 8, !tbaa !23
  %79 = sub i64 %77, %78
  %80 = trunc i64 %79 to i16
  store i16 %80, ptr %10, align 2, !tbaa !9
  %81 = load i16, ptr %5, align 2, !tbaa !9
  %82 = load ptr, ptr %4, align 8, !tbaa !5
  %83 = getelementptr inbounds %struct._MTFTP6_INSTANCE, ptr %82, i32 0, i32 9
  store i16 %81, ptr %83, align 2, !tbaa !25
  %84 = load ptr, ptr %4, align 8, !tbaa !5
  %85 = getelementptr inbounds %struct._MTFTP6_INSTANCE, ptr %84, i32 0, i32 10
  %86 = load i16, ptr %5, align 2, !tbaa !9
  call void @Mtftp6SetLastBlockNum(ptr noundef %85, i16 noundef zeroext %86)
  br label %87

87:                                               ; preds = %74, %54
  %88 = load i16, ptr %10, align 2, !tbaa !9
  %89 = zext i16 %88 to i32
  %90 = icmp sgt i32 %89, 0
  br i1 %90, label %91, label %107

91:                                               ; preds = %87
  %92 = load ptr, ptr %8, align 8, !tbaa !5
  %93 = load i16, ptr %10, align 2, !tbaa !9
  %94 = zext i16 %93 to i32
  %95 = call ptr @NetbufAllocSpace(ptr noundef %92, i32 noundef %94, i8 noundef zeroext 0)
  %96 = load ptr, ptr %6, align 8, !tbaa !5
  %97 = getelementptr inbounds %struct.EFI_MTFTP6_DATA_HEADER, ptr %96, i32 0, i32 2
  %98 = getelementptr inbounds [1 x i8], ptr %97, i64 0, i64 0
  %99 = load ptr, ptr %7, align 8, !tbaa !5
  %100 = getelementptr inbounds %struct._EFI_MTFTP6_TOKEN, ptr %99, i32 0, i32 8
  %101 = load ptr, ptr %100, align 8, !tbaa !21
  %102 = load i64, ptr %12, align 8, !tbaa !23
  %103 = getelementptr inbounds i8, ptr %101, i64 %102
  %104 = load i16, ptr %10, align 2, !tbaa !9
  %105 = zext i16 %104 to i64
  %106 = call ptr @CopyMem(ptr noundef %98, ptr noundef %103, i64 noundef %105)
  br label %107

107:                                              ; preds = %91, %87
  br label %175

108:                                              ; preds = %36
  store ptr null, ptr %11, align 8, !tbaa !5
  %109 = load ptr, ptr %7, align 8, !tbaa !5
  %110 = getelementptr inbounds %struct._EFI_MTFTP6_TOKEN, ptr %109, i32 0, i32 12
  %111 = load ptr, ptr %110, align 8, !tbaa !26
  %112 = load ptr, ptr %4, align 8, !tbaa !5
  %113 = getelementptr inbounds %struct._MTFTP6_INSTANCE, ptr %112, i32 0, i32 3
  %114 = load ptr, ptr %7, align 8, !tbaa !5
  %115 = call i64 %111(ptr noundef %113, ptr noundef %114, ptr noundef %10, ptr noundef %11)
  store i64 %115, ptr %9, align 8, !tbaa !23
  %116 = load i64, ptr %9, align 8, !tbaa !23
  %117 = icmp slt i64 %116, 0
  br i1 %117, label %126, label %118

118:                                              ; preds = %108
  %119 = load i16, ptr %10, align 2, !tbaa !9
  %120 = zext i16 %119 to i32
  %121 = load ptr, ptr %4, align 8, !tbaa !5
  %122 = getelementptr inbounds %struct._MTFTP6_INSTANCE, ptr %121, i32 0, i32 8
  %123 = load i16, ptr %122, align 8, !tbaa !11
  %124 = zext i16 %123 to i32
  %125 = icmp sgt i32 %120, %124
  br i1 %125, label %126, label %138

126:                                              ; preds = %118, %108
  %127 = load ptr, ptr %11, align 8, !tbaa !5
  %128 = icmp ne ptr %127, null
  br i1 %128, label %129, label %135

129:                                              ; preds = %126
  %130 = load ptr, ptr @gBS, align 8, !tbaa !5
  %131 = getelementptr inbounds %struct.EFI_BOOT_SERVICES, ptr %130, i32 0, i32 7
  %132 = load ptr, ptr %131, align 8, !tbaa !27
  %133 = load ptr, ptr %11, align 8, !tbaa !5
  %134 = call i64 %132(ptr noundef %133)
  br label %135

135:                                              ; preds = %129, %126
  %136 = load ptr, ptr %4, align 8, !tbaa !5
  %137 = call i64 @Mtftp6SendError(ptr noundef %136, i16 noundef zeroext 8, ptr noundef @.str.2)
  store i64 -9223372036854775787, ptr %3, align 8
  store i32 1, ptr %13, align 4
  br label %181

138:                                              ; preds = %118
  %139 = load i16, ptr %10, align 2, !tbaa !9
  %140 = zext i16 %139 to i32
  %141 = load ptr, ptr %4, align 8, !tbaa !5
  %142 = getelementptr inbounds %struct._MTFTP6_INSTANCE, ptr %141, i32 0, i32 8
  %143 = load i16, ptr %142, align 8, !tbaa !11
  %144 = zext i16 %143 to i32
  %145 = icmp slt i32 %140, %144
  br i1 %145, label %146, label %153

146:                                              ; preds = %138
  %147 = load i16, ptr %5, align 2, !tbaa !9
  %148 = load ptr, ptr %4, align 8, !tbaa !5
  %149 = getelementptr inbounds %struct._MTFTP6_INSTANCE, ptr %148, i32 0, i32 9
  store i16 %147, ptr %149, align 2, !tbaa !25
  %150 = load ptr, ptr %4, align 8, !tbaa !5
  %151 = getelementptr inbounds %struct._MTFTP6_INSTANCE, ptr %150, i32 0, i32 10
  %152 = load i16, ptr %5, align 2, !tbaa !9
  call void @Mtftp6SetLastBlockNum(ptr noundef %151, i16 noundef zeroext %152)
  br label %153

153:                                              ; preds = %146, %138
  %154 = load i16, ptr %10, align 2, !tbaa !9
  %155 = zext i16 %154 to i32
  %156 = icmp sgt i32 %155, 0
  br i1 %156, label %157, label %174

157:                                              ; preds = %153
  %158 = load ptr, ptr %8, align 8, !tbaa !5
  %159 = load i16, ptr %10, align 2, !tbaa !9
  %160 = zext i16 %159 to i32
  %161 = call ptr @NetbufAllocSpace(ptr noundef %158, i32 noundef %160, i8 noundef zeroext 0)
  %162 = load ptr, ptr %6, align 8, !tbaa !5
  %163 = getelementptr inbounds %struct.EFI_MTFTP6_DATA_HEADER, ptr %162, i32 0, i32 2
  %164 = getelementptr inbounds [1 x i8], ptr %163, i64 0, i64 0
  %165 = load ptr, ptr %11, align 8, !tbaa !5
  %166 = load i16, ptr %10, align 2, !tbaa !9
  %167 = zext i16 %166 to i64
  %168 = call ptr @CopyMem(ptr noundef %164, ptr noundef %165, i64 noundef %167)
  %169 = load ptr, ptr @gBS, align 8, !tbaa !5
  %170 = getelementptr inbounds %struct.EFI_BOOT_SERVICES, ptr %169, i32 0, i32 7
  %171 = load ptr, ptr %170, align 8, !tbaa !27
  %172 = load ptr, ptr %11, align 8, !tbaa !5
  %173 = call i64 %171(ptr noundef %172)
  br label %174

174:                                              ; preds = %157, %153
  br label %175

175:                                              ; preds = %174, %107
  %176 = load ptr, ptr %4, align 8, !tbaa !5
  %177 = getelementptr inbounds %struct._MTFTP6_INSTANCE, ptr %176, i32 0, i32 19
  store i32 0, ptr %177, align 8, !tbaa !30
  %178 = load ptr, ptr %4, align 8, !tbaa !5
  %179 = load ptr, ptr %8, align 8, !tbaa !5
  %180 = call i64 @Mtftp6TransmitPacket(ptr noundef %178, ptr noundef %179)
  store i64 %180, ptr %3, align 8
  store i32 1, ptr %13, align 4
  br label %181

181:                                              ; preds = %175, %135, %22
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #3
  call void @llvm.lifetime.end.p0(i64 2, ptr %10) #3
  call void @llvm.lifetime.end.p0(i64 8, 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
  %182 = load i64, ptr %3, align 8
  ret i64 %182
}

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

declare ptr @NetbufAlloc(i32 noundef) #2

declare ptr @NetbufAllocSpace(ptr noundef, i32 noundef, i8 noundef zeroext) #2

declare zeroext i8 @DebugAssertEnabled() #2

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

declare zeroext i16 @SwapBytes16(i16 noundef zeroext) #2

declare i64 @MultU64x32(i64 noundef, i32 noundef) #2

declare void @Mtftp6SetLastBlockNum(ptr noundef, i16 noundef zeroext) #2

declare ptr @CopyMem(ptr noundef, ptr noundef, i64 noundef) #2

declare i64 @Mtftp6SendError(ptr noundef, i16 noundef zeroext, ptr noundef) #2

declare i64 @Mtftp6TransmitPacket(ptr noundef, ptr noundef) #2

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

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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = !{!"short", !7, i64 0}
!11 = !{!12, !10, i64 152}
!12 = !{!"_MTFTP6_INSTANCE", !13, i64 0, !6, i64 8, !14, i64 16, !15, i64 32, !6, i64 96, !6, i64 104, !6, i64 112, !16, i64 120, !10, i64 152, !10, i64 154, !14, i64 160, !17, i64 176, !10, i64 192, !10, i64 194, !6, i64 200, !17, i64 208, !10, i64 224, !6, i64 232, !6, i64 240, !13, i64 248, !13, i64 252, !13, i64 256, !13, i64 260, !18, i64 264, !7, i64 272, !7, i64 273, !7, i64 274}
!13 = !{!"int", !7, i64 0}
!14 = !{!"_LIST_ENTRY", !6, i64 0, !6, i64 8}
!15 = !{!"_EFI_MTFTP6_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}
!16 = !{!"", !10, i64 0, !7, i64 2, !13, i64 4, !17, i64 8, !10, i64 24, !7, i64 26, !13, i64 28}
!17 = !{!"", !7, i64 0}
!18 = !{!"long long", !7, i64 0}
!19 = !{!7, !7, i64 0}
!20 = !{!12, !6, i64 112}
!21 = !{!22, !6, i64 64}
!22 = !{!"_EFI_MTFTP6_TOKEN", !18, i64 0, !6, i64 8, !6, i64 16, !6, i64 24, !6, i64 32, !13, i64 40, !6, i64 48, !18, i64 56, !6, i64 64, !6, i64 72, !6, i64 80, !6, i64 88, !6, i64 96}
!23 = !{!18, !18, i64 0}
!24 = !{!22, !18, i64 56}
!25 = !{!12, !10, i64 154}
!26 = !{!22, !6, i64 96}
!27 = !{!28, !6, i64 72}
!28 = !{!"", !29, 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}
!29 = !{!"", !18, i64 0, !13, i64 8, !13, i64 12, !13, i64 16, !13, i64 20}
!30 = !{!12, !13, i64 248}


; 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 [134 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [23 x i8], align 1
@gBS = external local_unnamed_addr global ptr, align 8
@.str.2 = external hidden unnamed_addr constant [26 x i8], align 1

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

11:                                               ; preds = %2
  %12 = tail call ptr @NetbufAllocSpace(ptr noundef nonnull %9, i32 noundef 4, i8 noundef zeroext 0) #3
  %13 = tail call zeroext i8 @DebugAssertEnabled() #3
  %14 = icmp eq i8 %13, 0
  %15 = icmp ne ptr %12, null
  %or.cond = select i1 %14, i1 true, i1 %15
  br i1 %or.cond, label %17, label %16

16:                                               ; preds = %11
  tail call void @DebugAssert(ptr noundef nonnull @.str, i64 noundef 59, ptr noundef nonnull @.str.1) #3
  br label %17

17:                                               ; preds = %16, %11
  %18 = tail call zeroext i16 @SwapBytes16(i16 noundef zeroext 3) #3
  store i16 %18, ptr %12, align 1, !tbaa !17
  %19 = tail call zeroext i16 @SwapBytes16(i16 noundef zeroext %1) #3
  %20 = getelementptr inbounds i8, ptr %12, i64 2
  store i16 %19, ptr %20, align 1, !tbaa !17
  %21 = getelementptr inbounds i8, ptr %0, i64 112
  %22 = load ptr, ptr %21, align 8, !tbaa !18
  %23 = load i16, ptr %5, align 8, !tbaa !5
  store i16 %23, ptr %3, align 2, !tbaa !19
  %24 = getelementptr inbounds i8, ptr %22, i64 64
  %25 = load ptr, ptr %24, align 8, !tbaa !20
  %.not = icmp eq ptr %25, null
  br i1 %.not, label %52, label %26

26:                                               ; preds = %17
  %27 = zext i16 %1 to i64
  %28 = add nsw i64 %27, -1
  %29 = zext i16 %23 to i32
  %30 = tail call i64 @MultU64x32(i64 noundef %28, i32 noundef %29) #3
  %31 = getelementptr inbounds i8, ptr %22, i64 56
  %32 = load i64, ptr %31, align 8, !tbaa !22
  %33 = load i16, ptr %5, align 8, !tbaa !5
  %34 = zext i16 %33 to i64
  %35 = add i64 %30, %34
  %36 = icmp ult i64 %32, %35
  br i1 %36, label %37, label %42

37:                                               ; preds = %26
  %38 = sub i64 %32, %30
  %39 = trunc i64 %38 to i16
  store i16 %39, ptr %3, align 2, !tbaa !19
  %40 = getelementptr inbounds i8, ptr %0, i64 154
  store i16 %1, ptr %40, align 2, !tbaa !23
  %41 = getelementptr inbounds i8, ptr %0, i64 160
  tail call void @Mtftp6SetLastBlockNum(ptr noundef nonnull %41, i16 noundef zeroext %1) #3
  br label %42

42:                                               ; preds = %37, %26
  %43 = phi i16 [ %39, %37 ], [ %23, %26 ]
  %.not51 = icmp eq i16 %43, 0
  br i1 %.not51, label %91, label %44

44:                                               ; preds = %42
  %45 = zext i16 %43 to i32
  %46 = tail call ptr @NetbufAllocSpace(ptr noundef nonnull %9, i32 noundef %45, i8 noundef zeroext 0) #3
  %47 = getelementptr inbounds i8, ptr %12, i64 4
  %48 = load ptr, ptr %24, align 8, !tbaa !20
  %49 = getelementptr inbounds i8, ptr %48, i64 %30
  %50 = zext i16 %43 to i64
  %51 = tail call ptr @CopyMem(ptr noundef nonnull %47, ptr noundef %49, i64 noundef %50) #3
  br label %91

52:                                               ; preds = %17
  store ptr null, ptr %4, align 8, !tbaa !24
  %53 = getelementptr inbounds i8, ptr %22, i64 96
  %54 = load ptr, ptr %53, align 8, !tbaa !25
  %55 = getelementptr inbounds i8, ptr %0, i64 32
  %56 = call i64 %54(ptr noundef nonnull %55, ptr noundef nonnull %22, ptr noundef nonnull %3, ptr noundef nonnull %4) #3
  %57 = icmp slt i64 %56, 0
  br i1 %57, label %62, label %58

58:                                               ; preds = %52
  %59 = load i16, ptr %3, align 2, !tbaa !19
  %60 = load i16, ptr %5, align 8, !tbaa !5
  %61 = icmp ugt i16 %59, %60
  br i1 %61, label %62, label %71

62:                                               ; preds = %58, %52
  %63 = load ptr, ptr %4, align 8, !tbaa !24
  %.not50 = icmp eq ptr %63, null
  br i1 %.not50, label %69, label %64

64:                                               ; preds = %62
  %65 = load ptr, ptr @gBS, align 8, !tbaa !24
  %66 = getelementptr inbounds i8, ptr %65, i64 72
  %67 = load ptr, ptr %66, align 8, !tbaa !26
  %68 = call i64 %67(ptr noundef nonnull %63) #3
  br label %69

69:                                               ; preds = %64, %62
  %70 = call i64 @Mtftp6SendError(ptr noundef nonnull %0, i16 noundef zeroext 8, ptr noundef nonnull @.str.2) #3
  br label %94

71:                                               ; preds = %58
  %72 = icmp ult i16 %59, %60
  br i1 %72, label %73, label %76

73:                                               ; preds = %71
  %74 = getelementptr inbounds i8, ptr %0, i64 154
  store i16 %1, ptr %74, align 2, !tbaa !23
  %75 = getelementptr inbounds i8, ptr %0, i64 160
  call void @Mtftp6SetLastBlockNum(ptr noundef nonnull %75, i16 noundef zeroext %1) #3
  %.pr = load i16, ptr %3, align 2, !tbaa !19
  br label %76

76:                                               ; preds = %73, %71
  %77 = phi i16 [ %.pr, %73 ], [ %59, %71 ]
  %.not49 = icmp eq i16 %77, 0
  br i1 %.not49, label %91, label %78

78:                                               ; preds = %76
  %79 = zext i16 %77 to i32
  %80 = call ptr @NetbufAllocSpace(ptr noundef nonnull %9, i32 noundef %79, i8 noundef zeroext 0) #3
  %81 = getelementptr inbounds i8, ptr %12, i64 4
  %82 = load ptr, ptr %4, align 8, !tbaa !24
  %83 = load i16, ptr %3, align 2, !tbaa !19
  %84 = zext i16 %83 to i64
  %85 = call ptr @CopyMem(ptr noundef nonnull %81, ptr noundef %82, i64 noundef %84) #3
  %86 = load ptr, ptr @gBS, align 8, !tbaa !24
  %87 = getelementptr inbounds i8, ptr %86, i64 72
  %88 = load ptr, ptr %87, align 8, !tbaa !26
  %89 = load ptr, ptr %4, align 8, !tbaa !24
  %90 = call i64 %88(ptr noundef %89) #3
  br label %91

91:                                               ; preds = %76, %78, %42, %44
  %92 = getelementptr inbounds i8, ptr %0, i64 248
  store i32 0, ptr %92, align 8, !tbaa !29
  %93 = call i64 @Mtftp6TransmitPacket(ptr noundef nonnull %0, ptr noundef nonnull %9) #3
  br label %94

94:                                               ; preds = %2, %91, %69
  %.0 = phi i64 [ %93, %91 ], [ -9223372036854775787, %69 ], [ -9223372036854775799, %2 ]
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %4) #3
  call void @llvm.lifetime.end.p0(i64 2, ptr nonnull %3) #3
  ret i64 %.0
}

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

declare ptr @NetbufAlloc(i32 noundef) local_unnamed_addr #2

declare ptr @NetbufAllocSpace(ptr noundef, i32 noundef, i8 noundef zeroext) local_unnamed_addr #2

declare zeroext i8 @DebugAssertEnabled() local_unnamed_addr #2

declare void @DebugAssert(ptr noundef, i64 noundef, ptr noundef) local_unnamed_addr #2

declare zeroext i16 @SwapBytes16(i16 noundef zeroext) local_unnamed_addr #2

declare i64 @MultU64x32(i64 noundef, i32 noundef) local_unnamed_addr #2

declare void @Mtftp6SetLastBlockNum(ptr noundef, i16 noundef zeroext) local_unnamed_addr #2

declare ptr @CopyMem(ptr noundef, ptr noundef, i64 noundef) local_unnamed_addr #2

declare i64 @Mtftp6SendError(ptr noundef, i16 noundef zeroext, ptr noundef) local_unnamed_addr #2

declare i64 @Mtftp6TransmitPacket(ptr noundef, ptr noundef) local_unnamed_addr #2

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

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 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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, !14, i64 152}
!6 = !{!"_MTFTP6_INSTANCE", !7, i64 0, !10, i64 8, !11, i64 16, !12, i64 32, !10, i64 96, !10, i64 104, !10, i64 112, !13, i64 120, !14, i64 152, !14, i64 154, !11, i64 160, !15, i64 176, !14, i64 192, !14, i64 194, !10, i64 200, !15, i64 208, !14, i64 224, !10, i64 232, !10, i64 240, !7, i64 248, !7, i64 252, !7, i64 256, !7, i64 260, !16, i64 264, !8, i64 272, !8, i64 273, !8, i64 274}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"any pointer", !8, i64 0}
!11 = !{!"_LIST_ENTRY", !10, i64 0, !10, i64 8}
!12 = !{!"_EFI_MTFTP6_PROTOCOL", !10, i64 0, !10, i64 8, !10, i64 16, !10, i64 24, !10, i64 32, !10, i64 40, !10, i64 48, !10, i64 56}
!13 = !{!"", !14, i64 0, !8, i64 2, !7, i64 4, !15, i64 8, !14, i64 24, !8, i64 26, !7, i64 28}
!14 = !{!"short", !8, i64 0}
!15 = !{!"", !8, i64 0}
!16 = !{!"long long", !8, i64 0}
!17 = !{!8, !8, i64 0}
!18 = !{!6, !10, i64 112}
!19 = !{!14, !14, i64 0}
!20 = !{!21, !10, i64 64}
!21 = !{!"_EFI_MTFTP6_TOKEN", !16, i64 0, !10, i64 8, !10, i64 16, !10, i64 24, !10, i64 32, !7, i64 40, !10, i64 48, !16, i64 56, !10, i64 64, !10, i64 72, !10, i64 80, !10, i64 88, !10, i64 96}
!22 = !{!21, !16, i64 56}
!23 = !{!6, !14, i64 154}
!24 = !{!10, !10, i64 0}
!25 = !{!21, !10, i64 96}
!26 = !{!27, !10, i64 72}
!27 = !{!"", !28, i64 0, !10, i64 24, !10, i64 32, !10, i64 40, !10, i64 48, !10, i64 56, !10, i64 64, !10, i64 72, !10, i64 80, !10, i64 88, !10, i64 96, !10, i64 104, !10, i64 112, !10, i64 120, !10, i64 128, !10, i64 136, !10, i64 144, !10, i64 152, !10, i64 160, !10, i64 168, !10, i64 176, !10, i64 184, !10, i64 192, !10, i64 200, !10, i64 208, !10, i64 216, !10, i64 224, !10, i64 232, !10, i64 240, !10, i64 248, !10, i64 256, !10, i64 264, !10, i64 272, !10, i64 280, !10, i64 288, !10, i64 296, !10, i64 304, !10, i64 312, !10, i64 320, !10, i64 328, !10, i64 336, !10, i64 344, !10, i64 352, !10, i64 360, !10, i64 368}
!28 = !{!"", !16, i64 0, !7, i64 8, !7, i64 12, !7, i64 16, !7, i64 20}
!29 = !{!6, !7, i64 248}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass