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

; 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.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._TCP4_IO = type { ptr, ptr, ptr, ptr, %struct.EFI_TCP4_CONNECTION_TOKEN, %struct.EFI_TCP4_IO_TOKEN, %struct.EFI_TCP4_IO_TOKEN, %struct.EFI_TCP4_CLOSE_TOKEN, i8, i8, i8, i8 }
%struct.EFI_TCP4_CONNECTION_TOKEN = type { %struct.EFI_TCP4_COMPLETION_TOKEN }
%struct.EFI_TCP4_COMPLETION_TOKEN = type { ptr, i64 }
%struct.EFI_TCP4_IO_TOKEN = type { %struct.EFI_TCP4_COMPLETION_TOKEN, %union.anon }
%union.anon = type { ptr }
%struct.EFI_TCP4_CLOSE_TOKEN = type { %struct.EFI_TCP4_COMPLETION_TOKEN, i8 }
%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
define dso_local i64 @Tcp4IoTransmit(ptr noundef %0, ptr noundef %1) #1 {
  %3 = alloca i64, align 8
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca i64, align 8
  %9 = 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
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #3
  %10 = load ptr, ptr %5, align 8, !tbaa !5
  %11 = getelementptr inbounds %struct.NET_BUF, ptr %10, i32 0, i32 8
  %12 = load i32, ptr %11, align 8, !tbaa !9
  %13 = sub i32 %12, 1
  %14 = zext i32 %13 to i64
  %15 = mul i64 %14, 16
  %16 = add i64 32, %15
  %17 = call ptr @AllocatePool(i64 noundef %16)
  store ptr %17, ptr %6, align 8, !tbaa !5
  %18 = load ptr, ptr %6, align 8, !tbaa !5
  %19 = icmp eq ptr %18, null
  br i1 %19, label %20, label %21

20:                                               ; preds = %2
  store i64 -9223372036854775799, ptr %3, align 8
  store i32 1, ptr %9, align 4
  br label %84

21:                                               ; preds = %2
  %22 = load ptr, ptr %6, align 8, !tbaa !5
  %23 = getelementptr inbounds %struct.EFI_TCP4_TRANSMIT_DATA, ptr %22, i32 0, i32 0
  store i8 1, ptr %23, align 8, !tbaa !14
  %24 = load ptr, ptr %6, align 8, !tbaa !5
  %25 = getelementptr inbounds %struct.EFI_TCP4_TRANSMIT_DATA, ptr %24, i32 0, i32 1
  store i8 0, ptr %25, align 1, !tbaa !16
  %26 = load ptr, ptr %5, align 8, !tbaa !5
  %27 = getelementptr inbounds %struct.NET_BUF, ptr %26, i32 0, i32 9
  %28 = load i32, ptr %27, align 4, !tbaa !17
  %29 = load ptr, ptr %6, align 8, !tbaa !5
  %30 = getelementptr inbounds %struct.EFI_TCP4_TRANSMIT_DATA, ptr %29, i32 0, i32 2
  store i32 %28, ptr %30, align 4, !tbaa !18
  %31 = load ptr, ptr %5, align 8, !tbaa !5
  %32 = getelementptr inbounds %struct.NET_BUF, ptr %31, i32 0, i32 8
  %33 = load i32, ptr %32, align 8, !tbaa !9
  %34 = load ptr, ptr %6, align 8, !tbaa !5
  %35 = getelementptr inbounds %struct.EFI_TCP4_TRANSMIT_DATA, ptr %34, i32 0, i32 3
  store i32 %33, ptr %35, align 8, !tbaa !19
  %36 = load ptr, ptr %5, align 8, !tbaa !5
  %37 = load ptr, ptr %6, align 8, !tbaa !5
  %38 = getelementptr inbounds %struct.EFI_TCP4_TRANSMIT_DATA, ptr %37, i32 0, i32 4
  %39 = getelementptr inbounds [1 x %struct.EFI_TCP4_FRAGMENT_DATA], ptr %38, i64 0, i64 0
  %40 = load ptr, ptr %6, align 8, !tbaa !5
  %41 = getelementptr inbounds %struct.EFI_TCP4_TRANSMIT_DATA, ptr %40, i32 0, i32 3
  %42 = call i64 @NetbufBuildExt(ptr noundef %36, ptr noundef %39, ptr noundef %41)
  %43 = load ptr, ptr %6, align 8, !tbaa !5
  %44 = load ptr, ptr %4, align 8, !tbaa !5
  %45 = getelementptr inbounds %struct._TCP4_IO, ptr %44, i32 0, i32 5
  %46 = getelementptr inbounds %struct.EFI_TCP4_IO_TOKEN, ptr %45, i32 0, i32 1
  store ptr %43, ptr %46, align 8, !tbaa !20
  %47 = load ptr, ptr %4, align 8, !tbaa !5
  %48 = getelementptr inbounds %struct._TCP4_IO, ptr %47, i32 0, i32 3
  %49 = load ptr, ptr %48, align 8, !tbaa !21
  store ptr %49, ptr %7, align 8, !tbaa !5
  %50 = load ptr, ptr %7, align 8, !tbaa !5
  %51 = getelementptr inbounds %struct._EFI_TCP4_PROTOCOL, ptr %50, i32 0, i32 5
  %52 = load ptr, ptr %51, align 8, !tbaa !26
  %53 = load ptr, ptr %7, align 8, !tbaa !5
  %54 = load ptr, ptr %4, align 8, !tbaa !5
  %55 = getelementptr inbounds %struct._TCP4_IO, ptr %54, i32 0, i32 5
  %56 = call i64 %52(ptr noundef %53, ptr noundef %55)
  store i64 %56, ptr %8, align 8, !tbaa !28
  %57 = load i64, ptr %8, align 8, !tbaa !28
  %58 = icmp slt i64 %57, 0
  br i1 %58, label %59, label %60

