; LLVM IR from CLASS-SZ/class_sz :: class-sz/tools (arrays)

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

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

; Function Attrs: nounwind uwtable
define dso_local i32 @array_integrate_all(ptr noundef %0, i32 noundef %1, i32 noundef %2, i32 noundef %3, i32 noundef %4, ptr noundef %5) #2 {
  %7 = alloca ptr, align 8
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  %10 = alloca i32, align 4
  %11 = alloca i32, align 4
  %12 = alloca ptr, align 8
  %13 = alloca i32, align 4
  %14 = alloca double, align 8
  store ptr %0, ptr %7, align 8, !tbaa !5
  store i32 %1, ptr %8, align 4, !tbaa !9
  store i32 %2, ptr %9, align 4, !tbaa !9
  store i32 %3, ptr %10, align 4, !tbaa !9
  store i32 %4, ptr %11, align 4, !tbaa !9
  store ptr %5, ptr %12, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %13) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %14) #3
  store double 0.000000e+00, ptr %14, align 8, !tbaa !11
  store i32 1, ptr %13, align 4, !tbaa !9
  br label %15

15:                                               ; preds = %67, %6
  %16 = load i32, ptr %13, align 4, !tbaa !9
  %17 = load i32, ptr %9, align 4, !tbaa !9
  %18 = icmp slt i32 %16, %17
  br i1 %18, label %19, label %70

19:                                               ; preds = %15
  %20 = load ptr, ptr %7, align 8, !tbaa !5
  %21 = load i32, ptr %13, align 4, !tbaa !9
  %22 = load i32, ptr %8, align 4, !tbaa !9
  %23 = mul nsw i32 %21, %22
  %24 = sext i32 %23 to i64
  %25 = getelementptr inbounds double, ptr %20, i64 %24
  %26 = load i32, ptr %11, align 4, !tbaa !9
  %27 = sext i32 %26 to i64
  %28 = getelementptr inbounds double, ptr %25, i64 %27
  %29 = load double, ptr %28, align 8, !tbaa !11
  %30 = load ptr, ptr %7, align 8, !tbaa !5
  %31 = load i32, ptr %13, align 4, !tbaa !9
  %32 = sub nsw i32 %31, 1
  %33 = load i32, ptr %8, align 4, !tbaa !9
  %34 = mul nsw i32 %32, %33
  %35 = sext i32 %34 to i64
  %36 = getelementptr inbounds double, ptr %30, i64 %35
  %37 = load i32, ptr %11, align 4, !tbaa !9
  %38 = sext i32 %37 to i64
  %39 = getelementptr inbounds double, ptr %36, i64 %38
  %40 = load double, ptr %39, align 8, !tbaa !11
  %41 = fadd double %29, %40
  %42 = fmul double 5.000000e-01, %41
  %43 = load ptr, ptr %7, align 8, !tbaa !5
  %44 = load i32, ptr %13, align 4, !tbaa !9
  %45 = load i32, ptr %8, align 4, !tbaa !9
  %46 = mul nsw i32 %44, %45
  %47 = sext i32 %46 to i64
  %48 = getelementptr inbounds double, ptr %43, i64 %47
  %49 = load i32, ptr %10, align 4, !tbaa !9
  %50 = sext i32 %49 to i64
  %51 = getelementptr inbounds double, ptr %48, i64 %50
  %52 = load double, ptr %51, align 8, !tbaa !11
  %53 = load ptr, ptr %7, align 8, !tbaa !5
  %54 = load i32, ptr %13, align 4, !tbaa !9
  %55 = sub nsw i32 %54, 1
  %56 = load i32, ptr %8, align 4, !tbaa !9
  %57 = mul nsw i32 %55, %56
  %58 = sext i32 %57 to i64
  %59 = getelementptr inbounds double, ptr %53, i64 %58
  %60 = load i32, ptr %10, align 4, !tbaa !9
  %61 = sext i32 %60 to i64
  %62 = getelementptr inbounds double, ptr %59, i64 %61
  %63 = load double, ptr %62, align 8, !tbaa !11
  %64 = fsub double %52, %63
  %65 = load double, ptr %14, align 8, !tbaa !11
  %66 = call double @llvm.fmuladd.f64(double %42, double %64, double %65)
  store double %66, ptr %14, align 8, !tbaa !11
  br label %67

67:                                               ; preds = %19
  %68 = load i32, ptr %13, align 4, !tbaa !9
  %69 = add nsw i32 %68, 1
  store i32 %69, ptr %13, align 4, !tbaa !9
  br label %15, !llvm.loop !13

70:                                               ; preds = %15
  %71 = load double, ptr %14, align 8, !tbaa !11
  %72 = load ptr, ptr %12, align 8, !tbaa !5
  store double %71, ptr %72, align 8, !tbaa !11
  call void @llvm.lifetime.end.p0(i64 8, ptr %14) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %13) #3
  ret i32 0
}

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

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

; Function Attrs: nofree norecurse nosync nounwind memory(argmem: readwrite) uwtable
define dso_local noundef i32 @array_integrate_all(ptr nocapture noundef readonly %0, i32 noundef %1, i32 noundef %2, i32 noundef %3, i32 noundef %4, ptr nocapture noundef writeonly %5) local_unnamed_addr #1 {
  %7 = icmp sgt i32 %2, 1
  br i1 %7, label %.lr.ph, label %._crit_edge

.lr.ph:                                           ; preds = %6
  %8 = sext i32 %4 to i64
  %9 = sext i32 %3 to i64
  %10 = sext i32 %1 to i64
  %wide.trip.count = zext nneg i32 %2 to i64
  %11 = add nsw i64 %wide.trip.count, -1
  %xtraiter = and i64 %11, 1
  %12 = icmp eq i32 %2, 2
  br i1 %12, label %._crit_edge.loopexit.unr-lcssa, label %.lr.ph.new

.lr.ph.new:                                       ; preds = %.lr.ph
  %unroll_iter = and i64 %11, -2
  br label %13

13:                                               ; preds = %13, %.lr.ph.new
  %indvars.iv = phi i64 [ 1, %.lr.ph.new ], [ %indvars.iv.next.1, %13 ]
  %.023 = phi double [ 0.000000e+00, %.lr.ph.new ], [ %40, %13 ]
  %niter = phi i64 [ 0, %.lr.ph.new ], [ %niter.next.1, %13 ]
  %14 = mul nsw i64 %indvars.iv, %10
  %15 = getelementptr inbounds double, ptr %0, i64 %14
  %16 = getelementptr inbounds double, ptr %15, i64 %8
  %17 = load double, ptr %16, align 8, !tbaa !5
  %18 = add nsw i64 %indvars.iv, -1
  %19 = mul nsw i64 %18, %10
  %20 = getelementptr inbounds double, ptr %0, i64 %19
  %21 = getelementptr inbounds double, ptr %20, i64 %8
  %22 = load double, ptr %21, align 8, !tbaa !5
  %23 = fadd double %17, %22
  %24 = fmul double %23, 5.000000e-01
  %25 = getelementptr inbounds double, ptr %15, i64 %9
  %26 = load double, ptr %25, align 8, !tbaa !5
  %27 = getelementptr inbounds double, ptr %20, i64 %9
  %28 = load double, ptr %27, align 8, !tbaa !5
  %29 = fsub double %26, %28
  %30 = tail call double @llvm.fmuladd.f64(double %24, double %29, double %.023)
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %31 = mul nsw i64 %indvars.iv.next, %10
  %32 = getelementptr inbounds double, ptr %0, i64 %31
  %33 = getelementptr inbounds double, ptr %32, i64 %8
  %34 = load double, ptr %33, align 8, !tbaa !5
  %35 = fadd double %34, %17
  %36 = fmul double %35, 5.000000e-01
  %37 = getelementptr inbounds double, ptr %32, i64 %9
  %38 = load double, ptr %37, align 8, !tbaa !5
  %39 = fsub double %38, %26
  %40 = tail call double @llvm.fmuladd.f64(double %36, double %39, double %30)
  %indvars.iv.next.1 = add nuw nsw i64 %indvars.iv, 2
  %niter.next.1 = add i64 %niter, 2
  %niter.ncmp.1 = icmp eq i64 %niter.next.1, %unroll_iter
  br i1 %niter.ncmp.1, label %._crit_edge.loopexit.unr-lcssa, label %13, !llvm.loop !9

._crit_edge.loopexit.unr-lcssa:                   ; preds = %13, %.lr.ph
  %.lcssa.ph = phi double [ poison, %.lr.ph ], [ %40, %13 ]
  %indvars.iv.unr = phi i64 [ 1, %.lr.ph ], [ %indvars.iv.next.1, %13 ]
  %.023.unr = phi double [ 0.000000e+00, %.lr.ph ], [ %40, %13 ]
  %lcmp.mod.not = icmp eq i64 %xtraiter, 0
  br i1 %lcmp.mod.not, label %._crit_edge, label %._crit_edge.loopexit.epilog-lcssa

._crit_edge.loopexit.epilog-lcssa:                ; preds = %._crit_edge.loopexit.unr-lcssa
  %41 = mul nsw i64 %indvars.iv.unr, %10
  %42 = getelementptr inbounds double, ptr %0, i64 %41
  %43 = getelementptr inbounds double, ptr %42, i64 %8
  %44 = load double, ptr %43, align 8, !tbaa !5
  %45 = add nsw i64 %indvars.iv.unr, -1
  %46 = mul nsw i64 %45, %10
  %47 = getelementptr inbounds double, ptr %0, i64 %46
  %48 = getelementptr inbounds double, ptr %47, i64 %8
  %49 = load double, ptr %48, align 8, !tbaa !5
  %50 = fadd double %44, %49
  %51 = fmul double %50, 5.000000e-01
  %52 = getelementptr inbounds double, ptr %42, i64 %9
  %53 = load double, ptr %52, align 8, !tbaa !5
  %54 = getelementptr inbounds double, ptr %47, i64 %9
  %55 = load double, ptr %54, align 8, !tbaa !5
  %56 = fsub double %53, %55
  %57 = tail call double @llvm.fmuladd.f64(double %51, double %56, double %.023.unr)
  br label %._crit_edge

._crit_edge:                                      ; preds = %._crit_edge.loopexit.epilog-lcssa, %._crit_edge.loopexit.unr-lcssa, %6
  %.0.lcssa = phi double [ 0.000000e+00, %6 ], [ %.lcssa.ph, %._crit_edge.loopexit.unr-lcssa ], [ %57, %._crit_edge.loopexit.epilog-lcssa ]
  store double %.0.lcssa, ptr %5, align 8, !tbaa !5
  ret i32 0
}

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


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