program preparing_boxes
    implicit none
    integer(4):: n, i, j, all
    integer(4), allocatable:: a(:), b(:)
    

    read*, n
    allocate(a(n), b(n))
    read*, a(:)
    b(:)=0
    do i=n, 1,-1
        all = 0
        do j=i,n,i
            all = xor(all,b(j))
        end do
        b(i) = xor(a(i),all)
    end do

    print'(i0)', sum(b(:))
    do i=1,n
        if (b(i)==1) print*, i 
    end do
end program preparing_boxes
; 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
@_QFEb.0 = internal unnamed_addr global ptr null
@_QFEb.8 = internal unnamed_addr global i64 0
@_QQcl.0073dc03b76014096504e47751aa9a4e = linkonce constant [73 x i8] c"/home/ubuntu/Downloads/TheStack_IR/Collated/Fortran/Source_3744/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 { ptr, i64, i32, i8, i8, i8, i8, [1 x [3 x i64]] }, align 8
  %2 = alloca i32, align 4
  %3 = tail call ptr @_FortranAioBeginExternalListInput(i32 -1, ptr nonnull @_QQcl.0073dc03b76014096504e47751aa9a4e, i32 7)
  %4 = call i1 @_FortranAioInputInteger(ptr %3, ptr nonnull %2, i32 4)
  %5 = call i32 @_FortranAioEndIoStatement(ptr %3)
  %6 = load i32, ptr %2, align 4, !tbaa !3
  %7 = call i32 @llvm.smax.i32(i32 %6, i32 0)
  %8 = zext i32 %7 to i64
  %9 = shl nuw nsw i64 %8, 2
  %10 = call ptr @malloc(i64 %9)
  store ptr %10, ptr @_QFEa.0, align 8, !tbaa !7
  store i64 %8, ptr @_QFEa.8, align 8, !tbaa !7
  %11 = call ptr @malloc(i64 %9)
  store ptr %11, ptr @_QFEb.0, align 8, !tbaa !7
  store i64 %8, ptr @_QFEb.8, align 8, !tbaa !7
  %12 = call ptr @_FortranAioBeginExternalListInput(i32 -1, ptr nonnull @_QQcl.0073dc03b76014096504e47751aa9a4e, i32 9)
  %.unpack = load ptr, ptr @_QFEa.0, align 8, !tbaa !7
  %.unpack315.unpack.unpack317 = load i64, ptr @_QFEa.8, align 8, !tbaa !7
  %13 = call i64 @llvm.smax.i64(i64 %.unpack315.unpack.unpack317, i64 0)
  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 9, 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 %13, 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
  %14 = call i1 @_FortranAioInputDescriptor(ptr %12, ptr nonnull %1)
  %15 = call i32 @_FortranAioEndIoStatement(ptr %12)
  %.unpack320 = load ptr, ptr @_QFEb.0, align 8, !tbaa !7
  %.unpack327.unpack.unpack329 = load i64, ptr @_QFEb.8, align 8, !tbaa !7
  %.not401 = icmp slt i64 %.unpack327.unpack.unpack329, 1
  br i1 %.not401, label %._crit_edge, label %.lr.ph.preheader

.lr.ph.preheader:                                 ; preds = %0
  %16 = shl nuw i64 %.unpack327.unpack.unpack329, 2
  call void @llvm.memset.p0.i64(ptr align 4 %.unpack320, i8 0, i64 %16, i1 false), !tbaa !3
  br label %._crit_edge

._crit_edge:                                      ; preds = %.lr.ph.preheader, %0
  %17 = load i32, ptr %2, align 4, !tbaa !3
  %18 = icmp sgt i32 %17, 0
  br i1 %18, label %.lr.ph397, label %._crit_edge398

.lr.ph397:                                        ; preds = %._crit_edge
  %19 = zext i32 %17 to i64
  %.unpack356 = load ptr, ptr @_QFEa.0, align 8, !tbaa !7
  br label %20

20:                                               ; preds = %.lr.ph397, %._crit_edge395
  %21 = phi i64 [ %19, %.lr.ph397 ], [ %66, %._crit_edge395 ]
  %indvars403 = trunc i64 %21 to i32
  %sext = shl i64 %21, 32
  %22 = ashr exact i64 %sext, 32
  %23 = load i32, ptr %2, align 4, !tbaa !3
  %24 = sext i32 %23 to i64
  %25 = sdiv i64 %24, %22
  %26 = icmp sgt i64 %25, 0
  br i1 %26, label %.lr.ph394.preheader, label %._crit_edge395

.lr.ph394.preheader:                              ; preds = %20
  %xtraiter = and i64 %25, 3
  %27 = icmp ult i64 %25, 4
  br i1 %27, label %._crit_edge395.loopexit.unr-lcssa, label %.lr.ph394.preheader.new

.lr.ph394.preheader.new:                          ; preds = %.lr.ph394.preheader
  %unroll_iter = and i64 %25, -4
  br label %.lr.ph394

