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

; 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_HEAD = type { i16, i16, i32, i32, i8, i8, i16, i16, i16 }
%struct._TCP_SEG = type { i32, i32, i32, i8, i16, i32 }

@.str = external hidden unnamed_addr constant [153 x i8], align 1
@.str.28 = external hidden unnamed_addr constant [107 x i8], align 1

; 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 @DebugAssertEnabled() #1

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

; Function Attrs: nounwind uwtable
define dso_local i64 @TcpVerifySegment(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 = icmp eq ptr %8, null
  br i1 %9, label %10, label %11

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

11:                                               ; preds = %1
  br label %12

12:                                               ; preds = %11
  %13 = call zeroext i8 @DebugAssertEnabled()
  %14 = icmp ne i8 %13, 0
  br i1 %14, label %15, label %25

15:                                               ; preds = %12
  %16 = load ptr, ptr %3, align 8, !tbaa !5
  %17 = icmp ne ptr %16, null
  br i1 %17, label %18, label %23

18:                                               ; preds = %15
  %19 = load ptr, ptr %3, align 8, !tbaa !5
  %20 = getelementptr inbounds %struct.NET_BUF, ptr %19, i32 0, i32 0
  %21 = load i32, ptr %20, align 8, !tbaa !9
  %22 = icmp eq i32 %21, 1718968942
  br i1 %22, label %24, label %23

23:                                               ; preds = %18, %15
  call void @DebugAssert(ptr noundef @.str, i64 noundef 1135, ptr noundef @.str.28)
  br label %24

24:                                               ; preds = %23, %18
  br label %25

25:                                               ; preds = %24, %12
  br label %26

26:                                               ; preds = %25
  br label %27

27:                                               ; preds = %26
  %28 = load ptr, ptr %3, align 8, !tbaa !5
  %29 = getelementptr inbounds %struct.NET_BUF, ptr %28, i32 0, i32 6
  %30 = getelementptr inbounds [64 x i8], ptr %29, i64 0, i64 0
  store ptr %30, ptr %5, align 8, !tbaa !5
  %31 = load ptr, ptr %3, align 8, !tbaa !5
  %32 = getelementptr inbounds %struct.NET_BUF, ptr %31, i32 0, i32 9
  %33 = load i32, ptr %32, align 4, !tbaa !14
  store i32 %33, ptr %6, align 4, !tbaa !15
  %34 = load ptr, ptr %3, align 8, !tbaa !5
  %35 = getelementptr inbounds %struct.NET_BUF, ptr %34, i32 0, i32 4
  %36 = load ptr, ptr %35, align 8, !tbaa !16
  store ptr %36, ptr %4, align 8, !tbaa !5
  %37 = load ptr, ptr %4, align 8, !tbaa !5
  %38 = icmp ne ptr %37, null
  br i1 %38, label %39, label %59

39:                                               ; preds = %27
  %40 = load ptr, ptr %4, align 8, !tbaa !5
  %41 = getelementptr inbounds %struct.TCP_HEAD, ptr %40, i32 0, i32 5
  %42 = load i8, ptr %41, align 1, !tbaa !17
  %43 = zext i8 %42 to i32
  %44 = load ptr, ptr %5, align 8, !tbaa !5
  %45 = getelementptr inbounds %struct._TCP_SEG, ptr %44, i32 0, i32 3
  %46 = load i8, ptr %45, align 4, !tbaa !20
  %47 = zext i8 %46 to i32
  %48 = icmp ne i32 %43, %47
  br i1 %48, label %49, label %50

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

50:                                               ; preds = %39
  %51 = load ptr, ptr %4, align 8, !tbaa !5
  %52 = getelementptr inbounds %struct.TCP_HEAD, ptr %51, i32 0, i32 4
  %53 = load i8, ptr %52, align 1
  %54 = lshr i8 %53, 4
  %55 = zext i8 %54 to i32
  %56 = shl i32 %55, 2
  %57 = load i32, ptr %6, align 4, !tbaa !15
  %58 = sub i32 %57, %56
  store i32 %58, ptr %6, align 4, !tbaa !15
  br label %59

59:                                               ; preds = %50, %27
  %60 = load ptr, ptr %5, align 8, !tbaa !5
  %61 = getelementptr inbounds %struct._TCP_SEG, ptr %60, i32 0, i32 3
  %62 = load i8, ptr %61, align 4, !tbaa !20
  %63 = zext i8 %62 to i32
  %64 = and i32 %63, 2
  %65 = icmp ne i32 %64, 0
  %66 = zext i1 %65 to i32
  %67 = trunc i32 %66 to i8
  %68 = icmp ne i8 %67, 0
  br i1 %68, label %69, label %72

69:                                               ; preds = %59
  %70 = load i32, ptr %6, align 4, !tbaa !15
  %71 = add i32 %70, 1
  store i32 %71, ptr %6, align 4, !tbaa !15
  br label %72

72:                                               ; preds = %69, %59
  %73 = load ptr, ptr %5, align 8, !tbaa !5
  %74 = getelementptr inbounds %struct._TCP_SEG, ptr %73, i32 0, i32 3
  %75 = load i8, ptr %74, align 4, !tbaa !20
  %76 = zext i8 %75 to i32
  %77 = and i32 %76, 1
  %78 = icmp ne i32 %77, 0
  %79 = zext i1 %78 to i32
  %80 = trunc i32 %79 to i8
  %81 = icmp ne i8 %80, 0
  br i1 %81, label %82, label %85

82:                                               ; preds = %72
  %83 = load i32, ptr %6, align 4, !tbaa !15
  %84 = add i32 %83, 1
  store i32 %84, ptr %6, align 4, !tbaa !15
  br label %85

85:                                               ; preds = %82, %72
  %86 = load ptr, ptr %5, align 8, !tbaa !5
  %87 = getelementptr inbounds %struct._TCP_SEG, ptr %86, i32 0, i32 0
  %88 = load i32, ptr %87, align 4, !tbaa !22
  %89 = load i32, ptr %6, align 4, !tbaa !15
  %90 = add i32 %88, %89
  %91 = load ptr, ptr %5, align 8, !tbaa !5
  %92 = getelementptr inbounds %struct._TCP_SEG, ptr %91, i32 0, i32 1
  %93 = load i32, ptr %92, align 4, !tbaa !23
  %94 = icmp ne i32 %90, %93
  br i1 %94, label %95, label %96

95:                                               ; preds = %85
  store i64 0, ptr %2, align 8
  store i32 1, ptr %7, align 4
  br label %97

96:                                               ; preds = %85
  store i64 1, ptr %2, align 8
  store i32 1, ptr %7, align 4
  br label %97

97:                                               ; preds = %96, %95, %49, %10
  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
  %98 = load i64, ptr %2, align 8
  ret i64 %98
}

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, !11, i64 0}
!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 = !{!10, !11, i64 132}
!15 = !{!11, !11, i64 0}
!16 = !{!10, !6, i64 40}
!17 = !{!18, !7, i64 13}
!18 = !{!"", !19, i64 0, !19, i64 2, !11, i64 4, !11, i64 8, !7, i64 12, !7, i64 12, !7, i64 13, !19, i64 14, !19, i64 16, !19, i64 18}
!19 = !{!"short", !7, i64 0}
!20 = !{!21, !7, i64 12}
!21 = !{!"_TCP_SEG", !11, i64 0, !11, i64 4, !11, i64 8, !7, i64 12, !19, i64 14, !11, i64 16}
!22 = !{!21, !11, i64 0}
!23 = !{!21, !11, i64 4}


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

