program main
integer :: n,i
real :: ans
real,allocatable :: a(:)
read *,n
allocate(a(n))
read *,a

call quicksort(a,1,n)

do i = 1,n-1
	a(i+1) = (a(i) + a(i+1))/2
end do

print *,a(n)
contains
recursive subroutine quicksort(a, first, last)
  implicit none
  real  a(*)
  integer first, last
  integer i, j
  real*8  x, t
  
  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 quicksort(a, first, i - 1)
  if (j + 1 < last)  call quicksort(a, j + 1, last)
end subroutine quicksort
end program
; 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
@_QFEa.8 = internal unnamed_addr global i64 0
@_QQcl.98e52c210e846107479c66fcb9a413ea = linkonce constant [73 x i8] c"/home/ubuntu/Downloads/TheStack_IR/Collated/Fortran/Source_3457/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 = tail call ptr @_FortranAioBeginExternalListInput(i32 -1, ptr nonnull @_QQcl.98e52c210e846107479c66fcb9a413ea, i32 5)
  %5 = call i1 @_FortranAioInputInteger(ptr %4, ptr nonnull %3, i32 4)
  %6 = call i32 @_FortranAioEndIoStatement(ptr %4)
  %7 = load i32, ptr %3, align 4, !tbaa !3
  %8 = call i32 @llvm.smax.i32(i32 %7, i32 0)
  %9 = zext i32 %8 to i64
  %10 = shl nuw nsw i64 %9, 2
  %11 = call ptr @malloc(i64 %10)
  store ptr %11, ptr @_QFEa.0, align 8, !tbaa !7
  store i64 %9, ptr @_QFEa.8, align 8, !tbaa !7
  %12 = call ptr @_FortranAioBeginExternalListInput(i32 -1, ptr nonnull @_QQcl.98e52c210e846107479c66fcb9a413ea, i32 7)
  %.unpack = load ptr, ptr @_QFEa.0, align 8, !tbaa !7
  %.unpack143.unpack.unpack145 = load i64, ptr @_QFEa.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 27, 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 %.unpack143.unpack.unpack145, 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
  %13 = call i1 @_FortranAioInputDescriptor(ptr %12, ptr nonnull %1)
  %14 = call i32 @_FortranAioEndIoStatement(ptr %12)
  %.unpack148 = load ptr, ptr @_QFEa.0, align 8, !tbaa !7
  store i32 1, ptr %2, align 4, !tbaa !3
  call void @_QFPquicksort(ptr %.unpack148, ptr nonnull %2, ptr nonnull %3)
  %15 = load i32, ptr %3, align 4, !tbaa !3
  %16 = add i32 %15, -1
  %17 = icmp sgt i32 %16, 0
  br i1 %17, label %.lver.check, label %._crit_edge

.lver.check:                                      ; preds = %0
  %18 = zext i32 %16 to i64
  %19 = add nsw i64 %18, -1
  %20 = trunc i64 %19 to i32
  %21 = icmp ugt i32 %20, 2147483645
  %22 = icmp ugt i64 %19, 4294967295
  %23 = or i1 %21, %22
  br i1 %23, label %.ph.lver.orig.preheader, label %.ph

.ph.lver.orig.preheader:                          ; preds = %.lver.check
  %xtraiter187 = and i64 %18, 1
  %24 = icmp eq i64 %19, 0
  br i1 %24, label %._crit_edge.loopexit.unr-lcssa, label %.ph.lver.orig.preheader.new

.ph.lver.orig.preheader.new:                      ; preds = %.ph.lver.orig.preheader
  %unroll_iter189 = and i64 %18, 4294967294
  br label %.ph.lver.orig

