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

; 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_iothread_s = type { %union.pthread_mutex_t, %union.pthread_mutex_t, i32, i32, ptr, ptr, ptr, ptr, ptr, ptr, i32, ptr, ptr }
%union.pthread_mutex_t = type { %struct.__pthread_mutex_s }
%struct.__pthread_mutex_s = type { i32, i32, i32, i32, i32, i16, i16, %struct.__pthread_internal_list }
%struct.__pthread_internal_list = type { ptr, ptr }
%struct.mln_iothread_msg_s = type { ptr, ptr, i32, i32, ptr, %union.pthread_mutex_t }

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

; Function Attrs: inlinehint nounwind uwtable
declare hidden void @mln_iothread_msg_chain_del(ptr noundef, ptr noundef, ptr noundef) #2

; Function Attrs: nounwind
declare i32 @pthread_mutex_unlock(ptr noundef) #1

; Function Attrs: inlinehint nounwind uwtable
declare hidden void @mln_iothread_msg_free(ptr noundef) #2

; Function Attrs: nounwind uwtable
define dso_local i32 @mln_iothread_recv(ptr noundef %0, i32 noundef %1) #3 {
  %3 = alloca ptr, align 8
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  %7 = alloca i8, align 1
  %8 = alloca ptr, align 8
  %9 = alloca ptr, align 8
  %10 = alloca ptr, align 8
  %11 = alloca ptr, align 8
  %12 = alloca ptr, align 8
  store ptr %0, ptr %3, align 8, !tbaa !5
  store i32 %1, ptr %4, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #5
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #5
  store i32 0, ptr %6, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 1, ptr %7) #5
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #5
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #5
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #5
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #5
  call void @llvm.lifetime.start.p0(i64 8, ptr %12) #5
  %13 = load i32, ptr %4, align 4, !tbaa !9
  %14 = icmp eq i32 %13, 0
  br i1 %14, label %15, label %25

15:                                               ; preds = %2
  %16 = load ptr, ptr %3, align 8, !tbaa !5
  %17 = getelementptr inbounds %struct.mln_iothread_s, ptr %16, i32 0, i32 3
  %18 = load i32, ptr %17, align 4, !tbaa !11
  store i32 %18, ptr %5, align 4, !tbaa !9
  %19 = load ptr, ptr %3, align 8, !tbaa !5
  %20 = getelementptr inbounds %struct.mln_iothread_s, ptr %19, i32 0, i32 1
  store ptr %20, ptr %8, align 8, !tbaa !5
  %21 = load ptr, ptr %3, align 8, !tbaa !5
  %22 = getelementptr inbounds %struct.mln_iothread_s, ptr %21, i32 0, i32 11
  store ptr %22, ptr %11, align 8, !tbaa !5
  %23 = load ptr, ptr %3, align 8, !tbaa !5
  %24 = getelementptr inbounds %struct.mln_iothread_s, ptr %23, i32 0, i32 12
  store ptr %24, ptr %12, align 8, !tbaa !5
  br label %35

25:                                               ; preds = %2
  %26 = load ptr, ptr %3, align 8, !tbaa !5
  %27 = getelementptr inbounds %struct.mln_iothread_s, ptr %26, i32 0, i32 2
  %28 = load i32, ptr %27, align 8, !tbaa !13
  store i32 %28, ptr %5, align 4, !tbaa !9
  %29 = load ptr, ptr %3, align 8, !tbaa !5
  %30 = getelementptr inbounds %struct.mln_iothread_s, ptr %29, i32 0, i32 0
  store ptr %30, ptr %8, align 8, !tbaa !5
  %31 = load ptr, ptr %3, align 8, !tbaa !5
  %32 = getelementptr inbounds %struct.mln_iothread_s, ptr %31, i32 0, i32 5
  store ptr %32, ptr %11, align 8, !tbaa !5
  %33 = load ptr, ptr %3, align 8, !tbaa !5
  %34 = getelementptr inbounds %struct.mln_iothread_s, ptr %33, i32 0, i32 6
  store ptr %34, ptr %12, align 8, !tbaa !5
  br label %35

35:                                               ; preds = %25, %15
  %36 = load ptr, ptr %8, align 8, !tbaa !5
  %37 = call i32 @pthread_mutex_lock(ptr noundef %36) #5
  %38 = load ptr, ptr %11, align 8, !tbaa !5
  %39 = load ptr, ptr %38, align 8, !tbaa !5
  store ptr %39, ptr %10, align 8, !tbaa !5
  br label %40

40:                                               ; preds = %79, %35
  %41 = load ptr, ptr %11, align 8, !tbaa !5
  %42 = load ptr, ptr %41, align 8, !tbaa !5
  store ptr %42, ptr %9, align 8, !tbaa !5
  %43 = icmp ne ptr %42, null
  br i1 %43, label %44, label %82

