; LLVM IR from tyoma/agge :: src/agge/parallel.ll (ZN4agge8parallelC2Ej)

; 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.agge::parallel" = type { [8 x i8], %"class.agge::raw_memory_object", i32, [4 x i8] }
%"class.agge::raw_memory_object" = type <{ ptr, i32, [4 x i8] }>
%"struct.agge::parallel::thread" = type { [8 x i8], %"class.agge::hybrid_event", %"class.agge::hybrid_event", ptr, i32, %"class.agge::thread" }
%"class.agge::hybrid_event" = type { i64, ptr }
%"class.agge::thread" = type { ptr, ptr, ptr }

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

declare i32 @__gxx_personality_v0(...)

; Function Attrs: noinline noreturn nounwind uwtable
declare hidden void @__clang_call_terminate(ptr noundef) #1

declare ptr @__cxa_begin_catch(ptr)

; 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 @_ZN4agge8parallelC2Ej(ptr noundef nonnull align 8 dereferenceable(28) %0, i32 noundef %1) unnamed_addr #3 align 2 personality ptr @__gxx_personality_v0 {
  %3 = alloca ptr, align 8
  %4 = alloca i32, align 4
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  store ptr %0, ptr %3, align 8, !tbaa !5
  store i32 %1, ptr %4, align 4, !tbaa !9
  %9 = load ptr, ptr %3, align 8
  call void @_ZN4agge11noncopyableC2Ev(ptr noundef nonnull align 1 dereferenceable(1) %9) #6
  %10 = getelementptr inbounds %"class.agge::parallel", ptr %9, i32 0, i32 1
  call void @_ZN4agge17raw_memory_objectC2Ev(ptr noundef nonnull align 8 dereferenceable(12) %10) #6
  %11 = getelementptr inbounds %"class.agge::parallel", ptr %9, i32 0, i32 2
  store i32 0, ptr %11, align 8, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #6
  %12 = getelementptr inbounds %"class.agge::parallel", ptr %9, i32 0, i32 1
  %13 = load i32, ptr %4, align 4, !tbaa !9
  %14 = sub i32 %13, 1
  %15 = invoke noundef ptr @_ZN4agge17raw_memory_object3getINS_8parallel6threadEEEPT_j(ptr noundef nonnull align 8 dereferenceable(12) %12, i32 noundef %14)
          to label %16 unwind label %22

16:                                               ; preds = %2
  store ptr %15, ptr %5, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #6
  store i32 1, ptr %8, align 4, !tbaa !9
  br label %17

17:                                               ; preds = %30, %16
  %18 = load i32, ptr %8, align 4, !tbaa !9
  %19 = load i32, ptr %4, align 4, !tbaa !9
  %20 = icmp ne i32 %18, %19
  br i1 %20, label %26, label %21

21:                                               ; preds = %17
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #6
  br label %42

22:                                               ; preds = %2
  %23 = landingpad { ptr, i32 }
          catch ptr null
  %24 = extractvalue { ptr, i32 } %23, 0
  store ptr %24, ptr %6, align 8
  %25 = extractvalue { ptr, i32 } %23, 1
  store i32 %25, ptr %7, align 4
  br label %43

26:                                               ; preds = %17
  %27 = load ptr, ptr %5, align 8, !tbaa !5
  %28 = load i32, ptr %8, align 4, !tbaa !9
  invoke void @_ZN4agge8parallel6threadC1Ej(ptr noundef nonnull align 8 dereferenceable(80) %27, i32 noundef %28)
          to label %29 unwind label %38

29:                                               ; preds = %26
  br label %30

30:                                               ; preds = %29
  %31 = load i32, ptr %8, align 4, !tbaa !9
  %32 = add i32 %31, 1
  store i32 %32, ptr %8, align 4, !tbaa !9
  %33 = getelementptr inbounds %"class.agge::parallel", ptr %9, i32 0, i32 2
  %34 = load i32, ptr %33, align 8, !tbaa !11
  %35 = add i32 %34, 1
  store i32 %35, ptr %33, align 8, !tbaa !11
  %36 = load ptr, ptr %5, align 8, !tbaa !5
  %37 = getelementptr inbounds %"struct.agge::parallel::thread", ptr %36, i32 1
  store ptr %37, ptr %5, align 8, !tbaa !5
  br label %17, !llvm.loop !14

