; 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.Element = type { ptr, [2 x i32], %struct.PhysicalCoordinates }
%struct.PhysicalCoordinates = type { [12 x i32] }
%struct.LLVMRuntime = type { %struct.PreallocatedMemoryChunk, %struct.PreallocatedMemoryChunk, ptr, ptr, ptr, ptr, ptr, [512 x ptr], [512 x i64], ptr, ptr, [1024 x ptr], [1024 x ptr], [1024 x ptr], ptr, ptr, ptr, ptr, ptr, [2048 x i8], [32 x i64], i32, i64, ptr, i32, i32, i64 }
%struct.PreallocatedMemoryChunk = type { ptr, ptr, i64 }

; 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: mustprogress uwtable
define dso_local void @runtime_initialize_snodes(ptr noundef %0, i64 noundef %1, i32 noundef %2, i32 noundef %3, i32 noundef %4, i64 noundef %5, ptr noundef %6, i1 noundef zeroext %7) #1 {
  %9 = alloca ptr, align 8
  %10 = alloca i64, align 8
  %11 = alloca i32, align 4
  %12 = alloca i32, align 4
  %13 = alloca i32, align 4
  %14 = alloca i64, align 8
  %15 = alloca ptr, align 8
  %16 = alloca i8, align 1
  %17 = alloca i32, align 4
  %18 = alloca i64, align 8
  %19 = alloca i32, align 4
  %20 = alloca %struct.Element, align 8
  %21 = alloca i32, align 4
  store ptr %0, ptr %9, align 8, !tbaa !5
  store i64 %1, ptr %10, align 8, !tbaa !9
  store i32 %2, ptr %11, align 4, !tbaa !11
  store i32 %3, ptr %12, align 4, !tbaa !11
  store i32 %4, ptr %13, align 4, !tbaa !11
  store i64 %5, ptr %14, align 8, !tbaa !9
  store ptr %6, ptr %15, align 8, !tbaa !5
  %22 = zext i1 %7 to i8
  store i8 %22, ptr %16, align 1, !tbaa !13
  %23 = load i64, ptr %14, align 8, !tbaa !9
  %24 = load ptr, ptr %9, align 8, !tbaa !5
  %25 = getelementptr inbounds %struct.LLVMRuntime, ptr %24, i32 0, i32 8
  %26 = load i32, ptr %13, align 4, !tbaa !11
  %27 = sext i32 %26 to i64
  %28 = getelementptr inbounds [512 x i64], ptr %25, i64 0, i64 %27
  store i64 %23, ptr %28, align 8, !tbaa !9
  %29 = load ptr, ptr %15, align 8, !tbaa !5
  %30 = load ptr, ptr %9, align 8, !tbaa !5
  %31 = getelementptr inbounds %struct.LLVMRuntime, ptr %30, i32 0, i32 7
  %32 = load i32, ptr %13, align 4, !tbaa !11
  %33 = sext i32 %32 to i64
  %34 = getelementptr inbounds [512 x ptr], ptr %31, i64 0, i64 %33
  store ptr %29, ptr %34, align 8, !tbaa !5
  %35 = load i8, ptr %16, align 1, !tbaa !13, !range !15, !noundef !16
  %36 = trunc i8 %35 to i1
  br i1 %36, label %37, label %38

37:                                               ; preds = %8
  br label %90

38:                                               ; preds = %8
  call void @llvm.lifetime.start.p0(i64 4, ptr %17) #2
  %39 = load i32, ptr %11, align 4, !tbaa !11
  store i32 %39, ptr %17, align 4, !tbaa !11
  br label %40

40:                                               ; preds = %55, %38
  %41 = load i32, ptr %17, align 4, !tbaa !11
  %42 = load i32, ptr %11, align 4, !tbaa !11
  %43 = load i32, ptr %12, align 4, !tbaa !11
  %44 = add nsw i32 %42, %43
  %45 = icmp slt i32 %41, %44
  br i1 %45, label %47, label %46

46:                                               ; preds = %40
  call void @llvm.lifetime.end.p0(i64 4, ptr %17) #2
  br label %58

