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

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

; 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
declare dso_local i32 @TcpRcvWinNow(ptr noundef) #1

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

8:                                                ; preds = %2
  %9 = load ptr, ptr %3, align 8, !tbaa !5
  %10 = getelementptr inbounds %struct._TCP_CB, ptr %9, i32 0, i32 2
  %11 = load ptr, ptr %10, align 8, !tbaa !10
  %12 = getelementptr inbounds %struct._SOCKET, ptr %11, i32 0, i32 12
  %13 = getelementptr inbounds %struct._SOCK_BUFFER, ptr %12, i32 0, i32 0
  %14 = load i32, ptr %13, align 8, !tbaa !17
  store i32 %14, ptr %5, align 4, !tbaa !22
  br label %21

15:                                               ; preds = %2
  %16 = load ptr, ptr %3, align 8, !tbaa !5
  %17 = call i32 @TcpRcvWinNow(ptr noundef %16)
  store i32 %17, ptr %5, align 4, !tbaa !22
  %18 = load i32, ptr %5, align 4, !tbaa !22
  %19 = load ptr, ptr %3, align 8, !tbaa !5
  %20 = getelementptr inbounds %struct._TCP_CB, ptr %19, i32 0, i32 23
  store i32 %18, ptr %20, align 8, !tbaa !23
  br label %21

21:                                               ; preds = %15, %8
  %22 = load i32, ptr %5, align 4, !tbaa !22
  %23 = load ptr, ptr %3, align 8, !tbaa !5
  %24 = getelementptr inbounds %struct._TCP_CB, ptr %23, i32 0, i32 35
  %25 = load i8, ptr %24, align 2, !tbaa !24
  %26 = zext i8 %25 to i32
  %27 = lshr i32 %22, %26
  %28 = icmp ult i32 %27, 65535
  br i1 %28, label %29, label %36

29:                                               ; preds = %21
  %30 = load i32, ptr %5, align 4, !tbaa !22
  %31 = load ptr, ptr %3, align 8, !tbaa !5
  %32 = getelementptr inbounds %struct._TCP_CB, ptr %31, i32 0, i32 35
  %33 = load i8, ptr %32, align 2, !tbaa !24
  %34 = zext i8 %33 to i32
  %35 = lshr i32 %30, %34
  br label %37

36:                                               ; preds = %21
  br label %37

37:                                               ; preds = %36, %29
  %38 = phi i32 [ %35, %29 ], [ 65535, %36 ]
  store i32 %38, ptr %5, align 4, !tbaa !22
  %39 = load i32, ptr %5, align 4, !tbaa !22
  %40 = trunc i32 %39 to i16
  %41 = call zeroext i16 @SwapBytes16(i16 noundef zeroext %40)
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #3
  ret i16 %41
}

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

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


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

; Function Attrs: nounwind uwtable
declare dso_local i32 @TcpRcvWinNow(ptr noundef) local_unnamed_addr #0

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

3:                                                ; preds = %2
  %4 = getelementptr inbounds i8, ptr %0, i64 24
  %5 = load ptr, ptr %4, align 8, !tbaa !5
  %6 = getelementptr inbounds i8, ptr %5, i64 112
  %7 = load i32, ptr %6, align 8, !tbaa !15
  br label %11

8:                                                ; preds = %2
  %9 = tail call i32 @TcpRcvWinNow(ptr noundef %0)
  %10 = getelementptr inbounds i8, ptr %0, i64 136
  store i32 %9, ptr %10, align 8, !tbaa !20
  br label %11

11:                                               ; preds = %8, %3
  %.0 = phi i32 [ %7, %3 ], [ %9, %8 ]
  %12 = getelementptr inbounds i8, ptr %0, i64 194
  %13 = load i8, ptr %12, align 2, !tbaa !21
  %14 = zext nneg i8 %13 to i32
  %15 = lshr i32 %.0, %14
  %spec.select10 = tail call i32 @llvm.umin.i32(i32 %15, i32 65535)
  %spec.select = trunc nuw i32 %spec.select10 to i16
  %16 = tail call zeroext i16 @SwapBytes16(i16 noundef zeroext %spec.select) #3
  ret i16 %16
}

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

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i32 @llvm.umin.i32(i32, i32) #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 = { "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 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
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, !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, !12, i64 112}
!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 = !{!6, !12, i64 136}
!21 = !{!6, !9, i64 194}


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