implicit none
integer(8):: n,y,i,j,count,s_len
character(10**5+5)::s,s_rev
character(5)::a
character(5)::b
character(6)::c
character(7)::d
 
a="maerd"
b="esare"
c="resare"
d="remaerd"
 
s_rev=""
 
read(5,*) s
s_len=len_trim(s)
 
do i=1,s_len
    s_rev(s_len+1-i:s_len+1-i)=s(i:i)
enddo
 
!write(6,*) trim(s_rev)
 
count=1
 
do while (count<=s_len)
 
    
    if (index(s_rev,a)==1) then
        count=count+len(a)
        s_rev=s_rev(len(a)+1:) 

    else if (index(s_rev,b)==1) then
        count=count+len(b)
        s_rev=s_rev(len(b)+1:)

    else if (index(s_rev,c)==1) then
        count=count+len(c)
        s_rev=s_rev(len(c)+1:)

    else if (index(s_rev,d)==1) then
        count=count+len(d)
        s_rev=s_rev(len(d)+1:)

    else 
        write(6,*) "NO"
        goto 100
        
    endif

    
enddo
 
write(6,*) "YES"
 
100 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"

@_QFEs = internal global [100005 x i8] undef
@_QFEs_rev = internal global [100005 x i8] undef
@_QQcl.6D61657264 = linkonce local_unnamed_addr constant [5 x i8] c"maerd"
@_QQcl.6573617265 = linkonce local_unnamed_addr constant [5 x i8] c"esare"
@_QQcl.726573617265 = linkonce local_unnamed_addr constant [6 x i8] c"resare"
@_QQcl.72656D61657264 = linkonce local_unnamed_addr constant [7 x i8] c"remaerd"
@_QQcl.a5d52d94e9dd8b176aefc7606845a8d8 = linkonce constant [73 x i8] c"/home/ubuntu/Downloads/TheStack_IR/Collated/Fortran/Source_7683/source.f\00"
@_QQcl.4E4F = linkonce constant [2 x i8] c"NO"
@_QQcl.594553 = linkonce constant [3 x i8] c"YES"
@_QQEnvironmentDefaults = local_unnamed_addr constant ptr null

define void @_QQmain() local_unnamed_addr {
  %1 = alloca [5 x i8], align 1
  %2 = alloca [5 x i8], align 1
  %3 = alloca [6 x i8], align 1
  %4 = alloca [7 x i8], align 1
  call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 1 dereferenceable(5) %1, ptr noundef nonnull align 1 dereferenceable(5) @_QQcl.6D61657264, i64 5, i1 false)
  call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 1 dereferenceable(5) %2, ptr noundef nonnull align 1 dereferenceable(5) @_QQcl.6573617265, i64 5, i1 false)
  call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 1 dereferenceable(6) %3, ptr noundef nonnull align 1 dereferenceable(6) @_QQcl.726573617265, i64 6, i1 false)
  call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 1 dereferenceable(7) %4, ptr noundef nonnull align 1 dereferenceable(7) @_QQcl.72656D61657264, i64 7, i1 false)
  tail call void @llvm.memset.p0.i64(ptr noundef nonnull align 16 dereferenceable(100005) @_QFEs_rev, i8 32, i64 100005, i1 false), !tbaa !3
  %5 = tail call ptr @_FortranAioBeginExternalListInput(i32 5, ptr nonnull @_QQcl.a5d52d94e9dd8b176aefc7606845a8d8, i32 16)
  %6 = tail call i1 @_FortranAioInputAscii(ptr %5, ptr nonnull @_QFEs, i64 100005)
  %7 = tail call i32 @_FortranAioEndIoStatement(ptr %5)
  br label %8

8:                                                ; preds = %0, %8
  %9 = phi i64 [ 100004, %0 ], [ %13, %8 ]
  %10 = getelementptr [100005 x [1 x i8]], ptr @_QFEs, i64 0, i64 %9
  %11 = load i8, ptr %10, align 1, !tbaa !3
  %12 = icmp eq i8 %11, 32
  %13 = add nsw i64 %9, -1
  %14 = icmp ne i64 %9, 0
  %15 = and i1 %12, %14
  br i1 %15, label %8, label %16

16:                                               ; preds = %8
  %17 = shl i64 %9, 32
  %sext = add i64 %17, 4294967296
  %18 = ashr exact i64 %sext, 32
  %19 = select i1 %12, i64 0, i64 %18
  %20 = icmp sgt i64 %19, 0
  br i1 %20, label %iter.check, label %._crit_edge

