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

; 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_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.6 = external hidden unnamed_addr constant [54 x i8], align 1

; Function Attrs: nounwind uwtable
declare dso_local void @SockFreeFoo(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

; Function Attrs: nounwind uwtable
define dso_local i64 @SockProcessTcpSndData(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 ptr, 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
  store ptr %10, ptr %8, align 8, !tbaa !5
  %11 = load ptr, ptr %8, align 8, !tbaa !5
  %12 = getelementptr inbounds %struct.EFI_TCP4_TRANSMIT_DATA, ptr %11, i32 0, i32 4
  %13 = getelementptr inbounds [1 x %struct.EFI_TCP4_FRAGMENT_DATA], ptr %12, i64 0, i64 0
  %14 = load ptr, ptr %8, align 8, !tbaa !5
  %15 = getelementptr inbounds %struct.EFI_TCP4_TRANSMIT_DATA, ptr %14, i32 0, i32 3
  %16 = load i32, ptr %15, align 8, !tbaa !9
  %17 = call ptr @NetbufFromExt(ptr noundef %13, i32 noundef %16, i32 noundef 0, i32 noundef 0, ptr noundef @SockFreeFoo, ptr noundef null)
  store ptr %17, ptr %6, align 8, !tbaa !5
  %18 = load ptr, ptr %6, align 8, !tbaa !5
  %19 = icmp eq ptr null, %18
  br i1 %19, label %20, label %35

20:                                               ; preds = %2
  br label %21

21:                                               ; preds = %20
  %22 = call zeroext i8 @DebugPrintEnabled()
  %23 = icmp ne i8 %22, 0
  br i1 %23, label %24, label %32

24:                                               ; preds = %21
  br label %25

25:                                               ; preds = %24
  %26 = call zeroext i8 @DebugPrintLevelEnabled(i64 noundef 2147483648)
  %27 = icmp ne i8 %26, 0
  br i1 %27, label %28, label %29

28:                                               ; preds = %25
  call void (i64, ptr, ...) @DebugPrint(i64 noundef 2147483648, ptr noundef @.str.6)
  br label %29

29:                                               ; preds = %28, %25
  br label %30

30:                                               ; preds = %29
  br label %31

31:                                               ; preds = %30
  br label %32

32:                                               ; preds = %31, %21
  br label %33

33:                                               ; preds = %32
  br label %34

34:                                               ; preds = %33
  store i64 -9223372036854775799, ptr %3, align 8
  store i32 1, ptr %9, align 4
  br label %83

35:                                               ; preds = %2
  %36 = load ptr, ptr %4, align 8, !tbaa !5
  %37 = getelementptr inbounds %struct._SOCKET, ptr %36, i32 0, i32 11
  %38 = getelementptr inbounds %struct._SOCK_BUFFER, ptr %37, i32 0, i32 2
  %39 = load ptr, ptr %38, align 8, !tbaa !12
  %40 = load ptr, ptr %6, align 8, !tbaa !5
  call void @NetbufQueAppend(ptr noundef %39, ptr noundef %40)
  %41 = load ptr, ptr %8, align 8, !tbaa !5
  %42 = getelementptr inbounds %struct.EFI_TCP4_TRANSMIT_DATA, ptr %41, i32 0, i32 1
  %43 = load i8, ptr %42, align 1, !tbaa !19
  %44 = icmp ne i8 %43, 0
  br i1 %44, label %45, label %56

45:                                               ; preds = %35
  %46 = load ptr, ptr %4, align 8, !tbaa !5
  %47 = getelementptr inbounds %struct._SOCKET, ptr %46, i32 0, i32 25
  %48 = load ptr, ptr %47, align 8, !tbaa !20
  %49 = load ptr, ptr %4, align 8, !tbaa !5
  %50 = call i64 %48(ptr noundef %49, i8 noundef zeroext 6, ptr noundef null)
  store i64 %50, ptr %7, align 8, !tbaa !21
  %51 = load i64, ptr %7, align 8, !tbaa !21
  %52 = icmp slt i64 %51, 0
  br i1 %52, label %53, label %55

53:                                               ; preds = %45
  %54 = load i64, ptr %7, align 8, !tbaa !21
  store i64 %54, ptr %3, align 8
  store i32 1, ptr %9, align 4
  br label %83

55:                                               ; preds = %45
  br label %56

56:                                               ; preds = %55, %35
  %57 = load ptr, ptr %8, align 8, !tbaa !5
  %58 = getelementptr inbounds %struct.EFI_TCP4_TRANSMIT_DATA, ptr %57, i32 0, i32 0
  %59 = load i8, ptr %58, align 8, !tbaa !22
  %60 = icmp ne i8 %59, 0
  br i1 %60, label %61, label %72

61:                                               ; preds = %56
  %62 = load ptr, ptr %4, align 8, !tbaa !5
  %63 = getelementptr inbounds %struct._SOCKET, ptr %62, i32 0, i32 25
  %64 = load ptr, ptr %63, align 8, !tbaa !20
  %65 = load ptr, ptr %4, align 8, !tbaa !5
  %66 = call i64 %64(ptr noundef %65, i8 noundef zeroext 5, ptr noundef null)
  store i64 %66, ptr %7, align 8, !tbaa !21
  %67 = load i64, ptr %7, align 8, !tbaa !21
  %68 = icmp slt i64 %67, 0
  br i1 %68, label %69, label %71

69:                                               ; preds = %61
  %70 = load i64, ptr %7, align 8, !tbaa !21
  store i64 %70, ptr %3, align 8
  store i32 1, ptr %9, align 4
  br label %83

71:                                               ; preds = %61
  br label %72

72:                                               ; preds = %71, %56
  %73 = load ptr, ptr %4, align 8, !tbaa !5
  %74 = getelementptr inbounds %struct._SOCKET, ptr %73, i32 0, i32 25
  %75 = load ptr, ptr %74, align 8, !tbaa !20
  %76 = load ptr, ptr %4, align 8, !tbaa !5
  %77 = call i64 %75(ptr noundef %76, i8 noundef zeroext 4, ptr noundef null)
  store i64 %77, ptr %7, align 8, !tbaa !21
  %78 = load i64, ptr %7, align 8, !tbaa !21
  %79 = icmp slt i64 %78, 0
  br i1 %79, label %80, label %82

80:                                               ; preds = %72
  %81 = load i64, ptr %7, align 8, !tbaa !21
  store i64 %81, ptr %3, align 8
  store i32 1, ptr %9, align 4
  br label %83

82:                                               ; preds = %72
  store i64 0, ptr %3, align 8
  store i32 1, ptr %9, align 4
  br label %83

83:                                               ; preds = %82, %80, %69, %53, %34
  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
  %84 = load i64, ptr %3, align 8
  ret i64 %84
}

declare ptr @NetbufFromExt(ptr noundef, i32 noundef, i32 noundef, i32 noundef, ptr noundef, ptr noundef) #2

declare zeroext i8 @DebugPrintEnabled() #2

declare zeroext i8 @DebugPrintLevelEnabled(i64 noundef) #2

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

declare void @NetbufQueAppend(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, !11, i64 8}
!10 = !{!"", !7, i64 0, !7, i64 1, !11, i64 4, !11, i64 8, !7, i64 16}
!11 = !{!"int", !7, i64 0}
!12 = !{!13, !6, i64 104}
!13 = !{!"_SOCKET", !11, i64 0, !6, i64 8, !6, i64 16, !6, i64 24, !6, i64 32, !14, i64 40, !7, i64 56, !11, i64 60, !7, i64 64, !15, i64 66, !16, i64 72, !18, i64 96, !18, i64 112, !17, i64 128, !7, i64 136, !11, i64 140, !11, i64 144, !6, i64 152, !14, i64 160, !14, i64 176, !14, i64 192, !14, i64 208, !14, 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}
!14 = !{!"_LIST_ENTRY", !6, i64 0, !6, i64 8}
!15 = !{!"short", !7, i64 0}
!16 = !{!"", !17, i64 0, !17, i64 8, !11, i64 16}
!17 = !{!"long long", !7, i64 0}
!18 = !{!"_SOCK_BUFFER", !11, i64 0, !11, i64 4, !6, i64 8}
!19 = !{!10, !7, i64 1}
!20 = !{!13, !6, i64 256}
!21 = !{!17, !17, i64 0}
!22 = !{!10, !7, i64 0}


; 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.6 = external hidden unnamed_addr constant [54 x i8], align 1

; Function Attrs: nounwind uwtable
declare dso_local void @SockFreeFoo(ptr noundef) #0

; Function Attrs: nounwind uwtable
define dso_local range(i64 -9223372036854775808, 1) i64 @SockProcessTcpSndData(ptr noundef %0, ptr noundef %1) local_unnamed_addr #0 {
  %3 = getelementptr inbounds i8, ptr %1, i64 16
  %4 = getelementptr inbounds i8, ptr %1, i64 8
  %5 = load i32, ptr %4, align 8, !tbaa !5
  %6 = tail call ptr @NetbufFromExt(ptr noundef nonnull %3, i32 noundef %5, i32 noundef 0, i32 noundef 0, ptr noundef nonnull @SockFreeFoo, ptr noundef null) #3
  %7 = icmp eq ptr %6, null
  br i1 %7, label %8, label %13

8:                                                ; preds = %2
  %9 = tail call zeroext i8 @DebugPrintEnabled() #3
  %.not25 = icmp eq i8 %9, 0
  br i1 %.not25, label %34, label %10

10:                                               ; preds = %8
  %11 = tail call zeroext i8 @DebugPrintLevelEnabled(i64 noundef 2147483648) #3
  %.not26 = icmp eq i8 %11, 0
  br i1 %.not26, label %34, label %12

12:                                               ; preds = %10
  tail call void (i64, ptr, ...) @DebugPrint(i64 noundef 2147483648, ptr noundef nonnull @.str.6) #3
  br label %34

13:                                               ; preds = %2
  %14 = getelementptr inbounds i8, ptr %0, i64 104
  %15 = load ptr, ptr %14, align 8, !tbaa !10
  tail call void @NetbufQueAppend(ptr noundef %15, ptr noundef nonnull %6) #3
  %16 = getelementptr inbounds i8, ptr %1, i64 1
  %17 = load i8, ptr %16, align 1, !tbaa !18
  %.not = icmp eq i8 %17, 0
  br i1 %.not, label %23, label %18

18:                                               ; preds = %13
  %19 = getelementptr inbounds i8, ptr %0, i64 256
  %20 = load ptr, ptr %19, align 8, !tbaa !19
  %21 = tail call i64 %20(ptr noundef nonnull %0, i8 noundef zeroext 6, ptr noundef null) #3
  %22 = icmp slt i64 %21, 0
  br i1 %22, label %34, label %23

23:                                               ; preds = %18, %13
  %24 = load i8, ptr %1, align 8, !tbaa !20
  %.not24 = icmp eq i8 %24, 0
  br i1 %.not24, label %30, label %25

25:                                               ; preds = %23
  %26 = getelementptr inbounds i8, ptr %0, i64 256
  %27 = load ptr, ptr %26, align 8, !tbaa !19
  %28 = tail call i64 %27(ptr noundef nonnull %0, i8 noundef zeroext 5, ptr noundef null) #3
  %29 = icmp slt i64 %28, 0
  br i1 %29, label %34, label %30

30:                                               ; preds = %25, %23
  %31 = getelementptr inbounds i8, ptr %0, i64 256
  %32 = load ptr, ptr %31, align 8, !tbaa !19
  %33 = tail call i64 %32(ptr noundef nonnull %0, i8 noundef zeroext 4, ptr noundef null) #3
  %. = tail call i64 @llvm.smin.i64(i64 %33, i64 0)
  br label %34

34:                                               ; preds = %30, %25, %18, %8, %12, %10
  %.0 = phi i64 [ -9223372036854775799, %10 ], [ -9223372036854775799, %12 ], [ -9223372036854775799, %8 ], [ %21, %18 ], [ %28, %25 ], [ %., %30 ]
  ret i64 %.0
}

