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

; 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.enkiCustomAllocator = type { ptr, ptr, ptr }
%"struct.enki::CustomAllocator" = type { ptr, ptr, ptr }

@_ZN12_GLOBAL__N_17gc_FileE = external hidden global ptr, align 8

; 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: inlinehint mustprogress nounwind uwtable
declare dso_local void @_ZN4enki15CustomAllocatorC2Ev(ptr noundef nonnull align 8 dereferenceable(24)) unnamed_addr #1 align 2

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

; Function Attrs: mustprogress uwtable
define dso_local ptr @enkiNewTaskSchedulerWithCustomAllocator(ptr noundef byval(%struct.enkiCustomAllocator) align 8 %0) #3 {
  %2 = alloca ptr, align 8
  %3 = alloca %"struct.enki::CustomAllocator", align 8
  %4 = alloca %"struct.enki::CustomAllocator", align 8
  call void @llvm.lifetime.start.p0(i64 8, ptr %2) #5
  %5 = getelementptr inbounds %struct.enkiCustomAllocator, ptr %0, i32 0, i32 0
  %6 = load ptr, ptr %5, align 8, !tbaa !5
  %7 = getelementptr inbounds %struct.enkiCustomAllocator, ptr %0, i32 0, i32 2
  %8 = load ptr, ptr %7, align 8, !tbaa !10
  %9 = load ptr, ptr @_ZN12_GLOBAL__N_17gc_FileE, align 8, !tbaa !11
  %10 = call noundef ptr %6(i64 noundef 8, i64 noundef 224, ptr noundef %8, ptr noundef %9, i32 noundef 0)
  store ptr %10, ptr %2, align 8, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 24, ptr %3) #5
  call void @_ZN4enki15CustomAllocatorC2Ev(ptr noundef nonnull align 8 dereferenceable(24) %3) #5
  %11 = getelementptr inbounds %struct.enkiCustomAllocator, ptr %0, i32 0, i32 0
  %12 = load ptr, ptr %11, align 8, !tbaa !5
  %13 = getelementptr inbounds %"struct.enki::CustomAllocator", ptr %3, i32 0, i32 0
  store ptr %12, ptr %13, align 8, !tbaa !12
  %14 = getelementptr inbounds %struct.enkiCustomAllocator, ptr %0, i32 0, i32 1
  %15 = load ptr, ptr %14, align 8, !tbaa !14
  %16 = getelementptr inbounds %"struct.enki::CustomAllocator", ptr %3, i32 0, i32 1
  store ptr %15, ptr %16, align 8, !tbaa !15
  %17 = getelementptr inbounds %struct.enkiCustomAllocator, ptr %0, i32 0, i32 2
  %18 = load ptr, ptr %17, align 8, !tbaa !10
  %19 = getelementptr inbounds %"struct.enki::CustomAllocator", ptr %3, i32 0, i32 2
  store ptr %18, ptr %19, align 8, !tbaa !16
  %20 = load ptr, ptr %2, align 8, !tbaa !11
  call void @_ZN17enkiTaskSchedulerC2Ev(ptr noundef nonnull align 8 dereferenceable(220) %20)
  %21 = load ptr, ptr %2, align 8, !tbaa !11
  call void @llvm.memcpy.p0.p0.i64(ptr align 8 %4, ptr align 8 %3, i64 24, i1 false), !tbaa.struct !17
  call void @_ZN17enkiTaskScheduler22enkiSetCustomAllocatorEN4enki15CustomAllocatorE(ptr noundef nonnull align 8 dereferenceable(220) %21, ptr noundef byval(%"struct.enki::CustomAllocator") align 8 %4)
  %22 = load ptr, ptr %2, align 8, !tbaa !11
  call void @llvm.lifetime.end.p0(i64 24, ptr %3) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %2) #5
  ret ptr %22
}

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN17enkiTaskScheduler22enkiSetCustomAllocatorEN4enki15CustomAllocatorE(ptr noundef nonnull align 8 dereferenceable(220), ptr noundef byval(%"struct.enki::CustomAllocator") align 8) #3 align 2

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

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


; 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.enkiCustomAllocator = type { ptr, ptr, ptr }
%"struct.enki::CustomAllocator" = type { ptr, ptr, ptr }

@_ZN12_GLOBAL__N_17gc_FileE = external hidden local_unnamed_addr global ptr, align 8

; 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: inlinehint mustprogress nounwind uwtable
declare dso_local void @_ZN4enki15CustomAllocatorC2Ev(ptr noundef nonnull align 8 dereferenceable(24)) unnamed_addr #1 align 2

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

; Function Attrs: mustprogress uwtable
define dso_local noundef ptr @enkiNewTaskSchedulerWithCustomAllocator(ptr nocapture noundef readonly byval(%struct.enkiCustomAllocator) align 8 %0) local_unnamed_addr #3 {
  %2 = alloca %"struct.enki::CustomAllocator", align 8
  %3 = load ptr, ptr %0, align 8, !tbaa !5
  %4 = getelementptr inbounds i8, ptr %0, i64 16
  %5 = load ptr, ptr %4, align 8, !tbaa !10
  %6 = load ptr, ptr @_ZN12_GLOBAL__N_17gc_FileE, align 8, !tbaa !11
  %7 = tail call noundef ptr %3(i64 noundef 8, i64 noundef 224, ptr noundef %5, ptr noundef %6, i32 noundef 0)
  call void @llvm.lifetime.start.p0(i64 24, ptr nonnull %2) #4
  call void @_ZN4enki15CustomAllocatorC2Ev(ptr noundef nonnull align 8 dereferenceable(24) %2) #4
  store ptr %3, ptr %2, align 8, !tbaa !12
  %8 = getelementptr inbounds i8, ptr %0, i64 8
  %9 = load ptr, ptr %8, align 8, !tbaa !14
  %10 = getelementptr inbounds i8, ptr %2, i64 8
  store ptr %9, ptr %10, align 8, !tbaa !15
  %11 = getelementptr inbounds i8, ptr %2, i64 16
  store ptr %5, ptr %11, align 8, !tbaa !16
  call void @_ZN17enkiTaskSchedulerC2Ev(ptr noundef nonnull align 8 dereferenceable(220) %7)
  call void @_ZN17enkiTaskScheduler22enkiSetCustomAllocatorEN4enki15CustomAllocatorE(ptr noundef nonnull align 8 dereferenceable(220) %7, ptr noundef nonnull byval(%"struct.enki::CustomAllocator") align 8 %2)
  call void @llvm.lifetime.end.p0(i64 24, ptr nonnull %2) #4
  ret ptr %7
}

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN17enkiTaskScheduler22enkiSetCustomAllocatorEN4enki15CustomAllocatorE(ptr noundef nonnull align 8 dereferenceable(220), ptr noundef byval(%"struct.enki::CustomAllocator") align 8) local_unnamed_addr #3 align 2

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


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