declare zeroext i8 @DebugAssertEnabled() local_unnamed_addr #0

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

; Function Attrs: nounwind uwtable
define dso_local range(i64 0, 2) i64 @TcpVerifySegment(ptr noundef readonly %0) local_unnamed_addr #1 {
  %2 = icmp eq ptr %0, null
  br i1 %2, label %38, label %3

3:                                                ; preds = %1
  %4 = tail call zeroext i8 @DebugAssertEnabled() #2
  %.not = icmp eq i8 %4, 0
  br i1 %.not, label %9, label %5

5:                                                ; preds = %3
  %6 = load i32, ptr %0, align 8, !tbaa !5
  %7 = icmp eq i32 %6, 1718968942
  br i1 %7, label %9, label %8

8:                                                ; preds = %5
  tail call void @DebugAssert(ptr noundef nonnull @.str, i64 noundef 1135, ptr noundef nonnull @.str.28) #2
  br label %9

9:                                                ; preds = %5, %8, %3
  %10 = getelementptr inbounds i8, ptr %0, i64 56
  %11 = getelementptr inbounds i8, ptr %0, i64 132
  %12 = load i32, ptr %11, align 4, !tbaa !13
  %13 = getelementptr inbounds i8, ptr %0, i64 40
  %14 = load ptr, ptr %13, align 8, !tbaa !14
  %.not21 = icmp eq ptr %14, null
  br i1 %.not21, label %._crit_edge, label %15