47:                                               ; preds = %40
  %48 = load ptr, ptr %9, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %18) #2
  store i64 64, ptr %18, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %19) #2
  store i32 65536, ptr %19, align 4, !tbaa !11
  %49 = call noundef ptr @_ZN11LLVMRuntime6createI11ListManagerJRPS_miEEEPT_DpOT0_(ptr noundef nonnull align 8 dereferenceable(35256) %48, ptr noundef nonnull align 8 dereferenceable(8) %9, ptr noundef nonnull align 8 dereferenceable(8) %18, ptr noundef nonnull align 4 dereferenceable(4) %19)
  %50 = load ptr, ptr %9, align 8, !tbaa !5
  %51 = getelementptr inbounds %struct.LLVMRuntime, ptr %50, i32 0, i32 11
  %52 = load i32, ptr %17, align 4, !tbaa !11
  %53 = sext i32 %52 to i64
  %54 = getelementptr inbounds [1024 x ptr], ptr %51, i64 0, i64 %53
  store ptr %49, ptr %54, align 8, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 4, ptr %19) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %18) #2
  br label %55

55:                                               ; preds = %47
  %56 = load i32, ptr %17, align 4, !tbaa !11
  %57 = add nsw i32 %56, 1
  store i32 %57, ptr %17, align 4, !tbaa !11
  br label %40, !llvm.loop !17

58:                                               ; preds = %46
  call void @llvm.lifetime.start.p0(i64 64, ptr %20) #2
  %59 = getelementptr inbounds %struct.Element, ptr %20, i32 0, i32 1
  %60 = getelementptr inbounds [2 x i32], ptr %59, i64 0, i64 0
  store i32 0, ptr %60, align 8, !tbaa !11
  %61 = getelementptr inbounds %struct.Element, ptr %20, i32 0, i32 1
  %62 = getelementptr inbounds [2 x i32], ptr %61, i64 0, i64 1
  store i32 1, ptr %62, align 4, !tbaa !11
  %63 = load ptr, ptr %9, align 8, !tbaa !5
  %64 = getelementptr inbounds %struct.LLVMRuntime, ptr %63, i32 0, i32 7
  %65 = load i32, ptr %13, align 4, !tbaa !11
  %66 = sext i32 %65 to i64
  %67 = getelementptr inbounds [512 x ptr], ptr %64, i64 0, i64 %66
  %68 = load ptr, ptr %67, align 8, !tbaa !5
  %69 = getelementptr inbounds %struct.Element, ptr %20, i32 0, i32 0
  store ptr %68, ptr %69, align 8, !tbaa !19
  call void @llvm.lifetime.start.p0(i64 4, ptr %21) #2
  store i32 0, ptr %21, align 4, !tbaa !11
  br label %70

70:                                               ; preds = %80, %58
  %71 = load i32, ptr %21, align 4, !tbaa !11
  %72 = icmp slt i32 %71, 12
  br i1 %72, label %74, label %73

73:                                               ; preds = %70
  call void @llvm.lifetime.end.p0(i64 4, ptr %21) #2
  br label %83

74:                                               ; preds = %70
  %75 = getelementptr inbounds %struct.Element, ptr %20, i32 0, i32 2
  %76 = getelementptr inbounds %struct.PhysicalCoordinates, ptr %75, i32 0, i32 0
  %77 = load i32, ptr %21, align 4, !tbaa !11
  %78 = sext i32 %77 to i64
  %79 = getelementptr inbounds [12 x i32], ptr %76, i64 0, i64 %78
  store i32 0, ptr %79, align 4, !tbaa !11
  br label %80

80:                                               ; preds = %74
  %81 = load i32, ptr %21, align 4, !tbaa !11
  %82 = add nsw i32 %81, 1
  store i32 %82, ptr %21, align 4, !tbaa !11
  br label %70, !llvm.loop !22

83:                                               ; preds = %73
  %84 = load ptr, ptr %9, align 8, !tbaa !5
  %85 = getelementptr inbounds %struct.LLVMRuntime, ptr %84, i32 0, i32 11
  %86 = load i32, ptr %11, align 4, !tbaa !11
  %87 = sext i32 %86 to i64
  %88 = getelementptr inbounds [1024 x ptr], ptr %85, i64 0, i64 %87
  %89 = load ptr, ptr %88, align 8, !tbaa !5
  call void @_ZN11ListManager6appendEPv(ptr noundef nonnull align 8 dereferenceable(1048616) %89, ptr noundef %20)
  call void @llvm.lifetime.end.p0(i64 64, ptr %20) #2
  br label %90

