program juice
	implicit none
    integer :: n, k, i, m, j
    integer,allocatable :: p(:)
    
    read(*,*) n, k
    allocate(p(n))
    
    read(*,*) p
    
    do i = n, 2, -1
    	do j = 1, i-1
        	if ( p(j)>=p(j+1) ) then
            	m = p(j+1)
                p(j+1) = p(j)
                p(j) = m
            end if
        end do
    end do
    
    write(*,*) sum(p(1:k))
    
    stop
end program juice
; 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"

@_QFEp.0 = internal unnamed_addr global ptr null
@_QFEp.8 = internal unnamed_addr global i64 0
@_QQcl.1a41ea4b906dcd92f67c9c8995f39f0a = linkonce constant [73 x i8] c"/home/ubuntu/Downloads/TheStack_IR/Collated/Fortran/Source_1118/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

; Function Attrs: noreturn
define void @_QQmain() local_unnamed_addr #1 {
  %1 = alloca { ptr, i64, i32, i8, i8, i8, i8, [1 x [3 x i64]] }, align 8
  %2 = alloca { ptr, i64, i32, i8, i8, i8, i8, [1 x [3 x i64]] }, align 8
  %3 = alloca i32, align 4
  %4 = alloca i32, align 4
  %5 = tail call ptr @_FortranAioBeginExternalListInput(i32 -1, ptr nonnull @_QQcl.1a41ea4b906dcd92f67c9c8995f39f0a, i32 6)
  %6 = call i1 @_FortranAioInputInteger(ptr %5, ptr nonnull %4, i32 4)
  %7 = call i1 @_FortranAioInputInteger(ptr %5, ptr nonnull %3, i32 4)
  %8 = call i32 @_FortranAioEndIoStatement(ptr %5)
  %9 = load i32, ptr %4, align 4, !tbaa !3
  %10 = call i32 @llvm.smax.i32(i32 %9, i32 0)
  %11 = zext i32 %10 to i64
  %12 = shl nuw nsw i64 %11, 2
  %13 = call ptr @malloc(i64 %12)
  store ptr %13, ptr @_QFEp.0, align 8, !tbaa !7
  store i64 %11, ptr @_QFEp.8, align 8, !tbaa !7
  %14 = call ptr @_FortranAioBeginExternalListInput(i32 -1, ptr nonnull @_QQcl.1a41ea4b906dcd92f67c9c8995f39f0a, i32 9)
  %.unpack = load ptr, ptr @_QFEp.0, align 8, !tbaa !7
  %.unpack233.unpack.unpack235 = load i64, ptr @_QFEp.8, align 8, !tbaa !7
  store ptr %.unpack, ptr %2, align 8, !tbaa !7
  %.fca.1.gep = getelementptr inbounds { ptr, i64, i32, i8, i8, i8, i8, [1 x [3 x i64]] }, ptr %2, 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 %2, 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 %2, 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 %2, 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 %2, 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 %2, 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 %2, 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 %2, i64 0, i32 7, i64 0, i64 1
  store i64 %.unpack233.unpack.unpack235, 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 %2, i64 0, i32 7, i64 0, i64 2
  store i64 4, ptr %.fca.7.0.2.gep, align 8, !tbaa !7
  %15 = call i1 @_FortranAioInputDescriptor(ptr %14, ptr nonnull %2)
  %16 = call i32 @_FortranAioEndIoStatement(ptr %14)
  %17 = load i32, ptr %4, align 4, !tbaa !3
  %18 = icmp sgt i32 %17, 1
  br i1 %18, label %.lr.ph274, label %._crit_edge

.lr.ph274:                                        ; preds = %0
  %19 = zext i32 %17 to i64
  %.unpack250 = load ptr, ptr @_QFEp.0, align 8
  br label %21

.loopexit:                                        ; preds = %36, %21
  %20 = icmp sgt i64 %.in, 2
  br i1 %20, label %21, label %._crit_edge

