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

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

@_ZTVN3JPH20JobSystemWithBarrier11BarrierImplE = external dso_local unnamed_addr constant { [7 x ptr] }, align 8

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

declare i32 @__gxx_personality_v0(...)

; 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 @_ZN3JPH20JobSystemWithBarrier11BarrierImplC2Ev(ptr noundef nonnull align 64 dereferenceable(16640) %0) unnamed_addr #1 align 2 personality ptr @__gxx_personality_v0 {
  %2 = alloca ptr, align 8
  %3 = alloca ptr, align 8
  %4 = alloca i32, align 4
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca ptr, align 8
  store ptr %0, ptr %2, align 8, !tbaa !5
  %9 = load ptr, ptr %2, align 8
  call void @_ZN3JPH9JobSystem7BarrierC2Ev(ptr noundef nonnull align 8 dereferenceable(8) %9) #5
  store ptr getelementptr inbounds inrange(-16, 40) ({ [7 x ptr] }, ptr @_ZTVN3JPH20JobSystemWithBarrier11BarrierImplE, i32 0, i32 0, i32 2), ptr %9, align 64, !tbaa !9
  %10 = getelementptr inbounds %"class.JPH::JobSystemWithBarrier::BarrierImpl", ptr %9, i32 0, i32 1
  call void @_ZNSt6atomicIbEC2Eb(ptr noundef nonnull align 1 dereferenceable(1) %10, i1 noundef zeroext false) #5
  %11 = getelementptr inbounds %"class.JPH::JobSystemWithBarrier::BarrierImpl", ptr %9, i32 0, i32 2
  %12 = getelementptr inbounds %"class.JPH::JobSystemWithBarrier::BarrierImpl", ptr %9, i32 0, i32 4
  call void @_ZNSt6atomicIjEC2Ej(ptr noundef nonnull align 4 dereferenceable(4) %12, i32 noundef 0) #5
  %13 = getelementptr inbounds %"class.JPH::JobSystemWithBarrier::BarrierImpl", ptr %9, i32 0, i32 6
  call void @_ZNSt6atomicIjEC2Ej(ptr noundef nonnull align 4 dereferenceable(4) %13, i32 noundef 0) #5
  %14 = getelementptr inbounds %"class.JPH::JobSystemWithBarrier::BarrierImpl", ptr %9, i32 0, i32 7
  call void @_ZNSt6atomicIiEC2Ei(ptr noundef nonnull align 4 dereferenceable(4) %14, i32 noundef 0) #5
  %15 = getelementptr inbounds %"class.JPH::JobSystemWithBarrier::BarrierImpl", ptr %9, i32 0, i32 9
  invoke void @_ZN3JPH9SemaphoreC1Ev(ptr noundef nonnull align 64 dereferenceable(40) %15)
          to label %16 unwind label %28

16:                                               ; preds = %1
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #5
  %17 = getelementptr inbounds %"class.JPH::JobSystemWithBarrier::BarrierImpl", ptr %9, i32 0, i32 2
  store ptr %17, ptr %5, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #5
  %18 = load ptr, ptr %5, align 8, !tbaa !5
  %19 = getelementptr inbounds [2048 x %"struct.std::atomic.0"], ptr %18, i64 0, i64 0
  store ptr %19, ptr %6, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #5
  %20 = load ptr, ptr %5, align 8, !tbaa !5
  %21 = getelementptr inbounds [2048 x %"struct.std::atomic.0"], ptr %20, i64 0, i64 0
  %22 = getelementptr inbounds %"struct.std::atomic.0", ptr %21, i64 2048
  store ptr %22, ptr %7, align 8, !tbaa !5
  br label %23

23:                                               ; preds = %36, %16
  %24 = load ptr, ptr %6, align 8, !tbaa !5
  %25 = load ptr, ptr %7, align 8, !tbaa !5
  %26 = icmp ne ptr %24, %25
  br i1 %26, label %32, label %27

27:                                               ; preds = %23
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #5
  br label %39

28:                                               ; preds = %1
  %29 = landingpad { ptr, i32 }
          cleanup
  %30 = extractvalue { ptr, i32 } %29, 0
  store ptr %30, ptr %3, align 8
  %31 = extractvalue { ptr, i32 } %29, 1
  store i32 %31, ptr %4, align 4
  call void @_ZN3JPH9JobSystem7BarrierD2Ev(ptr noundef nonnull align 8 dereferenceable(8) %9) #5
  br label %40

32:                                               ; preds = %23
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #5
  %33 = load ptr, ptr %6, align 8, !tbaa !5
  store ptr %33, ptr %8, align 8, !tbaa !5
  %34 = load ptr, ptr %8, align 8, !tbaa !5
  %35 = call noundef ptr @_ZNSt6atomicIPN3JPH9JobSystem3JobEEaSES3_(ptr noundef nonnull align 8 dereferenceable(8) %34, ptr noundef null) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #5
  br label %36

36:                                               ; preds = %32
  %37 = load ptr, ptr %6, align 8, !tbaa !5
  %38 = getelementptr inbounds %"struct.std::atomic.0", ptr %37, i32 1
  store ptr %38, ptr %6, align 8, !tbaa !5
  br label %23

39:                                               ; preds = %27
  ret void

40:                                               ; preds = %28
  %41 = load ptr, ptr %3, align 8
  %42 = load i32, ptr %4, align 4
  %43 = insertvalue { ptr, i32 } poison, ptr %41, 0
  %44 = insertvalue { ptr, i32 } %43, i32 %42, 1
  resume { ptr, i32 } %44
}

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

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZNSt6atomicIbEC2Eb(ptr noundef nonnull align 1 dereferenceable(1), i1 noundef zeroext) unnamed_addr #3 align 2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZNSt6atomicIjEC2Ej(ptr noundef nonnull align 4 dereferenceable(4), i32 noundef) unnamed_addr #3 align 2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZNSt6atomicIiEC2Ei(ptr noundef nonnull align 4 dereferenceable(4), i32 noundef) unnamed_addr #3 align 2

declare void @_ZN3JPH9SemaphoreC1Ev(ptr noundef nonnull align 64 dereferenceable(40)) unnamed_addr #4

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

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZN3JPH9JobSystem7BarrierD2Ev(ptr noundef nonnull align 8 dereferenceable(8)) unnamed_addr #3 align 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 = { 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 #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 = { "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++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"vtable pointer", !8, 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"

@_ZTVN3JPH20JobSystemWithBarrier11BarrierImplE = external dso_local unnamed_addr constant { [7 x ptr] }, align 8

declare i32 @__gxx_personality_v0(...)

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN3JPH20JobSystemWithBarrier11BarrierImplC2Ev(ptr noundef nonnull align 64 dereferenceable(16640) %0) unnamed_addr #0 align 2 personality ptr @__gxx_personality_v0 {
  tail call void @_ZN3JPH9JobSystem7BarrierC2Ev(ptr noundef nonnull align 8 dereferenceable(8) %0) #4
  store ptr getelementptr inbounds inrange(-16, 40) (i8, ptr @_ZTVN3JPH20JobSystemWithBarrier11BarrierImplE, i64 16), ptr %0, align 64, !tbaa !5
  %2 = getelementptr inbounds i8, ptr %0, i64 8
  tail call void @_ZNSt6atomicIbEC2Eb(ptr noundef nonnull align 1 dereferenceable(1) %2, i1 noundef zeroext false) #4
  %3 = getelementptr inbounds i8, ptr %0, i64 16448
  tail call void @_ZNSt6atomicIjEC2Ej(ptr noundef nonnull align 4 dereferenceable(4) %3, i32 noundef 0) #4
  %4 = getelementptr inbounds i8, ptr %0, i64 16512
  tail call void @_ZNSt6atomicIjEC2Ej(ptr noundef nonnull align 4 dereferenceable(4) %4, i32 noundef 0) #4
  %5 = getelementptr inbounds i8, ptr %0, i64 16516
  tail call void @_ZNSt6atomicIiEC2Ei(ptr noundef nonnull align 4 dereferenceable(4) %5, i32 noundef 0) #4
  %6 = getelementptr inbounds i8, ptr %0, i64 16576
  invoke void @_ZN3JPH9SemaphoreC1Ev(ptr noundef nonnull align 64 dereferenceable(40) %6)
          to label %.preheader unwind label %8

7:                                                ; preds = %.preheader
  ret void

8:                                                ; preds = %1
  %9 = landingpad { ptr, i32 }
          cleanup
  tail call void @_ZN3JPH9JobSystem7BarrierD2Ev(ptr noundef nonnull align 8 dereferenceable(8) %0) #4
  resume { ptr, i32 } %9

.preheader:                                       ; preds = %1, %.preheader
  %.0.idx10 = phi i64 [ %.0.add, %.preheader ], [ 16, %1 ]
  %.0.ptr = getelementptr inbounds i8, ptr %0, i64 %.0.idx10
  %10 = tail call noundef ptr @_ZNSt6atomicIPN3JPH9JobSystem3JobEEaSES3_(ptr noundef nonnull align 8 dereferenceable(8) %.0.ptr, ptr noundef null) #4
  %.0.add = add nuw nsw i64 %.0.idx10, 8
  %.not = icmp eq i64 %.0.add, 16400
  br i1 %.not, label %7, label %.preheader
}

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local void @_ZN3JPH9JobSystem7BarrierC2Ev(ptr noundef nonnull align 8 dereferenceable(8)) unnamed_addr #1 align 2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZNSt6atomicIbEC2Eb(ptr noundef nonnull align 1 dereferenceable(1), i1 noundef zeroext) unnamed_addr #2 align 2

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

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

declare void @_ZN3JPH9SemaphoreC1Ev(ptr noundef nonnull align 64 dereferenceable(40)) unnamed_addr #3

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

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

attributes #0 = { 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 #1 = { 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 #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 = { "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 = !{!"vtable pointer", !7, i64 0}
!7 = !{!"Simple C++ TBAA"}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,SROAPass,SimplifyCFGPass,TailCallElimPass