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

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

; 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

declare zeroext i8 @IsListEmpty(ptr noundef) #1

; Function Attrs: nounwind uwtable
declare dso_local i64 @TcpVerifySegment(ptr noundef) #2

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

11:                                               ; preds = %1
  store i64 1, ptr %2, align 8
  store i32 1, ptr %7, align 4
  br label %61

12:                                               ; preds = %1
  %13 = load ptr, ptr %3, align 8, !tbaa !5
  %14 = getelementptr inbounds %struct._LIST_ENTRY, ptr %13, i32 0, i32 0
  %15 = load ptr, ptr %14, align 8, !tbaa !9
  store ptr %15, ptr %4, align 8, !tbaa !5
  %16 = load ptr, ptr %4, align 8, !tbaa !5
  %17 = ptrtoint ptr %16 to i64
  %18 = sub i64 %17, ptrtoint (ptr getelementptr inbounds (%struct.NET_BUF, ptr null, i32 0, i32 2) to i64)
  %19 = inttoptr i64 %18 to ptr
  store ptr %19, ptr %5, align 8, !tbaa !5
  %20 = load ptr, ptr %5, align 8, !tbaa !5
  %21 = getelementptr inbounds %struct.NET_BUF, ptr %20, i32 0, i32 6
  %22 = getelementptr inbounds [64 x i8], ptr %21, i64 0, i64 0
  %23 = getelementptr inbounds %struct._TCP_SEG, ptr %22, i32 0, i32 0
  %24 = load i32, ptr %23, align 8, !tbaa !11
  store i32 %24, ptr %6, align 4, !tbaa !15
  %25 = load ptr, ptr %3, align 8, !tbaa !5
  %26 = getelementptr inbounds %struct._LIST_ENTRY, ptr %25, i32 0, i32 0
  %27 = load ptr, ptr %26, align 8, !tbaa !9
  store ptr %27, ptr %4, align 8, !tbaa !5
  br label %28

28:                                               ; preds = %56, %12
  %29 = load ptr, ptr %4, align 8, !tbaa !5
  %30 = load ptr, ptr %3, align 8, !tbaa !5
  %31 = icmp ne ptr %29, %30
  br i1 %31, label %32, label %60

32:                                               ; preds = %28
  %33 = load ptr, ptr %4, align 8, !tbaa !5
  %34 = ptrtoint ptr %33 to i64
  %35 = sub i64 %34, ptrtoint (ptr getelementptr inbounds (%struct.NET_BUF, ptr null, i32 0, i32 2) to i64)
  %36 = inttoptr i64 %35 to ptr
  store ptr %36, ptr %5, align 8, !tbaa !5
  %37 = load ptr, ptr %5, align 8, !tbaa !5
  %38 = call i64 @TcpVerifySegment(ptr noundef %37)
  %39 = icmp eq i64 %38, 0
  br i1 %39, label %40, label %41

40:                                               ; preds = %32
  store i64 0, ptr %2, align 8
  store i32 1, ptr %7, align 4
  br label %61

41:                                               ; preds = %32
  %42 = load i32, ptr %6, align 4, !tbaa !15
  %43 = load ptr, ptr %5, align 8, !tbaa !5
  %44 = getelementptr inbounds %struct.NET_BUF, ptr %43, i32 0, i32 6
  %45 = getelementptr inbounds [64 x i8], ptr %44, i64 0, i64 0
  %46 = getelementptr inbounds %struct._TCP_SEG, ptr %45, i32 0, i32 0
  %47 = load i32, ptr %46, align 8, !tbaa !11
  %48 = icmp ne i32 %42, %47
  br i1 %48, label %49, label %50

49:                                               ; preds = %41
  store i64 0, ptr %2, align 8
  store i32 1, ptr %7, align 4
  br label %61

50:                                               ; preds = %41
  %51 = load ptr, ptr %5, align 8, !tbaa !5
  %52 = getelementptr inbounds %struct.NET_BUF, ptr %51, i32 0, i32 6
  %53 = getelementptr inbounds [64 x i8], ptr %52, i64 0, i64 0
  %54 = getelementptr inbounds %struct._TCP_SEG, ptr %53, i32 0, i32 1
  %55 = load i32, ptr %54, align 4, !tbaa !16
  store i32 %55, ptr %6, align 4, !tbaa !15
  br label %56

