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

; 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_MTFTP4_DATA_HEADER = type <{ i16, i16, [1 x i8] }>
%struct._MTFTP4_PROTOCOL = type { i32, %struct._LIST_ENTRY, %struct._EFI_MTFTP4_PROTOCOL, i64, i8, ptr, ptr, %struct.EFI_MTFTP4_CONFIG_DATA, ptr, %struct.MTFTP4_OPTION, i16, i16, i16, %struct._LIST_ENTRY, i32, i16, i16, i32, ptr, ptr, i32, i32, i32, i32, i32, i16, i8, ptr }
%struct._EFI_MTFTP4_PROTOCOL = type { ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr }
%struct.EFI_MTFTP4_CONFIG_DATA = type { i8, %struct.EFI_IPv4_ADDRESS, %struct.EFI_IPv4_ADDRESS, i16, %struct.EFI_IPv4_ADDRESS, %struct.EFI_IPv4_ADDRESS, i16, i16, i16 }
%struct.EFI_IPv4_ADDRESS = type { [4 x i8] }
%struct.MTFTP4_OPTION = type { i16, i8, i32, i32, i16, i8, i32 }
%struct._LIST_ENTRY = type { ptr, ptr }

@.str = external hidden unnamed_addr constant [154 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [14 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

; 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 i64 @Mtftp4RrqSendAck(ptr noundef, i16 noundef zeroext) #1

declare zeroext i8 @DebugAssertEnabled() #2

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

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

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

; Function Attrs: nounwind uwtable
define dso_local i64 @Mtftp4RrqHandleData(ptr noundef %0, ptr noundef %1, i32 noundef %2, i8 noundef zeroext %3, ptr noundef %4) #1 {
  %6 = alloca i64, align 8
  %7 = alloca ptr, align 8
  %8 = alloca ptr, align 8
  %9 = alloca i32, align 4
  %10 = alloca i8, align 1
  %11 = alloca ptr, align 8
  %12 = alloca i64, align 8
  %13 = alloca i16, align 2
  %14 = alloca i64, align 8
  %15 = alloca i32, align 4
  store ptr %0, ptr %7, align 8, !tbaa !5
  store ptr %1, ptr %8, align 8, !tbaa !5
  store i32 %2, ptr %9, align 4, !tbaa !9
  store i8 %3, ptr %10, align 1, !tbaa !11
  store ptr %4, ptr %11, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %12) #3
  call void @llvm.lifetime.start.p0(i64 2, ptr %13) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %14) #3
  %16 = load ptr, ptr %11, align 8, !tbaa !5
  store i8 0, ptr %16, align 1, !tbaa !11
  %17 = load ptr, ptr %8, align 8, !tbaa !5
  %18 = getelementptr inbounds %struct.EFI_MTFTP4_DATA_HEADER, ptr %17, i32 0, i32 1
  %19 = load i16, ptr %18, align 1, !tbaa !11
  %20 = call zeroext i16 @SwapBytes16(i16 noundef zeroext %19)
  store i16 %20, ptr %13, align 2, !tbaa !12
  %21 = load ptr, ptr %7, align 8, !tbaa !5
  %22 = getelementptr inbounds %struct._MTFTP4_PROTOCOL, ptr %21, i32 0, i32 13
  %23 = call i64 @Mtftp4GetNextBlockNum(ptr noundef %22)
  store i64 %23, ptr %14, align 8, !tbaa !14
  br label %24

24:                                               ; preds = %5
  %25 = call zeroext i8 @DebugAssertEnabled()
  %26 = icmp ne i8 %25, 0
  br i1 %26, label %27, label %32

27:                                               ; preds = %24
  %28 = load i64, ptr %14, align 8, !tbaa !14
  %29 = icmp sge i64 %28, 0
  br i1 %29, label %31, label %30

30:                                               ; preds = %27
  call void @DebugAssert(ptr noundef @.str, i64 noundef 262, ptr noundef @.str.4)
  br label %31

31:                                               ; preds = %30, %27
  br label %32

32:                                               ; preds = %31, %24
  br label %33

33:                                               ; preds = %32
  br label %34

