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

; 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._TCP_CB = type { %struct._LIST_ENTRY, ptr, ptr, %struct._TCP_PEER, %struct._TCP_PEER, %struct._LIST_ENTRY, %struct._LIST_ENTRY, i32, i32, i8, i8, i16, i32, i32, i32, i32, i32, i32, i32, i32, i32, i16, i32, i32, i32, i32, i32, i16, i16, [6 x i32], i32, i32, i32, i8, i8, i8, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i16, i8, i8, i32, i32, i32, i8, i8, i16, i32, i32, i32, i8, i8, i8, %struct.EFI_IPv4_ADDRESS, ptr }
%struct._TCP_PEER = type { i32, i16 }
%struct._LIST_ENTRY = type { ptr, ptr }
%struct.EFI_IPv4_ADDRESS = type { [4 x i8] }

@.str.26 = external hidden unnamed_addr constant [66 x i8], align 1
@.str.27 = external hidden unnamed_addr constant [70 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

declare zeroext i8 @DebugPrintEnabled() #1

declare zeroext i8 @DebugPrintLevelEnabled(i64 noundef) #1

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

; Function Attrs: nounwind uwtable
define dso_local void @TcpOnAppConsume(ptr noundef %0) #2 {
  %2 = alloca ptr, align 8
  %3 = alloca i32, align 4
  %4 = alloca i32, align 4
  store ptr %0, ptr %2, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #3
  %5 = load ptr, ptr %2, align 8, !tbaa !5
  %6 = getelementptr inbounds %struct._TCP_CB, ptr %5, i32 0, i32 9
  %7 = load i8, ptr %6, align 8, !tbaa !9
  %8 = zext i8 %7 to i32
  switch i32 %8, label %72 [
    i32 0, label %9
    i32 1, label %10
    i32 2, label %11
    i32 3, label %11
    i32 4, label %12
    i32 9, label %70
    i32 5, label %71
    i32 6, label %71
    i32 7, label %71
    i32 10, label %71
    i32 8, label %71
  ]

9:                                                ; preds = %1
  store i32 1, ptr %4, align 4
  br label %74

10:                                               ; preds = %1
  store i32 1, ptr %4, align 4
  br label %74

11:                                               ; preds = %1, %1
  store i32 1, ptr %4, align 4
  br label %74

12:                                               ; preds = %1
  %13 = load ptr, ptr %2, align 8, !tbaa !5
  %14 = call i32 @TcpRcvWinOld(ptr noundef %13)
  store i32 %14, ptr %3, align 4, !tbaa !16
  %15 = load ptr, ptr %2, align 8, !tbaa !5
  %16 = call i32 @TcpRcvWinNow(ptr noundef %15)
  %17 = load i32, ptr %3, align 4, !tbaa !16
  %18 = icmp ugt i32 %16, %17
  br i1 %18, label %19, label %69

19:                                               ; preds = %12
  %20 = load i32, ptr %3, align 4, !tbaa !16
  %21 = load ptr, ptr %2, align 8, !tbaa !5
  %22 = getelementptr inbounds %struct._TCP_CB, ptr %21, i32 0, i32 27
  %23 = load i16, ptr %22, align 8, !tbaa !17
  %24 = zext i16 %23 to i32
  %25 = icmp ult i32 %20, %24
  br i1 %25, label %26, label %43

26:                                               ; preds = %19
  br label %27

27:                                               ; preds = %26
  %28 = call zeroext i8 @DebugPrintEnabled()
  %29 = icmp ne i8 %28, 0
  br i1 %29, label %30, label %39

30:                                               ; preds = %27
  br label %31

31:                                               ; preds = %30
  %32 = call zeroext i8 @DebugPrintLevelEnabled(i64 noundef 64)
  %33 = icmp ne i8 %32, 0
  br i1 %33, label %34, label %36

34:                                               ; preds = %31
  %35 = load ptr, ptr %2, align 8, !tbaa !5
  call void (i64, ptr, ...) @DebugPrint(i64 noundef 64, ptr noundef @.str.26, ptr noundef %35)
  br label %36

36:                                               ; preds = %34, %31
  br label %37

37:                                               ; preds = %36
  br label %38

38:                                               ; preds = %37
  br label %39

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

40:                                               ; preds = %39
  br label %41

41:                                               ; preds = %40
  %42 = load ptr, ptr %2, align 8, !tbaa !5
  call void @TcpSendAck(ptr noundef %42)
  br label %68

43:                                               ; preds = %19
  %44 = load ptr, ptr %2, align 8, !tbaa !5
  %45 = getelementptr inbounds %struct._TCP_CB, ptr %44, i32 0, i32 10
  %46 = load i8, ptr %45, align 1, !tbaa !18
  %47 = zext i8 %46 to i32
  %48 = icmp eq i32 %47, 0
  br i1 %48, label %49, label %67

49:                                               ; preds = %43
  br label %50

50:                                               ; preds = %49
  %51 = call zeroext i8 @DebugPrintEnabled()
  %52 = icmp ne i8 %51, 0
  br i1 %52, label %53, label %62

53:                                               ; preds = %50
  br label %54

54:                                               ; preds = %53
  %55 = call zeroext i8 @DebugPrintLevelEnabled(i64 noundef 64)
  %56 = icmp ne i8 %55, 0
  br i1 %56, label %57, label %59

57:                                               ; preds = %54
  %58 = load ptr, ptr %2, align 8, !tbaa !5
  call void (i64, ptr, ...) @DebugPrint(i64 noundef 64, ptr noundef @.str.27, ptr noundef %58)
  br label %59

59:                                               ; preds = %57, %54
  br label %60

60:                                               ; preds = %59
  br label %61

61:                                               ; preds = %60
  br label %62

62:                                               ; preds = %61, %50
  br label %63

63:                                               ; preds = %62
  br label %64

64:                                               ; preds = %63
  %65 = load ptr, ptr %2, align 8, !tbaa !5
  %66 = getelementptr inbounds %struct._TCP_CB, ptr %65, i32 0, i32 10
  store i8 1, ptr %66, align 1, !tbaa !18
  br label %67

67:                                               ; preds = %64, %43
  br label %68

68:                                               ; preds = %67, %41
  br label %69

69:                                               ; preds = %68, %12
  br label %73

70:                                               ; preds = %1
  store i32 1, ptr %4, align 4
  br label %74

71:                                               ; preds = %1, %1, %1, %1, %1
  store i32 1, ptr %4, align 4
  br label %74

72:                                               ; preds = %1
  br label %73

73:                                               ; preds = %72, %69
  store i32 0, ptr %4, align 4
  br label %74

74:                                               ; preds = %73, %71, %70, %11, %10, %9
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #3
  %75 = load i32, ptr %4, align 4
  switch i32 %75, label %77 [
    i32 0, label %76
    i32 1, label %76
  ]

76:                                               ; preds = %74, %74
  ret void

77:                                               ; preds = %74
  unreachable
}

