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

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

@mTcpListenQue = external dso_local global %struct._LIST_ENTRY, align 8

; 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 ptr @TcpLocateListenTcb(ptr noundef %0, ptr noundef %1) #1 {
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca ptr, align 8
  %9 = alloca i64, align 8
  %10 = alloca i64, align 8
  %11 = alloca i32, align 4
  store ptr %0, ptr %4, align 8, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #2
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #2
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #2
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #2
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #2
  store i64 4, ptr %9, align 8, !tbaa !9
  store ptr null, ptr %8, align 8, !tbaa !5
  %12 = load ptr, ptr @mTcpListenQue, align 8, !tbaa !11
  store ptr %12, ptr %6, align 8, !tbaa !5
  br label %13

13:                                               ; preds = %139, %2
  %14 = load ptr, ptr %6, align 8, !tbaa !5
  %15 = icmp ne ptr %14, @mTcpListenQue
  br i1 %15, label %16, label %143

16:                                               ; preds = %13
  %17 = load ptr, ptr %6, align 8, !tbaa !5
  %18 = ptrtoint ptr %17 to i64
  %19 = sub i64 %18, 0
  %20 = inttoptr i64 %19 to ptr
  store ptr %20, ptr %7, align 8, !tbaa !5
  %21 = load ptr, ptr %4, align 8, !tbaa !5
  %22 = getelementptr inbounds %struct._TCP_PEER, ptr %21, i32 0, i32 1
  %23 = load i16, ptr %22, align 4, !tbaa !13
  %24 = zext i16 %23 to i32
  %25 = load ptr, ptr %7, align 8, !tbaa !5
  %26 = getelementptr inbounds %struct._TCP_CB, ptr %25, i32 0, i32 3
  %27 = getelementptr inbounds %struct._TCP_PEER, ptr %26, i32 0, i32 1
  %28 = load i16, ptr %27, align 4, !tbaa !17
  %29 = zext i16 %28 to i32
  %30 = icmp ne i32 %24, %29
  br i1 %30, label %97, label %31

31:                                               ; preds = %16
  %32 = load ptr, ptr %7, align 8, !tbaa !5
  %33 = getelementptr inbounds %struct._TCP_CB, ptr %32, i32 0, i32 4
  %34 = getelementptr inbounds %struct._TCP_PEER, ptr %33, i32 0, i32 0
  %35 = load i32, ptr %34, align 8, !tbaa !20
  %36 = icmp eq i32 %35, 0
  br i1 %36, label %46, label %37

37:                                               ; preds = %31
  %38 = load ptr, ptr %7, align 8, !tbaa !5
  %39 = getelementptr inbounds %struct._TCP_CB, ptr %38, i32 0, i32 4
  %40 = getelementptr inbounds %struct._TCP_PEER, ptr %39, i32 0, i32 0
  %41 = load i32, ptr %40, align 8, !tbaa !20
  %42 = load ptr, ptr %5, align 8, !tbaa !5
  %43 = getelementptr inbounds %struct._TCP_PEER, ptr %42, i32 0, i32 0
  %44 = load i32, ptr %43, align 4, !tbaa !21
  %45 = icmp eq i32 %41, %44
  br i1 %45, label %46, label %97

46:                                               ; preds = %37, %31
  %47 = load ptr, ptr %7, align 8, !tbaa !5
  %48 = getelementptr inbounds %struct._TCP_CB, ptr %47, i32 0, i32 4
  %49 = getelementptr inbounds %struct._TCP_PEER, ptr %48, i32 0, i32 1
  %50 = load i16, ptr %49, align 4, !tbaa !22
  %51 = zext i16 %50 to i32
  %52 = icmp eq i32 %51, 0
  br i1 %52, label %64, label %53

53:                                               ; preds = %46
  %54 = load ptr, ptr %7, align 8, !tbaa !5
  %55 = getelementptr inbounds %struct._TCP_CB, ptr %54, i32 0, i32 4
  %56 = getelementptr inbounds %struct._TCP_PEER, ptr %55, i32 0, i32 1
  %57 = load i16, ptr %56, align 4, !tbaa !22
  %58 = zext i16 %57 to i32
  %59 = load ptr, ptr %5, align 8, !tbaa !5
  %60 = getelementptr inbounds %struct._TCP_PEER, ptr %59, i32 0, i32 1
  %61 = load i16, ptr %60, align 4, !tbaa !13
  %62 = zext i16 %61 to i32
  %63 = icmp eq i32 %58, %62
  br i1 %63, label %64, label %97