declare ptr @NetbufFromExt(ptr noundef, i32 noundef, i32 noundef, i32 noundef, ptr noundef, ptr noundef) local_unnamed_addr #1

declare zeroext i8 @DebugPrintEnabled() local_unnamed_addr #1

declare zeroext i8 @DebugPrintLevelEnabled(i64 noundef) local_unnamed_addr #1

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

declare void @NetbufQueAppend(ptr noundef, ptr noundef) local_unnamed_addr #1

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i64 @llvm.smin.i64(i64, i64) #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, !9, i64 8}
!6 = !{!"", !7, i64 0, !7, i64 1, !9, i64 4, !9, i64 8, !7, i64 16}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!"int", !7, i64 0}
!10 = !{!11, !12, i64 104}
!11 = !{!"_SOCKET", !9, i64 0, !12, i64 8, !12, i64 16, !12, i64 24, !12, i64 32, !13, i64 40, !7, i64 56, !9, i64 60, !7, i64 64, !14, i64 66, !15, i64 72, !17, i64 96, !17, i64 112, !16, i64 128, !7, i64 136, !9, i64 140, !9, i64 144, !12, i64 152, !13, i64 160, !13, i64 176, !13, i64 192, !13, i64 208, !13, i64 224, !12, i64 240, !12, i64 248, !12, i64 256, !7, i64 264, !7, i64 288, !12, i64 368, !12, i64 376, !12, i64 384}
!12 = !{!"any pointer", !7, i64 0}
!13 = !{!"_LIST_ENTRY", !12, i64 0, !12, i64 8}
!14 = !{!"short", !7, i64 0}
!15 = !{!"", !16, i64 0, !16, i64 8, !9, i64 16}
!16 = !{!"long long", !7, i64 0}
!17 = !{!"_SOCK_BUFFER", !9, i64 0, !9, i64 4, !12, i64 8}
!18 = !{!6, !7, i64 1}
!19 = !{!11, !12, i64 256}
!20 = !{!6, !7, i64 0}


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