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

; 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.NET_BUF = type { i32, i64, %struct._LIST_ENTRY, %union.NET_IP_HEAD, ptr, ptr, [64 x i8], ptr, i32, i32, [1 x %struct.NET_BLOCK_OP] }
%struct._LIST_ENTRY = type { ptr, ptr }
%union.NET_IP_HEAD = type { ptr }
%struct.NET_BLOCK_OP = type { ptr, ptr, ptr, ptr, i32 }
%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] }
%struct._TCP_SEG = type { i32, i32, i32, i8, i16, i32 }

@.str = external hidden unnamed_addr constant [153 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [79 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [21 x i8], align 1
@mTcpTick = external global i32, align 4

; 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 void @TcpPutUint32(ptr noundef, i32 noundef) #1

declare zeroext i8 @DebugAssertEnabled() #2

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

declare ptr @NetbufAllocSpace(ptr noundef, i32 noundef, i8 noundef zeroext) #2

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

7:                                                ; preds = %2
  %8 = call zeroext i8 @DebugAssertEnabled()
  %9 = icmp ne i8 %8, 0
  br i1 %9, label %10, label %23

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

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

16:                                               ; preds = %13
  %17 = load ptr, ptr %4, align 8, !tbaa !5
  %18 = getelementptr inbounds %struct.NET_BUF, ptr %17, i32 0, i32 4
  %19 = load ptr, ptr %18, align 8, !tbaa !9
  %20 = icmp eq ptr %19, null
  br i1 %20, label %22, label %21

21:                                               ; preds = %16, %13, %10
  call void @DebugAssert(ptr noundef @.str, i64 noundef 199, ptr noundef @.str.2)
  br label %22

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

23:                                               ; preds = %22, %7
  br label %24

24:                                               ; preds = %23
  br label %25

25:                                               ; preds = %24
  store i16 0, ptr %6, align 2, !tbaa !14
  %26 = load ptr, ptr %3, align 8, !tbaa !5
  %27 = getelementptr inbounds %struct._TCP_CB, ptr %26, i32 0, i32 7
  %28 = load i32, ptr %27, align 8, !tbaa !16
  %29 = and i32 %28, 64
  %30 = icmp ne i32 %29, 0
  %31 = zext i1 %30 to i32
  %32 = trunc i32 %31 to i8
  %33 = zext i8 %32 to i32
  %34 = icmp ne i32 %33, 0
  br i1 %34, label %35, label %74

35:                                               ; preds = %25
  %36 = load ptr, ptr %4, align 8, !tbaa !5
  %37 = getelementptr inbounds %struct.NET_BUF, ptr %36, i32 0, i32 6
  %38 = getelementptr inbounds [64 x i8], ptr %37, i64 0, i64 0
  %39 = getelementptr inbounds %struct._TCP_SEG, ptr %38, i32 0, i32 3
  %40 = load i8, ptr %39, align 4, !tbaa !20
  %41 = zext i8 %40 to i32
  %42 = and i32 %41, 4
  %43 = icmp ne i32 %42, 0
  %44 = zext i1 %43 to i32
  %45 = trunc i32 %44 to i8
  %46 = icmp ne i8 %45, 0
  br i1 %46, label %74, label %47

47:                                               ; preds = %35
  %48 = load ptr, ptr %4, align 8, !tbaa !5
  %49 = call ptr @NetbufAllocSpace(ptr noundef %48, i32 noundef 12, i8 noundef zeroext 1)
  store ptr %49, ptr %5, align 8, !tbaa !5
  br label %50

50:                                               ; preds = %47
  %51 = call zeroext i8 @DebugAssertEnabled()
  %52 = icmp ne i8 %51, 0
  br i1 %52, label %53, label %58

53:                                               ; preds = %50
  %54 = load ptr, ptr %5, align 8, !tbaa !5
  %55 = icmp ne ptr %54, null
  br i1 %55, label %57, label %56

56:                                               ; preds = %53
  call void @DebugAssert(ptr noundef @.str, i64 noundef 214, ptr noundef @.str.3)
  br label %57

57:                                               ; preds = %56, %53
  br label %58

58:                                               ; preds = %57, %50
  br label %59

59:                                               ; preds = %58
  br label %60

60:                                               ; preds = %59
  %61 = load i16, ptr %6, align 2, !tbaa !14
  %62 = zext i16 %61 to i32
  %63 = add nsw i32 %62, 12
  %64 = trunc i32 %63 to i16
  store i16 %64, ptr %6, align 2, !tbaa !14
  %65 = load ptr, ptr %5, align 8, !tbaa !5
  call void @TcpPutUint32(ptr noundef %65, i32 noundef 16844810)
  %66 = load ptr, ptr %5, align 8, !tbaa !5
  %67 = getelementptr inbounds i8, ptr %66, i64 4
  %68 = load i32, ptr @mTcpTick, align 4, !tbaa !22
  call void @TcpPutUint32(ptr noundef %67, i32 noundef %68)
  %69 = load ptr, ptr %5, align 8, !tbaa !5
  %70 = getelementptr inbounds i8, ptr %69, i64 8
  %71 = load ptr, ptr %3, align 8, !tbaa !5
  %72 = getelementptr inbounds %struct._TCP_CB, ptr %71, i32 0, i32 36
  %73 = load i32, ptr %72, align 4, !tbaa !23
  call void @TcpPutUint32(ptr noundef %70, i32 noundef %73)
  br label %74

74:                                               ; preds = %60, %35, %25
  %75 = load i16, ptr %6, align 2, !tbaa !14
  call void @llvm.lifetime.end.p0(i64 2, ptr %6) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #3
  ret i16 %75
}

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


; 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 = external hidden unnamed_addr constant [153 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [79 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [21 x i8], align 1
@mTcpTick = external local_unnamed_addr global i32, align 4

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

declare zeroext i8 @DebugAssertEnabled() local_unnamed_addr #1

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

declare ptr @NetbufAllocSpace(ptr noundef, i32 noundef, i8 noundef zeroext) local_unnamed_addr #1

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

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

7:                                                ; preds = %4
  %8 = getelementptr inbounds i8, ptr %1, i64 40
  %9 = load ptr, ptr %8, align 8, !tbaa !5
  %10 = icmp eq ptr %9, null
  br i1 %10, label %12, label %11

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

12:                                               ; preds = %7, %11, %2
  %13 = getelementptr inbounds i8, ptr %0, i64 80
  %14 = load i32, ptr %13, align 8, !tbaa !13
  %15 = and i32 %14, 64
  %.not16 = icmp eq i32 %15, 0
  br i1 %.not16, label %32, label %16

16:                                               ; preds = %12
  %17 = getelementptr inbounds i8, ptr %1, i64 68
  %18 = load i8, ptr %17, align 4, !tbaa !18
  %19 = and i8 %18, 4
  %.not17 = icmp eq i8 %19, 0
  br i1 %.not17, label %20, label %32

20:                                               ; preds = %16
  %21 = tail call ptr @NetbufAllocSpace(ptr noundef nonnull %1, i32 noundef 12, i8 noundef zeroext 1) #2
  %22 = tail call zeroext i8 @DebugAssertEnabled() #2
  %23 = icmp eq i8 %22, 0
  %24 = icmp ne ptr %21, null
  %or.cond3 = select i1 %23, i1 true, i1 %24
  br i1 %or.cond3, label %26, label %25

25:                                               ; preds = %20
  tail call void @DebugAssert(ptr noundef nonnull @.str, i64 noundef 214, ptr noundef nonnull @.str.3) #2
  br label %26

26:                                               ; preds = %25, %20
  tail call void @TcpPutUint32(ptr noundef %21, i32 noundef 16844810)
  %27 = getelementptr inbounds i8, ptr %21, i64 4
  %28 = load i32, ptr @mTcpTick, align 4, !tbaa !20
  tail call void @TcpPutUint32(ptr noundef nonnull %27, i32 noundef %28)
  %29 = getelementptr inbounds i8, ptr %21, i64 8
  %30 = getelementptr inbounds i8, ptr %0, i64 196
  %31 = load i32, ptr %30, align 4, !tbaa !21
  tail call void @TcpPutUint32(ptr noundef nonnull %29, i32 noundef %31)
  br label %32

32:                                               ; preds = %26, %16, %12
  %.0 = phi i16 [ 0, %16 ], [ 12, %26 ], [ 0, %12 ]
  ret i16 %.0
}

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


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