64:                                               ; preds = %53, %46
  %65 = load ptr, ptr %7, align 8, !tbaa !5
  %66 = getelementptr inbounds %struct._TCP_CB, ptr %65, i32 0, i32 3
  %67 = getelementptr inbounds %struct._TCP_PEER, ptr %66, i32 0, i32 0
  %68 = load i32, ptr %67, align 8, !tbaa !23
  %69 = icmp eq i32 %68, 0
  br i1 %69, label %79, label %70

70:                                               ; preds = %64
  %71 = load ptr, ptr %7, align 8, !tbaa !5
  %72 = getelementptr inbounds %struct._TCP_CB, ptr %71, i32 0, i32 3
  %73 = getelementptr inbounds %struct._TCP_PEER, ptr %72, i32 0, i32 0
  %74 = load i32, ptr %73, align 8, !tbaa !23
  %75 = load ptr, ptr %4, align 8, !tbaa !5
  %76 = getelementptr inbounds %struct._TCP_PEER, ptr %75, i32 0, i32 0
  %77 = load i32, ptr %76, align 4, !tbaa !21
  %78 = icmp eq i32 %74, %77
  br i1 %78, label %79, label %97

79:                                               ; preds = %70, %64
  %80 = load ptr, ptr %7, align 8, !tbaa !5
  %81 = getelementptr inbounds %struct._TCP_CB, ptr %80, i32 0, i32 3
  %82 = getelementptr inbounds %struct._TCP_PEER, ptr %81, i32 0, i32 1
  %83 = load i16, ptr %82, align 4, !tbaa !17
  %84 = zext i16 %83 to i32
  %85 = icmp eq i32 %84, 0
  br i1 %85, label %98, label %86

86:                                               ; preds = %79
  %87 = load ptr, ptr %7, align 8, !tbaa !5
  %88 = getelementptr inbounds %struct._TCP_CB, ptr %87, i32 0, i32 3
  %89 = getelementptr inbounds %struct._TCP_PEER, ptr %88, i32 0, i32 1
  %90 = load i16, ptr %89, align 4, !tbaa !17
  %91 = zext i16 %90 to i32
  %92 = load ptr, ptr %4, align 8, !tbaa !5
  %93 = getelementptr inbounds %struct._TCP_PEER, ptr %92, i32 0, i32 1
  %94 = load i16, ptr %93, align 4, !tbaa !13
  %95 = zext i16 %94 to i32
  %96 = icmp eq i32 %91, %95
  br i1 %96, label %98, label %97

97:                                               ; preds = %86, %70, %53, %37, %16
  br label %139

98:                                               ; preds = %86, %79
  store i64 0, ptr %10, align 8, !tbaa !9
  %99 = load ptr, ptr %7, align 8, !tbaa !5
  %100 = getelementptr inbounds %struct._TCP_CB, ptr %99, i32 0, i32 4
  %101 = getelementptr inbounds %struct._TCP_PEER, ptr %100, i32 0, i32 0
  %102 = load i32, ptr %101, align 8, !tbaa !20
  %103 = icmp eq i32 %102, 0
  br i1 %103, label %104, label %107

104:                                              ; preds = %98
  %105 = load i64, ptr %10, align 8, !tbaa !9
  %106 = add nsw i64 %105, 1
  store i64 %106, ptr %10, align 8, !tbaa !9
  br label %107

107:                                              ; preds = %104, %98
  %108 = load ptr, ptr %7, align 8, !tbaa !5
  %109 = getelementptr inbounds %struct._TCP_CB, ptr %108, i32 0, i32 4
  %110 = getelementptr inbounds %struct._TCP_PEER, ptr %109, i32 0, i32 1
  %111 = load i16, ptr %110, align 4, !tbaa !22
  %112 = zext i16 %111 to i32
  %113 = icmp eq i32 %112, 0
  br i1 %113, label %114, label %117

