; LLVM IR from wichue/nethello :: src/base/util.ll (ZN3chw11setPriorityENS_8PriorityEm)

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

@_ZZN3chw11setPriorityENS_8PriorityEmE3Min = external hidden global i32, align 4
@_ZGVZN3chw11setPriorityENS_8PriorityEmE3Min = external hidden global i64, align 8
@_ZZN3chw11setPriorityENS_8PriorityEmE3Max = external hidden global i32, align 4
@_ZGVZN3chw11setPriorityENS_8PriorityEmE3Max = external hidden global i64, align 8
@_ZZN3chw11setPriorityENS_8PriorityEmE10Priorities = external hidden global [5 x i32], align 16
@_ZGVZN3chw11setPriorityENS_8PriorityEmE10Priorities = external hidden global i64, align 8

; Function Attrs: nounwind willreturn memory(none)
declare i64 @pthread_self() #0

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #1

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #1

; Function Attrs: mustprogress nounwind uwtable
define dso_local noundef zeroext i1 @_ZN3chw11setPriorityENS_8PriorityEm(i32 noundef %0, i64 noundef %1) #2 {
  %3 = alloca i1, align 1
  %4 = alloca i32, align 4
  %5 = alloca i64, align 8
  %6 = alloca %struct.sched_param, align 4
  store i32 %0, ptr %4, align 4, !tbaa !5
  store i64 %1, ptr %5, align 8, !tbaa !9
  %7 = load atomic i8, ptr @_ZGVZN3chw11setPriorityENS_8PriorityEmE3Min acquire, align 8
  %8 = icmp eq i8 %7, 0
  br i1 %8, label %9, label %14, !prof !11

9:                                                ; preds = %2
  %10 = call i32 @__cxa_guard_acquire(ptr @_ZGVZN3chw11setPriorityENS_8PriorityEmE3Min) #3
  %11 = icmp ne i32 %10, 0
  br i1 %11, label %12, label %14

12:                                               ; preds = %9
  %13 = call i32 @sched_get_priority_min(i32 noundef 1) #3
  store i32 %13, ptr @_ZZN3chw11setPriorityENS_8PriorityEmE3Min, align 4, !tbaa !12
  call void @__cxa_guard_release(ptr @_ZGVZN3chw11setPriorityENS_8PriorityEmE3Min) #3
  br label %14

14:                                               ; preds = %12, %9, %2
  %15 = load i32, ptr @_ZZN3chw11setPriorityENS_8PriorityEmE3Min, align 4, !tbaa !12
  %16 = icmp eq i32 %15, -1
  br i1 %16, label %17, label %18

17:                                               ; preds = %14
  store i1 false, ptr %3, align 1
  br label %72

18:                                               ; preds = %14
  %19 = load atomic i8, ptr @_ZGVZN3chw11setPriorityENS_8PriorityEmE3Max acquire, align 8
  %20 = icmp eq i8 %19, 0
  br i1 %20, label %21, label %26, !prof !11

21:                                               ; preds = %18
  %22 = call i32 @__cxa_guard_acquire(ptr @_ZGVZN3chw11setPriorityENS_8PriorityEmE3Max) #3
  %23 = icmp ne i32 %22, 0
  br i1 %23, label %24, label %26

24:                                               ; preds = %21
  %25 = call i32 @sched_get_priority_max(i32 noundef 1) #3
  store i32 %25, ptr @_ZZN3chw11setPriorityENS_8PriorityEmE3Max, align 4, !tbaa !12
  call void @__cxa_guard_release(ptr @_ZGVZN3chw11setPriorityENS_8PriorityEmE3Max) #3
  br label %26

26:                                               ; preds = %24, %21, %18
  %27 = load i32, ptr @_ZZN3chw11setPriorityENS_8PriorityEmE3Max, align 4, !tbaa !12
  %28 = icmp eq i32 %27, -1
  br i1 %28, label %29, label %30

29:                                               ; preds = %26
  store i1 false, ptr %3, align 1
  br label %72

30:                                               ; preds = %26
  %31 = load atomic i8, ptr @_ZGVZN3chw11setPriorityENS_8PriorityEmE10Priorities acquire, align 8
  %32 = icmp eq i8 %31, 0
  br i1 %32, label %33, label %58, !prof !11

