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

; 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_thread_pool_attr = type { ptr, ptr, ptr, ptr, i64, i32, i32 }
%struct.mln_thread_pool_s = type { %union.pthread_mutex_t, %union.pthread_cond_t, %union.pthread_attr_t, ptr, ptr, ptr, ptr, i32, i32, i32, i32, i64, i64, 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 }
%union.pthread_cond_t = type { %struct.__pthread_cond_s }
%struct.__pthread_cond_s = type { %union.__atomic_wide_counter, %union.__atomic_wide_counter, [2 x i32], [2 x i32], i32, i32, [2 x i32] }
%union.__atomic_wide_counter = type { i64 }
%union.pthread_attr_t = type { i64, [48 x i8] }
%struct.mln_thread_pool_member_s = type { ptr, ptr, i8, ptr, ptr }

@m_thread_pool_self = external dso_local thread_local global ptr, 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 speculatable willreturn memory(none)
declare nonnull ptr @llvm.threadlocal.address.p0(ptr nonnull) #1

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

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

; 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_thread_pool_run(ptr noundef nonnull %0) #3 {
  %2 = alloca i32, align 4
  %3 = alloca ptr, align 8
  %4 = alloca i32, align 4
  %5 = alloca ptr, align 8
  %6 = alloca i32, align 4
  store ptr %0, ptr %3, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #5
  store i32 0, ptr %4, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #5
  %7 = load ptr, ptr %3, align 8, !tbaa !5
  %8 = getelementptr inbounds %struct.mln_thread_pool_attr, ptr %7, i32 0, i32 1
  %9 = load ptr, ptr %8, align 8, !tbaa !11
  %10 = icmp eq ptr %9, null
  br i1 %10, label %16, label %11

11:                                               ; preds = %1
  %12 = load ptr, ptr %3, align 8, !tbaa !5
  %13 = getelementptr inbounds %struct.mln_thread_pool_attr, ptr %12, i32 0, i32 2
  %14 = load ptr, ptr %13, align 8, !tbaa !14
  %15 = icmp eq ptr %14, null
  br i1 %15, label %16, label %17

16:                                               ; preds = %11, %1
  store i32 22, ptr %2, align 4
  store i32 1, ptr %6, align 4
  br label %81

17:                                               ; preds = %11
  %18 = load ptr, ptr %3, align 8, !tbaa !5
  %19 = call ptr @mln_thread_pool_new(ptr noundef %18, ptr noundef %4)
  store ptr %19, ptr %5, align 8, !tbaa !5
  %20 = icmp eq ptr %19, null
  br i1 %20, label %21, label %23

21:                                               ; preds = %17
  %22 = load i32, ptr %4, align 4, !tbaa !9
  store i32 %22, ptr %2, align 4
  store i32 1, ptr %6, align 4
  br label %81

23:                                               ; preds = %17
  %24 = load ptr, ptr %3, align 8, !tbaa !5
  %25 = getelementptr inbounds %struct.mln_thread_pool_attr, ptr %24, i32 0, i32 2
  %26 = load ptr, ptr %25, align 8, !tbaa !14
  %27 = load ptr, ptr %3, align 8, !tbaa !5
  %28 = getelementptr inbounds %struct.mln_thread_pool_attr, ptr %27, i32 0, i32 0
  %29 = load ptr, ptr %28, align 8, !tbaa !15
  %30 = call i32 %26(ptr noundef %29)
  store i32 %30, ptr %4, align 4, !tbaa !9
  %31 = load ptr, ptr %5, align 8, !tbaa !5
  %32 = getelementptr inbounds %struct.mln_thread_pool_s, ptr %31, i32 0, i32 10
  %33 = load i32, ptr %32, align 4
  %34 = and i32 %33, -2
  %35 = or i32 %34, 1
  store i32 %35, ptr %32, align 4
  br label %36

36:                                               ; preds = %61, %23
  br label %37

37:                                               ; preds = %36
  %38 = call align 8 ptr @llvm.threadlocal.address.p0(ptr align 8 @m_thread_pool_self)
  %39 = load ptr, ptr %38, align 8, !tbaa !5
  %40 = getelementptr inbounds %struct.mln_thread_pool_member_s, ptr %39, i32 0, i32 2
  %41 = load i8, ptr %40, align 8
  %42 = and i8 %41, -3
  %43 = or i8 %42, 2
  store i8 %43, ptr %40, align 8
  %44 = load ptr, ptr %5, align 8, !tbaa !5
  %45 = getelementptr inbounds %struct.mln_thread_pool_s, ptr %44, i32 0, i32 0
  %46 = call i32 @pthread_mutex_lock(ptr noundef %45) #5
  %47 = load ptr, ptr %5, align 8, !tbaa !5
  %48 = getelementptr inbounds %struct.mln_thread_pool_s, ptr %47, i32 0, i32 9
  %49 = load i32, ptr %48, align 8, !tbaa !16
  %50 = icmp ule i32 %49, 1
  br i1 %50, label %51, label %61

51:                                               ; preds = %37
  %52 = load ptr, ptr %5, align 8, !tbaa !5
  %53 = getelementptr inbounds %struct.mln_thread_pool_s, ptr %52, i32 0, i32 0
  %54 = call i32 @pthread_mutex_unlock(ptr noundef %53) #5
  %55 = call align 8 ptr @llvm.threadlocal.address.p0(ptr align 8 @m_thread_pool_self)
  %56 = load ptr, ptr %55, align 8, !tbaa !5
  %57 = getelementptr inbounds %struct.mln_thread_pool_member_s, ptr %56, i32 0, i32 2
  %58 = load i8, ptr %57, align 8
  %59 = and i8 %58, -3
  %60 = or i8 %59, 0
  store i8 %60, ptr %57, align 8
  br label %75

61:                                               ; preds = %37
  %62 = load ptr, ptr %5, align 8, !tbaa !5
  %63 = getelementptr inbounds %struct.mln_thread_pool_s, ptr %62, i32 0, i32 1
  %64 = call i32 @pthread_cond_broadcast(ptr noundef %63) #5
  %65 = load ptr, ptr %5, align 8, !tbaa !5
  %66 = getelementptr inbounds %struct.mln_thread_pool_s, ptr %65, i32 0, i32 0
  %67 = call i32 @pthread_mutex_unlock(ptr noundef %66) #5
  %68 = call align 8 ptr @llvm.threadlocal.address.p0(ptr align 8 @m_thread_pool_self)
  %69 = load ptr, ptr %68, align 8, !tbaa !5
  %70 = getelementptr inbounds %struct.mln_thread_pool_member_s, ptr %69, i32 0, i32 2
  %71 = load i8, ptr %70, align 8
  %72 = and i8 %71, -3
  %73 = or i8 %72, 0
  store i8 %73, ptr %70, align 8
  %74 = call i32 @usleep(i32 noundef 50000)
  br label %36

75:                                               ; preds = %51
  %76 = call align 8 ptr @llvm.threadlocal.address.p0(ptr align 8 @m_thread_pool_self)
  %77 = load ptr, ptr %76, align 8, !tbaa !5
  call void @mln_thread_pool_member_exit(ptr noundef %77)
  %78 = call align 8 ptr @llvm.threadlocal.address.p0(ptr align 8 @m_thread_pool_self)
  store ptr null, ptr %78, align 8, !tbaa !5
  %79 = load ptr, ptr %5, align 8, !tbaa !5
  call void @mln_thread_pool_free(ptr noundef %79)
  %80 = load i32, ptr %4, align 4, !tbaa !9
  store i32 %80, ptr %2, align 4
  store i32 1, ptr %6, align 4
  br label %81

81:                                               ; preds = %75, %21, %16
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #5
  %82 = load i32, ptr %2, align 4
  ret i32 %82
}

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

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

declare i32 @usleep(i32 noundef) #4

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

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

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
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 = { 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, !6, i64 8}
!12 = !{!"mln_thread_pool_attr", !6, i64 0, !6, i64 8, !6, i64 16, !6, i64 24, !13, i64 32, !10, i64 40, !10, i64 44}
!13 = !{!"long", !7, i64 0}
!14 = !{!12, !6, i64 16}
!15 = !{!12, !6, i64 0}
!16 = !{!17, !10, i64 184}
!17 = !{!"mln_thread_pool_s", !7, i64 0, !7, i64 40, !7, i64 88, !6, i64 144, !6, i64 152, !6, i64 160, !6, i64 168, !10, i64 176, !10, i64 180, !10, i64 184, !10, i64 188, !10, i64 188, !13, i64 192, !13, i64 200, !6, i64 208, !6, i64 216}


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

@m_thread_pool_self = external dso_local thread_local local_unnamed_addr global ptr, align 8

; 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 speculatable willreturn memory(none)
declare nonnull ptr @llvm.threadlocal.address.p0(ptr nonnull) #1

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

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

; 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 uwtable
define dso_local i32 @mln_thread_pool_run(ptr noundef nonnull %0) local_unnamed_addr #3 {
  %2 = alloca i32, align 4
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %2) #5
  store i32 0, ptr %2, align 4, !tbaa !5
  %3 = getelementptr inbounds i8, ptr %0, i64 8
  %4 = load ptr, ptr %3, align 8, !tbaa !9
  %5 = icmp eq ptr %4, null
  br i1 %5, label %53, label %6

6:                                                ; preds = %1
  %7 = getelementptr inbounds i8, ptr %0, i64 16
  %8 = load ptr, ptr %7, align 8, !tbaa !13
  %9 = icmp eq ptr %8, null
  br i1 %9, label %53, label %10

10:                                               ; preds = %6
  %11 = call ptr @mln_thread_pool_new(ptr noundef nonnull %0, ptr noundef nonnull %2)
  %12 = icmp eq ptr %11, null
  br i1 %12, label %13, label %15

13:                                               ; preds = %10
  %14 = load i32, ptr %2, align 4, !tbaa !5
  br label %53

15:                                               ; preds = %10
  %16 = load ptr, ptr %7, align 8, !tbaa !13
  %17 = load ptr, ptr %0, align 8, !tbaa !14
  %18 = call i32 %16(ptr noundef %17) #5
  store i32 %18, ptr %2, align 4, !tbaa !5
  %19 = getelementptr inbounds i8, ptr %11, i64 188
  %20 = load i32, ptr %19, align 4
  %21 = or i32 %20, 1
  store i32 %21, ptr %19, align 4
  %22 = call align 8 ptr @llvm.threadlocal.address.p0(ptr align 8 @m_thread_pool_self)
  %23 = load ptr, ptr %22, align 8, !tbaa !15
  %24 = getelementptr inbounds i8, ptr %23, i64 16
  %25 = load i8, ptr %24, align 8
  %26 = or i8 %25, 2
  store i8 %26, ptr %24, align 8
  %27 = call i32 @pthread_mutex_lock(ptr noundef nonnull %11) #5
  %28 = getelementptr inbounds i8, ptr %11, i64 184
  %29 = load i32, ptr %28, align 8, !tbaa !16
  %30 = icmp ult i32 %29, 2
  br i1 %30, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %15
  %31 = getelementptr inbounds i8, ptr %11, i64 40
  br label %38

._crit_edge:                                      ; preds = %38, %15
  %32 = call i32 @pthread_mutex_unlock(ptr noundef nonnull %11) #5
  %33 = load ptr, ptr %22, align 8, !tbaa !15
  %34 = getelementptr inbounds i8, ptr %33, i64 16
  %35 = load i8, ptr %34, align 8
  %36 = and i8 %35, -3
  store i8 %36, ptr %34, align 8
  call void @mln_thread_pool_member_exit(ptr noundef %33)
  store ptr null, ptr %22, align 8, !tbaa !15
  call void @mln_thread_pool_free(ptr noundef nonnull %11)
  %37 = load i32, ptr %2, align 4, !tbaa !5
  br label %53

38:                                               ; preds = %.lr.ph, %38
  %39 = call i32 @pthread_cond_broadcast(ptr noundef nonnull %31) #5
  %40 = call i32 @pthread_mutex_unlock(ptr noundef nonnull %11) #5
  %41 = load ptr, ptr %22, align 8, !tbaa !15
  %42 = getelementptr inbounds i8, ptr %41, i64 16
  %43 = load i8, ptr %42, align 8
  %44 = and i8 %43, -3
  store i8 %44, ptr %42, align 8
  %45 = call i32 @usleep(i32 noundef 50000) #5
  %46 = load ptr, ptr %22, align 8, !tbaa !15
  %47 = getelementptr inbounds i8, ptr %46, i64 16
  %48 = load i8, ptr %47, align 8
  %49 = or i8 %48, 2
  store i8 %49, ptr %47, align 8
  %50 = call i32 @pthread_mutex_lock(ptr noundef nonnull %11) #5
  %51 = load i32, ptr %28, align 8, !tbaa !16
  %52 = icmp ult i32 %51, 2
  br i1 %52, label %._crit_edge, label %38

53:                                               ; preds = %1, %6, %._crit_edge, %13
  %.0 = phi i32 [ %14, %13 ], [ %37, %._crit_edge ], [ 22, %6 ], [ 22, %1 ]
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %2) #5
  ret i32 %.0
}

; Function Attrs: nounwind uwtable
declare hidden ptr @mln_thread_pool_new(ptr noundef, ptr noundef) local_unnamed_addr #3

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

declare i32 @usleep(i32 noundef) local_unnamed_addr #4

; Function Attrs: nounwind uwtable
declare hidden void @mln_thread_pool_member_exit(ptr noundef) local_unnamed_addr #3

; Function Attrs: nounwind uwtable
declare hidden void @mln_thread_pool_free(ptr noundef) local_unnamed_addr #3

attributes #0 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none) }
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 = { 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, !11, i64 8}
!10 = !{!"mln_thread_pool_attr", !11, i64 0, !11, i64 8, !11, i64 16, !11, i64 24, !12, i64 32, !6, i64 40, !6, i64 44}
!11 = !{!"any pointer", !7, i64 0}
!12 = !{!"long", !7, i64 0}
!13 = !{!10, !11, i64 16}
!14 = !{!10, !11, i64 0}
!15 = !{!11, !11, i64 0}
!16 = !{!17, !6, i64 184}
!17 = !{!"mln_thread_pool_s", !7, i64 0, !7, i64 40, !7, i64 88, !11, i64 144, !11, i64 152, !11, i64 160, !11, i64 168, !6, i64 176, !6, i64 180, !6, i64 184, !6, i64 188, !6, i64 188, !12, i64 192, !12, i64 200, !11, i64 208, !11, i64 216}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LCSSAPass,LICMPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,SROAPass,SimplifyCFGPass