program answer2
 implicit none
 
 integer :: i, j, N, K, m
 integer, allocatable :: p(:)
 
 read(*,*) N, K
 allocate(p(N))
 read(*,*) p
 
 do j =1, N-1
   do i = 1, N-1
   if(p(i)>p(i+1)) then
     m=p(i)
     p(i)=p(i+1)
     p(i+1)=m
   end if
   end do
 end do
 
 m=0
 do i =1, K
   m= m+p(i)
 end do
 
 write(*,*) m
 deallocate(p)
 stop
end program answer2
 

; 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.5220d42cec8f7e2a3aa776460b8f7833 = linkonce constant [73 x i8] c"/home/ubuntu/Downloads/TheStack_IR/Collated/Fortran/Source_1116/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: mustprogress nounwind willreturn allockind("free") memory(argmem: readwrite, inaccessiblemem: readwrite)
declare void @free(ptr allocptr nocapture noundef) local_unnamed_addr #1

; Function Attrs: noreturn
define void @_QQmain() local_unnamed_addr #2 {
  %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 = tail call ptr @_FortranAioBeginExternalListInput(i32 -1, ptr nonnull @_QQcl.5220d42cec8f7e2a3aa776460b8f7833, i32 7)
  %5 = call i1 @_FortranAioInputInteger(ptr %4, ptr nonnull %3, i32 4)
  %6 = call i1 @_FortranAioInputInteger(ptr %4, ptr nonnull %2, i32 4)
  %7 = call i32 @_FortranAioEndIoStatement(ptr %4)
  %8 = load i32, ptr %3, align 4, !tbaa !3
  %9 = call i32 @llvm.smax.i32(i32 %8, i32 0)
  %10 = zext i32 %9 to i64
  %11 = shl nuw nsw i64 %10, 2
  %12 = call ptr @malloc(i64 %11)
  store ptr %12, ptr @_QFEp.0, align 8, !tbaa !7
  store i64 %10, ptr @_QFEp.8, align 8, !tbaa !7
  %13 = call ptr @_FortranAioBeginExternalListInput(i32 -1, ptr nonnull @_QQcl.5220d42cec8f7e2a3aa776460b8f7833, i32 9)
  %.unpack = load ptr, ptr @_QFEp.0, align 8, !tbaa !7
  %.unpack287.unpack.unpack289 = 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 %.unpack287.unpack.unpack289, 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
  %14 = call i1 @_FortranAioInputDescriptor(ptr %13, ptr nonnull %1)
  %15 = call i32 @_FortranAioEndIoStatement(ptr %13)
  %16 = load i32, ptr %3, align 4, !tbaa !3
  %17 = add i32 %16, -1
  %18 = icmp sgt i32 %17, 0
  br i1 %18, label %.lr.ph341, label %._crit_edge342

.lr.ph341:                                        ; preds = %0
  %19 = zext i32 %17 to i64
  %.unpack316 = load ptr, ptr @_QFEp.0, align 8
  br label %20

20:                                               ; preds = %.lr.ph341, %._crit_edge
  %21 = phi i64 [ %19, %.lr.ph341 ], [ %36, %._crit_edge ]
  %22 = load i32, ptr %3, align 4, !tbaa !3
  %23 = add i32 %22, -1
  %24 = icmp sgt i32 %23, 0
  br i1 %24, label %.lr.ph.preheader, label %._crit_edge

.lr.ph.preheader:                                 ; preds = %20
  %25 = zext i32 %23 to i64
  br label %.lr.ph

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

34:                                               ; preds = %.lr.ph
  store i32 %32, ptr %27, align 4, !tbaa !3
  store i32 %28, ptr %31, align 4, !tbaa !3
  br label %35

35:                                               ; preds = %34, %.lr.ph
  %exitcond.not = icmp eq i64 %indvars.iv, %25
  br i1 %exitcond.not, label %._crit_edge, label %.lr.ph

._crit_edge:                                      ; preds = %35, %20
  %36 = add nsw i64 %21, -1
  %37 = icmp sgt i64 %21, 1
  br i1 %37, label %20, label %._crit_edge342

._crit_edge342:                                   ; preds = %._crit_edge, %0
  %38 = load i32, ptr %2, align 4, !tbaa !3
  %39 = icmp sgt i32 %38, 0
  br i1 %39, label %.lr.ph345, label %._crit_edge346

