; LLVM IR from 1runeberg/xrlib :: src (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.sched_param = type { i32 }

; 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: mustprogress uwtable
define dso_local void @_ZN5xrlib11CThreadPool17SetThreadPriorityERSt6threadNS_15EThreadPriorityE(ptr noundef nonnull align 8 dereferenceable(504) %0, ptr noundef nonnull align 8 dereferenceable(8) %1, i32 noundef %2) #1 align 2 {
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  %8 = alloca %struct.sched_param, align 4
  store ptr %0, ptr %4, align 8, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !5
  store i32 %2, ptr %6, align 4, !tbaa !9
  %9 = load ptr, ptr %4, align 8
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #4
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #4
  %10 = load ptr, ptr %5, align 8, !tbaa !5
  %11 = call noundef i64 @_ZNSt6thread13native_handleEv(ptr noundef nonnull align 8 dereferenceable(8) %10)
  %12 = call i32 @pthread_getschedparam(i64 noundef %11, ptr noundef %7, ptr noundef %8) #4
  %13 = load i32, ptr %6, align 4, !tbaa !9
  switch i32 %13, label %29 [
    i32 0, label %14
    i32 1, label %17
    i32 2, label %23
    i32 3, label %26
  ]

14:                                               ; preds = %3
  %15 = call i32 @sched_get_priority_min(i32 noundef 0) #4
  %16 = getelementptr inbounds %struct.sched_param, ptr %8, i32 0, i32 0
  store i32 %15, ptr %16, align 4, !tbaa !11
  br label %29

17:                                               ; preds = %3
  %18 = call i32 @sched_get_priority_max(i32 noundef 0) #4
  %19 = call i32 @sched_get_priority_min(i32 noundef 0) #4
  %20 = add nsw i32 %18, %19
  %21 = sdiv i32 %20, 2
  %22 = getelementptr inbounds %struct.sched_param, ptr %8, i32 0, i32 0
  store i32 %21, ptr %22, align 4, !tbaa !11
  br label %29

23:                                               ; preds = %3
  %24 = call i32 @sched_get_priority_max(i32 noundef 0) #4
  %25 = getelementptr inbounds %struct.sched_param, ptr %8, i32 0, i32 0
  store i32 %24, ptr %25, align 4, !tbaa !11
  br label %29

26:                                               ; preds = %3
  store i32 2, ptr %7, align 4, !tbaa !14
  %27 = call i32 @sched_get_priority_max(i32 noundef 2) #4
  %28 = getelementptr inbounds %struct.sched_param, ptr %8, i32 0, i32 0
  store i32 %27, ptr %28, align 4, !tbaa !11
  br label %29

29:                                               ; preds = %26, %23, %17, %14, %3
  %30 = load ptr, ptr %5, align 8, !tbaa !5
  %31 = call noundef i64 @_ZNSt6thread13native_handleEv(ptr noundef nonnull align 8 dereferenceable(8) %30)
  %32 = load i32, ptr %7, align 4, !tbaa !14
  %33 = call i32 @pthread_setschedparam(i64 noundef %31, i32 noundef %32, ptr noundef %8) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #4
  ret void
}

; Function Attrs: nounwind
declare i32 @pthread_getschedparam(i64 noundef, ptr noundef, ptr noundef) #2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i64 @_ZNSt6thread13native_handleEv(ptr noundef nonnull align 8 dereferenceable(8)) #3 align 2

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

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

; Function Attrs: nounwind
declare i32 @pthread_setschedparam(i64 noundef, i32 noundef, ptr noundef) #2

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 #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 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"_ZTSN5xrlib15EThreadPriorityE", !7, i64 0}
!11 = !{!12, !13, i64 0}
!12 = !{!"_ZTS11sched_param", !13, i64 0}
!13 = !{!"int", !7, i64 0}
!14 = !{!13, !13, i64 0}


; 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.sched_param = type { i32 }

; 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: mustprogress nounwind uwtable
define dso_local void @_ZN5xrlib11CThreadPool17SetThreadPriorityERSt6threadNS_15EThreadPriorityE(ptr nocapture noundef nonnull readnone align 8 dereferenceable(504) %0, ptr noundef nonnull align 8 dereferenceable(8) %1, i32 noundef %2) local_unnamed_addr #1 align 2 {
  %4 = alloca i32, align 4
  %5 = alloca %struct.sched_param, align 4
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %4) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %5) #3
  %6 = tail call noundef i64 @_ZNSt6thread13native_handleEv(ptr noundef nonnull align 8 dereferenceable(8) %1)
  %7 = call i32 @pthread_getschedparam(i64 noundef %6, ptr noundef nonnull %4, ptr noundef nonnull %5) #3
  switch i32 %2, label %19 [
    i32 0, label %8
    i32 1, label %10
    i32 2, label %15
    i32 3, label %17
  ]

8:                                                ; preds = %3
  %9 = call i32 @sched_get_priority_min(i32 noundef 0) #3
  store i32 %9, ptr %5, align 4, !tbaa !5
  br label %19

10:                                               ; preds = %3
  %11 = call i32 @sched_get_priority_max(i32 noundef 0) #3
  %12 = call i32 @sched_get_priority_min(i32 noundef 0) #3
  %13 = add nsw i32 %12, %11
  %14 = sdiv i32 %13, 2
  store i32 %14, ptr %5, align 4, !tbaa !5
  br label %19

15:                                               ; preds = %3
  %16 = call i32 @sched_get_priority_max(i32 noundef 0) #3
  store i32 %16, ptr %5, align 4, !tbaa !5
  br label %19

17:                                               ; preds = %3
  store i32 2, ptr %4, align 4, !tbaa !10
  %18 = call i32 @sched_get_priority_max(i32 noundef 2) #3
  store i32 %18, ptr %5, align 4, !tbaa !5
  br label %19

19:                                               ; preds = %17, %15, %10, %8, %3
  %20 = call noundef i64 @_ZNSt6thread13native_handleEv(ptr noundef nonnull align 8 dereferenceable(8) %1)
  %21 = load i32, ptr %4, align 4, !tbaa !10
  %22 = call i32 @pthread_setschedparam(i64 noundef %20, i32 noundef %21, ptr noundef nonnull %5) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %5) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %4) #3
  ret void
}

; Function Attrs: nounwind
declare i32 @pthread_getschedparam(i64 noundef, ptr noundef, ptr noundef) local_unnamed_addr #2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i64 @_ZNSt6thread13native_handleEv(ptr noundef nonnull align 8 dereferenceable(8)) local_unnamed_addr #1 align 2

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

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

; Function Attrs: nounwind
declare i32 @pthread_setschedparam(i64 noundef, i32 noundef, ptr noundef) local_unnamed_addr #2

attributes #0 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 #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 }

!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 = !{!"_ZTS11sched_param", !7, i64 0}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}
!10 = !{!7, !7, i64 0}


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