; 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
declare dso_local zeroext i8 @XWS_OpCode(i32 noundef) #1

; Function Attrs: nounwind uwtable
declare dso_local ptr @XWS_CreateFrame(ptr noundef, i64 noundef, i8 noundef zeroext, i8 noundef zeroext, ptr noundef) #1

; Function Attrs: nounwind uwtable
declare dso_local void @XWebFrame_Init(ptr noundef) #1

; Function Attrs: nounwind
declare void @free(ptr noundef) #2

; Function Attrs: nounwind uwtable
define dso_local i32 @XWebFrame_Create(ptr noundef %0, ptr noundef %1, i64 noundef %2, i32 noundef %3, i8 noundef zeroext %4) #1 {
  %6 = alloca i32, align 4
  %7 = alloca ptr, align 8
  %8 = alloca ptr, align 8
  %9 = alloca i64, align 8
  %10 = alloca i32, align 4
  %11 = alloca i8, align 1
  %12 = alloca ptr, align 8
  %13 = alloca i64, align 8
  %14 = alloca i32, align 4
  store ptr %0, ptr %7, align 8, !tbaa !5
  store ptr %1, ptr %8, align 8, !tbaa !5
  store i64 %2, ptr %9, align 8, !tbaa !9
  store i32 %3, ptr %10, align 4, !tbaa !11
  store i8 %4, ptr %11, align 1, !tbaa !13
  %15 = load ptr, ptr %7, align 8, !tbaa !5
  %16 = icmp ne ptr %15, null
  br i1 %16, label %18, label %17

17:                                               ; preds = %5
  store i32 3, ptr %6, align 4
  br label %79

18:                                               ; preds = %5
  %19 = load ptr, ptr %8, align 8, !tbaa !5
  %20 = icmp ne ptr %19, null
  br i1 %20, label %25, label %21

21:                                               ; preds = %18
  %22 = load i64, ptr %9, align 8, !tbaa !9
  %23 = icmp ne i64 %22, 0
  br i1 %23, label %24, label %25

24:                                               ; preds = %21
  store i32 3, ptr %6, align 4
  br label %79

25:                                               ; preds = %21, %18
  %26 = load i32, ptr %10, align 4, !tbaa !11
  %27 = icmp ne i32 %26, 16
  br i1 %27, label %29, label %28

28:                                               ; preds = %25
  store i32 4, ptr %6, align 4
  br label %79

29:                                               ; preds = %25
  call void @llvm.lifetime.start.p0(i64 8, ptr %12) #4
  store ptr null, ptr %12, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %13) #4
  store i64 0, ptr %13, align 8, !tbaa !9
  %30 = load ptr, ptr %7, align 8, !tbaa !5
  call void @XWebFrame_Init(ptr noundef %30)
  %31 = load i32, ptr %10, align 4, !tbaa !11
  %32 = load ptr, ptr %7, align 8, !tbaa !5
  %33 = getelementptr inbounds %struct.xweb_frame_, ptr %32, i32 0, i32 0
  store i32 %31, ptr %33, align 8, !tbaa !14
  %34 = load i8, ptr %11, align 1, !tbaa !13
  %35 = load ptr, ptr %7, align 8, !tbaa !5
  %36 = getelementptr inbounds %struct.xweb_frame_, ptr %35, i32 0, i32 9
  store i8 %34, ptr %36, align 8, !tbaa !18
  %37 = load ptr, ptr %7, align 8, !tbaa !5
  %38 = getelementptr inbounds %struct.xweb_frame_, ptr %37, i32 0, i32 0
  %39 = load i32, ptr %38, align 8, !tbaa !14
  %40 = call zeroext i8 @XWS_OpCode(i32 noundef %39)
  %41 = load ptr, ptr %7, align 8, !tbaa !5
  %42 = getelementptr inbounds %struct.xweb_frame_, ptr %41, i32 0, i32 5
  store i8 %40, ptr %42, align 4, !tbaa !19
  %43 = load ptr, ptr %8, align 8, !tbaa !5
  %44 = load i64, ptr %9, align 8, !tbaa !9
  %45 = load ptr, ptr %7, align 8, !tbaa !5
  %46 = getelementptr inbounds %struct.xweb_frame_, ptr %45, i32 0, i32 5
  %47 = load i8, ptr %46, align 4, !tbaa !19
  %48 = load ptr, ptr %7, align 8, !tbaa !5
  %49 = getelementptr inbounds %struct.xweb_frame_, ptr %48, i32 0, i32 9
  %50 = load i8, ptr %49, align 8, !tbaa !18
  %51 = call ptr @XWS_CreateFrame(ptr noundef %43, i64 noundef %44, i8 noundef zeroext %47, i8 noundef zeroext %50, ptr noundef %13)
  store ptr %51, ptr %12, align 8, !tbaa !5
  %52 = load ptr, ptr %12, align 8, !tbaa !5
  %53 = icmp ne ptr %52, null
  br i1 %53, label %55, label %54

