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

; 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 ptr @XWS_CreateFrame(ptr noundef %0, i64 noundef %1, i8 noundef zeroext %2, i8 noundef zeroext %3, ptr noundef %4) #1 {
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca i64, align 8
  %9 = alloca i8, align 1
  %10 = alloca i8, align 1
  %11 = alloca ptr, align 8
  %12 = alloca i8, align 1
  %13 = alloca i8, align 1
  %14 = alloca i8, align 1
  %15 = alloca i64, align 8
  %16 = alloca i64, align 8
  %17 = alloca ptr, align 8
  %18 = alloca i32, align 4
  %19 = alloca i16, align 2
  %20 = alloca i64, align 8
  store ptr %0, ptr %7, align 8, !tbaa !5
  store i64 %1, ptr %8, align 8, !tbaa !9
  store i8 %2, ptr %9, align 1, !tbaa !11
  store i8 %3, ptr %10, align 1, !tbaa !11
  store ptr %4, ptr %11, align 8, !tbaa !5
  %21 = load ptr, ptr %11, align 8, !tbaa !5
  %22 = icmp ne ptr %21, null
  br i1 %22, label %23, label %25

23:                                               ; preds = %5
  %24 = load ptr, ptr %11, align 8, !tbaa !5
  store i64 0, ptr %24, align 8, !tbaa !9
  br label %25

25:                                               ; preds = %23, %5
  call void @llvm.lifetime.start.p0(i64 1, ptr %12) #5
  %26 = load i8, ptr %10, align 1, !tbaa !11
  %27 = zext i8 %26 to i32
  %28 = icmp ne i32 %27, 0
  %29 = zext i1 %28 to i64
  %30 = select i1 %28, i32 1, i32 0
  %31 = trunc i32 %30 to i8
  store i8 %31, ptr %12, align 1, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 1, ptr %13) #5
  %32 = load i8, ptr %12, align 1, !tbaa !11
  %33 = zext i8 %32 to i32
  %34 = shl i32 %33, 7
  %35 = load i8, ptr %9, align 1, !tbaa !11
  %36 = zext i8 %35 to i32
  %37 = or i32 %34, %36
  %38 = trunc i32 %37 to i8
  store i8 %38, ptr %13, align 1, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 1, ptr %14) #5
  store i8 0, ptr %14, align 1, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 8, ptr %15) #5
  store i64 2, ptr %15, align 8, !tbaa !9
  %39 = load i64, ptr %8, align 8, !tbaa !9
  %40 = icmp ule i64 %39, 125
  br i1 %40, label %41, label %44

41:                                               ; preds = %25
  %42 = load i64, ptr %8, align 8, !tbaa !9
  %43 = trunc i64 %42 to i8
  store i8 %43, ptr %14, align 1, !tbaa !11
  br label %54

44:                                               ; preds = %25
  %45 = load i64, ptr %8, align 8, !tbaa !9
  %46 = icmp ule i64 %45, 65535
  br i1 %46, label %47, label %50

47:                                               ; preds = %44
  store i8 126, ptr %14, align 1, !tbaa !11
  %48 = load i64, ptr %15, align 8, !tbaa !9
  %49 = add i64 %48, 2
  store i64 %49, ptr %15, align 8, !tbaa !9
  br label %53

50:                                               ; preds = %44
  store i8 127, ptr %14, align 1, !tbaa !11
  %51 = load i64, ptr %15, align 8, !tbaa !9
  %52 = add i64 %51, 8
  store i64 %52, ptr %15, align 8, !tbaa !9
  br label %53

53:                                               ; preds = %50, %47
  br label %54

54:                                               ; preds = %53, %41
  call void @llvm.lifetime.start.p0(i64 8, ptr %16) #5
  %55 = load i64, ptr %15, align 8, !tbaa !9
  %56 = load i64, ptr %8, align 8, !tbaa !9
  %57 = add i64 %55, %56
  store i64 %57, ptr %16, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %17) #5
  %58 = load i64, ptr %16, align 8, !tbaa !9
  %59 = add i64 %58, 1
  %60 = call noalias ptr @malloc(i64 noundef %59) #6
  store ptr %60, ptr %17, align 8, !tbaa !5
  %61 = load ptr, ptr %17, align 8, !tbaa !5
  %62 = icmp ne ptr %61, null
  br i1 %62, label %64, label %63

63:                                               ; preds = %54
  store ptr null, ptr %6, align 8
  store i32 1, ptr %18, align 4
  br label %113

