program main

  implicit none

  integer    :: n, k
  integer,allocatable :: p(:)
  real(8)   ,allocatable :: sp(:)
  real(8)   ,allocatable :: h(:)
  real(8)   ,allocatable :: sh(:)
  integer :: i, j 
  real(8) :: rj
  
  read(*,*) n, k
  allocate( p(n) )
  allocate( h(n) )
  read(*,*) p

  allocate( sp(maxval( p )) )
  j = 0
  do i = 1, maxval( p )
    j = j + i
    sp(i) = j
  end do

  do i = 1, n
    h(i) = sp(p(i)) / p(i) 
  end do

  allocate( sh(n-k+1) )
  rj = sum( h(1:k) )
  do i = 1, n-k+1
    sh(i) = rj
    rj = rj + h(i+k) - h(i) 
  end do
  
  call quicksort1( sh, 1, n-k+1 ) 

  print*, sh( n-k+1 )

end program main

recursive subroutine quicksort1(a, first, last)
  implicit none
  real(8),intent(inout)::a(*)
  integer,intent(in)::first,last
  !
  ! Original
  ! https://gist.github.com/t-nissie/479f0f16966925fa29ea
  !
  real(8)::x,t
  integer::i,j

  x = a((first+last)/2)
  i = first
  j = last
  do
     do while (a(i) < x)
        i=i+1
     end do
     do while (x < a(j))
        j=j-1
     end do
     if (i >= j) exit
     t = a(i)
     a(i) = a(j)
     a(j) = t
     i=i+1
     j=j-1
  end do
  if (first < i-1) call quicksort1(a, first, i-1)
  if (j+1 < last)  call quicksort1(a, j+1, last)

  return
end subroutine quicksort1

; ModuleID = 'FIRModule'
source_filename = "FIRModule"
target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
target triple = "x86_64-pc-linux-gnu"

@_QFEh.0 = internal unnamed_addr global ptr null
@_QFEp.0 = internal unnamed_addr global ptr null
@_QFEp.8 = internal unnamed_addr global i64 0
@_QFEsh.0 = internal unnamed_addr global ptr null
@_QFEsp = internal unnamed_addr global { ptr, i64, i32, i8, i8, i8, i8, [1 x [3 x i64]] } { ptr null, i64 ptrtoint (ptr getelementptr (double, ptr null, i32 1) to i64), i32 20180515, i8 1, i8 28, i8 2, i8 0, [1 x [3 x i64]] [[3 x i64] [i64 1, i64 0, i64 ptrtoint (ptr getelementptr (double, ptr null, i32 1) to i64)]] }
@_QQcl.7ba75c5e669b814bad919dd3efde8bf9 = linkonce constant [73 x i8] c"/home/ubuntu/Downloads/TheStack_IR/Collated/Fortran/Source_2471/source.f\00"
@_QQEnvironmentDefaults = local_unnamed_addr constant ptr null

; Function Attrs: mustprogress nofree nounwind willreturn allockind("alloc,uninitialized") allocsize(0) memory(inaccessiblemem: readwrite)
declare noalias noundef ptr @malloc(i64 noundef) local_unnamed_addr #0