38:                                               ; preds = %26
  %39 = landingpad { ptr, i32 }
          catch ptr null
  %40 = extractvalue { ptr, i32 } %39, 0
  store ptr %40, ptr %6, align 8
  %41 = extractvalue { ptr, i32 } %39, 1
  store i32 %41, ptr %7, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #6
  br label %43

42:                                               ; preds = %21
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #6
  br label %52

43:                                               ; preds = %38, %22
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #6
  br label %44

44:                                               ; preds = %43
  %45 = load ptr, ptr %6, align 8
  %46 = call ptr @__cxa_begin_catch(ptr %45) #6
  call void @_ZN4agge8parallel15destroy_threadsEv(ptr noundef nonnull align 8 dereferenceable(28) %9) #6
  invoke void @__cxa_rethrow() #7
          to label %61 unwind label %47

47:                                               ; preds = %44
  %48 = landingpad { ptr, i32 }
          cleanup
  %49 = extractvalue { ptr, i32 } %48, 0
  store ptr %49, ptr %6, align 8
  %50 = extractvalue { ptr, i32 } %48, 1
  store i32 %50, ptr %7, align 4
  invoke void @__cxa_end_catch()
          to label %51 unwind label %58

51:                                               ; preds = %47
  call void @_ZN4agge17raw_memory_objectD2Ev(ptr noundef nonnull align 8 dereferenceable(12) %10) #6
  br label %53

52:                                               ; preds = %42
  ret void

53:                                               ; preds = %51
  %54 = load ptr, ptr %6, align 8
  %55 = load i32, ptr %7, align 4
  %56 = insertvalue { ptr, i32 } poison, ptr %54, 0
  %57 = insertvalue { ptr, i32 } %56, i32 %55, 1
  resume { ptr, i32 } %57

58:                                               ; preds = %47
  %59 = landingpad { ptr, i32 }
          catch ptr null
  %60 = extractvalue { ptr, i32 } %59, 0
  call void @__clang_call_terminate(ptr %60) #8
  unreachable

61:                                               ; preds = %44
  unreachable
}

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

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local noundef ptr @_ZN4agge17raw_memory_object3getINS_8parallel6threadEEEPT_j(ptr noundef nonnull align 8 dereferenceable(12), i32 noundef) #5 align 2

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

declare void @__cxa_rethrow()

declare void @__cxa_end_catch()

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

declare void @_ZN4agge8parallel6threadC1Ej(ptr, i32)

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 = { noinline noreturn nounwind uwtable "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 = { 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 #5 = { 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 #6 = { nounwind }
attributes #7 = { noreturn }
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 24}
!12 = !{!"_ZTSN4agge8parallelE", !13, i64 8, !10, i64 24}
!13 = !{!"_ZTSN4agge17raw_memory_objectE", !6, i64 0, !10, i64 8}
!14 = distinct !{!14, !15}
!15 = !{!"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"

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

declare i32 @__gxx_personality_v0(...)

; Function Attrs: noinline noreturn nounwind uwtable
declare hidden void @__clang_call_terminate(ptr noundef) local_unnamed_addr #1

declare ptr @__cxa_begin_catch(ptr) local_unnamed_addr

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN4agge8parallelC2Ej(ptr noundef nonnull align 8 dereferenceable(28) %0, i32 noundef %1) unnamed_addr #2 align 2 personality ptr @__gxx_personality_v0 {
  tail call void @_ZN4agge11noncopyableC2Ev(ptr noundef nonnull align 1 dereferenceable(1) %0) #5
  %3 = getelementptr inbounds i8, ptr %0, i64 8
  tail call void @_ZN4agge17raw_memory_objectC2Ev(ptr noundef nonnull align 8 dereferenceable(12) %3) #5
  %4 = getelementptr inbounds i8, ptr %0, i64 24
  store i32 0, ptr %4, align 8, !tbaa !5
  %5 = add i32 %1, -1
  %6 = invoke noundef ptr @_ZN4agge17raw_memory_object3getINS_8parallel6threadEEEPT_j(ptr noundef nonnull align 8 dereferenceable(12) %3, i32 noundef %5)
          to label %.preheader unwind label %7

.preheader:                                       ; preds = %2
  %.not12 = icmp eq i32 %1, 1
  br i1 %.not12, label %._crit_edge, label %.lr.ph

._crit_edge:                                      ; preds = %9, %.preheader
  ret void

7:                                                ; preds = %2
  %8 = landingpad { ptr, i32 }
          catch ptr null
  br label %16

.lr.ph:                                           ; preds = %.preheader, %9
  %.014 = phi i32 [ %10, %9 ], [ 1, %.preheader ]
  %.01113 = phi ptr [ %13, %9 ], [ %6, %.preheader ]
  invoke void @_ZN4agge8parallel6threadC1Ej(ptr noundef nonnull align 8 dereferenceable(80) %.01113, i32 noundef %.014)
          to label %9 unwind label %14

9:                                                ; preds = %.lr.ph
  %10 = add i32 %.014, 1
  %11 = load i32, ptr %4, align 8, !tbaa !5
  %12 = add i32 %11, 1
  store i32 %12, ptr %4, align 8, !tbaa !5
  %13 = getelementptr inbounds i8, ptr %.01113, i64 80
  %.not = icmp eq i32 %10, %1
  br i1 %.not, label %._crit_edge, label %.lr.ph, !llvm.loop !12

14:                                               ; preds = %.lr.ph
  %15 = landingpad { ptr, i32 }
          catch ptr null
  br label %16

16:                                               ; preds = %14, %7
  %.pn = phi { ptr, i32 } [ %15, %14 ], [ %8, %7 ]
  %.010 = extractvalue { ptr, i32 } %.pn, 0
  %17 = tail call ptr @__cxa_begin_catch(ptr %.010) #5
  tail call void @_ZN4agge8parallel15destroy_threadsEv(ptr noundef nonnull align 8 dereferenceable(28) %0) #5
  invoke void @__cxa_rethrow() #6
          to label %24 unwind label %18

18:                                               ; preds = %16
  %19 = landingpad { ptr, i32 }
          cleanup
  invoke void @__cxa_end_catch()
          to label %20 unwind label %21

20:                                               ; preds = %18
  tail call void @_ZN4agge17raw_memory_objectD2Ev(ptr noundef nonnull align 8 dereferenceable(12) %3) #5
  resume { ptr, i32 } %19

21:                                               ; preds = %18
  %22 = landingpad { ptr, i32 }
          catch ptr null
  %23 = extractvalue { ptr, i32 } %22, 0
  tail call void @__clang_call_terminate(ptr %23) #7
  unreachable

24:                                               ; preds = %16
  unreachable
}

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

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local noundef ptr @_ZN4agge17raw_memory_object3getINS_8parallel6threadEEEPT_j(ptr noundef nonnull align 8 dereferenceable(12), i32 noundef) local_unnamed_addr #4 align 2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZN4agge8parallel15destroy_threadsEv(ptr noundef nonnull align 8 dereferenceable(28)) local_unnamed_addr #0 align 2

declare void @__cxa_rethrow() local_unnamed_addr

declare void @__cxa_end_catch() local_unnamed_addr

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

declare void @_ZN4agge8parallel6threadC1Ej(ptr, i32) local_unnamed_addr

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 = { noinline noreturn nounwind uwtable "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 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 = { 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 #5 = { nounwind }
attributes #6 = { noreturn }
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, !11, i64 24}
!6 = !{!"_ZTSN4agge8parallelE", !7, i64 8, !11, i64 24}
!7 = !{!"_ZTSN4agge17raw_memory_objectE", !8, i64 0, !11, i64 8}
!8 = !{!"any pointer", !9, i64 0}
!9 = !{!"omnipotent char", !10, i64 0}
!10 = !{!"Simple C++ TBAA"}
!11 = !{!"int", !9, i64 0}
!12 = distinct !{!12, !13}
!13 = !{!"llvm.loop.mustprogress"}


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