21:                                               ; preds = %.lr.ph274, %.loopexit
  %.in = phi i64 [ %19, %.lr.ph274 ], [ %23, %.loopexit ]
  %22 = phi i32 [ %17, %.lr.ph274 ], [ %24, %.loopexit ]
  %23 = add nsw i64 %.in, -1
  %24 = add i32 %22, -1
  %25 = icmp sgt i32 %24, 0
  br i1 %25, label %.lr.ph.preheader, label %.loopexit

.lr.ph.preheader:                                 ; preds = %21
  %26 = zext i32 %24 to i64
  br label %.lr.ph

.lr.ph:                                           ; preds = %.lr.ph.preheader, %36
  %indvars.iv = phi i64 [ 1, %.lr.ph.preheader ], [ %indvars.iv.next, %36 ]
  %27 = phi i64 [ %26, %.lr.ph.preheader ], [ %37, %36 ]
  %28 = add nsw i64 %indvars.iv, -1
  %29 = getelementptr i32, ptr %.unpack250, i64 %28
  %30 = load i32, ptr %29, align 4, !tbaa !3
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %sext = shl i64 %indvars.iv.next, 32
  %31 = ashr exact i64 %sext, 32
  %32 = add nsw i64 %31, -1
  %33 = getelementptr i32, ptr %.unpack250, i64 %32
  %34 = load i32, ptr %33, align 4, !tbaa !3
  %.not = icmp slt i32 %30, %34
  br i1 %.not, label %36, label %35

35:                                               ; preds = %.lr.ph
  store i32 %30, ptr %33, align 4, !tbaa !3
  store i32 %34, ptr %29, align 4, !tbaa !3
  br label %36

36:                                               ; preds = %35, %.lr.ph
  %37 = add nsw i64 %27, -1
  %38 = icmp sgt i64 %27, 1
  br i1 %38, label %.lr.ph, label %.loopexit

._crit_edge:                                      ; preds = %.loopexit, %0
  %39 = call ptr @_FortranAioBeginExternalListOutput(i32 -1, ptr nonnull @_QQcl.1a41ea4b906dcd92f67c9c8995f39f0a, i32 21)
  %.unpack238 = load ptr, ptr @_QFEp.0, align 8, !tbaa !7
  %40 = load i32, ptr %3, align 4, !tbaa !3
  %41 = call i32 @llvm.smax.i32(i32 %40, i32 0)
  %42 = zext i32 %41 to i64
  store ptr %.unpack238, ptr %1, align 8, !tbaa !7
  %.fca.1.gep78 = 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.gep78, align 8, !tbaa !7
  %.fca.2.gep80 = 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.gep80, align 8, !tbaa !7
  %.fca.3.gep82 = 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.gep82, align 4, !tbaa !7
  %.fca.4.gep84 = 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.gep84, align 1, !tbaa !7
  %.fca.5.gep86 = 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.gep86, align 2, !tbaa !7
  %.fca.6.gep88 = 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.gep88, align 1, !tbaa !7
  %.fca.7.0.0.gep90 = 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.gep90, align 8, !tbaa !7
  %.fca.7.0.1.gep92 = 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 %42, ptr %.fca.7.0.1.gep92, align 8, !tbaa !7
  %.fca.7.0.2.gep94 = 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.gep94, align 8, !tbaa !7
  %43 = call i32 @_FortranASumInteger4x1_contract_simplified(ptr nonnull %1)
  %44 = call i1 @_FortranAioOutputInteger32(ptr %39, i32 %43)
  %45 = call i32 @_FortranAioEndIoStatement(ptr %39)
  %46 = call {} @_FortranAStopStatement(i32 0, i1 false, i1 false)
  unreachable
}

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 @_FortranAioOutputInteger32(ptr, i32) local_unnamed_addr

declare {} @_FortranAStopStatement(i32, i1, i1) local_unnamed_addr