.lr.ph394:                                        ; preds = %.lr.ph394, %.lr.ph394.preheader.new
  %28 = phi i32 [ %indvars403, %.lr.ph394.preheader.new ], [ %52, %.lr.ph394 ]
  %.0392 = phi i32 [ 0, %.lr.ph394.preheader.new ], [ %51, %.lr.ph394 ]
  %niter = phi i64 [ 0, %.lr.ph394.preheader.new ], [ %niter.next.3, %.lr.ph394 ]
  %29 = sext i32 %28 to i64
  %30 = add nsw i64 %29, -1
  %31 = getelementptr i32, ptr %.unpack320, i64 %30
  %32 = load i32, ptr %31, align 4, !tbaa !3
  %33 = xor i32 %32, %.0392
  %34 = add i32 %28, %indvars403
  %35 = sext i32 %34 to i64
  %36 = add nsw i64 %35, -1
  %37 = getelementptr i32, ptr %.unpack320, i64 %36
  %38 = load i32, ptr %37, align 4, !tbaa !3
  %39 = xor i32 %38, %33
  %40 = add i32 %34, %indvars403
  %41 = sext i32 %40 to i64
  %42 = add nsw i64 %41, -1
  %43 = getelementptr i32, ptr %.unpack320, i64 %42
  %44 = load i32, ptr %43, align 4, !tbaa !3
  %45 = xor i32 %44, %39
  %46 = add i32 %40, %indvars403
  %47 = sext i32 %46 to i64
  %48 = add nsw i64 %47, -1
  %49 = getelementptr i32, ptr %.unpack320, i64 %48
  %50 = load i32, ptr %49, align 4, !tbaa !3
  %51 = xor i32 %50, %45
  %52 = add i32 %46, %indvars403
  %niter.next.3 = add i64 %niter, 4
  %niter.ncmp.3.not = icmp eq i64 %niter.next.3, %unroll_iter
  br i1 %niter.ncmp.3.not, label %._crit_edge395.loopexit.unr-lcssa, label %.lr.ph394

._crit_edge395.loopexit.unr-lcssa:                ; preds = %.lr.ph394, %.lr.ph394.preheader
  %.lcssa419.ph = phi i32 [ undef, %.lr.ph394.preheader ], [ %51, %.lr.ph394 ]
  %.unr420 = phi i32 [ %indvars403, %.lr.ph394.preheader ], [ %52, %.lr.ph394 ]
  %.0392.unr = phi i32 [ 0, %.lr.ph394.preheader ], [ %51, %.lr.ph394 ]
  %lcmp.mod.not = icmp eq i64 %xtraiter, 0
  br i1 %lcmp.mod.not, label %._crit_edge395, label %.lr.ph394.epil

.lr.ph394.epil:                                   ; preds = %._crit_edge395.loopexit.unr-lcssa, %.lr.ph394.epil
  %53 = phi i32 [ %59, %.lr.ph394.epil ], [ %.unr420, %._crit_edge395.loopexit.unr-lcssa ]
  %.0392.epil = phi i32 [ %58, %.lr.ph394.epil ], [ %.0392.unr, %._crit_edge395.loopexit.unr-lcssa ]
  %epil.iter = phi i64 [ %epil.iter.next, %.lr.ph394.epil ], [ 0, %._crit_edge395.loopexit.unr-lcssa ]
  %54 = sext i32 %53 to i64
  %55 = add nsw i64 %54, -1
  %56 = getelementptr i32, ptr %.unpack320, i64 %55
  %57 = load i32, ptr %56, align 4, !tbaa !3
  %58 = xor i32 %57, %.0392.epil
  %59 = add i32 %53, %indvars403
  %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_edge395, label %.lr.ph394.epil, !llvm.loop !9

._crit_edge395:                                   ; preds = %._crit_edge395.loopexit.unr-lcssa, %.lr.ph394.epil, %20
  %.0.lcssa = phi i32 [ 0, %20 ], [ %.lcssa419.ph, %._crit_edge395.loopexit.unr-lcssa ], [ %58, %.lr.ph394.epil ]
  %60 = add nsw i64 %22, -1
  %61 = getelementptr i32, ptr %.unpack356, i64 %60
  %62 = load i32, ptr %61, align 4, !tbaa !3
  %63 = xor i32 %62, %.0.lcssa
  %64 = add nsw i64 %22, -1
  %65 = getelementptr i32, ptr %.unpack320, i64 %64
  store i32 %63, ptr %65, align 4, !tbaa !3
  %66 = add nsw i64 %21, -1
  %67 = icmp sgt i64 %21, 1
  br i1 %67, label %20, label %._crit_edge398