34:                                               ; preds = %33
  %35 = load ptr, ptr %7, align 8, !tbaa !5
  %36 = getelementptr inbounds %struct._MTFTP4_PROTOCOL, ptr %35, i32 0, i32 26
  %37 = load i8, ptr %36, align 2, !tbaa !16
  %38 = zext i8 %37 to i32
  %39 = icmp ne i32 %38, 0
  br i1 %39, label %40, label %48

40:                                               ; preds = %34
  %41 = load i64, ptr %14, align 8, !tbaa !14
  %42 = load i16, ptr %13, align 2, !tbaa !12
  %43 = zext i16 %42 to i64
  %44 = icmp ne i64 %41, %43
  br i1 %44, label %45, label %48

45:                                               ; preds = %40
  %46 = load ptr, ptr %7, align 8, !tbaa !5
  %47 = call i64 @Mtftp4Retransmit(ptr noundef %46)
  store i64 0, ptr %6, align 8
  store i32 1, ptr %15, align 4
  br label %93

48:                                               ; preds = %40, %34
  %49 = load ptr, ptr %7, align 8, !tbaa !5
  %50 = load ptr, ptr %8, align 8, !tbaa !5
  %51 = load i32, ptr %9, align 4, !tbaa !9
  %52 = call i64 @Mtftp4RrqSaveBlock(ptr noundef %49, ptr noundef %50, i32 noundef %51)
  store i64 %52, ptr %12, align 8, !tbaa !14
  %53 = load i64, ptr %12, align 8, !tbaa !14
  %54 = icmp slt i64 %53, 0
  br i1 %54, label %55, label %57

55:                                               ; preds = %48
  %56 = load i64, ptr %12, align 8, !tbaa !14
  store i64 %56, ptr %6, align 8
  store i32 1, ptr %15, align 4
  br label %93

57:                                               ; preds = %48
  %58 = load ptr, ptr %7, align 8, !tbaa !5
  %59 = getelementptr inbounds %struct._MTFTP4_PROTOCOL, ptr %58, i32 0, i32 26
  %60 = load i8, ptr %59, align 2, !tbaa !16
  %61 = icmp ne i8 %60, 0
  br i1 %61, label %64, label %62

62:                                               ; preds = %57
  %63 = load ptr, ptr %7, align 8, !tbaa !5
  call void @Mtftp4SetTimeout(ptr noundef %63)
  br label %64

64:                                               ; preds = %62, %57
  %65 = load ptr, ptr %7, align 8, !tbaa !5
  %66 = getelementptr inbounds %struct._MTFTP4_PROTOCOL, ptr %65, i32 0, i32 13
  %67 = call i64 @Mtftp4GetNextBlockNum(ptr noundef %66)
  store i64 %67, ptr %14, align 8, !tbaa !14
  %68 = load ptr, ptr %7, align 8, !tbaa !5
  %69 = getelementptr inbounds %struct._MTFTP4_PROTOCOL, ptr %68, i32 0, i32 26
  %70 = load i8, ptr %69, align 2, !tbaa !16
  %71 = zext i8 %70 to i32
  %72 = icmp ne i32 %71, 0
  br i1 %72, label %76, label %73

73:                                               ; preds = %64
  %74 = load i64, ptr %14, align 8, !tbaa !14
  %75 = icmp slt i64 %74, 0
  br i1 %75, label %76, label %92

76:                                               ; preds = %73, %64
  %77 = load i64, ptr %14, align 8, !tbaa !14
  %78 = icmp slt i64 %77, 0
  br i1 %78, label %79, label %84

79:                                               ; preds = %76
  %80 = load ptr, ptr %7, align 8, !tbaa !5
  %81 = getelementptr inbounds %struct._MTFTP4_PROTOCOL, ptr %80, i32 0, i32 12
  %82 = load i16, ptr %81, align 8, !tbaa !23
  store i16 %82, ptr %13, align 2, !tbaa !12
  %83 = load ptr, ptr %11, align 8, !tbaa !5
  store i8 1, ptr %83, align 1, !tbaa !11
  br label %88

84:                                               ; preds = %76
  %85 = load i64, ptr %14, align 8, !tbaa !14
  %86 = sub nsw i64 %85, 1
  %87 = trunc i64 %86 to i16
  store i16 %87, ptr %13, align 2, !tbaa !12
  br label %88

