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

; 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_TOKEN = type { i64, ptr, ptr, ptr, ptr, i32, ptr, i64, ptr, ptr, ptr, ptr, ptr }
%struct.EFI_MTFTP4_ERROR_HEADER = type <{ i16, i16, [1 x i8] }>
%struct.MTFTP4_GETINFO_STATE = type { ptr, ptr, i64 }
%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 }

@gBS = external global ptr, align 8
@.str.2 = external hidden unnamed_addr constant [36 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [20 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
define dso_local i64 @Mtftp4GetInfoCheckPacket(ptr noundef %0, ptr noundef %1, i16 noundef zeroext %2, ptr noundef %3) #1 {
  %5 = alloca i64, align 8
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca i16, align 2
  %9 = alloca ptr, align 8
  %10 = alloca ptr, align 8
  %11 = alloca i64, align 8
  %12 = alloca i16, align 2
  %13 = alloca ptr, 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 i16 %2, ptr %8, align 2, !tbaa !9
  store ptr %3, ptr %9, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #3
  call void @llvm.lifetime.start.p0(i64 2, ptr %12) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %13) #3
  %15 = load ptr, ptr %7, align 8, !tbaa !5
  %16 = getelementptr inbounds %struct._EFI_MTFTP4_TOKEN, ptr %15, i32 0, i32 9
  %17 = load ptr, ptr %16, align 8, !tbaa !11
  store ptr %17, ptr %10, align 8, !tbaa !5
  %18 = load ptr, ptr %9, align 8, !tbaa !5
  %19 = load i16, ptr %18, align 1, !tbaa !15
  %20 = call zeroext i16 @SwapBytes16(i16 noundef zeroext %19)
  store i16 %20, ptr %12, align 2, !tbaa !9
  %21 = load i16, ptr %12, align 2, !tbaa !9
  %22 = zext i16 %21 to i32
  switch i32 %22, label %70 [
    i32 5, label %23
    i32 6, label %67
  ]

23:                                               ; preds = %4
  %24 = load ptr, ptr %9, align 8, !tbaa !5
  store ptr %24, ptr %13, align 8, !tbaa !5
  %25 = load ptr, ptr %13, align 8, !tbaa !5
  %26 = getelementptr inbounds %struct.EFI_MTFTP4_ERROR_HEADER, ptr %25, i32 0, i32 1
  %27 = load i16, ptr %26, align 1, !tbaa !16
  %28 = zext i16 %27 to i32
  %29 = icmp eq i32 %28, 1
  br i1 %29, label %30, label %45

30:                                               ; preds = %23
  br label %31

31:                                               ; preds = %30
  %32 = call zeroext i8 @DebugPrintEnabled()
  %33 = icmp ne i8 %32, 0
  br i1 %33, label %34, label %42

34:                                               ; preds = %31
  br label %35

35:                                               ; preds = %34
  %36 = call zeroext i8 @DebugPrintLevelEnabled(i64 noundef 2147483648)
  %37 = icmp ne i8 %36, 0
  br i1 %37, label %38, label %39

38:                                               ; preds = %35
  call void (i64, ptr, ...) @DebugPrint(i64 noundef 2147483648, ptr noundef @.str.2)
  br label %39

39:                                               ; preds = %38, %35
  br label %40

40:                                               ; preds = %39
  br label %41

41:                                               ; preds = %40
  br label %42

42:                                               ; preds = %41, %31
  br label %43

43:                                               ; preds = %42
  br label %44

44:                                               ; preds = %43
  br label %64

45:                                               ; preds = %23
  br label %46

46:                                               ; preds = %45
  %47 = call zeroext i8 @DebugPrintEnabled()
  %48 = icmp ne i8 %47, 0
  br i1 %48, label %49, label %61

49:                                               ; preds = %46
  br label %50

50:                                               ; preds = %49
  %51 = call zeroext i8 @DebugPrintLevelEnabled(i64 noundef 2147483648)
  %52 = icmp ne i8 %51, 0
  br i1 %52, label %53, label %58

53:                                               ; preds = %50
  %54 = load ptr, ptr %13, align 8, !tbaa !5
  %55 = getelementptr inbounds %struct.EFI_MTFTP4_ERROR_HEADER, ptr %54, i32 0, i32 1
  %56 = load i16, ptr %55, align 1, !tbaa !16
  %57 = zext i16 %56 to i32
  call void (i64, ptr, ...) @DebugPrint(i64 noundef 2147483648, ptr noundef @.str.3, i32 noundef %57)
  br label %58

58:                                               ; preds = %53, %50
  br label %59

59:                                               ; preds = %58
  br label %60

60:                                               ; preds = %59
  br label %61

61:                                               ; preds = %60, %46
  br label %62

62:                                               ; preds = %61
  br label %63

63:                                               ; preds = %62
  br label %64

64:                                               ; preds = %63, %44
  %65 = load ptr, ptr %10, align 8, !tbaa !5
  %66 = getelementptr inbounds %struct.MTFTP4_GETINFO_STATE, ptr %65, i32 0, i32 2
  store i64 -9223372036854775785, ptr %66, align 8, !tbaa !18
  br label %73

67:                                               ; preds = %4
  %68 = load ptr, ptr %10, align 8, !tbaa !5
  %69 = getelementptr inbounds %struct.MTFTP4_GETINFO_STATE, ptr %68, i32 0, i32 2
  store i64 0, ptr %69, align 8, !tbaa !18
  br label %73

70:                                               ; preds = %4
  %71 = load ptr, ptr %10, align 8, !tbaa !5
  %72 = getelementptr inbounds %struct.MTFTP4_GETINFO_STATE, ptr %71, i32 0, i32 2
  store i64 -9223372036854775784, ptr %72, align 8, !tbaa !18
  br label %73

73:                                               ; preds = %70, %67, %64
  %74 = load ptr, ptr @gBS, align 8, !tbaa !5
  %75 = getelementptr inbounds %struct.EFI_BOOT_SERVICES, ptr %74, i32 0, i32 6
  %76 = load ptr, ptr %75, align 8, !tbaa !20
  %77 = load i16, ptr %8, align 2, !tbaa !9
  %78 = zext i16 %77 to i64
  %79 = load ptr, ptr %10, align 8, !tbaa !5
  %80 = getelementptr inbounds %struct.MTFTP4_GETINFO_STATE, ptr %79, i32 0, i32 0
  %81 = load ptr, ptr %80, align 8, !tbaa !23
  %82 = call i64 %76(i32 noundef 4, i64 noundef %78, ptr noundef %81)
  store i64 %82, ptr %11, align 8, !tbaa !24
  %83 = load i64, ptr %11, align 8, !tbaa !24
  %84 = icmp slt i64 %83, 0
  br i1 %84, label %85, label %88

85:                                               ; preds = %73
  %86 = load ptr, ptr %10, align 8, !tbaa !5
  %87 = getelementptr inbounds %struct.MTFTP4_GETINFO_STATE, ptr %86, i32 0, i32 2
  store i64 -9223372036854775799, ptr %87, align 8, !tbaa !18
  store i64 -9223372036854775787, ptr %5, align 8
  store i32 1, ptr %14, align 4
  br label %102

88:                                               ; preds = %73
  %89 = load i16, ptr %8, align 2, !tbaa !9
  %90 = zext i16 %89 to i32
  %91 = load ptr, ptr %10, align 8, !tbaa !5
  %92 = getelementptr inbounds %struct.MTFTP4_GETINFO_STATE, ptr %91, i32 0, i32 1
  %93 = load ptr, ptr %92, align 8, !tbaa !25
  store i32 %90, ptr %93, align 4, !tbaa !26
  %94 = load ptr, ptr %10, align 8, !tbaa !5
  %95 = getelementptr inbounds %struct.MTFTP4_GETINFO_STATE, ptr %94, i32 0, i32 0
  %96 = load ptr, ptr %95, align 8, !tbaa !23
  %97 = load ptr, ptr %96, align 8, !tbaa !5
  %98 = load ptr, ptr %9, align 8, !tbaa !5
  %99 = load i16, ptr %8, align 2, !tbaa !9
  %100 = zext i16 %99 to i64
  %101 = call ptr @CopyMem(ptr noundef %97, ptr noundef %98, i64 noundef %100)
  store i64 -9223372036854775787, ptr %5, align 8
  store i32 1, ptr %14, align 4
  br label %102

102:                                              ; preds = %88, %85
  call void @llvm.lifetime.end.p0(i64 8, ptr %13) #3
  call void @llvm.lifetime.end.p0(i64 2, ptr %12) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #3
  %103 = load i64, ptr %5, align 8
  ret i64 %103
}

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