.lr.ph345:                                        ; preds = %._crit_edge342
  %40 = zext i32 %38 to i64
  %.unpack304 = load ptr, ptr @_QFEp.0, align 8, !tbaa !7
  %min.iters.check = icmp ult i32 %38, 8
  br i1 %min.iters.check, label %scalar.ph.preheader, label %vector.ph

vector.ph:                                        ; preds = %.lr.ph345
  %n.vec = and i64 %40, 4294967288
  %ind.end = or i64 %n.vec, 1
  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> [ zeroinitializer, %vector.ph ], [ %43, %vector.body ]
  %vec.phi352 = phi <4 x i32> [ zeroinitializer, %vector.ph ], [ %44, %vector.body ]
  %41 = getelementptr i32, ptr %.unpack304, i64 %index
  %wide.load = load <4 x i32>, ptr %41, align 4, !tbaa !3
  %42 = getelementptr i32, ptr %41, i64 4
  %wide.load353 = load <4 x i32>, ptr %42, align 4, !tbaa !3
  %43 = add <4 x i32> %wide.load, %vec.phi
  %44 = add <4 x i32> %wide.load353, %vec.phi352
  %index.next = add nuw i64 %index, 8
  %45 = icmp eq i64 %index.next, %n.vec
  br i1 %45, label %middle.block, label %vector.body, !llvm.loop !9

middle.block:                                     ; preds = %vector.body
  %bin.rdx = add <4 x i32> %44, %43
  %46 = call i32 @llvm.vector.reduce.add.v4i32(<4 x i32> %bin.rdx)
  %cmp.n = icmp eq i64 %n.vec, %40
  br i1 %cmp.n, label %._crit_edge346, label %scalar.ph.preheader

scalar.ph.preheader:                              ; preds = %.lr.ph345, %middle.block
  %indvars.iv348.ph = phi i64 [ 1, %.lr.ph345 ], [ %ind.end, %middle.block ]
  %.0343.ph = phi i32 [ 0, %.lr.ph345 ], [ %46, %middle.block ]
  br label %scalar.ph

scalar.ph:                                        ; preds = %scalar.ph.preheader, %scalar.ph
  %indvars.iv348 = phi i64 [ %indvars.iv.next349, %scalar.ph ], [ %indvars.iv348.ph, %scalar.ph.preheader ]
  %.0343 = phi i32 [ %50, %scalar.ph ], [ %.0343.ph, %scalar.ph.preheader ]
  %47 = add i64 %indvars.iv348, -1
  %48 = getelementptr i32, ptr %.unpack304, i64 %47
  %49 = load i32, ptr %48, align 4, !tbaa !3
  %50 = add i32 %49, %.0343
  %indvars.iv.next349 = add nuw nsw i64 %indvars.iv348, 1
  %exitcond351.not = icmp eq i64 %indvars.iv348, %40
  br i1 %exitcond351.not, label %._crit_edge346, label %scalar.ph, !llvm.loop !12

._crit_edge346:                                   ; preds = %scalar.ph, %middle.block, %._crit_edge342
  %.0.lcssa = phi i32 [ 0, %._crit_edge342 ], [ %46, %middle.block ], [ %50, %scalar.ph ]
  %51 = call ptr @_FortranAioBeginExternalListOutput(i32 -1, ptr nonnull @_QQcl.5220d42cec8f7e2a3aa776460b8f7833, i32 26)
  %52 = call i1 @_FortranAioOutputInteger32(ptr %51, i32 %.0.lcssa)
  %53 = call i32 @_FortranAioEndIoStatement(ptr %51)
  %.unpack292 = load ptr, ptr @_QFEp.0, align 8, !tbaa !7
  call void @free(ptr %.unpack292)
  store ptr null, ptr @_QFEp.0, align 8, !tbaa !7
  store i64 0, ptr @_QFEp.8, align 8, !tbaa !7
  %54 = 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

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

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

attributes #0 = { mustprogress nofree nounwind willreturn allockind("alloc,uninitialized") allocsize(0) memory(inaccessiblemem: readwrite) "alloc-family"="malloc" }
attributes #1 = { mustprogress nounwind willreturn allockind("free") memory(argmem: readwrite, inaccessiblemem: readwrite) "alloc-family"="malloc" }
attributes #2 = { noreturn }
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}