define void @_QQmain() local_unnamed_addr {
  %1 = alloca { ptr, i64, i32, i8, i8, i8, i8, [1 x [3 x i64]] }, align 8
  %2 = alloca i32, align 4
  %3 = alloca i32, align 4
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  %6 = tail call ptr @_FortranAioBeginExternalListInput(i32 -1, ptr nonnull @_QQcl.7ba75c5e669b814bad919dd3efde8bf9, i32 13)
  %7 = call i1 @_FortranAioInputInteger(ptr %6, ptr nonnull %5, i32 4)
  %8 = call i1 @_FortranAioInputInteger(ptr %6, ptr nonnull %4, i32 4)
  %9 = call i32 @_FortranAioEndIoStatement(ptr %6)
  %10 = load i32, ptr %5, align 4, !tbaa !3
  %11 = call i32 @llvm.smax.i32(i32 %10, i32 0)
  %12 = zext i32 %11 to i64
  %13 = shl nuw nsw i64 %12, 2
  %14 = call ptr @malloc(i64 %13)
  store ptr %14, ptr @_QFEp.0, align 8, !tbaa !7
  store i64 %12, ptr @_QFEp.8, align 8, !tbaa !7
  %15 = shl nuw nsw i64 %12, 3
  %16 = call ptr @malloc(i64 %15)
  store ptr %16, ptr @_QFEh.0, align 8, !tbaa !7
  %17 = call ptr @_FortranAioBeginExternalListInput(i32 -1, ptr nonnull @_QQcl.7ba75c5e669b814bad919dd3efde8bf9, i32 16)
  %.unpack = load ptr, ptr @_QFEp.0, align 8, !tbaa !7
  %.unpack605.unpack.unpack607 = load i64, ptr @_QFEp.8, align 8, !tbaa !7
  store ptr %.unpack, ptr %1, align 8, !tbaa !7
  %.fca.1.gep = getelementptr inbounds { ptr, i64, i32, i8, i8, i8, i8, [1 x [3 x i64]] }, ptr %1, i64 0, i32 1
  store i64 4, ptr %.fca.1.gep, align 8, !tbaa !7
  %.fca.2.gep = getelementptr inbounds { ptr, i64, i32, i8, i8, i8, i8, [1 x [3 x i64]] }, ptr %1, i64 0, i32 2
  store i32 20180515, ptr %.fca.2.gep, align 8, !tbaa !7
  %.fca.3.gep = getelementptr inbounds { ptr, i64, i32, i8, i8, i8, i8, [1 x [3 x i64]] }, ptr %1, i64 0, i32 3
  store i8 1, ptr %.fca.3.gep, align 4, !tbaa !7
  %.fca.4.gep = getelementptr inbounds { ptr, i64, i32, i8, i8, i8, i8, [1 x [3 x i64]] }, ptr %1, i64 0, i32 4
  store i8 9, ptr %.fca.4.gep, align 1, !tbaa !7
  %.fca.5.gep = getelementptr inbounds { ptr, i64, i32, i8, i8, i8, i8, [1 x [3 x i64]] }, ptr %1, i64 0, i32 5
  store i8 0, ptr %.fca.5.gep, align 2, !tbaa !7
  %.fca.6.gep = getelementptr inbounds { ptr, i64, i32, i8, i8, i8, i8, [1 x [3 x i64]] }, ptr %1, i64 0, i32 6
  store i8 0, ptr %.fca.6.gep, align 1, !tbaa !7
  %.fca.7.0.0.gep = getelementptr inbounds { ptr, i64, i32, i8, i8, i8, i8, [1 x [3 x i64]] }, ptr %1, i64 0, i32 7, i64 0, i64 0
  store i64 1, ptr %.fca.7.0.0.gep, align 8, !tbaa !7
  %.fca.7.0.1.gep = getelementptr inbounds { ptr, i64, i32, i8, i8, i8, i8, [1 x [3 x i64]] }, ptr %1, i64 0, i32 7, i64 0, i64 1
  store i64 %.unpack605.unpack.unpack607, ptr %.fca.7.0.1.gep, align 8, !tbaa !7
  %.fca.7.0.2.gep = getelementptr inbounds { ptr, i64, i32, i8, i8, i8, i8, [1 x [3 x i64]] }, ptr %1, i64 0, i32 7, i64 0, i64 2
  store i64 4, ptr %.fca.7.0.2.gep, align 8, !tbaa !7
  %18 = call i1 @_FortranAioInputDescriptor(ptr %17, ptr nonnull %1)
  %19 = call i32 @_FortranAioEndIoStatement(ptr %17)
  %.unpack610 = load ptr, ptr @_QFEp.0, align 8, !tbaa !7
  %.unpack617.unpack.unpack619 = load i64, ptr @_QFEp.8, align 8, !tbaa !7
  %20 = icmp sgt i64 %.unpack617.unpack.unpack619, 0
  br i1 %20, label %.lr.ph.i.preheader, label %_FortranAMaxvalInteger4x1_contract_simplified.exit

.lr.ph.i.preheader:                               ; preds = %0
  %min.iters.check = icmp ult i64 %.unpack617.unpack.unpack619, 8
  br i1 %min.iters.check, label %.lr.ph.i.preheader838, label %vector.ph

vector.ph:                                        ; preds = %.lr.ph.i.preheader
  %n.vec = and i64 %.unpack617.unpack.unpack619, -8
  br label %vector.body

vector.body:                                      ; preds = %vector.body, %vector.ph
  %index = phi i64 [ 0, %vector.ph ], [ %index.next, %vector.body ]
  %vec.phi = phi <4 x i32> [ <i32 -2147483648, i32 -2147483648, i32 -2147483648, i32 -2147483648>, %vector.ph ], [ %24, %vector.body ]
  %vec.phi813 = phi <4 x i32> [ <i32 -2147483648, i32 -2147483648, i32 -2147483648, i32 -2147483648>, %vector.ph ], [ %25, %vector.body ]
  %21 = shl i64 %index, 2
  %22 = getelementptr i8, ptr %.unpack610, i64 %21
  %wide.load = load <4 x i32>, ptr %22, align 4, !tbaa !3
  %23 = getelementptr i32, ptr %22, i64 4
  %wide.load814 = load <4 x i32>, ptr %23, align 4, !tbaa !3
  %24 = call <4 x i32> @llvm.smax.v4i32(<4 x i32> %wide.load, <4 x i32> %vec.phi)
  %25 = call <4 x i32> @llvm.smax.v4i32(<4 x i32> %wide.load814, <4 x i32> %vec.phi813)
  %index.next = add nuw i64 %index, 8
  %26 = icmp eq i64 %index.next, %n.vec
  br i1 %26, label %middle.block, label %vector.body, !llvm.loop !9

middle.block:                                     ; preds = %vector.body
  %rdx.minmax.select = call <4 x i32> @llvm.smax.v4i32(<4 x i32> %24, <4 x i32> %25)
  %27 = call i32 @llvm.vector.reduce.smax.v4i32(<4 x i32> %rdx.minmax.select)
  %cmp.n = icmp eq i64 %.unpack617.unpack.unpack619, %n.vec
  br i1 %cmp.n, label %_FortranAMaxvalInteger4x1_contract_simplified.exit, label %.lr.ph.i.preheader838

.lr.ph.i.preheader838:                            ; preds = %.lr.ph.i.preheader, %middle.block
  %.ph839 = phi i32 [ -2147483648, %.lr.ph.i.preheader ], [ %27, %middle.block ]
  %.ph840 = phi i64 [ 0, %.lr.ph.i.preheader ], [ %n.vec, %middle.block ]
  br label %.lr.ph.i

.lr.ph.i:                                         ; preds = %.lr.ph.i.preheader838, %.lr.ph.i
  %28 = phi i32 [ %33, %.lr.ph.i ], [ %.ph839, %.lr.ph.i.preheader838 ]
  %29 = phi i64 [ %34, %.lr.ph.i ], [ %.ph840, %.lr.ph.i.preheader838 ]
  %30 = shl i64 %29, 2
  %31 = getelementptr i8, ptr %.unpack610, i64 %30
  %32 = load i32, ptr %31, align 4, !tbaa !3
  %33 = call i32 @llvm.smax.i32(i32 %32, i32 %28)
  %34 = add nuw nsw i64 %29, 1
  %exitcond.not.i = icmp eq i64 %34, %.unpack617.unpack.unpack619
  br i1 %exitcond.not.i, label %_FortranAMaxvalInteger4x1_contract_simplified.exit, label %.lr.ph.i, !llvm.loop !12

_FortranAMaxvalInteger4x1_contract_simplified.exit: ; preds = %.lr.ph.i, %middle.block, %0
  %.lcssa.i = phi i32 [ -2147483648, %0 ], [ %27, %middle.block ], [ %33, %.lr.ph.i ]
  %35 = call i32 @llvm.smax.i32(i32 %.lcssa.i, i32 0)
  %36 = zext i32 %35 to i64
  %37 = shl nuw nsw i64 %36, 3
  %38 = call ptr @malloc(i64 %37)
  store ptr %38, ptr @_QFEsp, align 16, !tbaa !7
  store i64 8, ptr getelementptr inbounds ({ ptr, i64, i32, i8, i8, i8, i8, [1 x [3 x i64]] }, ptr @_QFEsp, i64 0, i32 1), align 8, !tbaa !7
  store i32 20180515, ptr getelementptr inbounds ({ ptr, i64, i32, i8, i8, i8, i8, [1 x [3 x i64]] }, ptr @_QFEsp, i64 0, i32 2), align 16, !tbaa !7
  store i8 1, ptr getelementptr inbounds ({ ptr, i64, i32, i8, i8, i8, i8, [1 x [3 x i64]] }, ptr @_QFEsp, i64 0, i32 3), align 4, !tbaa !7
  store i8 28, ptr getelementptr inbounds ({ ptr, i64, i32, i8, i8, i8, i8, [1 x [3 x i64]] }, ptr @_QFEsp, i64 0, i32 4), align 1, !tbaa !7
  store i8 2, ptr getelementptr inbounds ({ ptr, i64, i32, i8, i8, i8, i8, [1 x [3 x i64]] }, ptr @_QFEsp, i64 0, i32 5), align 2, !tbaa !7
  store i8 0, ptr getelementptr inbounds ({ ptr, i64, i32, i8, i8, i8, i8, [1 x [3 x i64]] }, ptr @_QFEsp, i64 0, i32 6), align 1, !tbaa !7
  store i64 1, ptr getelementptr inbounds ({ ptr, i64, i32, i8, i8, i8, i8, [1 x [3 x i64]] }, ptr @_QFEsp, i64 0, i32 7), align 8, !tbaa !7
  store i64 %36, ptr getelementptr inbounds ({ ptr, i64, i32, i8, i8, i8, i8, [1 x [3 x i64]] }, ptr @_QFEsp, i64 0, i32 7, i64 0, i64 1), align 16, !tbaa !7
  store i64 8, ptr getelementptr inbounds ({ ptr, i64, i32, i8, i8, i8, i8, [1 x [3 x i64]] }, ptr @_QFEsp, i64 0, i32 7, i64 0, i64 2), align 8, !tbaa !7
  br i1 %20, label %.lr.ph.i760.preheader, label %._crit_edge

.lr.ph.i760.preheader:                            ; preds = %_FortranAMaxvalInteger4x1_contract_simplified.exit
  %min.iters.check817 = icmp ult i64 %.unpack617.unpack.unpack619, 8
  br i1 %min.iters.check817, label %.lr.ph.i760.preheader833, label %vector.ph818

vector.ph818:                                     ; preds = %.lr.ph.i760.preheader
  %n.vec820 = and i64 %.unpack617.unpack.unpack619, -8
  br label %vector.body823

vector.body823:                                   ; preds = %vector.body823, %vector.ph818
  %index824 = phi i64 [ 0, %vector.ph818 ], [ %index.next829, %vector.body823 ]
  %vec.phi825 = phi <4 x i32> [ <i32 -2147483648, i32 -2147483648, i32 -2147483648, i32 -2147483648>, %vector.ph818 ], [ %42, %vector.body823 ]
  %vec.phi826 = phi <4 x i32> [ <i32 -2147483648, i32 -2147483648, i32 -2147483648, i32 -2147483648>, %vector.ph818 ], [ %43, %vector.body823 ]
  %39 = shl i64 %index824, 2
  %40 = getelementptr i8, ptr %.unpack610, i64 %39
  %wide.load827 = load <4 x i32>, ptr %40, align 4, !tbaa !3
  %41 = getelementptr i32, ptr %40, i64 4
  %wide.load828 = load <4 x i32>, ptr %41, align 4, !tbaa !3
  %42 = call <4 x i32> @llvm.smax.v4i32(<4 x i32> %wide.load827, <4 x i32> %vec.phi825)
  %43 = call <4 x i32> @llvm.smax.v4i32(<4 x i32> %wide.load828, <4 x i32> %vec.phi826)
  %index.next829 = add nuw i64 %index824, 8
  %44 = icmp eq i64 %index.next829, %n.vec820
  br i1 %44, label %middle.block815, label %vector.body823, !llvm.loop !13

middle.block815:                                  ; preds = %vector.body823
  %rdx.minmax.select831 = call <4 x i32> @llvm.smax.v4i32(<4 x i32> %42, <4 x i32> %43)
  %45 = call i32 @llvm.vector.reduce.smax.v4i32(<4 x i32> %rdx.minmax.select831)
  %cmp.n822 = icmp eq i64 %.unpack617.unpack.unpack619, %n.vec820
  br i1 %cmp.n822, label %_FortranAMaxvalInteger4x1_contract_simplified.exit763, label %.lr.ph.i760.preheader833

.lr.ph.i760.preheader833:                         ; preds = %.lr.ph.i760.preheader, %middle.block815
  %.ph = phi i32 [ -2147483648, %.lr.ph.i760.preheader ], [ %45, %middle.block815 ]
  %.ph834 = phi i64 [ 0, %.lr.ph.i760.preheader ], [ %n.vec820, %middle.block815 ]
  br label %.lr.ph.i760

.lr.ph.i760:                                      ; preds = %.lr.ph.i760.preheader833, %.lr.ph.i760
  %46 = phi i32 [ %51, %.lr.ph.i760 ], [ %.ph, %.lr.ph.i760.preheader833 ]
  %47 = phi i64 [ %52, %.lr.ph.i760 ], [ %.ph834, %.lr.ph.i760.preheader833 ]
  %48 = shl i64 %47, 2
  %49 = getelementptr i8, ptr %.unpack610, i64 %48
  %50 = load i32, ptr %49, align 4, !tbaa !3
  %51 = call i32 @llvm.smax.i32(i32 %50, i32 %46)
  %52 = add nuw nsw i64 %47, 1
  %exitcond.not.i761 = icmp eq i64 %52, %.unpack617.unpack.unpack619
  br i1 %exitcond.not.i761, label %_FortranAMaxvalInteger4x1_contract_simplified.exit763, label %.lr.ph.i760, !llvm.loop !14

_FortranAMaxvalInteger4x1_contract_simplified.exit763: ; preds = %.lr.ph.i760, %middle.block815
  %.lcssa811 = phi i32 [ %45, %middle.block815 ], [ %51, %.lr.ph.i760 ]
  %53 = icmp sgt i32 %.lcssa811, 0
  br i1 %53, label %.lr.ph.preheader, label %._crit_edge

.lr.ph.preheader:                                 ; preds = %_FortranAMaxvalInteger4x1_contract_simplified.exit763
  %54 = zext i32 %.lcssa811 to i64
  %xtraiter = and i64 %54, 3
  %55 = icmp ult i32 %.lcssa811, 4
  br i1 %55, label %._crit_edge.loopexit.unr-lcssa, label %.lr.ph.preheader.new

.lr.ph.preheader.new:                             ; preds = %.lr.ph.preheader
  %unroll_iter = and i64 %54, 4294967292
  br label %.lr.ph

.lr.ph:                                           ; preds = %.lr.ph, %.lr.ph.preheader.new
  %indvars.iv = phi i64 [ 1, %.lr.ph.preheader.new ], [ %indvars.iv.next.3, %.lr.ph ]
  %.0577789 = phi i32 [ 0, %.lr.ph.preheader.new ], [ %71, %.lr.ph ]
  %niter = phi i64 [ 0, %.lr.ph.preheader.new ], [ %niter.next.3, %.lr.ph ]
  %56 = trunc i64 %indvars.iv to i32
  %57 = add i32 %.0577789, %56
  %58 = sitofp i32 %57 to double
  %59 = add nsw i64 %indvars.iv, -1
  %60 = getelementptr double, ptr %38, i64 %59
  store double %58, ptr %60, align 8, !tbaa !3
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %61 = trunc i64 %indvars.iv.next to i32
  %62 = add i32 %57, %61
  %63 = sitofp i32 %62 to double
  %64 = getelementptr double, ptr %38, i64 %indvars.iv
  store double %63, ptr %64, align 8, !tbaa !3
  %indvars.iv.next.1 = add nuw nsw i64 %indvars.iv, 2
  %65 = trunc i64 %indvars.iv.next.1 to i32
  %66 = add i32 %62, %65
  %67 = sitofp i32 %66 to double
  %68 = getelementptr double, ptr %38, i64 %indvars.iv.next
  store double %67, ptr %68, align 8, !tbaa !3
  %69 = trunc i64 %indvars.iv to i32
  %70 = add i32 %69, 3
  %71 = add i32 %66, %70
  %72 = sitofp i32 %71 to double
  %73 = getelementptr double, ptr %38, i64 %indvars.iv.next.1
  store double %72, ptr %73, align 8, !tbaa !3
  %indvars.iv.next.3 = add nuw nsw i64 %indvars.iv, 4
  %niter.next.3 = add i64 %niter, 4
  %niter.ncmp.3 = icmp eq i64 %niter.next.3, %unroll_iter
  br i1 %niter.ncmp.3, label %._crit_edge.loopexit.unr-lcssa, label %.lr.ph

._crit_edge.loopexit.unr-lcssa:                   ; preds = %.lr.ph, %.lr.ph.preheader
  %indvars.iv.unr = phi i64 [ 1, %.lr.ph.preheader ], [ %indvars.iv.next.3, %.lr.ph ]
  %.0577789.unr = phi i32 [ 0, %.lr.ph.preheader ], [ %71, %.lr.ph ]
  %lcmp.mod.not = icmp eq i64 %xtraiter, 0
  br i1 %lcmp.mod.not, label %._crit_edge, label %.lr.ph.epil

.lr.ph.epil:                                      ; preds = %._crit_edge.loopexit.unr-lcssa, %.lr.ph.epil
  %indvars.iv.epil = phi i64 [ %indvars.iv.next.epil, %.lr.ph.epil ], [ %indvars.iv.unr, %._crit_edge.loopexit.unr-lcssa ]
  %.0577789.epil = phi i32 [ %75, %.lr.ph.epil ], [ %.0577789.unr, %._crit_edge.loopexit.unr-lcssa ]
  %epil.iter = phi i64 [ %epil.iter.next, %.lr.ph.epil ], [ 0, %._crit_edge.loopexit.unr-lcssa ]
  %74 = trunc i64 %indvars.iv.epil to i32
  %75 = add i32 %.0577789.epil, %74
  %76 = sitofp i32 %75 to double
  %77 = add nsw i64 %indvars.iv.epil, -1
  %78 = getelementptr double, ptr %38, i64 %77
  store double %76, ptr %78, align 8, !tbaa !3
  %indvars.iv.next.epil = add nuw nsw i64 %indvars.iv.epil, 1
  %epil.iter.next = add i64 %epil.iter, 1
  %epil.iter.cmp.not = icmp eq i64 %epil.iter.next, %xtraiter
  br i1 %epil.iter.cmp.not, label %._crit_edge, label %.lr.ph.epil, !llvm.loop !15

._crit_edge:                                      ; preds = %._crit_edge.loopexit.unr-lcssa, %.lr.ph.epil, %_FortranAMaxvalInteger4x1_contract_simplified.exit, %_FortranAMaxvalInteger4x1_contract_simplified.exit763
  %79 = load i32, ptr %5, align 4, !tbaa !3
  %80 = icmp sgt i32 %79, 0
  br i1 %80, label %.lr.ph791, label %._crit_edge.._crit_edge792_crit_edge

._crit_edge.._crit_edge792_crit_edge:             ; preds = %._crit_edge
  %.unpack652.pre = load ptr, ptr @_QFEh.0, align 8, !tbaa !7
  br label %._crit_edge792

.lr.ph791:                                        ; preds = %._crit_edge
  %81 = zext i32 %79 to i64
  %.unpack736 = load ptr, ptr @_QFEh.0, align 8, !tbaa !7
  %xtraiter844 = and i64 %81, 1
  %82 = icmp eq i32 %79, 1
  br i1 %82, label %._crit_edge792.loopexit.unr-lcssa, label %.lr.ph791.new

.lr.ph791.new:                                    ; preds = %.lr.ph791
  %unroll_iter847 = and i64 %81, 4294967294
  br label %83

83:                                               ; preds = %83, %.lr.ph791.new
  %indvars.iv799 = phi i64 [ 1, %.lr.ph791.new ], [ %indvars.iv.next800.1, %83 ]
  %niter848 = phi i64 [ 0, %.lr.ph791.new ], [ %niter848.next.1, %83 ]
  %84 = add nsw i64 %indvars.iv799, -1
  %85 = getelementptr i32, ptr %.unpack610, i64 %84
  %86 = load i32, ptr %85, align 4, !tbaa !3
  %87 = sext i32 %86 to i64
  %88 = add nsw i64 %87, -1
  %89 = getelementptr double, ptr %38, i64 %88
  %90 = load double, ptr %89, align 8, !tbaa !3
  %91 = sitofp i32 %86 to double
  %92 = fdiv contract double %90, %91
  %93 = add nsw i64 %indvars.iv799, -1
  %94 = getelementptr double, ptr %.unpack736, i64 %93
  store double %92, ptr %94, align 8, !tbaa !3
  %95 = getelementptr i32, ptr %.unpack610, i64 %indvars.iv799
  %96 = load i32, ptr %95, align 4, !tbaa !3
  %97 = sext i32 %96 to i64
  %98 = add nsw i64 %97, -1
  %99 = getelementptr double, ptr %38, i64 %98
  %100 = load double, ptr %99, align 8, !tbaa !3
  %101 = sitofp i32 %96 to double
  %102 = fdiv contract double %100, %101
  %103 = getelementptr double, ptr %.unpack736, i64 %indvars.iv799
  store double %102, ptr %103, align 8, !tbaa !3
  %indvars.iv.next800.1 = add nuw nsw i64 %indvars.iv799, 2
  %niter848.next.1 = add i64 %niter848, 2
  %niter848.ncmp.1 = icmp eq i64 %niter848.next.1, %unroll_iter847
  br i1 %niter848.ncmp.1, label %._crit_edge792.loopexit.unr-lcssa.loopexit, label %83

._crit_edge792.loopexit.unr-lcssa.loopexit:       ; preds = %83
  %104 = add nuw nsw i64 %indvars.iv799, 1
  br label %._crit_edge792.loopexit.unr-lcssa

._crit_edge792.loopexit.unr-lcssa:                ; preds = %._crit_edge792.loopexit.unr-lcssa.loopexit, %.lr.ph791
  %indvars.iv799.unr = phi i64 [ 0, %.lr.ph791 ], [ %104, %._crit_edge792.loopexit.unr-lcssa.loopexit ]
  %lcmp.mod846.not = icmp eq i64 %xtraiter844, 0
  br i1 %lcmp.mod846.not, label %._crit_edge792, label %._crit_edge792.loopexit.epilog-lcssa

._crit_edge792.loopexit.epilog-lcssa:             ; preds = %._crit_edge792.loopexit.unr-lcssa
  %105 = getelementptr i32, ptr %.unpack610, i64 %indvars.iv799.unr
  %106 = load i32, ptr %105, align 4, !tbaa !3
  %107 = sext i32 %106 to i64
  %108 = add nsw i64 %107, -1
  %109 = getelementptr double, ptr %38, i64 %108
  %110 = load double, ptr %109, align 8, !tbaa !3
  %111 = sitofp i32 %106 to double
  %112 = fdiv contract double %110, %111
  %113 = getelementptr double, ptr %.unpack736, i64 %indvars.iv799.unr
  store double %112, ptr %113, align 8, !tbaa !3
  br label %._crit_edge792

._crit_edge792:                                   ; preds = %._crit_edge792.loopexit.epilog-lcssa, %._crit_edge792.loopexit.unr-lcssa, %._crit_edge.._crit_edge792_crit_edge
  %.unpack652 = phi ptr [ %.unpack652.pre, %._crit_edge.._crit_edge792_crit_edge ], [ %.unpack736, %._crit_edge792.loopexit.unr-lcssa ], [ %.unpack736, %._crit_edge792.loopexit.epilog-lcssa ]
  %114 = load i32, ptr %4, align 4, !tbaa !3
  %115 = sub i32 %79, %114
  %116 = add i32 %115, 1
  %117 = call i32 @llvm.smax.i32(i32 %116, i32 0)
  %118 = zext i32 %117 to i64
  %119 = shl nuw nsw i64 %118, 3
  %120 = call ptr @malloc(i64 %119)
  store ptr %120, ptr @_QFEsh.0, align 8, !tbaa !7
  %121 = call i32 @llvm.smax.i32(i32 %114, i32 0)
  %122 = zext i32 %121 to i64
  %.not = icmp slt i32 %114, 1
  br i1 %.not, label %_FortranASumReal8x1_contract_simplified.exit, label %.lr.ph.i764.preheader

.lr.ph.i764.preheader:                            ; preds = %._crit_edge792
  %123 = add nsw i64 %122, -1
  %xtraiter849 = and i64 %122, 3
  %124 = icmp ult i64 %123, 3
  br i1 %124, label %_FortranASumReal8x1_contract_simplified.exit.loopexit.unr-lcssa, label %.lr.ph.i764.preheader.new

.lr.ph.i764.preheader.new:                        ; preds = %.lr.ph.i764.preheader
  %unroll_iter854 = and i64 %122, 2147483644
  br label %.lr.ph.i764

.lr.ph.i764:                                      ; preds = %.lr.ph.i764, %.lr.ph.i764.preheader.new
  %125 = phi double [ 0.000000e+00, %.lr.ph.i764.preheader.new ], [ %145, %.lr.ph.i764 ]
  %126 = phi i64 [ 0, %.lr.ph.i764.preheader.new ], [ %146, %.lr.ph.i764 ]
  %niter855 = phi i64 [ 0, %.lr.ph.i764.preheader.new ], [ %niter855.next.3, %.lr.ph.i764 ]
  %127 = shl i64 %126, 3
  %128 = getelementptr i8, ptr %.unpack652, i64 %127
  %129 = load double, ptr %128, align 8, !tbaa !3
  %130 = fadd contract double %125, %129
  %131 = shl i64 %126, 3
  %132 = or i64 %131, 8
  %133 = getelementptr i8, ptr %.unpack652, i64 %132
  %134 = load double, ptr %133, align 8, !tbaa !3
  %135 = fadd contract double %130, %134
  %136 = shl i64 %126, 3
  %137 = or i64 %136, 16
  %138 = getelementptr i8, ptr %.unpack652, i64 %137
  %139 = load double, ptr %138, align 8, !tbaa !3
  %140 = fadd contract double %135, %139
  %141 = shl i64 %126, 3
  %142 = or i64 %141, 24
  %143 = getelementptr i8, ptr %.unpack652, i64 %142
  %144 = load double, ptr %143, align 8, !tbaa !3
  %145 = fadd contract double %140, %144
  %146 = add nuw nsw i64 %126, 4
  %niter855.next.3 = add i64 %niter855, 4
  %niter855.ncmp.3 = icmp eq i64 %niter855.next.3, %unroll_iter854
  br i1 %niter855.ncmp.3, label %_FortranASumReal8x1_contract_simplified.exit.loopexit.unr-lcssa, label %.lr.ph.i764

_FortranASumReal8x1_contract_simplified.exit.loopexit.unr-lcssa: ; preds = %.lr.ph.i764, %.lr.ph.i764.preheader
  %.lcssa.ph = phi double [ undef, %.lr.ph.i764.preheader ], [ %145, %.lr.ph.i764 ]
  %.unr = phi double [ 0.000000e+00, %.lr.ph.i764.preheader ], [ %145, %.lr.ph.i764 ]
  %.unr851 = phi i64 [ 0, %.lr.ph.i764.preheader ], [ %146, %.lr.ph.i764 ]
  %lcmp.mod852.not = icmp eq i64 %xtraiter849, 0
  br i1 %lcmp.mod852.not, label %_FortranASumReal8x1_contract_simplified.exit, label %.lr.ph.i764.epil

.lr.ph.i764.epil:                                 ; preds = %_FortranASumReal8x1_contract_simplified.exit.loopexit.unr-lcssa, %.lr.ph.i764.epil
  %147 = phi double [ %152, %.lr.ph.i764.epil ], [ %.unr, %_FortranASumReal8x1_contract_simplified.exit.loopexit.unr-lcssa ]
  %148 = phi i64 [ %153, %.lr.ph.i764.epil ], [ %.unr851, %_FortranASumReal8x1_contract_simplified.exit.loopexit.unr-lcssa ]
  %epil.iter850 = phi i64 [ %epil.iter850.next, %.lr.ph.i764.epil ], [ 0, %_FortranASumReal8x1_contract_simplified.exit.loopexit.unr-lcssa ]
  %149 = shl i64 %148, 3
  %150 = getelementptr i8, ptr %.unpack652, i64 %149
  %151 = load double, ptr %150, align 8, !tbaa !3
  %152 = fadd contract double %147, %151
  %153 = add nuw nsw i64 %148, 1
  %epil.iter850.next = add i64 %epil.iter850, 1
  %epil.iter850.cmp.not = icmp eq i64 %epil.iter850.next, %xtraiter849
  br i1 %epil.iter850.cmp.not, label %_FortranASumReal8x1_contract_simplified.exit, label %.lr.ph.i764.epil, !llvm.loop !17

_FortranASumReal8x1_contract_simplified.exit:     ; preds = %_FortranASumReal8x1_contract_simplified.exit.loopexit.unr-lcssa, %.lr.ph.i764.epil, %._crit_edge792
  %.lcssa.i766 = phi double [ 0.000000e+00, %._crit_edge792 ], [ %.lcssa.ph, %_FortranASumReal8x1_contract_simplified.exit.loopexit.unr-lcssa ], [ %152, %.lr.ph.i764.epil ]
  %154 = icmp ult i32 %115, 2147483647
  br i1 %154, label %.lr.ph794.preheader, label %._crit_edge795

.lr.ph794.preheader:                              ; preds = %_FortranASumReal8x1_contract_simplified.exit
  %155 = zext i32 %116 to i64
  br label %.lr.ph794

.lr.ph794:                                        ; preds = %.lr.ph794.preheader, %.lr.ph794
  %indvars.iv803 = phi i64 [ 1, %.lr.ph794.preheader ], [ %indvars.iv.next804, %.lr.ph794 ]
  %156 = phi i64 [ %155, %.lr.ph794.preheader ], [ %170, %.lr.ph794 ]
  %.0793 = phi double [ %.lcssa.i766, %.lr.ph794.preheader ], [ %169, %.lr.ph794 ]
  %157 = add nsw i64 %indvars.iv803, -1
  %158 = getelementptr double, ptr %120, i64 %157
  store double %.0793, ptr %158, align 8, !tbaa !3
  %159 = trunc i64 %indvars.iv803 to i32
  %160 = add i32 %114, %159
  %161 = sext i32 %160 to i64
  %162 = add nsw i64 %161, -1
  %163 = getelementptr double, ptr %.unpack652, i64 %162
  %164 = load double, ptr %163, align 8, !tbaa !3
  %165 = fadd contract double %.0793, %164
  %166 = add nsw i64 %indvars.iv803, -1
  %167 = getelementptr double, ptr %.unpack652, i64 %166
  %168 = load double, ptr %167, align 8, !tbaa !3
  %169 = fsub contract double %165, %168
  %indvars.iv.next804 = add nuw nsw i64 %indvars.iv803, 1
  %170 = add nsw i64 %156, -1
  %171 = icmp ugt i64 %156, 1
  br i1 %171, label %.lr.ph794, label %._crit_edge795

._crit_edge795:                                   ; preds = %.lr.ph794, %_FortranASumReal8x1_contract_simplified.exit
  store i32 1, ptr %3, align 4, !tbaa !3
  store i32 %116, ptr %2, align 4, !tbaa !3
  call void @quicksort1_(ptr %120, ptr nonnull %3, ptr nonnull %2)
  %172 = call ptr @_FortranAioBeginExternalListOutput(i32 -1, ptr nonnull @_QQcl.7ba75c5e669b814bad919dd3efde8bf9, i32 38)
  %.unpack676 = load ptr, ptr @_QFEsh.0, align 8, !tbaa !7
  %173 = load i32, ptr %5, align 4, !tbaa !3
  %174 = load i32, ptr %4, align 4, !tbaa !3
  %175 = add i32 %173, 1
  %176 = sub i32 %175, %174
  %177 = sext i32 %176 to i64
  %178 = add nsw i64 %177, -1
  %179 = getelementptr double, ptr %.unpack676, i64 %178
  %180 = load double, ptr %179, align 8, !tbaa !3
  %181 = call i1 @_FortranAioOutputReal64(ptr %172, double %180)
  %182 = call i32 @_FortranAioEndIoStatement(ptr %172)
  ret void
}

; Function Attrs: nofree nosync nounwind memory(argmem: readwrite)
define void @quicksort1_(ptr %0, ptr nocapture readonly %1, ptr nocapture readonly %2) local_unnamed_addr #1 {
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  %6 = load i32, ptr %1, align 4, !tbaa !3
  %7 = load i32, ptr %2, align 4, !tbaa !3
  %8 = add i32 %7, %6
  %9 = sdiv i32 %8, 2
  %narrow = add nsw i32 %9, -1
  %10 = sext i32 %narrow to i64
  %11 = getelementptr double, ptr %0, i64 %10
  %12 = load double, ptr %11, align 8, !tbaa !3
  br label %.outer

.outer:                                           ; preds = %40, %3
  %.018.ph = phi i32 [ %27, %40 ], [ %7, %3 ]
  %.0.ph = phi i32 [ %19, %40 ], [ %6, %3 ]
  br label %13

13:                                               ; preds = %13, %.outer
  %.0 = phi i32 [ %19, %13 ], [ %.0.ph, %.outer ]
  %14 = sext i32 %.0 to i64
  %15 = add nsw i64 %14, -1
  %16 = getelementptr double, ptr %0, i64 %15
  %17 = load double, ptr %16, align 8, !tbaa !3
  %18 = fcmp olt double %17, %12
  %19 = add i32 %.0, 1
  br i1 %18, label %13, label %.preheader

.preheader:                                       ; preds = %13
  %20 = getelementptr double, ptr %0, i64 %15
  br label %21

21:                                               ; preds = %21, %.preheader
  %.1 = phi i32 [ %27, %21 ], [ %.018.ph, %.preheader ]
  %22 = sext i32 %.1 to i64
  %23 = add nsw i64 %22, -1
  %24 = getelementptr double, ptr %0, i64 %23
  %25 = load double, ptr %24, align 8, !tbaa !3
  %26 = fcmp olt double %12, %25
  %27 = add i32 %.1, -1
  br i1 %26, label %21, label %28

28:                                               ; preds = %21
  %.not = icmp slt i32 %.0, %.1
  br i1 %.not, label %40, label %29

29:                                               ; preds = %28
  %30 = load i32, ptr %1, align 4, !tbaa !3
  %31 = add i32 %.0, -1
  %32 = icmp slt i32 %30, %31
  br i1 %32, label %33, label %34

33:                                               ; preds = %29
  store i32 %31, ptr %5, align 4, !tbaa !3
  call void @quicksort1_(ptr nonnull %0, ptr nonnull %1, ptr nonnull %5)
  br label %34

34:                                               ; preds = %33, %29
  %35 = add i32 %.1, 1
  %36 = load i32, ptr %2, align 4, !tbaa !3
  %37 = icmp slt i32 %35, %36
  br i1 %37, label %38, label %39

38:                                               ; preds = %34
  store i32 %35, ptr %4, align 4, !tbaa !3
  call void @quicksort1_(ptr nonnull %0, ptr nonnull %4, ptr nonnull %2)
  br label %39

39:                                               ; preds = %38, %34
  ret void

40:                                               ; preds = %28
  %41 = getelementptr double, ptr %0, i64 %23
  store double %25, ptr %20, align 8, !tbaa !3
  store double %17, ptr %41, align 8, !tbaa !3
  br label %.outer
}

declare ptr @_FortranAioBeginExternalListInput(i32, ptr, i32) local_unnamed_addr

declare i1 @_FortranAioInputInteger(ptr, ptr, i32) local_unnamed_addr

declare i32 @_FortranAioEndIoStatement(ptr) local_unnamed_addr

declare i1 @_FortranAioInputDescriptor(ptr, ptr) local_unnamed_addr

declare ptr @_FortranAioBeginExternalListOutput(i32, ptr, i32) local_unnamed_addr

declare i1 @_FortranAioOutputReal64(ptr, double) local_unnamed_addr

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

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare <4 x i32> @llvm.smax.v4i32(<4 x i32>, <4 x i32>) #3

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(none)
declare i32 @llvm.vector.reduce.smax.v4i32(<4 x i32>) #4

attributes #0 = { mustprogress nofree nounwind willreturn allockind("alloc,uninitialized") allocsize(0) memory(inaccessiblemem: readwrite) "alloc-family"="malloc" }
attributes #1 = { nofree nosync nounwind memory(argmem: readwrite) }
attributes #2 = { mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #3 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #4 = { nocallback nofree nosync nounwind willreturn memory(none) }

!llvm.module.flags = !{!0, !1, !2}

!0 = !{i32 2, !"Debug Info Version", i32 3}
!1 = !{i32 8, !"PIC Level", i32 2}
!2 = !{i32 7, !"PIE Level", i32 2}
!3 = !{!4, !4, i64 0}
!4 = !{!"any data access", !5, i64 0}
!5 = !{!"any access", !6, i64 0}
!6 = !{!"Flang Type TBAA Root"}
!7 = !{!8, !8, i64 0}
!8 = !{!"descriptor member", !5, i64 0}
!9 = distinct !{!9, !10, !11}
!10 = !{!"llvm.loop.isvectorized", i32 1}
!11 = !{!"llvm.loop.unroll.runtime.disable"}
!12 = distinct !{!12, !11, !10}
!13 = distinct !{!13, !10, !11}
!14 = distinct !{!14, !11, !10}
!15 = distinct !{!15, !16}
!16 = !{!"llvm.loop.unroll.disable"}
!17 = distinct !{!17, !16}