44:                                               ; preds = %40
  %45 = load ptr, ptr %11, align 8, !tbaa !5
  %46 = load ptr, ptr %12, align 8, !tbaa !5
  %47 = load ptr, ptr %9, align 8, !tbaa !5
  call void @mln_iothread_msg_chain_del(ptr noundef %45, ptr noundef %46, ptr noundef %47)
  %48 = load ptr, ptr %3, align 8, !tbaa !5
  %49 = getelementptr inbounds %struct.mln_iothread_s, ptr %48, i32 0, i32 4
  %50 = load ptr, ptr %49, align 8, !tbaa !14
  %51 = icmp ne ptr %50, null
  br i1 %51, label %52, label %59

52:                                               ; preds = %44
  %53 = load ptr, ptr %3, align 8, !tbaa !5
  %54 = getelementptr inbounds %struct.mln_iothread_s, ptr %53, i32 0, i32 4
  %55 = load ptr, ptr %54, align 8, !tbaa !14
  %56 = load ptr, ptr %3, align 8, !tbaa !5
  %57 = load i32, ptr %4, align 4, !tbaa !9
  %58 = load ptr, ptr %9, align 8, !tbaa !5
  call void %55(ptr noundef %56, i32 noundef %57, ptr noundef %58)
  br label %59

59:                                               ; preds = %52, %44
  %60 = load ptr, ptr %9, align 8, !tbaa !5
  %61 = getelementptr inbounds %struct.mln_iothread_msg_s, ptr %60, i32 0, i32 2
  %62 = load i32, ptr %61, align 8
  %63 = and i32 %62, 1
  %64 = icmp ne i32 %63, 0
  br i1 %64, label %65, label %77

65:                                               ; preds = %59
  %66 = load ptr, ptr %9, align 8, !tbaa !5
  %67 = getelementptr inbounds %struct.mln_iothread_msg_s, ptr %66, i32 0, i32 2
  %68 = load i32, ptr %67, align 8
  %69 = lshr i32 %68, 1
  %70 = and i32 %69, 1
  %71 = icmp ne i32 %70, 0
  br i1 %71, label %76, label %72

72:                                               ; preds = %65
  %73 = load ptr, ptr %9, align 8, !tbaa !5
  %74 = getelementptr inbounds %struct.mln_iothread_msg_s, ptr %73, i32 0, i32 5
  %75 = call i32 @pthread_mutex_unlock(ptr noundef %74) #5
  br label %76

76:                                               ; preds = %72, %65
  br label %79

77:                                               ; preds = %59
  %78 = load ptr, ptr %9, align 8, !tbaa !5
  call void @mln_iothread_msg_free(ptr noundef %78)
  br label %79

79:                                               ; preds = %77, %76
  %80 = load i32, ptr %6, align 4, !tbaa !9
  %81 = add nsw i32 %80, 1
  store i32 %81, ptr %6, align 4, !tbaa !9
  br label %40, !llvm.loop !15

82:                                               ; preds = %40
  %83 = load ptr, ptr %10, align 8, !tbaa !5
  %84 = load ptr, ptr %11, align 8, !tbaa !5
  %85 = load ptr, ptr %84, align 8, !tbaa !5
  %86 = icmp ne ptr %83, %85
  br i1 %86, label %87, label %90

87:                                               ; preds = %82
  %88 = load i32, ptr %5, align 4, !tbaa !9
  %89 = call i64 @recv(i32 noundef %88, ptr noundef %7, i64 noundef 1, i32 noundef 0)
  br label %90

90:                                               ; preds = %87, %82
  %91 = load ptr, ptr %8, align 8, !tbaa !5
  %92 = call i32 @pthread_mutex_unlock(ptr noundef %91) #5
  %93 = load i32, ptr %6, align 4, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #5
  call void @llvm.lifetime.end.p0(i64 1, ptr %7) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #5
  ret i32 %93
}

declare i64 @recv(i32 noundef, ptr noundef, i64 noundef, i32 noundef) #4

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 #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 = { 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 = { "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 #5 = { 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, !10, i64 84}
!12 = !{!"mln_iothread_s", !7, i64 0, !7, i64 40, !10, i64 80, !10, i64 84, !6, i64 88, !6, i64 96, !6, i64 104, !6, i64 112, !6, i64 120, !6, i64 128, !10, i64 136, !6, i64 144, !6, i64 152}
!13 = !{!12, !10, i64 80}
!14 = !{!12, !6, i64 88}
!15 = distinct !{!15, !16}
!16 = !{!"llvm.loop.mustprogress"}


; 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
declare i32 @pthread_mutex_lock(ptr noundef) local_unnamed_addr #1

; Function Attrs: inlinehint nounwind uwtable
declare hidden void @mln_iothread_msg_chain_del(ptr noundef, ptr noundef, ptr noundef) local_unnamed_addr #2

; Function Attrs: nounwind
declare i32 @pthread_mutex_unlock(ptr noundef) local_unnamed_addr #1

; Function Attrs: inlinehint nounwind uwtable
declare hidden void @mln_iothread_msg_free(ptr noundef) local_unnamed_addr #2

; Function Attrs: nounwind uwtable
define dso_local i32 @mln_iothread_recv(ptr noundef %0, i32 noundef %1) local_unnamed_addr #3 {
  %3 = alloca i8, align 1
  call void @llvm.lifetime.start.p0(i64 1, ptr nonnull %3) #5
  %4 = icmp eq i32 %1, 0
  br i1 %4, label %5, label %8

5:                                                ; preds = %2
  %6 = getelementptr inbounds i8, ptr %0, i64 84
  %7 = getelementptr inbounds i8, ptr %0, i64 40
  br label %10

8:                                                ; preds = %2
  %9 = getelementptr inbounds i8, ptr %0, i64 80
  br label %10

10:                                               ; preds = %8, %5
  %.sink43 = phi i64 [ 96, %8 ], [ 144, %5 ]
  %.sink = phi i64 [ 104, %8 ], [ 152, %5 ]
  %.032 = phi ptr [ %0, %8 ], [ %7, %5 ]
  %.030.in = phi ptr [ %9, %8 ], [ %6, %5 ]
  %11 = getelementptr inbounds i8, ptr %0, i64 %.sink43
  %12 = getelementptr inbounds i8, ptr %0, i64 %.sink
  %.030 = load i32, ptr %.030.in, align 4, !tbaa !5
  %13 = tail call i32 @pthread_mutex_lock(ptr noundef %.032) #5
  %14 = load ptr, ptr %11, align 8, !tbaa !9
  %.not39 = icmp eq ptr %14, null
  br i1 %.not39, label %._crit_edge.thread, label %.lr.ph

.lr.ph:                                           ; preds = %10
  %15 = getelementptr inbounds i8, ptr %0, i64 88
  br label %16

16:                                               ; preds = %.lr.ph, %30
  %.03140 = phi i32 [ 0, %.lr.ph ], [ %31, %30 ]
  %17 = phi ptr [ %14, %.lr.ph ], [ %.pr, %30 ]
  tail call void @mln_iothread_msg_chain_del(ptr noundef nonnull %11, ptr noundef nonnull %12, ptr noundef nonnull %17)
  %18 = load ptr, ptr %15, align 8, !tbaa !11
  %.not36 = icmp eq ptr %18, null
  br i1 %.not36, label %20, label %19

19:                                               ; preds = %16
  tail call void %18(ptr noundef nonnull %0, i32 noundef %1, ptr noundef nonnull %17) #5
  br label %20

20:                                               ; preds = %19, %16
  %21 = getelementptr inbounds i8, ptr %17, i64 16
  %22 = load i32, ptr %21, align 8
  %23 = and i32 %22, 1
  %.not37 = icmp eq i32 %23, 0
  br i1 %.not37, label %29, label %24

24:                                               ; preds = %20
  %25 = and i32 %22, 2
  %.not38 = icmp eq i32 %25, 0
  br i1 %.not38, label %26, label %30

26:                                               ; preds = %24
  %27 = getelementptr inbounds i8, ptr %17, i64 32
  %28 = tail call i32 @pthread_mutex_unlock(ptr noundef nonnull %27) #5
  br label %30

29:                                               ; preds = %20
  tail call void @mln_iothread_msg_free(ptr noundef nonnull %17)
  br label %30

30:                                               ; preds = %24, %26, %29
  %31 = add nuw nsw i32 %.03140, 1
  %.pr = load ptr, ptr %11, align 8, !tbaa !9
  %.not = icmp eq ptr %.pr, null
  br i1 %.not, label %._crit_edge, label %16, !llvm.loop !13

._crit_edge:                                      ; preds = %30
  br i1 %.not39, label %._crit_edge.thread, label %32

32:                                               ; preds = %._crit_edge
  %33 = call i64 @recv(i32 noundef %.030, ptr noundef nonnull %3, i64 noundef 1, i32 noundef 0) #5
  br label %._crit_edge.thread

._crit_edge.thread:                               ; preds = %10, %32, %._crit_edge
  %.031.lcssa42 = phi i32 [ %31, %32 ], [ %31, %._crit_edge ], [ 0, %10 ]
  %34 = call i32 @pthread_mutex_unlock(ptr noundef %.032) #5
  call void @llvm.lifetime.end.p0(i64 1, ptr nonnull %3) #5
  ret i32 %.031.lcssa42
}

declare i64 @recv(i32 noundef, ptr noundef, i64 noundef, i32 noundef) local_unnamed_addr #4

attributes #0 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 #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 = { 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 = { "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 #5 = { 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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"any pointer", !7, i64 0}
!11 = !{!12, !10, i64 88}
!12 = !{!"mln_iothread_s", !7, i64 0, !7, i64 40, !6, i64 80, !6, i64 84, !10, i64 88, !10, i64 96, !10, i64 104, !10, i64 112, !10, i64 120, !10, i64 128, !6, i64 136, !10, i64 144, !10, i64 152}
!13 = distinct !{!13, !14}
!14 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LICMPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,SROAPass,SimplifyCFGPass,TailCallElimPass