114:                                              ; preds = %107
  %115 = load i64, ptr %10, align 8, !tbaa !9
  %116 = add nsw i64 %115, 1
  store i64 %116, ptr %10, align 8, !tbaa !9
  br label %117

117:                                              ; preds = %114, %107
  %118 = load ptr, ptr %7, align 8, !tbaa !5
  %119 = getelementptr inbounds %struct._TCP_CB, ptr %118, i32 0, i32 3
  %120 = getelementptr inbounds %struct._TCP_PEER, ptr %119, i32 0, i32 0
  %121 = load i32, ptr %120, align 8, !tbaa !23
  %122 = icmp eq i32 %121, 0
  br i1 %122, label %123, label %126

123:                                              ; preds = %117
  %124 = load i64, ptr %10, align 8, !tbaa !9
  %125 = add nsw i64 %124, 1
  store i64 %125, ptr %10, align 8, !tbaa !9
  br label %126

126:                                              ; preds = %123, %117
  %127 = load i64, ptr %10, align 8, !tbaa !9
  %128 = load i64, ptr %9, align 8, !tbaa !9
  %129 = icmp slt i64 %127, %128
  br i1 %129, label %130, label %138

130:                                              ; preds = %126
  %131 = load i64, ptr %10, align 8, !tbaa !9
  %132 = icmp eq i64 %131, 0
  br i1 %132, label %133, label %135

133:                                              ; preds = %130
  %134 = load ptr, ptr %7, align 8, !tbaa !5
  store ptr %134, ptr %3, align 8
  store i32 1, ptr %11, align 4
  br label %145

135:                                              ; preds = %130
  %136 = load i64, ptr %10, align 8, !tbaa !9
  store i64 %136, ptr %9, align 8, !tbaa !9
  %137 = load ptr, ptr %7, align 8, !tbaa !5
  store ptr %137, ptr %8, align 8, !tbaa !5
  br label %138

138:                                              ; preds = %135, %126
  br label %139

139:                                              ; preds = %138, %97
  %140 = load ptr, ptr %6, align 8, !tbaa !5
  %141 = getelementptr inbounds %struct._LIST_ENTRY, ptr %140, i32 0, i32 0
  %142 = load ptr, ptr %141, align 8, !tbaa !11
  store ptr %142, ptr %6, align 8, !tbaa !5
  br label %13, !llvm.loop !24

143:                                              ; preds = %13
  %144 = load ptr, ptr %8, align 8, !tbaa !5
  store ptr %144, ptr %3, align 8
  store i32 1, ptr %11, align 4
  br label %145

145:                                              ; preds = %143, %133
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #2
  %146 = load ptr, ptr %3, align 8
  ret ptr %146
}

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


; 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 }

@mTcpListenQue = external dso_local global %struct._LIST_ENTRY, align 8

; Function Attrs: nofree norecurse nosync nounwind memory(read, inaccessiblemem: none) uwtable
define dso_local ptr @TcpLocateListenTcb(ptr nocapture noundef readonly %0, ptr nocapture noundef readonly %1) local_unnamed_addr #0 {
  %.03541 = load ptr, ptr @mTcpListenQue, align 8, !tbaa !5
  %.not42 = icmp eq ptr %.03541, @mTcpListenQue
  br i1 %.not42, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %2
  %3 = getelementptr inbounds i8, ptr %0, i64 4
  %4 = load i16, ptr %3, align 4, !tbaa !10
  %5 = getelementptr inbounds i8, ptr %1, i64 4
  br label %6

6:                                                ; preds = %.lr.ph, %36
  %.03545 = phi ptr [ %.03541, %.lr.ph ], [ %.035, %36 ]
  %.03044 = phi i64 [ 4, %.lr.ph ], [ %.131, %36 ]
  %.03243 = phi ptr [ null, %.lr.ph ], [ %.133, %36 ]
  %7 = getelementptr inbounds i8, ptr %.03545, i64 32
  %8 = getelementptr inbounds i8, ptr %.03545, i64 36
  %9 = load i16, ptr %8, align 4, !tbaa !14
  %.not40 = icmp eq i16 %4, %9
  br i1 %.not40, label %10, label %36

10:                                               ; preds = %6
  %11 = getelementptr inbounds i8, ptr %.03545, i64 40
  %12 = load i32, ptr %11, align 8, !tbaa !17
  %13 = icmp eq i32 %12, 0
  br i1 %13, label %17, label %14

14:                                               ; preds = %10
  %15 = load i32, ptr %1, align 4, !tbaa !18
  %16 = icmp eq i32 %12, %15
  br i1 %16, label %17, label %36

17:                                               ; preds = %14, %10
  %18 = getelementptr inbounds i8, ptr %.03545, i64 44
  %19 = load i16, ptr %18, align 4, !tbaa !19
  %20 = icmp eq i16 %19, 0
  br i1 %20, label %24, label %21

21:                                               ; preds = %17
  %22 = load i16, ptr %5, align 4, !tbaa !10
  %23 = icmp eq i16 %19, %22
  br i1 %23, label %24, label %36

24:                                               ; preds = %21, %17
  %25 = load i32, ptr %7, align 8, !tbaa !20
  %26 = icmp eq i32 %25, 0
  br i1 %26, label %30, label %27

27:                                               ; preds = %24
  %28 = load i32, ptr %0, align 4, !tbaa !18
  %29 = icmp eq i32 %25, %28
  br i1 %29, label %30, label %36

30:                                               ; preds = %24, %27
  %spec.select = zext i1 %13 to i64
  %31 = select i1 %13, i64 2, i64 1
  %.1 = select i1 %20, i64 %31, i64 %spec.select
  %32 = zext i1 %26 to i64
  %.2 = add nuw nsw i64 %.1, %32
  %33 = icmp slt i64 %.2, %.03044
  br i1 %33, label %34, label %36

34:                                               ; preds = %30
  %35 = icmp eq i64 %.2, 0
  br i1 %35, label %._crit_edge, label %36

36:                                               ; preds = %34, %30, %6, %14, %21, %27
  %.133 = phi ptr [ %.03243, %6 ], [ %.03243, %30 ], [ %.03243, %27 ], [ %.03243, %21 ], [ %.03243, %14 ], [ %.03545, %34 ]
  %.131 = phi i64 [ %.03044, %6 ], [ %.03044, %30 ], [ %.03044, %27 ], [ %.03044, %21 ], [ %.03044, %14 ], [ %.2, %34 ]
  %.035 = load ptr, ptr %.03545, align 8, !tbaa !5
  %.not = icmp eq ptr %.035, @mTcpListenQue
  br i1 %.not, label %._crit_edge, label %6, !llvm.loop !21

._crit_edge:                                      ; preds = %34, %36, %2
  %.034 = phi ptr [ null, %2 ], [ %.133, %36 ], [ %.03545, %34 ]
  ret ptr %.034
}

attributes #0 = { nofree norecurse nosync nounwind memory(read, inaccessiblemem: none) 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" }

!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, !13, i64 4}
!11 = !{!"_TCP_PEER", !12, i64 0, !13, i64 4}
!12 = !{!"int", !8, i64 0}
!13 = !{!"short", !8, i64 0}
!14 = !{!15, !13, i64 36}
!15 = !{!"_TCP_CB", !6, i64 0, !7, i64 16, !7, i64 24, !11, i64 32, !11, i64 40, !6, i64 48, !6, i64 64, !12, i64 80, !12, i64 84, !8, i64 88, !8, 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, !8, i64 156, !12, i64 180, !12, i64 184, !12, i64 188, !8, i64 192, !8, i64 193, !8, 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, !8, i64 238, !8, i64 239, !12, i64 240, !12, i64 244, !12, i64 248, !8, i64 252, !8, i64 253, !13, i64 254, !12, i64 256, !12, i64 260, !12, i64 264, !8, i64 268, !8, i64 269, !8, i64 270, !16, i64 271, !7, i64 280}
!16 = !{!"", !8, i64 0}
!17 = !{!15, !12, i64 40}
!18 = !{!11, !12, i64 0}
!19 = !{!15, !13, i64 44}
!20 = !{!15, !12, i64 32}
!21 = distinct !{!21, !22}
!22 = !{!"llvm.loop.mustprogress"}


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