program prob4
    implicit none
    integer::p(100005), a(100005)
    integer::i, j, Q, l, r

    p = 0
    do i = 2, 100000
        if(p(i) == 0) then
            do j = 2*i, 100000, i
                p(j) = 1
            end do
        end if
    end do

    a = 0
    do i = 3, 100000
        if(p(i) == 0 .and. p((i+1)/2) == 0) then
            a(i) = a(i-1) + 1
        else
            a(i) = a(i-1)
        end if
    end do
    
    read(*,*) Q
    do i = 1, Q
        read(*,*) l, r
        write(*,*) a(r) - a(l-1)
    end do
    stop
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 = internal unnamed_addr global [100005 x i32] undef
@_QFEp = internal unnamed_addr global [100005 x i32] undef
@_QQcl.8349e03c9d121301be855289a15c3d02 = linkonce constant [73 x i8] c"/home/ubuntu/Downloads/TheStack_IR/Collated/Fortran/Source_6507/source.f\00"
@_QQEnvironmentDefaults = local_unnamed_addr constant ptr null

; Function Attrs: noreturn
define void @_QQmain() local_unnamed_addr #0 {
.preheader16.preheader:
  %0 = alloca i32, align 4
  %1 = alloca i32, align 4
  %2 = alloca i32, align 4
  tail call void @llvm.memset.p0.i64(ptr noundef nonnull align 16 dereferenceable(400020) @_QFEp, i8 0, i64 400020, i1 false), !tbaa !3
  br label %.preheader16

.preheader16:                                     ; preds = %.preheader16.preheader, %.loopexit
  %indvars.iv = phi i64 [ 2, %.preheader16.preheader ], [ %indvars.iv.next, %.loopexit ]
  %3 = add nsw i64 %indvars.iv, -1
  %4 = getelementptr [100005 x i32], ptr @_QFEp, i64 0, i64 %3
  %5 = load i32, ptr %4, align 4, !tbaa !3
  %6 = icmp eq i32 %5, 0
  br i1 %6, label %7, label %.loopexit

7:                                                ; preds = %.preheader16
  %8 = shl nuw i64 %indvars.iv, 1
  %9 = add nuw nsw i64 %indvars.iv, 100000
  %10 = sub nuw nsw i64 %9, %8
  %.udiv = udiv i64 %10, %indvars.iv
  %11 = icmp sgt i64 %.udiv, 0
  br i1 %11, label %.lr.ph.preheader, label %.loopexit

.lr.ph.preheader:                                 ; preds = %7
  %12 = trunc i64 %8 to i32
  %13 = trunc i64 %indvars.iv to i32
  %xtraiter = and i64 %.udiv, 1
  %lcmp.mod.not = icmp eq i64 %xtraiter, 0
  br i1 %lcmp.mod.not, label %.lr.ph.prol.loopexit, label %.lr.ph.prol

.lr.ph.prol:                                      ; preds = %.lr.ph.preheader
  %sext = shl i64 %indvars.iv, 33
  %14 = ashr exact i64 %sext, 32
  %15 = add nsw i64 %14, -1
  %16 = getelementptr [100005 x i32], ptr @_QFEp, i64 0, i64 %15
  store i32 1, ptr %16, align 4, !tbaa !3
  %17 = add i32 %12, %13
  %18 = add nsw i64 %.udiv, -1
  br label %.lr.ph.prol.loopexit

.lr.ph.prol.loopexit:                             ; preds = %.lr.ph.prol, %.lr.ph.preheader
  %.unr = phi i64 [ %.udiv, %.lr.ph.preheader ], [ %18, %.lr.ph.prol ]
  %.unr25 = phi i32 [ %12, %.lr.ph.preheader ], [ %17, %.lr.ph.prol ]
  %19 = icmp eq i64 %.udiv, 1
  br i1 %19, label %.loopexit, label %.lr.ph

.lr.ph:                                           ; preds = %.lr.ph.prol.loopexit, %.lr.ph
  %20 = phi i64 [ %30, %.lr.ph ], [ %.unr, %.lr.ph.prol.loopexit ]
  %21 = phi i32 [ %29, %.lr.ph ], [ %.unr25, %.lr.ph.prol.loopexit ]
  %22 = sext i32 %21 to i64
  %23 = add nsw i64 %22, -1
  %24 = getelementptr [100005 x i32], ptr @_QFEp, i64 0, i64 %23
  store i32 1, ptr %24, align 4, !tbaa !3
  %25 = add i32 %21, %13
  %26 = sext i32 %25 to i64
  %27 = add nsw i64 %26, -1
  %28 = getelementptr [100005 x i32], ptr @_QFEp, i64 0, i64 %27
  store i32 1, ptr %28, align 4, !tbaa !3
  %29 = add i32 %25, %13
  %30 = add nsw i64 %20, -2
  %31 = add i64 %20, -3
  %32 = icmp ult i64 %31, -2
  br i1 %32, label %.lr.ph, label %.loopexit

.loopexit:                                        ; preds = %.lr.ph.prol.loopexit, %.lr.ph, %7, %.preheader16
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %exitcond.not = icmp eq i64 %indvars.iv.next, 100001
  br i1 %exitcond.not, label %.preheader15.preheader, label %.preheader16

