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

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

@mTcpRunQue = external dso_local global %struct._LIST_ENTRY, align 8
@mTcpListenQue = external dso_local global %struct._LIST_ENTRY, align 8
@.str.11 = external hidden unnamed_addr constant [151 x i8], align 1
@.str.14 = external hidden unnamed_addr constant [38 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 i8 @DebugAssertEnabled() #1

declare void @DebugAssert(ptr noundef, i64 noundef, 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
define dso_local zeroext i8 @TcpFindTcbByPeer(ptr noundef %0, i16 noundef zeroext %1) #2 {
  %3 = alloca i8, align 1
  %4 = alloca ptr, align 8
  %5 = alloca i16, align 2
  %6 = alloca i16, align 2
  %7 = alloca ptr, align 8
  %8 = alloca ptr, align 8
  %9 = alloca i32, align 4
  store ptr %0, ptr %4, align 8, !tbaa !5
  store i16 %1, ptr %5, align 2, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 2, ptr %6) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #3
  br label %10

10:                                               ; preds = %2
  %11 = call zeroext i8 @DebugAssertEnabled()
  %12 = icmp ne i8 %11, 0
  br i1 %12, label %13, label %22

13:                                               ; preds = %10
  %14 = load ptr, ptr %4, align 8, !tbaa !5
  %15 = icmp ne ptr %14, null
  br i1 %15, label %16, label %20

16:                                               ; preds = %13
  %17 = load i16, ptr %5, align 2, !tbaa !9
  %18 = zext i16 %17 to i32
  %19 = icmp ne i32 %18, 0
  br i1 %19, label %21, label %20

20:                                               ; preds = %16, %13
  call void @DebugAssert(ptr noundef @.str.11, i64 noundef 254, ptr noundef @.str.14)
  br label %21

21:                                               ; preds = %20, %16
  br label %22

22:                                               ; preds = %21, %10
  br label %23

23:                                               ; preds = %22
  br label %24

24:                                               ; preds = %23
  %25 = load i16, ptr %5, align 2, !tbaa !9
  %26 = call zeroext i16 @SwapBytes16(i16 noundef zeroext %25)
  store i16 %26, ptr %6, align 2, !tbaa !9
  %27 = load ptr, ptr @mTcpListenQue, align 8, !tbaa !11
  store ptr %27, ptr %7, align 8, !tbaa !5
  br label %28

28:                                               ; preds = %53, %24
  %29 = load ptr, ptr %7, align 8, !tbaa !5
  %30 = icmp ne ptr %29, @mTcpListenQue
  br i1 %30, label %31, label %57

31:                                               ; preds = %28
  %32 = load ptr, ptr %7, align 8, !tbaa !5
  %33 = ptrtoint ptr %32 to i64
  %34 = sub i64 %33, 0
  %35 = inttoptr i64 %34 to ptr
  store ptr %35, ptr %8, align 8, !tbaa !5
  %36 = load ptr, ptr %4, align 8, !tbaa !5
  %37 = load ptr, ptr %8, align 8, !tbaa !5
  %38 = getelementptr inbounds %struct._TCP_CB, ptr %37, i32 0, i32 3
  %39 = getelementptr inbounds %struct._TCP_PEER, ptr %38, i32 0, i32 0
  %40 = call i64 @CompareMem(ptr noundef %36, ptr noundef %39, i64 noundef 4)
  %41 = icmp eq i64 %40, 0
  br i1 %41, label %42, label %52

42:                                               ; preds = %31
  %43 = load i16, ptr %6, align 2, !tbaa !9
  %44 = zext i16 %43 to i32
  %45 = load ptr, ptr %8, align 8, !tbaa !5
  %46 = getelementptr inbounds %struct._TCP_CB, ptr %45, i32 0, i32 3
  %47 = getelementptr inbounds %struct._TCP_PEER, ptr %46, i32 0, i32 1
  %48 = load i16, ptr %47, align 4, !tbaa !13
  %49 = zext i16 %48 to i32
  %50 = icmp eq i32 %44, %49
  br i1 %50, label %51, label %52

51:                                               ; preds = %42
  store i8 1, ptr %3, align 1
  store i32 1, ptr %9, align 4
  br label %89

52:                                               ; preds = %42, %31
  br label %53

53:                                               ; preds = %52
  %54 = load ptr, ptr %7, align 8, !tbaa !5
  %55 = getelementptr inbounds %struct._LIST_ENTRY, ptr %54, i32 0, i32 0
  %56 = load ptr, ptr %55, align 8, !tbaa !11
  store ptr %56, ptr %7, align 8, !tbaa !5
  br label %28, !llvm.loop !18

57:                                               ; preds = %28
  %58 = load ptr, ptr @mTcpRunQue, align 8, !tbaa !11
  store ptr %58, ptr %7, align 8, !tbaa !5
  br label %59

59:                                               ; preds = %84, %57
  %60 = load ptr, ptr %7, align 8, !tbaa !5
  %61 = icmp ne ptr %60, @mTcpRunQue
  br i1 %61, label %62, label %88

62:                                               ; preds = %59
  %63 = load ptr, ptr %7, align 8, !tbaa !5
  %64 = ptrtoint ptr %63 to i64
  %65 = sub i64 %64, 0
  %66 = inttoptr i64 %65 to ptr
  store ptr %66, ptr %8, align 8, !tbaa !5
  %67 = load ptr, ptr %4, align 8, !tbaa !5
  %68 = load ptr, ptr %8, align 8, !tbaa !5
  %69 = getelementptr inbounds %struct._TCP_CB, ptr %68, i32 0, i32 3
  %70 = getelementptr inbounds %struct._TCP_PEER, ptr %69, i32 0, i32 0
  %71 = call i64 @CompareMem(ptr noundef %67, ptr noundef %70, i64 noundef 4)
  %72 = icmp eq i64 %71, 0
  br i1 %72, label %73, label %83

73:                                               ; preds = %62
  %74 = load i16, ptr %6, align 2, !tbaa !9
  %75 = zext i16 %74 to i32
  %76 = load ptr, ptr %8, align 8, !tbaa !5
  %77 = getelementptr inbounds %struct._TCP_CB, ptr %76, i32 0, i32 3
  %78 = getelementptr inbounds %struct._TCP_PEER, ptr %77, i32 0, i32 1
  %79 = load i16, ptr %78, align 4, !tbaa !13
  %80 = zext i16 %79 to i32
  %81 = icmp eq i32 %75, %80
  br i1 %81, label %82, label %83

82:                                               ; preds = %73
  store i8 1, ptr %3, align 1
  store i32 1, ptr %9, align 4
  br label %89

83:                                               ; preds = %73, %62
  br label %84

84:                                               ; preds = %83
  %85 = load ptr, ptr %7, align 8, !tbaa !5
  %86 = getelementptr inbounds %struct._LIST_ENTRY, ptr %85, i32 0, i32 0
  %87 = load ptr, ptr %86, align 8, !tbaa !11
  store ptr %87, ptr %7, align 8, !tbaa !5
  br label %59, !llvm.loop !20

88:                                               ; preds = %59
  store i8 0, ptr %3, align 1
  store i32 1, ptr %9, align 4
  br label %89

89:                                               ; preds = %88, %82, %51
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #3
  call void @llvm.lifetime.end.p0(i64 2, ptr %6) #3
  %90 = load i8, ptr %3, align 1
  ret i8 %90
}

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

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


; 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._LIST_ENTRY = type { ptr, ptr }

@mTcpRunQue = external dso_local global %struct._LIST_ENTRY, align 8
@mTcpListenQue = external dso_local global %struct._LIST_ENTRY, align 8
@.str.11 = external hidden unnamed_addr constant [151 x i8], align 1
@.str.14 = external hidden unnamed_addr constant [38 x i8], align 1

declare zeroext i8 @DebugAssertEnabled() local_unnamed_addr #0

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

; Function Attrs: nounwind uwtable
define dso_local zeroext range(i8 0, 2) i8 @TcpFindTcbByPeer(ptr noundef %0, i16 noundef zeroext %1) local_unnamed_addr #1 {
  %3 = tail call zeroext i8 @DebugAssertEnabled() #2
  %.not = icmp eq i8 %3, 0
  br i1 %.not, label %8, label %4

4:                                                ; preds = %2
  %5 = icmp ne ptr %0, null
  %6 = icmp ne i16 %1, 0
  %or.cond = and i1 %5, %6
  br i1 %or.cond, label %8, label %7

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

8:                                                ; preds = %7, %4, %2
  %9 = tail call zeroext i16 @SwapBytes16(i16 noundef zeroext %1) #2
  %.023 = load ptr, ptr @mTcpListenQue, align 8, !tbaa !5
  %.not2024 = icmp eq ptr %.023, @mTcpListenQue
  br i1 %.not2024, label %.preheader, label %.lr.ph

.preheader:                                       ; preds = %17, %8
  %.126 = load ptr, ptr @mTcpRunQue, align 8, !tbaa !5
  %.not2127 = icmp eq ptr %.126, @mTcpRunQue
  br i1 %.not2127, label %.loopexit, label %.lr.ph29

.lr.ph:                                           ; preds = %8, %17
  %.025 = phi ptr [ %.0, %17 ], [ %.023, %8 ]
  %10 = getelementptr inbounds i8, ptr %.025, i64 32
  %11 = tail call i64 @CompareMem(ptr noundef %0, ptr noundef nonnull %10, i64 noundef 4) #2
  %12 = icmp eq i64 %11, 0
  br i1 %12, label %13, label %17

13:                                               ; preds = %.lr.ph
  %14 = getelementptr inbounds i8, ptr %.025, i64 36
  %15 = load i16, ptr %14, align 4, !tbaa !10
  %16 = icmp eq i16 %9, %15
  br i1 %16, label %.loopexit, label %17

17:                                               ; preds = %.lr.ph, %13
  %.0 = load ptr, ptr %.025, align 8, !tbaa !5
  %.not20 = icmp eq ptr %.0, @mTcpListenQue
  br i1 %.not20, label %.preheader, label %.lr.ph, !llvm.loop !16

.lr.ph29:                                         ; preds = %.preheader, %25
  %.128 = phi ptr [ %.1, %25 ], [ %.126, %.preheader ]
  %18 = getelementptr inbounds i8, ptr %.128, i64 32
  %19 = tail call i64 @CompareMem(ptr noundef %0, ptr noundef nonnull %18, i64 noundef 4) #2
  %20 = icmp eq i64 %19, 0
  br i1 %20, label %21, label %25

21:                                               ; preds = %.lr.ph29
  %22 = getelementptr inbounds i8, ptr %.128, i64 36
  %23 = load i16, ptr %22, align 4, !tbaa !10
  %24 = icmp eq i16 %9, %23
  br i1 %24, label %.loopexit, label %25

25:                                               ; preds = %.lr.ph29, %21
  %.1 = load ptr, ptr %.128, align 8, !tbaa !5
  %.not21 = icmp eq ptr %.1, @mTcpRunQue
  br i1 %.not21, label %.loopexit, label %.lr.ph29, !llvm.loop !18

.loopexit:                                        ; preds = %13, %21, %25, %.preheader
  %.019 = phi i8 [ 0, %.preheader ], [ 1, %21 ], [ 0, %25 ], [ 1, %13 ]
  ret i8 %.019
}

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

declare i64 @CompareMem(ptr noundef, ptr noundef, i64 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, !7, i64 0}
!6 = !{!"_LIST_ENTRY", !7, i64 0, !7, i64 8}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!11, !14, i64 36}
!11 = !{!"_TCP_CB", !6, i64 0, !7, i64 16, !7, i64 24, !12, i64 32, !12, i64 40, !6, i64 48, !6, i64 64, !13, i64 80, !13, i64 84, !8, i64 88, !8, 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, !8, i64 156, !13, i64 180, !13, i64 184, !13, i64 188, !8, i64 192, !8, i64 193, !8, 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, !8, i64 238, !8, i64 239, !13, i64 240, !13, i64 244, !13, i64 248, !8, i64 252, !8, i64 253, !14, i64 254, !13, i64 256, !13, i64 260, !13, i64 264, !8, i64 268, !8, i64 269, !8, i64 270, !15, i64 271, !7, i64 280}
!12 = !{!"_TCP_PEER", !13, i64 0, !14, i64 4}
!13 = !{!"int", !8, i64 0}
!14 = !{!"short", !8, i64 0}
!15 = !{!"", !8, i64 0}
!16 = distinct !{!16, !17}
!17 = !{!"llvm.loop.mustprogress"}
!18 = distinct !{!18, !17}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,SROAPass,SimplifyCFGPass,TailCallElimPass