declare i32 @TcpRcvWinOld(ptr noundef) #1

declare i32 @TcpRcvWinNow(ptr noundef) #1

declare void @TcpSendAck(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, !7, i64 88}
!10 = !{!"_TCP_CB", !11, i64 0, !6, i64 16, !6, i64 24, !12, i64 32, !12, i64 40, !11, i64 48, !11, i64 64, !13, i64 80, !13, i64 84, !7, i64 88, !7, i64 89, !14, i64 90, !13, i64 92, !13, i64 96, !13, i64 100, !13, i64 104, !13, i64 108, !13, i64 112, !13, i64 116, !13, i64 120, !13, i64 124, !14, i64 128, !13, i64 132, !13, i64 136, !13, i64 140, !13, i64 144, !13, i64 148, !14, i64 152, !14, i64 154, !7, i64 156, !13, i64 180, !13, i64 184, !13, i64 188, !7, i64 192, !7, i64 193, !7, i64 194, !13, i64 196, !13, i64 200, !13, i64 204, !13, i64 208, !13, i64 212, !13, i64 216, !13, i64 220, !13, i64 224, !13, i64 228, !13, i64 232, !14, i64 236, !7, i64 238, !7, i64 239, !13, i64 240, !13, i64 244, !13, i64 248, !7, i64 252, !7, i64 253, !14, i64 254, !13, i64 256, !13, i64 260, !13, i64 264, !7, i64 268, !7, i64 269, !7, i64 270, !15, i64 271, !6, i64 280}
!11 = !{!"_LIST_ENTRY", !6, i64 0, !6, i64 8}
!12 = !{!"_TCP_PEER", !13, i64 0, !14, i64 4}
!13 = !{!"int", !7, i64 0}
!14 = !{!"short", !7, i64 0}
!15 = !{!"", !7, i64 0}
!16 = !{!13, !13, i64 0}
!17 = !{!10, !14, i64 152}
!18 = !{!10, !7, i64 89}


; 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.26 = external hidden unnamed_addr constant [66 x i8], align 1
@.str.27 = external hidden unnamed_addr constant [70 x i8], align 1

declare zeroext i8 @DebugPrintEnabled() local_unnamed_addr #0

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

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

; Function Attrs: nounwind uwtable
define dso_local void @TcpOnAppConsume(ptr noundef %0) local_unnamed_addr #1 {
  %2 = getelementptr inbounds i8, ptr %0, i64 88
  %3 = load i8, ptr %2, align 8, !tbaa !5
  %cond = icmp eq i8 %3, 4
  br i1 %cond, label %4, label %29

