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

; 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_ACK_HEADER = type { i16, [1 x i16] }
%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.3 = external hidden unnamed_addr constant [14 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [25 x i8], align 1
@.str.5 = external hidden unnamed_addr constant [59 x i8], align 1

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

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

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 @Mtftp4SendError(ptr noundef, i16 noundef zeroext, ptr noundef) #2

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

; Function Attrs: nounwind uwtable
define dso_local i64 @Mtftp4WrqHandleAck(ptr noundef %0, ptr noundef %1, i32 noundef %2, ptr noundef %3) #0 {
  %5 = alloca i64, align 8
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca i32, align 4
  %9 = alloca ptr, align 8
  %10 = alloca i16, align 2
  %11 = alloca i64, align 8
  %12 = alloca i64, align 8
  %13 = alloca i32, align 4
  store ptr %0, ptr %6, align 8, !tbaa !5
  store ptr %1, ptr %7, align 8, !tbaa !5
  store i32 %2, ptr %8, align 4, !tbaa !9
  store ptr %3, ptr %9, align 8, !tbaa !5
  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 %9, align 8, !tbaa !5
  store i8 0, ptr %14, align 1, !tbaa !11
  %15 = load ptr, ptr %7, align 8, !tbaa !5
  %16 = getelementptr inbounds %struct.EFI_MTFTP4_ACK_HEADER, ptr %15, i32 0, i32 1
  %17 = getelementptr inbounds [1 x i16], ptr %16, i64 0, i64 0
  %18 = load i16, ptr %17, align 1, !tbaa !11
  %19 = call zeroext i16 @SwapBytes16(i16 noundef zeroext %18)
  store i16 %19, ptr %10, align 2, !tbaa !12
  %20 = load ptr, ptr %6, align 8, !tbaa !5
  %21 = getelementptr inbounds %struct._MTFTP4_PROTOCOL, ptr %20, i32 0, i32 13
  %22 = call i64 @Mtftp4GetNextBlockNum(ptr noundef %21)
  store i64 %22, ptr %11, align 8, !tbaa !14
  br label %23

23:                                               ; preds = %4
  %24 = call zeroext i8 @DebugAssertEnabled()
  %25 = icmp ne i8 %24, 0
  br i1 %25, label %26, label %31

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

29:                                               ; preds = %26
  call void @DebugAssert(ptr noundef @.str, i64 noundef 154, ptr noundef @.str.3)
  br label %30

30:                                               ; preds = %29, %26
  br label %31

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

32:                                               ; preds = %31
  br label %33

33:                                               ; preds = %32
  %34 = load i64, ptr %11, align 8, !tbaa !14
  %35 = load i16, ptr %10, align 2, !tbaa !12
  %36 = zext i16 %35 to i64
  %37 = icmp ne i64 %34, %36
  br i1 %37, label %38, label %39

38:                                               ; preds = %33
  store i64 0, ptr %5, align 8
  store i32 1, ptr %13, align 4
  br label %83

39:                                               ; preds = %33
  %40 = load ptr, ptr %6, align 8, !tbaa !5
  %41 = getelementptr inbounds %struct._MTFTP4_PROTOCOL, ptr %40, i32 0, i32 13
  %42 = load i16, ptr %10, align 2, !tbaa !12
  %43 = load ptr, ptr %9, align 8, !tbaa !5
  %44 = load i8, ptr %43, align 1, !tbaa !11
  %45 = call i64 @Mtftp4RemoveBlockNum(ptr noundef %41, i16 noundef zeroext %42, i8 noundef zeroext %44, ptr noundef %12)
  %46 = load ptr, ptr %6, align 8, !tbaa !5
  %47 = getelementptr inbounds %struct._MTFTP4_PROTOCOL, ptr %46, i32 0, i32 13
  %48 = call i64 @Mtftp4GetNextBlockNum(ptr noundef %47)
  store i64 %48, ptr %11, align 8, !tbaa !14
  %49 = load i64, ptr %11, align 8, !tbaa !14
  %50 = icmp slt i64 %49, 0
  br i1 %50, label %51, label %78

51:                                               ; preds = %39
  %52 = load ptr, ptr %6, align 8, !tbaa !5
  %53 = getelementptr inbounds %struct._MTFTP4_PROTOCOL, ptr %52, i32 0, i32 12
  %54 = load i16, ptr %53, align 8, !tbaa !16
  %55 = zext i16 %54 to i32
  %56 = load i16, ptr %10, align 2, !tbaa !12
  %57 = zext i16 %56 to i32
  %58 = icmp eq i32 %55, %57
  br i1 %58, label %59, label %75

59:                                               ; preds = %51
  br label %60

60:                                               ; preds = %59
  %61 = call zeroext i8 @DebugAssertEnabled()
  %62 = icmp ne i8 %61, 0
  br i1 %62, label %63, label %71

63:                                               ; preds = %60
  %64 = load ptr, ptr %6, align 8, !tbaa !5
  %65 = getelementptr inbounds %struct._MTFTP4_PROTOCOL, ptr %64, i32 0, i32 12
  %66 = load i16, ptr %65, align 8, !tbaa !16
  %67 = zext i16 %66 to i32
  %68 = icmp sge i32 %67, 1
  br i1 %68, label %70, label %69

69:                                               ; preds = %63
  call void @DebugAssert(ptr noundef @.str, i64 noundef 181, ptr noundef @.str.4)
  br label %70

70:                                               ; preds = %69, %63
  br label %71

71:                                               ; preds = %70, %60
  br label %72

72:                                               ; preds = %71
  br label %73

73:                                               ; preds = %72
  %74 = load ptr, ptr %9, align 8, !tbaa !5
  store i8 1, ptr %74, align 1, !tbaa !11
  store i64 0, ptr %5, align 8
  store i32 1, ptr %13, align 4
  br label %83

75:                                               ; preds = %51
  %76 = load ptr, ptr %6, align 8, !tbaa !5
  %77 = call i64 @Mtftp4SendError(ptr noundef %76, i16 noundef zeroext 8, ptr noundef @.str.5)
  store i64 -9223372036854775785, ptr %5, align 8
  store i32 1, ptr %13, align 4
  br label %83

78:                                               ; preds = %39
  %79 = load ptr, ptr %6, align 8, !tbaa !5
  %80 = load i64, ptr %11, align 8, !tbaa !14
  %81 = trunc i64 %80 to i16
  %82 = call i64 @Mtftp4WrqSendBlock(ptr noundef %79, i16 noundef zeroext %81)
  store i64 %82, ptr %5, align 8
  store i32 1, ptr %13, align 4
  br label %83

83:                                               ; preds = %78, %75, %73, %38
  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
  %84 = load i64, ptr %5, align 8
  ret i64 %84
}

declare i64 @Mtftp4GetNextBlockNum(ptr noundef) #2

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

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 = !{!"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, !13, i64 184}
!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}


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

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

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

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 @Mtftp4SendError(ptr noundef, i16 noundef zeroext, 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

; Function Attrs: nounwind uwtable
define dso_local i64 @Mtftp4WrqHandleAck(ptr noundef %0, ptr nocapture noundef readonly %1, i32 noundef %2, ptr nocapture noundef %3) local_unnamed_addr #0 {
  %5 = alloca i64, align 8
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %5) #3
  store i8 0, ptr %3, 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) #3
  %9 = getelementptr inbounds i8, ptr %0, i64 192
  %10 = tail call i64 @Mtftp4GetNextBlockNum(ptr noundef nonnull %9) #3
  %11 = tail call zeroext i8 @DebugAssertEnabled() #3
  %12 = icmp eq i8 %11, 0
  %13 = icmp sgt i64 %10, -1
  %or.cond = select i1 %12, i1 true, i1 %13
  br i1 %or.cond, label %15, label %14

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

15:                                               ; preds = %14, %4
  %16 = zext i16 %8 to i64
  %.not = icmp eq i64 %10, %16
  br i1 %.not, label %17, label %37

17:                                               ; preds = %15
  %18 = load i8, ptr %3, align 1, !tbaa !5
  %19 = call i64 @Mtftp4RemoveBlockNum(ptr noundef nonnull %9, i16 noundef zeroext %8, i8 noundef zeroext %18, ptr noundef nonnull %5) #3
  %20 = call i64 @Mtftp4GetNextBlockNum(ptr noundef nonnull %9) #3
  %21 = icmp slt i64 %20, 0
  br i1 %21, label %22, label %34

22:                                               ; preds = %17
  %23 = getelementptr inbounds i8, ptr %0, i64 184
  %24 = load i16, ptr %23, align 8, !tbaa !8
  %25 = icmp eq i16 %24, %8
  br i1 %25, label %26, label %32

26:                                               ; preds = %22
  %27 = call zeroext i8 @DebugAssertEnabled() #3
  %.not20 = icmp eq i8 %27, 0
  br i1 %.not20, label %31, label %28

28:                                               ; preds = %26
  %29 = load i16, ptr %23, align 8, !tbaa !8
  %.not21 = icmp eq i16 %29, 0
  br i1 %.not21, label %30, label %31

30:                                               ; preds = %28
  call void @DebugAssert(ptr noundef nonnull @.str, i64 noundef 181, ptr noundef nonnull @.str.4) #3
  br label %31

31:                                               ; preds = %28, %30, %26
  store i8 1, ptr %3, align 1, !tbaa !5
  br label %37

32:                                               ; preds = %22
  %33 = call i64 @Mtftp4SendError(ptr noundef nonnull %0, i16 noundef zeroext 8, ptr noundef nonnull @.str.5) #3
  br label %37

34:                                               ; preds = %17
  %35 = trunc i64 %20 to i16
  %36 = call i64 @Mtftp4WrqSendBlock(ptr noundef %0, i16 noundef zeroext %35)
  br label %37

37:                                               ; preds = %15, %34, %32, %31
  %.0 = phi i64 [ 0, %31 ], [ -9223372036854775785, %32 ], [ %36, %34 ], [ 0, %15 ]
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %5) #3
  ret i64 %.0
}

declare i64 @Mtftp4GetNextBlockNum(ptr noundef) local_unnamed_addr #2

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

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, !6, i64 0}
!6 = !{!"omnipotent char", !7, i64 0}
!7 = !{!"Simple C/C++ TBAA"}
!8 = !{!9, !17, i64 184}
!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}


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