; LLVM IR from VastoLorde95/Competitive-Programming :: Codeforces/293 Division 2/Problem D (D)

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

@dp = external dso_local global [2001 x [2001 x double]], align 16
@p = external dso_local global double, align 8
@n = external dso_local global i32, align 4
@t = external dso_local global i32, align 4
@.str = external hidden unnamed_addr constant [10 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [7 x i8], align 1

; Function Attrs: mustprogress norecurse uwtable
define dso_local noundef i32 @main() #0 {
  %1 = alloca i32, align 4
  %2 = alloca i32, align 4
  %3 = alloca i32, align 4
  %4 = alloca i32, align 4
  store i32 0, ptr %1, align 4
  %5 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef @n, ptr noundef @p, ptr noundef @t)
  call void @llvm.lifetime.start.p0(i64 4, ptr %2) #4
  store i32 1, ptr %2, align 4, !tbaa !5
  br label %6

6:                                                ; preds = %51, %0
  %7 = load i32, ptr %2, align 4, !tbaa !5
  %8 = load i32, ptr @t, align 4, !tbaa !5
  %9 = icmp sle i32 %7, %8
  br i1 %9, label %11, label %10

10:                                               ; preds = %6
  store i32 2, ptr %3, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %2) #4
  br label %54

11:                                               ; preds = %6
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #4
  store i32 1, ptr %4, align 4, !tbaa !5
  br label %12

12:                                               ; preds = %47, %11
  %13 = load i32, ptr %4, align 4, !tbaa !5
  %14 = load i32, ptr @n, align 4, !tbaa !5
  %15 = icmp sle i32 %13, %14
  br i1 %15, label %17, label %16

16:                                               ; preds = %12
  store i32 5, ptr %3, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #4
  br label %50

17:                                               ; preds = %12
  %18 = load double, ptr @p, align 8, !tbaa !9
  %19 = load i32, ptr %2, align 4, !tbaa !5
  %20 = sub nsw i32 %19, 1
  %21 = sext i32 %20 to i64
  %22 = getelementptr inbounds [2001 x [2001 x double]], ptr @dp, i64 0, i64 %21
  %23 = load i32, ptr %4, align 4, !tbaa !5
  %24 = sub nsw i32 %23, 1
  %25 = sext i32 %24 to i64
  %26 = getelementptr inbounds [2001 x double], ptr %22, i64 0, i64 %25
  %27 = load double, ptr %26, align 8, !tbaa !9
  %28 = fadd double 1.000000e+00, %27
  %29 = load double, ptr @p, align 8, !tbaa !9
  %30 = fsub double 1.000000e+00, %29
  %31 = load i32, ptr %2, align 4, !tbaa !5
  %32 = sub nsw i32 %31, 1
  %33 = sext i32 %32 to i64
  %34 = getelementptr inbounds [2001 x [2001 x double]], ptr @dp, i64 0, i64 %33
  %35 = load i32, ptr %4, align 4, !tbaa !5
  %36 = sext i32 %35 to i64
  %37 = getelementptr inbounds [2001 x double], ptr %34, i64 0, i64 %36
  %38 = load double, ptr %37, align 8, !tbaa !9
  %39 = fmul double %30, %38
  %40 = call double @llvm.fmuladd.f64(double %18, double %28, double %39)
  %41 = load i32, ptr %2, align 4, !tbaa !5
  %42 = sext i32 %41 to i64
  %43 = getelementptr inbounds [2001 x [2001 x double]], ptr @dp, i64 0, i64 %42
  %44 = load i32, ptr %4, align 4, !tbaa !5
  %45 = sext i32 %44 to i64
  %46 = getelementptr inbounds [2001 x double], ptr %43, i64 0, i64 %45
  store double %40, ptr %46, align 8, !tbaa !9
  br label %47

47:                                               ; preds = %17
  %48 = load i32, ptr %4, align 4, !tbaa !5
  %49 = add nsw i32 %48, 1
  store i32 %49, ptr %4, align 4, !tbaa !5
  br label %12, !llvm.loop !11

50:                                               ; preds = %16
  br label %51

51:                                               ; preds = %50
  %52 = load i32, ptr %2, align 4, !tbaa !5
  %53 = add nsw i32 %52, 1
  store i32 %53, ptr %2, align 4, !tbaa !5
  br label %6, !llvm.loop !13