4:                                                ; preds = %1
  %5 = tail call i32 @TcpRcvWinOld(ptr noundef nonnull %0) #2
  %6 = tail call i32 @TcpRcvWinNow(ptr noundef nonnull %0) #2
  %7 = icmp ugt i32 %6, %5
  br i1 %7, label %8, label %29

8:                                                ; preds = %4
  %9 = getelementptr inbounds i8, ptr %0, i64 152
  %10 = load i16, ptr %9, align 8, !tbaa !15
  %11 = zext i16 %10 to i32
  %12 = icmp ult i32 %5, %11
  br i1 %12, label %13, label %19

13:                                               ; preds = %8
  %14 = tail call zeroext i8 @DebugPrintEnabled() #2
  %.not11 = icmp eq i8 %14, 0
  br i1 %.not11, label %18, label %15

15:                                               ; preds = %13
  %16 = tail call zeroext i8 @DebugPrintLevelEnabled(i64 noundef 64) #2
  %.not12 = icmp eq i8 %16, 0
  br i1 %.not12, label %18, label %17

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

18:                                               ; preds = %15, %17, %13
  tail call void @TcpSendAck(ptr noundef nonnull %0) #2
  br label %29

19:                                               ; preds = %8
  %20 = getelementptr inbounds i8, ptr %0, i64 89
  %21 = load i8, ptr %20, align 1, !tbaa !16
  %22 = icmp eq i8 %21, 0
  br i1 %22, label %23, label %29

23:                                               ; preds = %19
  %24 = tail call zeroext i8 @DebugPrintEnabled() #2
  %.not = icmp eq i8 %24, 0
  br i1 %.not, label %28, label %25

25:                                               ; preds = %23
  %26 = tail call zeroext i8 @DebugPrintLevelEnabled(i64 noundef 64) #2
  %.not10 = icmp eq i8 %26, 0
  br i1 %.not10, label %28, label %27

27:                                               ; preds = %25
  tail call void (i64, ptr, ...) @DebugPrint(i64 noundef 64, ptr noundef nonnull @.str.27, ptr noundef nonnull %0) #2
  br label %28

28:                                               ; preds = %25, %27, %23
  store i8 1, ptr %20, align 1, !tbaa !16
  br label %29

29:                                               ; preds = %1, %18, %28, %19, %4
  ret void
}

declare i32 @TcpRcvWinOld(ptr noundef) local_unnamed_addr #0

declare i32 @TcpRcvWinNow(ptr noundef) local_unnamed_addr #0

declare void @TcpSendAck(ptr noundef) local_unnamed_addr #0

attributes #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 = { 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 = { 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, !9, i64 88}
!6 = !{!"_TCP_CB", !7, i64 0, !8, i64 16, !8, i64 24, !11, i64 32, !11, i64 40, !7, i64 48, !7, i64 64, !12, i64 80, !12, i64 84, !9, i64 88, !9, i64 89, !13, i64 90, !12, i64 92, !12, i64 96, !12, i64 100, !12, i64 104, !12, i64 108, !12, i64 112, !12, i64 116, !12, i64 120, !12, i64 124, !13, i64 128, !12, i64 132, !12, i64 136, !12, i64 140, !12, i64 144, !12, i64 148, !13, i64 152, !13, i64 154, !9, i64 156, !12, i64 180, !12, i64 184, !12, i64 188, !9, i64 192, !9, i64 193, !9, i64 194, !12, i64 196, !12, i64 200, !12, i64 204, !12, i64 208, !12, i64 212, !12, i64 216, !12, i64 220, !12, i64 224, !12, i64 228, !12, i64 232, !13, i64 236, !9, i64 238, !9, i64 239, !12, i64 240, !12, i64 244, !12, i64 248, !9, i64 252, !9, i64 253, !13, i64 254, !12, i64 256, !12, i64 260, !12, i64 264, !9, i64 268, !9, i64 269, !9, i64 270, !14, i64 271, !8, i64 280}
!7 = !{!"_LIST_ENTRY", !8, i64 0, !8, i64 8}
!8 = !{!"any pointer", !9, i64 0}
!9 = !{!"omnipotent char", !10, i64 0}
!10 = !{!"Simple C/C++ TBAA"}
!11 = !{!"_TCP_PEER", !12, i64 0, !13, i64 4}
!12 = !{!"int", !9, i64 0}
!13 = !{!"short", !9, i64 0}
!14 = !{!"", !9, i64 0}
!15 = !{!6, !13, i64 152}
!16 = !{!6, !9, i64 89}


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