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

; 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_MTFTP6_ACK_HEADER = type { i16, [1 x i16] }
%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] }

@.str = external hidden unnamed_addr constant [134 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [14 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [23 x i8], align 1
@.str.5 = external hidden unnamed_addr constant [59 x i8], align 1

; Function Attrs: nounwind uwtable
declare dso_local i64 @Mtftp6WrqSendBlock(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 @Mtftp6SendError(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 @Mtftp6WrqHandleAck(ptr noundef %0, ptr noundef %1, i32 noundef %2, ptr noundef %3, ptr noundef %4) #0 {
  %6 = alloca i64, align 8
  %7 = alloca ptr, align 8
  %8 = alloca ptr, align 8
  %9 = alloca i32, align 4
  %10 = alloca ptr, align 8
  %11 = alloca ptr, align 8
  %12 = alloca i16, align 2
  %13 = alloca i64, align 8
  %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 ptr %3, ptr %10, align 8, !tbaa !5
  store ptr %4, ptr %11, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 2, ptr %12) #3
  call void @llvm.lifetime.start.p0(i64 8, 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_MTFTP6_ACK_HEADER, ptr %17, i32 0, i32 1
  %19 = getelementptr inbounds [1 x i16], ptr %18, i64 0, i64 0
  %20 = load i16, ptr %19, align 1, !tbaa !11
  %21 = call zeroext i16 @SwapBytes16(i16 noundef zeroext %20)
  store i16 %21, ptr %12, align 2, !tbaa !12
  %22 = load ptr, ptr %7, align 8, !tbaa !5
  %23 = getelementptr inbounds %struct._MTFTP6_INSTANCE, ptr %22, i32 0, i32 10
  %24 = call i64 @Mtftp6GetNextBlockNum(ptr noundef %23)
  store i64 %24, ptr %13, align 8, !tbaa !14
  br label %25

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

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

31:                                               ; preds = %28
  call void @DebugAssert(ptr noundef @.str, i64 noundef 162, ptr noundef @.str.3)
  br label %32

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

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

34:                                               ; preds = %33
  br label %35

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

40:                                               ; preds = %35
  store i64 0, ptr %6, align 8
  store i32 1, ptr %15, align 4
  br label %91

41:                                               ; preds = %35
  %42 = load ptr, ptr %7, align 8, !tbaa !5
  %43 = getelementptr inbounds %struct._MTFTP6_INSTANCE, ptr %42, i32 0, i32 10
  %44 = load i16, ptr %12, align 2, !tbaa !12
  %45 = load ptr, ptr %11, align 8, !tbaa !5
  %46 = load i8, ptr %45, align 1, !tbaa !11
  %47 = call i64 @Mtftp6RemoveBlockNum(ptr noundef %43, i16 noundef zeroext %44, i8 noundef zeroext %46, ptr noundef %14)
  %48 = load ptr, ptr %7, align 8, !tbaa !5
  %49 = getelementptr inbounds %struct._MTFTP6_INSTANCE, ptr %48, i32 0, i32 10
  %50 = call i64 @Mtftp6GetNextBlockNum(ptr noundef %49)
  store i64 %50, ptr %13, align 8, !tbaa !14
  %51 = load i64, ptr %13, align 8, !tbaa !14
  %52 = icmp slt i64 %51, 0
  br i1 %52, label %53, label %83

53:                                               ; preds = %41
  %54 = load ptr, ptr %7, align 8, !tbaa !5
  %55 = getelementptr inbounds %struct._MTFTP6_INSTANCE, ptr %54, i32 0, i32 9
  %56 = load i16, ptr %55, align 2, !tbaa !16
  %57 = zext i16 %56 to i32
  %58 = load i16, ptr %12, align 2, !tbaa !12
  %59 = zext i16 %58 to i32
  %60 = icmp eq i32 %57, %59
  br i1 %60, label %61, label %77

61:                                               ; preds = %53
  br label %62

62:                                               ; preds = %61
  %63 = call zeroext i8 @DebugAssertEnabled()
  %64 = icmp ne i8 %63, 0
  br i1 %64, label %65, label %73

65:                                               ; preds = %62
  %66 = load ptr, ptr %7, align 8, !tbaa !5
  %67 = getelementptr inbounds %struct._MTFTP6_INSTANCE, ptr %66, i32 0, i32 9
  %68 = load i16, ptr %67, align 2, !tbaa !16
  %69 = zext i16 %68 to i32
  %70 = icmp sge i32 %69, 1
  br i1 %70, label %72, label %71

71:                                               ; preds = %65
  call void @DebugAssert(ptr noundef @.str, i64 noundef 188, ptr noundef @.str.4)
  br label %72

72:                                               ; preds = %71, %65
  br label %73

73:                                               ; preds = %72, %62
  br label %74

74:                                               ; preds = %73
  br label %75

75:                                               ; preds = %74
  %76 = load ptr, ptr %11, align 8, !tbaa !5
  store i8 1, ptr %76, align 1, !tbaa !11
  store i64 0, ptr %6, align 8
  store i32 1, ptr %15, align 4
  br label %91

77:                                               ; preds = %53
  %78 = load ptr, ptr %10, align 8, !tbaa !5
  %79 = load ptr, ptr %78, align 8, !tbaa !5
  call void @NetbufFree(ptr noundef %79)
  %80 = load ptr, ptr %10, align 8, !tbaa !5
  store ptr null, ptr %80, align 8, !tbaa !5
  %81 = load ptr, ptr %7, align 8, !tbaa !5
  %82 = call i64 @Mtftp6SendError(ptr noundef %81, i16 noundef zeroext 8, ptr noundef @.str.5)
  store i64 -9223372036854775785, ptr %6, align 8
  store i32 1, ptr %15, align 4
  br label %91

83:                                               ; preds = %41
  %84 = load ptr, ptr %10, align 8, !tbaa !5
  %85 = load ptr, ptr %84, align 8, !tbaa !5
  call void @NetbufFree(ptr noundef %85)
  %86 = load ptr, ptr %10, align 8, !tbaa !5
  store ptr null, ptr %86, align 8, !tbaa !5
  %87 = load ptr, ptr %7, align 8, !tbaa !5
  %88 = load i64, ptr %13, align 8, !tbaa !14
  %89 = trunc i64 %88 to i16
  %90 = call i64 @Mtftp6WrqSendBlock(ptr noundef %87, i16 noundef zeroext %89)
  store i64 %90, ptr %6, align 8
  store i32 1, ptr %15, align 4
  br label %91

91:                                               ; preds = %83, %77, %75, %40
  call void @llvm.lifetime.end.p0(i64 8, ptr %14) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %13) #3
  call void @llvm.lifetime.end.p0(i64 2, ptr %12) #3
  %92 = load i64, ptr %6, align 8
  ret i64 %92
}

declare i64 @Mtftp6GetNextBlockNum(ptr noundef) #2

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

declare void @NetbufFree(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 154}
!17 = !{!"_MTFTP6_INSTANCE", !10, i64 0, !6, i64 8, !18, i64 16, !19, i64 32, !6, i64 96, !6, i64 104, !6, i64 112, !20, i64 120, !13, i64 152, !13, i64 154, !18, i64 160, !21, i64 176, !13, i64 192, !13, i64 194, !6, i64 200, !21, i64 208, !13, i64 224, !6, i64 232, !6, i64 240, !10, i64 248, !10, i64 252, !10, i64 256, !10, i64 260, !15, i64 264, !7, i64 272, !7, i64 273, !7, i64 274}
!18 = !{!"_LIST_ENTRY", !6, i64 0, !6, i64 8}
!19 = !{!"_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}
!20 = !{!"", !13, i64 0, !7, i64 2, !10, i64 4, !21, i64 8, !13, i64 24, !7, i64 26, !10, i64 28}
!21 = !{!"", !7, i64 0}


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

; Function Attrs: nounwind uwtable
declare dso_local i64 @Mtftp6WrqSendBlock(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 @Mtftp6SendError(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 @Mtftp6WrqHandleAck(ptr noundef %0, ptr nocapture noundef readonly %1, i32 noundef %2, ptr nocapture noundef %3, ptr nocapture noundef %4) local_unnamed_addr #0 {
  %6 = alloca i64, align 8
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %6) #3
  store i8 0, ptr %4, align 1, !tbaa !5
  %7 = getelementptr inbounds i8, ptr %1, i64 2
  %8 = load i16, ptr %7, align 1, !tbaa !5
  %9 = tail call zeroext i16 @SwapBytes16(i16 noundef zeroext %8) #3
  %10 = getelementptr inbounds i8, ptr %0, i64 160
  %11 = tail call i64 @Mtftp6GetNextBlockNum(ptr noundef nonnull %10) #3
  %12 = tail call zeroext i8 @DebugAssertEnabled() #3
  %13 = icmp eq i8 %12, 0
  %14 = icmp sgt i64 %11, -1
  %or.cond = select i1 %13, i1 true, i1 %14
  br i1 %or.cond, label %16, label %15

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

16:                                               ; preds = %15, %5
  %17 = zext i16 %9 to i64
  %.not = icmp eq i64 %11, %17
  br i1 %.not, label %18, label %40

18:                                               ; preds = %16
  %19 = load i8, ptr %4, align 1, !tbaa !5
  %20 = call i64 @Mtftp6RemoveBlockNum(ptr noundef nonnull %10, i16 noundef zeroext %9, i8 noundef zeroext %19, ptr noundef nonnull %6) #3
  %21 = call i64 @Mtftp6GetNextBlockNum(ptr noundef nonnull %10) #3
  %22 = icmp slt i64 %21, 0
  br i1 %22, label %23, label %36

23:                                               ; preds = %18
  %24 = getelementptr inbounds i8, ptr %0, i64 154
  %25 = load i16, ptr %24, align 2, !tbaa !8
  %26 = icmp eq i16 %25, %9
  br i1 %26, label %27, label %33

27:                                               ; preds = %23
  %28 = call zeroext i8 @DebugAssertEnabled() #3
  %.not24 = icmp eq i8 %28, 0
  br i1 %.not24, label %32, label %29

29:                                               ; preds = %27
  %30 = load i16, ptr %24, align 2, !tbaa !8
  %.not25 = icmp eq i16 %30, 0
  br i1 %.not25, label %31, label %32

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

32:                                               ; preds = %29, %31, %27
  store i8 1, ptr %4, align 1, !tbaa !5
  br label %40

33:                                               ; preds = %23
  %34 = load ptr, ptr %3, align 8, !tbaa !18
  call void @NetbufFree(ptr noundef %34) #3
  store ptr null, ptr %3, align 8, !tbaa !18
  %35 = call i64 @Mtftp6SendError(ptr noundef nonnull %0, i16 noundef zeroext 8, ptr noundef nonnull @.str.5) #3
  br label %40

36:                                               ; preds = %18
  %37 = load ptr, ptr %3, align 8, !tbaa !18
  call void @NetbufFree(ptr noundef %37) #3
  store ptr null, ptr %3, align 8, !tbaa !18
  %38 = trunc i64 %21 to i16
  %39 = call i64 @Mtftp6WrqSendBlock(ptr noundef %0, i16 noundef zeroext %38)
  br label %40

40:                                               ; preds = %16, %36, %33, %32
  %.0 = phi i64 [ 0, %32 ], [ -9223372036854775785, %33 ], [ %39, %36 ], [ 0, %16 ]
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %6) #3
  ret i64 %.0
}

declare i64 @Mtftp6GetNextBlockNum(ptr noundef) local_unnamed_addr #2

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

declare void @NetbufFree(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, !15, i64 154}
!9 = !{!"_MTFTP6_INSTANCE", !10, i64 0, !11, i64 8, !12, i64 16, !13, i64 32, !11, i64 96, !11, i64 104, !11, i64 112, !14, i64 120, !15, i64 152, !15, i64 154, !12, i64 160, !16, i64 176, !15, i64 192, !15, i64 194, !11, i64 200, !16, i64 208, !15, i64 224, !11, i64 232, !11, i64 240, !10, i64 248, !10, i64 252, !10, i64 256, !10, i64 260, !17, i64 264, !6, i64 272, !6, i64 273, !6, i64 274}
!10 = !{!"int", !6, i64 0}
!11 = !{!"any pointer", !6, i64 0}
!12 = !{!"_LIST_ENTRY", !11, i64 0, !11, i64 8}
!13 = !{!"_EFI_MTFTP6_PROTOCOL", !11, i64 0, !11, i64 8, !11, i64 16, !11, i64 24, !11, i64 32, !11, i64 40, !11, i64 48, !11, i64 56}
!14 = !{!"", !15, i64 0, !6, i64 2, !10, i64 4, !16, i64 8, !15, i64 24, !6, i64 26, !10, i64 28}
!15 = !{!"short", !6, i64 0}
!16 = !{!"", !6, i64 0}
!17 = !{!"long long", !6, i64 0}
!18 = !{!11, !11, i64 0}


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