; LLVM IR from alexzheng42/sDMD :: analysis (Tools)

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

@boxOrigDim = external global [4 x double], align 16
@cutoffr = external global double, align 8
@cellNum = external global [4 x double], align 16
@atomnum = external global i32, align 4
@cellSize = external global [4 x double], align 16
@celllist = external global ptr, align 8

; 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: nounwind uwtable
define dso_local void @EstCell() #1 {
  %1 = alloca i32, align 4
  %2 = alloca i32, align 4
  call void @llvm.lifetime.start.p0(i64 4, ptr %1) #5
  store i32 1, ptr %1, align 4, !tbaa !5
  br label %3

3:                                                ; preds = %28, %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) #5
  br label %31

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 @boxOrigDim, 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 = load i32, ptr %1, align 4, !tbaa !5
  %16 = sext i32 %15 to i64
  %17 = getelementptr inbounds [4 x double], ptr @cellNum, i64 0, i64 %16
  store double %14, ptr %17, align 8, !tbaa !9
  %18 = load i32, ptr %1, align 4, !tbaa !5
  %19 = sext i32 %18 to i64
  %20 = getelementptr inbounds [4 x double], ptr @cellNum, i64 0, i64 %19
  %21 = load double, ptr %20, align 8, !tbaa !9
  %22 = fcmp olt double %21, 3.000000e+00
  br i1 %22, label %23, label %27

23:                                               ; preds = %7
  %24 = load i32, ptr %1, align 4, !tbaa !5
  %25 = sext i32 %24 to i64
  %26 = getelementptr inbounds [4 x double], ptr @cellNum, i64 0, i64 %25
  store double 3.000000e+00, ptr %26, align 8, !tbaa !9
  br label %27

27:                                               ; preds = %23, %7
  br label %28

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

31:                                               ; preds = %6
  %32 = load i32, ptr @atomnum, align 4, !tbaa !5
  %33 = sitofp i32 %32 to double
  %34 = load double, ptr getelementptr inbounds ([4 x double], ptr @cellNum, i64 0, i64 1), align 8, !tbaa !9
  %35 = load double, ptr getelementptr inbounds ([4 x double], ptr @cellNum, i64 0, i64 2), align 16, !tbaa !9
  %36 = fmul double %34, %35
  %37 = load double, ptr getelementptr inbounds ([4 x double], ptr @cellNum, i64 0, i64 3), align 8, !tbaa !9
  %38 = call double @llvm.fmuladd.f64(double %36, double %37, double %33)
  %39 = fadd double %38, 1.000000e+00
  store double %39, ptr @cellNum, align 16, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %2) #5
  store i32 1, ptr %2, align 4, !tbaa !5
  br label %40

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

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

44:                                               ; preds = %40
  %45 = load i32, ptr %2, align 4, !tbaa !5
  %46 = sext i32 %45 to i64
  %47 = getelementptr inbounds [4 x double], ptr @boxOrigDim, i64 0, i64 %46
  %48 = load double, ptr %47, align 8, !tbaa !9
  %49 = load i32, ptr %2, align 4, !tbaa !5
  %50 = sext i32 %49 to i64
  %51 = getelementptr inbounds [4 x double], ptr @cellNum, i64 0, i64 %50
  %52 = load double, ptr %51, align 8, !tbaa !9
  %53 = fdiv double %48, %52
  %54 = load i32, ptr %2, align 4, !tbaa !5
  %55 = sext i32 %54 to i64
  %56 = getelementptr inbounds [4 x double], ptr @cellSize, i64 0, i64 %55
  store double %53, ptr %56, align 8, !tbaa !9
  br label %57

57:                                               ; preds = %44
  %58 = load i32, ptr %2, align 4, !tbaa !5
  %59 = add nsw i32 %58, 1
  store i32 %59, ptr %2, align 4, !tbaa !5
  br label %40, !llvm.loop !13

60:                                               ; preds = %43
  %61 = load ptr, ptr @celllist, align 8, !tbaa !14
  %62 = icmp ne ptr %61, null
  br i1 %62, label %63, label %65

63:                                               ; preds = %60
  %64 = load ptr, ptr @celllist, align 8, !tbaa !14
  call void @free(ptr noundef %64) #5
  store ptr null, ptr @celllist, align 8, !tbaa !14
  br label %65

65:                                               ; preds = %63, %60
  %66 = load double, ptr @cellNum, align 16, !tbaa !9
  %67 = fptoui double %66 to i64
  %68 = call noalias ptr @calloc(i64 noundef %67, i64 noundef 4) #6
  store ptr %68, ptr @celllist, align 8, !tbaa !14
  ret void
}

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

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