90:                                               ; preds = %83, %37
  ret void
}

; Function Attrs: mustprogress uwtable
declare dso_local noundef ptr @_ZN11LLVMRuntime6createI11ListManagerJRPS_miEEEPT_DpOT0_(ptr noundef nonnull align 8 dereferenceable(35256), ptr noundef nonnull align 8 dereferenceable(8), ptr noundef nonnull align 8 dereferenceable(8), ptr noundef nonnull align 4 dereferenceable(4)) #1 align 2

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN11ListManager6appendEPv(ptr noundef nonnull align 8 dereferenceable(1048616), ptr noundef) #1 align 2

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 = { 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 = !{!"long", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"int", !7, i64 0}
!13 = !{!14, !14, i64 0}
!14 = !{!"bool", !7, i64 0}
!15 = !{i8 0, i8 2}
!16 = !{}
!17 = distinct !{!17, !18}
!18 = !{!"llvm.loop.mustprogress"}
!19 = !{!20, !6, i64 0}
!20 = !{!"_ZTS7Element", !6, i64 0, !7, i64 8, !21, i64 16}
!21 = !{!"_ZTS19PhysicalCoordinates", !7, i64 0}
!22 = distinct !{!22, !18}


; 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.Element = type { ptr, [2 x i32], %struct.PhysicalCoordinates }
%struct.PhysicalCoordinates = type { [12 x i32] }

; 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 uwtable
define dso_local void @runtime_initialize_snodes(ptr noundef %0, i64 noundef %1, i32 noundef %2, i32 noundef %3, i32 noundef %4, i64 noundef %5, ptr noundef %6, i1 noundef zeroext %7) local_unnamed_addr #1 {
  %9 = alloca ptr, align 8
  %10 = alloca i64, align 8
  %11 = alloca i32, align 4
  %12 = alloca %struct.Element, align 8
  store ptr %0, ptr %9, align 8, !tbaa !5
  %13 = getelementptr inbounds i8, ptr %0, i64 4184
  %14 = sext i32 %4 to i64
  %15 = getelementptr inbounds [512 x i64], ptr %13, i64 0, i64 %14
  store i64 %5, ptr %15, align 8, !tbaa !9
  %16 = getelementptr inbounds i8, ptr %0, i64 88
  %17 = getelementptr inbounds [512 x ptr], ptr %16, i64 0, i64 %14
  store ptr %6, ptr %17, align 8, !tbaa !5
  br i1 %7, label %36, label %.preheader

.preheader:                                       ; preds = %8
  %18 = icmp sgt i32 %3, 0
  br i1 %18, label %.lr.ph.preheader, label %.preheader.._crit_edge_crit_edge

.preheader.._crit_edge_crit_edge:                 ; preds = %.preheader
  %.pre24 = sext i32 %2 to i64
  br label %._crit_edge

.lr.ph.preheader:                                 ; preds = %.preheader
  %19 = add nsw i32 %3, %2
  %20 = sext i32 %2 to i64
  %21 = sext i32 %19 to i64
  br label %.lr.ph

._crit_edge.loopexit:                             ; preds = %.lr.ph
  %.pre = load ptr, ptr %9, align 8, !tbaa !5
  %.phi.trans.insert = getelementptr inbounds i8, ptr %.pre, i64 88
  %.phi.trans.insert22 = getelementptr inbounds [512 x ptr], ptr %.phi.trans.insert, i64 0, i64 %14
  %.pre23 = load ptr, ptr %.phi.trans.insert22, align 8, !tbaa !5
  br label %._crit_edge

._crit_edge:                                      ; preds = %.preheader.._crit_edge_crit_edge, %._crit_edge.loopexit
  %.pre-phi = phi i64 [ %.pre24, %.preheader.._crit_edge_crit_edge ], [ %20, %._crit_edge.loopexit ]
  %22 = phi ptr [ %6, %.preheader.._crit_edge_crit_edge ], [ %.pre23, %._crit_edge.loopexit ]
  %23 = phi ptr [ %0, %.preheader.._crit_edge_crit_edge ], [ %.pre, %._crit_edge.loopexit ]
  call void @llvm.lifetime.start.p0(i64 64, ptr nonnull %12) #3
  %24 = getelementptr inbounds i8, ptr %12, i64 8
  store i32 0, ptr %24, align 8, !tbaa !11
  %25 = getelementptr inbounds i8, ptr %12, i64 12
  store i32 1, ptr %25, align 4, !tbaa !11
  store ptr %22, ptr %12, align 8, !tbaa !13
  %26 = getelementptr inbounds i8, ptr %12, i64 16
  call void @llvm.memset.p0.i64(ptr noundef nonnull align 8 dereferenceable(48) %26, i8 0, i64 48, i1 false), !tbaa !11
  %27 = getelementptr inbounds i8, ptr %23, i64 8296
  %28 = getelementptr inbounds [1024 x ptr], ptr %27, i64 0, i64 %.pre-phi
  %29 = load ptr, ptr %28, align 8, !tbaa !5
  call void @_ZN11ListManager6appendEPv(ptr noundef nonnull align 8 dereferenceable(1048616) %29, ptr noundef nonnull %12)
  call void @llvm.lifetime.end.p0(i64 64, ptr nonnull %12) #3
  br label %36

.lr.ph:                                           ; preds = %.lr.ph.preheader, %.lr.ph
  %indvars.iv = phi i64 [ %20, %.lr.ph.preheader ], [ %indvars.iv.next, %.lr.ph ]
  %30 = load ptr, ptr %9, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %10) #3
  store i64 64, ptr %10, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %11) #3
  store i32 65536, ptr %11, align 4, !tbaa !11
  %31 = call noundef ptr @_ZN11LLVMRuntime6createI11ListManagerJRPS_miEEEPT_DpOT0_(ptr noundef nonnull align 8 dereferenceable(35256) %30, ptr noundef nonnull align 8 dereferenceable(8) %9, ptr noundef nonnull align 8 dereferenceable(8) %10, ptr noundef nonnull align 4 dereferenceable(4) %11)
  %32 = load ptr, ptr %9, align 8, !tbaa !5
  %33 = getelementptr inbounds i8, ptr %32, i64 8296
  %34 = getelementptr inbounds [1024 x ptr], ptr %33, i64 0, i64 %indvars.iv
  store ptr %31, ptr %34, align 8, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %11) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %10) #3
  %indvars.iv.next = add nsw i64 %indvars.iv, 1
  %35 = icmp slt i64 %indvars.iv.next, %21
  br i1 %35, label %.lr.ph, label %._crit_edge.loopexit, !llvm.loop !16

36:                                               ; preds = %8, %._crit_edge
  ret void
}

; Function Attrs: mustprogress uwtable
declare dso_local noundef ptr @_ZN11LLVMRuntime6createI11ListManagerJRPS_miEEEPT_DpOT0_(ptr noundef nonnull align 8 dereferenceable(35256), ptr noundef nonnull align 8 dereferenceable(8), ptr noundef nonnull align 8 dereferenceable(8), ptr noundef nonnull align 4 dereferenceable(4)) local_unnamed_addr #1 align 2

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN11ListManager6appendEPv(ptr noundef nonnull align 8 dereferenceable(1048616), ptr noundef) local_unnamed_addr #1 align 2

; 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 nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 = { nocallback nofree nounwind willreturn memory(argmem: write) }
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, !10, i64 0}
!10 = !{!"long", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"int", !7, i64 0}
!13 = !{!14, !6, i64 0}
!14 = !{!"_ZTS7Element", !6, i64 0, !7, i64 8, !15, i64 16}
!15 = !{!"_ZTS19PhysicalCoordinates", !7, i64 0}
!16 = distinct !{!16, !17}
!17 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: BDCEPass,EarlyCSEPass,GVNPass,GlobalOptPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,LICMPass,LoopIdiomRecognizePass,LoopRotatePass,LoopSimplifyPass,ReassociatePass,SROAPass,SimplifyCFGPass