define linkonce_odr i32 @_FortranASumInteger4x1_contract_simplified(ptr %0) local_unnamed_addr {
  %2 = getelementptr { ptr, i64, i32, i8, i8, i8, i8, [1 x [3 x i64]] }, ptr %0, i64 0, i32 7, i64 0, i64 1
  %3 = load i64, ptr %2, align 8, !tbaa !7
  %4 = icmp sgt i64 %3, 0
  br i1 %4, label %.lr.ph, label %._crit_edge

.lr.ph:                                           ; preds = %1
  %5 = load ptr, ptr %0, align 8, !tbaa !7
  %6 = getelementptr { ptr, i64, i32, i8, i8, i8, i8, [1 x [3 x i64]] }, ptr %0, i64 0, i32 7, i64 0, i64 2
  %7 = load i64, ptr %6, align 8, !tbaa !7
  %xtraiter = and i64 %3, 3
  %8 = icmp ult i64 %3, 4
  br i1 %8, label %._crit_edge.loopexit.unr-lcssa, label %.lr.ph.new

.lr.ph.new:                                       ; preds = %.lr.ph
  %unroll_iter = and i64 %3, -4
  br label %9

9:                                                ; preds = %9, %.lr.ph.new
  %10 = phi i32 [ 0, %.lr.ph.new ], [ %30, %9 ]
  %11 = phi i64 [ 0, %.lr.ph.new ], [ %31, %9 ]
  %niter = phi i64 [ 0, %.lr.ph.new ], [ %niter.next.3, %9 ]
  %12 = mul i64 %7, %11
  %13 = getelementptr i8, ptr %5, i64 %12
  %14 = load i32, ptr %13, align 4, !tbaa !3
  %15 = add i32 %14, %10
  %16 = or i64 %11, 1
  %17 = mul i64 %7, %16
  %18 = getelementptr i8, ptr %5, i64 %17
  %19 = load i32, ptr %18, align 4, !tbaa !3
  %20 = add i32 %19, %15
  %21 = or i64 %11, 2
  %22 = mul i64 %7, %21
  %23 = getelementptr i8, ptr %5, i64 %22
  %24 = load i32, ptr %23, align 4, !tbaa !3
  %25 = add i32 %24, %20
  %26 = or i64 %11, 3
  %27 = mul i64 %7, %26
  %28 = getelementptr i8, ptr %5, i64 %27
  %29 = load i32, ptr %28, align 4, !tbaa !3
  %30 = add i32 %29, %25
  %31 = add nuw nsw i64 %11, 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 %9

._crit_edge.loopexit.unr-lcssa:                   ; preds = %9, %.lr.ph
  %.lcssa4.ph = phi i32 [ undef, %.lr.ph ], [ %30, %9 ]
  %.unr = phi i32 [ 0, %.lr.ph ], [ %30, %9 ]
  %.unr5 = phi i64 [ 0, %.lr.ph ], [ %31, %9 ]
  %lcmp.mod.not = icmp eq i64 %xtraiter, 0
  br i1 %lcmp.mod.not, label %._crit_edge, label %.epil.preheader

.epil.preheader:                                  ; preds = %._crit_edge.loopexit.unr-lcssa, %.epil.preheader
  %32 = phi i32 [ %37, %.epil.preheader ], [ %.unr, %._crit_edge.loopexit.unr-lcssa ]
  %33 = phi i64 [ %38, %.epil.preheader ], [ %.unr5, %._crit_edge.loopexit.unr-lcssa ]
  %epil.iter = phi i64 [ %epil.iter.next, %.epil.preheader ], [ 0, %._crit_edge.loopexit.unr-lcssa ]
  %34 = mul i64 %7, %33
  %35 = getelementptr i8, ptr %5, i64 %34
  %36 = load i32, ptr %35, align 4, !tbaa !3
  %37 = add i32 %36, %32
  %38 = add nuw nsw i64 %33, 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 %.epil.preheader, !llvm.loop !9

._crit_edge:                                      ; preds = %._crit_edge.loopexit.unr-lcssa, %.epil.preheader, %1
  %.lcssa = phi i32 [ 0, %1 ], [ %.lcssa4.ph, %._crit_edge.loopexit.unr-lcssa ], [ %37, %.epil.preheader ]
  ret i32 %.lcssa
}

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

attributes #0 = { mustprogress nofree nounwind willreturn allockind("alloc,uninitialized") allocsize(0) memory(inaccessiblemem: readwrite) "alloc-family"="malloc" }
attributes #1 = { noreturn }
attributes #2 = { nocallback nofree nosync nounwind speculatable 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}
!10 = !{!"llvm.loop.unroll.disable"}