iter.check:                                       ; preds = %16
  %min.iters.check = icmp ult i64 %19, 8
  br i1 %min.iters.check, label %.lr.ph.preheader, label %vector.main.loop.iter.check

vector.main.loop.iter.check:                      ; preds = %iter.check
  %min.iters.check33 = icmp ult i64 %19, 32
  br i1 %min.iters.check33, label %vec.epilog.ph, label %vector.ph

vector.ph:                                        ; preds = %vector.main.loop.iter.check
  %n.vec = and i64 %19, -32
  br label %vector.body

vector.body:                                      ; preds = %vector.body, %vector.ph
  %index = phi i64 [ 0, %vector.ph ], [ %index.next, %vector.body ]
  %offset.idx.neg = xor i64 %index, -1
  %21 = getelementptr [100005 x [1 x i8]], ptr @_QFEs, i64 0, i64 %index
  %22 = add i64 %19, %offset.idx.neg
  %23 = getelementptr [100005 x [1 x i8]], ptr @_QFEs_rev, i64 0, i64 %22
  %wide.load = load <16 x i8>, ptr %21, align 16
  %24 = getelementptr i8, ptr %21, i64 16
  %wide.load34 = load <16 x i8>, ptr %24, align 16
  %reverse = shufflevector <16 x i8> %wide.load, <16 x i8> poison, <16 x i32> <i32 15, i32 14, i32 13, i32 12, i32 11, i32 10, i32 9, i32 8, i32 7, i32 6, i32 5, i32 4, i32 3, i32 2, i32 1, i32 0>
  %25 = getelementptr i8, ptr %23, i64 -15
  store <16 x i8> %reverse, ptr %25, align 1
  %reverse35 = shufflevector <16 x i8> %wide.load34, <16 x i8> poison, <16 x i32> <i32 15, i32 14, i32 13, i32 12, i32 11, i32 10, i32 9, i32 8, i32 7, i32 6, i32 5, i32 4, i32 3, i32 2, i32 1, i32 0>
  %26 = getelementptr i8, ptr %23, i64 -31
  store <16 x i8> %reverse35, ptr %26, align 1
  %index.next = add nuw i64 %index, 32
  %27 = icmp eq i64 %index.next, %n.vec
  br i1 %27, label %middle.block, label %vector.body, !llvm.loop !7

middle.block:                                     ; preds = %vector.body
  %cmp.n = icmp eq i64 %19, %n.vec
  br i1 %cmp.n, label %.preheader, label %vec.epilog.iter.check

vec.epilog.iter.check:                            ; preds = %middle.block
  %ind.end38 = or i64 %n.vec, 1
  %n.vec.remaining = and i64 %19, 24
  %min.epilog.iters.check = icmp eq i64 %n.vec.remaining, 0
  br i1 %min.epilog.iters.check, label %.lr.ph.preheader, label %vec.epilog.ph

vec.epilog.ph:                                    ; preds = %vector.main.loop.iter.check, %vec.epilog.iter.check
  %vec.epilog.resume.val = phi i64 [ %n.vec, %vec.epilog.iter.check ], [ 0, %vector.main.loop.iter.check ]
  %n.vec37 = and i64 %19, -8
  %ind.end = or i64 %n.vec37, 1
  br label %vec.epilog.vector.body

vec.epilog.vector.body:                           ; preds = %vec.epilog.vector.body, %vec.epilog.ph
  %index40 = phi i64 [ %vec.epilog.resume.val, %vec.epilog.ph ], [ %index.next44, %vec.epilog.vector.body ]
  %offset.idx41.neg = xor i64 %index40, -1
  %28 = getelementptr [100005 x [1 x i8]], ptr @_QFEs, i64 0, i64 %index40
  %29 = add i64 %19, %offset.idx41.neg
  %30 = getelementptr [100005 x [1 x i8]], ptr @_QFEs_rev, i64 0, i64 %29
  %wide.load42 = load <8 x i8>, ptr %28, align 8
  %reverse43 = shufflevector <8 x i8> %wide.load42, <8 x i8> poison, <8 x i32> <i32 7, i32 6, i32 5, i32 4, i32 3, i32 2, i32 1, i32 0>
  %31 = getelementptr i8, ptr %30, i64 -7
  store <8 x i8> %reverse43, ptr %31, align 1
  %index.next44 = add nuw i64 %index40, 8
  %32 = icmp eq i64 %index.next44, %n.vec37
  br i1 %32, label %vec.epilog.middle.block, label %vec.epilog.vector.body, !llvm.loop !10