; Function Attrs: nounwind
declare void @free(ptr noundef) #3

; Function Attrs: nounwind allocsize(0,1)
declare noalias ptr @calloc(i64 noundef, i64 noundef) #4

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 "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 allocsize(0,1) "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 }
attributes #6 = { nounwind allocsize(0,1) }

!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}
!14 = !{!15, !15, i64 0}
!15 = !{!"any pointer", !7, i64 0}


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

@boxOrigDim = external local_unnamed_addr global [4 x double], align 16
@cutoffr = external local_unnamed_addr global double, align 8
@cellNum = external local_unnamed_addr global [4 x double], align 16
@atomnum = external local_unnamed_addr global i32, align 4
@cellSize = external local_unnamed_addr global [4 x double], align 16
@celllist = external local_unnamed_addr global ptr, align 8

; Function Attrs: mustprogress nounwind willreturn uwtable
define dso_local void @EstCell() local_unnamed_addr #0 {
  %1 = load double, ptr @cutoffr, align 8, !tbaa !5
  %2 = load <2 x double>, ptr getelementptr inbounds (i8, ptr @boxOrigDim, 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 = fcmp olt <2 x double> %6, <double 3.000000e+00, double 3.000000e+00>
  %8 = select <2 x i1> %7, <2 x double> <double 3.000000e+00, double 3.000000e+00>, <2 x double> %6
  store <2 x double> %8, ptr getelementptr inbounds (i8, ptr @cellNum, i64 8), align 8, !tbaa !5
  %9 = load double, ptr getelementptr inbounds (i8, ptr @boxOrigDim, i64 24), align 8, !tbaa !5
  %10 = fdiv double %9, %1
  %11 = tail call double @llvm.floor.f64(double %10)
  %12 = fcmp olt double %11, 3.000000e+00
  %storemerge.2 = select i1 %12, double 3.000000e+00, double %11
  store double %storemerge.2, ptr getelementptr inbounds (i8, ptr @cellNum, i64 24), align 8, !tbaa !5
  %13 = load i32, ptr @atomnum, align 4, !tbaa !9
  %14 = sitofp i32 %13 to double
  %shift = shufflevector <2 x double> %8, <2 x double> poison, <2 x i32> <i32 1, i32 poison>
  %15 = fmul <2 x double> %8, %shift
  %16 = extractelement <2 x double> %15, i64 0
  %17 = tail call double @llvm.fmuladd.f64(double %16, double %storemerge.2, double %14)
  %18 = fadd double %17, 1.000000e+00
  store double %18, ptr @cellNum, align 16, !tbaa !5
  %19 = fdiv <2 x double> %2, %8
  store <2 x double> %19, ptr getelementptr inbounds (i8, ptr @cellSize, i64 8), align 8, !tbaa !5
  %20 = fdiv double %9, %storemerge.2
  store double %20, ptr getelementptr inbounds (i8, ptr @cellSize, i64 24), align 8, !tbaa !5
  %21 = load ptr, ptr @celllist, align 8, !tbaa !11
  %.not = icmp eq ptr %21, null
  br i1 %.not, label %23, label %22

22:                                               ; preds = %0
  tail call void @free(ptr noundef nonnull %21) #5
  %.pre = load double, ptr @cellNum, align 16, !tbaa !5
  br label %23

23:                                               ; preds = %22, %0
  %24 = phi double [ %.pre, %22 ], [ %18, %0 ]
  %25 = fptoui double %24 to i64
  %26 = tail call noalias ptr @calloc(i64 noundef %25, i64 noundef 4) #6
  store ptr %26, ptr @celllist, align 8, !tbaa !11
  ret void
}

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

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

; Function Attrs: mustprogress nounwind willreturn allockind("free") memory(argmem: readwrite, inaccessiblemem: readwrite)
declare void @free(ptr allocptr nocapture noundef) local_unnamed_addr #2

; Function Attrs: mustprogress nofree nounwind willreturn allockind("alloc,zeroed") allocsize(0,1) memory(inaccessiblemem: readwrite)
declare noalias noundef ptr @calloc(i64 noundef, i64 noundef) local_unnamed_addr #3

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

attributes #0 = { mustprogress nounwind willreturn 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 = { mustprogress nounwind willreturn allockind("free") memory(argmem: readwrite, inaccessiblemem: readwrite) "alloc-family"="malloc" "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 nofree nounwind willreturn allockind("alloc,zeroed") allocsize(0,1) memory(inaccessiblemem: readwrite) "alloc-family"="malloc" "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 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #5 = { nounwind }
attributes #6 = { nounwind allocsize(0,1) }

!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}
!11 = !{!12, !12, i64 0}
!12 = !{!"any pointer", !7, i64 0}


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