59:                                               ; preds = %21
  br label %81

60:                                               ; preds = %21
  br label %61

61:                                               ; preds = %67, %60
  %62 = load ptr, ptr %4, align 8, !tbaa !5
  %63 = getelementptr inbounds %struct._TCP4_IO, ptr %62, i32 0, i32 9
  %64 = load i8, ptr %63, align 1, !tbaa !29
  %65 = icmp ne i8 %64, 0
  %66 = xor i1 %65, true
  br i1 %66, label %67, label %73

67:                                               ; preds = %61
  %68 = load ptr, ptr %7, align 8, !tbaa !5
  %69 = getelementptr inbounds %struct._EFI_TCP4_PROTOCOL, ptr %68, i32 0, i32 9
  %70 = load ptr, ptr %69, align 8, !tbaa !30
  %71 = load ptr, ptr %7, align 8, !tbaa !5
  %72 = call i64 %70(ptr noundef %71)
  br label %61, !llvm.loop !31

73:                                               ; preds = %61
  %74 = load ptr, ptr %4, align 8, !tbaa !5
  %75 = getelementptr inbounds %struct._TCP4_IO, ptr %74, i32 0, i32 9
  store i8 0, ptr %75, align 1, !tbaa !29
  %76 = load ptr, ptr %4, align 8, !tbaa !5
  %77 = getelementptr inbounds %struct._TCP4_IO, ptr %76, i32 0, i32 5
  %78 = getelementptr inbounds %struct.EFI_TCP4_IO_TOKEN, ptr %77, i32 0, i32 0
  %79 = getelementptr inbounds %struct.EFI_TCP4_COMPLETION_TOKEN, ptr %78, i32 0, i32 1
  %80 = load i64, ptr %79, align 8, !tbaa !33
  store i64 %80, ptr %8, align 8, !tbaa !28
  br label %81

81:                                               ; preds = %73, %59
  %82 = load ptr, ptr %6, align 8, !tbaa !5
  call void @FreePool(ptr noundef %82)
  %83 = load i64, ptr %8, align 8, !tbaa !28
  store i64 %83, ptr %3, align 8
  store i32 1, ptr %9, align 4
  br label %84

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

declare ptr @AllocatePool(i64 noundef) #2

declare i64 @NetbufBuildExt(ptr noundef, ptr noundef, ptr noundef) #2

declare void @FreePool(ptr noundef) #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 = !{!10, !11, i64 128}
!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, !7, i64 0}
!15 = !{!"", !7, i64 0, !7, i64 1, !11, i64 4, !11, i64 8, !7, i64 16}
!16 = !{!15, !7, i64 1}
!17 = !{!10, !11, i64 132}
!18 = !{!15, !11, i64 4}
!19 = !{!15, !11, i64 8}
!20 = !{!7, !7, i64 0}
!21 = !{!22, !6, i64 24}
!22 = !{!"_TCP4_IO", !6, i64 0, !6, i64 8, !6, i64 16, !6, i64 24, !23, i64 32, !25, i64 48, !25, i64 72, !25, i64 96, !7, i64 120, !7, i64 121, !7, i64 122, !7, i64 123}
!23 = !{!"", !24, i64 0}
!24 = !{!"", !6, i64 0, !12, i64 8}
!25 = !{!"", !24, i64 0, !7, i64 16}
!26 = !{!27, !6, i64 40}
!27 = !{!"_EFI_TCP4_PROTOCOL", !6, i64 0, !6, i64 8, !6, i64 16, !6, i64 24, !6, i64 32, !6, i64 40, !6, i64 48, !6, i64 56, !6, i64 64, !6, i64 72}
!28 = !{!12, !12, i64 0}
!29 = !{!22, !7, i64 121}
!30 = !{!27, !6, i64 72}
!31 = distinct !{!31, !32}
!32 = !{!"llvm.loop.mustprogress"}
!33 = !{!22, !12, i64 56}


