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

; 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.MTFTP4_OPTION = type { i16, i8, i32, i32, i16, i8, i32 }
%union.EFI_MTFTP4_PACKET = type <{ %struct.EFI_MTFTP4_ACK_HEADER, [7 x i8] }>
%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._LIST_ENTRY = type { ptr, ptr }

@.str.6 = external hidden unnamed_addr constant [25 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

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

declare i64 @Mtftp4SendError(ptr noundef, i16 noundef zeroext, ptr noundef) #1

; 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 @Mtftp4WrqHandleAck(ptr noundef, ptr noundef, i32 noundef, ptr noundef) #2

declare i64 @Mtftp4GetNextBlockNum(ptr noundef) #1

; Function Attrs: nounwind uwtable
declare dso_local zeroext i8 @Mtftp4WrqOackValid(ptr noundef, ptr noundef) #2

; Function Attrs: nounwind uwtable
define dso_local i64 @Mtftp4WrqHandleOack(ptr noundef %0, ptr noundef %1, i32 noundef %2, ptr noundef %3) #2 {
  %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 %struct.MTFTP4_OPTION, align 4
  %11 = alloca %union.EFI_MTFTP4_PACKET, align 1
  %12 = alloca i64, align 8
  %13 = alloca i64, align 8
  %14 = 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 20, ptr %10) #3
  call void @llvm.lifetime.start.p0(i64 11, 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
  %15 = load ptr, ptr %9, align 8, !tbaa !5
  store i8 0, ptr %15, align 1, !tbaa !11
  %16 = load ptr, ptr %6, align 8, !tbaa !5
  %17 = getelementptr inbounds %struct._MTFTP4_PROTOCOL, ptr %16, i32 0, i32 13
  %18 = call i64 @Mtftp4GetNextBlockNum(ptr noundef %17)
  store i64 %18, ptr %13, align 8, !tbaa !12
  %19 = load i64, ptr %13, align 8, !tbaa !12
  %20 = icmp ne i64 %19, 0
  br i1 %20, label %21, label %22

21:                                               ; preds = %4
  store i64 0, ptr %5, align 8
  store i32 1, ptr %14, align 4
  br label %71

22:                                               ; preds = %4
  %23 = call ptr @ZeroMem(ptr noundef %10, i64 noundef 20)
  %24 = load ptr, ptr %7, align 8, !tbaa !5
  %25 = load i32, ptr %8, align 4, !tbaa !9
  %26 = call i64 @Mtftp4ParseOptionOack(ptr noundef %24, i32 noundef %25, ptr noundef %10)
  store i64 %26, ptr %12, align 8, !tbaa !12
  %27 = load i64, ptr %12, align 8, !tbaa !12
  %28 = icmp slt i64 %27, 0
  br i1 %28, label %34, label %29

29:                                               ; preds = %22
  %30 = load ptr, ptr %6, align 8, !tbaa !5
  %31 = getelementptr inbounds %struct._MTFTP4_PROTOCOL, ptr %30, i32 0, i32 9
  %32 = call zeroext i8 @Mtftp4WrqOackValid(ptr noundef %10, ptr noundef %31)
  %33 = icmp ne i8 %32, 0
  br i1 %33, label %41, label %34

34:                                               ; preds = %29, %22
  %35 = load i64, ptr %12, align 8, !tbaa !12
  %36 = icmp ne i64 %35, -9223372036854775799
  br i1 %36, label %37, label %40

37:                                               ; preds = %34
  %38 = load ptr, ptr %6, align 8, !tbaa !5
  %39 = call i64 @Mtftp4SendError(ptr noundef %38, i16 noundef zeroext 4, ptr noundef @.str.6)
  br label %40

40:                                               ; preds = %37, %34
  store i64 -9223372036854775785, ptr %5, align 8
  store i32 1, ptr %14, align 4
  br label %71

41:                                               ; preds = %29
  %42 = getelementptr inbounds %struct.MTFTP4_OPTION, ptr %10, i32 0, i32 0
  %43 = load i16, ptr %42, align 4, !tbaa !14
  %44 = zext i16 %43 to i32
  %45 = icmp ne i32 %44, 0
  br i1 %45, label %46, label %51

46:                                               ; preds = %41
  %47 = getelementptr inbounds %struct.MTFTP4_OPTION, ptr %10, i32 0, i32 0
  %48 = load i16, ptr %47, align 4, !tbaa !14
  %49 = load ptr, ptr %6, align 8, !tbaa !5
  %50 = getelementptr inbounds %struct._MTFTP4_PROTOCOL, ptr %49, i32 0, i32 11
  store i16 %48, ptr %50, align 2, !tbaa !17
  br label %51

51:                                               ; preds = %46, %41
  %52 = getelementptr inbounds %struct.MTFTP4_OPTION, ptr %10, i32 0, i32 1
  %53 = load i8, ptr %52, align 2, !tbaa !23
  %54 = zext i8 %53 to i32
  %55 = icmp ne i32 %54, 0
  br i1 %55, label %56, label %62

56:                                               ; preds = %51
  %57 = getelementptr inbounds %struct.MTFTP4_OPTION, ptr %10, i32 0, i32 1
  %58 = load i8, ptr %57, align 2, !tbaa !23
  %59 = zext i8 %58 to i32
  %60 = load ptr, ptr %6, align 8, !tbaa !5
  %61 = getelementptr inbounds %struct._MTFTP4_PROTOCOL, ptr %60, i32 0, i32 23
  store i32 %59, ptr %61, align 4, !tbaa !24
  br label %62

62:                                               ; preds = %56, %51
  %63 = call zeroext i16 @SwapBytes16(i16 noundef zeroext 4)
  %64 = getelementptr inbounds %struct.EFI_MTFTP4_ACK_HEADER, ptr %11, i32 0, i32 0
  store i16 %63, ptr %64, align 1, !tbaa !11
  %65 = getelementptr inbounds %struct.EFI_MTFTP4_ACK_HEADER, ptr %11, i32 0, i32 1
  %66 = getelementptr inbounds [1 x i16], ptr %65, i64 0, i64 0
  store i16 0, ptr %66, align 1, !tbaa !11
  %67 = load ptr, ptr %6, align 8, !tbaa !5
  %68 = load ptr, ptr %9, align 8, !tbaa !5
  %69 = call i64 @Mtftp4WrqHandleAck(ptr noundef %67, ptr noundef %11, i32 noundef 4, ptr noundef %68)
  store i64 %69, ptr %12, align 8, !tbaa !12
  %70 = load i64, ptr %12, align 8, !tbaa !12
  store i64 %70, ptr %5, align 8
  store i32 1, ptr %14, align 4
  br label %71

71:                                               ; preds = %62, %40, %21
  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 11, ptr %11) #3
  call void @llvm.lifetime.end.p0(i64 20, ptr %10) #3
  %72 = load i64, ptr %5, align 8
  ret i64 %72
}

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