.preheader15.preheader:                           ; preds = %.loopexit
  tail call void @llvm.memset.p0.i64(ptr noundef nonnull align 16 dereferenceable(400020) @_QFEa, i8 0, i64 400020, i1 false), !tbaa !3
  %load_initial = load i32, ptr getelementptr inbounds ([100005 x i32], ptr @_QFEa, i64 0, i64 1), align 4
  br label %.preheader

.preheader:                                       ; preds = %.preheader15.preheader, %.preheader
  %store_forwarded = phi i32 [ %load_initial, %.preheader15.preheader ], [ %.sink, %.preheader ]
  %indvars.iv20 = phi i64 [ 3, %.preheader15.preheader ], [ %indvars.iv.next21, %.preheader ]
  %33 = add nsw i64 %indvars.iv20, -1
  %34 = getelementptr [100005 x i32], ptr @_QFEp, i64 0, i64 %33
  %35 = load i32, ptr %34, align 4, !tbaa !3
  %indvars.iv.next21 = add nuw nsw i64 %indvars.iv20, 1
  %36 = trunc i64 %indvars.iv.next21 to i32
  %.udiv1924 = lshr i32 %36, 1
  %narrow = add nsw i32 %.udiv1924, -1
  %37 = sext i32 %narrow to i64
  %38 = getelementptr [100005 x i32], ptr @_QFEp, i64 0, i64 %37
  %39 = load i32, ptr %38, align 4, !tbaa !3
  %40 = or i32 %39, %35
  %41 = icmp eq i32 %40, 0
  %42 = zext i1 %41 to i32
  %.sink = add i32 %store_forwarded, %42
  %43 = getelementptr [100005 x i32], ptr @_QFEa, i64 0, i64 %33
  store i32 %.sink, ptr %43, align 4
  %exitcond23.not = icmp eq i64 %indvars.iv.next21, 100001
  br i1 %exitcond23.not, label %44, label %.preheader

44:                                               ; preds = %.preheader
  %45 = tail call ptr @_FortranAioBeginExternalListInput(i32 -1, ptr nonnull @_QQcl.8349e03c9d121301be855289a15c3d02, i32 24)
  %46 = call i1 @_FortranAioInputInteger(ptr %45, ptr nonnull %1, i32 4)
  %47 = call i32 @_FortranAioEndIoStatement(ptr %45)
  %48 = load i32, ptr %1, align 4, !tbaa !3
  %49 = icmp sgt i32 %48, 0
  br i1 %49, label %.lr.ph17.preheader, label %._crit_edge

.lr.ph17.preheader:                               ; preds = %44
  %50 = zext i32 %48 to i64
  br label %.lr.ph17

.lr.ph17:                                         ; preds = %.lr.ph17.preheader, %.lr.ph17
  %51 = phi i64 [ %71, %.lr.ph17 ], [ %50, %.lr.ph17.preheader ]
  %52 = call ptr @_FortranAioBeginExternalListInput(i32 -1, ptr nonnull @_QQcl.8349e03c9d121301be855289a15c3d02, i32 26)
  %53 = call i1 @_FortranAioInputInteger(ptr %52, ptr nonnull %0, i32 4)
  %54 = call i1 @_FortranAioInputInteger(ptr %52, ptr nonnull %2, i32 4)
  %55 = call i32 @_FortranAioEndIoStatement(ptr %52)
  %56 = call ptr @_FortranAioBeginExternalListOutput(i32 -1, ptr nonnull @_QQcl.8349e03c9d121301be855289a15c3d02, i32 27)
  %57 = load i32, ptr %2, align 4, !tbaa !3
  %58 = sext i32 %57 to i64
  %59 = add nsw i64 %58, -1
  %60 = getelementptr [100005 x i32], ptr @_QFEa, i64 0, i64 %59
  %61 = load i32, ptr %60, align 4, !tbaa !3
  %62 = load i32, ptr %0, align 4, !tbaa !3
  %63 = add i32 %62, -1
  %64 = sext i32 %63 to i64
  %65 = add nsw i64 %64, -1
  %66 = getelementptr [100005 x i32], ptr @_QFEa, i64 0, i64 %65
  %67 = load i32, ptr %66, align 4, !tbaa !3
  %68 = sub i32 %61, %67
  %69 = call i1 @_FortranAioOutputInteger32(ptr %56, i32 %68)
  %70 = call i32 @_FortranAioEndIoStatement(ptr %56)
  %71 = add nsw i64 %51, -1
  %72 = icmp ugt i64 %51, 1
  br i1 %72, label %.lr.ph17, label %._crit_edge

._crit_edge:                                      ; preds = %.lr.ph17, %44
  %73 = call {} @_FortranAStopStatement(i32 0, i1 false, i1 false)
  unreachable
}

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

declare i1 @_FortranAioOutputInteger32(ptr, i32) local_unnamed_addr

declare {} @_FortranAStopStatement(i32, i1, i1) local_unnamed_addr

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

attributes #0 = { noreturn }
attributes #1 = { 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"}
