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

@.str = external hidden unnamed_addr constant [2 x i8], align 1

; 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 i32 @mln_iothread_send(ptr noundef %0, i32 noundef %1, ptr noundef %2, i32 noundef %3, i32 noundef %4) #1 {
  %6 = alloca i32, align 4
  %7 = alloca ptr, align 8
  %8 = alloca i32, align 4
  %9 = alloca ptr, align 8
  %10 = alloca i32, align 4
  %11 = alloca i32, align 4
  %12 = alloca i32, align 4
  %13 = alloca ptr, align 8
  %14 = alloca ptr, align 8
  %15 = alloca ptr, align 8
  %16 = alloca ptr, align 8
  %17 = alloca i32, align 4
  store ptr %0, ptr %7, align 8, !tbaa !5
  store i32 %1, ptr %8, align 4, !tbaa !9
  store ptr %2, ptr %9, align 8, !tbaa !5
  store i32 %3, ptr %10, align 4, !tbaa !9
  store i32 %4, ptr %11, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %12) #5
  call void @llvm.lifetime.start.p0(i64 8, ptr %13) #5
  call void @llvm.lifetime.start.p0(i64 8, ptr %14) #5
  call void @llvm.lifetime.start.p0(i64 8, ptr %15) #5
  call void @llvm.lifetime.start.p0(i64 8, ptr %16) #5
  %18 = load i32, ptr %10, align 4, !tbaa !9
  %19 = icmp eq i32 %18, 0
  br i1 %19, label %20, label %30

20:                                               ; preds = %5
  %21 = load ptr, ptr %7, align 8, !tbaa !5
  %22 = getelementptr inbounds %struct.mln_iothread_s, ptr %21, i32 0, i32 3
  %23 = load i32, ptr %22, align 4, !tbaa !11
  store i32 %23, ptr %12, align 4, !tbaa !9
  %24 = load ptr, ptr %7, align 8, !tbaa !5
  %25 = getelementptr inbounds %struct.mln_iothread_s, ptr %24, i32 0, i32 0
  store ptr %25, ptr %13, align 8, !tbaa !5
  %26 = load ptr, ptr %7, align 8, !tbaa !5
  %27 = getelementptr inbounds %struct.mln_iothread_s, ptr %26, i32 0, i32 5
  store ptr %27, ptr %15, align 8, !tbaa !5
  %28 = load ptr, ptr %7, align 8, !tbaa !5
  %29 = getelementptr inbounds %struct.mln_iothread_s, ptr %28, i32 0, i32 6
  store ptr %29, ptr %16, align 8, !tbaa !5
  br label %40

30:                                               ; preds = %5
  %31 = load ptr, ptr %7, align 8, !tbaa !5
  %32 = getelementptr inbounds %struct.mln_iothread_s, ptr %31, i32 0, i32 2
  %33 = load i32, ptr %32, align 8, !tbaa !13
  store i32 %33, ptr %12, align 4, !tbaa !9
  %34 = load ptr, ptr %7, align 8, !tbaa !5
  %35 = getelementptr inbounds %struct.mln_iothread_s, ptr %34, i32 0, i32 1
  store ptr %35, ptr %13, align 8, !tbaa !5
  %36 = load ptr, ptr %7, align 8, !tbaa !5
  %37 = getelementptr inbounds %struct.mln_iothread_s, ptr %36, i32 0, i32 11
  store ptr %37, ptr %15, align 8, !tbaa !5
  %38 = load ptr, ptr %7, align 8, !tbaa !5
  %39 = getelementptr inbounds %struct.mln_iothread_s, ptr %38, i32 0, i32 12
  store ptr %39, ptr %16, align 8, !tbaa !5
  br label %40

40:                                               ; preds = %30, %20
  %41 = load i32, ptr %8, align 4, !tbaa !9
  %42 = load ptr, ptr %9, align 8, !tbaa !5
  %43 = load i32, ptr %11, align 4, !tbaa !9
  %44 = call ptr @mln_iothread_msg_new(i32 noundef %41, ptr noundef %42, i32 noundef %43)
  store ptr %44, ptr %14, align 8, !tbaa !5
  %45 = icmp eq ptr %44, null
  br i1 %45, label %46, label %47

46:                                               ; preds = %40
  store i32 -1, ptr %6, align 4
  store i32 1, ptr %17, align 4
  br label %102

47:                                               ; preds = %40
  %48 = load i32, ptr %11, align 4, !tbaa !9
  %49 = icmp ne i32 %48, 0
  br i1 %49, label %50, label %54

50:                                               ; preds = %47
  %51 = load ptr, ptr %14, align 8, !tbaa !5
  %52 = getelementptr inbounds %struct.mln_iothread_msg_s, ptr %51, i32 0, i32 5
  %53 = call i32 @pthread_mutex_lock(ptr noundef %52) #5
  br label %54

54:                                               ; preds = %50, %47
  %55 = load ptr, ptr %13, align 8, !tbaa !5
  %56 = call i32 @pthread_mutex_lock(ptr noundef %55) #5
  %57 = load ptr, ptr %15, align 8, !tbaa !5
  %58 = load ptr, ptr %16, align 8, !tbaa !5
  %59 = load ptr, ptr %14, align 8, !tbaa !5
  call void @mln_iothread_msg_chain_add(ptr noundef %57, ptr noundef %58, ptr noundef %59)
  %60 = load ptr, ptr %15, align 8, !tbaa !5
  %61 = load ptr, ptr %60, align 8, !tbaa !5
  %62 = load ptr, ptr %16, align 8, !tbaa !5
  %63 = load ptr, ptr %62, align 8, !tbaa !5
  %64 = icmp eq ptr %61, %63
  br i1 %64, label %65, label %88

65:                                               ; preds = %54
  %66 = load ptr, ptr %15, align 8, !tbaa !5
  %67 = load ptr, ptr %66, align 8, !tbaa !5
  %68 = load ptr, ptr %14, align 8, !tbaa !5
  %69 = icmp eq ptr %67, %68
  br i1 %69, label %70, label %88

70:                                               ; preds = %65
  %71 = load i32, ptr %12, align 4, !tbaa !9
  %72 = call i64 @send(i32 noundef %71, ptr noundef @.str, i64 noundef 1, i32 noundef 0)
  %73 = icmp ne i64 %72, 1
  br i1 %73, label %74, label %88

74:                                               ; preds = %70
  %75 = load ptr, ptr %15, align 8, !tbaa !5
  %76 = load ptr, ptr %16, align 8, !tbaa !5
  %77 = load ptr, ptr %14, align 8, !tbaa !5
  call void @mln_iothread_msg_chain_del(ptr noundef %75, ptr noundef %76, ptr noundef %77)
  %78 = load i32, ptr %11, align 4, !tbaa !9
  %79 = icmp ne i32 %78, 0
  br i1 %79, label %80, label %84

80:                                               ; preds = %74
  %81 = load ptr, ptr %14, align 8, !tbaa !5
  %82 = getelementptr inbounds %struct.mln_iothread_msg_s, ptr %81, i32 0, i32 5
  %83 = call i32 @pthread_mutex_unlock(ptr noundef %82) #5
  br label %84

84:                                               ; preds = %80, %74
  %85 = load ptr, ptr %13, align 8, !tbaa !5
  %86 = call i32 @pthread_mutex_unlock(ptr noundef %85) #5
  %87 = load ptr, ptr %14, align 8, !tbaa !5
  call void @mln_iothread_msg_free(ptr noundef %87)
  store i32 1, ptr %6, align 4
  store i32 1, ptr %17, align 4
  br label %102

88:                                               ; preds = %70, %65, %54
  %89 = load ptr, ptr %13, align 8, !tbaa !5
  %90 = call i32 @pthread_mutex_unlock(ptr noundef %89) #5
  %91 = load i32, ptr %11, align 4, !tbaa !9
  %92 = icmp ne i32 %91, 0
  br i1 %92, label %93, label %101

93:                                               ; preds = %88
  %94 = load ptr, ptr %14, align 8, !tbaa !5
  %95 = getelementptr inbounds %struct.mln_iothread_msg_s, ptr %94, i32 0, i32 5
  %96 = call i32 @pthread_mutex_lock(ptr noundef %95) #5
  %97 = load ptr, ptr %14, align 8, !tbaa !5
  %98 = getelementptr inbounds %struct.mln_iothread_msg_s, ptr %97, i32 0, i32 5
  %99 = call i32 @pthread_mutex_unlock(ptr noundef %98) #5
  %100 = load ptr, ptr %14, align 8, !tbaa !5
  call void @mln_iothread_msg_free(ptr noundef %100)
  br label %101

101:                                              ; preds = %93, %88
  store i32 0, ptr %6, align 4
  store i32 1, ptr %17, align 4
  br label %102

102:                                              ; preds = %101, %84, %46
  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 8, ptr %14) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %13) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %12) #5
  %103 = load i32, ptr %6, align 4
  ret i32 %103
}

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

; Function Attrs: nounwind
declare i32 @pthread_mutex_lock(ptr noundef) #3

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

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

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

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

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 = { 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 "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}


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

@.str = external hidden unnamed_addr constant [2 x i8], align 1

; Function Attrs: nounwind uwtable
define dso_local range(i32 -1, 2) i32 @mln_iothread_send(ptr noundef %0, i32 noundef %1, ptr noundef %2, i32 noundef %3, i32 noundef %4) local_unnamed_addr #0 {
  %6 = icmp eq i32 %3, 0
  br i1 %6, label %7, label %9

7:                                                ; preds = %5
  %8 = getelementptr inbounds i8, ptr %0, i64 84
  br label %12

9:                                                ; preds = %5
  %10 = getelementptr inbounds i8, ptr %0, i64 80
  %11 = getelementptr inbounds i8, ptr %0, i64 40
  br label %12

12:                                               ; preds = %9, %7
  %.sink42 = phi i64 [ 144, %9 ], [ 96, %7 ]
  %.sink = phi i64 [ 152, %9 ], [ 104, %7 ]
  %.038.in = phi ptr [ %10, %9 ], [ %8, %7 ]
  %.037 = phi ptr [ %11, %9 ], [ %0, %7 ]
  %13 = getelementptr inbounds i8, ptr %0, i64 %.sink42
  %14 = getelementptr inbounds i8, ptr %0, i64 %.sink
  %.038 = load i32, ptr %.038.in, align 4, !tbaa !5
  %15 = tail call ptr @mln_iothread_msg_new(i32 noundef %1, ptr noundef %2, i32 noundef %4)
  %16 = icmp eq ptr %15, null
  br i1 %16, label %41, label %17

17:                                               ; preds = %12
  %.not = icmp eq i32 %4, 0
  br i1 %.not, label %21, label %18

18:                                               ; preds = %17
  %19 = getelementptr inbounds i8, ptr %15, i64 32
  %20 = tail call i32 @pthread_mutex_lock(ptr noundef nonnull %19) #4
  br label %21

21:                                               ; preds = %18, %17
  %22 = tail call i32 @pthread_mutex_lock(ptr noundef %.037) #4
  tail call void @mln_iothread_msg_chain_add(ptr noundef nonnull %13, ptr noundef nonnull %14, ptr noundef nonnull %15)
  %23 = load ptr, ptr %13, align 8, !tbaa !9
  %24 = load ptr, ptr %14, align 8, !tbaa !9
  %25 = icmp eq ptr %23, %24
  %26 = icmp eq ptr %23, %15
  %or.cond = and i1 %26, %25
  br i1 %or.cond, label %27, label %35

27:                                               ; preds = %21
  %28 = tail call i64 @send(i32 noundef %.038, ptr noundef nonnull @.str, i64 noundef 1, i32 noundef 0) #4
  %.not41 = icmp eq i64 %28, 1
  br i1 %.not41, label %35, label %29

29:                                               ; preds = %27
  tail call void @mln_iothread_msg_chain_del(ptr noundef nonnull %13, ptr noundef nonnull %14, ptr noundef nonnull %15)
  br i1 %.not, label %33, label %30

30:                                               ; preds = %29
  %31 = getelementptr inbounds i8, ptr %15, i64 32
  %32 = tail call i32 @pthread_mutex_unlock(ptr noundef nonnull %31) #4
  br label %33

33:                                               ; preds = %30, %29
  %34 = tail call i32 @pthread_mutex_unlock(ptr noundef %.037) #4
  br label %.sink.split

35:                                               ; preds = %27, %21
  %36 = tail call i32 @pthread_mutex_unlock(ptr noundef %.037) #4
  br i1 %.not, label %41, label %37

37:                                               ; preds = %35
  %38 = getelementptr inbounds i8, ptr %15, i64 32
  %39 = tail call i32 @pthread_mutex_lock(ptr noundef nonnull %38) #4
  %40 = tail call i32 @pthread_mutex_unlock(ptr noundef nonnull %38) #4
  br label %.sink.split

.sink.split:                                      ; preds = %33, %37
  %.036.ph = phi i32 [ 0, %37 ], [ 1, %33 ]
  tail call void @mln_iothread_msg_free(ptr noundef nonnull %15)
  br label %41

41:                                               ; preds = %.sink.split, %35, %12
  %.036 = phi i32 [ -1, %12 ], [ 0, %35 ], [ %.036.ph, %.sink.split ]
  ret i32 %.036
}

; Function Attrs: inlinehint nounwind uwtable
declare hidden ptr @mln_iothread_msg_new(i32 noundef, ptr noundef, i32 noundef) local_unnamed_addr #1

; Function Attrs: nounwind
declare i32 @pthread_mutex_lock(ptr noundef) local_unnamed_addr #2

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

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

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

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

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

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 = { 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 #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 = !{!"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}


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