program sample
    implicit none
  
    integer(8) :: i,j,m,n,a(10000000)
    
    integer(8),allocatable :: x(:),y(:)
  
    read(*,*) n

    do i=1,10000000
        a(i)=0
    end do
    do i=1,n
        do j=1,n/i
             a(i*j)=a(i*j)+1
         end do
    end do
    m=0
    do i=1,n
        m=m+a(i)*i

    end do
    write(*,*) m
  
    stop
end program sample
  


; 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 [10000000 x i64] undef
@_QQcl.afcd41cb582ed62d382a56dd343f7ea8 = linkonce constant [73 x i8] c"/home/ubuntu/Downloads/TheStack_IR/Collated/Fortran/Source_1091/source.f\00"
@_QQEnvironmentDefaults = local_unnamed_addr constant ptr null

; Function Attrs: noreturn
define void @_QQmain() local_unnamed_addr #0 {
  %1 = alloca i64, align 8
  %2 = tail call ptr @_FortranAioBeginExternalListInput(i32 -1, ptr nonnull @_QQcl.afcd41cb582ed62d382a56dd343f7ea8, i32 8)
  %3 = call i1 @_FortranAioInputInteger(ptr %2, ptr nonnull %1, i32 8)
  %4 = call i32 @_FortranAioEndIoStatement(ptr %2)
  call void @llvm.memset.p0.i64(ptr noundef nonnull align 16 dereferenceable(80000000) @_QFEa, i8 0, i64 80000000, i1 false), !tbaa !3
  %5 = load i64, ptr %1, align 8, !tbaa !3
  %6 = icmp sgt i64 %5, 0
  br i1 %6, label %.lr.ph16, label %._crit_edge19

.preheader:                                       ; preds = %._crit_edge
  br i1 %6, label %.lr.ph18.preheader, label %._crit_edge19

.lr.ph18.preheader:                               ; preds = %.preheader
  %min.iters.check = icmp ult i64 %5, 4
  br i1 %min.iters.check, label %.lr.ph18.preheader25, label %vector.ph

vector.ph:                                        ; preds = %.lr.ph18.preheader
  %n.vec = and i64 %5, -4
  %ind.end = or i64 %n.vec, 1
  br label %vector.body

vector.body:                                      ; preds = %vector.body, %vector.ph
  %index = phi i64 [ 0, %vector.ph ], [ %index.next, %vector.body ]
  %vec.ind = phi <2 x i64> [ <i64 1, i64 2>, %vector.ph ], [ %vec.ind.next, %vector.body ]
  %vec.phi = phi <2 x i64> [ zeroinitializer, %vector.ph ], [ %11, %vector.body ]
  %vec.phi23 = phi <2 x i64> [ zeroinitializer, %vector.ph ], [ %12, %vector.body ]
  %step.add = add <2 x i64> %vec.ind, <i64 2, i64 2>
  %7 = getelementptr [10000000 x i64], ptr @_QFEa, i64 0, i64 %index
  %wide.load = load <2 x i64>, ptr %7, align 16, !tbaa !3
  %8 = getelementptr i64, ptr %7, i64 2
  %wide.load24 = load <2 x i64>, ptr %8, align 16, !tbaa !3
  %9 = mul <2 x i64> %wide.load, %vec.ind
  %10 = mul <2 x i64> %wide.load24, %step.add
  %11 = add <2 x i64> %9, %vec.phi
  %12 = add <2 x i64> %10, %vec.phi23
  %index.next = add nuw i64 %index, 4
  %vec.ind.next = add <2 x i64> %vec.ind, <i64 4, i64 4>
  %13 = icmp eq i64 %index.next, %n.vec
  br i1 %13, label %middle.block, label %vector.body, !llvm.loop !7

middle.block:                                     ; preds = %vector.body
  %bin.rdx = add <2 x i64> %12, %11
  %14 = call i64 @llvm.vector.reduce.add.v2i64(<2 x i64> %bin.rdx)
  %cmp.n = icmp eq i64 %5, %n.vec
  br i1 %cmp.n, label %._crit_edge19, label %.lr.ph18.preheader25

.lr.ph18.preheader25:                             ; preds = %.lr.ph18.preheader, %middle.block
  %.ph = phi i64 [ 1, %.lr.ph18.preheader ], [ %ind.end, %middle.block ]
  %.017.ph = phi i64 [ 0, %.lr.ph18.preheader ], [ %14, %middle.block ]
  br label %.lr.ph18

.lr.ph16:                                         ; preds = %0, %._crit_edge
  %15 = phi i64 [ %37, %._crit_edge ], [ 1, %0 ]
  %16 = sdiv i64 %5, %15
  %17 = icmp sgt i64 %16, 0
  br i1 %17, label %.lr.ph.preheader, label %._crit_edge

