; 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.mesh_task_helper_context = type { ptr, ptr, ptr, ptr, i64, i32, i32 }
%struct.RuntimeContext = type { ptr, ptr, i32, ptr }

; 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: 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) #1

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef nonnull align 4 dereferenceable(4) ptr @_ZSt3minIiERKT_S2_S2_(ptr noundef nonnull align 4 dereferenceable(4), ptr noundef nonnull align 4 dereferenceable(4)) #2

; Function Attrs: nocallback nofree nosync nounwind willreturn
declare ptr @llvm.stacksave.p0() #3

; Function Attrs: nocallback nofree nosync nounwind willreturn
declare void @llvm.stackrestore.p0(ptr) #3

; Function Attrs: mustprogress uwtable
define dso_local void @cpu_parallel_mesh_for_task(ptr noundef %0, i32 noundef %1, i32 noundef %2) #4 {
  %4 = alloca ptr, align 8
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  %7 = alloca %struct.mesh_task_helper_context, align 8
  %8 = alloca ptr, align 8
  %9 = alloca i64, align 8
  %10 = alloca ptr, align 8
  %11 = alloca %struct.RuntimeContext, align 8
  %12 = alloca i32, align 4
  %13 = alloca i32, align 4
  %14 = alloca i32, align 4
  %15 = alloca i32, align 4
  store ptr %0, ptr %4, align 8, !tbaa !5
  store i32 %1, ptr %5, align 4, !tbaa !9
  store i32 %2, ptr %6, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 48, ptr %7) #5
  %16 = load ptr, ptr %4, align 8, !tbaa !5
  call void @llvm.memcpy.p0.p0.i64(ptr align 8 %7, ptr align 8 %16, i64 48, i1 false), !tbaa.struct !11
  %17 = getelementptr inbounds %struct.mesh_task_helper_context, ptr %7, i32 0, i32 4
  %18 = load i64, ptr %17, align 8, !tbaa !14
  %19 = call ptr @llvm.stacksave.p0()
  store ptr %19, ptr %8, align 8
  %20 = alloca i8, i64 %18, align 8
  store i64 %18, ptr %9, align 8
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #5
  %21 = getelementptr inbounds i8, ptr %20, i64 0
  store ptr %21, ptr %10, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 32, ptr %11) #5
  %22 = getelementptr inbounds %struct.mesh_task_helper_context, ptr %7, i32 0, i32 0
  %23 = load ptr, ptr %22, align 8, !tbaa !16
  call void @llvm.memcpy.p0.p0.i64(ptr align 8 %11, ptr align 8 %23, i64 32, i1 false), !tbaa.struct !17
  %24 = load i32, ptr %5, align 4, !tbaa !9
  %25 = getelementptr inbounds %struct.RuntimeContext, ptr %11, i32 0, i32 2
  store i32 %24, ptr %25, align 8, !tbaa !18
  call void @llvm.lifetime.start.p0(i64 4, ptr %12) #5
  %26 = load i32, ptr %6, align 4, !tbaa !9
  %27 = getelementptr inbounds %struct.mesh_task_helper_context, ptr %7, i32 0, i32 6
  %28 = load i32, ptr %27, align 4, !tbaa !20
  %29 = mul nsw i32 %26, %28
  store i32 %29, ptr %12, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %13) #5
  call void @llvm.lifetime.start.p0(i64 4, ptr %14) #5
  %30 = load i32, ptr %12, align 4, !tbaa !9
  %31 = getelementptr inbounds %struct.mesh_task_helper_context, ptr %7, i32 0, i32 6
  %32 = load i32, ptr %31, align 4, !tbaa !20
  %33 = add nsw i32 %30, %32
  store i32 %33, ptr %14, align 4, !tbaa !9
  %34 = getelementptr inbounds %struct.mesh_task_helper_context, ptr %7, i32 0, i32 5
  %35 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZSt3minIiERKT_S2_S2_(ptr noundef nonnull align 4 dereferenceable(4) %14, ptr noundef nonnull align 4 dereferenceable(4) %34)
  %36 = load i32, ptr %35, align 4, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 4, ptr %14) #5
  store i32 %36, ptr %13, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %15) #5
  %37 = load i32, ptr %12, align 4, !tbaa !9
  store i32 %37, ptr %15, align 4, !tbaa !9
  br label %38

38:                                               ; preds = %70, %3
  %39 = load i32, ptr %15, align 4, !tbaa !9
  %40 = load i32, ptr %13, align 4, !tbaa !9
  %41 = icmp slt i32 %39, %40
  br i1 %41, label %43, label %42

42:                                               ; preds = %38
  call void @llvm.lifetime.end.p0(i64 4, ptr %15) #5
  br label %73

43:                                               ; preds = %38
  %44 = getelementptr inbounds %struct.mesh_task_helper_context, ptr %7, i32 0, i32 1
  %45 = load ptr, ptr %44, align 8, !tbaa !21
  %46 = icmp ne ptr %45, null
  br i1 %46, label %47, label %54

47:                                               ; preds = %43
  %48 = getelementptr inbounds %struct.mesh_task_helper_context, ptr %7, i32 0, i32 1
  %49 = load ptr, ptr %48, align 8, !tbaa !21
  %50 = getelementptr inbounds %struct.mesh_task_helper_context, ptr %7, i32 0, i32 0
  %51 = load ptr, ptr %50, align 8, !tbaa !16
  %52 = load ptr, ptr %10, align 8, !tbaa !5
  %53 = load i32, ptr %15, align 4, !tbaa !9
  call void %49(ptr noundef %51, ptr noundef %52, i32 noundef %53)
  br label %54

54:                                               ; preds = %47, %43
  %55 = getelementptr inbounds %struct.mesh_task_helper_context, ptr %7, i32 0, i32 2
  %56 = load ptr, ptr %55, align 8, !tbaa !22
  %57 = load ptr, ptr %10, align 8, !tbaa !5
  %58 = load i32, ptr %15, align 4, !tbaa !9
  call void %56(ptr noundef %11, ptr noundef %57, i32 noundef %58)
  %59 = getelementptr inbounds %struct.mesh_task_helper_context, ptr %7, i32 0, i32 3
  %60 = load ptr, ptr %59, align 8, !tbaa !23
  %61 = icmp ne ptr %60, null
  br i1 %61, label %62, label %69

62:                                               ; preds = %54
  %63 = getelementptr inbounds %struct.mesh_task_helper_context, ptr %7, i32 0, i32 3
  %64 = load ptr, ptr %63, align 8, !tbaa !23
  %65 = getelementptr inbounds %struct.mesh_task_helper_context, ptr %7, i32 0, i32 0
  %66 = load ptr, ptr %65, align 8, !tbaa !16
  %67 = load ptr, ptr %10, align 8, !tbaa !5
  %68 = load i32, ptr %15, align 4, !tbaa !9
  call void %64(ptr noundef %66, ptr noundef %67, i32 noundef %68)
  br label %69

69:                                               ; preds = %62, %54
  br label %70

70:                                               ; preds = %69
  %71 = load i32, ptr %15, align 4, !tbaa !9
  %72 = add nsw i32 %71, 1
  store i32 %72, ptr %15, align 4, !tbaa !9
  br label %38, !llvm.loop !24

73:                                               ; preds = %42
  call void @llvm.lifetime.end.p0(i64 4, ptr %13) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %12) #5
  call void @llvm.lifetime.end.p0(i64 32, ptr %11) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #5
  %74 = load ptr, ptr %8, align 8
  call void @llvm.stackrestore.p0(ptr %74)
  call void @llvm.lifetime.end.p0(i64 48, ptr %7) #5
  ret void
}

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

!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 = !{i64 0, i64 8, !5, i64 8, i64 8, !5, i64 16, i64 8, !5, i64 24, i64 8, !5, i64 32, i64 8, !12, i64 40, i64 4, !9, i64 44, i64 4, !9}
!12 = !{!13, !13, i64 0}
!13 = !{!"long", !7, i64 0}
!14 = !{!15, !13, i64 32}
!15 = !{!"_ZTS24mesh_task_helper_context", !6, i64 0, !6, i64 8, !6, i64 16, !6, i64 24, !13, i64 32, !10, i64 40, !10, i64 44}
!16 = !{!15, !6, i64 0}
!17 = !{i64 0, i64 8, !5, i64 8, i64 8, !5, i64 16, i64 4, !9, i64 24, i64 8, !5}
!18 = !{!19, !10, i64 16}
!19 = !{!"_ZTS14RuntimeContext", !6, i64 0, !6, i64 8, !10, i64 16, !6, i64 24}
!20 = !{!15, !10, i64 44}
!21 = !{!15, !6, i64 8}
!22 = !{!15, !6, i64 16}
!23 = !{!15, !6, i64 24}
!24 = distinct !{!24, !25}
!25 = !{!"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.mesh_task_helper_context = type { ptr, ptr, ptr, ptr, i64, i32, i32 }
%struct.RuntimeContext = type { ptr, ptr, i32, ptr }

; 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: mustprogress 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) #1

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef nonnull align 4 dereferenceable(4) ptr @_ZSt3minIiERKT_S2_S2_(ptr noundef nonnull align 4 dereferenceable(4), ptr noundef nonnull align 4 dereferenceable(4)) local_unnamed_addr #2

; Function Attrs: mustprogress nocallback nofree nosync nounwind willreturn
declare ptr @llvm.stacksave.p0() #3

; Function Attrs: mustprogress nocallback nofree nosync nounwind willreturn
declare void @llvm.stackrestore.p0(ptr) #3

; Function Attrs: mustprogress uwtable
define dso_local void @cpu_parallel_mesh_for_task(ptr nocapture noundef readonly %0, i32 noundef %1, i32 noundef %2) local_unnamed_addr #4 {
  %4 = alloca %struct.mesh_task_helper_context, align 8
  %5 = alloca %struct.RuntimeContext, align 8
  %6 = alloca i32, align 4
  call void @llvm.lifetime.start.p0(i64 48, ptr nonnull %4) #5
  call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 8 dereferenceable(48) %4, ptr noundef nonnull align 8 dereferenceable(48) %0, i64 48, i1 false), !tbaa.struct !5
  %7 = getelementptr inbounds i8, ptr %4, i64 32
  %8 = load i64, ptr %7, align 8, !tbaa !14
  %9 = tail call ptr @llvm.stacksave.p0()
  %10 = alloca i8, i64 %8, align 8
  call void @llvm.lifetime.start.p0(i64 32, ptr nonnull %5) #5
  %11 = load ptr, ptr %4, align 8, !tbaa !16
  call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 8 dereferenceable(32) %5, ptr noundef nonnull align 8 dereferenceable(32) %11, i64 32, i1 false), !tbaa.struct !17
  %12 = getelementptr inbounds i8, ptr %5, i64 16
  store i32 %1, ptr %12, align 8, !tbaa !18
  %13 = getelementptr inbounds i8, ptr %4, i64 44
  %14 = load i32, ptr %13, align 4, !tbaa !20
  %15 = mul nsw i32 %14, %2
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %6) #5
  %16 = add nsw i32 %15, %14
  store i32 %16, ptr %6, align 4, !tbaa !12
  %17 = getelementptr inbounds i8, ptr %4, i64 40
  %18 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZSt3minIiERKT_S2_S2_(ptr noundef nonnull align 4 dereferenceable(4) %6, ptr noundef nonnull align 4 dereferenceable(4) %17)
  %19 = load i32, ptr %18, align 4, !tbaa !12
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %6) #5
  %20 = icmp slt i32 %15, %19
  br i1 %20, label %.lr.ph, label %._crit_edge

.lr.ph:                                           ; preds = %3
  %21 = getelementptr inbounds i8, ptr %4, i64 8
  %22 = getelementptr inbounds i8, ptr %4, i64 16
  %23 = getelementptr inbounds i8, ptr %4, i64 24
  br label %24

._crit_edge:                                      ; preds = %33, %3
  call void @llvm.lifetime.end.p0(i64 32, ptr nonnull %5) #5
  call void @llvm.stackrestore.p0(ptr %9)
  call void @llvm.lifetime.end.p0(i64 48, ptr nonnull %4) #5
  ret void

24:                                               ; preds = %.lr.ph, %33
  %.017 = phi i32 [ %15, %.lr.ph ], [ %34, %33 ]
  %25 = load ptr, ptr %21, align 8, !tbaa !21
  %.not = icmp eq ptr %25, null
  br i1 %.not, label %28, label %26

26:                                               ; preds = %24
  %27 = load ptr, ptr %4, align 8, !tbaa !16
  call void %25(ptr noundef %27, ptr noundef nonnull %10, i32 noundef %.017)
  br label %28

28:                                               ; preds = %26, %24
  %29 = load ptr, ptr %22, align 8, !tbaa !22
  call void %29(ptr noundef nonnull %5, ptr noundef nonnull %10, i32 noundef %.017)
  %30 = load ptr, ptr %23, align 8, !tbaa !23
  %.not16 = icmp eq ptr %30, null
  br i1 %.not16, label %33, label %31

31:                                               ; preds = %28
  %32 = load ptr, ptr %4, align 8, !tbaa !16
  call void %30(ptr noundef %32, ptr noundef nonnull %10, i32 noundef %.017)
  br label %33

33:                                               ; preds = %28, %31
  %34 = add i32 %.017, 1
  %exitcond.not = icmp eq i32 %34, %19
  br i1 %exitcond.not, label %._crit_edge, label %24, !llvm.loop !24
}

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

!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 = !{i64 0, i64 8, !6, i64 8, i64 8, !6, i64 16, i64 8, !6, i64 24, i64 8, !6, i64 32, i64 8, !10, i64 40, i64 4, !12, i64 44, i64 4, !12}
!6 = !{!7, !7, i64 0}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}
!10 = !{!11, !11, i64 0}
!11 = !{!"long", !8, i64 0}
!12 = !{!13, !13, i64 0}
!13 = !{!"int", !8, i64 0}
!14 = !{!15, !11, i64 32}
!15 = !{!"_ZTS24mesh_task_helper_context", !7, i64 0, !7, i64 8, !7, i64 16, !7, i64 24, !11, i64 32, !13, i64 40, !13, i64 44}
!16 = !{!15, !7, i64 0}
!17 = !{i64 0, i64 8, !6, i64 8, i64 8, !6, i64 16, i64 4, !12, i64 24, i64 8, !6}
!18 = !{!19, !13, i64 16}
!19 = !{!"_ZTS14RuntimeContext", !7, i64 0, !7, i64 8, !13, i64 16, !7, i64 24}
!20 = !{!15, !13, i64 44}
!21 = !{!15, !7, i64 8}
!22 = !{!15, !7, i64 16}
!23 = !{!15, !7, i64 24}
!24 = distinct !{!24, !25}
!25 = !{!"llvm.loop.mustprogress"}


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