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

; 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.15 = external hidden unnamed_addr constant [108 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

declare ptr @InsertHeadList(ptr noundef, ptr noundef) #1

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

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

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

14:                                               ; preds = %11
  %15 = load ptr, ptr %3, align 8, !tbaa !5
  %16 = getelementptr inbounds %struct._TCP_CB, ptr %15, i32 0, i32 9
  %17 = load i8, ptr %16, align 8, !tbaa !9
  %18 = zext i8 %17 to i32
  %19 = icmp eq i32 %18, 1
  br i1 %19, label %39, label %20

20:                                               ; preds = %14
  %21 = load ptr, ptr %3, align 8, !tbaa !5
  %22 = getelementptr inbounds %struct._TCP_CB, ptr %21, i32 0, i32 9
  %23 = load i8, ptr %22, align 8, !tbaa !9
  %24 = zext i8 %23 to i32
  %25 = icmp eq i32 %24, 2
  br i1 %25, label %39, label %26

26:                                               ; preds = %20
  %27 = load ptr, ptr %3, align 8, !tbaa !5
  %28 = getelementptr inbounds %struct._TCP_CB, ptr %27, i32 0, i32 9
  %29 = load i8, ptr %28, align 8, !tbaa !9
  %30 = zext i8 %29 to i32
  %31 = icmp eq i32 %30, 3
  br i1 %31, label %39, label %32

32:                                               ; preds = %26
  %33 = load ptr, ptr %3, align 8, !tbaa !5
  %34 = getelementptr inbounds %struct._TCP_CB, ptr %33, i32 0, i32 9
  %35 = load i8, ptr %34, align 8, !tbaa !9
  %36 = zext i8 %35 to i32
  %37 = icmp eq i32 %36, 0
  br i1 %37, label %39, label %38

38:                                               ; preds = %32, %11
  call void @DebugAssert(ptr noundef @.str.11, i64 noundef 366, ptr noundef @.str.15)
  br label %39

39:                                               ; preds = %38, %32, %26, %20, %14
  br label %40

40:                                               ; preds = %39, %8
  br label %41

41:                                               ; preds = %40
  br label %42

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

49:                                               ; preds = %42
  store i64 -1, ptr %2, align 8
  store i32 1, ptr %7, align 4
  br label %124

50:                                               ; preds = %42
  store ptr @mTcpRunQue, ptr %5, align 8, !tbaa !5
  %51 = load ptr, ptr %3, align 8, !tbaa !5
  %52 = getelementptr inbounds %struct._TCP_CB, ptr %51, i32 0, i32 9
  %53 = load i8, ptr %52, align 8, !tbaa !9
  %54 = zext i8 %53 to i32
  %55 = icmp eq i32 %54, 1
  br i1 %55, label %56, label %57

56:                                               ; preds = %50
  store ptr @mTcpListenQue, ptr %5, align 8, !tbaa !5
  br label %57

57:                                               ; preds = %56, %50
  %58 = load ptr, ptr %5, align 8, !tbaa !5
  %59 = getelementptr inbounds %struct._LIST_ENTRY, ptr %58, i32 0, i32 0
  %60 = load ptr, ptr %59, align 8, !tbaa !17
  store ptr %60, ptr %4, align 8, !tbaa !5
  br label %61

61:                                               ; preds = %115, %57
  %62 = load ptr, ptr %4, align 8, !tbaa !5
  %63 = load ptr, ptr %5, align 8, !tbaa !5
  %64 = icmp ne ptr %62, %63
  br i1 %64, label %65, label %119

65:                                               ; preds = %61
  %66 = load ptr, ptr %4, align 8, !tbaa !5
  %67 = ptrtoint ptr %66 to i64
  %68 = sub i64 %67, 0
  %69 = inttoptr i64 %68 to ptr
  store ptr %69, ptr %6, align 8, !tbaa !5
  %70 = load ptr, ptr %3, align 8, !tbaa !5
  %71 = getelementptr inbounds %struct._TCP_CB, ptr %70, i32 0, i32 3
  %72 = getelementptr inbounds %struct._TCP_PEER, ptr %71, i32 0, i32 0
  %73 = load i32, ptr %72, align 8, !tbaa !18
  %74 = load ptr, ptr %6, align 8, !tbaa !5
  %75 = getelementptr inbounds %struct._TCP_CB, ptr %74, i32 0, i32 3
  %76 = getelementptr inbounds %struct._TCP_PEER, ptr %75, i32 0, i32 0
  %77 = load i32, ptr %76, align 8, !tbaa !18
  %78 = icmp eq i32 %73, %77
  br i1 %78, label %79, label %114

79:                                               ; preds = %65
  %80 = load ptr, ptr %3, 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 !16
  %84 = zext i16 %83 to i32
  %85 = load ptr, ptr %6, align 8, !tbaa !5
  %86 = getelementptr inbounds %struct._TCP_CB, ptr %85, i32 0, i32 3
  %87 = getelementptr inbounds %struct._TCP_PEER, ptr %86, i32 0, i32 1
  %88 = load i16, ptr %87, align 4, !tbaa !16
  %89 = zext i16 %88 to i32
  %90 = icmp eq i32 %84, %89
  br i1 %90, label %91, label %114

91:                                               ; preds = %79
  %92 = load ptr, ptr %3, align 8, !tbaa !5
  %93 = getelementptr inbounds %struct._TCP_CB, ptr %92, i32 0, i32 4
  %94 = getelementptr inbounds %struct._TCP_PEER, ptr %93, i32 0, i32 0
  %95 = load i32, ptr %94, align 8, !tbaa !19
  %96 = load ptr, ptr %6, align 8, !tbaa !5
  %97 = getelementptr inbounds %struct._TCP_CB, ptr %96, i32 0, i32 4
  %98 = getelementptr inbounds %struct._TCP_PEER, ptr %97, i32 0, i32 0
  %99 = load i32, ptr %98, align 8, !tbaa !19
  %100 = icmp eq i32 %95, %99
  br i1 %100, label %101, label %114

101:                                              ; preds = %91
  %102 = load ptr, ptr %3, align 8, !tbaa !5
  %103 = getelementptr inbounds %struct._TCP_CB, ptr %102, i32 0, i32 4
  %104 = getelementptr inbounds %struct._TCP_PEER, ptr %103, i32 0, i32 1
  %105 = load i16, ptr %104, align 4, !tbaa !20
  %106 = zext i16 %105 to i32
  %107 = load ptr, ptr %6, align 8, !tbaa !5
  %108 = getelementptr inbounds %struct._TCP_CB, ptr %107, i32 0, i32 4
  %109 = getelementptr inbounds %struct._TCP_PEER, ptr %108, i32 0, i32 1
  %110 = load i16, ptr %109, align 4, !tbaa !20
  %111 = zext i16 %110 to i32
  %112 = icmp eq i32 %106, %111
  br i1 %112, label %113, label %114

113:                                              ; preds = %101
  store i64 -1, ptr %2, align 8
  store i32 1, ptr %7, align 4
  br label %124

114:                                              ; preds = %101, %91, %79, %65
  br label %115

115:                                              ; preds = %114
  %116 = load ptr, ptr %4, align 8, !tbaa !5
  %117 = getelementptr inbounds %struct._LIST_ENTRY, ptr %116, i32 0, i32 0
  %118 = load ptr, ptr %117, align 8, !tbaa !17
  store ptr %118, ptr %4, align 8, !tbaa !5
  br label %61, !llvm.loop !21

119:                                              ; preds = %61
  %120 = load ptr, ptr %5, align 8, !tbaa !5
  %121 = load ptr, ptr %3, align 8, !tbaa !5
  %122 = getelementptr inbounds %struct._TCP_CB, ptr %121, i32 0, i32 0
  %123 = call ptr @InsertHeadList(ptr noundef %120, ptr noundef %122)
  store i64 0, ptr %2, align 8
  store i32 1, ptr %7, align 4
  br label %124

124:                                              ; preds = %119, %113, %49
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #3
  %125 = load i64, ptr %2, align 8
  ret i64 %125
}

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 = !{!10, !14, i64 36}
!17 = !{!11, !6, i64 0}
!18 = !{!10, !13, i64 32}
!19 = !{!10, !13, i64 40}
!20 = !{!10, !14, i64 44}
!21 = distinct !{!21, !22}
!22 = !{!"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 }

@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.15 = external hidden unnamed_addr constant [108 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

declare ptr @InsertHeadList(ptr noundef, ptr noundef) local_unnamed_addr #0

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

3:                                                ; preds = %1
  %.not25 = icmp eq ptr %0, null
  br i1 %.not25, label %7, label %4

4:                                                ; preds = %3
  %5 = getelementptr inbounds i8, ptr %0, i64 88
  %6 = load i8, ptr %5, align 8, !tbaa !5
  %switch = icmp ult i8 %6, 4
  br i1 %switch, label %8, label %7

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

8:                                                ; preds = %4, %7, %1
  %9 = getelementptr inbounds i8, ptr %0, i64 32
  %10 = getelementptr inbounds i8, ptr %0, i64 36
  %11 = load i16, ptr %10, align 4, !tbaa !15
  %12 = icmp eq i16 %11, 0
  br i1 %12, label %.loopexit, label %13

13:                                               ; preds = %8
  %14 = getelementptr inbounds i8, ptr %0, i64 88
  %15 = load i8, ptr %14, align 8, !tbaa !5
  %16 = icmp eq i8 %15, 1
  %spec.store.select = select i1 %16, ptr @mTcpListenQue, ptr @mTcpRunQue
  %.02227 = load ptr, ptr %spec.store.select, align 8, !tbaa !16
  %.not2628 = icmp eq ptr %.02227, %spec.store.select
  br i1 %.not2628, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %13
  %17 = load i32, ptr %9, align 8, !tbaa !17
  %18 = getelementptr inbounds i8, ptr %0, i64 40
  %19 = getelementptr inbounds i8, ptr %0, i64 44
  br label %20

20:                                               ; preds = %.lr.ph, %38
  %.02229 = phi ptr [ %.02227, %.lr.ph ], [ %.022, %38 ]
  %21 = getelementptr inbounds i8, ptr %.02229, i64 32
  %22 = load i32, ptr %21, align 8, !tbaa !17
  %23 = icmp eq i32 %17, %22
  br i1 %23, label %24, label %38

24:                                               ; preds = %20
  %25 = getelementptr inbounds i8, ptr %.02229, i64 36
  %26 = load i16, ptr %25, align 4, !tbaa !15
  %27 = icmp eq i16 %11, %26
  br i1 %27, label %28, label %38

28:                                               ; preds = %24
  %29 = load i32, ptr %18, align 8, !tbaa !18
  %30 = getelementptr inbounds i8, ptr %.02229, i64 40
  %31 = load i32, ptr %30, align 8, !tbaa !18
  %32 = icmp eq i32 %29, %31
  br i1 %32, label %33, label %38

33:                                               ; preds = %28
  %34 = load i16, ptr %19, align 4, !tbaa !19
  %35 = getelementptr inbounds i8, ptr %.02229, i64 44
  %36 = load i16, ptr %35, align 4, !tbaa !19
  %37 = icmp eq i16 %34, %36
  br i1 %37, label %.loopexit, label %38

38:                                               ; preds = %20, %24, %28, %33
  %.022 = load ptr, ptr %.02229, align 8, !tbaa !16
  %.not26 = icmp eq ptr %.022, %spec.store.select
  br i1 %.not26, label %._crit_edge, label %20, !llvm.loop !20

._crit_edge:                                      ; preds = %38, %13
  %39 = tail call ptr @InsertHeadList(ptr noundef nonnull %spec.store.select, ptr noundef nonnull %0) #2
  br label %.loopexit

.loopexit:                                        ; preds = %33, %8, %._crit_edge
  %.0 = phi i64 [ 0, %._crit_edge ], [ -1, %8 ], [ -1, %33 ]
  ret i64 %.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 36}
!16 = !{!7, !8, i64 0}
!17 = !{!6, !12, i64 32}
!18 = !{!6, !12, i64 40}
!19 = !{!6, !13, i64 44}
!20 = distinct !{!20, !21}
!21 = !{!"llvm.loop.mustprogress"}


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