33:                                               ; preds = %30
  %34 = call i32 @__cxa_guard_acquire(ptr @_ZGVZN3chw11setPriorityENS_8PriorityEmE10Priorities) #3
  %35 = icmp ne i32 %34, 0
  br i1 %35, label %36, label %58

36:                                               ; preds = %33
  %37 = load i32, ptr @_ZZN3chw11setPriorityENS_8PriorityEmE3Min, align 4, !tbaa !12
  store i32 %37, ptr @_ZZN3chw11setPriorityENS_8PriorityEmE10Priorities, align 4, !tbaa !12
  %38 = load i32, ptr @_ZZN3chw11setPriorityENS_8PriorityEmE3Min, align 4, !tbaa !12
  %39 = load i32, ptr @_ZZN3chw11setPriorityENS_8PriorityEmE3Max, align 4, !tbaa !12
  %40 = load i32, ptr @_ZZN3chw11setPriorityENS_8PriorityEmE3Min, align 4, !tbaa !12
  %41 = sub nsw i32 %39, %40
  %42 = sdiv i32 %41, 4
  %43 = add nsw i32 %38, %42
  store i32 %43, ptr getelementptr inbounds (i32, ptr @_ZZN3chw11setPriorityENS_8PriorityEmE10Priorities, i64 1), align 4, !tbaa !12
  %44 = load i32, ptr @_ZZN3chw11setPriorityENS_8PriorityEmE3Min, align 4, !tbaa !12
  %45 = load i32, ptr @_ZZN3chw11setPriorityENS_8PriorityEmE3Max, align 4, !tbaa !12
  %46 = load i32, ptr @_ZZN3chw11setPriorityENS_8PriorityEmE3Min, align 4, !tbaa !12
  %47 = sub nsw i32 %45, %46
  %48 = sdiv i32 %47, 2
  %49 = add nsw i32 %44, %48
  store i32 %49, ptr getelementptr inbounds (i32, ptr @_ZZN3chw11setPriorityENS_8PriorityEmE10Priorities, i64 2), align 4, !tbaa !12
  %50 = load i32, ptr @_ZZN3chw11setPriorityENS_8PriorityEmE3Min, align 4, !tbaa !12
  %51 = load i32, ptr @_ZZN3chw11setPriorityENS_8PriorityEmE3Max, align 4, !tbaa !12
  %52 = load i32, ptr @_ZZN3chw11setPriorityENS_8PriorityEmE3Min, align 4, !tbaa !12
  %53 = sub nsw i32 %51, %52
  %54 = mul nsw i32 %53, 3
  %55 = sdiv i32 %54, 4
  %56 = add nsw i32 %50, %55
  store i32 %56, ptr getelementptr inbounds (i32, ptr @_ZZN3chw11setPriorityENS_8PriorityEmE10Priorities, i64 3), align 4, !tbaa !12
  %57 = load i32, ptr @_ZZN3chw11setPriorityENS_8PriorityEmE3Max, align 4, !tbaa !12
  store i32 %57, ptr getelementptr inbounds (i32, ptr @_ZZN3chw11setPriorityENS_8PriorityEmE10Priorities, i64 4), align 4, !tbaa !12
  call void @__cxa_guard_release(ptr @_ZGVZN3chw11setPriorityENS_8PriorityEmE10Priorities) #3
  br label %58

58:                                               ; preds = %36, %33, %30
  %59 = load i64, ptr %5, align 8, !tbaa !9
  %60 = icmp eq i64 %59, 0
  br i1 %60, label %61, label %63

61:                                               ; preds = %58
  %62 = call i64 @pthread_self() #5
  store i64 %62, ptr %5, align 8, !tbaa !9
  br label %63

63:                                               ; preds = %61, %58
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #3
  %64 = load i32, ptr %4, align 4, !tbaa !5
  %65 = zext i32 %64 to i64
  %66 = getelementptr inbounds [5 x i32], ptr @_ZZN3chw11setPriorityENS_8PriorityEmE10Priorities, i64 0, i64 %65
  %67 = load i32, ptr %66, align 4, !tbaa !12
  %68 = getelementptr inbounds %struct.sched_param, ptr %6, i32 0, i32 0
  store i32 %67, ptr %68, align 4, !tbaa !14
  %69 = load i64, ptr %5, align 8, !tbaa !9
  %70 = call i32 @pthread_setschedparam(i64 noundef %69, i32 noundef 1, ptr noundef %6) #3
  %71 = icmp eq i32 %70, 0
  store i1 %71, ptr %3, align 1
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #3
  br label %72

72:                                               ; preds = %63, %29, %17
  %73 = load i1, ptr %3, align 1
  ret i1 %73
}

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

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

; Function Attrs: nounwind
declare void @__cxa_guard_release(ptr) #3

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

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

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

!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 = !{!"_ZTSN3chw8PriorityE", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"long", !7, i64 0}
!11 = !{!"branch_weights", i32 1, i32 1048575}
!12 = !{!13, !13, i64 0}
!13 = !{!"int", !7, i64 0}
!14 = !{!15, !13, i64 0}
!15 = !{!"_ZTS11sched_param", !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 }

@_ZZN3chw11setPriorityENS_8PriorityEmE3Min = external hidden local_unnamed_addr global i32, align 4
@_ZGVZN3chw11setPriorityENS_8PriorityEmE3Min = external hidden global i64, align 8
@_ZZN3chw11setPriorityENS_8PriorityEmE3Max = external hidden local_unnamed_addr global i32, align 4
@_ZGVZN3chw11setPriorityENS_8PriorityEmE3Max = external hidden global i64, align 8
@_ZZN3chw11setPriorityENS_8PriorityEmE10Priorities = external hidden local_unnamed_addr global [5 x i32], align 16
@_ZGVZN3chw11setPriorityENS_8PriorityEmE10Priorities = external hidden global i64, align 8

; Function Attrs: mustprogress nofree nosync nounwind willreturn memory(none)
declare i64 @pthread_self() local_unnamed_addr #0

; Function Attrs: mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #1

; Function Attrs: mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #1

; Function Attrs: mustprogress nounwind uwtable
define dso_local noundef zeroext i1 @_ZN3chw11setPriorityENS_8PriorityEm(i32 noundef %0, i64 noundef %1) local_unnamed_addr #2 {
  %3 = alloca %struct.sched_param, align 4
  %4 = load atomic i8, ptr @_ZGVZN3chw11setPriorityENS_8PriorityEmE3Min acquire, align 8
  %5 = icmp eq i8 %4, 0
  br i1 %5, label %6, label %10, !prof !5

6:                                                ; preds = %2
  %7 = tail call i32 @__cxa_guard_acquire(ptr nonnull @_ZGVZN3chw11setPriorityENS_8PriorityEmE3Min) #5
  %.not = icmp eq i32 %7, 0
  br i1 %.not, label %10, label %8

8:                                                ; preds = %6
  %9 = tail call i32 @sched_get_priority_min(i32 noundef 1) #5
  store i32 %9, ptr @_ZZN3chw11setPriorityENS_8PriorityEmE3Min, align 4, !tbaa !6
  tail call void @__cxa_guard_release(ptr nonnull @_ZGVZN3chw11setPriorityENS_8PriorityEmE3Min) #5
  br label %10

10:                                               ; preds = %8, %6, %2
  %11 = load i32, ptr @_ZZN3chw11setPriorityENS_8PriorityEmE3Min, align 4, !tbaa !6
  %12 = icmp eq i32 %11, -1
  br i1 %12, label %49, label %13

13:                                               ; preds = %10
  %14 = load atomic i8, ptr @_ZGVZN3chw11setPriorityENS_8PriorityEmE3Max acquire, align 8
  %15 = icmp eq i8 %14, 0
  br i1 %15, label %16, label %20, !prof !5

16:                                               ; preds = %13
  %17 = tail call i32 @__cxa_guard_acquire(ptr nonnull @_ZGVZN3chw11setPriorityENS_8PriorityEmE3Max) #5
  %.not5 = icmp eq i32 %17, 0
  br i1 %.not5, label %20, label %18

18:                                               ; preds = %16
  %19 = tail call i32 @sched_get_priority_max(i32 noundef 1) #5
  store i32 %19, ptr @_ZZN3chw11setPriorityENS_8PriorityEmE3Max, align 4, !tbaa !6
  tail call void @__cxa_guard_release(ptr nonnull @_ZGVZN3chw11setPriorityENS_8PriorityEmE3Max) #5
  br label %20

20:                                               ; preds = %18, %16, %13
  %21 = load i32, ptr @_ZZN3chw11setPriorityENS_8PriorityEmE3Max, align 4, !tbaa !6
  %22 = icmp eq i32 %21, -1
  br i1 %22, label %49, label %23

23:                                               ; preds = %20
  %24 = load atomic i8, ptr @_ZGVZN3chw11setPriorityENS_8PriorityEmE10Priorities acquire, align 8
  %25 = icmp eq i8 %24, 0
  br i1 %25, label %26, label %39, !prof !5

26:                                               ; preds = %23
  %27 = tail call i32 @__cxa_guard_acquire(ptr nonnull @_ZGVZN3chw11setPriorityENS_8PriorityEmE10Priorities) #5
  %.not6 = icmp eq i32 %27, 0
  br i1 %.not6, label %39, label %28

28:                                               ; preds = %26
  %29 = load i32, ptr @_ZZN3chw11setPriorityENS_8PriorityEmE3Min, align 4, !tbaa !6
  store i32 %29, ptr @_ZZN3chw11setPriorityENS_8PriorityEmE10Priorities, align 16, !tbaa !6
  %30 = load i32, ptr @_ZZN3chw11setPriorityENS_8PriorityEmE3Max, align 4, !tbaa !6
  %31 = sub nsw i32 %30, %29
  %32 = sdiv i32 %31, 4
  %33 = add nsw i32 %32, %29
  store i32 %33, ptr getelementptr inbounds (i8, ptr @_ZZN3chw11setPriorityENS_8PriorityEmE10Priorities, i64 4), align 4, !tbaa !6
  %34 = sdiv i32 %31, 2
  %35 = add nsw i32 %34, %29
  store i32 %35, ptr getelementptr inbounds (i8, ptr @_ZZN3chw11setPriorityENS_8PriorityEmE10Priorities, i64 8), align 8, !tbaa !6
  %36 = mul nsw i32 %31, 3
  %37 = sdiv i32 %36, 4
  %38 = add nsw i32 %37, %29
  store i32 %38, ptr getelementptr inbounds (i8, ptr @_ZZN3chw11setPriorityENS_8PriorityEmE10Priorities, i64 12), align 4, !tbaa !6
  store i32 %30, ptr getelementptr inbounds (i8, ptr @_ZZN3chw11setPriorityENS_8PriorityEmE10Priorities, i64 16), align 16, !tbaa !6
  tail call void @__cxa_guard_release(ptr nonnull @_ZGVZN3chw11setPriorityENS_8PriorityEmE10Priorities) #5
  br label %39

39:                                               ; preds = %28, %26, %23
  %40 = icmp eq i64 %1, 0
  br i1 %40, label %41, label %43

41:                                               ; preds = %39
  %42 = tail call i64 @pthread_self() #6
  br label %43

43:                                               ; preds = %41, %39
  %.0 = phi i64 [ %42, %41 ], [ %1, %39 ]
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %3) #5
  %44 = zext i32 %0 to i64
  %45 = getelementptr inbounds [5 x i32], ptr @_ZZN3chw11setPriorityENS_8PriorityEmE10Priorities, i64 0, i64 %44
  %46 = load i32, ptr %45, align 4, !tbaa !6
  store i32 %46, ptr %3, align 4, !tbaa !10
  %47 = call i32 @pthread_setschedparam(i64 noundef %.0, i32 noundef 1, ptr noundef nonnull %3) #5
  %48 = icmp eq i32 %47, 0
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %3) #5
  br label %49

49:                                               ; preds = %20, %10, %43
  %.03 = phi i1 [ %48, %43 ], [ false, %10 ], [ false, %20 ]
  ret i1 %.03
}

; Function Attrs: nofree nounwind
declare i32 @__cxa_guard_acquire(ptr) local_unnamed_addr #3

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

; Function Attrs: nofree nounwind
declare void @__cxa_guard_release(ptr) local_unnamed_addr #3

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

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

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

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


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