; LLVM IR from VastoLorde95/Competitive-Programming :: Codeforces/253 Division 1/Problem B (B)

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

%"struct.std::greater" = type { i8 }

@n = external dso_local global i32, align 4
@p = external dso_local global [101 x double], align 16
@ans = external dso_local global double, align 8
@.str = external hidden unnamed_addr constant [3 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [4 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [8 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 %"struct.std::greater", align 1
  %4 = alloca double, align 8
  %5 = alloca double, align 8
  %6 = alloca i32, align 4
  %7 = alloca double, align 8
  store i32 0, ptr %1, align 4
  %8 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef @n)
  call void @llvm.lifetime.start.p0(i64 4, ptr %2) #5
  store i32 0, ptr %2, align 4, !tbaa !5
  br label %9

9:                                                ; preds = %19, %0
  %10 = load i32, ptr %2, align 4, !tbaa !5
  %11 = load i32, ptr @n, align 4, !tbaa !5
  %12 = icmp slt i32 %10, %11
  br i1 %12, label %14, label %13

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

14:                                               ; preds = %9
  %15 = load i32, ptr %2, align 4, !tbaa !5
  %16 = sext i32 %15 to i64
  %17 = getelementptr inbounds [101 x double], ptr @p, i64 0, i64 %16
  %18 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str.1, ptr noundef %17)
  br label %19

19:                                               ; preds = %14
  %20 = load i32, ptr %2, align 4, !tbaa !5
  %21 = add nsw i32 %20, 1
  store i32 %21, ptr %2, align 4, !tbaa !5
  br label %9, !llvm.loop !9

22:                                               ; preds = %13
  %23 = load i32, ptr @n, align 4, !tbaa !5
  %24 = sext i32 %23 to i64
  %25 = getelementptr inbounds double, ptr @p, i64 %24
  call void @_ZSt4sortIPdSt7greaterIdEEvT_S3_T0_(ptr noundef @p, ptr noundef %25)
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #5
  %26 = load double, ptr @p, align 16, !tbaa !11
  store double %26, ptr %4, align 8, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #5
  %27 = load double, ptr @p, align 16, !tbaa !11
  %28 = fsub double 1.000000e+00, %27
  store double %28, ptr %5, align 8, !tbaa !11
  %29 = load double, ptr %4, align 8, !tbaa !11
  store double %29, ptr @ans, align 8, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #5
  store i32 1, ptr %6, align 4, !tbaa !5
  br label %30

30:                                               ; preds = %63, %22
  %31 = load i32, ptr %6, align 4, !tbaa !5
  %32 = load i32, ptr @n, align 4, !tbaa !5
  %33 = icmp slt i32 %31, %32
  br i1 %33, label %35, label %34

34:                                               ; preds = %30
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #5
  br label %66

35:                                               ; preds = %30
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #5
  %36 = load double, ptr %4, align 8, !tbaa !11
  %37 = load i32, ptr %6, align 4, !tbaa !5
  %38 = sext i32 %37 to i64
  %39 = getelementptr inbounds [101 x double], ptr @p, i64 0, i64 %38
  %40 = load double, ptr %39, align 8, !tbaa !11
  %41 = fsub double 1.000000e+00, %40
  %42 = load double, ptr %5, align 8, !tbaa !11
  %43 = load i32, ptr %6, align 4, !tbaa !5
  %44 = sext i32 %43 to i64
  %45 = getelementptr inbounds [101 x double], ptr @p, i64 0, i64 %44
  %46 = load double, ptr %45, align 8, !tbaa !11
  %47 = fmul double %42, %46
  %48 = call double @llvm.fmuladd.f64(double %36, double %41, double %47)
  store double %48, ptr %7, align 8, !tbaa !11
  %49 = load double, ptr %7, align 8, !tbaa !11
  %50 = load double, ptr @ans, align 8, !tbaa !11
  %51 = fcmp ogt double %49, %50
  br i1 %51, label %52, label %62

52:                                               ; preds = %35
  %53 = load double, ptr %7, align 8, !tbaa !11
  store double %53, ptr @ans, align 8, !tbaa !11
  %54 = load double, ptr %7, align 8, !tbaa !11
  store double %54, ptr %4, align 8, !tbaa !11
  %55 = load double, ptr %5, align 8, !tbaa !11
  %56 = load i32, ptr %6, align 4, !tbaa !5
  %57 = sext i32 %56 to i64
  %58 = getelementptr inbounds [101 x double], ptr @p, i64 0, i64 %57
  %59 = load double, ptr %58, align 8, !tbaa !11
  %60 = fsub double 1.000000e+00, %59
  %61 = fmul double %55, %60
  store double %61, ptr %5, align 8, !tbaa !11
  br label %62

62:                                               ; preds = %52, %35
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #5
  br label %63

63:                                               ; preds = %62
  %64 = load i32, ptr %6, align 4, !tbaa !5
  %65 = add nsw i32 %64, 1
  store i32 %65, ptr %6, align 4, !tbaa !5
  br label %30, !llvm.loop !13

66:                                               ; preds = %34
  %67 = load double, ptr @ans, align 8, !tbaa !11
  %68 = call i32 (ptr, ...) @printf(ptr noundef @.str.2, double noundef %67)
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #5
  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: inlinehint mustprogress uwtable
declare dso_local void @_ZSt4sortIPdSt7greaterIdEEvT_S3_T0_(ptr noundef, ptr noundef) #3

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

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 = { inlinehint mustprogress 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 #4 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #5 = { 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}


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

@n = external dso_local global i32, align 4
@p = external dso_local global [101 x double], align 16
@ans = external dso_local local_unnamed_addr global double, align 8
@.str = external hidden unnamed_addr constant [3 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [4 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [8 x i8], align 1

; Function Attrs: mustprogress norecurse 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)
  %2 = load i32, ptr @n, align 4, !tbaa !5
  %3 = icmp sgt i32 %2, 0
  br i1 %3, label %.lr.ph, label %.._crit_edge_crit_edge

.._crit_edge_crit_edge:                           ; preds = %0
  %.pre = sext i32 %2 to i64
  br label %._crit_edge

._crit_edge:                                      ; preds = %.lr.ph, %.._crit_edge_crit_edge
  %.pre-phi = phi i64 [ %.pre, %.._crit_edge_crit_edge ], [ %14, %.lr.ph ]
  %4 = getelementptr inbounds double, ptr @p, i64 %.pre-phi
  tail call void @_ZSt4sortIPdSt7greaterIdEEvT_S3_T0_(ptr noundef nonnull @p, ptr noundef nonnull %4)
  %5 = load double, ptr @p, align 16, !tbaa !9
  store double %5, ptr @ans, align 8, !tbaa !9
  %6 = load i32, ptr @n, align 4, !tbaa !5
  %7 = icmp sgt i32 %6, 1
  br i1 %7, label %.lr.ph25.preheader, label %._crit_edge26

.lr.ph25.preheader:                               ; preds = %._crit_edge
  %8 = fsub double 1.000000e+00, %5
  %wide.trip.count = zext nneg i32 %6 to i64
  %9 = add nsw i64 %wide.trip.count, -1
  %xtraiter = and i64 %9, 1
  %10 = icmp eq i32 %6, 2
  br i1 %10, label %._crit_edge26.loopexit.unr-lcssa, label %.lr.ph25.preheader.new

.lr.ph25.preheader.new:                           ; preds = %.lr.ph25.preheader
  %unroll_iter = and i64 %9, -2
  br label %.lr.ph25

.lr.ph:                                           ; preds = %0, %.lr.ph
  %indvars.iv = phi i64 [ %indvars.iv.next, %.lr.ph ], [ 0, %0 ]
  %11 = getelementptr inbounds [101 x double], ptr @p, i64 0, i64 %indvars.iv
  %12 = tail call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str.1, ptr noundef nonnull %11)
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %13 = load i32, ptr @n, align 4, !tbaa !5
  %14 = sext i32 %13 to i64
  %15 = icmp slt i64 %indvars.iv.next, %14
  br i1 %15, label %.lr.ph, label %._crit_edge, !llvm.loop !11

._crit_edge26.loopexit.unr-lcssa:                 ; preds = %43, %.lr.ph25.preheader
  %.lcssa.ph = phi double [ poison, %.lr.ph25.preheader ], [ %44, %43 ]
  %indvars.iv29.unr = phi i64 [ 1, %.lr.ph25.preheader ], [ %indvars.iv.next30.1, %43 ]
  %.01522.unr = phi double [ %8, %.lr.ph25.preheader ], [ %.1.1, %43 ]
  %.01621.unr = phi double [ %5, %.lr.ph25.preheader ], [ %.117.1, %43 ]
  %.unr = phi double [ %5, %.lr.ph25.preheader ], [ %44, %43 ]
  %lcmp.mod.not = icmp eq i64 %xtraiter, 0
  br i1 %lcmp.mod.not, label %._crit_edge26, label %.lr.ph25.epil

.lr.ph25.epil:                                    ; preds = %._crit_edge26.loopexit.unr-lcssa
  %16 = getelementptr inbounds [101 x double], ptr @p, i64 0, i64 %indvars.iv29.unr
  %17 = load double, ptr %16, align 8, !tbaa !9
  %18 = fsub double 1.000000e+00, %17
  %19 = fmul double %.01522.unr, %17
  %20 = tail call double @llvm.fmuladd.f64(double %.01621.unr, double %18, double %19)
  %21 = fcmp ogt double %20, %.unr
  br i1 %21, label %22, label %._crit_edge26

22:                                               ; preds = %.lr.ph25.epil
  store double %20, ptr @ans, align 8, !tbaa !9
  br label %._crit_edge26

._crit_edge26:                                    ; preds = %._crit_edge26.loopexit.unr-lcssa, %22, %.lr.ph25.epil, %._crit_edge
  %23 = phi double [ %5, %._crit_edge ], [ %.lcssa.ph, %._crit_edge26.loopexit.unr-lcssa ], [ %20, %22 ], [ %.unr, %.lr.ph25.epil ]
  %24 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.2, double noundef %23)
  ret i32 0

.lr.ph25:                                         ; preds = %43, %.lr.ph25.preheader.new
  %indvars.iv29 = phi i64 [ 1, %.lr.ph25.preheader.new ], [ %indvars.iv.next30.1, %43 ]
  %.01522 = phi double [ %8, %.lr.ph25.preheader.new ], [ %.1.1, %43 ]
  %.01621 = phi double [ %5, %.lr.ph25.preheader.new ], [ %.117.1, %43 ]
  %25 = phi double [ %5, %.lr.ph25.preheader.new ], [ %44, %43 ]
  %niter = phi i64 [ 0, %.lr.ph25.preheader.new ], [ %niter.next.1, %43 ]
  %26 = getelementptr inbounds [101 x double], ptr @p, i64 0, i64 %indvars.iv29
  %27 = load double, ptr %26, align 8, !tbaa !9
  %28 = fsub double 1.000000e+00, %27
  %29 = fmul double %.01522, %27
  %30 = tail call double @llvm.fmuladd.f64(double %.01621, double %28, double %29)
  %31 = fcmp ogt double %30, %25
  br i1 %31, label %32, label %.lr.ph25.1

32:                                               ; preds = %.lr.ph25
  store double %30, ptr @ans, align 8, !tbaa !9
  %33 = fmul double %.01522, %28
  br label %.lr.ph25.1

.lr.ph25.1:                                       ; preds = %32, %.lr.ph25
  %34 = phi double [ %30, %32 ], [ %25, %.lr.ph25 ]
  %.117 = phi double [ %30, %32 ], [ %.01621, %.lr.ph25 ]
  %.1 = phi double [ %33, %32 ], [ %.01522, %.lr.ph25 ]
  %indvars.iv.next30 = add nuw nsw i64 %indvars.iv29, 1
  %35 = getelementptr inbounds [101 x double], ptr @p, i64 0, i64 %indvars.iv.next30
  %36 = load double, ptr %35, align 8, !tbaa !9
  %37 = fsub double 1.000000e+00, %36
  %38 = fmul double %.1, %36
  %39 = tail call double @llvm.fmuladd.f64(double %.117, double %37, double %38)
  %40 = fcmp ogt double %39, %34
  br i1 %40, label %41, label %43

41:                                               ; preds = %.lr.ph25.1
  store double %39, ptr @ans, align 8, !tbaa !9
  %42 = fmul double %.1, %37
  br label %43

43:                                               ; preds = %41, %.lr.ph25.1
  %44 = phi double [ %39, %41 ], [ %34, %.lr.ph25.1 ]
  %.117.1 = phi double [ %39, %41 ], [ %.117, %.lr.ph25.1 ]
  %.1.1 = phi double [ %42, %41 ], [ %.1, %.lr.ph25.1 ]
  %indvars.iv.next30.1 = add nuw nsw i64 %indvars.iv29, 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_edge26.loopexit.unr-lcssa, label %.lr.ph25, !llvm.loop !13
}

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

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local void @_ZSt4sortIPdSt7greaterIdEEvT_S3_T0_(ptr noundef, ptr noundef) local_unnamed_addr #2

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

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


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