54:                                               ; preds = %29
  store i32 1, ptr %6, align 4
  store i32 1, ptr %14, align 4
  br label %78

55:                                               ; preds = %29
  br label %56

56:                                               ; preds = %55
  %57 = load i64, ptr %13, align 8, !tbaa !9
  %58 = load i64, ptr %9, align 8, !tbaa !9
  %59 = icmp ugt i64 %57, %58
  br i1 %59, label %62, label %60

60:                                               ; preds = %56
  %61 = load ptr, ptr %12, align 8, !tbaa !5
  call void @free(ptr noundef %61) #4
  store i32 2, ptr %6, align 4
  store i32 1, ptr %14, align 4
  br label %78

62:                                               ; preds = %56
  br label %63

63:                                               ; preds = %62
  br label %64

64:                                               ; preds = %63
  %65 = load ptr, ptr %7, align 8, !tbaa !5
  %66 = getelementptr inbounds %struct.xweb_frame_, ptr %65, i32 0, i32 1
  %67 = load ptr, ptr %12, align 8, !tbaa !5
  %68 = load i64, ptr %13, align 8, !tbaa !9
  %69 = call i32 @XByteBuffer_OwnData(ptr noundef %66, ptr noundef %67, i64 noundef %68)
  %70 = load i64, ptr %13, align 8, !tbaa !9
  %71 = load i64, ptr %9, align 8, !tbaa !9
  %72 = sub i64 %70, %71
  %73 = load ptr, ptr %7, align 8, !tbaa !5
  %74 = getelementptr inbounds %struct.xweb_frame_, ptr %73, i32 0, i32 3
  store i64 %72, ptr %74, align 8, !tbaa !20
  %75 = load i64, ptr %9, align 8, !tbaa !9
  %76 = load ptr, ptr %7, align 8, !tbaa !5
  %77 = getelementptr inbounds %struct.xweb_frame_, ptr %76, i32 0, i32 2
  store i64 %75, ptr %77, align 8, !tbaa !21
  store i32 0, ptr %6, align 4
  store i32 1, ptr %14, align 4
  br label %78

78:                                               ; preds = %64, %60, %54
  call void @llvm.lifetime.end.p0(i64 8, ptr %13) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #4
  br label %79

79:                                               ; preds = %78, %28, %24, %17
  %80 = load i32, ptr %6, align 4
  ret i32 %80
}

declare i32 @XByteBuffer_OwnData(ptr noundef, ptr noundef, i64 noundef) #3

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


; 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 nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #0

; Function Attrs: mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #0

