program DBS
 implicit none
 integer::N=0,K=0,s=0,i,ishota,ishotb,p=0,q=0
 integer,allocatable::a(:)
 read(*,*)N,K
 allocate(a(N))
 read(*,*)(a(i),i=1,N)
 do ishota=1,N
  do ishotb=1,N-1
   if(a(ishotb)>a(ishotb+1))then
    p=a(ishotb)
    q=a(ishotb+1)
    a(ishotb)=q
    a(ishotb+1)=p
   end if
  end do
 end do
 s=sum(a(1:K))
 print'(i0)',s
 deallocate(a)
end program DBS
; 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"

@_QFEa.0 = internal unnamed_addr global ptr null
@_QFEk = internal global i32 0
@_QFEn = internal global i32 0
@_QFEs = internal unnamed_addr global i32 0
@_QQcl.10c7ad27a4b484e55baeb4a76b61ac08 = linkonce constant [73 x i8] c"/home/ubuntu/Downloads/TheStack_IR/Collated/Fortran/Source_1117/source.f\00"
@_QQcl.28693029 = linkonce constant [4 x i8] c"(i0)"
@_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

define void @_QQmain() local_unnamed_addr {
  %1 = tail call ptr @_FortranAioBeginExternalListInput(i32 -1, ptr nonnull @_QQcl.10c7ad27a4b484e55baeb4a76b61ac08, i32 5)
  %2 = tail call i1 @_FortranAioInputInteger(ptr %1, ptr nonnull @_QFEn, i32 4)
  %3 = tail call i1 @_FortranAioInputInteger(ptr %1, ptr nonnull @_QFEk, i32 4)
  %4 = tail call i32 @_FortranAioEndIoStatement(ptr %1)
  %5 = load i32, ptr @_QFEn, align 4, !tbaa !3
  %6 = tail call i32 @llvm.smax.i32(i32 %5, i32 0)
  %7 = zext i32 %6 to i64
  %8 = shl nuw nsw i64 %7, 2
  %9 = tail call ptr @malloc(i64 %8)
  store ptr %9, ptr @_QFEa.0, align 8, !tbaa !7
  %10 = tail call ptr @_FortranAioBeginExternalListInput(i32 -1, ptr nonnull @_QQcl.10c7ad27a4b484e55baeb4a76b61ac08, i32 7)
  %11 = load i32, ptr @_QFEn, align 4, !tbaa !3
  %12 = icmp sgt i32 %11, 0
  br i1 %12, label %.lr.ph.preheader, label %._crit_edge

.lr.ph.preheader:                                 ; preds = %0
  %13 = zext i32 %11 to i64
  br label %.lr.ph

.lr.ph:                                           ; preds = %.lr.ph.preheader, %.lr.ph
  %14 = phi i64 [ %19, %.lr.ph ], [ 1, %.lr.ph.preheader ]
  %.unpack377 = load ptr, ptr @_QFEa.0, align 8, !tbaa !7
  %sext = shl i64 %14, 32
  %15 = ashr exact i64 %sext, 32
  %16 = add nsw i64 %15, -1
  %17 = getelementptr i32, ptr %.unpack377, i64 %16
  %18 = tail call i1 @_FortranAioInputInteger(ptr %10, ptr %17, i32 4)
  %19 = add nuw nsw i64 %14, 1
  %exitcond.not = icmp eq i64 %14, %13
  br i1 %exitcond.not, label %._crit_edge, label %.lr.ph

._crit_edge:                                      ; preds = %.lr.ph, %0
  %20 = tail call i32 @_FortranAioEndIoStatement(ptr %10)
  %21 = load i32, ptr @_QFEn, align 4, !tbaa !3
  %22 = icmp sgt i32 %21, 0
  br i1 %22, label %.lr.ph393, label %._crit_edge.._crit_edge394_crit_edge

._crit_edge.._crit_edge394_crit_edge:             ; preds = %._crit_edge
  %.unpack.pre = load ptr, ptr @_QFEa.0, align 8, !tbaa !7
  br label %._crit_edge394

.lr.ph393:                                        ; preds = %._crit_edge
  %23 = zext i32 %21 to i64
  %.unpack329 = load ptr, ptr @_QFEa.0, align 8
  br label %24

24:                                               ; preds = %.lr.ph393, %._crit_edge391
  %25 = phi i64 [ %23, %.lr.ph393 ], [ %40, %._crit_edge391 ]
  %26 = load i32, ptr @_QFEn, align 4, !tbaa !3
  %27 = add i32 %26, -1
  %28 = icmp sgt i32 %27, 0
  br i1 %28, label %.lr.ph390.preheader, label %._crit_edge391

.lr.ph390.preheader:                              ; preds = %24
  %29 = zext i32 %27 to i64
  br label %.lr.ph390

.lr.ph390:                                        ; preds = %.lr.ph390.preheader, %39
  %indvars.iv = phi i64 [ 1, %.lr.ph390.preheader ], [ %indvars.iv.next, %39 ]
  %30 = add nsw i64 %indvars.iv, -1
  %31 = getelementptr i32, ptr %.unpack329, i64 %30
  %32 = load i32, ptr %31, align 4, !tbaa !3
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %sext399 = shl i64 %indvars.iv.next, 32
  %33 = ashr exact i64 %sext399, 32
  %34 = add nsw i64 %33, -1
  %35 = getelementptr i32, ptr %.unpack329, i64 %34
  %36 = load i32, ptr %35, align 4, !tbaa !3
  %37 = icmp sgt i32 %32, %36
  br i1 %37, label %38, label %39

38:                                               ; preds = %.lr.ph390
  store i32 %36, ptr %31, align 4, !tbaa !3
  store i32 %32, ptr %35, align 4, !tbaa !3
  br label %39

39:                                               ; preds = %38, %.lr.ph390
  %exitcond396.not = icmp eq i64 %indvars.iv, %29
  br i1 %exitcond396.not, label %._crit_edge391, label %.lr.ph390

._crit_edge391:                                   ; preds = %39, %24
  %40 = add nsw i64 %25, -1
  %41 = icmp sgt i64 %25, 1
  br i1 %41, label %24, label %._crit_edge394

._crit_edge394:                                   ; preds = %._crit_edge391, %._crit_edge.._crit_edge394_crit_edge
  %.unpack = phi ptr [ %.unpack.pre, %._crit_edge.._crit_edge394_crit_edge ], [ %.unpack329, %._crit_edge391 ]
  %42 = load i32, ptr @_QFEk, align 4, !tbaa !3
  %43 = tail call i32 @llvm.smax.i32(i32 %42, i32 0)
  %44 = zext i32 %43 to i64
  %.not = icmp slt i32 %42, 1
  br i1 %.not, label %_FortranASumInteger4x1_contract_simplified.exit, label %.lr.ph.i.preheader

.lr.ph.i.preheader:                               ; preds = %._crit_edge394
  %min.iters.check = icmp ult i32 %43, 8
  br i1 %min.iters.check, label %.lr.ph.i.preheader402, label %vector.ph

vector.ph:                                        ; preds = %.lr.ph.i.preheader
  %n.vec = and i64 %44, 2147483640
  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 ], [ %48, %vector.body ]
  %vec.phi400 = phi <4 x i32> [ zeroinitializer, %vector.ph ], [ %49, %vector.body ]
  %45 = shl i64 %index, 2
  %46 = getelementptr i8, ptr %.unpack, i64 %45
  %wide.load = load <4 x i32>, ptr %46, align 4, !tbaa !3
  %47 = getelementptr i32, ptr %46, i64 4
  %wide.load401 = load <4 x i32>, ptr %47, align 4, !tbaa !3
  %48 = add <4 x i32> %wide.load, %vec.phi
  %49 = add <4 x i32> %wide.load401, %vec.phi400
  %index.next = add nuw i64 %index, 8
  %50 = icmp eq i64 %index.next, %n.vec
  br i1 %50, label %middle.block, label %vector.body, !llvm.loop !9