54:                                               ; preds = %10
  %55 = load i32, ptr @t, align 4, !tbaa !5
  %56 = sext i32 %55 to i64
  %57 = getelementptr inbounds [2001 x [2001 x double]], ptr @dp, i64 0, i64 %56
  %58 = load i32, ptr @n, align 4, !tbaa !5
  %59 = sext i32 %58 to i64
  %60 = getelementptr inbounds [2001 x double], ptr %57, i64 0, i64 %59
  %61 = load double, ptr %60, align 8, !tbaa !9
  %62 = call i32 (ptr, ...) @printf(ptr noundef @.str.1, double noundef %61)
  ret i32 0
}

declare i32 @__isoc99_scanf(ptr noundef, ...) #1

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

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

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

declare i32 @printf(ptr noundef, ...) #1

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

@dp = external dso_local local_unnamed_addr global [2001 x [2001 x double]], align 16
@p = external dso_local global double, align 8
@n = external dso_local global i32, align 4
@t = external dso_local global i32, align 4
@.str = external hidden unnamed_addr constant [10 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [7 x i8], align 1

; Function Attrs: mustprogress nofree norecurse nounwind uwtable
define dso_local noundef i32 @main() local_unnamed_addr #0 {
  %1 = tail call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull @n, ptr noundef nonnull @p, ptr noundef nonnull @t)
  %2 = load i32, ptr @t, align 4, !tbaa !5
  %.not15 = icmp slt i32 %2, 1
  %.pre25 = load i32, ptr @n, align 4, !tbaa !5
  br i1 %.not15, label %._crit_edge17, label %.preheader.lr.ph

.preheader.lr.ph:                                 ; preds = %0
  %.not1213 = icmp slt i32 %.pre25, 1
  %3 = load double, ptr @p, align 8
  %4 = fsub double 1.000000e+00, %3
  br i1 %.not1213, label %._crit_edge17, label %.preheader.preheader

.preheader.preheader:                             ; preds = %.preheader.lr.ph
  %5 = add nuw i32 %.pre25, 1
  %6 = add nuw i32 %2, 1
  %wide.trip.count23 = zext i32 %6 to i64
  %wide.trip.count = zext i32 %5 to i64
  %7 = zext nneg i32 %.pre25 to i64
  %min.iters.check = icmp eq i32 %.pre25, 1
  %n.vec = and i64 %7, 2147483646
  %ind.end = or i64 %7, 1
  %broadcast.splatinsert = insertelement <2 x double> poison, double %4, i64 0
  %broadcast.splat = shufflevector <2 x double> %broadcast.splatinsert, <2 x double> poison, <2 x i32> zeroinitializer
  %broadcast.splatinsert26 = insertelement <2 x double> poison, double %3, i64 0
  %broadcast.splat27 = shufflevector <2 x double> %broadcast.splatinsert26, <2 x double> poison, <2 x i32> zeroinitializer
  %cmp.n = icmp eq i64 %n.vec, %7
  br label %.preheader

.preheader:                                       ; preds = %.preheader.preheader, %._crit_edge
  %indvars.iv20 = phi i64 [ 1, %.preheader.preheader ], [ %indvars.iv.next21, %._crit_edge ]
  %8 = add nsw i64 %indvars.iv20, -1
  %.phi.trans.insert = getelementptr inbounds [2001 x [2001 x double]], ptr @dp, i64 0, i64 %8, i64 0
  %.pre = load double, ptr %.phi.trans.insert, align 8, !tbaa !9
  br i1 %min.iters.check, label %scalar.ph.preheader, label %vector.ph

scalar.ph.preheader:                              ; preds = %middle.block, %.preheader
  %.ph = phi double [ %.pre, %.preheader ], [ %vector.recur.extract, %middle.block ]
  %indvars.iv.ph = phi i64 [ 1, %.preheader ], [ %ind.end, %middle.block ]
  br label %scalar.ph

vector.ph:                                        ; preds = %.preheader
  %vector.recur.init = insertelement <2 x double> poison, double %.pre, i64 1
  br label %vector.body