; Function Attrs: nounwind uwtable
declare dso_local zeroext i8 @XWS_OpCode(i32 noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
declare dso_local ptr @XWS_CreateFrame(ptr noundef, i64 noundef, i8 noundef zeroext, i8 noundef zeroext, ptr noundef) local_unnamed_addr #1

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

; Function Attrs: mustprogress nounwind willreturn allockind("free") memory(argmem: readwrite, inaccessiblemem: readwrite)
declare void @free(ptr allocptr nocapture noundef) local_unnamed_addr #2

; Function Attrs: nounwind uwtable
define dso_local range(i32 0, 5) i32 @XWebFrame_Create(ptr noundef %0, ptr noundef %1, i64 noundef %2, i32 noundef %3, i8 noundef zeroext %4) local_unnamed_addr #1 {
  %6 = alloca i64, align 8
  %.not = icmp eq ptr %0, null
  br i1 %.not, label %29, label %7

7:                                                ; preds = %5
  %8 = icmp eq ptr %1, null
  %9 = icmp ne i64 %2, 0
  %or.cond = and i1 %8, %9
  br i1 %or.cond, label %29, label %10

10:                                               ; preds = %7
  %.not30 = icmp eq i32 %3, 16
  br i1 %.not30, label %29, label %11

11:                                               ; preds = %10
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %6) #4
  store i64 0, ptr %6, align 8, !tbaa !5
  tail call void @XWebFrame_Init(ptr noundef nonnull %0)
  store i32 %3, ptr %0, align 8, !tbaa !9
  %12 = getelementptr inbounds i8, ptr %0, i64 64
  store i8 %4, ptr %12, align 8, !tbaa !15
  %13 = tail call zeroext i8 @XWS_OpCode(i32 noundef %3)
  %14 = getelementptr inbounds i8, ptr %0, i64 60
  store i8 %13, ptr %14, align 4, !tbaa !16
  %15 = load i8, ptr %12, align 8, !tbaa !15
  %16 = call ptr @XWS_CreateFrame(ptr noundef %1, i64 noundef %2, i8 noundef zeroext %13, i8 noundef zeroext %15, ptr noundef nonnull %6)
  %.not31 = icmp eq ptr %16, null
  br i1 %.not31, label %28, label %17

17:                                               ; preds = %11
  %18 = load i64, ptr %6, align 8, !tbaa !5
  %19 = icmp ugt i64 %18, %2
  br i1 %19, label %21, label %20

20:                                               ; preds = %17
  call void @free(ptr noundef nonnull %16) #4
  br label %28

21:                                               ; preds = %17
  %22 = getelementptr inbounds i8, ptr %0, i64 8
  %23 = call i32 @XByteBuffer_OwnData(ptr noundef nonnull %22, ptr noundef nonnull %16, i64 noundef %18) #4
  %24 = load i64, ptr %6, align 8, !tbaa !5
  %25 = sub i64 %24, %2
  %26 = getelementptr inbounds i8, ptr %0, i64 48
  store i64 %25, ptr %26, align 8, !tbaa !17
  %27 = getelementptr inbounds i8, ptr %0, i64 40
  store i64 %2, ptr %27, align 8, !tbaa !18
  br label %28

28:                                               ; preds = %11, %21, %20
  %.0 = phi i32 [ 0, %21 ], [ 2, %20 ], [ 1, %11 ]
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %6) #4
  br label %29

29:                                               ; preds = %10, %7, %5, %28
  %.1 = phi i32 [ %.0, %28 ], [ 3, %5 ], [ 3, %7 ], [ 4, %10 ]
  ret i32 %.1
}

declare i32 @XByteBuffer_OwnData(ptr noundef, ptr noundef, i64 noundef) local_unnamed_addr #3

attributes #0 = { mustprogress 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 = { mustprogress nounwind willreturn allockind("free") memory(argmem: readwrite, inaccessiblemem: readwrite) "alloc-family"="malloc" "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 = { "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 #4 = { 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 = !{!"long", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !11, i64 0}
!10 = !{!"xweb_frame_", !11, i64 0, !12, i64 8, !6, i64 40, !6, 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", !13, i64 0, !6, i64 8, !6, i64 16, !14, i64 24, !14, i64 26, !11, i64 28}
!13 = !{!"any pointer", !7, i64 0}
!14 = !{!"short", !7, i64 0}
!15 = !{!10, !7, i64 64}
!16 = !{!10, !7, i64 60}
!17 = !{!10, !6, i64 48}
!18 = !{!10, !6, i64 40}


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