implicit none
integer :: n,m,x
integer,allocatable :: a(:),c(:)
integer :: i,j
read *,n,m,x
allocate(a(m))
read *,(a(i),i=1,m)
allocate(c(0:n))
c(:) = 0
do i = 1, m
   c(a(i)) = 1
enddo
i = sum(c(0:x-1))
j = sum(c(x+1:n))
if (i < j) then
   write(6,'(i0)') i
else
   write(6,'(i0)') j
endif
end
; 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
@_QFEc = internal unnamed_addr global { ptr, i64, i32, i8, i8, i8, i8, [1 x [3 x i64]] } { ptr null, i64 ptrtoint (ptr getelementptr (i32, ptr null, i32 1) to i64), i32 20180515, i8 1, i8 9, i8 2, i8 0, [1 x [3 x i64]] [[3 x i64] [i64 1, i64 0, i64 ptrtoint (ptr getelementptr (i32, ptr null, i32 1) to i64)]] }
@_QQcl.fd6eb3f40f2d8f9a57152f0e5dc7d722 = linkonce constant [73 x i8] c"/home/ubuntu/Downloads/TheStack_IR/Collated/Fortran/Source_6084/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

define void @_QQmain() local_unnamed_addr {
  %1 = alloca i32, align 4
  %2 = alloca i32, align 4
  %3 = alloca i32, align 4
  %4 = tail call ptr @_FortranAioBeginExternalListInput(i32 -1, ptr nonnull @_QQcl.fd6eb3f40f2d8f9a57152f0e5dc7d722, i32 5)
  %5 = call i1 @_FortranAioInputInteger(ptr %4, ptr nonnull %2, i32 4)
  %6 = call i1 @_FortranAioInputInteger(ptr %4, ptr nonnull %1, i32 4)
  %7 = call i1 @_FortranAioInputInteger(ptr %4, ptr nonnull %3, i32 4)
  %8 = call i32 @_FortranAioEndIoStatement(ptr %4)
  %9 = load i32, ptr %1, 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 @_QFEa.0, align 8, !tbaa !7
  %14 = call ptr @_FortranAioBeginExternalListInput(i32 -1, ptr nonnull @_QQcl.fd6eb3f40f2d8f9a57152f0e5dc7d722, i32 7)
  %15 = load i32, ptr %1, align 4, !tbaa !3
  %16 = icmp sgt i32 %15, 0
  br i1 %16, label %.lr.ph.preheader, label %._crit_edge

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

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

._crit_edge:                                      ; preds = %.lr.ph, %0
  %24 = call i32 @_FortranAioEndIoStatement(ptr %14)
  %25 = load i32, ptr %2, align 4, !tbaa !3
  %26 = call i32 @llvm.smax.i32(i32 %25, i32 -1)
  %27 = sext i32 %26 to i64
  %28 = add nsw i64 %27, 1
  %29 = shl nuw nsw i64 %28, 2
  %30 = call ptr @malloc(i64 %29)
  %31 = icmp eq i64 %28, 0
  %.neg = sext i1 %31 to i64
  %32 = zext i1 %31 to i64
  store ptr %30, ptr @_QFEc, align 16, !tbaa !7
  store i64 4, ptr getelementptr inbounds ({ ptr, i64, i32, i8, i8, i8, i8, [1 x [3 x i64]] }, ptr @_QFEc, 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 @_QFEc, 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 @_QFEc, i64 0, i32 3), align 4, !tbaa !7
  store i8 9, ptr getelementptr inbounds ({ ptr, i64, i32, i8, i8, i8, i8, [1 x [3 x i64]] }, ptr @_QFEc, 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 @_QFEc, 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 @_QFEc, i64 0, i32 6), align 1, !tbaa !7
  store i64 %32, ptr getelementptr inbounds ({ ptr, i64, i32, i8, i8, i8, i8, [1 x [3 x i64]] }, ptr @_QFEc, i64 0, i32 7), align 8, !tbaa !7
  store i64 %28, ptr getelementptr inbounds ({ ptr, i64, i32, i8, i8, i8, i8, [1 x [3 x i64]] }, ptr @_QFEc, i64 0, i32 7, i64 0, i64 1), align 16, !tbaa !7
  store i64 4, ptr getelementptr inbounds ({ ptr, i64, i32, i8, i8, i8, i8, [1 x [3 x i64]] }, ptr @_QFEc, i64 0, i32 7, i64 0, i64 2), align 8, !tbaa !7
  %33 = icmp sgt i32 %25, -1
  br i1 %33, label %.lr.ph342.preheader, label %._crit_edge343

.lr.ph342.preheader:                              ; preds = %._crit_edge
  %34 = add nsw i64 %27, 2
  %smin = call i64 @llvm.smin.i64(i64 %28, i64 1)
  %35 = sub nuw nsw i64 %34, %smin
  %36 = shl nuw nsw i64 %35, 2
  call void @llvm.memset.p0.i64(ptr align 4 %30, i8 0, i64 %36, i1 false), !tbaa !3
  br label %._crit_edge343

._crit_edge343:                                   ; preds = %.lr.ph342.preheader, %._crit_edge
  %37 = load i32, ptr %1, align 4, !tbaa !3
  %38 = icmp sgt i32 %37, 0
  br i1 %38, label %.lr.ph345, label %._crit_edge346

.lr.ph345:                                        ; preds = %._crit_edge343
  %39 = zext i32 %37 to i64
  %.unpack301 = load ptr, ptr @_QFEa.0, align 8, !tbaa !7
  %xtraiter = and i64 %39, 3
  %40 = icmp ult i32 %37, 4
  br i1 %40, label %._crit_edge346.loopexit.unr-lcssa, label %.lr.ph345.new

.lr.ph345.new:                                    ; preds = %.lr.ph345
  %unroll_iter = and i64 %39, 4294967292
  br label %41

41:                                               ; preds = %41, %.lr.ph345.new
  %indvars.iv = phi i64 [ 1, %.lr.ph345.new ], [ %indvars.iv.next.3, %41 ]
  %niter = phi i64 [ 0, %.lr.ph345.new ], [ %niter.next.3, %41 ]
  %42 = add nsw i64 %indvars.iv, -1
  %43 = getelementptr i32, ptr %.unpack301, i64 %42
  %44 = load i32, ptr %43, align 4, !tbaa !3
  %45 = sext i32 %44 to i64
  %46 = sub nsw i64 %45, %32
  %47 = getelementptr i32, ptr %30, i64 %46
  store i32 1, ptr %47, align 4, !tbaa !3
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %48 = getelementptr i32, ptr %.unpack301, i64 %indvars.iv
  %49 = load i32, ptr %48, align 4, !tbaa !3
  %50 = sext i32 %49 to i64
  %51 = sub nsw i64 %50, %32
  %52 = getelementptr i32, ptr %30, i64 %51
  store i32 1, ptr %52, align 4, !tbaa !3
  %indvars.iv.next.1 = add nuw nsw i64 %indvars.iv, 2
  %53 = getelementptr i32, ptr %.unpack301, i64 %indvars.iv.next
  %54 = load i32, ptr %53, align 4, !tbaa !3
  %55 = sext i32 %54 to i64
  %56 = sub nsw i64 %55, %32
  %57 = getelementptr i32, ptr %30, i64 %56
  store i32 1, ptr %57, align 4, !tbaa !3
  %58 = getelementptr i32, ptr %.unpack301, i64 %indvars.iv.next.1
  %59 = load i32, ptr %58, align 4, !tbaa !3
  %60 = sext i32 %59 to i64
  %61 = sub nsw i64 %60, %32
  %62 = getelementptr i32, ptr %30, i64 %61
  store i32 1, ptr %62, align 4, !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_edge346.loopexit.unr-lcssa, label %41

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

.epil.preheader:                                  ; preds = %._crit_edge346.loopexit.unr-lcssa, %.epil.preheader
  %indvars.iv.epil = phi i64 [ %indvars.iv.next.epil, %.epil.preheader ], [ %indvars.iv.unr, %._crit_edge346.loopexit.unr-lcssa ]
  %epil.iter = phi i64 [ %epil.iter.next, %.epil.preheader ], [ 0, %._crit_edge346.loopexit.unr-lcssa ]
  %63 = add nsw i64 %indvars.iv.epil, -1
  %64 = getelementptr i32, ptr %.unpack301, i64 %63
  %65 = load i32, ptr %64, align 4, !tbaa !3
  %66 = sext i32 %65 to i64
  %67 = sub nsw i64 %66, %32
  %68 = getelementptr i32, ptr %30, i64 %67
  store i32 1, ptr %68, align 4, !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_edge346, label %.epil.preheader, !llvm.loop !9

._crit_edge346:                                   ; preds = %._crit_edge346.loopexit.unr-lcssa, %.epil.preheader, %._crit_edge343
  %69 = load i32, ptr %3, align 4, !tbaa !3
  %70 = add i32 %69, -1
  %71 = call i32 @llvm.smax.i32(i32 %70, i32 -1)
  %72 = sext i32 %71 to i64
  %73 = getelementptr i32, ptr %30, i64 %.neg
  %.not = icmp slt i32 %70, 0
  br i1 %.not, label %_FortranASumInteger4x1_contract_simplified.exit, label %.lr.ph.i.preheader

.lr.ph.i.preheader:                               ; preds = %._crit_edge346
  %74 = add nsw i64 %72, 1
  %min.iters.check = icmp ult i64 %74, 8
  br i1 %min.iters.check, label %.lr.ph.i.preheader375, label %vector.ph

vector.ph:                                        ; preds = %.lr.ph.i.preheader
  %n.vec = and i64 %74, -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> [ zeroinitializer, %vector.ph ], [ %78, %vector.body ]
  %vec.phi352 = phi <4 x i32> [ zeroinitializer, %vector.ph ], [ %79, %vector.body ]
  %75 = shl i64 %index, 2
  %76 = getelementptr i8, ptr %73, i64 %75
  %wide.load = load <4 x i32>, ptr %76, align 4, !tbaa !3
  %77 = getelementptr i32, ptr %76, i64 4
  %wide.load353 = load <4 x i32>, ptr %77, align 4, !tbaa !3
  %78 = add <4 x i32> %wide.load, %vec.phi
  %79 = add <4 x i32> %wide.load353, %vec.phi352
  %index.next = add nuw i64 %index, 8
  %80 = icmp eq i64 %index.next, %n.vec
  br i1 %80, label %middle.block, label %vector.body, !llvm.loop !11

middle.block:                                     ; preds = %vector.body
  %bin.rdx = add <4 x i32> %79, %78
  %81 = call i32 @llvm.vector.reduce.add.v4i32(<4 x i32> %bin.rdx)
  %cmp.n = icmp eq i64 %74, %n.vec
  br i1 %cmp.n, label %_FortranASumInteger4x1_contract_simplified.exit, label %.lr.ph.i.preheader375

.lr.ph.i.preheader375:                            ; preds = %.lr.ph.i.preheader, %middle.block
  %.ph376 = phi i32 [ 0, %.lr.ph.i.preheader ], [ %81, %middle.block ]
  %.ph377 = phi i64 [ 0, %.lr.ph.i.preheader ], [ %n.vec, %middle.block ]
  br label %.lr.ph.i

.lr.ph.i:                                         ; preds = %.lr.ph.i.preheader375, %.lr.ph.i
  %82 = phi i32 [ %87, %.lr.ph.i ], [ %.ph376, %.lr.ph.i.preheader375 ]
  %83 = phi i64 [ %88, %.lr.ph.i ], [ %.ph377, %.lr.ph.i.preheader375 ]
  %84 = shl i64 %83, 2
  %85 = getelementptr i8, ptr %73, i64 %84
  %86 = load i32, ptr %85, align 4, !tbaa !3
  %87 = add i32 %86, %82
  %88 = add nuw nsw i64 %83, 1
  %exitcond.not.i = icmp eq i64 %83, %72
  br i1 %exitcond.not.i, label %_FortranASumInteger4x1_contract_simplified.exit, label %.lr.ph.i, !llvm.loop !14

_FortranASumInteger4x1_contract_simplified.exit:  ; preds = %.lr.ph.i, %middle.block, %._crit_edge346
  %.lcssa.i = phi i32 [ 0, %._crit_edge346 ], [ %81, %middle.block ], [ %87, %.lr.ph.i ]
  %89 = add i32 %69, 1
  %90 = sext i32 %89 to i64
  %91 = sext i32 %25 to i64
  %92 = sub nsw i64 %90, %32
  %93 = sub nsw i64 %91, %90
  %94 = call i64 @llvm.smax.i64(i64 %93, i64 -1)
  %95 = getelementptr i32, ptr %30, i64 %92
  %.not339 = icmp slt i64 %93, 0
  br i1 %.not339, label %_FortranASumInteger4x1_contract_simplified.exit328, label %.lr.ph.i325.preheader

.lr.ph.i325.preheader:                            ; preds = %_FortranASumInteger4x1_contract_simplified.exit
  %96 = add nsw i64 %94, 1
  %min.iters.check356 = icmp ult i64 %96, 8
  br i1 %min.iters.check356, label %.lr.ph.i325.preheader371, label %vector.ph357

vector.ph357:                                     ; preds = %.lr.ph.i325.preheader
  %n.vec359 = and i64 %96, -8
  br label %vector.body362

vector.body362:                                   ; preds = %vector.body362, %vector.ph357
  %index363 = phi i64 [ 0, %vector.ph357 ], [ %index.next368, %vector.body362 ]
  %vec.phi364 = phi <4 x i32> [ zeroinitializer, %vector.ph357 ], [ %100, %vector.body362 ]
  %vec.phi365 = phi <4 x i32> [ zeroinitializer, %vector.ph357 ], [ %101, %vector.body362 ]
  %97 = shl i64 %index363, 2
  %98 = getelementptr i8, ptr %95, i64 %97
  %wide.load366 = load <4 x i32>, ptr %98, align 4, !tbaa !3
  %99 = getelementptr i32, ptr %98, i64 4
  %wide.load367 = load <4 x i32>, ptr %99, align 4, !tbaa !3
  %100 = add <4 x i32> %wide.load366, %vec.phi364
  %101 = add <4 x i32> %wide.load367, %vec.phi365
  %index.next368 = add nuw i64 %index363, 8
  %102 = icmp eq i64 %index.next368, %n.vec359
  br i1 %102, label %middle.block354, label %vector.body362, !llvm.loop !15

middle.block354:                                  ; preds = %vector.body362
  %bin.rdx369 = add <4 x i32> %101, %100
  %103 = call i32 @llvm.vector.reduce.add.v4i32(<4 x i32> %bin.rdx369)
  %cmp.n361 = icmp eq i64 %96, %n.vec359
  br i1 %cmp.n361, label %_FortranASumInteger4x1_contract_simplified.exit328, label %.lr.ph.i325.preheader371

.lr.ph.i325.preheader371:                         ; preds = %.lr.ph.i325.preheader, %middle.block354
  %.ph = phi i32 [ 0, %.lr.ph.i325.preheader ], [ %103, %middle.block354 ]
  %.ph372 = phi i64 [ 0, %.lr.ph.i325.preheader ], [ %n.vec359, %middle.block354 ]
  br label %.lr.ph.i325

.lr.ph.i325:                                      ; preds = %.lr.ph.i325.preheader371, %.lr.ph.i325
  %104 = phi i32 [ %109, %.lr.ph.i325 ], [ %.ph, %.lr.ph.i325.preheader371 ]
  %105 = phi i64 [ %110, %.lr.ph.i325 ], [ %.ph372, %.lr.ph.i325.preheader371 ]
  %106 = shl i64 %105, 2
  %107 = getelementptr i8, ptr %95, i64 %106
  %108 = load i32, ptr %107, align 4, !tbaa !3
  %109 = add i32 %108, %104
  %110 = add nuw nsw i64 %105, 1
  %exitcond.not.i326 = icmp eq i64 %105, %94
  br i1 %exitcond.not.i326, label %_FortranASumInteger4x1_contract_simplified.exit328, label %.lr.ph.i325, !llvm.loop !16

_FortranASumInteger4x1_contract_simplified.exit328: ; preds = %.lr.ph.i325, %middle.block354, %_FortranASumInteger4x1_contract_simplified.exit
  %.lcssa.i327 = phi i32 [ 0, %_FortranASumInteger4x1_contract_simplified.exit ], [ %103, %middle.block354 ], [ %109, %.lr.ph.i325 ]
  %111 = icmp slt i32 %.lcssa.i, %.lcssa.i327
  br i1 %111, label %112, label %115

112:                                              ; preds = %_FortranASumInteger4x1_contract_simplified.exit328
  %113 = call ptr @_FortranAioBeginExternalFormattedOutput(ptr nonnull @_QQcl.28693029, i64 4, ptr null, i32 6, ptr nonnull @_QQcl.fd6eb3f40f2d8f9a57152f0e5dc7d722, i32 16)
  %114 = call i1 @_FortranAioOutputInteger32(ptr %113, i32 %.lcssa.i)
  br label %118

115:                                              ; preds = %_FortranASumInteger4x1_contract_simplified.exit328
  %116 = call ptr @_FortranAioBeginExternalFormattedOutput(ptr nonnull @_QQcl.28693029, i64 4, ptr null, i32 6, ptr nonnull @_QQcl.fd6eb3f40f2d8f9a57152f0e5dc7d722, i32 18)
  %117 = call i1 @_FortranAioOutputInteger32(ptr %116, i32 %.lcssa.i327)
  br label %118

118:                                              ; preds = %112, %115
  %.sink = phi ptr [ %113, %112 ], [ %116, %115 ]
  %119 = call i32 @_FortranAioEndIoStatement(ptr %.sink)
  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 i64 @llvm.smax.i64(i64, i64) #1

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

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i64 @llvm.smin.i64(i64, i64) #1

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #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 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #2 = { nocallback nofree nounwind willreturn memory(argmem: write) }
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}
!10 = !{!"llvm.loop.unroll.disable"}
!11 = distinct !{!11, !12, !13}
!12 = !{!"llvm.loop.isvectorized", i32 1}
!13 = !{!"llvm.loop.unroll.runtime.disable"}
!14 = distinct !{!14, !13, !12}
!15 = distinct !{!15, !12, !13}
!16 = distinct !{!16, !13, !12}