vector.body:                                      ; preds = %vector.body, %vector.ph
  %index = phi i64 [ 0, %vector.ph ], [ %index.next, %vector.body ]
  %vector.recur = phi <2 x double> [ %vector.recur.init, %vector.ph ], [ %wide.load, %vector.body ]
  %offset.idx = or disjoint i64 %index, 1
  %9 = getelementptr inbounds [2001 x [2001 x double]], ptr @dp, i64 0, i64 %8, i64 %offset.idx
  %wide.load = load <2 x double>, ptr %9, align 8, !tbaa !9
  %10 = shufflevector <2 x double> %vector.recur, <2 x double> %wide.load, <2 x i32> <i32 1, i32 2>
  %11 = fadd <2 x double> %10, <double 1.000000e+00, double 1.000000e+00>
  %12 = fmul <2 x double> %broadcast.splat, %wide.load
  %13 = tail call <2 x double> @llvm.fmuladd.v2f64(<2 x double> %broadcast.splat27, <2 x double> %11, <2 x double> %12)
  %14 = getelementptr inbounds [2001 x [2001 x double]], ptr @dp, i64 0, i64 %indvars.iv20, i64 %offset.idx
  store <2 x double> %13, ptr %14, align 8, !tbaa !9
  %index.next = add nuw i64 %index, 2
  %15 = icmp eq i64 %index.next, %n.vec
  br i1 %15, label %middle.block, label %vector.body, !llvm.loop !11

middle.block:                                     ; preds = %vector.body
  %vector.recur.extract = extractelement <2 x double> %wide.load, i64 1
  br i1 %cmp.n, label %._crit_edge, label %scalar.ph.preheader

._crit_edge17:                                    ; preds = %._crit_edge, %.preheader.lr.ph, %0
  %16 = sext i32 %2 to i64
  %17 = sext i32 %.pre25 to i64
  %18 = getelementptr inbounds [2001 x [2001 x double]], ptr @dp, i64 0, i64 %16, i64 %17
  %19 = load double, ptr %18, align 8, !tbaa !9
  %20 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.1, double noundef %19)
  ret i32 0

._crit_edge:                                      ; preds = %scalar.ph, %middle.block
  %indvars.iv.next21 = add nuw nsw i64 %indvars.iv20, 1
  %exitcond24.not = icmp eq i64 %indvars.iv.next21, %wide.trip.count23
  br i1 %exitcond24.not, label %._crit_edge17, label %.preheader, !llvm.loop !15

scalar.ph:                                        ; preds = %scalar.ph.preheader, %scalar.ph
  %21 = phi double [ %24, %scalar.ph ], [ %.ph, %scalar.ph.preheader ]
  %indvars.iv = phi i64 [ %indvars.iv.next, %scalar.ph ], [ %indvars.iv.ph, %scalar.ph.preheader ]
  %22 = fadd double %21, 1.000000e+00
  %23 = getelementptr inbounds [2001 x [2001 x double]], ptr @dp, i64 0, i64 %8, i64 %indvars.iv
  %24 = load double, ptr %23, align 8, !tbaa !9
  %25 = fmul double %4, %24
  %26 = tail call double @llvm.fmuladd.f64(double %3, double %22, double %25)
  %27 = getelementptr inbounds [2001 x [2001 x double]], ptr @dp, i64 0, i64 %indvars.iv20, i64 %indvars.iv
  store double %26, ptr %27, align 8, !tbaa !9
  %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 !16
}

; Function Attrs: nofree nounwind
declare noundef i32 @__isoc99_scanf(ptr nocapture noundef readonly, ...) local_unnamed_addr #1

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

; Function Attrs: nofree nounwind
declare noundef i32 @printf(ptr nocapture noundef readonly, ...) local_unnamed_addr #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>) #3

attributes #0 = { mustprogress nofree norecurse 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 #1 = { nofree 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 #2 = { mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #3 = { 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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"double", !7, i64 0}
!11 = distinct !{!11, !12, !13, !14}
!12 = !{!"llvm.loop.mustprogress"}
!13 = !{!"llvm.loop.isvectorized", i32 1}
!14 = !{!"llvm.loop.unroll.runtime.disable"}
!15 = distinct !{!15, !12}
!16 = distinct !{!16, !12, !14, !13}


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