.lr.ph.preheader:                                 ; preds = %.lr.ph16
  %xtraiter = and i64 %16, 1
  %18 = icmp eq i64 %16, 1
  br i1 %18, label %._crit_edge.loopexit.unr-lcssa, label %.lr.ph.preheader.new

.lr.ph.preheader.new:                             ; preds = %.lr.ph.preheader
  %unroll_iter = and i64 %16, -2
  br label %.lr.ph

.lr.ph:                                           ; preds = %.lr.ph, %.lr.ph.preheader.new
  %19 = phi i64 [ 1, %.lr.ph.preheader.new ], [ %31, %.lr.ph ]
  %niter = phi i64 [ 0, %.lr.ph.preheader.new ], [ %niter.next.1, %.lr.ph ]
  %20 = mul i64 %19, %15
  %21 = add i64 %20, -1
  %22 = getelementptr [10000000 x i64], ptr @_QFEa, i64 0, i64 %21
  %23 = load i64, ptr %22, align 8, !tbaa !3
  %24 = add i64 %23, 1
  store i64 %24, ptr %22, align 8, !tbaa !3
  %25 = add nuw i64 %19, 1
  %26 = mul i64 %25, %15
  %27 = add i64 %26, -1
  %28 = getelementptr [10000000 x i64], ptr @_QFEa, i64 0, i64 %27
  %29 = load i64, ptr %28, align 8, !tbaa !3
  %30 = add i64 %29, 1
  store i64 %30, ptr %28, align 8, !tbaa !3
  %31 = add nuw i64 %19, 2
  %niter.next.1 = add i64 %niter, 2
  %niter.ncmp.1 = icmp eq i64 %niter.next.1, %unroll_iter
  br i1 %niter.ncmp.1, label %._crit_edge.loopexit.unr-lcssa, label %.lr.ph

._crit_edge.loopexit.unr-lcssa:                   ; preds = %.lr.ph, %.lr.ph.preheader
  %.unr = phi i64 [ 1, %.lr.ph.preheader ], [ %31, %.lr.ph ]
  %lcmp.mod.not = icmp eq i64 %xtraiter, 0
  br i1 %lcmp.mod.not, label %._crit_edge, label %.lr.ph.epil

.lr.ph.epil:                                      ; preds = %._crit_edge.loopexit.unr-lcssa
  %32 = mul i64 %.unr, %15
  %33 = add i64 %32, -1
  %34 = getelementptr [10000000 x i64], ptr @_QFEa, i64 0, i64 %33
  %35 = load i64, ptr %34, align 8, !tbaa !3
  %36 = add i64 %35, 1
  store i64 %36, ptr %34, align 8, !tbaa !3
  br label %._crit_edge

._crit_edge:                                      ; preds = %.lr.ph.epil, %._crit_edge.loopexit.unr-lcssa, %.lr.ph16
  %37 = add nuw i64 %15, 1
  %exitcond20.not = icmp eq i64 %15, %5
  br i1 %exitcond20.not, label %.preheader, label %.lr.ph16

.lr.ph18:                                         ; preds = %.lr.ph18.preheader25, %.lr.ph18
  %38 = phi i64 [ %44, %.lr.ph18 ], [ %.ph, %.lr.ph18.preheader25 ]
  %.017 = phi i64 [ %43, %.lr.ph18 ], [ %.017.ph, %.lr.ph18.preheader25 ]
  %39 = add nsw i64 %38, -1
  %40 = getelementptr [10000000 x i64], ptr @_QFEa, i64 0, i64 %39
  %41 = load i64, ptr %40, align 8, !tbaa !3
  %42 = mul i64 %41, %38
  %43 = add i64 %42, %.017
  %44 = add nuw i64 %38, 1
  %exitcond21.not = icmp eq i64 %38, %5
  br i1 %exitcond21.not, label %._crit_edge19, label %.lr.ph18, !llvm.loop !10

._crit_edge19:                                    ; preds = %.lr.ph18, %middle.block, %0, %.preheader
  %.0.lcssa = phi i64 [ 0, %.preheader ], [ 0, %0 ], [ %14, %middle.block ], [ %43, %.lr.ph18 ]
  %45 = call ptr @_FortranAioBeginExternalListOutput(i32 -1, ptr nonnull @_QQcl.afcd41cb582ed62d382a56dd343f7ea8, i32 23)
  %46 = call i1 @_FortranAioOutputInteger64(ptr %45, i64 %.0.lcssa)
  %47 = call i32 @_FortranAioEndIoStatement(ptr %45)
  %48 = 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 @_FortranAioOutputInteger64(ptr, i64) 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

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(none)
declare i64 @llvm.vector.reduce.add.v2i64(<2 x i64>) #2

attributes #0 = { noreturn }
attributes #1 = { nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #2 = { 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 = distinct !{!7, !8, !9}
!8 = !{!"llvm.loop.isvectorized", i32 1}
!9 = !{!"llvm.loop.unroll.runtime.disable"}
!10 = distinct !{!10, !9, !8}
