; LLVM IR from VastoLorde95/Competitive-Programming :: Hackerrank/Company Contests/Cisco iCode/iCode/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"

@t = external dso_local global i32, align 4
@n = external dso_local global i32, align 4
@k = external dso_local global i32, align 4
@dp = external dso_local global [1001 x [1001 x double]], align 16
@p = external dso_local global [1001 x double], align 16
@.str = external hidden unnamed_addr constant [3 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [5 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [4 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [16 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
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  store i32 0, ptr %1, align 4
  %7 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, 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 %8

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

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

13:                                               ; preds = %8
  %14 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str.1, ptr noundef @n, ptr noundef @k)
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #4
  store i32 1, ptr %4, align 4, !tbaa !5
  br label %15

15:                                               ; preds = %25, %13
  %16 = load i32, ptr %4, align 4, !tbaa !5
  %17 = load i32, ptr @n, align 4, !tbaa !5
  %18 = icmp sle i32 %16, %17
  br i1 %18, label %20, label %19

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

20:                                               ; preds = %15
  %21 = load i32, ptr %4, align 4, !tbaa !5
  %22 = sext i32 %21 to i64
  %23 = getelementptr inbounds double, ptr @p, i64 %22
  %24 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str.2, ptr noundef %23)
  br label %25

25:                                               ; preds = %20
  %26 = load i32, ptr %4, align 4, !tbaa !5
  %27 = add nsw i32 %26, 1
  store i32 %27, ptr %4, align 4, !tbaa !5
  br label %15, !llvm.loop !9

28:                                               ; preds = %19
  store double 1.000000e+00, ptr @dp, align 16, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #4
  store i32 1, ptr %5, align 4, !tbaa !5
  br label %29

29:                                               ; preds = %90, %28
  %30 = load i32, ptr %5, align 4, !tbaa !5
  %31 = load i32, ptr @n, align 4, !tbaa !5
  %32 = icmp sle i32 %30, %31
  br i1 %32, label %34, label %33

33:                                               ; preds = %29
  store i32 8, ptr %3, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #4
  br label %93

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

35:                                               ; preds = %86, %34
  %36 = load i32, ptr %6, align 4, !tbaa !5
  %37 = load i32, ptr @k, align 4, !tbaa !5
  %38 = icmp sle i32 %36, %37
  br i1 %38, label %40, label %39

39:                                               ; preds = %35
  store i32 11, ptr %3, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #4
  br label %89

40:                                               ; preds = %35
  %41 = load i32, ptr %5, align 4, !tbaa !5
  %42 = sub nsw i32 %41, 1
  %43 = sext i32 %42 to i64
  %44 = getelementptr inbounds [1001 x [1001 x double]], ptr @dp, i64 0, i64 %43
  %45 = load i32, ptr %6, align 4, !tbaa !5
  %46 = sext i32 %45 to i64
  %47 = getelementptr inbounds [1001 x double], ptr %44, i64 0, i64 %46
  %48 = load double, ptr %47, align 8, !tbaa !11
  %49 = load i32, ptr %5, align 4, !tbaa !5
  %50 = sext i32 %49 to i64
  %51 = getelementptr inbounds [1001 x double], ptr @p, i64 0, i64 %50
  %52 = load double, ptr %51, align 8, !tbaa !11
  %53 = fsub double 1.000000e+00, %52
  %54 = fmul double %48, %53
  %55 = load i32, ptr %5, align 4, !tbaa !5
  %56 = sext i32 %55 to i64
  %57 = getelementptr inbounds [1001 x [1001 x double]], ptr @dp, i64 0, i64 %56
  %58 = load i32, ptr %6, align 4, !tbaa !5
  %59 = sext i32 %58 to i64
  %60 = getelementptr inbounds [1001 x double], ptr %57, i64 0, i64 %59
  store double %54, ptr %60, align 8, !tbaa !11
  %61 = load i32, ptr %6, align 4, !tbaa !5
  %62 = icmp sgt i32 %61, 0
  br i1 %62, label %63, label %85

63:                                               ; preds = %40
  %64 = load i32, ptr %5, align 4, !tbaa !5
  %65 = sub nsw i32 %64, 1
  %66 = sext i32 %65 to i64
  %67 = getelementptr inbounds [1001 x [1001 x double]], ptr @dp, i64 0, i64 %66
  %68 = load i32, ptr %6, align 4, !tbaa !5
  %69 = sub nsw i32 %68, 1
  %70 = sext i32 %69 to i64
  %71 = getelementptr inbounds [1001 x double], ptr %67, i64 0, i64 %70
  %72 = load double, ptr %71, align 8, !tbaa !11
  %73 = load i32, ptr %5, align 4, !tbaa !5
  %74 = sext i32 %73 to i64
  %75 = getelementptr inbounds [1001 x double], ptr @p, i64 0, i64 %74
  %76 = load double, ptr %75, align 8, !tbaa !11
  %77 = load i32, ptr %5, align 4, !tbaa !5
  %78 = sext i32 %77 to i64
  %79 = getelementptr inbounds [1001 x [1001 x double]], ptr @dp, i64 0, i64 %78
  %80 = load i32, ptr %6, align 4, !tbaa !5
  %81 = sext i32 %80 to i64
  %82 = getelementptr inbounds [1001 x double], ptr %79, i64 0, i64 %81
  %83 = load double, ptr %82, align 8, !tbaa !11
  %84 = call double @llvm.fmuladd.f64(double %72, double %76, double %83)
  store double %84, ptr %82, align 8, !tbaa !11
  br label %85

85:                                               ; preds = %63, %40
  br label %86

86:                                               ; preds = %85
  %87 = load i32, ptr %6, align 4, !tbaa !5
  %88 = add nsw i32 %87, 1
  store i32 %88, ptr %6, align 4, !tbaa !5
  br label %35, !llvm.loop !13

89:                                               ; preds = %39
  br label %90

90:                                               ; preds = %89
  %91 = load i32, ptr %5, align 4, !tbaa !5
  %92 = add nsw i32 %91, 1
  store i32 %92, ptr %5, align 4, !tbaa !5
  br label %29, !llvm.loop !14

93:                                               ; preds = %33
  %94 = load i32, ptr %2, align 4, !tbaa !5
  %95 = load i32, ptr @n, align 4, !tbaa !5
  %96 = sext i32 %95 to i64
  %97 = getelementptr inbounds [1001 x [1001 x double]], ptr @dp, i64 0, i64 %96
  %98 = load i32, ptr @k, align 4, !tbaa !5
  %99 = sext i32 %98 to i64
  %100 = getelementptr inbounds [1001 x double], ptr %97, i64 0, i64 %99
  %101 = load double, ptr %100, align 8, !tbaa !11
  %102 = call i32 (ptr, ...) @printf(ptr noundef @.str.3, i32 noundef %94, double noundef %101)
  br label %103

103:                                              ; preds = %93
  %104 = load i32, ptr %2, align 4, !tbaa !5
  %105 = add nsw i32 %104, 1
  store i32 %105, ptr %2, align 4, !tbaa !5
  br label %8, !llvm.loop !15

106:                                              ; preds = %12
  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 willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.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

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 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}
!11 = !{!12, !12, i64 0}
!12 = !{!"double", !7, i64 0}
!13 = distinct !{!13, !10}
!14 = distinct !{!14, !10}
!15 = distinct !{!15, !10}


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

@t = external dso_local global i32, align 4
@n = external dso_local global i32, align 4
@k = external dso_local global i32, align 4
@dp = external dso_local local_unnamed_addr global [1001 x [1001 x double]], align 16
@p = external dso_local global [1001 x double], align 16
@.str = external hidden unnamed_addr constant [3 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [5 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [4 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [16 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 @t)
  %2 = load i32, ptr @t, align 4, !tbaa !5
  %.not38 = icmp slt i32 %2, 1
  br i1 %.not38, label %._crit_edge42, label %.lr.ph41

._crit_edge42:                                    ; preds = %._crit_edge37, %0
  ret i32 0

.lr.ph41:                                         ; preds = %0, %._crit_edge37
  %.02339 = phi i32 [ %31, %._crit_edge37 ], [ 1, %0 ]
  %3 = tail call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str.1, ptr noundef nonnull @n, ptr noundef nonnull @k)
  %4 = load i32, ptr @n, align 4, !tbaa !5
  %.not2529 = icmp slt i32 %4, 1
  br i1 %.not2529, label %._crit_edge.thread, label %.lr.ph

._crit_edge.thread:                               ; preds = %.lr.ph41
  store double 1.000000e+00, ptr @dp, align 16, !tbaa !9
  %.pre58 = load i32, ptr @k, align 4, !tbaa !5
  br label %._crit_edge37

._crit_edge:                                      ; preds = %.lr.ph
  store double 1.000000e+00, ptr @dp, align 16, !tbaa !9
  %.not2635 = icmp slt i32 %10, 1
  %.pre = load i32, ptr @k, align 4, !tbaa !5
  %.not2731 = icmp slt i32 %.pre, 0
  %or.cond = select i1 %.not2635, i1 true, i1 %.not2731
  br i1 %or.cond, label %._crit_edge37, label %.preheader.preheader

.preheader.preheader:                             ; preds = %._crit_edge
  %5 = add nuw i32 %.pre, 1
  %6 = add nuw i32 %10, 1
  %wide.trip.count53 = zext i32 %6 to i64
  %wide.trip.count = zext i32 %5 to i64
  %7 = zext nneg i32 %.pre to i64
  %n.vec = and i64 %7, 2147483646
  %ind.end = or i64 %7, 1
  %cmp.n = icmp eq i64 %n.vec, %7
  br label %12

.lr.ph:                                           ; preds = %.lr.ph41, %.lr.ph
  %indvars.iv = phi i64 [ %indvars.iv.next, %.lr.ph ], [ 1, %.lr.ph41 ]
  %8 = getelementptr inbounds double, ptr @p, i64 %indvars.iv
  %9 = tail call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str.2, ptr noundef nonnull %8)
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %10 = load i32, ptr @n, align 4, !tbaa !5
  %11 = sext i32 %10 to i64
  %.not25.not = icmp slt i64 %indvars.iv, %11
  br i1 %.not25.not, label %.lr.ph, label %._crit_edge, !llvm.loop !11

12:                                               ; preds = %._crit_edge34, %.preheader.preheader
  %13 = phi double [ 1.000000e+00, %.preheader.preheader ], [ %18, %._crit_edge34 ]
  %indvars.iv50 = phi i64 [ 1, %.preheader.preheader ], [ %indvars.iv.next51, %._crit_edge34 ]
  %14 = add nsw i64 %indvars.iv50, -1
  %15 = getelementptr inbounds [1001 x double], ptr @p, i64 0, i64 %indvars.iv50
  %16 = load double, ptr %15, align 8, !tbaa !9
  %17 = fsub double 1.000000e+00, %16
  %18 = fmul double %13, %17
  %19 = getelementptr inbounds [1001 x [1001 x double]], ptr @dp, i64 0, i64 %indvars.iv50, i64 0
  store double %18, ptr %19, align 8, !tbaa !9
  switch i32 %.pre, label %vector.ph [
    i32 0, label %._crit_edge34
    i32 1, label %.peel.next.preheader
  ]

vector.ph:                                        ; preds = %12
  %broadcast.splatinsert = insertelement <2 x double> poison, double %17, i64 0
  %broadcast.splat = shufflevector <2 x double> %broadcast.splatinsert, <2 x double> poison, <2 x i32> zeroinitializer
  %broadcast.splatinsert62 = insertelement <2 x double> poison, double %16, i64 0
  %broadcast.splat63 = shufflevector <2 x double> %broadcast.splatinsert62, <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 ]
  %offset.idx = or disjoint i64 %index, 1
  %20 = getelementptr inbounds [1001 x [1001 x double]], ptr @dp, i64 0, i64 %14, i64 %offset.idx
  %wide.load = load <2 x double>, ptr %20, align 8, !tbaa !9
  %21 = fmul <2 x double> %wide.load, %broadcast.splat
  %22 = getelementptr inbounds [1001 x [1001 x double]], ptr @dp, i64 0, i64 %indvars.iv50, i64 %offset.idx
  %23 = getelementptr inbounds [1001 x [1001 x double]], ptr @dp, i64 0, i64 %14, i64 %index
  %wide.load61 = load <2 x double>, ptr %23, align 8, !tbaa !9
  %24 = tail call <2 x double> @llvm.fmuladd.v2f64(<2 x double> %wide.load61, <2 x double> %broadcast.splat63, <2 x double> %21)
  store <2 x double> %24, ptr %22, align 8, !tbaa !9
  %index.next = add nuw i64 %index, 2
  %25 = icmp eq i64 %index.next, %n.vec
  br i1 %25, label %middle.block, label %vector.body, !llvm.loop !13

middle.block:                                     ; preds = %vector.body
  br i1 %cmp.n, label %._crit_edge34, label %.peel.next.preheader

.peel.next.preheader:                             ; preds = %12, %middle.block
  %indvars.iv46.ph = phi i64 [ 1, %12 ], [ %ind.end, %middle.block ]
  br label %.peel.next

._crit_edge37:                                    ; preds = %._crit_edge34, %._crit_edge.thread, %._crit_edge
  %.pre60 = phi i32 [ %.pre58, %._crit_edge.thread ], [ %.pre, %._crit_edge ], [ %.pre, %._crit_edge34 ]
  %.lcssa59 = phi i32 [ %4, %._crit_edge.thread ], [ %10, %._crit_edge ], [ %10, %._crit_edge34 ]
  %26 = sext i32 %.lcssa59 to i64
  %27 = sext i32 %.pre60 to i64
  %28 = getelementptr inbounds [1001 x [1001 x double]], ptr @dp, i64 0, i64 %26, i64 %27
  %29 = load double, ptr %28, align 8, !tbaa !9
  %30 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.3, i32 noundef %.02339, double noundef %29)
  %31 = add nuw nsw i32 %.02339, 1
  %32 = load i32, ptr @t, align 4, !tbaa !5
  %.not.not = icmp slt i32 %.02339, %32
  br i1 %.not.not, label %.lr.ph41, label %._crit_edge42, !llvm.loop !17

._crit_edge34:                                    ; preds = %.peel.next, %middle.block, %12
  %indvars.iv.next51 = add nuw nsw i64 %indvars.iv50, 1
  %exitcond54.not = icmp eq i64 %indvars.iv.next51, %wide.trip.count53
  br i1 %exitcond54.not, label %._crit_edge37, label %12, !llvm.loop !18

.peel.next:                                       ; preds = %.peel.next.preheader, %.peel.next
  %indvars.iv46 = phi i64 [ %indvars.iv.next47, %.peel.next ], [ %indvars.iv46.ph, %.peel.next.preheader ]
  %33 = getelementptr inbounds [1001 x [1001 x double]], ptr @dp, i64 0, i64 %14, i64 %indvars.iv46
  %34 = load double, ptr %33, align 8, !tbaa !9
  %35 = fmul double %34, %17
  %36 = getelementptr inbounds [1001 x [1001 x double]], ptr @dp, i64 0, i64 %indvars.iv50, i64 %indvars.iv46
  %37 = add nsw i64 %indvars.iv46, -1
  %38 = getelementptr inbounds [1001 x [1001 x double]], ptr @dp, i64 0, i64 %14, i64 %37
  %39 = load double, ptr %38, align 8, !tbaa !9
  %40 = tail call double @llvm.fmuladd.f64(double %39, double %16, double %35)
  store double %40, ptr %36, align 8, !tbaa !9
  %indvars.iv.next47 = add nuw nsw i64 %indvars.iv46, 1
  %exitcond.not = icmp eq i64 %indvars.iv.next47, %wide.trip.count
  br i1 %exitcond.not, label %._crit_edge34, label %.peel.next, !llvm.loop !19
}

; 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}
!12 = !{!"llvm.loop.mustprogress"}
!13 = distinct !{!13, !12, !14, !15, !16}
!14 = !{!"llvm.loop.peeled.count", i32 1}
!15 = !{!"llvm.loop.isvectorized", i32 1}
!16 = !{!"llvm.loop.unroll.runtime.disable"}
!17 = distinct !{!17, !12}
!18 = distinct !{!18, !12}
!19 = distinct !{!19, !12, !14, !16, !15}


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