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

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

@.str.3 = external hidden unnamed_addr constant [90 x i8], align 1
@.str.21 = external hidden unnamed_addr constant [33 x i8], align 1
@.str.22 = external hidden unnamed_addr constant [40 x i8], align 1
@.str.28 = external hidden unnamed_addr constant [23 x i8], align 1
@__PRETTY_FUNCTION__._ZN4enki10Dependency15ClearDependencyEv = external hidden unnamed_addr constant [41 x i8], align 1
@.str.29 = external hidden unnamed_addr constant [48 x i8], align 1

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef zeroext i1 @_ZNK4enki12ICompletable13GetIsCompleteEv(ptr noundef nonnull align 8 dereferenceable(40)) #0 align 2

; Function Attrs: noreturn nounwind
declare void @__assert_fail(ptr noundef, ptr noundef, i32 noundef, ptr noundef) #1

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

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

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN4enki10Dependency15ClearDependencyEv(ptr noundef nonnull align 8 dereferenceable(24) %0) #3 align 2 {
  %2 = alloca ptr, align 8
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca i32, align 4
  store ptr %0, ptr %2, align 8, !tbaa !5
  %6 = load ptr, ptr %2, align 8
  %7 = getelementptr inbounds %"class.enki::Dependency", ptr %6, i32 0, i32 1
  %8 = load ptr, ptr %7, align 8, !tbaa !9
  %9 = icmp ne ptr %8, null
  br i1 %9, label %10, label %82

10:                                               ; preds = %1
  %11 = getelementptr inbounds %"class.enki::Dependency", ptr %6, i32 0, i32 0
  %12 = load ptr, ptr %11, align 8, !tbaa !11
  %13 = icmp ne ptr %12, null
  br i1 %13, label %14, label %15

14:                                               ; preds = %10
  br label %17

15:                                               ; preds = %10
  call void @__assert_fail(ptr noundef @.str.28, ptr noundef @.str.3, i32 noundef 1510, ptr noundef @__PRETTY_FUNCTION__._ZN4enki10Dependency15ClearDependencyEv) #4
  unreachable

16:                                               ; No predecessors!
  br label %17

17:                                               ; preds = %16, %14
  %18 = getelementptr inbounds %"class.enki::Dependency", ptr %6, i32 0, i32 1
  %19 = load ptr, ptr %18, align 8, !tbaa !9
  %20 = call noundef zeroext i1 @_ZNK4enki12ICompletable13GetIsCompleteEv(ptr noundef nonnull align 8 dereferenceable(40) %19)
  br i1 %20, label %21, label %22

21:                                               ; preds = %17
  br label %24

22:                                               ; preds = %17
  call void @__assert_fail(ptr noundef @.str.21, ptr noundef @.str.3, i32 noundef 1511, ptr noundef @__PRETTY_FUNCTION__._ZN4enki10Dependency15ClearDependencyEv) #4
  unreachable

23:                                               ; No predecessors!
  br label %24

24:                                               ; preds = %23, %21
  %25 = getelementptr inbounds %"class.enki::Dependency", ptr %6, i32 0, i32 0
  %26 = load ptr, ptr %25, align 8, !tbaa !11
  %27 = call noundef zeroext i1 @_ZNK4enki12ICompletable13GetIsCompleteEv(ptr noundef nonnull align 8 dereferenceable(40) %26)
  br i1 %27, label %28, label %29

28:                                               ; preds = %24
  br label %31

29:                                               ; preds = %24
  call void @__assert_fail(ptr noundef @.str.22, ptr noundef @.str.3, i32 noundef 1512, ptr noundef @__PRETTY_FUNCTION__._ZN4enki10Dependency15ClearDependencyEv) #4
  unreachable

30:                                               ; No predecessors!
  br label %31

31:                                               ; preds = %30, %28
  %32 = getelementptr inbounds %"class.enki::Dependency", ptr %6, i32 0, i32 0
  %33 = load ptr, ptr %32, align 8, !tbaa !11
  %34 = getelementptr inbounds %"class.enki::ICompletable", ptr %33, i32 0, i32 4
  %35 = load i32, ptr %34, align 4, !tbaa !12
  %36 = icmp sgt i32 %35, 0
  br i1 %36, label %37, label %38