middle.block:                                     ; preds = %vector.body
  %bin.rdx = add <4 x i32> %49, %48
  %51 = tail call i32 @llvm.vector.reduce.add.v4i32(<4 x i32> %bin.rdx)
  %cmp.n = icmp eq i64 %n.vec, %44
  br i1 %cmp.n, label %_FortranASumInteger4x1_contract_simplified.exit, label %.lr.ph.i.preheader402

.lr.ph.i.preheader402:                            ; preds = %.lr.ph.i.preheader, %middle.block
  %.ph = phi i32 [ 0, %.lr.ph.i.preheader ], [ %51, %middle.block ]
  %.ph403 = phi i64 [ 0, %.lr.ph.i.preheader ], [ %n.vec, %middle.block ]
  br label %.lr.ph.i

.lr.ph.i:                                         ; preds = %.lr.ph.i.preheader402, %.lr.ph.i
  %52 = phi i32 [ %57, %.lr.ph.i ], [ %.ph, %.lr.ph.i.preheader402 ]
  %53 = phi i64 [ %58, %.lr.ph.i ], [ %.ph403, %.lr.ph.i.preheader402 ]
  %54 = shl i64 %53, 2
  %55 = getelementptr i8, ptr %.unpack, i64 %54
  %56 = load i32, ptr %55, align 4, !tbaa !3
  %57 = add i32 %56, %52
  %58 = add nuw nsw i64 %53, 1
  %exitcond.not.i = icmp eq i64 %58, %44
  br i1 %exitcond.not.i, label %_FortranASumInteger4x1_contract_simplified.exit, label %.lr.ph.i, !llvm.loop !12

_FortranASumInteger4x1_contract_simplified.exit:  ; preds = %.lr.ph.i, %middle.block, %._crit_edge394
  %.lcssa.i = phi i32 [ 0, %._crit_edge394 ], [ %51, %middle.block ], [ %57, %.lr.ph.i ]
  store i32 %.lcssa.i, ptr @_QFEs, align 4, !tbaa !3
  %59 = tail call ptr @_FortranAioBeginExternalFormattedOutput(ptr nonnull @_QQcl.28693029, i64 4, ptr null, i32 -1, ptr nonnull @_QQcl.10c7ad27a4b484e55baeb4a76b61ac08, i32 19)
  %60 = load i32, ptr @_QFEs, align 4, !tbaa !3
  %61 = tail call i1 @_FortranAioOutputInteger32(ptr %59, i32 %60)
  %62 = tail call i32 @_FortranAioEndIoStatement(ptr %59)
  %.unpack317 = load ptr, ptr @_QFEa.0, align 8, !tbaa !7
  tail call void @free(ptr %.unpack317)
  store ptr null, ptr @_QFEa.0, align 8, !tbaa !7
  ret void
}

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

declare i1 @_FortranAioOutputInteger32(ptr, i32) local_unnamed_addr

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

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

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