; LLVM IR from alexzheng42/sDMD :: src (Initialization)

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

@boxDimension = external global [4 x double], align 16
@atomnum = external global i32, align 4
@cutoffr = external global double, align 8
@cellnum = external global [4 x i32], align 16
@cellsize = external global [4 x double], align 16

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #0

; Function Attrs: nounwind uwtable
define dso_local void @CreateCell() #1 {
  %1 = alloca i32, align 4
  %2 = alloca i32, align 4
  call void @llvm.lifetime.start.p0(i64 4, ptr %1) #3
  store i32 1, ptr %1, align 4, !tbaa !5
  br label %3

3:                                                ; preds = %29, %0
  %4 = load i32, ptr %1, align 4, !tbaa !5
  %5 = icmp sle i32 %4, 3
  br i1 %5, label %7, label %6

6:                                                ; preds = %3
  call void @llvm.lifetime.end.p0(i64 4, ptr %1) #3
  br label %32

7:                                                ; preds = %3
  %8 = load i32, ptr %1, align 4, !tbaa !5
  %9 = sext i32 %8 to i64
  %10 = getelementptr inbounds [4 x double], ptr @boxDimension, i64 0, i64 %9
  %11 = load double, ptr %10, align 8, !tbaa !9
  %12 = load double, ptr @cutoffr, align 8, !tbaa !9
  %13 = fdiv double %11, %12
  %14 = call double @llvm.floor.f64(double %13)
  %15 = fptosi double %14 to i32
  %16 = load i32, ptr %1, align 4, !tbaa !5
  %17 = sext i32 %16 to i64
  %18 = getelementptr inbounds [4 x i32], ptr @cellnum, i64 0, i64 %17
  store i32 %15, ptr %18, align 4, !tbaa !5
  %19 = load i32, ptr %1, align 4, !tbaa !5
  %20 = sext i32 %19 to i64
  %21 = getelementptr inbounds [4 x i32], ptr @cellnum, i64 0, i64 %20
  %22 = load i32, ptr %21, align 4, !tbaa !5
  %23 = icmp slt i32 %22, 3
  br i1 %23, label %24, label %28

24:                                               ; preds = %7
  %25 = load i32, ptr %1, align 4, !tbaa !5
  %26 = sext i32 %25 to i64
  %27 = getelementptr inbounds [4 x i32], ptr @cellnum, i64 0, i64 %26
  store i32 3, ptr %27, align 4, !tbaa !5
  br label %28

28:                                               ; preds = %24, %7
  br label %29

29:                                               ; preds = %28
  %30 = load i32, ptr %1, align 4, !tbaa !5
  %31 = add nsw i32 %30, 1
  store i32 %31, ptr %1, align 4, !tbaa !5
  br label %3, !llvm.loop !11

32:                                               ; preds = %6
  %33 = load i32, ptr @atomnum, align 4, !tbaa !5
  %34 = load i32, ptr getelementptr inbounds ([4 x i32], ptr @cellnum, i64 0, i64 1), align 4, !tbaa !5
  %35 = load i32, ptr getelementptr inbounds ([4 x i32], ptr @cellnum, i64 0, i64 2), align 8, !tbaa !5
  %36 = mul nsw i32 %34, %35
  %37 = load i32, ptr getelementptr inbounds ([4 x i32], ptr @cellnum, i64 0, i64 3), align 4, !tbaa !5
  %38 = mul nsw i32 %36, %37
  %39 = add nsw i32 %33, %38
  %40 = add nsw i32 %39, 1
  store i32 %40, ptr @cellnum, align 16, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %2) #3
  store i32 1, ptr %2, align 4, !tbaa !5
  br label %41

41:                                               ; preds = %59, %32
  %42 = load i32, ptr %2, align 4, !tbaa !5
  %43 = icmp sle i32 %42, 3
  br i1 %43, label %45, label %44

44:                                               ; preds = %41
  call void @llvm.lifetime.end.p0(i64 4, ptr %2) #3
  br label %62

45:                                               ; preds = %41
  %46 = load i32, ptr %2, align 4, !tbaa !5
  %47 = sext i32 %46 to i64
  %48 = getelementptr inbounds [4 x double], ptr @boxDimension, i64 0, i64 %47
  %49 = load double, ptr %48, align 8, !tbaa !9
  %50 = load i32, ptr %2, align 4, !tbaa !5
  %51 = sext i32 %50 to i64
  %52 = getelementptr inbounds [4 x i32], ptr @cellnum, i64 0, i64 %51
  %53 = load i32, ptr %52, align 4, !tbaa !5
  %54 = sitofp i32 %53 to double
  %55 = fdiv double %49, %54
  %56 = load i32, ptr %2, align 4, !tbaa !5
  %57 = sext i32 %56 to i64
  %58 = getelementptr inbounds [4 x double], ptr @cellsize, i64 0, i64 %57
  store double %55, ptr %58, align 8, !tbaa !9
  br label %59

