; LLVM IR from kala13x/libxutils :: src/net (ws)

; 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.xweb_frame_ = type { i32, %struct.XByteBuffer, i64, i64, i32, i8, i8, i8, i8, i8 }
%struct.XByteBuffer = type { ptr, i64, i64, i16, 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

; Function Attrs: nounwind uwtable
define dso_local zeroext i8 @XWebFrame_CheckPayload(ptr noundef %0) #1 {
  %2 = alloca i8, align 1
  %3 = alloca ptr, align 8
  %4 = alloca i64, align 8
  %5 = alloca i32, align 4
  %6 = alloca i64, align 8
  store ptr %0, ptr %3, align 8, !tbaa !5
  %7 = load ptr, ptr %3, align 8, !tbaa !5
  %8 = icmp ne ptr %7, null
  br i1 %8, label %9, label %31

9:                                                ; preds = %1
  %10 = load ptr, ptr %3, align 8, !tbaa !5
  %11 = getelementptr inbounds %struct.xweb_frame_, ptr %10, i32 0, i32 1
  %12 = getelementptr inbounds %struct.XByteBuffer, ptr %11, i32 0, i32 0
  %13 = load ptr, ptr %12, align 8, !tbaa !9
  %14 = icmp ne ptr %13, null
  br i1 %14, label %15, label %31

15:                                               ; preds = %9
  %16 = load ptr, ptr %3, align 8, !tbaa !5
  %17 = getelementptr inbounds %struct.xweb_frame_, ptr %16, i32 0, i32 1
  %18 = getelementptr inbounds %struct.XByteBuffer, ptr %17, i32 0, i32 2
  %19 = load i64, ptr %18, align 8, !tbaa !15
  %20 = icmp ne i64 %19, 0
  br i1 %20, label %21, label %31

21:                                               ; preds = %15
  %22 = load ptr, ptr %3, align 8, !tbaa !5
  %23 = getelementptr inbounds %struct.xweb_frame_, ptr %22, i32 0, i32 2
  %24 = load i64, ptr %23, align 8, !tbaa !16
  %25 = icmp ne i64 %24, 0
  br i1 %25, label %26, label %31

26:                                               ; preds = %21
  %27 = load ptr, ptr %3, align 8, !tbaa !5
  %28 = getelementptr inbounds %struct.xweb_frame_, ptr %27, i32 0, i32 3
  %29 = load i64, ptr %28, align 8, !tbaa !17
  %30 = icmp ne i64 %29, 0
  br i1 %30, label %32, label %31

31:                                               ; preds = %26, %21, %15, %9, %1
  store i8 0, ptr %2, align 1
  br label %67

32:                                               ; preds = %26
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #2
  %33 = load ptr, ptr %3, align 8, !tbaa !5
  %34 = getelementptr inbounds %struct.xweb_frame_, ptr %33, i32 0, i32 1
  %35 = getelementptr inbounds %struct.XByteBuffer, ptr %34, i32 0, i32 2
  %36 = load i64, ptr %35, align 8, !tbaa !15
  store i64 %36, ptr %4, align 8, !tbaa !18
  %37 = load i64, ptr %4, align 8, !tbaa !18
  %38 = load ptr, ptr %3, align 8, !tbaa !5
  %39 = getelementptr inbounds %struct.xweb_frame_, ptr %38, i32 0, i32 3
  %40 = load i64, ptr %39, align 8, !tbaa !17
  %41 = icmp ugt i64 %37, %40
  br i1 %41, label %43, label %42

42:                                               ; preds = %32
  store i8 0, ptr %2, align 1
  store i32 1, ptr %5, align 4
  br label %66

43:                                               ; preds = %32
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #2
  %44 = load i64, ptr %4, align 8, !tbaa !18
  %45 = load ptr, ptr %3, align 8, !tbaa !5
  %46 = getelementptr inbounds %struct.xweb_frame_, ptr %45, i32 0, i32 3
  %47 = load i64, ptr %46, align 8, !tbaa !17
  %48 = sub i64 %44, %47
  store i64 %48, ptr %6, align 8, !tbaa !18
  %49 = load i64, ptr %6, align 8, !tbaa !18
  %50 = load ptr, ptr %3, align 8, !tbaa !5
  %51 = getelementptr inbounds %struct.xweb_frame_, ptr %50, i32 0, i32 2
  %52 = load i64, ptr %51, align 8, !tbaa !16
  %53 = icmp uge i64 %49, %52
  br i1 %53, label %54, label %57

54:                                               ; preds = %43
  %55 = load ptr, ptr %3, align 8, !tbaa !5
  %56 = getelementptr inbounds %struct.xweb_frame_, ptr %55, i32 0, i32 6
  store i8 1, ptr %56, align 1, !tbaa !19
  br label %57

57:                                               ; preds = %54, %43
  %58 = load i64, ptr %4, align 8, !tbaa !18
  %59 = load ptr, ptr %3, align 8, !tbaa !5
  %60 = getelementptr inbounds %struct.xweb_frame_, ptr %59, i32 0, i32 3
  %61 = load i64, ptr %60, align 8, !tbaa !17
  %62 = icmp ugt i64 %58, %61
  %63 = zext i1 %62 to i64
  %64 = select i1 %62, i32 1, i32 0
  %65 = trunc i32 %64 to i8
  store i8 %65, ptr %2, align 1
  store i32 1, ptr %5, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #2
  br label %66

66:                                               ; preds = %57, %42
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #2
  br label %67

67:                                               ; preds = %66, %31
  %68 = load i8, ptr %2, align 1
  ret i8 %68
}

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 = { 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 8}
!10 = !{!"xweb_frame_", !11, i64 0, !12, i64 8, !13, i64 40, !13, i64 48, !11, i64 56, !7, i64 60, !7, i64 61, !7, i64 62, !7, i64 63, !7, i64 64}
!11 = !{!"int", !7, i64 0}
!12 = !{!"XByteBuffer", !6, i64 0, !13, i64 8, !13, i64 16, !14, i64 24, !14, i64 26, !11, i64 28}
!13 = !{!"long", !7, i64 0}
!14 = !{!"short", !7, i64 0}
!15 = !{!10, !13, i64 24}
!16 = !{!10, !13, i64 40}
!17 = !{!10, !13, i64 48}
!18 = !{!13, !13, i64 0}
!19 = !{!10, !7, i64 61}


; 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: mustprogress nofree norecurse nosync nounwind willreturn memory(argmem: readwrite) uwtable
define dso_local zeroext range(i8 0, 2) i8 @XWebFrame_CheckPayload(ptr noundef %0) local_unnamed_addr #0 {
  %.not = icmp eq ptr %0, null
  br i1 %.not, label %19, label %2

2:                                                ; preds = %1
  %3 = getelementptr inbounds i8, ptr %0, i64 8
  %4 = load ptr, ptr %3, align 8, !tbaa !5
  %.not19 = icmp eq ptr %4, null
  br i1 %.not19, label %19, label %5

5:                                                ; preds = %2
  %6 = getelementptr inbounds i8, ptr %0, i64 24
  %7 = load i64, ptr %6, align 8, !tbaa !14
  %.not20 = icmp eq i64 %7, 0
  br i1 %.not20, label %19, label %8

8:                                                ; preds = %5
  %9 = getelementptr inbounds i8, ptr %0, i64 40
  %10 = load i64, ptr %9, align 8, !tbaa !15
  %.not21 = icmp eq i64 %10, 0
  br i1 %.not21, label %19, label %11

11:                                               ; preds = %8
  %12 = getelementptr inbounds i8, ptr %0, i64 48
  %13 = load i64, ptr %12, align 8, !tbaa !16
  %.not22 = icmp ne i64 %13, 0
  %14 = icmp ugt i64 %7, %13
  %or.cond = and i1 %.not22, %14
  br i1 %or.cond, label %15, label %19

15:                                               ; preds = %11
  %16 = sub i64 %7, %13
  %.not23 = icmp ult i64 %16, %10
  br i1 %.not23, label %19, label %17

17:                                               ; preds = %15
  %18 = getelementptr inbounds i8, ptr %0, i64 61
  store i8 1, ptr %18, align 1, !tbaa !17
  br label %19

19:                                               ; preds = %15, %17, %1, %2, %5, %8, %11
  %.1 = phi i8 [ 0, %11 ], [ 0, %8 ], [ 0, %5 ], [ 0, %2 ], [ 0, %1 ], [ 1, %17 ], [ 1, %15 ]
  ret i8 %.1
}

attributes #0 = { mustprogress nofree norecurse nosync nounwind willreturn memory(argmem: readwrite) 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" }

!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, !11, i64 8}
!6 = !{!"xweb_frame_", !7, i64 0, !10, i64 8, !12, i64 40, !12, i64 48, !7, i64 56, !8, i64 60, !8, i64 61, !8, i64 62, !8, i64 63, !8, i64 64}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"XByteBuffer", !11, i64 0, !12, i64 8, !12, i64 16, !13, i64 24, !13, i64 26, !7, i64 28}
!11 = !{!"any pointer", !8, i64 0}
!12 = !{!"long", !8, i64 0}
!13 = !{!"short", !8, i64 0}
!14 = !{!6, !12, i64 24}
!15 = !{!6, !12, i64 40}
!16 = !{!6, !12, i64 48}
!17 = !{!6, !8, i64 61}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass