program ccc
implicit none

integer :: n, q, ln, i, j
character(100001) :: s
integer,allocatable,dimension(:) :: a, l, r

read*, n, q
read*, s
s=trim(s)
ln=len_trim(s)
allocate(a(0:ln),l(q),r(q))
do i=1, q
read*, l(i), r(i)
end do

j=0
do i=1,n-1
if(s(i:i)=='A'.and.s(i+1:i+1)=='C') j=j+1
a(i)=j
end do
a(0)=0
a(n)=a(n-1)

do i=1,q
write(*,'(i0)') a(r(i)-1)-a(l(i)-1)
end do

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.7 = internal unnamed_addr global i64 1
@_QFEl.0 = internal unnamed_addr global ptr null
@_QFEr.0 = internal unnamed_addr global ptr null
@_QFEs = internal global [100001 x i8] undef
@_QQcl.e4cf68b9309a043f3105f982d873db97 = linkonce constant [73 x i8] c"/home/ubuntu/Downloads/TheStack_IR/Collated/Fortran/Source_4669/source.f\00"
@_QQcl.41 = linkonce constant [1 x i8] c"A"
@_QQcl.43 = linkonce constant [1 x i8] c"C"
@_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 = alloca { ptr, i64, i32, i8, i8, i8, i8 }, align 8
  %2 = alloca { ptr, i64, i32, i8, i8, i8, i8 }, align 8
  %3 = alloca i32, align 4
  %4 = alloca i32, align 4
  %5 = tail call ptr @_FortranAioBeginExternalListInput(i32 -1, ptr nonnull @_QQcl.e4cf68b9309a043f3105f982d873db97, i32 8)
  %6 = call i1 @_FortranAioInputInteger(ptr %5, ptr nonnull %3, i32 4)
  %7 = call i1 @_FortranAioInputInteger(ptr %5, ptr nonnull %4, i32 4)
  %8 = call i32 @_FortranAioEndIoStatement(ptr %5)
  %9 = call ptr @_FortranAioBeginExternalListInput(i32 -1, ptr nonnull @_QQcl.e4cf68b9309a043f3105f982d873db97, i32 9)
  %10 = call i1 @_FortranAioInputAscii(ptr %9, ptr nonnull @_QFEs, i64 100001)
  %11 = call i32 @_FortranAioEndIoStatement(ptr %9)
  store ptr @_QFEs, ptr %1, align 8, !tbaa !3
  %.fca.1.gep20 = getelementptr inbounds { ptr, i64, i32, i8, i8, i8, i8 }, ptr %1, i64 0, i32 1
  store i64 100001, ptr %.fca.1.gep20, align 8, !tbaa !3
  %.fca.2.gep21 = getelementptr inbounds { ptr, i64, i32, i8, i8, i8, i8 }, ptr %1, i64 0, i32 2
  store i32 20180515, ptr %.fca.2.gep21, align 8, !tbaa !3
  %.fca.3.gep22 = getelementptr inbounds { ptr, i64, i32, i8, i8, i8, i8 }, ptr %1, i64 0, i32 3
  store i8 0, ptr %.fca.3.gep22, align 4, !tbaa !3
  %.fca.4.gep23 = getelementptr inbounds { ptr, i64, i32, i8, i8, i8, i8 }, ptr %1, i64 0, i32 4
  store i8 40, ptr %.fca.4.gep23, align 1, !tbaa !3
  %.fca.5.gep24 = getelementptr inbounds { ptr, i64, i32, i8, i8, i8, i8 }, ptr %1, i64 0, i32 5
  store i8 0, ptr %.fca.5.gep24, align 2, !tbaa !3
  %.fca.6.gep25 = getelementptr inbounds { ptr, i64, i32, i8, i8, i8, i8 }, ptr %1, i64 0, i32 6
  store i8 0, ptr %.fca.6.gep25, align 1, !tbaa !3
  %.fca.1.gep = getelementptr inbounds { ptr, i64, i32, i8, i8, i8, i8 }, ptr %2, i64 0, i32 1
  %.fca.2.gep = getelementptr inbounds { ptr, i64, i32, i8, i8, i8, i8 }, ptr %2, i64 0, i32 2
  call void @llvm.memset.p0.i64(ptr noundef nonnull align 8 dereferenceable(16) %2, i8 0, i64 16, i1 false)
  store i32 20180515, ptr %.fca.2.gep, align 8, !tbaa !3
  %.fca.3.gep = getelementptr inbounds { ptr, i64, i32, i8, i8, i8, i8 }, ptr %2, i64 0, i32 3
  store i8 0, ptr %.fca.3.gep, align 4, !tbaa !3
  %.fca.4.gep = getelementptr inbounds { ptr, i64, i32, i8, i8, i8, i8 }, ptr %2, i64 0, i32 4
  store i8 40, ptr %.fca.4.gep, align 1, !tbaa !3
  %.fca.5.gep = getelementptr inbounds { ptr, i64, i32, i8, i8, i8, i8 }, ptr %2, i64 0, i32 5
  store i8 2, ptr %.fca.5.gep, align 2, !tbaa !3
  %.fca.6.gep = getelementptr inbounds { ptr, i64, i32, i8, i8, i8, i8 }, ptr %2, i64 0, i32 6
  store i8 0, ptr %.fca.6.gep, align 1, !tbaa !3
  %12 = call {} @_FortranATrim(ptr nonnull %2, ptr nonnull %1, ptr nonnull @_QQcl.e4cf68b9309a043f3105f982d873db97, i32 10)
  %.fca.0.load = load ptr, ptr %2, align 8, !tbaa !3
  %.fca.1.load = load i64, ptr %.fca.1.gep, align 8, !tbaa !3
  %13 = call i64 @llvm.smin.i64(i64 %.fca.1.load, i64 100001)
  call void @llvm.memmove.p0.p0.i64(ptr nonnull align 16 @_QFEs, ptr align 1 %.fca.0.load, i64 %13, i1 false)
  %14 = sub i64 100001, %13
  %15 = icmp sgt i64 %14, 0
  br i1 %15, label %.lr.ph.preheader, label %._crit_edge

.lr.ph.preheader:                                 ; preds = %0
  %uglygep = getelementptr i8, ptr @_QFEs, i64 %13
  call void @llvm.memset.p0.i64(ptr align 1 %uglygep, i8 32, i64 %14, i1 false), !tbaa !7
  br label %._crit_edge

._crit_edge:                                      ; preds = %.lr.ph.preheader, %0
  call void @free(ptr %.fca.0.load)
  br label %16

16:                                               ; preds = %._crit_edge, %16
  %17 = phi i64 [ 100000, %._crit_edge ], [ %21, %16 ]
  %18 = getelementptr [100001 x [1 x i8]], ptr @_QFEs, i64 0, i64 %17
  %19 = load i8, ptr %18, align 1, !tbaa !7
  %20 = icmp eq i8 %19, 32
  %21 = add nsw i64 %17, -1
  %22 = icmp ne i64 %17, 0
  %23 = and i1 %20, %22
  br i1 %23, label %16, label %24

24:                                               ; preds = %16
  %25 = shl i64 %17, 32
  %sext = add i64 %25, 4294967296
  %26 = ashr exact i64 %sext, 32
  %27 = call i64 @llvm.smax.i64(i64 %26, i64 -1)
  %28 = add nsw i64 %27, 1
  %29 = select i1 %20, i64 1, i64 %28
  %30 = shl nuw nsw i64 %29, 2
  %31 = call ptr @malloc(i64 %30)
  %32 = icmp eq i64 %29, 0
  %33 = zext i1 %32 to i64
  store ptr %31, ptr @_QFEa.0, align 8, !tbaa !3
  store i64 %33, ptr @_QFEa.7, align 8, !tbaa !3
  %34 = load i32, ptr %4, align 4, !tbaa !7
  %35 = call i32 @llvm.smax.i32(i32 %34, i32 0)
  %36 = zext i32 %35 to i64
  %37 = shl nuw nsw i64 %36, 2
  %38 = call ptr @malloc(i64 %37)
  store ptr %38, ptr @_QFEl.0, align 8, !tbaa !3
  %39 = call ptr @malloc(i64 %37)
  store ptr %39, ptr @_QFEr.0, align 8, !tbaa !3
  %40 = icmp sgt i32 %34, 0
  br i1 %40, label %.lr.ph556.preheader, label %._crit_edge557

.lr.ph556.preheader:                              ; preds = %24
  %41 = zext i32 %34 to i64
  br label %.lr.ph556

.lr.ph556:                                        ; preds = %.lr.ph556.preheader, %.lr.ph556
  %indvars.iv = phi i64 [ 1, %.lr.ph556.preheader ], [ %indvars.iv.next, %.lr.ph556 ]
  %42 = call ptr @_FortranAioBeginExternalListInput(i32 -1, ptr nonnull @_QQcl.e4cf68b9309a043f3105f982d873db97, i32 14)
  %.unpack530 = load ptr, ptr @_QFEl.0, align 8, !tbaa !3
  %43 = add nsw i64 %indvars.iv, -1
  %44 = getelementptr i32, ptr %.unpack530, i64 %43
  %45 = call i1 @_FortranAioInputInteger(ptr %42, ptr %44, i32 4)
  %.unpack542 = load ptr, ptr @_QFEr.0, align 8, !tbaa !3
  %46 = add nsw i64 %indvars.iv, -1
  %47 = getelementptr i32, ptr %.unpack542, i64 %46
  %48 = call i1 @_FortranAioInputInteger(ptr %42, ptr %47, i32 4)
  %49 = call i32 @_FortranAioEndIoStatement(ptr %42)
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %exitcond.not = icmp eq i64 %indvars.iv, %41
  br i1 %exitcond.not, label %._crit_edge557, label %.lr.ph556

._crit_edge557:                                   ; preds = %.lr.ph556, %24
  %50 = load i32, ptr %3, align 4, !tbaa !7
  %51 = add i32 %50, -1
  %52 = icmp sgt i32 %51, 0
  br i1 %52, label %.lr.ph560.preheader, label %._crit_edge557.._crit_edge561_crit_edge

._crit_edge557.._crit_edge561_crit_edge:          ; preds = %._crit_edge557
  %.unpack.pre = load ptr, ptr @_QFEa.0, align 8, !tbaa !3
  %.unpack465.unpack.unpack.pre = load i64, ptr @_QFEa.7, align 8, !tbaa !3
  br label %._crit_edge561

.lr.ph560.preheader:                              ; preds = %._crit_edge557
  %53 = zext i32 %51 to i64
  br label %.lr.ph560

.lr.ph560:                                        ; preds = %.lr.ph560.preheader, %.lr.ph560
  %indvars.iv567 = phi i64 [ 1, %.lr.ph560.preheader ], [ %indvars.iv.next568, %.lr.ph560 ]
  %.0558 = phi i32 [ 0, %.lr.ph560.preheader ], [ %spec.select, %.lr.ph560 ]
  %54 = add nsw i64 %indvars.iv567, -1
  %55 = getelementptr [100001 x [1 x i8]], ptr @_QFEs, i64 0, i64 %54
  %56 = call i32 @_FortranACharacterCompareScalar1(ptr %55, ptr nonnull @_QQcl.41, i64 1, i64 1)
  %indvars.iv.next568 = add nuw nsw i64 %indvars.iv567, 1
  %sext577 = shl i64 %indvars.iv.next568, 32
  %57 = ashr exact i64 %sext577, 32
  %58 = add nsw i64 %57, -1
  %59 = getelementptr [100001 x [1 x i8]], ptr @_QFEs, i64 0, i64 %58
  %60 = call i32 @_FortranACharacterCompareScalar1(ptr %59, ptr nonnull @_QQcl.43, i64 1, i64 1)
  %61 = or i32 %60, %56
  %62 = icmp eq i32 %61, 0
  %63 = zext i1 %62 to i32
  %spec.select = add i32 %.0558, %63
  %.unpack518 = load ptr, ptr @_QFEa.0, align 8, !tbaa !3
  %.unpack525.unpack.unpack = load i64, ptr @_QFEa.7, align 8, !tbaa !3
  %64 = sub i64 %indvars.iv567, %.unpack525.unpack.unpack
  %65 = getelementptr i32, ptr %.unpack518, i64 %64
  store i32 %spec.select, ptr %65, align 4, !tbaa !7
  %exitcond570.not = icmp eq i64 %indvars.iv567, %53
  br i1 %exitcond570.not, label %._crit_edge561, label %.lr.ph560

._crit_edge561:                                   ; preds = %.lr.ph560, %._crit_edge557.._crit_edge561_crit_edge
  %.unpack465.unpack.unpack = phi i64 [ %.unpack465.unpack.unpack.pre, %._crit_edge557.._crit_edge561_crit_edge ], [ %.unpack525.unpack.unpack, %.lr.ph560 ]
  %.unpack = phi ptr [ %.unpack.pre, %._crit_edge557.._crit_edge561_crit_edge ], [ %.unpack518, %.lr.ph560 ]
  %66 = sub i64 0, %.unpack465.unpack.unpack
  %67 = getelementptr i32, ptr %.unpack, i64 %66
  store i32 0, ptr %67, align 4, !tbaa !7
  %68 = load i32, ptr %3, align 4, !tbaa !7
  %69 = add i32 %68, -1
  %70 = sext i32 %69 to i64
  %71 = sub i64 %70, %.unpack465.unpack.unpack
  %72 = getelementptr i32, ptr %.unpack, i64 %71
  %73 = load i32, ptr %72, align 4, !tbaa !7
  %74 = sext i32 %68 to i64
  %75 = sub i64 %74, %.unpack465.unpack.unpack
  %76 = getelementptr i32, ptr %.unpack, i64 %75
  store i32 %73, ptr %76, align 4, !tbaa !7
  %77 = load i32, ptr %4, align 4, !tbaa !7
  %78 = icmp sgt i32 %77, 0
  br i1 %78, label %.lr.ph563.preheader, label %._crit_edge564

.lr.ph563.preheader:                              ; preds = %._crit_edge561
  %79 = zext i32 %77 to i64
  br label %.lr.ph563

.lr.ph563:                                        ; preds = %.lr.ph563.preheader, %.lr.ph563
  %indvars.iv571 = phi i64 [ 1, %.lr.ph563.preheader ], [ %indvars.iv.next572, %.lr.ph563 ]
  %80 = call ptr @_FortranAioBeginExternalFormattedOutput(ptr nonnull @_QQcl.28693029, i64 4, ptr null, i32 -1, ptr nonnull @_QQcl.e4cf68b9309a043f3105f982d873db97, i32 26)
  %.unpack482 = load ptr, ptr @_QFEa.0, align 8, !tbaa !3
  %.unpack489.unpack.unpack = load i64, ptr @_QFEa.7, align 8, !tbaa !3
  %.unpack494 = load ptr, ptr @_QFEr.0, align 8, !tbaa !3
  %81 = add nsw i64 %indvars.iv571, -1
  %82 = getelementptr i32, ptr %.unpack494, i64 %81
  %83 = load i32, ptr %82, align 4, !tbaa !7
  %84 = add i32 %83, -1
  %85 = sext i32 %84 to i64
  %86 = sub i64 %85, %.unpack489.unpack.unpack
  %87 = getelementptr i32, ptr %.unpack482, i64 %86
  %88 = load i32, ptr %87, align 4, !tbaa !7
  %.unpack506 = load ptr, ptr @_QFEl.0, align 8, !tbaa !3
  %89 = add nsw i64 %indvars.iv571, -1
  %90 = getelementptr i32, ptr %.unpack506, i64 %89
  %91 = load i32, ptr %90, align 4, !tbaa !7
  %92 = add i32 %91, -1
  %93 = sext i32 %92 to i64
  %94 = sub i64 %93, %.unpack489.unpack.unpack
  %95 = getelementptr i32, ptr %.unpack482, i64 %94
  %96 = load i32, ptr %95, align 4, !tbaa !7
  %97 = sub i32 %88, %96
  %98 = call i1 @_FortranAioOutputInteger32(ptr %80, i32 %97)
  %99 = call i32 @_FortranAioEndIoStatement(ptr %80)
  %indvars.iv.next572 = add nuw nsw i64 %indvars.iv571, 1
  %exitcond574.not = icmp eq i64 %indvars.iv571, %79
  br i1 %exitcond574.not, label %._crit_edge564, label %.lr.ph563

._crit_edge564:                                   ; preds = %.lr.ph563, %._crit_edge561
  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 i1 @_FortranAioInputAscii(ptr, ptr, i64) local_unnamed_addr

declare {} @_FortranATrim(ptr, ptr, ptr, i32) local_unnamed_addr

; 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) #2

declare i32 @_FortranACharacterCompareScalar1(ptr, ptr, i64, i64) 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.smin.i64(i64, i64) #3

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

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

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #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 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #3 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #4 = { 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 = !{!"descriptor member", !5, i64 0}
!5 = !{!"any access", !6, i64 0}
!6 = !{!"Flang Type TBAA Root"}
!7 = !{!8, !8, i64 0}
!8 = !{!"any data access", !5, i64 0}