._crit_edge398:                                   ; preds = %._crit_edge395, %._crit_edge
  %68 = call ptr @_FortranAioBeginExternalFormattedOutput(ptr nonnull @_QQcl.28693029, i64 4, ptr null, i32 -1, ptr nonnull @_QQcl.0073dc03b76014096504e47751aa9a4e, i32 19)
  %.unpack332 = load ptr, ptr @_QFEb.0, align 8, !tbaa !7
  %.unpack339.unpack.unpack341 = load i64, ptr @_QFEb.8, align 8, !tbaa !7
  %69 = call i64 @llvm.smax.i64(i64 %.unpack339.unpack.unpack341, i64 0)
  %.not = icmp slt i64 %.unpack339.unpack.unpack341, 1
  br i1 %.not, label %_FortranASumInteger4x1_contract_simplified.exit, label %.lr.ph.i.preheader

.lr.ph.i.preheader:                               ; preds = %._crit_edge398
  %min.iters.check = icmp ult i64 %69, 8
  br i1 %min.iters.check, label %.lr.ph.i.preheader415, label %vector.ph

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

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

.lr.ph.i.preheader415:                            ; preds = %.lr.ph.i.preheader, %middle.block
  %.ph = phi i32 [ 0, %.lr.ph.i.preheader ], [ %76, %middle.block ]
  %.ph416 = phi i64 [ 0, %.lr.ph.i.preheader ], [ %n.vec, %middle.block ]
  br label %.lr.ph.i

.lr.ph.i:                                         ; preds = %.lr.ph.i.preheader415, %.lr.ph.i
  %77 = phi i32 [ %82, %.lr.ph.i ], [ %.ph, %.lr.ph.i.preheader415 ]
  %78 = phi i64 [ %83, %.lr.ph.i ], [ %.ph416, %.lr.ph.i.preheader415 ]
  %79 = shl i64 %78, 2
  %80 = getelementptr i8, ptr %.unpack332, i64 %79
  %81 = load i32, ptr %80, align 4, !tbaa !3
  %82 = add i32 %81, %77
  %83 = add nuw nsw i64 %78, 1
  %exitcond.not.i = icmp eq i64 %83, %69
  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_edge398
  %.lcssa.i = phi i32 [ 0, %._crit_edge398 ], [ %76, %middle.block ], [ %82, %.lr.ph.i ]
  %84 = call i1 @_FortranAioOutputInteger32(ptr %68, i32 %.lcssa.i)
  %85 = call i32 @_FortranAioEndIoStatement(ptr %68)
  %86 = load i32, ptr %2, align 4, !tbaa !3
  %87 = icmp sgt i32 %86, 0
  br i1 %87, label %.lr.ph399.preheader, label %._crit_edge400

.lr.ph399.preheader:                              ; preds = %_FortranASumInteger4x1_contract_simplified.exit
  %88 = zext i32 %86 to i64
  %.unpack344.pre405 = load ptr, ptr @_QFEb.0, align 8, !tbaa !7
  br label %.lr.ph399

.lr.ph399:                                        ; preds = %.lr.ph399.preheader, %98
  %.unpack344 = phi ptr [ %.unpack344.pre405, %.lr.ph399.preheader ], [ %.unpack344406, %98 ]
  %indvars.iv = phi i64 [ 1, %.lr.ph399.preheader ], [ %indvars.iv.next, %98 ]
  %89 = add nsw i64 %indvars.iv, -1
  %90 = getelementptr i32, ptr %.unpack344, i64 %89
  %91 = load i32, ptr %90, align 4, !tbaa !3
  %92 = icmp eq i32 %91, 1
  br i1 %92, label %93, label %98

93:                                               ; preds = %.lr.ph399
  %94 = call ptr @_FortranAioBeginExternalListOutput(i32 -1, ptr nonnull @_QQcl.0073dc03b76014096504e47751aa9a4e, i32 21)
  %95 = trunc i64 %indvars.iv to i32
  %96 = call i1 @_FortranAioOutputInteger32(ptr %94, i32 %95)
  %97 = call i32 @_FortranAioEndIoStatement(ptr %94)
  %.unpack344.pre = load ptr, ptr @_QFEb.0, align 8, !tbaa !7
  br label %98

98:                                               ; preds = %93, %.lr.ph399
  %.unpack344406 = phi ptr [ %.unpack344.pre, %93 ], [ %.unpack344, %.lr.ph399 ]
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %exitcond.not = icmp eq i64 %indvars.iv, %88
  br i1 %exitcond.not, label %._crit_edge400, label %.lr.ph399

._crit_edge400:                                   ; preds = %98, %_FortranASumInteger4x1_contract_simplified.exit
  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 @_FortranAioInputDescriptor(ptr, ptr) local_unnamed_addr

declare ptr @_FortranAioBeginExternalFormattedOutput(ptr, i64, ptr, i32, ptr, i32) local_unnamed_addr

declare i1 @_FortranAioOutputInteger32(ptr, i32) local_unnamed_addr

declare ptr @_FortranAioBeginExternalListOutput(i32, 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 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}