; 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
define dso_local i64 @Tcp4IoTransmit(ptr noundef %0, ptr noundef %1) local_unnamed_addr #0 {
  %3 = getelementptr inbounds i8, ptr %1, i64 128
  %4 = load i32, ptr %3, align 8, !tbaa !5
  %5 = add i32 %4, -1
  %6 = zext i32 %5 to i64
  %7 = shl nuw nsw i64 %6, 4
  %8 = add nuw nsw i64 %7, 32
  %9 = tail call ptr @AllocatePool(i64 noundef %8) #2
  %10 = icmp eq ptr %9, null
  br i1 %10, label %37, label %11

11:                                               ; preds = %2
  store i8 1, ptr %9, align 8, !tbaa !13
  %12 = getelementptr inbounds i8, ptr %9, i64 1
  store i8 0, ptr %12, align 1, !tbaa !15
  %13 = getelementptr inbounds i8, ptr %9, i64 4
  %14 = getelementptr inbounds i8, ptr %9, i64 8
  %15 = load <2 x i32>, ptr %3, align 8, !tbaa !16
  %16 = shufflevector <2 x i32> %15, <2 x i32> poison, <2 x i32> <i32 1, i32 0>
  store <2 x i32> %16, ptr %13, align 4, !tbaa !16
  %17 = getelementptr inbounds i8, ptr %9, i64 16
  %18 = tail call i64 @NetbufBuildExt(ptr noundef nonnull %1, ptr noundef nonnull %17, ptr noundef nonnull %14) #2
  %19 = getelementptr inbounds i8, ptr %0, i64 48
  %20 = getelementptr inbounds i8, ptr %0, i64 64
  store ptr %9, ptr %20, align 8, !tbaa !17
  %21 = getelementptr inbounds i8, ptr %0, i64 24
  %22 = load ptr, ptr %21, align 8, !tbaa !18
  %23 = getelementptr inbounds i8, ptr %22, i64 40
  %24 = load ptr, ptr %23, align 8, !tbaa !23
  %25 = tail call i64 %24(ptr noundef %22, ptr noundef nonnull %19) #2
  %26 = icmp slt i64 %25, 0
  br i1 %26, label %36, label %.preheader

.preheader:                                       ; preds = %11
  %27 = getelementptr inbounds i8, ptr %0, i64 121
  %28 = load i8, ptr %27, align 1, !tbaa !25
  %.not28 = icmp eq i8 %28, 0
  br i1 %.not28, label %.lr.ph, label %._crit_edge

.lr.ph:                                           ; preds = %.preheader
  %29 = getelementptr inbounds i8, ptr %22, i64 72
  br label %30

30:                                               ; preds = %.lr.ph, %30
  %31 = load ptr, ptr %29, align 8, !tbaa !26
  %32 = tail call i64 %31(ptr noundef nonnull %22) #2
  %33 = load i8, ptr %27, align 1, !tbaa !25
  %.not = icmp eq i8 %33, 0
  br i1 %.not, label %30, label %._crit_edge, !llvm.loop !27

._crit_edge:                                      ; preds = %30, %.preheader
  store i8 0, ptr %27, align 1, !tbaa !25
  %34 = getelementptr inbounds i8, ptr %0, i64 56
  %35 = load i64, ptr %34, align 8, !tbaa !29
  br label %36

36:                                               ; preds = %11, %._crit_edge
  %.0 = phi i64 [ %25, %11 ], [ %35, %._crit_edge ]
  tail call void @FreePool(ptr noundef nonnull %9) #2
  br label %37

37:                                               ; preds = %2, %36
  %.025 = phi i64 [ %.0, %36 ], [ -9223372036854775799, %2 ]
  ret i64 %.025
}

declare ptr @AllocatePool(i64 noundef) local_unnamed_addr #1

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

declare void @FreePool(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, !7, i64 128}
!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, !8, i64 0}
!14 = !{!"", !8, i64 0, !8, i64 1, !7, i64 4, !7, i64 8, !8, i64 16}
!15 = !{!14, !8, i64 1}
!16 = !{!7, !7, i64 0}
!17 = !{!8, !8, i64 0}
!18 = !{!19, !12, i64 24}
!19 = !{!"_TCP4_IO", !12, i64 0, !12, i64 8, !12, i64 16, !12, i64 24, !20, i64 32, !22, i64 48, !22, i64 72, !22, i64 96, !8, i64 120, !8, i64 121, !8, i64 122, !8, i64 123}
!20 = !{!"", !21, i64 0}
!21 = !{!"", !12, i64 0, !10, i64 8}
!22 = !{!"", !21, i64 0, !8, i64 16}
!23 = !{!24, !12, i64 40}
!24 = !{!"_EFI_TCP4_PROTOCOL", !12, i64 0, !12, i64 8, !12, i64 16, !12, i64 24, !12, i64 32, !12, i64 40, !12, i64 48, !12, i64 56, !12, i64 64, !12, i64 72}
!25 = !{!19, !8, i64 121}
!26 = !{!24, !12, i64 72}
!27 = distinct !{!27, !28}
!28 = !{!"llvm.loop.mustprogress"}
!29 = !{!19, !10, i64 56}


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