vec.epilog.middle.block:                          ; preds = %vec.epilog.vector.body
  %cmp.n39 = icmp eq i64 %19, %n.vec37
  br i1 %cmp.n39, label %.preheader, label %.lr.ph.preheader

.lr.ph.preheader:                                 ; preds = %iter.check, %vec.epilog.iter.check, %vec.epilog.middle.block
  %.ph = phi i64 [ 1, %iter.check ], [ %ind.end38, %vec.epilog.iter.check ], [ %ind.end, %vec.epilog.middle.block ]
  br label %.lr.ph

.preheader:                                       ; preds = %.lr.ph, %vec.epilog.middle.block, %middle.block
  %.not22 = icmp slt i64 %19, 1
  br i1 %.not22, label %._crit_edge, label %.lr.ph24

.lr.ph:                                           ; preds = %.lr.ph.preheader, %.lr.ph
  %33 = phi i64 [ %39, %.lr.ph ], [ %.ph, %.lr.ph.preheader ]
  %34 = add nsw i64 %33, -1
  %35 = getelementptr [100005 x [1 x i8]], ptr @_QFEs, i64 0, i64 %34
  %36 = sub nsw i64 %19, %33
  %37 = getelementptr [100005 x [1 x i8]], ptr @_QFEs_rev, i64 0, i64 %36
  %38 = load i8, ptr %35, align 1
  store i8 %38, ptr %37, align 1
  %39 = add nuw nsw i64 %33, 1
  %exitcond.not = icmp eq i64 %19, %33
  br i1 %exitcond.not, label %.preheader, label %.lr.ph, !llvm.loop !11

.backedge:                                        ; preds = %.backedge.loopexit27, %.backedge.loopexit26, %.backedge.loopexit25, %.backedge.loopexit
  %.sink = phi i64 [ 7, %.backedge.loopexit27 ], [ 6, %.backedge.loopexit26 ], [ 5, %.backedge.loopexit25 ], [ 5, %.backedge.loopexit ]
  %40 = add i64 %.023, %.sink
  %.not = icmp sgt i64 %40, %19
  br i1 %.not, label %._crit_edge, label %.lr.ph24

.lr.ph24:                                         ; preds = %.preheader, %.backedge
  %.023 = phi i64 [ %40, %.backedge ], [ 1, %.preheader ]
  %41 = call i64 @_FortranAIndex1(ptr nonnull @_QFEs_rev, i64 100005, ptr nonnull %1, i64 5, i1 false)
  %42 = and i64 %41, 4294967295
  %43 = icmp eq i64 %42, 1
  br i1 %43, label %.backedge.loopexit, label %44

.backedge.loopexit:                               ; preds = %.lr.ph24
  call void @llvm.memmove.p0.p0.i64(ptr noundef nonnull align 16 dereferenceable(100000) @_QFEs_rev, ptr noundef nonnull align 1 dereferenceable(100000) getelementptr inbounds ([100005 x i8], ptr @_QFEs_rev, i64 0, i64 5), i64 100000, i1 false)
  call void @llvm.memset.p0.i64(ptr noundef nonnull align 16 dereferenceable(5) getelementptr inbounds ([100005 x i8], ptr @_QFEs_rev, i64 0, i64 100000), i8 32, i64 5, i1 false), !tbaa !3
  br label %.backedge

44:                                               ; preds = %.lr.ph24
  %45 = call i64 @_FortranAIndex1(ptr nonnull @_QFEs_rev, i64 100005, ptr nonnull %2, i64 5, i1 false)
  %46 = and i64 %45, 4294967295
  %47 = icmp eq i64 %46, 1
  br i1 %47, label %.backedge.loopexit25, label %48

.backedge.loopexit25:                             ; preds = %44
  call void @llvm.memmove.p0.p0.i64(ptr noundef nonnull align 16 dereferenceable(100000) @_QFEs_rev, ptr noundef nonnull align 1 dereferenceable(100000) getelementptr inbounds ([100005 x i8], ptr @_QFEs_rev, i64 0, i64 5), i64 100000, i1 false)
  call void @llvm.memset.p0.i64(ptr noundef nonnull align 16 dereferenceable(5) getelementptr inbounds ([100005 x i8], ptr @_QFEs_rev, i64 0, i64 100000), i8 32, i64 5, i1 false), !tbaa !3
  br label %.backedge