declare zeroext i8 @DebugPrintEnabled() #2

declare zeroext i8 @DebugPrintLevelEnabled(i64 noundef) #2

declare void @DebugPrint(i64 noundef, ptr noundef, ...) #2

declare ptr @CopyMem(ptr noundef, ptr noundef, i64 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 = !{!"short", !7, i64 0}
!11 = !{!12, !6, i64 72}
!12 = !{!"_EFI_MTFTP4_TOKEN", !13, i64 0, !6, i64 8, !6, i64 16, !6, i64 24, !6, i64 32, !14, i64 40, !6, i64 48, !13, i64 56, !6, i64 64, !6, i64 72, !6, i64 80, !6, i64 88, !6, i64 96}
!13 = !{!"long long", !7, i64 0}
!14 = !{!"int", !7, i64 0}
!15 = !{!7, !7, i64 0}
!16 = !{!17, !10, i64 2}
!17 = !{!"", !10, i64 0, !10, i64 2, !7, i64 4}
!18 = !{!19, !13, i64 16}
!19 = !{!"", !6, i64 0, !6, i64 8, !13, i64 16}
!20 = !{!21, !6, i64 64}
!21 = !{!"", !22, 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}
!22 = !{!"", !13, i64 0, !14, i64 8, !14, i64 12, !14, i64 16, !14, i64 20}
!23 = !{!19, !6, i64 0}
!24 = !{!13, !13, i64 0}
!25 = !{!19, !6, i64 8}
!26 = !{!14, !14, 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"

@gBS = external local_unnamed_addr global ptr, align 8
@.str.2 = external hidden unnamed_addr constant [36 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [20 x i8], align 1

; Function Attrs: nounwind uwtable
define dso_local noundef i64 @Mtftp4GetInfoCheckPacket(ptr nocapture noundef readnone %0, ptr nocapture noundef readonly %1, i16 noundef zeroext %2, ptr noundef %3) local_unnamed_addr #0 {
  %5 = getelementptr inbounds i8, ptr %1, i64 72
  %6 = load ptr, ptr %5, align 8, !tbaa !5
  %7 = load i16, ptr %3, align 1, !tbaa !12
  %8 = tail call zeroext i16 @SwapBytes16(i16 noundef zeroext %7) #2
  switch i16 %8, label %24 [
    i16 5, label %9
    i16 6, label %25
  ]

9:                                                ; preds = %4
  %10 = getelementptr inbounds i8, ptr %3, i64 2
  %11 = load i16, ptr %10, align 1, !tbaa !13
  %12 = icmp eq i16 %11, 1
  %13 = tail call zeroext i8 @DebugPrintEnabled() #2
  %.not19 = icmp eq i8 %13, 0
  br i1 %12, label %14, label %18

14:                                               ; preds = %9
  br i1 %.not19, label %25, label %15

15:                                               ; preds = %14
  %16 = tail call zeroext i8 @DebugPrintLevelEnabled(i64 noundef 2147483648) #2
  %.not20 = icmp eq i8 %16, 0
  br i1 %.not20, label %25, label %17

17:                                               ; preds = %15
  tail call void (i64, ptr, ...) @DebugPrint(i64 noundef 2147483648, ptr noundef nonnull @.str.2) #2
  br label %25

18:                                               ; preds = %9
  br i1 %.not19, label %25, label %19

19:                                               ; preds = %18
  %20 = tail call zeroext i8 @DebugPrintLevelEnabled(i64 noundef 2147483648) #2
  %.not18 = icmp eq i8 %20, 0
  br i1 %.not18, label %25, label %21

21:                                               ; preds = %19
  %22 = load i16, ptr %10, align 1, !tbaa !13
  %23 = zext i16 %22 to i32
  tail call void (i64, ptr, ...) @DebugPrint(i64 noundef 2147483648, ptr noundef nonnull @.str.3, i32 noundef %23) #2
  br label %25

24:                                               ; preds = %4
  br label %25

25:                                               ; preds = %4, %15, %17, %14, %19, %21, %18, %24
  %.sink = phi i64 [ -9223372036854775784, %24 ], [ -9223372036854775785, %18 ], [ -9223372036854775785, %21 ], [ -9223372036854775785, %19 ], [ -9223372036854775785, %14 ], [ -9223372036854775785, %17 ], [ -9223372036854775785, %15 ], [ 0, %4 ]
  %26 = getelementptr inbounds i8, ptr %6, i64 16
  store i64 %.sink, ptr %26, align 8, !tbaa !16
  %27 = load ptr, ptr @gBS, align 8, !tbaa !18
  %28 = getelementptr inbounds i8, ptr %27, i64 64
  %29 = load ptr, ptr %28, align 8, !tbaa !19
  %30 = zext i16 %2 to i64
  %31 = load ptr, ptr %6, align 8, !tbaa !22
  %32 = tail call i64 %29(i32 noundef 4, i64 noundef %30, ptr noundef %31) #2
  %33 = icmp slt i64 %32, 0
  br i1 %33, label %34, label %36

34:                                               ; preds = %25
  %35 = getelementptr inbounds i8, ptr %6, i64 16
  store i64 -9223372036854775799, ptr %35, align 8, !tbaa !16
  br label %43

36:                                               ; preds = %25
  %37 = zext i16 %2 to i32
  %38 = getelementptr inbounds i8, ptr %6, i64 8
  %39 = load ptr, ptr %38, align 8, !tbaa !23
  store i32 %37, ptr %39, align 4, !tbaa !24
  %40 = load ptr, ptr %6, align 8, !tbaa !22
  %41 = load ptr, ptr %40, align 8, !tbaa !18
  %42 = tail call ptr @CopyMem(ptr noundef %41, ptr noundef nonnull %3, i64 noundef %30) #2
  br label %43

43:                                               ; preds = %36, %34
  ret i64 -9223372036854775787
}

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

declare zeroext i8 @DebugPrintEnabled() local_unnamed_addr #1

declare zeroext i8 @DebugPrintLevelEnabled(i64 noundef) local_unnamed_addr #1

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

declare ptr @CopyMem(ptr noundef, ptr noundef, i64 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, !10, i64 72}
!6 = !{!"_EFI_MTFTP4_TOKEN", !7, i64 0, !10, i64 8, !10, i64 16, !10, i64 24, !10, i64 32, !11, i64 40, !10, i64 48, !7, i64 56, !10, i64 64, !10, i64 72, !10, i64 80, !10, i64 88, !10, i64 96}
!7 = !{!"long long", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"any pointer", !8, i64 0}
!11 = !{!"int", !8, i64 0}
!12 = !{!8, !8, i64 0}
!13 = !{!14, !15, i64 2}
!14 = !{!"", !15, i64 0, !15, i64 2, !8, i64 4}
!15 = !{!"short", !8, i64 0}
!16 = !{!17, !7, i64 16}
!17 = !{!"", !10, i64 0, !10, i64 8, !7, i64 16}
!18 = !{!10, !10, i64 0}
!19 = !{!20, !10, i64 64}
!20 = !{!"", !21, 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}
!21 = !{!"", !7, i64 0, !11, i64 8, !11, i64 12, !11, i64 16, !11, i64 20}
!22 = !{!17, !10, i64 0}
!23 = !{!17, !10, i64 8}
!24 = !{!11, !11, i64 0}


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