.ph.lver.orig:                                    ; preds = %.ph.lver.orig, %.ph.lver.orig.preheader.new
  %indvars.iv.lver.orig = phi i64 [ 1, %.ph.lver.orig.preheader.new ], [ %indvars.iv.next.lver.orig.1, %.ph.lver.orig ]
  %niter190 = phi i64 [ 0, %.ph.lver.orig.preheader.new ], [ %niter190.next.1, %.ph.lver.orig ]
  %25 = add nsw i64 %indvars.iv.lver.orig, -1
  %26 = getelementptr float, ptr %.unpack148, i64 %25
  %27 = load float, ptr %26, align 4, !tbaa !3
  %indvars.iv.next.lver.orig = shl i64 %indvars.iv.lver.orig, 32
  %sext.lver.orig = add i64 %indvars.iv.next.lver.orig, 4294967296
  %28 = ashr exact i64 %sext.lver.orig, 32
  %29 = add nsw i64 %28, -1
  %30 = getelementptr float, ptr %.unpack148, i64 %29
  %31 = load float, ptr %30, align 4, !tbaa !3
  %32 = fadd contract float %27, %31
  %33 = fmul contract float %32, 5.000000e-01
  store float %33, ptr %30, align 4, !tbaa !3
  %34 = getelementptr float, ptr %.unpack148, i64 %indvars.iv.lver.orig
  %35 = load float, ptr %34, align 4, !tbaa !3
  %indvars.iv.next.lver.orig.1 = add nuw nsw i64 %indvars.iv.lver.orig, 2
  %sext.lver.orig.1 = shl i64 %indvars.iv.next.lver.orig.1, 32
  %36 = ashr exact i64 %sext.lver.orig.1, 32
  %37 = add nsw i64 %36, -1
  %38 = getelementptr float, ptr %.unpack148, i64 %37
  %39 = load float, ptr %38, align 4, !tbaa !3
  %40 = fadd contract float %35, %39
  %41 = fmul contract float %40, 5.000000e-01
  store float %41, ptr %38, align 4, !tbaa !3
  %niter190.next.1 = add i64 %niter190, 2
  %niter190.ncmp.1 = icmp eq i64 %niter190.next.1, %unroll_iter189
  br i1 %niter190.ncmp.1, label %._crit_edge.loopexit.unr-lcssa, label %.ph.lver.orig

.ph:                                              ; preds = %.lver.check
  %load_initial = load float, ptr %.unpack148, align 4
  %xtraiter = and i64 %18, 1
  %42 = icmp eq i64 %19, 0
  br i1 %42, label %._crit_edge.loopexit186.unr-lcssa, label %.ph.new

.ph.new:                                          ; preds = %.ph
  %unroll_iter = and i64 %18, 4294967294
  br label %43

43:                                               ; preds = %43, %.ph.new
  %store_forwarded = phi float [ %load_initial, %.ph.new ], [ %55, %43 ]
  %indvars.iv = phi i64 [ 1, %.ph.new ], [ %indvars.iv.next.1, %43 ]
  %niter = phi i64 [ 0, %.ph.new ], [ %niter.next.1, %43 ]
  %indvars.iv.next = shl i64 %indvars.iv, 32
  %sext = add i64 %indvars.iv.next, 4294967296
  %44 = ashr exact i64 %sext, 32
  %45 = add nsw i64 %44, -1
  %46 = getelementptr float, ptr %.unpack148, i64 %45
  %47 = load float, ptr %46, align 4, !tbaa !3
  %48 = fadd contract float %store_forwarded, %47
  %49 = fmul contract float %48, 5.000000e-01
  store float %49, ptr %46, align 4, !tbaa !3
  %indvars.iv.next.1 = add nuw nsw i64 %indvars.iv, 2
  %sext.1 = shl i64 %indvars.iv.next.1, 32
  %50 = ashr exact i64 %sext.1, 32
  %51 = add nsw i64 %50, -1
  %52 = getelementptr float, ptr %.unpack148, i64 %51
  %53 = load float, ptr %52, align 4, !tbaa !3
  %54 = fadd contract float %49, %53
  %55 = fmul contract float %54, 5.000000e-01
  store float %55, ptr %52, align 4, !tbaa !3
  %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_edge.loopexit186.unr-lcssa.loopexit, label %43

._crit_edge.loopexit.unr-lcssa:                   ; preds = %.ph.lver.orig, %.ph.lver.orig.preheader
  %indvars.iv.lver.orig.unr = phi i64 [ 1, %.ph.lver.orig.preheader ], [ %indvars.iv.next.lver.orig.1, %.ph.lver.orig ]
  %lcmp.mod188.not = icmp eq i64 %xtraiter187, 0
  br i1 %lcmp.mod188.not, label %._crit_edge, label %.ph.lver.orig.epil