56:                                               ; preds = %50
  %57 = load ptr, ptr %4, align 8, !tbaa !5
  %58 = getelementptr inbounds %struct._LIST_ENTRY, ptr %57, i32 0, i32 0
  %59 = load ptr, ptr %58, align 8, !tbaa !9
  store ptr %59, ptr %4, align 8, !tbaa !5
  br label %28, !llvm.loop !17

60:                                               ; preds = %28
  store i64 1, ptr %2, align 8
  store i32 1, ptr %7, align 4
  br label %61

61:                                               ; preds = %60, %49, %40, %11
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #3
  %62 = load i64, ptr %2, align 8
  ret i64 %62
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 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 #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 = !{!"_LIST_ENTRY", !6, i64 0, !6, i64 8}
!11 = !{!12, !13, i64 0}
!12 = !{!"_TCP_SEG", !13, i64 0, !13, i64 4, !13, i64 8, !7, i64 12, !14, i64 14, !13, i64 16}
!13 = !{!"int", !7, i64 0}
!14 = !{!"short", !7, i64 0}
!15 = !{!13, !13, i64 0}
!16 = !{!12, !13, i64 4}
!17 = distinct !{!17, !18}
!18 = !{!"llvm.loop.mustprogress"}


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

declare zeroext i8 @IsListEmpty(ptr noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
declare dso_local i64 @TcpVerifySegment(ptr noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
define dso_local range(i64 0, 2) i64 @TcpCheckSndQue(ptr noundef %0) local_unnamed_addr #1 {
  %2 = tail call zeroext i8 @IsListEmpty(ptr noundef %0) #2
  %.not = icmp eq i8 %2, 0
  br i1 %.not, label %3, label %.loopexit

3:                                                ; preds = %1
  %4 = load ptr, ptr %0, align 8, !tbaa !5
  %.not1518 = icmp eq ptr %4, %0
  br i1 %.not1518, label %.loopexit, label %.lr.ph.preheader

.lr.ph.preheader:                                 ; preds = %3
  %5 = ptrtoint ptr %4 to i64
  %6 = add i64 %5, -16
  %7 = inttoptr i64 %6 to ptr
  %8 = getelementptr inbounds i8, ptr %7, i64 56
  br label %.lr.ph

.lr.ph:                                           ; preds = %.lr.ph.preheader, %17
  %.020.in = phi ptr [ %18, %17 ], [ %8, %.lr.ph.preheader ]
  %.01319 = phi ptr [ %19, %17 ], [ %4, %.lr.ph.preheader ]
  %.020 = load i32, ptr %.020.in, align 4, !tbaa !10
  %9 = ptrtoint ptr %.01319 to i64
  %10 = add i64 %9, -16
  %11 = inttoptr i64 %10 to ptr
  %12 = tail call i64 @TcpVerifySegment(ptr noundef %11)
  %13 = icmp eq i64 %12, 0
  br i1 %13, label %.loopexit, label %14

14:                                               ; preds = %.lr.ph
  %15 = getelementptr inbounds i8, ptr %11, i64 56
  %16 = load i32, ptr %15, align 8, !tbaa !12
  %.not16 = icmp eq i32 %.020, %16
  br i1 %.not16, label %17, label %.loopexit

17:                                               ; preds = %14
  %18 = getelementptr inbounds i8, ptr %11, i64 60
  %19 = load ptr, ptr %.01319, align 8, !tbaa !5
  %.not15 = icmp eq ptr %19, %0
  br i1 %.not15, label %.loopexit, label %.lr.ph, !llvm.loop !15

.loopexit:                                        ; preds = %.lr.ph, %14, %17, %3, %1
  %.014 = phi i64 [ 1, %1 ], [ 1, %3 ], [ 0, %.lr.ph ], [ 0, %14 ], [ 1, %17 ]
  ret i64 %.014
}

attributes #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 = { 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 = { 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 0}
!6 = !{!"_LIST_ENTRY", !7, i64 0, !7, i64 8}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!11, !11, i64 0}
!11 = !{!"int", !8, i64 0}
!12 = !{!13, !11, i64 0}
!13 = !{!"_TCP_SEG", !11, i64 0, !11, i64 4, !11, i64 8, !8, i64 12, !14, i64 14, !11, i64 16}
!14 = !{!"short", !8, i64 0}
!15 = distinct !{!15, !16}
!16 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,SROAPass,SimplifyCFGPass,TailCallElimPass