64:                                               ; preds = %54
  %65 = load i8, ptr %13, align 1, !tbaa !11
  %66 = load ptr, ptr %17, align 8, !tbaa !5
  %67 = getelementptr inbounds i8, ptr %66, i64 0
  store i8 %65, ptr %67, align 1, !tbaa !11
  %68 = load i8, ptr %14, align 1, !tbaa !11
  %69 = load ptr, ptr %17, align 8, !tbaa !5
  %70 = getelementptr inbounds i8, ptr %69, i64 1
  store i8 %68, ptr %70, align 1, !tbaa !11
  %71 = load i8, ptr %14, align 1, !tbaa !11
  %72 = zext i8 %71 to i32
  %73 = icmp eq i32 %72, 126
  br i1 %73, label %74, label %80

74:                                               ; preds = %64
  call void @llvm.lifetime.start.p0(i64 2, ptr %19) #5
  %75 = load i64, ptr %8, align 8, !tbaa !9
  %76 = trunc i64 %75 to i16
  %77 = call zeroext i16 @__bswap_16(i16 noundef zeroext %76)
  store i16 %77, ptr %19, align 2, !tbaa !12
  %78 = load ptr, ptr %17, align 8, !tbaa !5
  %79 = getelementptr inbounds i8, ptr %78, i64 2
  call void @llvm.memcpy.p0.p0.i64(ptr align 1 %79, ptr align 2 %19, i64 2, i1 false)
  call void @llvm.lifetime.end.p0(i64 2, ptr %19) #5
  br label %90

80:                                               ; preds = %64
  %81 = load i8, ptr %14, align 1, !tbaa !11
  %82 = zext i8 %81 to i32
  %83 = icmp eq i32 %82, 127
  br i1 %83, label %84, label %89

84:                                               ; preds = %80
  call void @llvm.lifetime.start.p0(i64 8, ptr %20) #5
  %85 = load i64, ptr %8, align 8, !tbaa !9
  %86 = call i64 @__bswap_64(i64 noundef %85)
  store i64 %86, ptr %20, align 8, !tbaa !9
  %87 = load ptr, ptr %17, align 8, !tbaa !5
  %88 = getelementptr inbounds i8, ptr %87, i64 2
  call void @llvm.memcpy.p0.p0.i64(ptr align 1 %88, ptr align 8 %20, i64 8, i1 false)
  call void @llvm.lifetime.end.p0(i64 8, ptr %20) #5
  br label %89

89:                                               ; preds = %84, %80
  br label %90

90:                                               ; preds = %89, %74
  %91 = load ptr, ptr %7, align 8, !tbaa !5
  %92 = icmp ne ptr %91, null
  br i1 %92, label %93, label %102

93:                                               ; preds = %90
  %94 = load i64, ptr %8, align 8, !tbaa !9
  %95 = icmp ne i64 %94, 0
  br i1 %95, label %96, label %102

96:                                               ; preds = %93
  %97 = load ptr, ptr %17, align 8, !tbaa !5
  %98 = load i64, ptr %15, align 8, !tbaa !9
  %99 = getelementptr inbounds i8, ptr %97, i64 %98
  %100 = load ptr, ptr %7, align 8, !tbaa !5
  %101 = load i64, ptr %8, align 8, !tbaa !9
  call void @llvm.memcpy.p0.p0.i64(ptr align 1 %99, ptr align 1 %100, i64 %101, i1 false)
  br label %102

102:                                              ; preds = %96, %93, %90
  %103 = load ptr, ptr %17, align 8, !tbaa !5
  %104 = load i64, ptr %16, align 8, !tbaa !9
  %105 = getelementptr inbounds i8, ptr %103, i64 %104
  store i8 0, ptr %105, align 1, !tbaa !11
  %106 = load ptr, ptr %11, align 8, !tbaa !5
  %107 = icmp ne ptr %106, null
  br i1 %107, label %108, label %111

108:                                              ; preds = %102
  %109 = load i64, ptr %16, align 8, !tbaa !9
  %110 = load ptr, ptr %11, align 8, !tbaa !5
  store i64 %109, ptr %110, align 8, !tbaa !9
  br label %111

111:                                              ; preds = %108, %102
  %112 = load ptr, ptr %17, align 8, !tbaa !5
  store ptr %112, ptr %6, align 8
  store i32 1, ptr %18, align 4
  br label %113

113:                                              ; preds = %111, %63
  call void @llvm.lifetime.end.p0(i64 8, ptr %17) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %16) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %15) #5
  call void @llvm.lifetime.end.p0(i64 1, ptr %14) #5
  call void @llvm.lifetime.end.p0(i64 1, ptr %13) #5
  call void @llvm.lifetime.end.p0(i64 1, ptr %12) #5
  %114 = load ptr, ptr %6, align 8
  ret ptr %114
}

; Function Attrs: nounwind allocsize(0)
declare noalias ptr @malloc(i64 noundef) #2

; Function Attrs: inlinehint nounwind uwtable
declare hidden zeroext i16 @__bswap_16(i16 noundef zeroext) #3

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #4

; Function Attrs: inlinehint nounwind uwtable
declare hidden i64 @__bswap_64(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 allocsize(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 = { inlinehint 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 #4 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #5 = { nounwind }
attributes #6 = { nounwind allocsize(0) }

!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 = !{!7, !7, i64 0}
!12 = !{!13, !13, i64 0}
!13 = !{!"short", !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"

; Function Attrs: nounwind uwtable
define dso_local noalias noundef ptr @XWS_CreateFrame(ptr noundef readonly %0, i64 noundef %1, i8 noundef zeroext %2, i8 noundef zeroext %3, ptr noundef writeonly %4) local_unnamed_addr #0 {
  %.not = icmp eq ptr %4, null
  br i1 %.not, label %7, label %6

6:                                                ; preds = %5
  store i64 0, ptr %4, align 8, !tbaa !5
  br label %7

7:                                                ; preds = %6, %5
  %8 = icmp ult i64 %1, 126
  %9 = icmp ult i64 %1, 65536
  %. = select i1 %9, i64 4, i64 10
  %.039 = select i1 %8, i64 2, i64 %.
  %10 = add i64 %.039, %1
  %11 = add i64 %10, 1
  %12 = tail call noalias ptr @malloc(i64 noundef %11) #4
  %.not47 = icmp eq ptr %12, null
  br i1 %.not47, label %33, label %13

13:                                               ; preds = %7
  %14 = trunc nuw nsw i64 %1 to i8
  %.48 = select i1 %9, i8 126, i8 127
  %.038 = select i1 %8, i8 %14, i8 %.48
  %.not46.not = icmp eq i8 %3, 0
  %15 = select i1 %.not46.not, i8 0, i8 -128
  %16 = or i8 %15, %2
  store i8 %16, ptr %12, align 1, !tbaa !9
  %17 = getelementptr inbounds i8, ptr %12, i64 1
  store i8 %.038, ptr %17, align 1, !tbaa !9
  switch i8 %.038, label %25 [
    i8 126, label %18
    i8 127, label %22
  ]

18:                                               ; preds = %13
  %19 = trunc i64 %1 to i16
  %20 = tail call zeroext i16 @__bswap_16(i16 noundef zeroext %19)
  %21 = getelementptr inbounds i8, ptr %12, i64 2
  store i16 %20, ptr %21, align 1
  br label %25

22:                                               ; preds = %13
  %23 = tail call i64 @__bswap_64(i64 noundef %1)
  %24 = getelementptr inbounds i8, ptr %12, i64 2
  store i64 %23, ptr %24, align 1
  br label %25

25:                                               ; preds = %13, %22, %18
  %26 = icmp ne ptr %0, null
  %27 = icmp ne i64 %1, 0
  %or.cond = and i1 %26, %27
  br i1 %or.cond, label %28, label %30

28:                                               ; preds = %25
  %29 = getelementptr inbounds i8, ptr %12, i64 %.039
  tail call void @llvm.memcpy.p0.p0.i64(ptr nonnull align 1 %29, ptr nonnull align 1 %0, i64 %1, i1 false)
  br label %30

30:                                               ; preds = %28, %25
  %31 = getelementptr inbounds i8, ptr %12, i64 %10
  store i8 0, ptr %31, align 1, !tbaa !9
  br i1 %.not, label %33, label %32

32:                                               ; preds = %30
  store i64 %10, ptr %4, align 8, !tbaa !5
  br label %33

33:                                               ; preds = %30, %32, %7
  ret ptr %12
}

; Function Attrs: mustprogress nofree nounwind willreturn allockind("alloc,uninitialized") allocsize(0) memory(inaccessiblemem: readwrite)
declare noalias noundef ptr @malloc(i64 noundef) local_unnamed_addr #1

; Function Attrs: inlinehint nounwind uwtable
declare hidden zeroext i16 @__bswap_16(i16 noundef zeroext) local_unnamed_addr #2

; Function Attrs: mustprogress nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #3

; Function Attrs: inlinehint nounwind uwtable
declare hidden i64 @__bswap_64(i64 noundef) local_unnamed_addr #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 = { mustprogress nofree nounwind willreturn allockind("alloc,uninitialized") allocsize(0) memory(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 #2 = { inlinehint 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 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #4 = { nounwind allocsize(0) }

!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 = !{!7, !7, i64 0}


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