37:                                               ; preds = %31
  br label %40

38:                                               ; preds = %31
  call void @__assert_fail(ptr noundef @.str.29, ptr noundef @.str.3, i32 noundef 1513, ptr noundef @__PRETTY_FUNCTION__._ZN4enki10Dependency15ClearDependencyEv) #4
  unreachable

39:                                               ; No predecessors!
  br label %40

40:                                               ; preds = %39, %37
  call void @llvm.lifetime.start.p0(i64 8, ptr %3) #5
  %41 = getelementptr inbounds %"class.enki::Dependency", ptr %6, i32 0, i32 1
  %42 = load ptr, ptr %41, align 8, !tbaa !9
  %43 = getelementptr inbounds %"class.enki::ICompletable", ptr %42, i32 0, i32 6
  %44 = load ptr, ptr %43, align 8, !tbaa !18
  store ptr %44, ptr %3, align 8, !tbaa !5
  %45 = getelementptr inbounds %"class.enki::Dependency", ptr %6, i32 0, i32 0
  %46 = load ptr, ptr %45, align 8, !tbaa !11
  %47 = getelementptr inbounds %"class.enki::ICompletable", ptr %46, i32 0, i32 4
  %48 = load i32, ptr %47, align 4, !tbaa !12
  %49 = add nsw i32 %48, -1
  store i32 %49, ptr %47, align 4, !tbaa !12
  %50 = load ptr, ptr %3, align 8, !tbaa !5
  %51 = icmp eq ptr %6, %50
  br i1 %51, label %52, label %59

52:                                               ; preds = %40
  %53 = load ptr, ptr %3, align 8, !tbaa !5
  %54 = getelementptr inbounds %"class.enki::Dependency", ptr %53, i32 0, i32 2
  %55 = load ptr, ptr %54, align 8, !tbaa !19
  %56 = getelementptr inbounds %"class.enki::Dependency", ptr %6, i32 0, i32 1
  %57 = load ptr, ptr %56, align 8, !tbaa !9
  %58 = getelementptr inbounds %"class.enki::ICompletable", ptr %57, i32 0, i32 6
  store ptr %55, ptr %58, align 8, !tbaa !18
  br label %81

59:                                               ; preds = %40
  br label %60

60:                                               ; preds = %79, %59
  %61 = load ptr, ptr %3, align 8, !tbaa !5
  %62 = icmp ne ptr %61, null
  br i1 %62, label %63, label %80

63:                                               ; preds = %60
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #5
  %64 = load ptr, ptr %3, align 8, !tbaa !5
  store ptr %64, ptr %4, align 8, !tbaa !5
  %65 = load ptr, ptr %3, align 8, !tbaa !5
  %66 = getelementptr inbounds %"class.enki::Dependency", ptr %65, i32 0, i32 2
  %67 = load ptr, ptr %66, align 8, !tbaa !19
  store ptr %67, ptr %3, align 8, !tbaa !5
  %68 = load ptr, ptr %3, align 8, !tbaa !5
  %69 = icmp eq ptr %6, %68
  br i1 %69, label %70, label %76

70:                                               ; preds = %63
  %71 = load ptr, ptr %3, align 8, !tbaa !5
  %72 = getelementptr inbounds %"class.enki::Dependency", ptr %71, i32 0, i32 2
  %73 = load ptr, ptr %72, align 8, !tbaa !19
  %74 = load ptr, ptr %4, align 8, !tbaa !5
  %75 = getelementptr inbounds %"class.enki::Dependency", ptr %74, i32 0, i32 2
  store ptr %73, ptr %75, align 8, !tbaa !19
  store i32 3, ptr %5, align 4
  br label %77

76:                                               ; preds = %63
  store i32 0, ptr %5, align 4
  br label %77

77:                                               ; preds = %76, %70
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #5
  %78 = load i32, ptr %5, align 4
  switch i32 %78, label %86 [
    i32 0, label %79
    i32 3, label %80
  ]

79:                                               ; preds = %77
  br label %60, !llvm.loop !20

80:                                               ; preds = %77, %60
  br label %81

81:                                               ; preds = %80, %52
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #5
  br label %82

82:                                               ; preds = %81, %1
  %83 = getelementptr inbounds %"class.enki::Dependency", ptr %6, i32 0, i32 1
  store ptr null, ptr %83, align 8, !tbaa !9
  %84 = getelementptr inbounds %"class.enki::Dependency", ptr %6, i32 0, i32 1
  store ptr null, ptr %84, align 8, !tbaa !9
  %85 = getelementptr inbounds %"class.enki::Dependency", ptr %6, i32 0, i32 2
  store ptr null, ptr %85, align 8, !tbaa !19
  ret void

86:                                               ; preds = %77
  unreachable
}

attributes #0 = { 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 #1 = { 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 #2 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = { noreturn nounwind }
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, !6, i64 8}
!10 = !{!"_ZTSN4enki10DependencyE", !6, i64 0, !6, i64 8, !6, i64 16}
!11 = !{!10, !6, i64 0}
!12 = !{!13, !17, i64 20}
!13 = !{!"_ZTSN4enki12ICompletableE", !14, i64 8, !15, i64 12, !15, i64 16, !17, i64 20, !15, i64 24, !6, i64 32}
!14 = !{!"_ZTSN4enki12TaskPriorityE", !7, i64 0}
!15 = !{!"_ZTSSt6atomicIiE", !16, i64 0}
!16 = !{!"_ZTSSt13__atomic_baseIiE", !17, i64 0}
!17 = !{!"int", !7, i64 0}
!18 = !{!13, !6, i64 32}
!19 = !{!10, !6, i64 16}
!20 = distinct !{!20, !21}
!21 = !{!"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"

@.str.3 = external hidden unnamed_addr constant [90 x i8], align 1
@.str.21 = external hidden unnamed_addr constant [33 x i8], align 1
@.str.22 = external hidden unnamed_addr constant [40 x i8], align 1
@.str.28 = external hidden unnamed_addr constant [23 x i8], align 1
@__PRETTY_FUNCTION__._ZN4enki10Dependency15ClearDependencyEv = external hidden unnamed_addr constant [41 x i8], align 1
@.str.29 = external hidden unnamed_addr constant [48 x i8], align 1

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef zeroext i1 @_ZNK4enki12ICompletable13GetIsCompleteEv(ptr noundef nonnull align 8 dereferenceable(40)) local_unnamed_addr #0 align 2

; Function Attrs: noreturn nounwind
declare void @__assert_fail(ptr noundef, ptr noundef, i32 noundef, ptr noundef) local_unnamed_addr #1

; Function Attrs: mustprogress nounwind uwtable
define dso_local void @_ZN4enki10Dependency15ClearDependencyEv(ptr noundef nonnull align 8 dereferenceable(24) %0) local_unnamed_addr #0 align 2 {
  %2 = getelementptr inbounds i8, ptr %0, i64 8
  %3 = load ptr, ptr %2, align 8, !tbaa !5
  %.not = icmp eq ptr %3, null
  br i1 %.not, label %.loopexit, label %4

4:                                                ; preds = %1
  %5 = load ptr, ptr %0, align 8, !tbaa !10
  %.not14 = icmp eq ptr %5, null
  br i1 %.not14, label %6, label %7

6:                                                ; preds = %4
  tail call void @__assert_fail(ptr noundef nonnull @.str.28, ptr noundef nonnull @.str.3, i32 noundef 1510, ptr noundef nonnull @__PRETTY_FUNCTION__._ZN4enki10Dependency15ClearDependencyEv) #3
  unreachable

7:                                                ; preds = %4
  %8 = tail call noundef zeroext i1 @_ZNK4enki12ICompletable13GetIsCompleteEv(ptr noundef nonnull align 8 dereferenceable(40) %3)
  br i1 %8, label %10, label %9

9:                                                ; preds = %7
  tail call void @__assert_fail(ptr noundef nonnull @.str.21, ptr noundef nonnull @.str.3, i32 noundef 1511, ptr noundef nonnull @__PRETTY_FUNCTION__._ZN4enki10Dependency15ClearDependencyEv) #3
  unreachable

10:                                               ; preds = %7
  %11 = load ptr, ptr %0, align 8, !tbaa !10
  %12 = tail call noundef zeroext i1 @_ZNK4enki12ICompletable13GetIsCompleteEv(ptr noundef nonnull align 8 dereferenceable(40) %11)
  br i1 %12, label %14, label %13

13:                                               ; preds = %10
  tail call void @__assert_fail(ptr noundef nonnull @.str.22, ptr noundef nonnull @.str.3, i32 noundef 1512, ptr noundef nonnull @__PRETTY_FUNCTION__._ZN4enki10Dependency15ClearDependencyEv) #3
  unreachable

14:                                               ; preds = %10
  %15 = load ptr, ptr %0, align 8, !tbaa !10
  %16 = getelementptr inbounds i8, ptr %15, i64 20
  %17 = load i32, ptr %16, align 4, !tbaa !11
  %18 = icmp sgt i32 %17, 0
  br i1 %18, label %20, label %19

19:                                               ; preds = %14
  tail call void @__assert_fail(ptr noundef nonnull @.str.29, ptr noundef nonnull @.str.3, i32 noundef 1513, ptr noundef nonnull @__PRETTY_FUNCTION__._ZN4enki10Dependency15ClearDependencyEv) #3
  unreachable

20:                                               ; preds = %14
  %21 = load ptr, ptr %2, align 8, !tbaa !5
  %22 = getelementptr inbounds i8, ptr %21, i64 32
  %23 = load ptr, ptr %22, align 8, !tbaa !17
  %24 = add nsw i32 %17, -1
  store i32 %24, ptr %16, align 4, !tbaa !11
  %25 = icmp eq ptr %23, %0
  br i1 %25, label %.loopexit.sink.split, label %.preheader

.preheader:                                       ; preds = %20, %26
  %.09 = phi ptr [ %28, %26 ], [ %23, %20 ]
  %.not15 = icmp eq ptr %.09, null
  br i1 %.not15, label %.loopexit, label %26

26:                                               ; preds = %.preheader
  %27 = getelementptr inbounds i8, ptr %.09, i64 16
  %28 = load ptr, ptr %27, align 8, !tbaa !18
  %29 = icmp eq ptr %28, %0
  br i1 %29, label %.thread, label %.preheader

.thread:                                          ; preds = %26
  %30 = getelementptr inbounds i8, ptr %.09, i64 16
  br label %.loopexit.sink.split

.loopexit.sink.split:                             ; preds = %20, %.thread
  %.lcssa.sink = phi ptr [ %28, %.thread ], [ %23, %20 ]
  %.sink21 = phi ptr [ %30, %.thread ], [ %22, %20 ]
  %31 = getelementptr inbounds i8, ptr %.lcssa.sink, i64 16
  %32 = load ptr, ptr %31, align 8, !tbaa !18
  store ptr %32, ptr %.sink21, align 8, !tbaa !19
  br label %.loopexit

.loopexit:                                        ; preds = %.preheader, %.loopexit.sink.split, %1
  tail call void @llvm.memset.p0.i64(ptr noundef nonnull align 8 dereferenceable(16) %2, i8 0, i64 16, i1 false)
  ret void
}

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #2

attributes #0 = { 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 #1 = { 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 #2 = { nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #3 = { 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 8}
!6 = !{!"_ZTSN4enki10DependencyE", !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 0}
!11 = !{!12, !16, i64 20}
!12 = !{!"_ZTSN4enki12ICompletableE", !13, i64 8, !14, i64 12, !14, i64 16, !16, i64 20, !14, i64 24, !7, i64 32}
!13 = !{!"_ZTSN4enki12TaskPriorityE", !8, i64 0}
!14 = !{!"_ZTSSt6atomicIiE", !15, i64 0}
!15 = !{!"_ZTSSt13__atomic_baseIiE", !16, i64 0}
!16 = !{!"int", !8, i64 0}
!17 = !{!12, !7, i64 32}
!18 = !{!6, !7, i64 16}
!19 = !{!7, !7, i64 0}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GVNPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LICMPass,LoopSimplifyPass,LoopUnrollPass,MemCpyOptPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass