; LLVM IR from bondhugula/pluto :: examples/apop (apop)

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

@C = external dso_local global [3 x [2000001 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: 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 @computeCoeffs(double noundef %0, double noundef %1, double noundef %2, i32 noundef %3, i32 noundef %4) #1 {
  %6 = alloca double, align 8
  %7 = alloca double, align 8
  %8 = alloca double, align 8
  %9 = alloca i32, align 4
  %10 = alloca i32, align 4
  %11 = alloca double, align 8
  %12 = alloca double, align 8
  %13 = alloca double, align 8
  %14 = alloca double, align 8
  %15 = alloca i32, align 4
  store double %0, ptr %6, align 8, !tbaa !5
  store double %1, ptr %7, align 8, !tbaa !5
  store double %2, ptr %8, align 8, !tbaa !5
  store i32 %3, ptr %9, align 4, !tbaa !9
  store i32 %4, ptr %10, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #3
  %16 = load double, ptr %7, align 8, !tbaa !5
  %17 = load double, ptr %7, align 8, !tbaa !5
  %18 = fmul double %16, %17
  store double %18, ptr %11, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %12) #3
  %19 = load double, ptr %8, align 8, !tbaa !5
  %20 = load i32, ptr %10, align 4, !tbaa !9
  %21 = sitofp i32 %20 to double
  %22 = fdiv double %19, %21
  store double %22, ptr %12, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %13) #3
  %23 = load double, ptr %6, align 8, !tbaa !5
  %24 = load double, ptr %12, align 8, !tbaa !5
  %25 = call double @llvm.fmuladd.f64(double %23, double %24, double 1.000000e+00)
  %26 = fdiv double 1.000000e+00, %25
  store double %26, ptr %13, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %14) #3
  %27 = load double, ptr %12, align 8, !tbaa !5
  %28 = load double, ptr %6, align 8, !tbaa !5
  %29 = load double, ptr %12, align 8, !tbaa !5
  %30 = call double @llvm.fmuladd.f64(double %28, double %29, double 1.000000e+00)
  %31 = fdiv double %27, %30
  store double %31, ptr %14, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %15) #3
  store i32 0, ptr %15, align 4, !tbaa !9
  br label %32

32:                                               ; preds = %81, %5
  %33 = load i32, ptr %15, align 4, !tbaa !9
  %34 = load i32, ptr %9, align 4, !tbaa !9
  %35 = icmp sle i32 %33, %34
  br i1 %35, label %36, label %84

36:                                               ; preds = %32
  %37 = load double, ptr %14, align 8, !tbaa !5
  %38 = fmul double %37, 5.000000e-01
  %39 = load i32, ptr %15, align 4, !tbaa !9
  %40 = sitofp i32 %39 to double
  %41 = fmul double %38, %40
  %42 = load double, ptr %6, align 8, !tbaa !5
  %43 = fneg double %42
  %44 = load double, ptr %11, align 8, !tbaa !5
  %45 = load i32, ptr %15, align 4, !tbaa !9
  %46 = sitofp i32 %45 to double
  %47 = call double @llvm.fmuladd.f64(double %44, double %46, double %43)
  %48 = fmul double %41, %47
  %49 = load i32, ptr %15, align 4, !tbaa !9
  %50 = sext i32 %49 to i64
  %51 = getelementptr inbounds [2000001 x double], ptr @C, i64 0, i64 %50
  store double %48, ptr %51, align 8, !tbaa !5
  %52 = load double, ptr %13, align 8, !tbaa !5
  %53 = load double, ptr %11, align 8, !tbaa !5
  %54 = load i32, ptr %15, align 4, !tbaa !9
  %55 = sitofp i32 %54 to double
  %56 = fmul double %53, %55
  %57 = load i32, ptr %15, align 4, !tbaa !9
  %58 = sitofp i32 %57 to double
  %59 = fmul double %56, %58
  %60 = load double, ptr %12, align 8, !tbaa !5
  %61 = fneg double %59
  %62 = call double @llvm.fmuladd.f64(double %61, double %60, double 1.000000e+00)
  %63 = fmul double %52, %62
  %64 = load i32, ptr %15, align 4, !tbaa !9
  %65 = sext i32 %64 to i64
  %66 = getelementptr inbounds [2000001 x double], ptr getelementptr inbounds ([3 x [2000001 x double]], ptr @C, i64 0, i64 1), i64 0, i64 %65
  store double %63, ptr %66, align 8, !tbaa !5
  %67 = load double, ptr %14, align 8, !tbaa !5
  %68 = fmul double %67, 5.000000e-01
  %69 = load i32, ptr %15, align 4, !tbaa !9
  %70 = sitofp i32 %69 to double
  %71 = fmul double %68, %70
  %72 = load double, ptr %6, align 8, !tbaa !5
  %73 = load double, ptr %11, align 8, !tbaa !5
  %74 = load i32, ptr %15, align 4, !tbaa !9
  %75 = sitofp i32 %74 to double
  %76 = call double @llvm.fmuladd.f64(double %73, double %75, double %72)
  %77 = fmul double %71, %76
  %78 = load i32, ptr %15, align 4, !tbaa !9
  %79 = sext i32 %78 to i64
  %80 = getelementptr inbounds [2000001 x double], ptr getelementptr inbounds ([3 x [2000001 x double]], ptr @C, i64 0, i64 2), i64 0, i64 %79
  store double %77, ptr %80, align 8, !tbaa !5
  br label %81

81:                                               ; preds = %36
  %82 = load i32, ptr %15, align 4, !tbaa !9
  %83 = add nsw i32 %82, 1
  store i32 %83, ptr %15, align 4, !tbaa !9
  br label %32, !llvm.loop !11

84:                                               ; preds = %32
  call void @llvm.lifetime.end.p0(i64 4, ptr %15) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %14) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %13) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #3
  ret void
}

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare double @llvm.fmuladd.f64(double, double, 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 = !{!"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 = distinct !{!11, !12}
!12 = !{!"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"

@C = external dso_local local_unnamed_addr global [3 x [2000001 x double]], align 16

; Function Attrs: nofree norecurse nosync nounwind memory(write, argmem: none, inaccessiblemem: none) uwtable
define dso_local void @computeCoeffs(double noundef %0, double noundef %1, double noundef %2, i32 noundef %3, i32 noundef %4) local_unnamed_addr #0 {
  %6 = fmul double %1, %1
  %7 = sitofp i32 %4 to double
  %8 = fdiv double %2, %7
  %9 = tail call double @llvm.fmuladd.f64(double %0, double %8, double 1.000000e+00)
  %10 = fdiv double 1.000000e+00, %9
  %.not29 = icmp slt i32 %3, 0
  br i1 %.not29, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %5
  %11 = fdiv double %8, %9
  %12 = fmul double %11, 5.000000e-01
  %13 = fneg double %0
  %14 = fneg double %6
  %15 = add nuw i32 %3, 1
  %wide.trip.count = zext i32 %15 to i64
  %min.iters.check = icmp eq i32 %3, 0
  br i1 %min.iters.check, label %scalar.ph.preheader, label %vector.ph

vector.ph:                                        ; preds = %.lr.ph
  %n.vec = and i64 %wide.trip.count, 4294967294
  %broadcast.splatinsert = insertelement <2 x double> poison, double %12, i64 0
  %broadcast.splat = shufflevector <2 x double> %broadcast.splatinsert, <2 x double> poison, <2 x i32> zeroinitializer
  %broadcast.splatinsert32 = insertelement <2 x double> poison, double %6, i64 0
  %broadcast.splat33 = shufflevector <2 x double> %broadcast.splatinsert32, <2 x double> poison, <2 x i32> zeroinitializer
  %broadcast.splatinsert34 = insertelement <2 x double> poison, double %13, i64 0
  %broadcast.splat35 = shufflevector <2 x double> %broadcast.splatinsert34, <2 x double> poison, <2 x i32> zeroinitializer
  %broadcast.splatinsert36 = insertelement <2 x double> poison, double %14, i64 0
  %broadcast.splat37 = shufflevector <2 x double> %broadcast.splatinsert36, <2 x double> poison, <2 x i32> zeroinitializer
  %broadcast.splatinsert38 = insertelement <2 x double> poison, double %8, i64 0
  %broadcast.splat39 = shufflevector <2 x double> %broadcast.splatinsert38, <2 x double> poison, <2 x i32> zeroinitializer
  %broadcast.splatinsert40 = insertelement <2 x double> poison, double %10, i64 0
  %broadcast.splat41 = shufflevector <2 x double> %broadcast.splatinsert40, <2 x double> poison, <2 x i32> zeroinitializer
  %broadcast.splatinsert42 = insertelement <2 x double> poison, double %0, i64 0
  %broadcast.splat43 = shufflevector <2 x double> %broadcast.splatinsert42, <2 x double> poison, <2 x i32> zeroinitializer
  br label %vector.body

vector.body:                                      ; preds = %vector.body, %vector.ph
  %index = phi i64 [ 0, %vector.ph ], [ %index.next, %vector.body ]
  %vec.ind = phi <2 x i32> [ <i32 0, i32 1>, %vector.ph ], [ %vec.ind.next, %vector.body ]
  %16 = uitofp <2 x i32> %vec.ind to <2 x double>
  %17 = fmul <2 x double> %broadcast.splat, %16
  %18 = tail call <2 x double> @llvm.fmuladd.v2f64(<2 x double> %broadcast.splat33, <2 x double> %16, <2 x double> %broadcast.splat35)
  %19 = fmul <2 x double> %17, %18
  %20 = getelementptr inbounds [2000001 x double], ptr @C, i64 0, i64 %index
  store <2 x double> %19, ptr %20, align 16, !tbaa !5
  %21 = fmul <2 x double> %broadcast.splat37, %16
  %22 = fmul <2 x double> %21, %16
  %23 = tail call <2 x double> @llvm.fmuladd.v2f64(<2 x double> %22, <2 x double> %broadcast.splat39, <2 x double> <double 1.000000e+00, double 1.000000e+00>)
  %24 = fmul <2 x double> %broadcast.splat41, %23
  %25 = getelementptr inbounds [2000001 x double], ptr getelementptr inbounds (i8, ptr @C, i64 16000008), i64 0, i64 %index
  store <2 x double> %24, ptr %25, align 8, !tbaa !5
  %26 = tail call <2 x double> @llvm.fmuladd.v2f64(<2 x double> %broadcast.splat33, <2 x double> %16, <2 x double> %broadcast.splat43)
  %27 = fmul <2 x double> %17, %26
  %28 = getelementptr inbounds [2000001 x double], ptr getelementptr inbounds (i8, ptr @C, i64 32000016), i64 0, i64 %index
  store <2 x double> %27, ptr %28, align 16, !tbaa !5
  %index.next = add nuw i64 %index, 2
  %vec.ind.next = add <2 x i32> %vec.ind, <i32 2, i32 2>
  %29 = icmp eq i64 %index.next, %n.vec
  br i1 %29, label %middle.block, label %vector.body, !llvm.loop !9

middle.block:                                     ; preds = %vector.body
  %cmp.n = icmp eq i64 %n.vec, %wide.trip.count
  br i1 %cmp.n, label %._crit_edge, label %scalar.ph.preheader

scalar.ph.preheader:                              ; preds = %middle.block, %.lr.ph
  %indvars.iv.ph = phi i64 [ 0, %.lr.ph ], [ %n.vec, %middle.block ]
  br label %scalar.ph

scalar.ph:                                        ; preds = %scalar.ph.preheader, %scalar.ph
  %indvars.iv = phi i64 [ %indvars.iv.next, %scalar.ph ], [ %indvars.iv.ph, %scalar.ph.preheader ]
  %30 = trunc nuw nsw i64 %indvars.iv to i32
  %31 = uitofp nneg i32 %30 to double
  %32 = fmul double %12, %31
  %33 = tail call double @llvm.fmuladd.f64(double %6, double %31, double %13)
  %34 = fmul double %32, %33
  %35 = getelementptr inbounds [2000001 x double], ptr @C, i64 0, i64 %indvars.iv
  store double %34, ptr %35, align 8, !tbaa !5
  %36 = fmul double %14, %31
  %37 = fmul double %36, %31
  %38 = tail call double @llvm.fmuladd.f64(double %37, double %8, double 1.000000e+00)
  %39 = fmul double %10, %38
  %40 = getelementptr inbounds [2000001 x double], ptr getelementptr inbounds (i8, ptr @C, i64 16000008), i64 0, i64 %indvars.iv
  store double %39, ptr %40, align 8, !tbaa !5
  %41 = tail call double @llvm.fmuladd.f64(double %6, double %31, double %0)
  %42 = fmul double %32, %41
  %43 = getelementptr inbounds [2000001 x double], ptr getelementptr inbounds (i8, ptr @C, i64 32000016), i64 0, i64 %indvars.iv
  store double %42, ptr %43, align 8, !tbaa !5
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %exitcond.not = icmp eq i64 %indvars.iv.next, %wide.trip.count
  br i1 %exitcond.not, label %._crit_edge, label %scalar.ph, !llvm.loop !13

._crit_edge:                                      ; preds = %scalar.ph, %middle.block, %5
  ret void
}

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

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

attributes #0 = { nofree norecurse nosync nounwind memory(write, 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 = distinct !{!9, !10, !11, !12}
!10 = !{!"llvm.loop.mustprogress"}
!11 = !{!"llvm.loop.isvectorized", i32 1}
!12 = !{!"llvm.loop.unroll.runtime.disable"}
!13 = distinct !{!13, !10, !12, !11}


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