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

; 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.EFI_TCP4_IO_TOKEN = type { %struct.EFI_TCP4_COMPLETION_TOKEN, %union.anon }
%struct.EFI_TCP4_COMPLETION_TOKEN = type { ptr, i64 }
%union.anon = type { ptr }
%struct.EFI_TCP4_TRANSMIT_DATA = type { i8, i8, i32, i32, [1 x %struct.EFI_TCP4_FRAGMENT_DATA] }
%struct.EFI_TCP4_FRAGMENT_DATA = type { i32, ptr }
%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 }
%struct._LIST_ENTRY = type { ptr, ptr }
%union._NET_PROTOCOL = type { %struct._EFI_TCP4_PROTOCOL }
%struct._EFI_TCP4_PROTOCOL = type { ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr }

@.str = external hidden unnamed_addr constant [151 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [21 x i8], align 1

; Function Attrs: nounwind uwtable
declare dso_local i64 @Tcp4ChkDataBuf(i32 noundef, i32 noundef, ptr noundef) #0

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #1

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #1

declare zeroext i8 @DebugAssertEnabled() #2

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

; Function Attrs: nounwind uwtable
define dso_local i64 @Tcp4Transmit(ptr noundef %0, ptr noundef %1) #0 {
  %3 = alloca i64, align 8
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca i64, align 8
  %8 = 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) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #3
  %9 = load ptr, ptr %4, align 8, !tbaa !5
  %10 = icmp eq ptr null, %9
  br i1 %10, label %39, label %11

11:                                               ; preds = %2
  %12 = load ptr, ptr %5, align 8, !tbaa !5
  %13 = icmp eq ptr null, %12
  br i1 %13, label %39, label %14

14:                                               ; preds = %11
  %15 = load ptr, ptr %5, align 8, !tbaa !5
  %16 = getelementptr inbounds %struct.EFI_TCP4_IO_TOKEN, ptr %15, i32 0, i32 0
  %17 = getelementptr inbounds %struct.EFI_TCP4_COMPLETION_TOKEN, ptr %16, i32 0, i32 0
  %18 = load ptr, ptr %17, align 8, !tbaa !9
  %19 = icmp eq ptr null, %18
  br i1 %19, label %39, label %20

20:                                               ; preds = %14
  %21 = load ptr, ptr %5, align 8, !tbaa !5
  %22 = getelementptr inbounds %struct.EFI_TCP4_IO_TOKEN, ptr %21, i32 0, i32 1
  %23 = load ptr, ptr %22, align 8, !tbaa !13
  %24 = icmp eq ptr null, %23
  br i1 %24, label %39, label %25

25:                                               ; preds = %20
  %26 = load ptr, ptr %5, align 8, !tbaa !5
  %27 = getelementptr inbounds %struct.EFI_TCP4_IO_TOKEN, ptr %26, i32 0, i32 1
  %28 = load ptr, ptr %27, align 8, !tbaa !13
  %29 = getelementptr inbounds %struct.EFI_TCP4_TRANSMIT_DATA, ptr %28, i32 0, i32 3
  %30 = load i32, ptr %29, align 8, !tbaa !14
  %31 = icmp eq i32 0, %30
  br i1 %31, label %39, label %32

32:                                               ; preds = %25
  %33 = load ptr, ptr %5, align 8, !tbaa !5
  %34 = getelementptr inbounds %struct.EFI_TCP4_IO_TOKEN, ptr %33, i32 0, i32 1
  %35 = load ptr, ptr %34, align 8, !tbaa !13
  %36 = getelementptr inbounds %struct.EFI_TCP4_TRANSMIT_DATA, ptr %35, i32 0, i32 2
  %37 = load i32, ptr %36, align 4, !tbaa !17
  %38 = icmp eq i32 0, %37
  br i1 %38, label %39, label %40

39:                                               ; preds = %32, %25, %20, %14, %11, %2
  store i64 -9223372036854775806, ptr %3, align 8
  store i32 1, ptr %8, align 4
  br label %85

40:                                               ; preds = %32
  %41 = load ptr, ptr %5, align 8, !tbaa !5
  %42 = getelementptr inbounds %struct.EFI_TCP4_IO_TOKEN, ptr %41, i32 0, i32 1
  %43 = load ptr, ptr %42, align 8, !tbaa !13
  %44 = getelementptr inbounds %struct.EFI_TCP4_TRANSMIT_DATA, ptr %43, i32 0, i32 2
  %45 = load i32, ptr %44, align 4, !tbaa !17
  %46 = load ptr, ptr %5, align 8, !tbaa !5
  %47 = getelementptr inbounds %struct.EFI_TCP4_IO_TOKEN, ptr %46, i32 0, i32 1
  %48 = load ptr, ptr %47, align 8, !tbaa !13
  %49 = getelementptr inbounds %struct.EFI_TCP4_TRANSMIT_DATA, ptr %48, i32 0, i32 3
  %50 = load i32, ptr %49, align 8, !tbaa !14
  %51 = load ptr, ptr %5, align 8, !tbaa !5
  %52 = getelementptr inbounds %struct.EFI_TCP4_IO_TOKEN, ptr %51, i32 0, i32 1
  %53 = load ptr, ptr %52, align 8, !tbaa !13
  %54 = getelementptr inbounds %struct.EFI_TCP4_TRANSMIT_DATA, ptr %53, i32 0, i32 4
  %55 = getelementptr inbounds [1 x %struct.EFI_TCP4_FRAGMENT_DATA], ptr %54, i64 0, i64 0
  %56 = call i64 @Tcp4ChkDataBuf(i32 noundef %45, i32 noundef %50, ptr noundef %55)
  store i64 %56, ptr %7, align 8, !tbaa !18
  %57 = load i64, ptr %7, align 8, !tbaa !18
  %58 = icmp slt i64 %57, 0
  br i1 %58, label %59, label %61

59:                                               ; preds = %40
  %60 = load i64, ptr %7, align 8, !tbaa !18
  store i64 %60, ptr %3, align 8
  store i32 1, ptr %8, align 4
  br label %85

61:                                               ; preds = %40
  %62 = call zeroext i8 @DebugAssertEnabled()
  %63 = zext i8 %62 to i32
  %64 = icmp ne i32 %63, 0
  br i1 %64, label %65, label %75

65:                                               ; preds = %61
  %66 = load ptr, ptr %4, align 8, !tbaa !5
  %67 = ptrtoint ptr %66 to i64
  %68 = sub i64 %67, ptrtoint (ptr getelementptr inbounds (%struct._SOCKET, ptr null, i32 0, i32 27) to i64)
  %69 = inttoptr i64 %68 to ptr
  %70 = getelementptr inbounds %struct._SOCKET, ptr %69, i32 0, i32 0
  %71 = load i32, ptr %70, align 8, !tbaa !19
  %72 = icmp ne i32 %71, 1262702419
  br i1 %72, label %73, label %75

73:                                               ; preds = %65
  call void @DebugAssert(ptr noundef @.str, i64 noundef 451, ptr noundef @.str.1)
  %74 = load ptr, ptr %4, align 8, !tbaa !5
  br label %80

75:                                               ; preds = %65, %61
  %76 = load ptr, ptr %4, align 8, !tbaa !5
  %77 = ptrtoint ptr %76 to i64
  %78 = sub i64 %77, ptrtoint (ptr getelementptr inbounds (%struct._SOCKET, ptr null, i32 0, i32 27) to i64)
  %79 = inttoptr i64 %78 to ptr
  br label %80

80:                                               ; preds = %75, %73
  %81 = phi ptr [ %74, %73 ], [ %79, %75 ]
  store ptr %81, ptr %6, align 8, !tbaa !5
  %82 = load ptr, ptr %6, align 8, !tbaa !5
  %83 = load ptr, ptr %5, align 8, !tbaa !5
  %84 = call i64 @SockSend(ptr noundef %82, ptr noundef %83)
  store i64 %84, ptr %3, align 8
  store i32 1, ptr %8, align 4
  br label %85

85:                                               ; preds = %80, %59, %39
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #3
  %86 = load i64, ptr %3, align 8
  ret i64 %86
}

declare i64 @SockSend(ptr noundef, ptr noundef) #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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 0}
!10 = !{!"", !11, i64 0, !7, i64 16}
!11 = !{!"", !6, i64 0, !12, i64 8}
!12 = !{!"long long", !7, i64 0}
!13 = !{!7, !7, i64 0}
!14 = !{!15, !16, i64 8}
!15 = !{!"", !7, i64 0, !7, i64 1, !16, i64 4, !16, i64 8, !7, i64 16}
!16 = !{!"int", !7, i64 0}
!17 = !{!15, !16, i64 4}
!18 = !{!12, !12, i64 0}
!19 = !{!20, !16, i64 0}
!20 = !{!"_SOCKET", !16, i64 0, !6, i64 8, !6, i64 16, !6, i64 24, !6, i64 32, !21, i64 40, !7, i64 56, !16, i64 60, !7, i64 64, !22, i64 66, !23, i64 72, !24, i64 96, !24, i64 112, !12, i64 128, !7, i64 136, !16, i64 140, !16, i64 144, !6, i64 152, !21, i64 160, !21, i64 176, !21, i64 192, !21, i64 208, !21, 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}
!21 = !{!"_LIST_ENTRY", !6, i64 0, !6, i64 8}
!22 = !{!"short", !7, i64 0}
!23 = !{!"", !12, i64 0, !12, i64 8, !16, i64 16}
!24 = !{!"_SOCK_BUFFER", !16, i64 0, !16, i64 4, !6, i64 8}


; 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 [151 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [21 x i8], align 1

; Function Attrs: nounwind uwtable
declare dso_local i64 @Tcp4ChkDataBuf(i32 noundef, i32 noundef, ptr 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

; Function Attrs: nounwind uwtable
define dso_local i64 @Tcp4Transmit(ptr noundef %0, ptr noundef %1) local_unnamed_addr #0 {
  %3 = icmp eq ptr %0, null
  %4 = icmp eq ptr %1, null
  %or.cond = or i1 %3, %4
  br i1 %or.cond, label %31, label %5

5:                                                ; preds = %2
  %6 = load ptr, ptr %1, align 8, !tbaa !5
  %7 = icmp eq ptr %6, null
  br i1 %7, label %31, label %8

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

12:                                               ; preds = %8
  %13 = getelementptr inbounds i8, ptr %10, i64 8
  %14 = load i32, ptr %13, align 8, !tbaa !13
  %15 = icmp eq i32 %14, 0
  br i1 %15, label %31, label %16

16:                                               ; preds = %12
  %17 = getelementptr inbounds i8, ptr %10, i64 4
  %18 = load i32, ptr %17, align 4, !tbaa !16
  %19 = icmp eq i32 %18, 0
  br i1 %19, label %31, label %20

20:                                               ; preds = %16
  %21 = getelementptr inbounds i8, ptr %10, i64 16
  %22 = tail call i64 @Tcp4ChkDataBuf(i32 noundef %18, i32 noundef %14, ptr noundef nonnull %21)
  %23 = icmp slt i64 %22, 0
  br i1 %23, label %31, label %24

24:                                               ; preds = %20
  %25 = tail call zeroext i8 @DebugAssertEnabled() #2
  %.not = icmp eq i8 %25, 0
  %.pre = ptrtoint ptr %0 to i64
  %.pre24 = add i64 %.pre, -288
  %.pre26 = inttoptr i64 %.pre24 to ptr
  br i1 %.not, label %._crit_edge, label %26

26:                                               ; preds = %24
  %27 = load i32, ptr %.pre26, align 8, !tbaa !17
  %.not23 = icmp eq i32 %27, 1262702419
  br i1 %.not23, label %._crit_edge, label %28

28:                                               ; preds = %26
  tail call void @DebugAssert(ptr noundef nonnull @.str, i64 noundef 451, ptr noundef nonnull @.str.1) #2
  br label %._crit_edge

._crit_edge:                                      ; preds = %24, %26, %28
  %29 = phi ptr [ %0, %28 ], [ %.pre26, %26 ], [ %.pre26, %24 ]
  %30 = tail call i64 @SockSend(ptr noundef %29, ptr noundef nonnull %1) #2
  br label %31

31:                                               ; preds = %20, %2, %5, %8, %12, %16, %._crit_edge
  %.0 = phi i64 [ %30, %._crit_edge ], [ -9223372036854775806, %16 ], [ -9223372036854775806, %12 ], [ -9223372036854775806, %8 ], [ -9223372036854775806, %5 ], [ -9223372036854775806, %2 ], [ %22, %20 ]
  ret i64 %.0
}

declare i64 @SockSend(ptr noundef, ptr noundef) local_unnamed_addr #1

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, !8, i64 0}
!6 = !{!"", !7, i64 0, !9, i64 16}
!7 = !{!"", !8, i64 0, !11, i64 8}
!8 = !{!"any pointer", !9, i64 0}
!9 = !{!"omnipotent char", !10, i64 0}
!10 = !{!"Simple C/C++ TBAA"}
!11 = !{!"long long", !9, i64 0}
!12 = !{!9, !9, i64 0}
!13 = !{!14, !15, i64 8}
!14 = !{!"", !9, i64 0, !9, i64 1, !15, i64 4, !15, i64 8, !9, i64 16}
!15 = !{!"int", !9, i64 0}
!16 = !{!14, !15, i64 4}
!17 = !{!18, !15, i64 0}
!18 = !{!"_SOCKET", !15, i64 0, !8, i64 8, !8, i64 16, !8, i64 24, !8, i64 32, !19, i64 40, !9, i64 56, !15, i64 60, !9, i64 64, !20, i64 66, !21, i64 72, !22, i64 96, !22, i64 112, !11, i64 128, !9, i64 136, !15, i64 140, !15, i64 144, !8, i64 152, !19, i64 160, !19, i64 176, !19, i64 192, !19, i64 208, !19, 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}
!19 = !{!"_LIST_ENTRY", !8, i64 0, !8, i64 8}
!20 = !{!"short", !9, i64 0}
!21 = !{!"", !11, i64 0, !11, i64 8, !15, i64 16}
!22 = !{!"_SOCK_BUFFER", !15, i64 0, !15, i64 4, !8, i64 8}


; Effective O3 passes: BDCEPass,EarlyCSEPass,GVNPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,SROAPass,SimplifyCFGPass,TailCallElimPass