.ph.lver.orig.epil:                               ; preds = %._crit_edge.loopexit.unr-lcssa
  %56 = add nsw i64 %indvars.iv.lver.orig.unr, -1
  %57 = getelementptr float, ptr %.unpack148, i64 %56
  %58 = load float, ptr %57, align 4, !tbaa !3
  %indvars.iv.next.lver.orig.epil = shl i64 %indvars.iv.lver.orig.unr, 32
  %sext.lver.orig.epil = add i64 %indvars.iv.next.lver.orig.epil, 4294967296
  %59 = ashr exact i64 %sext.lver.orig.epil, 32
  %60 = add nsw i64 %59, -1
  %61 = getelementptr float, ptr %.unpack148, i64 %60
  %62 = load float, ptr %61, align 4, !tbaa !3
  %63 = fadd contract float %58, %62
  %64 = fmul contract float %63, 5.000000e-01
  store float %64, ptr %61, align 4, !tbaa !3
  br label %._crit_edge

._crit_edge.loopexit186.unr-lcssa.loopexit:       ; preds = %43
  %65 = shl i64 %indvars.iv, 32
  %66 = add i64 %65, 12884901888
  %67 = ashr exact i64 %66, 32
  %68 = add nsw i64 %67, -1
  br label %._crit_edge.loopexit186.unr-lcssa

._crit_edge.loopexit186.unr-lcssa:                ; preds = %._crit_edge.loopexit186.unr-lcssa.loopexit, %.ph
  %store_forwarded.unr = phi float [ %load_initial, %.ph ], [ %55, %._crit_edge.loopexit186.unr-lcssa.loopexit ]
  %indvars.iv.unr = phi i64 [ 1, %.ph ], [ %68, %._crit_edge.loopexit186.unr-lcssa.loopexit ]
  %lcmp.mod.not = icmp eq i64 %xtraiter, 0
  br i1 %lcmp.mod.not, label %._crit_edge, label %._crit_edge.loopexit186.epilog-lcssa

._crit_edge.loopexit186.epilog-lcssa:             ; preds = %._crit_edge.loopexit186.unr-lcssa
  %69 = getelementptr float, ptr %.unpack148, i64 %indvars.iv.unr
  %70 = load float, ptr %69, align 4, !tbaa !3
  %71 = fadd contract float %store_forwarded.unr, %70
  %72 = fmul contract float %71, 5.000000e-01
  store float %72, ptr %69, align 4, !tbaa !3
  br label %._crit_edge

._crit_edge:                                      ; preds = %._crit_edge.loopexit186.epilog-lcssa, %._crit_edge.loopexit186.unr-lcssa, %.ph.lver.orig.epil, %._crit_edge.loopexit.unr-lcssa, %0
  %73 = call ptr @_FortranAioBeginExternalListOutput(i32 -1, ptr nonnull @_QQcl.98e52c210e846107479c66fcb9a413ea, i32 15)
  %.unpack160 = load ptr, ptr @_QFEa.0, align 8, !tbaa !7
  %74 = load i32, ptr %3, align 4, !tbaa !3
  %75 = sext i32 %74 to i64
  %76 = add nsw i64 %75, -1
  %77 = getelementptr float, ptr %.unpack160, i64 %76
  %78 = load float, ptr %77, align 4, !tbaa !3
  %79 = call i1 @_FortranAioOutputReal32(ptr %73, float %78)
  %80 = call i32 @_FortranAioEndIoStatement(ptr %73)
  ret void
}

; Function Attrs: nofree nosync nounwind memory(argmem: readwrite)
define void @_QFPquicksort(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 float, ptr %0, i64 %10
  %12 = load float, ptr %11, align 4, !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 float, ptr %0, i64 %15
  %17 = load float, ptr %16, align 4, !tbaa !3
  %18 = fcmp olt float %17, %12
  %19 = add i32 %.0, 1
  br i1 %18, label %13, label %.preheader

.preheader:                                       ; preds = %13
  %20 = getelementptr float, 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 float, ptr %0, i64 %23
  %25 = load float, ptr %24, align 4, !tbaa !3
  %26 = fcmp olt float %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 @_QFPquicksort(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 @_QFPquicksort(ptr nonnull %0, ptr nonnull %4, ptr nonnull %2)
  br label %39

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

40:                                               ; preds = %28
  %41 = getelementptr float, ptr %0, i64 %23
  store float %25, ptr %20, align 4, !tbaa !3
  store float %17, ptr %41, align 4, !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 @_FortranAioOutputReal32(ptr, float) local_unnamed_addr

; 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 = { nofree nosync nounwind memory(argmem: readwrite) }
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}
