; LLVM IR from taichi-dev/taichi :: taichi/runtime/llvm/runtime_module (runtime)

; 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.NodeManager = type <{ ptr, i32, i32, i32, i32, ptr, ptr, ptr, i32, [4 x i8] }>

; Function Attrs: mustprogress nounwind uwtable
declare dso_local i32 @block_dim() #0

; Function Attrs: mustprogress nounwind uwtable
declare dso_local i32 @grid_dim() #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: mustprogress nounwind uwtable
declare dso_local noundef i32 @_ZN11ListManager4sizeEv(ptr noundef nonnull align 8 dereferenceable(1048616)) #0 align 2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local i32 @linear_thread_idx(ptr noundef) #0

; Function Attrs: mustprogress uwtable
define dso_local void @gc_parallel_impl_0(ptr noundef %0, ptr noundef %1) #2 {
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  %10 = alloca i32, align 4
  store ptr %0, ptr %3, align 8, !tbaa !5
  store ptr %1, ptr %4, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #3
  %11 = load ptr, ptr %4, align 8, !tbaa !5
  %12 = getelementptr inbounds %struct.NodeManager, ptr %11, i32 0, i32 5
  %13 = load ptr, ptr %12, align 8, !tbaa !9
  store ptr %13, ptr %5, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #3
  %14 = load ptr, ptr %5, align 8, !tbaa !5
  %15 = call noundef i32 @_ZN11ListManager4sizeEv(ptr noundef nonnull align 8 dereferenceable(1048616) %14)
  store i32 %15, ptr %6, align 4, !tbaa !12
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #3
  %16 = load ptr, ptr %4, align 8, !tbaa !5
  %17 = getelementptr inbounds %struct.NodeManager, ptr %16, i32 0, i32 4
  %18 = load i32, ptr %17, align 4, !tbaa !13
  store i32 %18, ptr %7, align 4, !tbaa !12
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #3
  %19 = load ptr, ptr %3, align 8, !tbaa !5
  %20 = call i32 @linear_thread_idx(ptr noundef %19)
  store i32 %20, ptr %8, align 4, !tbaa !12
  %21 = load i32, ptr %7, align 4, !tbaa !12
  %22 = mul nsw i32 %21, 2
  %23 = load i32, ptr %6, align 4, !tbaa !12
  %24 = icmp sgt i32 %22, %23
  br i1 %24, label %25, label %49

25:                                               ; preds = %2
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #3
  %26 = load i32, ptr %6, align 4, !tbaa !12
  %27 = load i32, ptr %7, align 4, !tbaa !12
  %28 = sub nsw i32 %26, %27
  store i32 %28, ptr %9, align 4, !tbaa !12
  br label %29

29:                                               ; preds = %33, %25
  %30 = load i32, ptr %8, align 4, !tbaa !12
  %31 = load i32, ptr %9, align 4, !tbaa !12
  %32 = icmp slt i32 %30, %31
  br i1 %32, label %33, label %48

33:                                               ; preds = %29
  %34 = load ptr, ptr %5, align 8, !tbaa !5
  %35 = load i32, ptr %7, align 4, !tbaa !12
  %36 = load i32, ptr %8, align 4, !tbaa !12
  %37 = add nsw i32 %35, %36
  %38 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZN11ListManager3getIiEERT_i(ptr noundef nonnull align 8 dereferenceable(1048616) %34, i32 noundef %37)
  %39 = load i32, ptr %38, align 4, !tbaa !12
  %40 = load ptr, ptr %5, align 8, !tbaa !5
  %41 = load i32, ptr %8, align 4, !tbaa !12
  %42 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZN11ListManager3getIiEERT_i(ptr noundef nonnull align 8 dereferenceable(1048616) %40, i32 noundef %41)
  store i32 %39, ptr %42, align 4, !tbaa !12
  %43 = call i32 @grid_dim()
  %44 = call i32 @block_dim()
  %45 = mul nsw i32 %43, %44
  %46 = load i32, ptr %8, align 4, !tbaa !12
  %47 = add nsw i32 %46, %45
  store i32 %47, ptr %8, align 4, !tbaa !12
  br label %29, !llvm.loop !14

48:                                               ; preds = %29
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #3
  br label %73

49:                                               ; preds = %2
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #3
  %50 = load i32, ptr %7, align 4, !tbaa !12
  store i32 %50, ptr %10, align 4, !tbaa !12
  br label %51

51:                                               ; preds = %55, %49
  %52 = load i32, ptr %8, align 4, !tbaa !12
  %53 = load i32, ptr %10, align 4, !tbaa !12
  %54 = icmp slt i32 %52, %53
  br i1 %54, label %55, label %72

55:                                               ; preds = %51
  %56 = load ptr, ptr %5, align 8, !tbaa !5
  %57 = load i32, ptr %6, align 4, !tbaa !12
  %58 = load i32, ptr %10, align 4, !tbaa !12
  %59 = sub nsw i32 %57, %58
  %60 = load i32, ptr %8, align 4, !tbaa !12
  %61 = add nsw i32 %59, %60
  %62 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZN11ListManager3getIiEERT_i(ptr noundef nonnull align 8 dereferenceable(1048616) %56, i32 noundef %61)
  %63 = load i32, ptr %62, align 4, !tbaa !12
  %64 = load ptr, ptr %5, align 8, !tbaa !5
  %65 = load i32, ptr %8, align 4, !tbaa !12
  %66 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZN11ListManager3getIiEERT_i(ptr noundef nonnull align 8 dereferenceable(1048616) %64, i32 noundef %65)
  store i32 %63, ptr %66, align 4, !tbaa !12
  %67 = call i32 @grid_dim()
  %68 = call i32 @block_dim()
  %69 = mul nsw i32 %67, %68
  %70 = load i32, ptr %8, align 4, !tbaa !12
  %71 = add nsw i32 %70, %69
  store i32 %71, ptr %8, align 4, !tbaa !12
  br label %51, !llvm.loop !16

72:                                               ; preds = %51
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #3
  br label %73

73:                                               ; preds = %72, %48
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #3
  ret void
}

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef nonnull align 4 dereferenceable(4) ptr @_ZN11ListManager3getIiEERT_i(ptr noundef nonnull align 8 dereferenceable(1048616), i32 noundef) #0 align 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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = { 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 24}
!10 = !{!"_ZTS11NodeManager", !6, i64 0, !11, i64 8, !11, i64 12, !11, i64 16, !11, i64 20, !6, i64 24, !6, i64 32, !6, i64 40, !11, i64 48}
!11 = !{!"int", !7, i64 0}
!12 = !{!11, !11, i64 0}
!13 = !{!10, !11, i64 20}
!14 = distinct !{!14, !15}
!15 = !{!"llvm.loop.mustprogress"}
!16 = distinct !{!16, !15}


; 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 i32 @block_dim() local_unnamed_addr #0

; Function Attrs: mustprogress nounwind uwtable
declare dso_local i32 @grid_dim() local_unnamed_addr #0

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i32 @_ZN11ListManager4sizeEv(ptr noundef nonnull align 8 dereferenceable(1048616)) local_unnamed_addr #0 align 2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local i32 @linear_thread_idx(ptr noundef) local_unnamed_addr #0

; Function Attrs: mustprogress nounwind uwtable
define dso_local void @gc_parallel_impl_0(ptr noundef %0, ptr nocapture noundef readonly %1) local_unnamed_addr #0 {
  %3 = getelementptr inbounds i8, ptr %1, i64 24
  %4 = load ptr, ptr %3, align 8, !tbaa !5
  %5 = tail call noundef i32 @_ZN11ListManager4sizeEv(ptr noundef nonnull align 8 dereferenceable(1048616) %4)
  %6 = getelementptr inbounds i8, ptr %1, i64 20
  %7 = load i32, ptr %6, align 4, !tbaa !11
  %8 = tail call i32 @linear_thread_idx(ptr noundef %0)
  %9 = shl nsw i32 %7, 1
  %10 = icmp sgt i32 %9, %5
  br i1 %10, label %13, label %.preheader

.preheader:                                       ; preds = %2
  %11 = icmp slt i32 %8, %7
  br i1 %11, label %.lr.ph, label %.loopexit

.lr.ph:                                           ; preds = %.preheader
  %12 = sub i32 %5, %7
  br label %25

13:                                               ; preds = %2
  %14 = sub nsw i32 %5, %7
  %15 = icmp slt i32 %8, %14
  br i1 %15, label %.lr.ph31, label %.loopexit

.lr.ph31:                                         ; preds = %13, %.lr.ph31
  %.030 = phi i32 [ %23, %.lr.ph31 ], [ %8, %13 ]
  %16 = add nsw i32 %.030, %7
  %17 = tail call noundef nonnull align 4 dereferenceable(4) ptr @_ZN11ListManager3getIiEERT_i(ptr noundef nonnull align 8 dereferenceable(1048616) %4, i32 noundef %16)
  %18 = load i32, ptr %17, align 4, !tbaa !12
  %19 = tail call noundef nonnull align 4 dereferenceable(4) ptr @_ZN11ListManager3getIiEERT_i(ptr noundef nonnull align 8 dereferenceable(1048616) %4, i32 noundef %.030)
  store i32 %18, ptr %19, align 4, !tbaa !12
  %20 = tail call i32 @grid_dim()
  %21 = tail call i32 @block_dim()
  %22 = mul nsw i32 %21, %20
  %23 = add nsw i32 %22, %.030
  %24 = icmp slt i32 %23, %14
  br i1 %24, label %.lr.ph31, label %.loopexit, !llvm.loop !13

25:                                               ; preds = %.lr.ph, %25
  %.129 = phi i32 [ %8, %.lr.ph ], [ %33, %25 ]
  %26 = add nsw i32 %12, %.129
  %27 = tail call noundef nonnull align 4 dereferenceable(4) ptr @_ZN11ListManager3getIiEERT_i(ptr noundef nonnull align 8 dereferenceable(1048616) %4, i32 noundef %26)
  %28 = load i32, ptr %27, align 4, !tbaa !12
  %29 = tail call noundef nonnull align 4 dereferenceable(4) ptr @_ZN11ListManager3getIiEERT_i(ptr noundef nonnull align 8 dereferenceable(1048616) %4, i32 noundef %.129)
  store i32 %28, ptr %29, align 4, !tbaa !12
  %30 = tail call i32 @grid_dim()
  %31 = tail call i32 @block_dim()
  %32 = mul nsw i32 %31, %30
  %33 = add nsw i32 %32, %.129
  %34 = icmp slt i32 %33, %7
  br i1 %34, label %25, label %.loopexit, !llvm.loop !15

.loopexit:                                        ; preds = %25, %.lr.ph31, %.preheader, %13
  ret void
}

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef nonnull align 4 dereferenceable(4) ptr @_ZN11ListManager3getIiEERT_i(ptr noundef nonnull align 8 dereferenceable(1048616), i32 noundef) local_unnamed_addr #0 align 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" }

!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 24}
!6 = !{!"_ZTS11NodeManager", !7, i64 0, !10, i64 8, !10, i64 12, !10, i64 16, !10, i64 20, !7, i64 24, !7, i64 32, !7, i64 40, !10, i64 48}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}
!10 = !{!"int", !8, i64 0}
!11 = !{!6, !10, i64 20}
!12 = !{!10, !10, i64 0}
!13 = distinct !{!13, !14}
!14 = !{!"llvm.loop.mustprogress"}
!15 = distinct !{!15, !14}


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