; LLVM IR from jrouwe/JoltPhysics :: Jolt/Core/JobSystemWithBarrier.ll (ZN3JPH20JobSystemWithBarrier11BarrierImpl4WaitEv)

; 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.JPH::AssertLastParam" = type { i8 }
%"class.JPH::JobSystemWithBarrier::BarrierImpl" = type { %"class.JPH::JobSystem::Barrier", %"struct.std::atomic", [2048 x %"struct.std::atomic.0"], [48 x i8], %"struct.std::atomic.2", [60 x i8], %"struct.std::atomic.2", %"struct.std::atomic.4", [56 x i8], %"class.JPH::Semaphore" }
%"class.JPH::JobSystem::Barrier" = type { ptr }
%"struct.std::atomic" = type { %"struct.std::__atomic_base" }
%"struct.std::__atomic_base" = type { i8 }
%"struct.std::atomic.0" = type { %"struct.std::__atomic_base.1" }
%"struct.std::__atomic_base.1" = type { ptr }
%"struct.std::atomic.2" = type { %"struct.std::__atomic_base.3" }
%"struct.std::__atomic_base.3" = type { i32 }
%"struct.std::atomic.4" = type { %"struct.std::__atomic_base.5" }
%"struct.std::__atomic_base.5" = type { i32 }
%"class.JPH::Semaphore" = type { %"struct.std::atomic.4", %union.sem_t, [24 x i8] }
%union.sem_t = type { i64, [24 x i8] }

@.str.1 = external hidden unnamed_addr constant [87 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [40 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: mustprogress nounwind uwtable
declare dso_local noundef ptr @_ZNSt6atomicIPN3JPH9JobSystem3JobEEaSES3_(ptr noundef nonnull align 8 dereferenceable(8), ptr noundef) #1 align 2

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local noundef zeroext i1 @_ZN3JPH23AssertFailedParamHelperEPKcS1_jNS_15AssertLastParamE(ptr noundef, ptr noundef, i32 noundef) #2

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef zeroext i1 @_ZNK3JPH9JobSystem3Job13CanBeExecutedEv(ptr noundef nonnull align 8 dereferenceable(56)) #3 align 2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i32 @_ZNKSt13__atomic_baseIjEcvjEv(ptr noundef nonnull align 4 dereferenceable(4)) #1 align 2

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN3JPH20JobSystemWithBarrier11BarrierImpl4WaitEv(ptr noundef nonnull align 64 dereferenceable(16640) %0) #4 align 2 {
  %2 = alloca ptr, align 8
  %3 = alloca i8, align 1
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  %8 = alloca ptr, align 8
  %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 %"struct.JPH::AssertLastParam", align 1
  store ptr %0, ptr %2, align 8, !tbaa !5
  %16 = load ptr, ptr %2, align 8
  br label %17

17:                                               ; preds = %90, %1
  %18 = getelementptr inbounds %"class.JPH::JobSystemWithBarrier::BarrierImpl", ptr %16, i32 0, i32 7
  %19 = call noundef i32 @_ZNKSt13__atomic_baseIiEcviEv(ptr noundef nonnull align 4 dereferenceable(4) %18) #6
  %20 = icmp sgt i32 %19, 0
  br i1 %20, label %21, label %100

21:                                               ; preds = %17
  call void @llvm.lifetime.start.p0(i64 1, ptr %3) #6
  br label %22

22:                                               ; preds = %87, %21
  store i8 0, ptr %3, align 1, !tbaa !9
  br label %23

23:                                               ; preds = %52, %22
  %24 = getelementptr inbounds %"class.JPH::JobSystemWithBarrier::BarrierImpl", ptr %16, i32 0, i32 4
  %25 = call noundef i32 @_ZNKSt13__atomic_baseIjEcvjEv(ptr noundef nonnull align 4 dereferenceable(4) %24) #6
  %26 = getelementptr inbounds %"class.JPH::JobSystemWithBarrier::BarrierImpl", ptr %16, i32 0, i32 6
  %27 = call noundef i32 @_ZNKSt13__atomic_baseIjEcvjEv(ptr noundef nonnull align 4 dereferenceable(4) %26) #6
  %28 = icmp ult i32 %25, %27
  br i1 %28, label %29, label %53

29:                                               ; preds = %23
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #6
  %30 = getelementptr inbounds %"class.JPH::JobSystemWithBarrier::BarrierImpl", ptr %16, i32 0, i32 2
  %31 = getelementptr inbounds %"class.JPH::JobSystemWithBarrier::BarrierImpl", ptr %16, i32 0, i32 4
  %32 = call noundef i32 @_ZNKSt13__atomic_baseIjEcvjEv(ptr noundef nonnull align 4 dereferenceable(4) %31) #6
  %33 = and i32 %32, 2047
  %34 = zext i32 %33 to i64
  %35 = getelementptr inbounds [2048 x %"struct.std::atomic.0"], ptr %30, i64 0, i64 %34
  store ptr %35, ptr %4, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #6
  %36 = load ptr, ptr %4, align 8, !tbaa !5
  %37 = call noundef ptr @_ZNKSt6atomicIPN3JPH9JobSystem3JobEE4loadESt12memory_order(ptr noundef nonnull align 8 dereferenceable(8) %36, i32 noundef 5) #6
  store ptr %37, ptr %5, align 8, !tbaa !5
  %38 = load ptr, ptr %5, align 8, !tbaa !5
  %39 = icmp eq ptr %38, null
  br i1 %39, label %43, label %40

40:                                               ; preds = %29
  %41 = load ptr, ptr %5, align 8, !tbaa !5
  %42 = call noundef zeroext i1 @_ZNK3JPH9JobSystem3Job6IsDoneEv(ptr noundef nonnull align 8 dereferenceable(56) %41)
  br i1 %42, label %44, label %43

43:                                               ; preds = %40, %29
  store i32 7, ptr %6, align 4
  br label %50

44:                                               ; preds = %40
  %45 = load ptr, ptr %5, align 8, !tbaa !5
  call void @_ZN3JPH9JobSystem3Job7ReleaseEv(ptr noundef nonnull align 8 dereferenceable(56) %45)
  %46 = load ptr, ptr %4, align 8, !tbaa !5
  %47 = call noundef ptr @_ZNSt6atomicIPN3JPH9JobSystem3JobEEaSES3_(ptr noundef nonnull align 8 dereferenceable(8) %46, ptr noundef null) #6
  %48 = getelementptr inbounds %"class.JPH::JobSystemWithBarrier::BarrierImpl", ptr %16, i32 0, i32 4
  %49 = call noundef i32 @_ZNSt13__atomic_baseIjEppEv(ptr noundef nonnull align 4 dereferenceable(4) %48) #6
  store i32 0, ptr %6, align 4
  br label %50

50:                                               ; preds = %44, %43
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #6
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #6
  %51 = load i32, ptr %6, align 4
  switch i32 %51, label %134 [
    i32 0, label %52
    i32 7, label %53
  ]

52:                                               ; preds = %50
  br label %23, !llvm.loop !11

53:                                               ; preds = %50, %23
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #6
  %54 = getelementptr inbounds %"class.JPH::JobSystemWithBarrier::BarrierImpl", ptr %16, i32 0, i32 4
  %55 = call noundef i32 @_ZNKSt13__atomic_baseIjEcvjEv(ptr noundef nonnull align 4 dereferenceable(4) %54) #6
  store i32 %55, ptr %7, align 4, !tbaa !13
  br label %56

56:                                               ; preds = %82, %53
  %57 = load i32, ptr %7, align 4, !tbaa !13
  %58 = getelementptr inbounds %"class.JPH::JobSystemWithBarrier::BarrierImpl", ptr %16, i32 0, i32 6
  %59 = call noundef i32 @_ZNKSt13__atomic_baseIjEcvjEv(ptr noundef nonnull align 4 dereferenceable(4) %58) #6
  %60 = icmp ult i32 %57, %59
  br i1 %60, label %62, label %61

61:                                               ; preds = %56
  store i32 8, ptr %6, align 4
  br label %85

62:                                               ; preds = %56
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #6
  %63 = getelementptr inbounds %"class.JPH::JobSystemWithBarrier::BarrierImpl", ptr %16, i32 0, i32 2
  %64 = load i32, ptr %7, align 4, !tbaa !13
  %65 = and i32 %64, 2047
  %66 = zext i32 %65 to i64
  %67 = getelementptr inbounds [2048 x %"struct.std::atomic.0"], ptr %63, i64 0, i64 %66
  store ptr %67, ptr %8, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #6
  %68 = load ptr, ptr %8, align 8, !tbaa !5
  %69 = call noundef ptr @_ZNKSt6atomicIPN3JPH9JobSystem3JobEE4loadESt12memory_order(ptr noundef nonnull align 8 dereferenceable(8) %68, i32 noundef 5) #6
  store ptr %69, ptr %9, align 8, !tbaa !5
  %70 = load ptr, ptr %9, align 8, !tbaa !5
  %71 = icmp ne ptr %70, null
  br i1 %71, label %72, label %78

72:                                               ; preds = %62
  %73 = load ptr, ptr %9, align 8, !tbaa !5
  %74 = call noundef zeroext i1 @_ZNK3JPH9JobSystem3Job13CanBeExecutedEv(ptr noundef nonnull align 8 dereferenceable(56) %73)
  br i1 %74, label %75, label %78

75:                                               ; preds = %72
  %76 = load ptr, ptr %9, align 8, !tbaa !5
  %77 = call noundef i32 @_ZN3JPH9JobSystem3Job7ExecuteEv(ptr noundef nonnull align 8 dereferenceable(56) %76)
  store i8 1, ptr %3, align 1, !tbaa !9
  store i32 8, ptr %6, align 4
  br label %79

78:                                               ; preds = %72, %62
  store i32 0, ptr %6, align 4
  br label %79

79:                                               ; preds = %78, %75
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #6
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #6
  %80 = load i32, ptr %6, align 4
  switch i32 %80, label %85 [
    i32 0, label %81
  ]

81:                                               ; preds = %79
  br label %82

82:                                               ; preds = %81
  %83 = load i32, ptr %7, align 4, !tbaa !13
  %84 = add i32 %83, 1
  store i32 %84, ptr %7, align 4, !tbaa !13
  br label %56, !llvm.loop !15

85:                                               ; preds = %79, %61
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #6
  br label %86

86:                                               ; preds = %85
  br label %87

87:                                               ; preds = %86
  %88 = load i8, ptr %3, align 1, !tbaa !9, !range !16, !noundef !17
  %89 = trunc i8 %88 to i1
  br i1 %89, label %22, label %90, !llvm.loop !18

90:                                               ; preds = %87
  call void @llvm.lifetime.end.p0(i64 1, ptr %3) #6
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #6
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #6
  store i32 1, ptr %11, align 4, !tbaa !13
  call void @llvm.lifetime.start.p0(i64 4, ptr %12) #6
  %91 = getelementptr inbounds %"class.JPH::JobSystemWithBarrier::BarrierImpl", ptr %16, i32 0, i32 9
  %92 = call noundef i32 @_ZNK3JPH9Semaphore8GetValueEv(ptr noundef nonnull align 64 dereferenceable(40) %91)
  store i32 %92, ptr %12, align 4, !tbaa !13
  %93 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZSt3maxIiERKT_S2_S2_(ptr noundef nonnull align 4 dereferenceable(4) %11, ptr noundef nonnull align 4 dereferenceable(4) %12)
  %94 = load i32, ptr %93, align 4, !tbaa !13
  call void @llvm.lifetime.end.p0(i64 4, ptr %12) #6
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #6
  store i32 %94, ptr %10, align 4, !tbaa !13
  %95 = getelementptr inbounds %"class.JPH::JobSystemWithBarrier::BarrierImpl", ptr %16, i32 0, i32 9
  %96 = load i32, ptr %10, align 4, !tbaa !13
  call void @_ZN3JPH9Semaphore7AcquireEj(ptr noundef nonnull align 64 dereferenceable(40) %95, i32 noundef %96)
  %97 = load i32, ptr %10, align 4, !tbaa !13
  %98 = getelementptr inbounds %"class.JPH::JobSystemWithBarrier::BarrierImpl", ptr %16, i32 0, i32 7
  %99 = call noundef i32 @_ZNSt13__atomic_baseIiEmIEi(ptr noundef nonnull align 4 dereferenceable(4) %98, i32 noundef %97) #6
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #6
  br label %17, !llvm.loop !19

100:                                              ; preds = %17
  br label %101

101:                                              ; preds = %127, %100
  %102 = getelementptr inbounds %"class.JPH::JobSystemWithBarrier::BarrierImpl", ptr %16, i32 0, i32 4
  %103 = call noundef i32 @_ZNKSt13__atomic_baseIjEcvjEv(ptr noundef nonnull align 4 dereferenceable(4) %102) #6
  %104 = getelementptr inbounds %"class.JPH::JobSystemWithBarrier::BarrierImpl", ptr %16, i32 0, i32 6
  %105 = call noundef i32 @_ZNKSt13__atomic_baseIjEcvjEv(ptr noundef nonnull align 4 dereferenceable(4) %104) #6
  %106 = icmp ult i32 %103, %105
  br i1 %106, label %107, label %133

107:                                              ; preds = %101
  call void @llvm.lifetime.start.p0(i64 8, ptr %13) #6
  %108 = getelementptr inbounds %"class.JPH::JobSystemWithBarrier::BarrierImpl", ptr %16, i32 0, i32 2
  %109 = getelementptr inbounds %"class.JPH::JobSystemWithBarrier::BarrierImpl", ptr %16, i32 0, i32 4
  %110 = call noundef i32 @_ZNKSt13__atomic_baseIjEcvjEv(ptr noundef nonnull align 4 dereferenceable(4) %109) #6
  %111 = and i32 %110, 2047
  %112 = zext i32 %111 to i64
  %113 = getelementptr inbounds [2048 x %"struct.std::atomic.0"], ptr %108, i64 0, i64 %112
  store ptr %113, ptr %13, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %14) #6
  %114 = load ptr, ptr %13, align 8, !tbaa !5
  %115 = call noundef ptr @_ZNKSt6atomicIPN3JPH9JobSystem3JobEE4loadESt12memory_order(ptr noundef nonnull align 8 dereferenceable(8) %114, i32 noundef 5) #6
  store ptr %115, ptr %14, align 8, !tbaa !5
  br label %116

116:                                              ; preds = %107
  %117 = load ptr, ptr %14, align 8, !tbaa !5
  %118 = icmp ne ptr %117, null
  br i1 %118, label %119, label %122

119:                                              ; preds = %116
  %120 = load ptr, ptr %14, align 8, !tbaa !5
  %121 = call noundef zeroext i1 @_ZNK3JPH9JobSystem3Job6IsDoneEv(ptr noundef nonnull align 8 dereferenceable(56) %120)
  br i1 %121, label %125, label %122

122:                                              ; preds = %119, %116
  %123 = call noundef zeroext i1 @_ZN3JPH23AssertFailedParamHelperEPKcS1_jNS_15AssertLastParamE(ptr noundef @.str.4, ptr noundef @.str.1, i32 noundef 163)
  br i1 %123, label %124, label %125

124:                                              ; preds = %122
  call void asm sideeffect "int $$0x3", "~{dirflag},~{fpsr},~{flags}"() #6, !srcloc !20
  br label %125

125:                                              ; preds = %124, %122, %119
  br label %126

126:                                              ; preds = %125
  br label %127

127:                                              ; preds = %126
  %128 = load ptr, ptr %14, align 8, !tbaa !5
  call void @_ZN3JPH9JobSystem3Job7ReleaseEv(ptr noundef nonnull align 8 dereferenceable(56) %128)
  %129 = load ptr, ptr %13, align 8, !tbaa !5
  %130 = call noundef ptr @_ZNSt6atomicIPN3JPH9JobSystem3JobEEaSES3_(ptr noundef nonnull align 8 dereferenceable(8) %129, ptr noundef null) #6
  %131 = getelementptr inbounds %"class.JPH::JobSystemWithBarrier::BarrierImpl", ptr %16, i32 0, i32 4
  %132 = call noundef i32 @_ZNSt13__atomic_baseIjEppEv(ptr noundef nonnull align 4 dereferenceable(4) %131) #6
  call void @llvm.lifetime.end.p0(i64 8, ptr %14) #6
  call void @llvm.lifetime.end.p0(i64 8, ptr %13) #6
  br label %101, !llvm.loop !21

133:                                              ; preds = %101
  ret void

134:                                              ; preds = %50
  unreachable
}

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i32 @_ZNKSt13__atomic_baseIiEcviEv(ptr noundef nonnull align 4 dereferenceable(4)) #1 align 2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef ptr @_ZNKSt6atomicIPN3JPH9JobSystem3JobEE4loadESt12memory_order(ptr noundef nonnull align 8 dereferenceable(8), i32 noundef) #1 align 2

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef zeroext i1 @_ZNK3JPH9JobSystem3Job6IsDoneEv(ptr noundef nonnull align 8 dereferenceable(56)) #3 align 2

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local void @_ZN3JPH9JobSystem3Job7ReleaseEv(ptr noundef nonnull align 8 dereferenceable(56)) #2 align 2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i32 @_ZNSt13__atomic_baseIjEppEv(ptr noundef nonnull align 4 dereferenceable(4)) #1 align 2

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local noundef i32 @_ZN3JPH9JobSystem3Job7ExecuteEv(ptr noundef nonnull align 8 dereferenceable(56)) #2 align 2

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef nonnull align 4 dereferenceable(4) ptr @_ZSt3maxIiERKT_S2_S2_(ptr noundef nonnull align 4 dereferenceable(4), ptr noundef nonnull align 4 dereferenceable(4)) #3

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef i32 @_ZNK3JPH9Semaphore8GetValueEv(ptr noundef nonnull align 64 dereferenceable(40)) #3 align 2

declare void @_ZN3JPH9Semaphore7AcquireEj(ptr noundef nonnull align 64 dereferenceable(40), i32 noundef) #5

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i32 @_ZNSt13__atomic_baseIiEmIEi(ptr noundef nonnull align 4 dereferenceable(4), i32 noundef) #1 align 2

attributes #0 = { 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 = { inlinehint 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 #3 = { inlinehint 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 = { 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 #5 = { "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 = !{!"bool", !7, i64 0}
!11 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}
!13 = !{!14, !14, i64 0}
!14 = !{!"int", !7, i64 0}
!15 = distinct !{!15, !12}
!16 = !{i8 0, i8 2}
!17 = !{}
!18 = distinct !{!18, !12}
!19 = distinct !{!19, !12}
!20 = !{i64 2157459227}
!21 = distinct !{!21, !12}


; 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.std::atomic.0" = type { %"struct.std::__atomic_base.1" }
%"struct.std::__atomic_base.1" = type { ptr }

@.str.1 = external hidden unnamed_addr constant [87 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [40 x i8], align 1

; 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
declare dso_local noundef ptr @_ZNSt6atomicIPN3JPH9JobSystem3JobEEaSES3_(ptr noundef nonnull align 8 dereferenceable(8), ptr noundef) local_unnamed_addr #1 align 2

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local noundef zeroext i1 @_ZN3JPH23AssertFailedParamHelperEPKcS1_jNS_15AssertLastParamE(ptr noundef, ptr noundef, i32 noundef) local_unnamed_addr #2

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

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i32 @_ZNKSt13__atomic_baseIjEcvjEv(ptr noundef nonnull align 4 dereferenceable(4)) local_unnamed_addr #1 align 2

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN3JPH20JobSystemWithBarrier11BarrierImpl4WaitEv(ptr noundef nonnull align 64 dereferenceable(16640) %0) local_unnamed_addr #4 align 2 {
  %2 = alloca i32, align 4
  %3 = alloca i32, align 4
  %4 = getelementptr inbounds i8, ptr %0, i64 16516
  %5 = tail call noundef i32 @_ZNKSt13__atomic_baseIiEcviEv(ptr noundef nonnull align 4 dereferenceable(4) %4) #6
  %6 = icmp sgt i32 %5, 0
  br i1 %6, label %.preheader36.lr.ph, label %.preheader

.preheader36.lr.ph:                               ; preds = %1
  %7 = getelementptr inbounds i8, ptr %0, i64 16
  %8 = getelementptr inbounds i8, ptr %0, i64 16448
  %9 = getelementptr inbounds i8, ptr %0, i64 16512
  %10 = getelementptr inbounds i8, ptr %0, i64 16576
  br label %.preheader36

.preheader:                                       ; preds = %.critedge, %1
  %11 = getelementptr inbounds i8, ptr %0, i64 16448
  %12 = call noundef i32 @_ZNKSt13__atomic_baseIjEcvjEv(ptr noundef nonnull align 4 dereferenceable(4) %11) #6
  %13 = getelementptr inbounds i8, ptr %0, i64 16512
  %14 = call noundef i32 @_ZNKSt13__atomic_baseIjEcvjEv(ptr noundef nonnull align 4 dereferenceable(4) %13) #6
  %15 = icmp ult i32 %12, %14
  br i1 %15, label %.lr.ph49, label %._crit_edge

.lr.ph49:                                         ; preds = %.preheader
  %16 = getelementptr inbounds i8, ptr %0, i64 16
  br label %55

.preheader36:                                     ; preds = %.preheader36.backedge, %.preheader36.lr.ph
  %17 = call noundef i32 @_ZNKSt13__atomic_baseIjEcvjEv(ptr noundef nonnull align 4 dereferenceable(4) %8) #6
  %18 = call noundef i32 @_ZNKSt13__atomic_baseIjEcvjEv(ptr noundef nonnull align 4 dereferenceable(4) %9) #6
  %19 = icmp ult i32 %17, %18
  br i1 %19, label %.lr.ph, label %.thread

.lr.ph:                                           ; preds = %.preheader36, %28
  %20 = call noundef i32 @_ZNKSt13__atomic_baseIjEcvjEv(ptr noundef nonnull align 4 dereferenceable(4) %8) #6
  %21 = and i32 %20, 2047
  %22 = zext nneg i32 %21 to i64
  %23 = getelementptr inbounds [2048 x %"struct.std::atomic.0"], ptr %7, i64 0, i64 %22
  %24 = call noundef ptr @_ZNKSt6atomicIPN3JPH9JobSystem3JobEE4loadESt12memory_order(ptr noundef nonnull align 8 dereferenceable(8) %23, i32 noundef 5) #6
  %25 = icmp eq ptr %24, null
  br i1 %25, label %.thread, label %26

26:                                               ; preds = %.lr.ph
  %27 = call noundef zeroext i1 @_ZNK3JPH9JobSystem3Job6IsDoneEv(ptr noundef nonnull align 8 dereferenceable(56) %24)
  br i1 %27, label %28, label %.thread

28:                                               ; preds = %26
  call void @_ZN3JPH9JobSystem3Job7ReleaseEv(ptr noundef nonnull align 8 dereferenceable(56) %24)
  %29 = call noundef ptr @_ZNSt6atomicIPN3JPH9JobSystem3JobEEaSES3_(ptr noundef nonnull align 8 dereferenceable(8) %23, ptr noundef null) #6
  %30 = call noundef i32 @_ZNSt13__atomic_baseIjEppEv(ptr noundef nonnull align 4 dereferenceable(4) %8) #6
  %31 = call noundef i32 @_ZNKSt13__atomic_baseIjEcvjEv(ptr noundef nonnull align 4 dereferenceable(4) %8) #6
  %32 = call noundef i32 @_ZNKSt13__atomic_baseIjEcvjEv(ptr noundef nonnull align 4 dereferenceable(4) %9) #6
  %33 = icmp ult i32 %31, %32
  br i1 %33, label %.lr.ph, label %.thread

.thread:                                          ; preds = %28, %26, %.lr.ph, %.preheader36
  %34 = call noundef i32 @_ZNKSt13__atomic_baseIjEcvjEv(ptr noundef nonnull align 4 dereferenceable(4) %8) #6
  %35 = call noundef i32 @_ZNKSt13__atomic_baseIjEcvjEv(ptr noundef nonnull align 4 dereferenceable(4) %9) #6
  %36 = icmp ult i32 %34, %35
  br i1 %36, label %.lr.ph48, label %.critedge

.lr.ph48:                                         ; preds = %.thread, %45
  %.02447 = phi i32 [ %46, %45 ], [ %34, %.thread ]
  %37 = and i32 %.02447, 2047
  %38 = zext nneg i32 %37 to i64
  %39 = getelementptr inbounds [2048 x %"struct.std::atomic.0"], ptr %7, i64 0, i64 %38
  %40 = call noundef ptr @_ZNKSt6atomicIPN3JPH9JobSystem3JobEE4loadESt12memory_order(ptr noundef nonnull align 8 dereferenceable(8) %39, i32 noundef 5) #6
  %.not28 = icmp eq ptr %40, null
  br i1 %.not28, label %45, label %41

41:                                               ; preds = %.lr.ph48
  %42 = call noundef zeroext i1 @_ZNK3JPH9JobSystem3Job13CanBeExecutedEv(ptr noundef nonnull align 8 dereferenceable(56) %40)
  br i1 %42, label %43, label %45

43:                                               ; preds = %41
  %44 = call noundef i32 @_ZN3JPH9JobSystem3Job7ExecuteEv(ptr noundef nonnull align 8 dereferenceable(56) %40)
  br label %.preheader36.backedge

.preheader36.backedge:                            ; preds = %43, %.critedge
  br label %.preheader36, !llvm.loop !5

45:                                               ; preds = %41, %.lr.ph48
  %46 = add nuw i32 %.02447, 1
  %47 = call noundef i32 @_ZNKSt13__atomic_baseIjEcvjEv(ptr noundef nonnull align 4 dereferenceable(4) %9) #6
  %48 = icmp ult i32 %46, %47
  br i1 %48, label %.lr.ph48, label %.critedge, !llvm.loop !7

.critedge:                                        ; preds = %45, %.thread
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %2) #6
  store i32 1, ptr %2, align 4, !tbaa !8
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %3) #6
  %49 = call noundef i32 @_ZNK3JPH9Semaphore8GetValueEv(ptr noundef nonnull align 64 dereferenceable(40) %10)
  store i32 %49, ptr %3, align 4, !tbaa !8
  %50 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZSt3maxIiERKT_S2_S2_(ptr noundef nonnull align 4 dereferenceable(4) %2, ptr noundef nonnull align 4 dereferenceable(4) %3)
  %51 = load i32, ptr %50, align 4, !tbaa !8
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %3) #6
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %2) #6
  call void @_ZN3JPH9Semaphore7AcquireEj(ptr noundef nonnull align 64 dereferenceable(40) %10, i32 noundef %51)
  %52 = call noundef i32 @_ZNSt13__atomic_baseIiEmIEi(ptr noundef nonnull align 4 dereferenceable(4) %4, i32 noundef %51) #6
  %53 = call noundef i32 @_ZNKSt13__atomic_baseIiEcviEv(ptr noundef nonnull align 4 dereferenceable(4) %4) #6
  %54 = icmp sgt i32 %53, 0
  br i1 %54, label %.preheader36.backedge, label %.preheader

55:                                               ; preds = %.lr.ph49, %66
  %56 = call noundef i32 @_ZNKSt13__atomic_baseIjEcvjEv(ptr noundef nonnull align 4 dereferenceable(4) %11) #6
  %57 = and i32 %56, 2047
  %58 = zext nneg i32 %57 to i64
  %59 = getelementptr inbounds [2048 x %"struct.std::atomic.0"], ptr %16, i64 0, i64 %58
  %60 = call noundef ptr @_ZNKSt6atomicIPN3JPH9JobSystem3JobEE4loadESt12memory_order(ptr noundef nonnull align 8 dereferenceable(8) %59, i32 noundef 5) #6
  %.not = icmp eq ptr %60, null
  br i1 %.not, label %63, label %61

61:                                               ; preds = %55
  %62 = call noundef zeroext i1 @_ZNK3JPH9JobSystem3Job6IsDoneEv(ptr noundef nonnull align 8 dereferenceable(56) %60)
  br i1 %62, label %66, label %63

63:                                               ; preds = %61, %55
  %64 = call noundef zeroext i1 @_ZN3JPH23AssertFailedParamHelperEPKcS1_jNS_15AssertLastParamE(ptr noundef nonnull @.str.4, ptr noundef nonnull @.str.1, i32 noundef 163)
  br i1 %64, label %65, label %66

65:                                               ; preds = %63
  call void asm sideeffect "int $$0x3", "~{dirflag},~{fpsr},~{flags}"() #6, !srcloc !12
  br label %66

66:                                               ; preds = %65, %63, %61
  call void @_ZN3JPH9JobSystem3Job7ReleaseEv(ptr noundef nonnull align 8 dereferenceable(56) %60)
  %67 = call noundef ptr @_ZNSt6atomicIPN3JPH9JobSystem3JobEEaSES3_(ptr noundef nonnull align 8 dereferenceable(8) %59, ptr noundef null) #6
  %68 = call noundef i32 @_ZNSt13__atomic_baseIjEppEv(ptr noundef nonnull align 4 dereferenceable(4) %11) #6
  %69 = call noundef i32 @_ZNKSt13__atomic_baseIjEcvjEv(ptr noundef nonnull align 4 dereferenceable(4) %11) #6
  %70 = call noundef i32 @_ZNKSt13__atomic_baseIjEcvjEv(ptr noundef nonnull align 4 dereferenceable(4) %13) #6
  %71 = icmp ult i32 %69, %70
  br i1 %71, label %55, label %._crit_edge, !llvm.loop !13

._crit_edge:                                      ; preds = %66, %.preheader
  ret void
}

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i32 @_ZNKSt13__atomic_baseIiEcviEv(ptr noundef nonnull align 4 dereferenceable(4)) local_unnamed_addr #1 align 2

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

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

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local void @_ZN3JPH9JobSystem3Job7ReleaseEv(ptr noundef nonnull align 8 dereferenceable(56)) local_unnamed_addr #2 align 2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i32 @_ZNSt13__atomic_baseIjEppEv(ptr noundef nonnull align 4 dereferenceable(4)) local_unnamed_addr #1 align 2

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local noundef i32 @_ZN3JPH9JobSystem3Job7ExecuteEv(ptr noundef nonnull align 8 dereferenceable(56)) local_unnamed_addr #2 align 2

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef nonnull align 4 dereferenceable(4) ptr @_ZSt3maxIiERKT_S2_S2_(ptr noundef nonnull align 4 dereferenceable(4), ptr noundef nonnull align 4 dereferenceable(4)) local_unnamed_addr #3

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef i32 @_ZNK3JPH9Semaphore8GetValueEv(ptr noundef nonnull align 64 dereferenceable(40)) local_unnamed_addr #3 align 2

declare void @_ZN3JPH9Semaphore7AcquireEj(ptr noundef nonnull align 64 dereferenceable(40), i32 noundef) local_unnamed_addr #5

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i32 @_ZNSt13__atomic_baseIiEmIEi(ptr noundef nonnull align 4 dereferenceable(4), i32 noundef) local_unnamed_addr #1 align 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 = { inlinehint 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 #3 = { inlinehint 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 = { 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 #5 = { "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 = distinct !{!5, !6}
!6 = !{!"llvm.loop.mustprogress"}
!7 = distinct !{!7, !6}
!8 = !{!9, !9, i64 0}
!9 = !{!"int", !10, i64 0}
!10 = !{!"omnipotent char", !11, i64 0}
!11 = !{!"Simple C++ TBAA"}
!12 = !{i64 2157459227}
!13 = distinct !{!13, !6}


; Effective O3 passes: ConstraintEliminationPass,CorrelatedValuePropagationPass,EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LICMPass,LoopInstSimplifyPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,SROAPass,SimplifyCFGPass,TailCallElimPass