; LLVM IR from NTHU-LSALAB/Gemini :: src/pod-manager.ll (Z26scheduler_thread_send_funcPv)

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

%"class.std::queue" = type { %"class.std::deque" }
%"class.std::deque" = type { %"class.std::_Deque_base" }
%"class.std::_Deque_base" = type { %"struct.std::_Deque_base<request, std::allocator<request>>::_Deque_impl" }
%"struct.std::_Deque_base<request, std::allocator<request>>::_Deque_impl" = type { %"struct.std::_Deque_base<request, std::allocator<request>>::_Deque_impl_data" }
%"struct.std::_Deque_base<request, std::allocator<request>>::_Deque_impl_data" = type { ptr, i64, %"struct.std::_Deque_iterator", %"struct.std::_Deque_iterator" }
%"struct.std::_Deque_iterator" = type { ptr, ptr, 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 }
%struct.request = type { i32, ptr }

@request_queue = external dso_local global %"class.std::queue", align 8
@req_queue_mutex = external dso_local global %union.pthread_mutex_t, align 8
@req_queue_cond = external dso_local global %union.pthread_cond_t, align 8
@.str.21 = external hidden unnamed_addr constant [54 x i8], align 1
@.str.22 = external hidden unnamed_addr constant [41 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

declare void @_Z5ERRORPKcz(ptr 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

; Function Attrs: mustprogress uwtable
define dso_local noundef ptr @_Z26scheduler_thread_send_funcPv(ptr noundef %0) #3 {
  %2 = alloca ptr, align 8
  %3 = alloca i32, align 4
  %4 = alloca i64, align 8
  %5 = alloca %struct.request, align 8
  store ptr %0, ptr %2, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #6
  %6 = load ptr, ptr %2, align 8, !tbaa !5
  %7 = load i32, ptr %6, align 4, !tbaa !9
  store i32 %7, ptr %3, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #6
  br label %8

8:                                                ; preds = %26, %1
  br label %9

9:                                                ; preds = %8
  %10 = call i32 @pthread_mutex_lock(ptr noundef @req_queue_mutex) #6
  %11 = call i32 @pthread_cond_wait(ptr noundef @req_queue_cond, ptr noundef @req_queue_mutex)
  %12 = call noundef zeroext i1 @_ZNKSt5queueI7requestSt5dequeIS0_SaIS0_EEE5emptyEv(ptr noundef nonnull align 8 dereferenceable(80) @request_queue)
  br i1 %12, label %26, label %13

13:                                               ; preds = %9
  call void @llvm.lifetime.start.p0(i64 16, ptr %5) #6
  %14 = call noundef nonnull align 8 dereferenceable(16) ptr @_ZNSt5queueI7requestSt5dequeIS0_SaIS0_EEE5frontEv(ptr noundef nonnull align 8 dereferenceable(80) @request_queue)
  call void @llvm.memcpy.p0.p0.i64(ptr align 8 %5, ptr align 8 %14, i64 16, i1 false), !tbaa.struct !11
  call void @_ZNSt5queueI7requestSt5dequeIS0_SaIS0_EEE3popEv(ptr noundef nonnull align 8 dereferenceable(80) @request_queue)
  %15 = load i32, ptr %3, align 4, !tbaa !9
  %16 = getelementptr inbounds %struct.request, ptr %5, i32 0, i32 1
  %17 = load ptr, ptr %16, align 8, !tbaa !12
  %18 = call i64 @send(i32 noundef %15, ptr noundef %17, i64 noundef 80, i32 noundef 0)
  store i64 %18, ptr %4, align 8, !tbaa !14
  %19 = icmp sle i64 %18, 0
  br i1 %19, label %20, label %22

20:                                               ; preds = %13
  %21 = load i64, ptr %4, align 8, !tbaa !14
  call void (ptr, ...) @_Z5ERRORPKcz(ptr noundef @.str.21, i64 noundef %21)
  br label %25

22:                                               ; preds = %13
  %23 = getelementptr inbounds %struct.request, ptr %5, i32 0, i32 0
  %24 = load i32, ptr %23, align 8, !tbaa !16
  call void (ptr, ...) @_Z5DEBUGPKcz(ptr noundef @.str.22, i32 noundef %24)
  br label %25

25:                                               ; preds = %22, %20
  call void @llvm.lifetime.end.p0(i64 16, ptr %5) #6
  br label %26

26:                                               ; preds = %25, %9
  %27 = call i32 @pthread_mutex_unlock(ptr noundef @req_queue_mutex) #6
  br label %8, !llvm.loop !17
}

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

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

declare void @_Z5DEBUGPKcz(ptr noundef, ...) #1

declare i32 @pthread_cond_wait(ptr noundef, ptr noundef) #1

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

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef zeroext i1 @_ZNKSt5queueI7requestSt5dequeIS0_SaIS0_EEE5emptyEv(ptr noundef nonnull align 8 dereferenceable(80)) #5 align 2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef nonnull align 8 dereferenceable(16) ptr @_ZNSt5queueI7requestSt5dequeIS0_SaIS0_EEE5frontEv(ptr noundef nonnull align 8 dereferenceable(80)) #5 align 2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZNSt5queueI7requestSt5dequeIS0_SaIS0_EEE3popEv(ptr noundef nonnull align 8 dereferenceable(80)) #5 align 2

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 = { mustprogress 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 "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 = { mustprogress 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 #6 = { 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++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = !{i64 0, i64 4, !9, i64 8, i64 8, !5}
!12 = !{!13, !6, i64 8}
!13 = !{!"_ZTS7request", !10, i64 0, !6, i64 8}
!14 = !{!15, !15, i64 0}
!15 = !{!"long", !7, i64 0}
!16 = !{!13, !10, i64 0}
!17 = distinct !{!17, !18}
!18 = !{!"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"

%"class.std::queue" = type { %"class.std::deque" }
%"class.std::deque" = type { %"class.std::_Deque_base" }
%"class.std::_Deque_base" = type { %"struct.std::_Deque_base<request, std::allocator<request>>::_Deque_impl" }
%"struct.std::_Deque_base<request, std::allocator<request>>::_Deque_impl" = type { %"struct.std::_Deque_base<request, std::allocator<request>>::_Deque_impl_data" }
%"struct.std::_Deque_base<request, std::allocator<request>>::_Deque_impl_data" = type { ptr, i64, %"struct.std::_Deque_iterator", %"struct.std::_Deque_iterator" }
%"struct.std::_Deque_iterator" = type { ptr, ptr, 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 }

@request_queue = external dso_local global %"class.std::queue", align 8
@req_queue_mutex = external dso_local global %union.pthread_mutex_t, align 8
@req_queue_cond = external dso_local global %union.pthread_cond_t, align 8
@.str.21 = external hidden unnamed_addr constant [54 x i8], align 1
@.str.22 = external hidden unnamed_addr constant [41 x i8], align 1

declare void @_Z5ERRORPKcz(ptr noundef, ...) local_unnamed_addr #0

; Function Attrs: mustprogress noreturn uwtable
define dso_local noalias noundef nonnull ptr @_Z26scheduler_thread_send_funcPv(ptr nocapture noundef readonly %0) local_unnamed_addr #1 {
  %2 = load i32, ptr %0, align 4, !tbaa !5
  br label %3

3:                                                ; preds = %13, %1
  %4 = tail call i32 @pthread_mutex_lock(ptr noundef nonnull @req_queue_mutex) #4
  %5 = tail call i32 @pthread_cond_wait(ptr noundef nonnull @req_queue_cond, ptr noundef nonnull @req_queue_mutex)
  %6 = tail call noundef zeroext i1 @_ZNKSt5queueI7requestSt5dequeIS0_SaIS0_EEE5emptyEv(ptr noundef nonnull align 8 dereferenceable(80) @request_queue)
  br i1 %6, label %13, label %7

7:                                                ; preds = %3
  %8 = tail call noundef nonnull align 8 dereferenceable(16) ptr @_ZNSt5queueI7requestSt5dequeIS0_SaIS0_EEE5frontEv(ptr noundef nonnull align 8 dereferenceable(80) @request_queue)
  %.sroa.0.0.copyload = load i32, ptr %8, align 8, !tbaa !5
  %.sroa.41.0..sroa_idx = getelementptr inbounds i8, ptr %8, i64 8
  %.sroa.41.0.copyload = load ptr, ptr %.sroa.41.0..sroa_idx, align 8, !tbaa !9
  tail call void @_ZNSt5queueI7requestSt5dequeIS0_SaIS0_EEE3popEv(ptr noundef nonnull align 8 dereferenceable(80) @request_queue)
  %9 = tail call i64 @send(i32 noundef %2, ptr noundef %.sroa.41.0.copyload, i64 noundef 80, i32 noundef 0)
  %10 = icmp slt i64 %9, 1
  br i1 %10, label %11, label %12

11:                                               ; preds = %7
  tail call void (ptr, ...) @_Z5ERRORPKcz(ptr noundef nonnull @.str.21, i64 noundef %9)
  br label %13

12:                                               ; preds = %7
  tail call void (ptr, ...) @_Z5DEBUGPKcz(ptr noundef nonnull @.str.22, i32 noundef %.sroa.0.0.copyload)
  br label %13

13:                                               ; preds = %11, %12, %3
  %14 = tail call i32 @pthread_mutex_unlock(ptr noundef nonnull @req_queue_mutex) #4
  br label %3, !llvm.loop !11
}

; 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

declare void @_Z5DEBUGPKcz(ptr noundef, ...) local_unnamed_addr #0

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

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

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef zeroext i1 @_ZNKSt5queueI7requestSt5dequeIS0_SaIS0_EEE5emptyEv(ptr noundef nonnull align 8 dereferenceable(80)) local_unnamed_addr #3 align 2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef nonnull align 8 dereferenceable(16) ptr @_ZNSt5queueI7requestSt5dequeIS0_SaIS0_EEE5frontEv(ptr noundef nonnull align 8 dereferenceable(80)) local_unnamed_addr #3 align 2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZNSt5queueI7requestSt5dequeIS0_SaIS0_EEE3popEv(ptr noundef nonnull align 8 dereferenceable(80)) local_unnamed_addr #3 align 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 noreturn 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 = { mustprogress 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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"any pointer", !7, i64 0}
!11 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}


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