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

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

declare i32 @__gxx_personality_v0(...)

; Function Attrs: noinline noreturn nounwind uwtable
declare hidden void @__clang_call_terminate(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: inlinehint mustprogress uwtable
declare dso_local noundef ptr @_ZN4agge17raw_memory_object3getINS_8parallel6threadEEEPT_j(ptr noundef nonnull align 8 dereferenceable(12), i32 noundef) #2 align 2

; Function Attrs: mustprogress nounwind uwtable
define dso_local void @_ZN4agge8parallel15destroy_threadsEv(ptr noundef nonnull align 8 dereferenceable(28) %0) #3 align 2 personality ptr @__gxx_personality_v0 {
  %2 = alloca ptr, align 8
  %3 = alloca ptr, align 8
  %4 = alloca i32, align 4
  store ptr %0, ptr %2, align 8, !tbaa !5
  %5 = load ptr, ptr %2, align 8
  call void @llvm.lifetime.start.p0(i64 8, ptr %3) #4
  %6 = getelementptr inbounds %"class.agge::parallel", ptr %5, i32 0, i32 1
  %7 = invoke noundef ptr @_ZN4agge17raw_memory_object3getINS_8parallel6threadEEEPT_j(ptr noundef nonnull align 8 dereferenceable(12) %6, i32 noundef 0)
          to label %8 unwind label %24

8:                                                ; preds = %1
  store ptr %7, ptr %3, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #4
  store i32 0, ptr %4, align 4, !tbaa !9
  br label %9

9:                                                ; preds = %20, %8
  %10 = load i32, ptr %4, align 4, !tbaa !9
  %11 = getelementptr inbounds %"class.agge::parallel", ptr %5, i32 0, i32 2
  %12 = load i32, ptr %11, align 8, !tbaa !11
  %13 = icmp ne i32 %10, %12
  br i1 %13, label %15, label %14

14:                                               ; preds = %9
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #4
  br label %23

15:                                               ; preds = %9
  %16 = load ptr, ptr %3, align 8, !tbaa !5
  %17 = load i32, ptr %4, align 4, !tbaa !9
  %18 = zext i32 %17 to i64
  %19 = getelementptr inbounds %"struct.agge::parallel::thread", ptr %16, i64 %18
  call void @_ZN4agge8parallel6threadD1Ev(ptr noundef nonnull align 8 dereferenceable(80) %19) #4
  br label %20

20:                                               ; preds = %15
  %21 = load i32, ptr %4, align 4, !tbaa !9
  %22 = add i32 %21, 1
  store i32 %22, ptr %4, align 4, !tbaa !9
  br label %9, !llvm.loop !14

23:                                               ; preds = %14
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #4
  ret void

24:                                               ; preds = %1
  %25 = landingpad { ptr, i32 }
          catch ptr null
  %26 = extractvalue { ptr, i32 } %25, 0
  call void @__clang_call_terminate(ptr %26) #5
  unreachable
}

declare void @_ZN4agge8parallel6threadD1Ev(ptr)

attributes #0 = { 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 #1 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 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 = { nounwind }
attributes #5 = { 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"

%"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 }

declare i32 @__gxx_personality_v0(...)

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

; 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 #1 align 2

; Function Attrs: mustprogress nounwind uwtable
define dso_local void @_ZN4agge8parallel15destroy_threadsEv(ptr noundef nonnull align 8 dereferenceable(28) %0) local_unnamed_addr #2 align 2 personality ptr @__gxx_personality_v0 {
  %2 = getelementptr inbounds i8, ptr %0, i64 8
  %3 = invoke noundef ptr @_ZN4agge17raw_memory_object3getINS_8parallel6threadEEEPT_j(ptr noundef nonnull align 8 dereferenceable(12) %2, i32 noundef 0)
          to label %.preheader unwind label %10

.preheader:                                       ; preds = %1
  %4 = getelementptr inbounds i8, ptr %0, i64 24
  %5 = load i32, ptr %4, align 8, !tbaa !5
  %.not4 = icmp eq i32 %5, 0
  br i1 %.not4, label %._crit_edge, label %.lr.ph

._crit_edge:                                      ; preds = %.lr.ph, %.preheader
  ret void

.lr.ph:                                           ; preds = %.preheader, %.lr.ph
  %.05 = phi i32 [ %8, %.lr.ph ], [ 0, %.preheader ]
  %6 = zext i32 %.05 to i64
  %7 = getelementptr inbounds %"struct.agge::parallel::thread", ptr %3, i64 %6
  tail call void @_ZN4agge8parallel6threadD1Ev(ptr noundef nonnull align 8 dereferenceable(80) %7) #3
  %8 = add i32 %.05, 1
  %9 = load i32, ptr %4, align 8, !tbaa !5
  %.not = icmp eq i32 %8, %9
  br i1 %.not, label %._crit_edge, label %.lr.ph, !llvm.loop !12

10:                                               ; preds = %1
  %11 = landingpad { ptr, i32 }
          catch ptr null
  %12 = extractvalue { ptr, i32 } %11, 0
  tail call void @__clang_call_terminate(ptr %12) #4
  unreachable
}

declare void @_ZN4agge8parallel6threadD1Ev(ptr) local_unnamed_addr

attributes #0 = { 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 #1 = { 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 #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 = { nounwind }
attributes #4 = { 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: GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LICMPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,SROAPass,SimplifyCFGPass,TailCallElimPass