59:                                               ; preds = %45
  %60 = load i32, ptr %2, align 4, !tbaa !5
  %61 = add nsw i32 %60, 1
  store i32 %61, ptr %2, align 4, !tbaa !5
  br label %41, !llvm.loop !13

62:                                               ; preds = %44
  ret void
}

; 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 nosync nounwind speculatable willreturn memory(none)
declare double @llvm.floor.f64(double) #2

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 #2 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"double", !7, i64 0}
!11 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}
!13 = distinct !{!13, !12}


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

@boxDimension = external local_unnamed_addr global [4 x double], align 16
@atomnum = external local_unnamed_addr global i32, align 4
@cutoffr = external local_unnamed_addr global double, align 8
@cellnum = external local_unnamed_addr global [4 x i32], align 16
@cellsize = external local_unnamed_addr global [4 x double], align 16

; Function Attrs: mustprogress nofree norecurse nosync nounwind willreturn memory(readwrite, argmem: none, inaccessiblemem: none) uwtable
define dso_local void @CreateCell() local_unnamed_addr #0 {
  %1 = load double, ptr @cutoffr, align 8, !tbaa !5
  %2 = load <2 x double>, ptr getelementptr inbounds (i8, ptr @boxDimension, i64 8), align 8, !tbaa !5
  %3 = insertelement <2 x double> poison, double %1, i64 0
  %4 = shufflevector <2 x double> %3, <2 x double> poison, <2 x i32> zeroinitializer
  %5 = fdiv <2 x double> %2, %4
  %6 = tail call <2 x double> @llvm.floor.v2f64(<2 x double> %5)
  %7 = fptosi <2 x double> %6 to <2 x i32>
  %8 = tail call <2 x i32> @llvm.smax.v2i32(<2 x i32> %7, <2 x i32> <i32 3, i32 3>)
  store <2 x i32> %8, ptr getelementptr inbounds (i8, ptr @cellnum, i64 4), align 4, !tbaa !9
  %9 = load double, ptr getelementptr inbounds (i8, ptr @boxDimension, i64 24), align 8, !tbaa !5
  %10 = fdiv double %9, %1
  %11 = tail call double @llvm.floor.f64(double %10)
  %12 = fptosi double %11 to i32
  %spec.select.2 = tail call i32 @llvm.smax.i32(i32 %12, i32 3)
  store i32 %spec.select.2, ptr getelementptr inbounds (i8, ptr @cellnum, i64 12), align 4, !tbaa !9
  %13 = load i32, ptr @atomnum, align 4, !tbaa !9
  %14 = extractelement <2 x i32> %8, i64 0
  %15 = extractelement <2 x i32> %8, i64 1
  %16 = mul nuw nsw i32 %15, %14
  %17 = mul nuw nsw i32 %16, %spec.select.2
  %18 = add i32 %13, 1
  %19 = add i32 %18, %17
  store i32 %19, ptr @cellnum, align 16, !tbaa !9
  %20 = uitofp nneg <2 x i32> %8 to <2 x double>
  %21 = fdiv <2 x double> %2, %20
  store <2 x double> %21, ptr getelementptr inbounds (i8, ptr @cellsize, i64 8), align 8, !tbaa !5
  %22 = uitofp nneg i32 %spec.select.2 to double
  %23 = fdiv double %9, %22
  store double %23, ptr getelementptr inbounds (i8, ptr @cellsize, i64 24), align 8, !tbaa !5
  ret void
}

; Function Attrs: mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare double @llvm.floor.f64(double) #1

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i32 @llvm.smax.i32(i32, i32) #2

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare <2 x double> @llvm.floor.v2f64(<2 x double>) #2

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare <2 x i32> @llvm.smax.v2i32(<2 x i32>, <2 x i32>) #2

attributes #0 = { mustprogress nofree norecurse nosync nounwind willreturn memory(readwrite, argmem: none, inaccessiblemem: none) 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 = { mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #2 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }

!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 = !{!"double", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"int", !7, i64 0}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,IndVarSimplifyPass,InferAlignmentPass,InferFunctionAttrsPass,InstCombinePass,LICMPass,LoopRotatePass,PostOrderFunctionAttrsPass,ReassociatePass,SCCPPass,SLPVectorizerPass,SROAPass,SimplifyCFGPass,TailCallElimPass