48:                                               ; preds = %44
  %49 = call i64 @_FortranAIndex1(ptr nonnull @_QFEs_rev, i64 100005, ptr nonnull %3, i64 6, i1 false)
  %50 = and i64 %49, 4294967295
  %51 = icmp eq i64 %50, 1
  br i1 %51, label %.backedge.loopexit26, label %52

.backedge.loopexit26:                             ; preds = %48
  call void @llvm.memmove.p0.p0.i64(ptr noundef nonnull align 16 dereferenceable(99999) @_QFEs_rev, ptr noundef nonnull align 2 dereferenceable(99999) getelementptr inbounds ([100005 x i8], ptr @_QFEs_rev, i64 0, i64 6), i64 99999, i1 false)
  call void @llvm.memset.p0.i64(ptr noundef nonnull align 1 dereferenceable(6) getelementptr inbounds ([100005 x i8], ptr @_QFEs_rev, i64 0, i64 99999), i8 32, i64 6, i1 false), !tbaa !3
  br label %.backedge

52:                                               ; preds = %48
  %53 = call i64 @_FortranAIndex1(ptr nonnull @_QFEs_rev, i64 100005, ptr nonnull %4, i64 7, i1 false)
  %54 = and i64 %53, 4294967295
  %55 = icmp eq i64 %54, 1
  br i1 %55, label %.backedge.loopexit27, label %56

.backedge.loopexit27:                             ; preds = %52
  call void @llvm.memmove.p0.p0.i64(ptr noundef nonnull align 16 dereferenceable(99998) @_QFEs_rev, ptr noundef nonnull align 1 dereferenceable(99998) getelementptr inbounds ([100005 x i8], ptr @_QFEs_rev, i64 0, i64 7), i64 99998, i1 false)
  call void @llvm.memset.p0.i64(ptr noundef nonnull align 2 dereferenceable(7) getelementptr inbounds ([100005 x i8], ptr @_QFEs_rev, i64 0, i64 99998), i8 32, i64 7, i1 false), !tbaa !3
  br label %.backedge

56:                                               ; preds = %52
  %57 = call ptr @_FortranAioBeginExternalListOutput(i32 6, ptr nonnull @_QQcl.a5d52d94e9dd8b176aefc7606845a8d8, i32 47)
  %58 = call i1 @_FortranAioOutputAscii(ptr %57, ptr nonnull @_QQcl.4E4F, i64 2)
  br label %61

._crit_edge:                                      ; preds = %.backedge, %16, %.preheader
  %59 = call ptr @_FortranAioBeginExternalListOutput(i32 6, ptr nonnull @_QQcl.a5d52d94e9dd8b176aefc7606845a8d8, i32 55)
  %60 = call i1 @_FortranAioOutputAscii(ptr %59, ptr nonnull @_QQcl.594553, i64 3)
  br label %61

61:                                               ; preds = %56, %._crit_edge
  %.sink31 = phi ptr [ %57, %56 ], [ %59, %._crit_edge ]
  %62 = call i32 @_FortranAioEndIoStatement(ptr %.sink31)
  ret void
}

; Function Attrs: mustprogress nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memmove.p0.p0.i64(ptr nocapture writeonly, ptr nocapture readonly, i64, i1 immarg) #0

declare ptr @_FortranAioBeginExternalListInput(i32, ptr, i32) local_unnamed_addr

declare i1 @_FortranAioInputAscii(ptr, ptr, i64) local_unnamed_addr

declare i32 @_FortranAioEndIoStatement(ptr) local_unnamed_addr

declare i64 @_FortranAIndex1(ptr, i64, ptr, i64, i1) local_unnamed_addr

declare ptr @_FortranAioBeginExternalListOutput(i32, ptr, i32) local_unnamed_addr

declare i1 @_FortranAioOutputAscii(ptr, ptr, i64) local_unnamed_addr

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #1

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #2

attributes #0 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { nocallback nofree nounwind willreturn memory(argmem: write) }

!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 = distinct !{!7, !8, !9}
!8 = !{!"llvm.loop.isvectorized", i32 1}
!9 = !{!"llvm.loop.unroll.runtime.disable"}
!10 = distinct !{!10, !8, !9}
!11 = distinct !{!11, !9, !8}