declare i64 @Mtftp4ParseOptionOack(ptr noundef, i32 noundef, ptr noundef) #1

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


; 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.MTFTP4_OPTION = type { i16, i8, i32, i32, i16, i8, i32 }
%union.EFI_MTFTP4_PACKET = type <{ %struct.EFI_MTFTP4_ACK_HEADER, [7 x i8] }>
%struct.EFI_MTFTP4_ACK_HEADER = type { i16, [1 x i16] }

@.str.6 = external hidden unnamed_addr constant [25 x i8], align 1

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

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

declare i64 @Mtftp4SendError(ptr noundef, i16 noundef zeroext, ptr noundef) local_unnamed_addr #1

; Function Attrs: mustprogress 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 @Mtftp4WrqHandleAck(ptr noundef, ptr noundef, i32 noundef, ptr noundef) local_unnamed_addr #2

declare i64 @Mtftp4GetNextBlockNum(ptr noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
declare dso_local zeroext i8 @Mtftp4WrqOackValid(ptr noundef, ptr noundef) local_unnamed_addr #2

; Function Attrs: nounwind uwtable
define dso_local i64 @Mtftp4WrqHandleOack(ptr noundef %0, ptr noundef %1, i32 noundef %2, ptr noundef %3) local_unnamed_addr #2 {
  %5 = alloca %struct.MTFTP4_OPTION, align 4
  %6 = alloca %union.EFI_MTFTP4_PACKET, align 2
  call void @llvm.lifetime.start.p0(i64 20, ptr nonnull %5) #3
  call void @llvm.lifetime.start.p0(i64 11, ptr nonnull %6) #3
  store i8 0, ptr %3, align 1, !tbaa !5
  %7 = getelementptr inbounds i8, ptr %0, i64 192
  %8 = tail call i64 @Mtftp4GetNextBlockNum(ptr noundef nonnull %7) #3
  %.not = icmp eq i64 %8, 0
  br i1 %.not, label %9, label %32

9:                                                ; preds = %4
  %10 = call ptr @ZeroMem(ptr noundef nonnull %5, i64 noundef 20) #3
  %11 = call i64 @Mtftp4ParseOptionOack(ptr noundef %1, i32 noundef %2, ptr noundef nonnull %5) #3
  %12 = icmp slt i64 %11, 0
  br i1 %12, label %16, label %13

13:                                               ; preds = %9
  %14 = getelementptr inbounds i8, ptr %0, i64 160
  %15 = call zeroext i8 @Mtftp4WrqOackValid(ptr noundef nonnull %5, ptr noundef nonnull %14)
  %.not15 = icmp eq i8 %15, 0
  br i1 %.not15, label %.thread, label %18

16:                                               ; preds = %9
  %.not18 = icmp eq i64 %11, -9223372036854775799
  br i1 %.not18, label %32, label %.thread

.thread:                                          ; preds = %13, %16
  %17 = call i64 @Mtftp4SendError(ptr noundef %0, i16 noundef zeroext 4, ptr noundef nonnull @.str.6) #3
  br label %32

18:                                               ; preds = %13
  %19 = load i16, ptr %5, align 4, !tbaa !8
  %.not16 = icmp eq i16 %19, 0
  br i1 %.not16, label %22, label %20

20:                                               ; preds = %18
  %21 = getelementptr inbounds i8, ptr %0, i64 182
  store i16 %19, ptr %21, align 2, !tbaa !12
  br label %22

22:                                               ; preds = %20, %18
  %23 = getelementptr inbounds i8, ptr %5, i64 2
  %24 = load i8, ptr %23, align 2, !tbaa !20
  %.not17 = icmp eq i8 %24, 0
  br i1 %.not17, label %28, label %25

25:                                               ; preds = %22
  %26 = zext i8 %24 to i32
  %27 = getelementptr inbounds i8, ptr %0, i64 252
  store i32 %26, ptr %27, align 4, !tbaa !21
  br label %28

28:                                               ; preds = %25, %22
  %29 = call zeroext i16 @SwapBytes16(i16 noundef zeroext 4) #3
  store i16 %29, ptr %6, align 2, !tbaa !5
  %30 = getelementptr inbounds i8, ptr %6, i64 2
  store i16 0, ptr %30, align 2, !tbaa !5
  %31 = call i64 @Mtftp4WrqHandleAck(ptr noundef %0, ptr noundef nonnull %6, i32 noundef 4, ptr noundef nonnull %3)
  br label %32

32:                                               ; preds = %16, %.thread, %4, %28
  %.0 = phi i64 [ %31, %28 ], [ 0, %4 ], [ -9223372036854775785, %.thread ], [ -9223372036854775785, %16 ]
  call void @llvm.lifetime.end.p0(i64 11, ptr nonnull %6) #3
  call void @llvm.lifetime.end.p0(i64 20, ptr nonnull %5) #3
  ret i64 %.0
}

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

declare i64 @Mtftp4ParseOptionOack(ptr noundef, i32 noundef, ptr noundef) local_unnamed_addr #1

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


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,InferAlignmentPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,SROAPass,SimplifyCFGPass,TailCallElimPass