._crit_edge:                                      ; preds = %9
  %.phi.trans.insert = getelementptr inbounds i8, ptr %0, i64 68
  %.pre = load i8, ptr %.phi.trans.insert, align 4, !tbaa !15
  br label %27

15:                                               ; preds = %9
  %16 = getelementptr inbounds i8, ptr %14, i64 13
  %17 = load i8, ptr %16, align 1, !tbaa !18
  %18 = getelementptr inbounds i8, ptr %0, i64 68
  %19 = load i8, ptr %18, align 4, !tbaa !15
  %.not22 = icmp eq i8 %17, %19
  br i1 %.not22, label %20, label %38

20:                                               ; preds = %15
  %21 = getelementptr inbounds i8, ptr %14, i64 12
  %22 = load i8, ptr %21, align 1
  %23 = lshr i8 %22, 2
  %24 = and i8 %23, 60
  %25 = zext nneg i8 %24 to i32
  %26 = sub i32 %12, %25
  br label %27

27:                                               ; preds = %._crit_edge, %20
  %28 = phi i8 [ %17, %20 ], [ %.pre, %._crit_edge ]
  %.0 = phi i32 [ %26, %20 ], [ %12, %._crit_edge ]
  %29 = lshr i8 %28, 1
  %30 = and i8 %29, 1
  %31 = zext nneg i8 %30 to i32
  %32 = and i8 %28, 1
  %33 = zext nneg i8 %32 to i32
  %34 = load i32, ptr %10, align 4, !tbaa !20
  %spec.select = add i32 %34, %.0
  %.2 = add i32 %spec.select, %33
  %35 = add i32 %.2, %31
  %36 = getelementptr inbounds i8, ptr %0, i64 60
  %37 = load i32, ptr %36, align 4, !tbaa !21
  %.not25 = icmp eq i32 %35, %37
  %spec.select26 = zext i1 %.not25 to i64
  br label %38

38:                                               ; preds = %27, %15, %1
  %.018 = phi i64 [ 1, %1 ], [ 0, %15 ], [ %spec.select26, %27 ]
  ret i64 %.018
}

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 = !{!"", !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 = !{!6, !7, i64 132}
!14 = !{!6, !12, i64 40}
!15 = !{!16, !8, i64 12}
!16 = !{!"_TCP_SEG", !7, i64 0, !7, i64 4, !7, i64 8, !8, i64 12, !17, i64 14, !7, i64 16}
!17 = !{!"short", !8, i64 0}
!18 = !{!19, !8, i64 13}
!19 = !{!"", !17, i64 0, !17, i64 2, !7, i64 4, !7, i64 8, !8, i64 12, !8, i64 12, !8, i64 13, !17, i64 14, !17, i64 16, !17, i64 18}
!20 = !{!16, !7, i64 0}
!21 = !{!16, !7, i64 4}


; Effective O3 passes: BDCEPass,EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass