; LLVM IR from aras-p/ToyPathTracer :: Cpp/Source/enkiTS (TaskScheduler)

; 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.enki::SubTaskSet" = type { ptr, %"struct.enki::TaskSetPartition" }
%"struct.enki::TaskSetPartition" = type { i32, i32 }
%"class.enki::ICompletable" = type { ptr, i32, %"struct.std::atomic.0", %"struct.std::atomic.0", i32, %"struct.std::atomic.0", ptr }
%"struct.std::atomic.0" = type { %"struct.std::__atomic_base.1" }
%"struct.std::__atomic_base.1" = type { i32 }
%"class.enki::TaskScheduler" = type <{ [3 x ptr], [3 x ptr], i32, [4 x i8], ptr, ptr, %"struct.std::atomic", %"struct.std::atomic", %"struct.std::atomic", i8, %"struct.std::atomic.0", %"struct.std::atomic.0", %"struct.std::atomic.0", i32, [4 x i8], ptr, ptr, i32, i8, [3 x i8], %"struct.enki::TaskSchedulerConfig", %"struct.std::atomic.0", [4 x i8] }>
%"struct.std::atomic" = type { %"struct.std::__atomic_base" }
%"struct.std::__atomic_base" = type { i8 }
%"struct.enki::TaskSchedulerConfig" = type { i32, i32, %"struct.enki::ProfilerCallbacks", %"struct.enki::CustomAllocator" }
%"struct.enki::ProfilerCallbacks" = type { ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr }
%"struct.enki::CustomAllocator" = type { ptr, ptr, ptr }
%"class.enki::TaskPipe" = type { %"class.enki::LockLessMultiReadPipe.base", [4 x i8] }
%"class.enki::LockLessMultiReadPipe.base" = type <{ [256 x %"struct.enki::SubTaskSet"], %"struct.std::atomic.3", %"struct.std::atomic.3", [256 x %"struct.std::atomic.3"], %"struct.std::atomic.3" }>
%"struct.std::atomic.3" = type { %"struct.std::__atomic_base.4" }
%"struct.std::__atomic_base.4" = type { i32 }
%"class.enki::ITaskSet" = type <{ %"class.enki::ICompletable", i32, i32, i32, [4 x i8] }>

@.str.3 = external hidden unnamed_addr constant [90 x i8], align 1
@.str.12 = external hidden unnamed_addr constant [54 x i8], align 1
@__PRETTY_FUNCTION__._ZN4enki13TaskScheduler15SplitAndAddTaskEjNS_10SubTaskSetEj = external hidden unnamed_addr constant [74 x i8], align 1
@.str.13 = external hidden unnamed_addr constant [18 x i8], align 1

; Function Attrs: noreturn nounwind
declare void @__assert_fail(ptr noundef, ptr noundef, i32 noundef, ptr noundef) #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: alwaysinline mustprogress nounwind uwtable
declare dso_local noundef i32 @_ZNSt13__atomic_baseIiE9fetch_subEiSt12memory_order(ptr noundef nonnull align 4 dereferenceable(4), i32 noundef, i32 noundef) #2 align 2

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN4enki13TaskScheduler22WakeThreadsForNewTasksEv(ptr noundef nonnull align 8 dereferenceable(220)) #3 align 2

; Function Attrs: mustprogress nounwind uwtable
declare hidden { ptr, i64 } @_ZN12_GLOBAL__N_19SplitTaskERN4enki10SubTaskSetEj(ptr noundef nonnull align 8 dereferenceable(16), i32 noundef) #4

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN4enki13TaskScheduler15SplitAndAddTaskEjNS_10SubTaskSetEj(ptr noundef nonnull align 8 dereferenceable(220) %0, i32 noundef %1, ptr %2, i64 %3, i32 noundef %4) #3 align 2 {
  %6 = alloca %"struct.enki::SubTaskSet", align 8
  %7 = alloca ptr, align 8
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  %10 = alloca i32, align 4
  %11 = alloca i32, align 4
  %12 = alloca i32, align 4
  %13 = alloca %"struct.enki::SubTaskSet", align 8
  %14 = alloca %"struct.enki::TaskSetPartition", align 4
  %15 = alloca i32, align 4
  %16 = alloca i32, align 4
  %17 = getelementptr inbounds { ptr, i64 }, ptr %6, i32 0, i32 0
  store ptr %2, ptr %17, align 8
  %18 = getelementptr inbounds { ptr, i64 }, ptr %6, i32 0, i32 1
  store i64 %3, ptr %18, align 8
  store ptr %0, ptr %7, align 8, !tbaa !5
  store i32 %1, ptr %8, align 4, !tbaa !9
  store i32 %4, ptr %9, align 4, !tbaa !9
  %19 = load ptr, ptr %7, align 8
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #7
  store i32 0, ptr %10, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #7
  store i32 0, ptr %11, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %12) #7
  %20 = getelementptr inbounds %"struct.enki::SubTaskSet", ptr %6, i32 0, i32 1
  %21 = getelementptr inbounds %"struct.enki::TaskSetPartition", ptr %20, i32 0, i32 1
  %22 = load i32, ptr %21, align 4, !tbaa !11
  %23 = getelementptr inbounds %"struct.enki::SubTaskSet", ptr %6, i32 0, i32 1
  %24 = getelementptr inbounds %"struct.enki::TaskSetPartition", ptr %23, i32 0, i32 0
  %25 = load i32, ptr %24, align 8, !tbaa !14
  %26 = sub i32 %22, %25
  %27 = load i32, ptr %9, align 4, !tbaa !9
  %28 = udiv i32 %26, %27
  %29 = add nsw i32 2, %28
  store i32 %29, ptr %12, align 4, !tbaa !9
  %30 = getelementptr inbounds %"struct.enki::SubTaskSet", ptr %6, i32 0, i32 0
  %31 = load ptr, ptr %30, align 8, !tbaa !15
  %32 = getelementptr inbounds %"class.enki::ICompletable", ptr %31, i32 0, i32 2
  %33 = load i32, ptr %12, align 4, !tbaa !9
  %34 = call noundef i32 @_ZNSt13__atomic_baseIiE9fetch_addEiSt12memory_order(ptr noundef nonnull align 4 dereferenceable(4) %32, i32 noundef %33, i32 noundef 2) #7
  br label %35

35:                                               ; preds = %122, %5
  %36 = getelementptr inbounds %"struct.enki::SubTaskSet", ptr %6, i32 0, i32 1
  %37 = getelementptr inbounds %"struct.enki::TaskSetPartition", ptr %36, i32 0, i32 0
  %38 = load i32, ptr %37, align 8, !tbaa !14
  %39 = getelementptr inbounds %"struct.enki::SubTaskSet", ptr %6, i32 0, i32 1
  %40 = getelementptr inbounds %"struct.enki::TaskSetPartition", ptr %39, i32 0, i32 1
  %41 = load i32, ptr %40, align 4, !tbaa !11
  %42 = icmp ne i32 %38, %41
  br i1 %42, label %43, label %123

43:                                               ; preds = %35
  call void @llvm.lifetime.start.p0(i64 16, ptr %13) #7
  %44 = load i32, ptr %9, align 4, !tbaa !9
  %45 = call { ptr, i64 } @_ZN12_GLOBAL__N_19SplitTaskERN4enki10SubTaskSetEj(ptr noundef nonnull align 8 dereferenceable(16) %6, i32 noundef %44)
  %46 = getelementptr inbounds { ptr, i64 }, ptr %13, i32 0, i32 0
  %47 = extractvalue { ptr, i64 } %45, 0
  store ptr %47, ptr %46, align 8
  %48 = getelementptr inbounds { ptr, i64 }, ptr %13, i32 0, i32 1
  %49 = extractvalue { ptr, i64 } %45, 1
  store i64 %49, ptr %48, align 8
  %50 = load i32, ptr %10, align 4, !tbaa !9
  %51 = add nsw i32 %50, 1
  store i32 %51, ptr %10, align 4, !tbaa !9
  %52 = load i32, ptr %11, align 4, !tbaa !9
  %53 = add nsw i32 %52, 1
  store i32 %53, ptr %11, align 4, !tbaa !9
  %54 = getelementptr inbounds %"class.enki::TaskScheduler", ptr %19, i32 0, i32 0
  %55 = getelementptr inbounds %"struct.enki::SubTaskSet", ptr %6, i32 0, i32 0
  %56 = load ptr, ptr %55, align 8, !tbaa !15
  %57 = getelementptr inbounds %"class.enki::ICompletable", ptr %56, i32 0, i32 1
  %58 = load i32, ptr %57, align 8, !tbaa !16
  %59 = zext i32 %58 to i64
  %60 = getelementptr inbounds [3 x ptr], ptr %54, i64 0, i64 %59
  %61 = load ptr, ptr %60, align 8, !tbaa !5
  %62 = load i32, ptr %8, align 4, !tbaa !9
  %63 = zext i32 %62 to i64
  %64 = getelementptr inbounds %"class.enki::TaskPipe", ptr %61, i64 %63
  %65 = call noundef zeroext i1 @_ZN4enki21LockLessMultiReadPipeILh8ENS_10SubTaskSetEE19WriterTryWriteFrontERKS1_(ptr noundef nonnull align 8 dereferenceable(5132) %64, ptr noundef nonnull align 8 dereferenceable(16) %13)
  br i1 %65, label %122, label %66

66:                                               ; preds = %43
  %67 = load i32, ptr %10, align 4, !tbaa !9
  %68 = add nsw i32 %67, -1
  store i32 %68, ptr %10, align 4, !tbaa !9
  %69 = load i32, ptr %11, align 4, !tbaa !9
  %70 = icmp sgt i32 %69, 1
  br i1 %70, label %71, label %72

71:                                               ; preds = %66
  call void @_ZN4enki13TaskScheduler22WakeThreadsForNewTasksEv(ptr noundef nonnull align 8 dereferenceable(220) %19)
  br label %72

72:                                               ; preds = %71, %66
  store i32 0, ptr %11, align 4, !tbaa !9
  %73 = getelementptr inbounds %"struct.enki::SubTaskSet", ptr %13, i32 0, i32 0
  %74 = load ptr, ptr %73, align 8, !tbaa !15
  %75 = getelementptr inbounds %"class.enki::ITaskSet", ptr %74, i32 0, i32 3
  %76 = load i32, ptr %75, align 8, !tbaa !21
  %77 = getelementptr inbounds %"struct.enki::SubTaskSet", ptr %13, i32 0, i32 1
  %78 = getelementptr inbounds %"struct.enki::TaskSetPartition", ptr %77, i32 0, i32 1
  %79 = load i32, ptr %78, align 4, !tbaa !11
  %80 = getelementptr inbounds %"struct.enki::SubTaskSet", ptr %13, i32 0, i32 1
  %81 = getelementptr inbounds %"struct.enki::TaskSetPartition", ptr %80, i32 0, i32 0
  %82 = load i32, ptr %81, align 8, !tbaa !14
  %83 = sub i32 %79, %82
  %84 = icmp ult i32 %76, %83
  br i1 %84, label %85, label %113

85:                                               ; preds = %72
  %86 = getelementptr inbounds %"struct.enki::SubTaskSet", ptr %13, i32 0, i32 1
  %87 = getelementptr inbounds %"struct.enki::TaskSetPartition", ptr %86, i32 0, i32 0
  %88 = load i32, ptr %87, align 8, !tbaa !14
  %89 = getelementptr inbounds %"struct.enki::SubTaskSet", ptr %13, i32 0, i32 0
  %90 = load ptr, ptr %89, align 8, !tbaa !15
  %91 = getelementptr inbounds %"class.enki::ITaskSet", ptr %90, i32 0, i32 3
  %92 = load i32, ptr %91, align 8, !tbaa !21
  %93 = add i32 %88, %92
  %94 = getelementptr inbounds %"struct.enki::SubTaskSet", ptr %13, i32 0, i32 1
  %95 = getelementptr inbounds %"struct.enki::TaskSetPartition", ptr %94, i32 0, i32 1
  store i32 %93, ptr %95, align 4, !tbaa !11
  %96 = getelementptr inbounds %"struct.enki::SubTaskSet", ptr %13, i32 0, i32 1
  %97 = getelementptr inbounds %"struct.enki::TaskSetPartition", ptr %96, i32 0, i32 1
  %98 = load i32, ptr %97, align 4, !tbaa !11
  %99 = getelementptr inbounds %"struct.enki::SubTaskSet", ptr %13, i32 0, i32 0
  %100 = load ptr, ptr %99, align 8, !tbaa !15
  %101 = getelementptr inbounds %"class.enki::ITaskSet", ptr %100, i32 0, i32 1
  %102 = load i32, ptr %101, align 8, !tbaa !23
  %103 = icmp ule i32 %98, %102
  br i1 %103, label %104, label %105

104:                                              ; preds = %85
  br label %107

105:                                              ; preds = %85
  call void @__assert_fail(ptr noundef @.str.12, ptr noundef @.str.3, i32 noundef 838, ptr noundef @__PRETTY_FUNCTION__._ZN4enki13TaskScheduler15SplitAndAddTaskEjNS_10SubTaskSetEj) #8
  unreachable

106:                                              ; No predecessors!
  br label %107

107:                                              ; preds = %106, %104
  %108 = getelementptr inbounds %"struct.enki::SubTaskSet", ptr %13, i32 0, i32 1
  %109 = getelementptr inbounds %"struct.enki::TaskSetPartition", ptr %108, i32 0, i32 1
  %110 = load i32, ptr %109, align 4, !tbaa !11
  %111 = getelementptr inbounds %"struct.enki::SubTaskSet", ptr %6, i32 0, i32 1
  %112 = getelementptr inbounds %"struct.enki::TaskSetPartition", ptr %111, i32 0, i32 0
  store i32 %110, ptr %112, align 8, !tbaa !14
  br label %113

113:                                              ; preds = %107, %72
  %114 = getelementptr inbounds %"struct.enki::SubTaskSet", ptr %13, i32 0, i32 0
  %115 = load ptr, ptr %114, align 8, !tbaa !15
  %116 = getelementptr inbounds %"struct.enki::SubTaskSet", ptr %13, i32 0, i32 1
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %14, ptr align 8 %116, i64 8, i1 false), !tbaa.struct !24
  %117 = load i32, ptr %8, align 4, !tbaa !9
  %118 = load i64, ptr %14, align 4
  %119 = load ptr, ptr %115, align 8, !tbaa !25
  %120 = getelementptr inbounds ptr, ptr %119, i64 3
  %121 = load ptr, ptr %120, align 8
  call void %121(ptr noundef nonnull align 8 dereferenceable(52) %115, i64 %118, i32 noundef %117)
  br label %122

122:                                              ; preds = %113, %43
  call void @llvm.lifetime.end.p0(i64 16, ptr %13) #7
  br label %35, !llvm.loop !27

123:                                              ; preds = %35
  call void @llvm.lifetime.start.p0(i64 4, ptr %15) #7
  %124 = load i32, ptr %12, align 4, !tbaa !9
  %125 = load i32, ptr %10, align 4, !tbaa !9
  %126 = sub nsw i32 %124, %125
  store i32 %126, ptr %15, align 4, !tbaa !9
  %127 = load i32, ptr %15, align 4, !tbaa !9
  %128 = icmp sgt i32 %127, 0
  br i1 %128, label %129, label %130

129:                                              ; preds = %123
  br label %132

130:                                              ; preds = %123
  call void @__assert_fail(ptr noundef @.str.13, ptr noundef @.str.3, i32 noundef 845, ptr noundef @__PRETTY_FUNCTION__._ZN4enki13TaskScheduler15SplitAndAddTaskEjNS_10SubTaskSetEj) #8
  unreachable

131:                                              ; No predecessors!
  br label %132

132:                                              ; preds = %131, %129
  call void @llvm.lifetime.start.p0(i64 4, ptr %16) #7
  %133 = getelementptr inbounds %"struct.enki::SubTaskSet", ptr %6, i32 0, i32 0
  %134 = load ptr, ptr %133, align 8, !tbaa !15
  %135 = getelementptr inbounds %"class.enki::ICompletable", ptr %134, i32 0, i32 2
  %136 = load i32, ptr %15, align 4, !tbaa !9
  %137 = call noundef i32 @_ZNSt13__atomic_baseIiE9fetch_subEiSt12memory_order(ptr noundef nonnull align 4 dereferenceable(4) %135, i32 noundef %136, i32 noundef 4) #7
  store i32 %137, ptr %16, align 4, !tbaa !9
  %138 = load i32, ptr %15, align 4, !tbaa !9
  %139 = sub nsw i32 %138, 1
  %140 = add nsw i32 %139, 2
  %141 = load i32, ptr %16, align 4, !tbaa !9
  %142 = icmp eq i32 %140, %141
  br i1 %142, label %143, label %147

143:                                              ; preds = %132
  %144 = getelementptr inbounds %"struct.enki::SubTaskSet", ptr %6, i32 0, i32 0
  %145 = load ptr, ptr %144, align 8, !tbaa !15
  %146 = load i32, ptr %8, align 4, !tbaa !9
  call void @_ZN4enki13TaskScheduler12TaskCompleteEPNS_12ICompletableEbj(ptr noundef nonnull align 8 dereferenceable(220) %19, ptr noundef %145, i1 noundef zeroext false, i32 noundef %146)
  br label %147

147:                                              ; preds = %143, %132
  call void @_ZN4enki13TaskScheduler22WakeThreadsForNewTasksEv(ptr noundef nonnull align 8 dereferenceable(220) %19)
  call void @llvm.lifetime.end.p0(i64 4, ptr %16) #7
  call void @llvm.lifetime.end.p0(i64 4, ptr %15) #7
  call void @llvm.lifetime.end.p0(i64 4, ptr %12) #7
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #7
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #7
  ret void
}

; 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) #5

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN4enki13TaskScheduler12TaskCompleteEPNS_12ICompletableEbj(ptr noundef nonnull align 8 dereferenceable(220), ptr noundef, i1 noundef zeroext, i32 noundef) #3 align 2

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

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef zeroext i1 @_ZN4enki21LockLessMultiReadPipeILh8ENS_10SubTaskSetEE19WriterTryWriteFrontERKS1_(ptr noundef nonnull align 8 dereferenceable(5132), ptr noundef nonnull align 8 dereferenceable(16)) #6 align 2

attributes #0 = { noreturn 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 #1 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { alwaysinline 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 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 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 #5 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #6 = { 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 #7 = { nounwind }
attributes #8 = { noreturn 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 = !{!12, !10, i64 12}
!12 = !{!"_ZTSN4enki10SubTaskSetE", !6, i64 0, !13, i64 8}
!13 = !{!"_ZTSN4enki16TaskSetPartitionE", !10, i64 0, !10, i64 4}
!14 = !{!12, !10, i64 8}
!15 = !{!12, !6, i64 0}
!16 = !{!17, !18, i64 8}
!17 = !{!"_ZTSN4enki12ICompletableE", !18, i64 8, !19, i64 12, !19, i64 16, !10, i64 20, !19, i64 24, !6, i64 32}
!18 = !{!"_ZTSN4enki12TaskPriorityE", !7, i64 0}
!19 = !{!"_ZTSSt6atomicIiE", !20, i64 0}
!20 = !{!"_ZTSSt13__atomic_baseIiE", !10, i64 0}
!21 = !{!22, !10, i64 48}
!22 = !{!"_ZTSN4enki8ITaskSetE", !17, i64 0, !10, i64 40, !10, i64 44, !10, i64 48}
!23 = !{!22, !10, i64 40}
!24 = !{i64 0, i64 4, !9, i64 4, i64 4, !9}
!25 = !{!26, !26, i64 0}
!26 = !{!"vtable pointer", !8, i64 0}
!27 = distinct !{!27, !28}
!28 = !{!"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"

%"struct.enki::SubTaskSet" = type { ptr, %"struct.enki::TaskSetPartition" }
%"struct.enki::TaskSetPartition" = type { i32, i32 }
%"class.enki::TaskPipe" = type { %"class.enki::LockLessMultiReadPipe.base", [4 x i8] }
%"class.enki::LockLessMultiReadPipe.base" = type <{ [256 x %"struct.enki::SubTaskSet"], %"struct.std::atomic.3", %"struct.std::atomic.3", [256 x %"struct.std::atomic.3"], %"struct.std::atomic.3" }>
%"struct.std::atomic.3" = type { %"struct.std::__atomic_base.4" }
%"struct.std::__atomic_base.4" = type { i32 }

@.str.3 = external hidden unnamed_addr constant [90 x i8], align 1
@.str.12 = external hidden unnamed_addr constant [54 x i8], align 1
@__PRETTY_FUNCTION__._ZN4enki13TaskScheduler15SplitAndAddTaskEjNS_10SubTaskSetEj = external hidden unnamed_addr constant [74 x i8], align 1
@.str.13 = external hidden unnamed_addr constant [18 x i8], align 1

; Function Attrs: noreturn nounwind
declare void @__assert_fail(ptr noundef, ptr noundef, i32 noundef, ptr noundef) 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: alwaysinline mustprogress nounwind uwtable
declare dso_local noundef i32 @_ZNSt13__atomic_baseIiE9fetch_subEiSt12memory_order(ptr noundef nonnull align 4 dereferenceable(4), i32 noundef, i32 noundef) local_unnamed_addr #2 align 2

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN4enki13TaskScheduler22WakeThreadsForNewTasksEv(ptr noundef nonnull align 8 dereferenceable(220)) local_unnamed_addr #3 align 2

; Function Attrs: mustprogress nounwind uwtable
declare hidden { ptr, i64 } @_ZN12_GLOBAL__N_19SplitTaskERN4enki10SubTaskSetEj(ptr noundef nonnull align 8 dereferenceable(16), i32 noundef) local_unnamed_addr #4

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN4enki13TaskScheduler15SplitAndAddTaskEjNS_10SubTaskSetEj(ptr noundef nonnull align 8 dereferenceable(220) %0, i32 noundef %1, ptr %2, i64 %3, i32 noundef %4) local_unnamed_addr #3 align 2 {
  %6 = alloca %"struct.enki::SubTaskSet", align 8
  %7 = alloca %"struct.enki::SubTaskSet", align 8
  store ptr %2, ptr %6, align 8
  %8 = getelementptr inbounds i8, ptr %6, i64 8
  store i64 %3, ptr %8, align 8
  %9 = getelementptr inbounds i8, ptr %6, i64 12
  %10 = lshr i64 %3, 32
  %11 = trunc nuw i64 %10 to i32
  %12 = trunc i64 %3 to i32
  %13 = sub i32 %11, %12
  %14 = udiv i32 %13, %4
  %15 = add nsw i32 %14, 2
  %16 = getelementptr inbounds i8, ptr %2, i64 12
  %17 = tail call noundef i32 @_ZNSt13__atomic_baseIiE9fetch_addEiSt12memory_order(ptr noundef nonnull align 4 dereferenceable(4) %16, i32 noundef %15, i32 noundef 2) #6
  %.not23 = icmp eq i32 %12, %11
  br i1 %.not23, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %5
  %18 = getelementptr inbounds i8, ptr %7, i64 8
  %19 = zext i32 %1 to i64
  %20 = getelementptr inbounds i8, ptr %7, i64 12
  br label %21

21:                                               ; preds = %.lr.ph, %56
  %.025 = phi i32 [ 0, %.lr.ph ], [ %.1, %56 ]
  %.01624 = phi i32 [ 0, %.lr.ph ], [ %.117, %56 ]
  call void @llvm.lifetime.start.p0(i64 16, ptr nonnull %7) #6
  %22 = call { ptr, i64 } @_ZN12_GLOBAL__N_19SplitTaskERN4enki10SubTaskSetEj(ptr noundef nonnull align 8 dereferenceable(16) %6, i32 noundef %4)
  %23 = extractvalue { ptr, i64 } %22, 0
  store ptr %23, ptr %7, align 8
  %24 = extractvalue { ptr, i64 } %22, 1
  store i64 %24, ptr %18, align 8
  %25 = add nsw i32 %.025, 1
  %26 = add nsw i32 %.01624, 1
  %27 = load ptr, ptr %6, align 8, !tbaa !5
  %28 = getelementptr inbounds i8, ptr %27, i64 8
  %29 = load i32, ptr %28, align 8, !tbaa !12
  %30 = zext i32 %29 to i64
  %31 = getelementptr inbounds [3 x ptr], ptr %0, i64 0, i64 %30
  %32 = load ptr, ptr %31, align 8, !tbaa !17
  %33 = getelementptr inbounds %"class.enki::TaskPipe", ptr %32, i64 %19
  %34 = call noundef zeroext i1 @_ZN4enki21LockLessMultiReadPipeILh8ENS_10SubTaskSetEE19WriterTryWriteFrontERKS1_(ptr noundef nonnull align 8 dereferenceable(5132) %33, ptr noundef nonnull align 8 dereferenceable(16) %7)
  br i1 %34, label %56, label %35

35:                                               ; preds = %21
  %36 = icmp sgt i32 %.01624, 0
  br i1 %36, label %37, label %38

37:                                               ; preds = %35
  call void @_ZN4enki13TaskScheduler22WakeThreadsForNewTasksEv(ptr noundef nonnull align 8 dereferenceable(220) %0)
  br label %38

38:                                               ; preds = %37, %35
  %39 = load ptr, ptr %7, align 8, !tbaa !5
  %40 = getelementptr inbounds i8, ptr %39, i64 48
  %41 = load i32, ptr %40, align 8, !tbaa !18
  %42 = load i32, ptr %20, align 4, !tbaa !20
  %43 = load i32, ptr %18, align 8, !tbaa !21
  %44 = sub i32 %42, %43
  %45 = icmp ult i32 %41, %44
  br i1 %45, label %46, label %52

46:                                               ; preds = %38
  %47 = add i32 %43, %41
  store i32 %47, ptr %20, align 4, !tbaa !20
  %48 = getelementptr inbounds i8, ptr %39, i64 40
  %49 = load i32, ptr %48, align 8, !tbaa !22
  %.not21 = icmp ugt i32 %47, %49
  br i1 %.not21, label %50, label %51

50:                                               ; preds = %46
  call void @__assert_fail(ptr noundef nonnull @.str.12, ptr noundef nonnull @.str.3, i32 noundef 838, ptr noundef nonnull @__PRETTY_FUNCTION__._ZN4enki13TaskScheduler15SplitAndAddTaskEjNS_10SubTaskSetEj) #7
  unreachable

51:                                               ; preds = %46
  store i32 %47, ptr %8, align 8, !tbaa !21
  br label %52

52:                                               ; preds = %51, %38
  %.sroa.0.0.copyload = load i64, ptr %18, align 8
  %53 = load ptr, ptr %39, align 8, !tbaa !23
  %54 = getelementptr inbounds i8, ptr %53, i64 24
  %55 = load ptr, ptr %54, align 8
  call void %55(ptr noundef nonnull align 8 dereferenceable(52) %39, i64 %.sroa.0.0.copyload, i32 noundef %1)
  br label %56

56:                                               ; preds = %52, %21
  %.117 = phi i32 [ %26, %21 ], [ 0, %52 ]
  %.1 = phi i32 [ %25, %21 ], [ %.025, %52 ]
  call void @llvm.lifetime.end.p0(i64 16, ptr nonnull %7) #6
  %57 = load i32, ptr %8, align 8, !tbaa !21
  %58 = load i32, ptr %9, align 4, !tbaa !20
  %.not = icmp eq i32 %57, %58
  br i1 %.not, label %._crit_edge, label %21, !llvm.loop !25

._crit_edge:                                      ; preds = %56, %5
  %.0.lcssa = phi i32 [ 0, %5 ], [ %.1, %56 ]
  %59 = sub nsw i32 %15, %.0.lcssa
  %60 = icmp sgt i32 %59, 0
  br i1 %60, label %62, label %61

61:                                               ; preds = %._crit_edge
  call void @__assert_fail(ptr noundef nonnull @.str.13, ptr noundef nonnull @.str.3, i32 noundef 845, ptr noundef nonnull @__PRETTY_FUNCTION__._ZN4enki13TaskScheduler15SplitAndAddTaskEjNS_10SubTaskSetEj) #7
  unreachable

62:                                               ; preds = %._crit_edge
  %63 = load ptr, ptr %6, align 8, !tbaa !5
  %64 = getelementptr inbounds i8, ptr %63, i64 12
  %65 = call noundef i32 @_ZNSt13__atomic_baseIiE9fetch_subEiSt12memory_order(ptr noundef nonnull align 4 dereferenceable(4) %64, i32 noundef %59, i32 noundef 4) #6
  %66 = add nuw nsw i32 %59, 1
  %67 = icmp eq i32 %66, %65
  br i1 %67, label %68, label %70

68:                                               ; preds = %62
  %69 = load ptr, ptr %6, align 8, !tbaa !5
  call void @_ZN4enki13TaskScheduler12TaskCompleteEPNS_12ICompletableEbj(ptr noundef nonnull align 8 dereferenceable(220) %0, ptr noundef %69, i1 noundef zeroext false, i32 noundef %1)
  br label %70

70:                                               ; preds = %68, %62
  call void @_ZN4enki13TaskScheduler22WakeThreadsForNewTasksEv(ptr noundef nonnull align 8 dereferenceable(220) %0)
  ret void
}

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN4enki13TaskScheduler12TaskCompleteEPNS_12ICompletableEbj(ptr noundef nonnull align 8 dereferenceable(220), ptr noundef, i1 noundef zeroext, i32 noundef) local_unnamed_addr #3 align 2

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

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef zeroext i1 @_ZN4enki21LockLessMultiReadPipeILh8ENS_10SubTaskSetEE19WriterTryWriteFrontERKS1_(ptr noundef nonnull align 8 dereferenceable(5132), ptr noundef nonnull align 8 dereferenceable(16)) local_unnamed_addr #5 align 2

attributes #0 = { noreturn 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 #1 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { alwaysinline 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 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 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 #5 = { 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 #6 = { nounwind }
attributes #7 = { noreturn 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 = !{!"_ZTSN4enki10SubTaskSetE", !7, i64 0, !10, i64 8}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}
!10 = !{!"_ZTSN4enki16TaskSetPartitionE", !11, i64 0, !11, i64 4}
!11 = !{!"int", !8, i64 0}
!12 = !{!13, !14, i64 8}
!13 = !{!"_ZTSN4enki12ICompletableE", !14, i64 8, !15, i64 12, !15, i64 16, !11, i64 20, !15, i64 24, !7, i64 32}
!14 = !{!"_ZTSN4enki12TaskPriorityE", !8, i64 0}
!15 = !{!"_ZTSSt6atomicIiE", !16, i64 0}
!16 = !{!"_ZTSSt13__atomic_baseIiE", !11, i64 0}
!17 = !{!7, !7, i64 0}
!18 = !{!19, !11, i64 48}
!19 = !{!"_ZTSN4enki8ITaskSetE", !13, i64 0, !11, i64 40, !11, i64 44, !11, i64 48}
!20 = !{!6, !11, i64 12}
!21 = !{!6, !11, i64 8}
!22 = !{!19, !11, i64 40}
!23 = !{!24, !24, i64 0}
!24 = !{!"vtable pointer", !9, i64 0}
!25 = distinct !{!25, !26}
!26 = !{!"llvm.loop.mustprogress"}


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