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

; 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._SOCKET = type { i32, ptr, ptr, ptr, ptr, %struct._LIST_ENTRY, i8, i32, i8, i16, %struct.EFI_LOCK, %struct._SOCK_BUFFER, %struct._SOCK_BUFFER, i64, i8, i32, i32, ptr, %struct._LIST_ENTRY, %struct._LIST_ENTRY, %struct._LIST_ENTRY, %struct._LIST_ENTRY, %struct._LIST_ENTRY, ptr, ptr, ptr, [20 x i8], %union._NET_PROTOCOL, ptr, ptr, ptr }
%struct.EFI_LOCK = type { i64, i64, i32 }
%struct._SOCK_BUFFER = type { i32, i32, ptr }
%struct._LIST_ENTRY = type { ptr, ptr }
%union._NET_PROTOCOL = type { %struct._EFI_TCP4_PROTOCOL }
%struct._EFI_TCP4_PROTOCOL = type { ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr }
%struct._SOCK_IO_TOKEN = type { %struct._SOCK_COMPLETION_TOKEN, %union.SOCK_IO_DATA }
%struct._SOCK_COMPLETION_TOKEN = type { ptr, i64 }
%union.SOCK_IO_DATA = type { ptr }
%struct.EFI_TCP4_RECEIVE_DATA = type { i8, i32, i32, [1 x %struct.EFI_TCP4_FRAGMENT_DATA] }
%struct.EFI_TCP4_FRAGMENT_DATA = type { i32, ptr }
%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 }

@.str = external hidden unnamed_addr constant [151 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [21 x i8], align 1
@.str.5 = external hidden unnamed_addr constant [25 x i8], align 1
@gBS = external global ptr, align 8

; Function Attrs: nounwind uwtable
declare dso_local i32 @SockTcpDataToRcv(ptr noundef, ptr noundef, i32 noundef) #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

; 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
declare dso_local void @SockSetTcpRxData(ptr noundef, ptr noundef, i32 noundef, i8 noundef zeroext) #0

; Function Attrs: nounwind uwtable
define dso_local i32 @SockProcessRcvToken(ptr noundef %0, ptr noundef %1) #0 {
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca i32, align 4
  %6 = alloca ptr, align 8
  %7 = alloca i8, align 1
  store ptr %0, ptr %3, align 8, !tbaa !5
  store ptr %1, ptr %4, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #3
  call void @llvm.lifetime.start.p0(i64 1, ptr %7) #3
  br label %8

8:                                                ; preds = %2
  %9 = call zeroext i8 @DebugAssertEnabled()
  %10 = icmp ne i8 %9, 0
  br i1 %10, label %11, label %16

11:                                               ; preds = %8
  %12 = load ptr, ptr %3, align 8, !tbaa !5
  %13 = icmp ne ptr %12, null
  br i1 %13, label %15, label %14

14:                                               ; preds = %11
  call void @DebugAssert(ptr noundef @.str, i64 noundef 217, ptr noundef @.str.4)
  br label %15

15:                                               ; preds = %14, %11
  br label %16

16:                                               ; preds = %15, %8
  br label %17

17:                                               ; preds = %16
  br label %18

18:                                               ; preds = %17
  br label %19

19:                                               ; preds = %18
  %20 = call zeroext i8 @DebugAssertEnabled()
  %21 = icmp ne i8 %20, 0
  br i1 %21, label %22, label %29

22:                                               ; preds = %19
  %23 = load ptr, ptr %3, align 8, !tbaa !5
  %24 = getelementptr inbounds %struct._SOCKET, ptr %23, i32 0, i32 7
  %25 = load i32, ptr %24, align 4, !tbaa !9
  %26 = icmp eq i32 1, %25
  br i1 %26, label %28, label %27

27:                                               ; preds = %22
  call void @DebugAssert(ptr noundef @.str, i64 noundef 219, ptr noundef @.str.5)
  br label %28

28:                                               ; preds = %27, %22
  br label %29

29:                                               ; preds = %28, %19
  br label %30

30:                                               ; preds = %29
  br label %31

31:                                               ; preds = %30
  %32 = load ptr, ptr %4, align 8, !tbaa !5
  %33 = getelementptr inbounds %struct._SOCK_IO_TOKEN, ptr %32, i32 0, i32 1
  %34 = load ptr, ptr %33, align 8, !tbaa !17
  store ptr %34, ptr %6, align 8, !tbaa !5
  %35 = load ptr, ptr %3, align 8, !tbaa !5
  %36 = getelementptr inbounds %struct._SOCKET, ptr %35, i32 0, i32 12
  %37 = load ptr, ptr %6, align 8, !tbaa !5
  %38 = getelementptr inbounds %struct.EFI_TCP4_RECEIVE_DATA, ptr %37, i32 0, i32 1
  %39 = load i32, ptr %38, align 4, !tbaa !18
  %40 = call i32 @SockTcpDataToRcv(ptr noundef %36, ptr noundef %7, i32 noundef %39)
  store i32 %40, ptr %5, align 4, !tbaa !20
  %41 = load ptr, ptr %3, align 8, !tbaa !5
  %42 = load ptr, ptr %6, align 8, !tbaa !5
  %43 = load i32, ptr %5, align 4, !tbaa !20
  %44 = load i8, ptr %7, align 1, !tbaa !17
  call void @SockSetTcpRxData(ptr noundef %41, ptr noundef %42, i32 noundef %43, i8 noundef zeroext %44)
  %45 = load ptr, ptr %3, align 8, !tbaa !5
  %46 = getelementptr inbounds %struct._SOCKET, ptr %45, i32 0, i32 12
  %47 = getelementptr inbounds %struct._SOCK_BUFFER, ptr %46, i32 0, i32 2
  %48 = load ptr, ptr %47, align 8, !tbaa !21
  %49 = load i32, ptr %5, align 4, !tbaa !20
  %50 = call i32 @NetbufQueTrim(ptr noundef %48, i32 noundef %49)
  br label %51

51:                                               ; preds = %31
  %52 = load ptr, ptr %4, align 8, !tbaa !5
  %53 = getelementptr inbounds %struct._SOCK_IO_TOKEN, ptr %52, i32 0, i32 0
  %54 = getelementptr inbounds %struct._SOCK_COMPLETION_TOKEN, ptr %53, i32 0, i32 1
  store i64 0, ptr %54, align 8, !tbaa !22
  %55 = load ptr, ptr @gBS, align 8, !tbaa !5
  %56 = getelementptr inbounds %struct.EFI_BOOT_SERVICES, ptr %55, i32 0, i32 11
  %57 = load ptr, ptr %56, align 8, !tbaa !25
  %58 = load ptr, ptr %4, align 8, !tbaa !5
  %59 = getelementptr inbounds %struct._SOCK_IO_TOKEN, ptr %58, i32 0, i32 0
  %60 = getelementptr inbounds %struct._SOCK_COMPLETION_TOKEN, ptr %59, i32 0, i32 0
  %61 = load ptr, ptr %60, align 8, !tbaa !28
  %62 = call i64 %57(ptr noundef %61)
  br label %63

63:                                               ; preds = %51
  br label %64

64:                                               ; preds = %63
  %65 = load i32, ptr %5, align 4, !tbaa !20
  call void @llvm.lifetime.end.p0(i64 1, ptr %7) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #3
  ret i32 %65
}

declare i32 @NetbufQueTrim(ptr noundef, i32 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, !11, i64 60}
!10 = !{!"_SOCKET", !11, i64 0, !6, i64 8, !6, i64 16, !6, i64 24, !6, i64 32, !12, i64 40, !7, i64 56, !11, i64 60, !7, i64 64, !13, i64 66, !14, i64 72, !16, i64 96, !16, i64 112, !15, i64 128, !7, i64 136, !11, i64 140, !11, i64 144, !6, i64 152, !12, i64 160, !12, i64 176, !12, i64 192, !12, i64 208, !12, i64 224, !6, i64 240, !6, i64 248, !6, i64 256, !7, i64 264, !7, i64 288, !6, i64 368, !6, i64 376, !6, i64 384}
!11 = !{!"int", !7, i64 0}
!12 = !{!"_LIST_ENTRY", !6, i64 0, !6, i64 8}
!13 = !{!"short", !7, i64 0}
!14 = !{!"", !15, i64 0, !15, i64 8, !11, i64 16}
!15 = !{!"long long", !7, i64 0}
!16 = !{!"_SOCK_BUFFER", !11, i64 0, !11, i64 4, !6, i64 8}
!17 = !{!7, !7, i64 0}
!18 = !{!19, !11, i64 4}
!19 = !{!"", !7, i64 0, !11, i64 4, !11, i64 8, !7, i64 16}
!20 = !{!11, !11, i64 0}
!21 = !{!10, !6, i64 120}
!22 = !{!23, !15, i64 8}
!23 = !{!"_SOCK_IO_TOKEN", !24, i64 0, !7, i64 16}
!24 = !{!"_SOCK_COMPLETION_TOKEN", !6, i64 0, !15, i64 8}
!25 = !{!26, !6, i64 104}
!26 = !{!"", !27, 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}
!27 = !{!"", !15, i64 0, !11, i64 8, !11, i64 12, !11, i64 16, !11, i64 20}
!28 = !{!23, !6, 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 [151 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [21 x i8], align 1
@.str.5 = external hidden unnamed_addr constant [25 x i8], align 1
@gBS = external local_unnamed_addr global ptr, align 8

; Function Attrs: nounwind uwtable
declare dso_local i32 @SockTcpDataToRcv(ptr noundef, ptr noundef, i32 noundef) 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

; 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
declare dso_local void @SockSetTcpRxData(ptr noundef, ptr noundef, i32 noundef, i8 noundef zeroext) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local noundef i32 @SockProcessRcvToken(ptr noundef %0, ptr nocapture noundef %1) local_unnamed_addr #0 {
  %3 = alloca i8, align 1
  call void @llvm.lifetime.start.p0(i64 1, ptr nonnull %3) #3
  %4 = tail call zeroext i8 @DebugAssertEnabled() #3
  %5 = icmp eq i8 %4, 0
  %6 = icmp ne ptr %0, null
  %or.cond = or i1 %6, %5
  br i1 %or.cond, label %8, label %7

7:                                                ; preds = %2
  tail call void @DebugAssert(ptr noundef nonnull @.str, i64 noundef 217, ptr noundef nonnull @.str.4) #3
  br label %8

8:                                                ; preds = %2, %7
  %9 = tail call zeroext i8 @DebugAssertEnabled() #3
  %.not = icmp eq i8 %9, 0
  br i1 %.not, label %15, label %10

10:                                               ; preds = %8
  %11 = getelementptr inbounds i8, ptr %0, i64 60
  %12 = load i32, ptr %11, align 4, !tbaa !5
  %13 = icmp eq i32 %12, 1
  br i1 %13, label %15, label %14

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

15:                                               ; preds = %10, %14, %8
  %16 = getelementptr inbounds i8, ptr %1, i64 16
  %17 = load ptr, ptr %16, align 8, !tbaa !16
  %18 = getelementptr inbounds i8, ptr %0, i64 112
  %19 = getelementptr inbounds i8, ptr %17, i64 4
  %20 = load i32, ptr %19, align 4, !tbaa !17
  %21 = call i32 @SockTcpDataToRcv(ptr noundef nonnull %18, ptr noundef nonnull %3, i32 noundef %20)
  %22 = load i8, ptr %3, align 1, !tbaa !16
  call void @SockSetTcpRxData(ptr noundef %0, ptr noundef %17, i32 noundef %21, i8 noundef zeroext %22)
  %23 = getelementptr inbounds i8, ptr %0, i64 120
  %24 = load ptr, ptr %23, align 8, !tbaa !19
  %25 = call i32 @NetbufQueTrim(ptr noundef %24, i32 noundef %21) #3
  %26 = getelementptr inbounds i8, ptr %1, i64 8
  store i64 0, ptr %26, align 8, !tbaa !20
  %27 = load ptr, ptr @gBS, align 8, !tbaa !23
  %28 = getelementptr inbounds i8, ptr %27, i64 104
  %29 = load ptr, ptr %28, align 8, !tbaa !24
  %30 = load ptr, ptr %1, align 8, !tbaa !27
  %31 = call i64 %29(ptr noundef %30) #3
  call void @llvm.lifetime.end.p0(i64 1, ptr nonnull %3) #3
  ret i32 %21
}

declare i32 @NetbufQueTrim(ptr noundef, i32 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, !7, i64 60}
!6 = !{!"_SOCKET", !7, i64 0, !10, i64 8, !10, i64 16, !10, i64 24, !10, i64 32, !11, i64 40, !8, i64 56, !7, i64 60, !8, i64 64, !12, i64 66, !13, i64 72, !15, i64 96, !15, i64 112, !14, i64 128, !8, i64 136, !7, i64 140, !7, i64 144, !10, i64 152, !11, i64 160, !11, i64 176, !11, i64 192, !11, i64 208, !11, i64 224, !10, i64 240, !10, i64 248, !10, i64 256, !8, i64 264, !8, i64 288, !10, i64 368, !10, i64 376, !10, i64 384}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"any pointer", !8, i64 0}
!11 = !{!"_LIST_ENTRY", !10, i64 0, !10, i64 8}
!12 = !{!"short", !8, i64 0}
!13 = !{!"", !14, i64 0, !14, i64 8, !7, i64 16}
!14 = !{!"long long", !8, i64 0}
!15 = !{!"_SOCK_BUFFER", !7, i64 0, !7, i64 4, !10, i64 8}
!16 = !{!8, !8, i64 0}
!17 = !{!18, !7, i64 4}
!18 = !{!"", !8, i64 0, !7, i64 4, !7, i64 8, !8, i64 16}
!19 = !{!6, !10, i64 120}
!20 = !{!21, !14, i64 8}
!21 = !{!"_SOCK_IO_TOKEN", !22, i64 0, !8, i64 16}
!22 = !{!"_SOCK_COMPLETION_TOKEN", !10, i64 0, !14, i64 8}
!23 = !{!10, !10, i64 0}
!24 = !{!25, !10, i64 104}
!25 = !{!"", !26, 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}
!26 = !{!"", !14, i64 0, !7, i64 8, !7, i64 12, !7, i64 16, !7, i64 20}
!27 = !{!21, !10, i64 0}


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