; LLVM IR from Water-Melon/Melon :: src (mln_websocket)

; 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.mln_websocket_s = type { ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, i64, i16, i16, i32 }

declare void @mln_alloc_free(ptr noundef) #0

; Function Attrs: nounwind uwtable
declare hidden i32 @mln_websocket_masking_key_generate() #1

; Function Attrs: nounwind uwtable
declare dso_local i32 @mln_websocket_generate(ptr noundef nonnull, ptr noundef) #1

; Function Attrs: nounwind uwtable
define dso_local i32 @mln_websocket_close_generate(ptr noundef nonnull %0, ptr noundef nonnull %1, ptr noundef %2, i16 noundef zeroext %3, i32 noundef %4) #1 {
  %6 = alloca i32, align 4
  %7 = alloca ptr, align 8
  %8 = alloca ptr, align 8
  %9 = alloca ptr, align 8
  %10 = alloca i16, align 2
  %11 = alloca i32, align 4
  store ptr %0, ptr %7, align 8, !tbaa !5
  store ptr %1, ptr %8, align 8, !tbaa !5
  store ptr %2, ptr %9, align 8, !tbaa !5
  store i16 %3, ptr %10, align 2, !tbaa !9
  store i32 %4, ptr %11, align 4, !tbaa !11
  %12 = load i32, ptr %11, align 4, !tbaa !11
  %13 = and i32 %12, 4
  %14 = icmp ne i32 %13, 0
  br i1 %14, label %15, label %20

15:                                               ; preds = %5
  %16 = load i32, ptr %11, align 4, !tbaa !11
  %17 = and i32 %16, 8
  %18 = icmp ne i32 %17, 0
  br i1 %18, label %19, label %20

19:                                               ; preds = %15
  store i32 -1, ptr %6, align 4
  br label %97

20:                                               ; preds = %15, %5
  %21 = load ptr, ptr %7, align 8, !tbaa !5
  %22 = getelementptr inbounds %struct.mln_websocket_s, ptr %21, i32 0, i32 11
  %23 = load i16, ptr %22, align 8
  %24 = and i16 %23, 1
  %25 = icmp ne i16 %24, 0
  br i1 %25, label %26, label %35

26:                                               ; preds = %20
  %27 = load ptr, ptr %7, align 8, !tbaa !5
  %28 = getelementptr inbounds %struct.mln_websocket_s, ptr %27, i32 0, i32 8
  %29 = load ptr, ptr %28, align 8, !tbaa !13
  call void @mln_alloc_free(ptr noundef %29)
  %30 = load ptr, ptr %7, align 8, !tbaa !5
  %31 = getelementptr inbounds %struct.mln_websocket_s, ptr %30, i32 0, i32 11
  %32 = load i16, ptr %31, align 8
  %33 = and i16 %32, -2
  %34 = or i16 %33, 0
  store i16 %34, ptr %31, align 8
  br label %35

35:                                               ; preds = %26, %20
  %36 = load ptr, ptr %9, align 8, !tbaa !5
  %37 = load ptr, ptr %7, align 8, !tbaa !5
  %38 = getelementptr inbounds %struct.mln_websocket_s, ptr %37, i32 0, i32 8
  store ptr %36, ptr %38, align 8, !tbaa !13
  %39 = load ptr, ptr %9, align 8, !tbaa !5
  %40 = icmp eq ptr %39, null
  br i1 %40, label %41, label %44

41:                                               ; preds = %35
  %42 = load ptr, ptr %7, align 8, !tbaa !5
  %43 = getelementptr inbounds %struct.mln_websocket_s, ptr %42, i32 0, i32 10
  store i64 0, ptr %43, align 8, !tbaa !16
  br label %49

44:                                               ; preds = %35
  %45 = load ptr, ptr %9, align 8, !tbaa !5
  %46 = call i64 @strlen(ptr noundef %45) #3
  %47 = load ptr, ptr %7, align 8, !tbaa !5
  %48 = getelementptr inbounds %struct.mln_websocket_s, ptr %47, i32 0, i32 10
  store i64 %46, ptr %48, align 8, !tbaa !16
  br label %49

49:                                               ; preds = %44, %41
  %50 = load ptr, ptr %7, align 8, !tbaa !5
  %51 = getelementptr inbounds %struct.mln_websocket_s, ptr %50, i32 0, i32 11
  %52 = load i16, ptr %51, align 8
  %53 = and i16 %52, -3
  %54 = or i16 %53, 2
  store i16 %54, ptr %51, align 8
  %55 = load ptr, ptr %7, align 8, !tbaa !5
  %56 = getelementptr inbounds %struct.mln_websocket_s, ptr %55, i32 0, i32 11
  %57 = load i16, ptr %56, align 8
  %58 = and i16 %57, -5
  %59 = or i16 %58, 0
  store i16 %59, ptr %56, align 8
  %60 = load ptr, ptr %7, align 8, !tbaa !5
  %61 = getelementptr inbounds %struct.mln_websocket_s, ptr %60, i32 0, i32 11
  %62 = load i16, ptr %61, align 8
  %63 = and i16 %62, -9
  %64 = or i16 %63, 0
  store i16 %64, ptr %61, align 8
  %65 = load ptr, ptr %7, align 8, !tbaa !5
  %66 = getelementptr inbounds %struct.mln_websocket_s, ptr %65, i32 0, i32 11
  %67 = load i16, ptr %66, align 8
  %68 = and i16 %67, -17
  %69 = or i16 %68, 0
  store i16 %69, ptr %66, align 8
  %70 = load ptr, ptr %7, align 8, !tbaa !5
  %71 = getelementptr inbounds %struct.mln_websocket_s, ptr %70, i32 0, i32 11
  %72 = load i16, ptr %71, align 8
  %73 = and i16 %72, -481
  %74 = or i16 %73, 256
  store i16 %74, ptr %71, align 8
  %75 = load i32, ptr %11, align 4, !tbaa !11
  %76 = and i32 %75, 4
  %77 = icmp ne i32 %76, 0
  br i1 %77, label %78, label %87

78:                                               ; preds = %49
  %79 = load ptr, ptr %7, align 8, !tbaa !5
  %80 = getelementptr inbounds %struct.mln_websocket_s, ptr %79, i32 0, i32 11
  %81 = load i16, ptr %80, align 8
  %82 = and i16 %81, -513
  %83 = or i16 %82, 512
  store i16 %83, ptr %80, align 8
  %84 = call i32 @mln_websocket_masking_key_generate()
  %85 = load ptr, ptr %7, align 8, !tbaa !5
  %86 = getelementptr inbounds %struct.mln_websocket_s, ptr %85, i32 0, i32 13
  store i32 %84, ptr %86, align 4, !tbaa !17
  br label %93

87:                                               ; preds = %49
  %88 = load ptr, ptr %7, align 8, !tbaa !5
  %89 = getelementptr inbounds %struct.mln_websocket_s, ptr %88, i32 0, i32 11
  %90 = load i16, ptr %89, align 8
  %91 = and i16 %90, -513
  %92 = or i16 %91, 0
  store i16 %92, ptr %89, align 8
  br label %93

93:                                               ; preds = %87, %78
  %94 = load ptr, ptr %7, align 8, !tbaa !5
  %95 = load ptr, ptr %8, align 8, !tbaa !5
  %96 = call i32 @mln_websocket_generate(ptr noundef %94, ptr noundef %95)
  store i32 %96, ptr %6, align 4
  br label %97

97:                                               ; preds = %93, %19
  %98 = load i32, ptr %6, align 4
  ret i32 %98
}

; Function Attrs: nounwind willreturn memory(read)
declare i64 @strlen(ptr noundef) #2

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 willreturn memory(read) "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 willreturn memory(read) }

!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 = !{!"short", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"int", !7, i64 0}
!13 = !{!14, !6, i64 64}
!14 = !{!"mln_websocket_s", !6, i64 0, !6, i64 8, !6, i64 16, !6, i64 24, !6, i64 32, !6, i64 40, !6, i64 48, !6, i64 56, !6, i64 64, !6, i64 72, !15, i64 80, !10, i64 88, !10, i64 88, !10, i64 88, !10, i64 88, !10, i64 88, !10, i64 88, !10, i64 89, !10, i64 89, !10, i64 90, !12, i64 92}
!15 = !{!"long", !7, i64 0}
!16 = !{!14, !15, i64 80}
!17 = !{!14, !12, i64 92}


; 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 void @mln_alloc_free(ptr noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
declare hidden i32 @mln_websocket_masking_key_generate() local_unnamed_addr #1

; Function Attrs: nounwind uwtable
declare dso_local i32 @mln_websocket_generate(ptr noundef nonnull, ptr noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
define dso_local i32 @mln_websocket_close_generate(ptr noundef nonnull %0, ptr noundef nonnull %1, ptr noundef %2, i16 noundef zeroext %3, i32 noundef %4) local_unnamed_addr #1 {
  %6 = and i32 %4, 4
  %.not = icmp eq i32 %6, 0
  %7 = and i32 %4, 12
  %or.cond.not = icmp eq i32 %7, 12
  br i1 %or.cond.not, label %34, label %8

8:                                                ; preds = %5
  %9 = getelementptr inbounds i8, ptr %0, i64 88
  %10 = load i16, ptr %9, align 8
  %11 = and i16 %10, 1
  %.not24 = icmp eq i16 %11, 0
  br i1 %.not24, label %17, label %12

12:                                               ; preds = %8
  %13 = getelementptr inbounds i8, ptr %0, i64 64
  %14 = load ptr, ptr %13, align 8, !tbaa !5
  tail call void @mln_alloc_free(ptr noundef %14) #3
  %15 = load i16, ptr %9, align 8
  %16 = and i16 %15, -2
  store i16 %16, ptr %9, align 8
  br label %17

17:                                               ; preds = %12, %8
  %18 = phi i16 [ %16, %12 ], [ %10, %8 ]
  %19 = getelementptr inbounds i8, ptr %0, i64 64
  store ptr %2, ptr %19, align 8, !tbaa !5
  %20 = icmp eq ptr %2, null
  br i1 %20, label %23, label %21

21:                                               ; preds = %17
  %22 = tail call i64 @strlen(ptr noundef nonnull dereferenceable(1) %2) #4
  br label %23

23:                                               ; preds = %17, %21
  %.sink = phi i64 [ %22, %21 ], [ 0, %17 ]
  %24 = getelementptr inbounds i8, ptr %0, i64 80
  store i64 %.sink, ptr %24, align 8
  %25 = and i16 %18, -1023
  br i1 %.not, label %30, label %26

26:                                               ; preds = %23
  %27 = or disjoint i16 %25, 770
  store i16 %27, ptr %9, align 8
  %28 = tail call i32 @mln_websocket_masking_key_generate()
  %29 = getelementptr inbounds i8, ptr %0, i64 92
  store i32 %28, ptr %29, align 4, !tbaa !13
  br label %32

30:                                               ; preds = %23
  %31 = or disjoint i16 %25, 258
  store i16 %31, ptr %9, align 8
  br label %32

32:                                               ; preds = %30, %26
  %33 = tail call i32 @mln_websocket_generate(ptr noundef %0, ptr noundef nonnull %1)
  br label %34

34:                                               ; preds = %5, %32
  %.0 = phi i32 [ %33, %32 ], [ -1, %5 ]
  ret i32 %.0
}

; Function Attrs: mustprogress nofree nounwind willreturn memory(argmem: read)
declare i64 @strlen(ptr nocapture noundef) local_unnamed_addr #2

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 = { mustprogress nofree nounwind willreturn memory(argmem: read) "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 }
attributes #4 = { nounwind willreturn memory(read) }

!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 64}
!6 = !{!"mln_websocket_s", !7, i64 0, !7, i64 8, !7, i64 16, !7, i64 24, !7, i64 32, !7, i64 40, !7, i64 48, !7, i64 56, !7, i64 64, !7, i64 72, !10, i64 80, !11, i64 88, !11, i64 88, !11, i64 88, !11, i64 88, !11, i64 88, !11, i64 88, !11, i64 89, !11, i64 89, !11, i64 90, !12, i64 92}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"long", !8, i64 0}
!11 = !{!"short", !8, i64 0}
!12 = !{!"int", !8, i64 0}
!13 = !{!6, !12, i64 92}


; Effective O3 passes: DSEPass,EarlyCSEPass,GVNPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,MergedLoadStoreMotionPass,SROAPass,SimplifyCFGPass,TailCallElimPass