88:                                               ; preds = %84, %79
  %89 = load ptr, ptr %7, align 8, !tbaa !5
  %90 = load i16, ptr %13, align 2, !tbaa !12
  %91 = call i64 @Mtftp4RrqSendAck(ptr noundef %89, i16 noundef zeroext %90)
  br label %92

92:                                               ; preds = %88, %73
  store i64 0, ptr %6, align 8
  store i32 1, ptr %15, align 4
  br label %93

93:                                               ; preds = %92, %55, %45
  call void @llvm.lifetime.end.p0(i64 8, ptr %14) #3
  call void @llvm.lifetime.end.p0(i64 2, ptr %13) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #3
  %94 = load i64, ptr %6, align 8
  ret i64 %94
}

declare i64 @Mtftp4GetNextBlockNum(ptr noundef) #2

declare i64 @Mtftp4Retransmit(ptr noundef) #2

declare void @Mtftp4SetTimeout(ptr noundef) #2

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 = !{!7, !7, i64 0}
!12 = !{!13, !13, i64 0}
!13 = !{!"short", !7, i64 0}
!14 = !{!15, !15, i64 0}
!15 = !{!"long long", !7, i64 0}
!16 = !{!17, !7, i64 262}
!17 = !{!"_MTFTP4_PROTOCOL", !10, i64 0, !18, i64 8, !19, i64 24, !15, i64 88, !7, i64 96, !6, i64 104, !6, i64 112, !20, i64 120, !6, i64 152, !22, i64 160, !13, i64 180, !13, i64 182, !13, i64 184, !18, i64 192, !10, i64 208, !13, i64 212, !13, i64 214, !10, i64 216, !6, i64 224, !6, i64 232, !10, i64 240, !10, i64 244, !10, i64 248, !10, i64 252, !10, i64 256, !13, i64 260, !7, i64 262, !6, i64 264}
!18 = !{!"_LIST_ENTRY", !6, i64 0, !6, i64 8}
!19 = !{!"_EFI_MTFTP4_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}
!20 = !{!"", !7, i64 0, !21, i64 1, !21, i64 5, !13, i64 10, !21, i64 12, !21, i64 16, !13, i64 20, !13, i64 22, !13, i64 24}
!21 = !{!"", !7, i64 0}
!22 = !{!"", !13, i64 0, !7, i64 2, !10, i64 4, !10, i64 8, !13, i64 12, !7, i64 14, !10, i64 16}
!23 = !{!17, !13, i64 184}


; 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 [154 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [14 x i8], align 1

; Function Attrs: nounwind uwtable
declare dso_local i64 @Mtftp4RrqSendAck(ptr noundef, i16 noundef zeroext) local_unnamed_addr #0

declare zeroext i8 @DebugAssertEnabled() local_unnamed_addr #1

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

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

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

; Function Attrs: nounwind uwtable
define dso_local range(i64 -9223372036854775808, 1) i64 @Mtftp4RrqHandleData(ptr noundef %0, ptr noundef %1, i32 noundef %2, i8 noundef zeroext %3, ptr nocapture noundef writeonly %4) local_unnamed_addr #0 {
  store i8 0, ptr %4, align 1, !tbaa !5
  %6 = getelementptr inbounds i8, ptr %1, i64 2
  %7 = load i16, ptr %6, align 1, !tbaa !5
  %8 = tail call zeroext i16 @SwapBytes16(i16 noundef zeroext %7) #2
  %9 = getelementptr inbounds i8, ptr %0, i64 192
  %10 = tail call i64 @Mtftp4GetNextBlockNum(ptr noundef nonnull %9) #2
  %11 = tail call zeroext i8 @DebugAssertEnabled() #2
  %12 = icmp eq i8 %11, 0
  %13 = icmp sgt i64 %10, -1
  %or.cond3 = select i1 %12, i1 true, i1 %13
  br i1 %or.cond3, label %15, label %14

14:                                               ; preds = %5
  tail call void @DebugAssert(ptr noundef nonnull @.str, i64 noundef 262, ptr noundef nonnull @.str.4) #2
  br label %15

15:                                               ; preds = %14, %5
  %16 = getelementptr inbounds i8, ptr %0, i64 262
  %17 = load i8, ptr %16, align 2, !tbaa !8
  %.not = icmp eq i8 %17, 0
  %18 = zext i16 %8 to i64
  %.not30 = icmp eq i64 %10, %18
  %or.cond32 = select i1 %.not, i1 true, i1 %.not30
  br i1 %or.cond32, label %21, label %19

19:                                               ; preds = %15
  %20 = tail call i64 @Mtftp4Retransmit(ptr noundef nonnull %0) #2
  br label %41

21:                                               ; preds = %15
  %22 = tail call i64 @Mtftp4RrqSaveBlock(ptr noundef nonnull %0, ptr noundef nonnull %1, i32 noundef %2)
  %23 = icmp slt i64 %22, 0
  br i1 %23, label %41, label %24

24:                                               ; preds = %21
  %25 = load i8, ptr %16, align 2, !tbaa !8
  %.not31 = icmp eq i8 %25, 0
  br i1 %.not31, label %26, label %27

26:                                               ; preds = %24
  tail call void @Mtftp4SetTimeout(ptr noundef nonnull %0) #2
  br label %27

27:                                               ; preds = %26, %24
  %28 = tail call i64 @Mtftp4GetNextBlockNum(ptr noundef nonnull %9) #2
  %29 = load i8, ptr %16, align 2, !tbaa !8
  %30 = icmp ne i8 %29, 0
  %31 = icmp slt i64 %28, 0
  %or.cond = select i1 %30, i1 true, i1 %31
  br i1 %or.cond, label %32, label %41

32:                                               ; preds = %27
  br i1 %31, label %33, label %36

33:                                               ; preds = %32
  %34 = getelementptr inbounds i8, ptr %0, i64 184
  %35 = load i16, ptr %34, align 8, !tbaa !19
  store i8 1, ptr %4, align 1, !tbaa !5
  br label %39

36:                                               ; preds = %32
  %37 = trunc i64 %28 to i16
  %38 = add i16 %37, -1
  br label %39

39:                                               ; preds = %36, %33
  %.0 = phi i16 [ %35, %33 ], [ %38, %36 ]
  %40 = tail call i64 @Mtftp4RrqSendAck(ptr noundef nonnull %0, i16 noundef zeroext %.0)
  br label %41

41:                                               ; preds = %39, %27, %21, %19
  %.027 = phi i64 [ 0, %19 ], [ %22, %21 ], [ 0, %27 ], [ 0, %39 ]
  ret i64 %.027
}

declare i64 @Mtftp4GetNextBlockNum(ptr noundef) local_unnamed_addr #1

declare i64 @Mtftp4Retransmit(ptr noundef) local_unnamed_addr #1

declare void @Mtftp4SetTimeout(ptr noundef) local_unnamed_addr #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 = { "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, !6, i64 0}
!6 = !{!"omnipotent char", !7, i64 0}
!7 = !{!"Simple C/C++ TBAA"}
!8 = !{!9, !6, i64 262}
!9 = !{!"_MTFTP4_PROTOCOL", !10, i64 0, !11, i64 8, !13, i64 24, !14, i64 88, !6, i64 96, !12, i64 104, !12, i64 112, !15, i64 120, !12, i64 152, !18, i64 160, !17, i64 180, !17, i64 182, !17, i64 184, !11, i64 192, !10, i64 208, !17, i64 212, !17, i64 214, !10, i64 216, !12, i64 224, !12, i64 232, !10, i64 240, !10, i64 244, !10, i64 248, !10, i64 252, !10, i64 256, !17, i64 260, !6, i64 262, !12, i64 264}
!10 = !{!"int", !6, i64 0}
!11 = !{!"_LIST_ENTRY", !12, i64 0, !12, i64 8}
!12 = !{!"any pointer", !6, i64 0}
!13 = !{!"_EFI_MTFTP4_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}
!14 = !{!"long long", !6, i64 0}
!15 = !{!"", !6, i64 0, !16, i64 1, !16, i64 5, !17, i64 10, !16, i64 12, !16, i64 16, !17, i64 20, !17, i64 22, !17, i64 24}
!16 = !{!"", !6, i64 0}
!17 = !{!"short", !6, i64 0}
!18 = !{!"", !17, i64 0, !6, i64 2, !10, i64 4, !10, i64 8, !17, i64 12, !6, i64 14, !10, i64 16}
!19 = !{!9, !17, i64 184}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass