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

; 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_tcp_conn_t = type { ptr, ptr, ptr, ptr, ptr, ptr, ptr, i32 }
%struct.mln_chain_s = type { ptr, ptr }
%struct.mln_buf_s = type { ptr, ptr, ptr, ptr, ptr, ptr, i64, i64, i64, ptr, i8 }

@master_conn = external dso_local global %struct.mln_tcp_conn_t, align 8

; 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 i32 @mln_event_fd_set(ptr noundef, i32 noundef, i32 noundef, i32 noundef, ptr noundef, ptr noundef) #1

declare ptr @mln_chain_new(ptr noundef) #1

declare ptr @mln_buf_new(ptr noundef) #1

declare void @mln_chain_pool_release(ptr noundef) #1

declare ptr @mln_alloc_m(ptr noundef, i64 noundef) #1

; 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) #2

declare void @mln_tcp_conn_append(ptr noundef, ptr noundef, i32 noundef) #1

; Function Attrs: nounwind uwtable
define dso_local i32 @mln_ipc_worker_send_prepare(ptr noundef nonnull %0, i32 noundef %1, ptr noundef nonnull %2, i64 noundef %3) #3 {
  %5 = alloca i32, align 4
  %6 = alloca ptr, align 8
  %7 = alloca i32, align 4
  %8 = alloca ptr, align 8
  %9 = alloca i64, align 8
  %10 = alloca i32, align 4
  %11 = alloca ptr, align 8
  %12 = alloca ptr, align 8
  %13 = alloca ptr, align 8
  %14 = alloca i64, align 8
  %15 = alloca ptr, align 8
  %16 = alloca ptr, align 8
  %17 = alloca i32, align 4
  store ptr %0, ptr %6, align 8, !tbaa !5
  store i32 %1, ptr %7, align 4, !tbaa !9
  store ptr %2, ptr %8, align 8, !tbaa !5
  store i64 %3, ptr %9, align 8, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #4
  %18 = load i64, ptr %9, align 8, !tbaa !11
  %19 = add i64 4, %18
  %20 = trunc i64 %19 to i32
  store i32 %20, ptr %10, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr %12) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr %13) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr %14) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr %15) #4
  store ptr @master_conn, ptr %15, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %16) #4
  %21 = load ptr, ptr %15, align 8, !tbaa !5
  %22 = getelementptr inbounds %struct.mln_tcp_conn_t, ptr %21, i32 0, i32 0
  %23 = load ptr, ptr %22, align 8, !tbaa !13
  store ptr %23, ptr %16, align 8, !tbaa !5
  %24 = load i32, ptr %10, align 4, !tbaa !9
  %25 = zext i32 %24 to i64
  %26 = add i64 %25, 4
  store i64 %26, ptr %14, align 8, !tbaa !11
  %27 = load ptr, ptr %16, align 8, !tbaa !5
  %28 = call ptr @mln_chain_new(ptr noundef %27)
  store ptr %28, ptr %12, align 8, !tbaa !5
  %29 = load ptr, ptr %12, align 8, !tbaa !5
  %30 = icmp eq ptr %29, null
  br i1 %30, label %31, label %32

31:                                               ; preds = %4
  store i32 -1, ptr %5, align 4
  store i32 1, ptr %17, align 4
  br label %95

32:                                               ; preds = %4
  %33 = load ptr, ptr %16, align 8, !tbaa !5
  %34 = call ptr @mln_buf_new(ptr noundef %33)
  store ptr %34, ptr %13, align 8, !tbaa !5
  %35 = load ptr, ptr %13, align 8, !tbaa !5
  %36 = icmp eq ptr %35, null
  br i1 %36, label %37, label %39

37:                                               ; preds = %32
  %38 = load ptr, ptr %12, align 8, !tbaa !5
  call void @mln_chain_pool_release(ptr noundef %38)
  store i32 -1, ptr %5, align 4
  store i32 1, ptr %17, align 4
  br label %95

39:                                               ; preds = %32
  %40 = load ptr, ptr %13, align 8, !tbaa !5
  %41 = load ptr, ptr %12, align 8, !tbaa !5
  %42 = getelementptr inbounds %struct.mln_chain_s, ptr %41, i32 0, i32 0
  store ptr %40, ptr %42, align 8, !tbaa !15
  %43 = load ptr, ptr %16, align 8, !tbaa !5
  %44 = load i64, ptr %14, align 8, !tbaa !11
  %45 = call ptr @mln_alloc_m(ptr noundef %43, i64 noundef %44)
  store ptr %45, ptr %11, align 8, !tbaa !5
  %46 = load ptr, ptr %11, align 8, !tbaa !5
  %47 = icmp eq ptr %46, null
  br i1 %47, label %48, label %50

48:                                               ; preds = %39
  %49 = load ptr, ptr %12, align 8, !tbaa !5
  call void @mln_chain_pool_release(ptr noundef %49)
  store i32 -1, ptr %5, align 4
  store i32 1, ptr %17, align 4
  br label %95

50:                                               ; preds = %39
  %51 = load ptr, ptr %11, align 8, !tbaa !5
  %52 = load ptr, ptr %13, align 8, !tbaa !5
  %53 = getelementptr inbounds %struct.mln_buf_s, ptr %52, i32 0, i32 3
  store ptr %51, ptr %53, align 8, !tbaa !17
  %54 = load ptr, ptr %13, align 8, !tbaa !5
  %55 = getelementptr inbounds %struct.mln_buf_s, ptr %54, i32 0, i32 1
  store ptr %51, ptr %55, align 8, !tbaa !19
  %56 = load ptr, ptr %13, align 8, !tbaa !5
  %57 = getelementptr inbounds %struct.mln_buf_s, ptr %56, i32 0, i32 0
  store ptr %51, ptr %57, align 8, !tbaa !20
  %58 = load ptr, ptr %11, align 8, !tbaa !5
  %59 = load i64, ptr %14, align 8, !tbaa !11
  %60 = getelementptr inbounds i8, ptr %58, i64 %59
  %61 = load ptr, ptr %13, align 8, !tbaa !5
  %62 = getelementptr inbounds %struct.mln_buf_s, ptr %61, i32 0, i32 4
  store ptr %60, ptr %62, align 8, !tbaa !21
  %63 = load ptr, ptr %13, align 8, !tbaa !5
  %64 = getelementptr inbounds %struct.mln_buf_s, ptr %63, i32 0, i32 2
  store ptr %60, ptr %64, align 8, !tbaa !22
  %65 = load ptr, ptr %13, align 8, !tbaa !5
  %66 = getelementptr inbounds %struct.mln_buf_s, ptr %65, i32 0, i32 10
  %67 = load i8, ptr %66, align 8
  %68 = and i8 %67, -5
  %69 = or i8 %68, 4
  store i8 %69, ptr %66, align 8
  %70 = load ptr, ptr %13, align 8, !tbaa !5
  %71 = getelementptr inbounds %struct.mln_buf_s, ptr %70, i32 0, i32 10
  %72 = load i8, ptr %71, align 8
  %73 = and i8 %72, -65
  %74 = or i8 %73, 64
  store i8 %74, ptr %71, align 8
  %75 = load ptr, ptr %13, align 8, !tbaa !5
  %76 = getelementptr inbounds %struct.mln_buf_s, ptr %75, i32 0, i32 10
  %77 = load i8, ptr %76, align 8
  %78 = and i8 %77, 127
  %79 = or i8 %78, -128
  store i8 %79, ptr %76, align 8
  %80 = load ptr, ptr %11, align 8, !tbaa !5
  call void @llvm.memcpy.p0.p0.i64(ptr align 1 %80, ptr align 4 %10, i64 4, i1 false)
  %81 = load ptr, ptr %11, align 8, !tbaa !5
  %82 = getelementptr inbounds i8, ptr %81, i64 4
  call void @llvm.memcpy.p0.p0.i64(ptr align 1 %82, ptr align 4 %7, i64 4, i1 false)
  %83 = load ptr, ptr %11, align 8, !tbaa !5
  %84 = getelementptr inbounds i8, ptr %83, i64 4
  %85 = getelementptr inbounds i8, ptr %84, i64 4
  %86 = load ptr, ptr %8, align 8, !tbaa !5
  %87 = load i64, ptr %9, align 8, !tbaa !11
  call void @llvm.memcpy.p0.p0.i64(ptr align 1 %85, ptr align 1 %86, i64 %87, i1 false)
  %88 = load ptr, ptr %15, align 8, !tbaa !5
  %89 = load ptr, ptr %12, align 8, !tbaa !5
  call void @mln_tcp_conn_append(ptr noundef %88, ptr noundef %89, i32 noundef 1)
  %90 = load ptr, ptr %6, align 8, !tbaa !5
  %91 = load ptr, ptr %15, align 8, !tbaa !5
  %92 = getelementptr inbounds %struct.mln_tcp_conn_t, ptr %91, i32 0, i32 7
  %93 = load i32, ptr %92, align 8, !tbaa !23
  %94 = call i32 @mln_event_fd_set(ptr noundef %90, i32 noundef %93, i32 noundef 90, i32 noundef -1, ptr noundef null, ptr noundef @mln_ipc_fd_handler_worker_send)
  store i32 0, ptr %5, align 4
  store i32 1, ptr %17, align 4
  br label %95

95:                                               ; preds = %50, %48, %37, %31
  call void @llvm.lifetime.end.p0(i64 8, ptr %16) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %15) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %14) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %13) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #4
  %96 = load i32, ptr %5, align 4
  ret i32 %96
}

; Function Attrs: nounwind uwtable
declare hidden void @mln_ipc_fd_handler_worker_send(ptr noundef, i32 noundef, ptr noundef) #3

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 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #3 = { 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 = { 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 = !{!"int", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"long", !7, i64 0}
!13 = !{!14, !6, i64 0}
!14 = !{!"", !6, i64 0, !6, i64 8, !6, i64 16, !6, i64 24, !6, i64 32, !6, i64 40, !6, i64 48, !10, i64 56}
!15 = !{!16, !6, i64 0}
!16 = !{!"mln_chain_s", !6, i64 0, !6, i64 8}
!17 = !{!18, !6, i64 24}
!18 = !{!"mln_buf_s", !6, i64 0, !6, i64 8, !6, i64 16, !6, i64 24, !6, i64 32, !6, i64 40, !12, i64 48, !12, i64 56, !12, i64 64, !6, i64 72, !10, i64 80, !10, i64 80, !10, i64 80, !10, i64 80, !10, i64 80, !10, i64 80, !10, i64 80, !10, i64 80}
!19 = !{!18, !6, i64 8}
!20 = !{!18, !6, i64 0}
!21 = !{!18, !6, i64 32}
!22 = !{!18, !6, i64 16}
!23 = !{!14, !10, i64 56}


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

%struct.mln_tcp_conn_t = type { ptr, ptr, ptr, ptr, ptr, ptr, ptr, i32 }

@master_conn = external dso_local global %struct.mln_tcp_conn_t, align 8

declare i32 @mln_event_fd_set(ptr noundef, i32 noundef, i32 noundef, i32 noundef, ptr noundef, ptr noundef) local_unnamed_addr #0

declare ptr @mln_chain_new(ptr noundef) local_unnamed_addr #0

declare ptr @mln_buf_new(ptr noundef) local_unnamed_addr #0

declare void @mln_chain_pool_release(ptr noundef) local_unnamed_addr #0

declare ptr @mln_alloc_m(ptr noundef, i64 noundef) local_unnamed_addr #0

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

declare void @mln_tcp_conn_append(ptr noundef, ptr noundef, i32 noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local range(i32 -1, 1) i32 @mln_ipc_worker_send_prepare(ptr noundef nonnull %0, i32 noundef %1, ptr nocapture noundef nonnull readonly %2, i64 noundef %3) local_unnamed_addr #2 {
  %5 = trunc i64 %3 to i32
  %6 = add i32 %5, 4
  %7 = load ptr, ptr @master_conn, align 8, !tbaa !5
  %8 = zext i32 %6 to i64
  %9 = add nuw nsw i64 %8, 4
  %10 = tail call ptr @mln_chain_new(ptr noundef %7) #3
  %11 = icmp eq ptr %10, null
  br i1 %11, label %33, label %12

12:                                               ; preds = %4
  %13 = tail call ptr @mln_buf_new(ptr noundef %7) #3
  %14 = icmp eq ptr %13, null
  br i1 %14, label %15, label %16

15:                                               ; preds = %12
  tail call void @mln_chain_pool_release(ptr noundef nonnull %10) #3
  br label %33

16:                                               ; preds = %12
  store ptr %13, ptr %10, align 8, !tbaa !11
  %17 = tail call ptr @mln_alloc_m(ptr noundef %7, i64 noundef %9) #3
  %18 = icmp eq ptr %17, null
  br i1 %18, label %19, label %20

19:                                               ; preds = %16
  tail call void @mln_chain_pool_release(ptr noundef nonnull %10) #3
  br label %33

20:                                               ; preds = %16
  %21 = getelementptr inbounds i8, ptr %13, i64 24
  store ptr %17, ptr %21, align 8, !tbaa !13
  %22 = getelementptr inbounds i8, ptr %13, i64 8
  store ptr %17, ptr %22, align 8, !tbaa !16
  store ptr %17, ptr %13, align 8, !tbaa !17
  %23 = getelementptr inbounds i8, ptr %17, i64 %9
  %24 = getelementptr inbounds i8, ptr %13, i64 32
  store ptr %23, ptr %24, align 8, !tbaa !18
  %25 = getelementptr inbounds i8, ptr %13, i64 16
  store ptr %23, ptr %25, align 8, !tbaa !19
  %26 = getelementptr inbounds i8, ptr %13, i64 80
  %27 = load i8, ptr %26, align 8
  %28 = or i8 %27, -60
  store i8 %28, ptr %26, align 8
  store i32 %6, ptr %17, align 1
  %29 = getelementptr inbounds i8, ptr %17, i64 4
  store i32 %1, ptr %29, align 1
  %30 = getelementptr inbounds i8, ptr %17, i64 8
  tail call void @llvm.memcpy.p0.p0.i64(ptr nonnull align 1 %30, ptr nonnull align 1 %2, i64 %3, i1 false)
  tail call void @mln_tcp_conn_append(ptr noundef nonnull @master_conn, ptr noundef nonnull %10, i32 noundef 1) #3
  %31 = load i32, ptr getelementptr inbounds (i8, ptr @master_conn, i64 56), align 8, !tbaa !20
  %32 = tail call i32 @mln_event_fd_set(ptr noundef nonnull %0, i32 noundef %31, i32 noundef 90, i32 noundef -1, ptr noundef null, ptr noundef nonnull @mln_ipc_fd_handler_worker_send) #3
  br label %33

33:                                               ; preds = %4, %20, %19, %15
  %.0 = phi i32 [ -1, %15 ], [ -1, %19 ], [ 0, %20 ], [ -1, %4 ]
  ret i32 %.0
}

; Function Attrs: nounwind uwtable
declare hidden void @mln_ipc_fd_handler_worker_send(ptr noundef, i32 noundef, 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 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: readwrite) }
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, !7, i64 0}
!6 = !{!"", !7, i64 0, !7, i64 8, !7, i64 16, !7, i64 24, !7, i64 32, !7, i64 40, !7, i64 48, !10, i64 56}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"int", !8, i64 0}
!11 = !{!12, !7, i64 0}
!12 = !{!"mln_chain_s", !7, i64 0, !7, i64 8}
!13 = !{!14, !7, i64 24}
!14 = !{!"mln_buf_s", !7, i64 0, !7, i64 8, !7, i64 16, !7, i64 24, !7, i64 32, !7, i64 40, !15, i64 48, !15, i64 56, !15, i64 64, !7, i64 72, !10, i64 80, !10, i64 80, !10, i64 80, !10, i64 80, !10, i64 80, !10, i64 80, !10, i64 80, !10, i64 80}
!15 = !{!"long", !8, i64 0}
!16 = !{!14, !7, i64 8}
!17 = !{!14, !7, i64 0}
!18 = !{!14, !7, i64 32}
!19 = !{!14, !7, i64 16}
!20 = !{!6, !10, i64 56}


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