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

; 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] }
%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 }
%union._NET_PROTOCOL = type { %struct._EFI_TCP4_PROTOCOL }
%struct._EFI_TCP4_PROTOCOL = type { ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr }
%struct.NET_BUF_QUEUE = type { i32, i64, %struct._LIST_ENTRY, %struct._LIST_ENTRY, i32, i32 }

@.str.11 = external hidden unnamed_addr constant [151 x i8], align 1
@.str.24 = external hidden unnamed_addr constant [20 x i8], align 1
@.str.25 = external hidden unnamed_addr constant [65 x i8], align 1

declare zeroext i8 @DebugAssertEnabled() #0

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

declare zeroext i8 @DebugPrintEnabled() #0

declare zeroext i8 @DebugPrintLevelEnabled(i64 noundef) #0

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

; Function Attrs: nounwind uwtable
declare dso_local void @TcpSetState(ptr noundef, i8 noundef zeroext) #1

; Function Attrs: nounwind uwtable
declare dso_local void @TcpResetConnection(ptr noundef) #1

declare i64 @TcpToSendData(ptr noundef, i64 noundef) #0

; Function Attrs: nounwind uwtable
define dso_local void @TcpOnAppClose(ptr noundef %0) #1 {
  %2 = alloca ptr, align 8
  store ptr %0, ptr %2, align 8, !tbaa !5
  br label %3

3:                                                ; preds = %1
  %4 = call zeroext i8 @DebugAssertEnabled()
  %5 = icmp ne i8 %4, 0
  br i1 %5, label %6, label %11

6:                                                ; preds = %3
  %7 = load ptr, ptr %2, align 8, !tbaa !5
  %8 = icmp ne ptr %7, null
  br i1 %8, label %10, label %9

9:                                                ; preds = %6
  call void @DebugAssert(ptr noundef @.str.11, i64 noundef 702, ptr noundef @.str.24)
  br label %10

10:                                               ; preds = %9, %6
  br label %11

11:                                               ; preds = %10, %3
  br label %12

12:                                               ; preds = %11
  %13 = load ptr, ptr %2, align 8, !tbaa !5
  %14 = getelementptr inbounds %struct._TCP_CB, ptr %13, i32 0, i32 6
  %15 = call zeroext i8 @IsListEmpty(ptr noundef %14)
  %16 = icmp ne i8 %15, 0
  br i1 %16, label %17, label %27

17:                                               ; preds = %12
  %18 = load ptr, ptr %2, align 8, !tbaa !5
  %19 = getelementptr inbounds %struct._TCP_CB, ptr %18, i32 0, i32 2
  %20 = load ptr, ptr %19, align 8, !tbaa !9
  %21 = getelementptr inbounds %struct._SOCKET, ptr %20, i32 0, i32 12
  %22 = getelementptr inbounds %struct._SOCK_BUFFER, ptr %21, i32 0, i32 2
  %23 = load ptr, ptr %22, align 8, !tbaa !16
  %24 = getelementptr inbounds %struct.NET_BUF_QUEUE, ptr %23, i32 0, i32 4
  %25 = load i32, ptr %24, align 8, !tbaa !21
  %26 = icmp ne i32 %25, 0
  br i1 %26, label %27, label %43

27:                                               ; preds = %17, %12
  br label %28

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

31:                                               ; preds = %28
  br label %32

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

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

37:                                               ; preds = %35, %32
  br label %38

38:                                               ; preds = %37
  br label %39

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

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

43:                                               ; preds = %17
  %44 = load ptr, ptr %2, align 8, !tbaa !5
  %45 = getelementptr inbounds %struct._TCP_CB, ptr %44, i32 0, i32 9
  %46 = load i8, ptr %45, align 8, !tbaa !23
  %47 = zext i8 %46 to i32
  switch i32 %47, label %54 [
    i32 0, label %48
    i32 1, label %48
    i32 2, label %48
    i32 3, label %50
    i32 4, label %50
    i32 9, label %52
  ]

48:                                               ; preds = %43, %43, %43
  %49 = load ptr, ptr %2, align 8, !tbaa !5
  call void @TcpSetState(ptr noundef %49, i8 noundef zeroext 0)
  br label %55

50:                                               ; preds = %43, %43
  %51 = load ptr, ptr %2, align 8, !tbaa !5
  call void @TcpSetState(ptr noundef %51, i8 noundef zeroext 5)
  br label %55

52:                                               ; preds = %43
  %53 = load ptr, ptr %2, align 8, !tbaa !5
  call void @TcpSetState(ptr noundef %53, i8 noundef zeroext 10)
  br label %55

54:                                               ; preds = %43
  br label %55

55:                                               ; preds = %54, %52, %50, %48
  %56 = load ptr, ptr %2, align 8, !tbaa !5
  %57 = call i64 @TcpToSendData(ptr noundef %56, i64 noundef 1)
  br label %58

58:                                               ; preds = %55, %40
  ret void
}

declare zeroext i8 @IsListEmpty(ptr noundef) #0

declare void @TcpClose(ptr noundef) #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" }

!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, !6, i64 24}
!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 = !{!17, !6, i64 120}
!17 = !{!"_SOCKET", !13, i64 0, !6, i64 8, !6, i64 16, !6, i64 24, !6, i64 32, !11, i64 40, !7, i64 56, !13, i64 60, !7, i64 64, !14, i64 66, !18, i64 72, !20, i64 96, !20, i64 112, !19, i64 128, !7, i64 136, !13, i64 140, !13, i64 144, !6, i64 152, !11, i64 160, !11, i64 176, !11, i64 192, !11, i64 208, !11, 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}
!18 = !{!"", !19, i64 0, !19, i64 8, !13, i64 16}
!19 = !{!"long long", !7, i64 0}
!20 = !{!"_SOCK_BUFFER", !13, i64 0, !13, i64 4, !6, i64 8}
!21 = !{!22, !13, i64 48}
!22 = !{!"", !13, i64 0, !19, i64 8, !11, i64 16, !11, i64 32, !13, i64 48, !13, i64 52}
!23 = !{!10, !7, i64 88}


; 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.11 = external hidden unnamed_addr constant [151 x i8], align 1
@.str.24 = external hidden unnamed_addr constant [20 x i8], align 1
@.str.25 = external hidden unnamed_addr constant [65 x i8], align 1
@switch.table.TcpOnAppClose = private unnamed_addr constant [10 x i8] c"\00\00\00\05\05\00\00\00\00\0A", align 1

declare zeroext i8 @DebugAssertEnabled() local_unnamed_addr #0

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

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
declare dso_local void @TcpSetState(ptr noundef, i8 noundef zeroext) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
declare dso_local void @TcpResetConnection(ptr noundef) local_unnamed_addr #1

declare i64 @TcpToSendData(ptr noundef, i64 noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local void @TcpOnAppClose(ptr noundef %0) local_unnamed_addr #1 {
  %2 = tail call zeroext i8 @DebugAssertEnabled() #2
  %3 = icmp eq i8 %2, 0
  %4 = icmp ne ptr %0, null
  %or.cond = or i1 %4, %3
  br i1 %or.cond, label %6, label %5

5:                                                ; preds = %1
  tail call void @DebugAssert(ptr noundef nonnull @.str.11, i64 noundef 702, ptr noundef nonnull @.str.24) #2
  br label %6

6:                                                ; preds = %1, %5
  %7 = getelementptr inbounds i8, ptr %0, i64 64
  %8 = tail call zeroext i8 @IsListEmpty(ptr noundef nonnull %7) #2
  %.not = icmp eq i8 %8, 0
  br i1 %.not, label %16, label %9

9:                                                ; preds = %6
  %10 = getelementptr inbounds i8, ptr %0, i64 24
  %11 = load ptr, ptr %10, align 8, !tbaa !5
  %12 = getelementptr inbounds i8, ptr %11, i64 120
  %13 = load ptr, ptr %12, align 8, !tbaa !15
  %14 = getelementptr inbounds i8, ptr %13, i64 48
  %15 = load i32, ptr %14, align 8, !tbaa !20
  %.not12 = icmp eq i32 %15, 0
  br i1 %.not12, label %22, label %16

16:                                               ; preds = %6, %9
  %17 = tail call zeroext i8 @DebugPrintEnabled() #2
  %.not13 = icmp eq i8 %17, 0
  br i1 %.not13, label %21, label %18

18:                                               ; preds = %16
  %19 = tail call zeroext i8 @DebugPrintLevelEnabled(i64 noundef 2) #2
  %.not14 = icmp eq i8 %19, 0
  br i1 %.not14, label %21, label %20

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

21:                                               ; preds = %16, %18, %20
  tail call void @TcpResetConnection(ptr noundef %0)
  tail call void @TcpClose(ptr noundef %0) #2
  br label %29

22:                                               ; preds = %9
  %23 = getelementptr inbounds i8, ptr %0, i64 88
  %24 = load i8, ptr %23, align 8, !tbaa !22
  %25 = icmp ult i8 %24, 10
  br i1 %25, label %switch.hole_check, label %27

switch.hole_check:                                ; preds = %22
  %switch.maskindex = zext nneg i8 %24 to i16
  %switch.shifted = lshr i16 543, %switch.maskindex
  %switch.lobit = trunc i16 %switch.shifted to i1
  br i1 %switch.lobit, label %switch.lookup, label %27

switch.lookup:                                    ; preds = %switch.hole_check
  %26 = zext nneg i8 %24 to i64
  %switch.gep = getelementptr inbounds [10 x i8], ptr @switch.table.TcpOnAppClose, i64 0, i64 %26
  %switch.load = load i8, ptr %switch.gep, align 1
  tail call void @TcpSetState(ptr noundef nonnull %0, i8 noundef zeroext %switch.load)
  br label %27

27:                                               ; preds = %switch.hole_check, %22, %switch.lookup
  %28 = tail call i64 @TcpToSendData(ptr noundef nonnull %0, i64 noundef 1) #2
  br label %29

29:                                               ; preds = %27, %21
  ret void
}

declare zeroext i8 @IsListEmpty(ptr noundef) local_unnamed_addr #0

declare void @TcpClose(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, !8, i64 24}
!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 = !{!16, !8, i64 120}
!16 = !{!"_SOCKET", !12, i64 0, !8, i64 8, !8, i64 16, !8, i64 24, !8, i64 32, !7, i64 40, !9, i64 56, !12, i64 60, !9, i64 64, !13, i64 66, !17, i64 72, !19, i64 96, !19, i64 112, !18, i64 128, !9, i64 136, !12, i64 140, !12, i64 144, !8, i64 152, !7, i64 160, !7, i64 176, !7, i64 192, !7, i64 208, !7, i64 224, !8, i64 240, !8, i64 248, !8, i64 256, !9, i64 264, !9, i64 288, !8, i64 368, !8, i64 376, !8, i64 384}
!17 = !{!"", !18, i64 0, !18, i64 8, !12, i64 16}
!18 = !{!"long long", !9, i64 0}
!19 = !{!"_SOCK_BUFFER", !12, i64 0, !12, i64 4, !8, i64 8}
!20 = !{!21, !12, i64 48}
!21 = !{!"", !12, i64 0, !18, i64 8, !7, i64 16, !7, i64 32, !12, i64 48, !12, i64 52}
!22 = !{!6, !9, i64 88}


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