program c177

implicit none
integer(16) :: n, ans, i, j, sum
integer(16), allocatable :: a(:), p(:)

read *, n
allocate(a(1:n))
allocate(p(1:n))

read *, a(:)

ans = 0
p(:) = 0

do i = n-1, 1, -1
 p(i) = p(i+1) + a(i+1)
end do

!print *, p(:)

do i = 1, n-1
 ans = ans + a(i) * p(i)
 !print *, a(i)*p(i)
end do

print *, mod(ans,1000000007)

end program c177
; 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
@_QFEp.0 = internal unnamed_addr global ptr null
@_QFEp.8 = internal unnamed_addr global i64 0
@_QQcl.787e73395c7380c6f74b1a1b025d5184 = linkonce constant [72 x i8] c"/home/ubuntu/Downloads/TheStack_IR/Collated/Fortran/Source_706/source.f\00"
@_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 i128, align 8
  %3 = tail call ptr @_FortranAioBeginExternalListInput(i32 -1, ptr nonnull @_QQcl.787e73395c7380c6f74b1a1b025d5184, i32 7)
  %4 = call i1 @_FortranAioInputInteger(ptr %3, ptr nonnull %2, i32 16)
  %5 = call i32 @_FortranAioEndIoStatement(ptr %3)
  %6 = load i128, ptr %2, align 8, !tbaa !3
  %7 = trunc i128 %6 to i64
  %8 = call i64 @llvm.smax.i64(i64 %7, i64 0)
  %9 = shl i64 %8, 4
  %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 @_QFEp.0, align 8, !tbaa !7
  store i64 %8, ptr @_QFEp.8, align 8, !tbaa !7
  %12 = call ptr @_FortranAioBeginExternalListInput(i32 -1, ptr nonnull @_QQcl.787e73395c7380c6f74b1a1b025d5184, i32 11)
  %.unpack = load ptr, ptr @_QFEa.0, align 8, !tbaa !7
  %.unpack260.unpack.unpack262 = load i64, ptr @_QFEa.8, align 8, !tbaa !7
  %13 = call i64 @llvm.smax.i64(i64 %.unpack260.unpack.unpack262, 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 16, 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 11, 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 16, 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)
  %.unpack265 = load ptr, ptr @_QFEp.0, align 8, !tbaa !7
  %.unpack272.unpack.unpack274 = load i64, ptr @_QFEp.8, align 8, !tbaa !7
  %.not = icmp slt i64 %.unpack272.unpack.unpack274, 1
  br i1 %.not, label %._crit_edge, label %.lr.ph.preheader

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

._crit_edge:                                      ; preds = %.lr.ph.preheader, %0
  %17 = load i128, ptr %2, align 8, !tbaa !3
  %18 = trunc i128 %17 to i64
  %19 = add i64 %18, -1
  %20 = icmp sgt i64 %19, 0
  br i1 %20, label %.lr.ph327, label %._crit_edge332

.lr.ph327:                                        ; preds = %._crit_edge
  %.unpack313 = load ptr, ptr @_QFEa.0, align 8, !tbaa !7
  %xtraiter = and i64 %19, 1
  %lcmp.mod.not = icmp eq i64 %xtraiter, 0
  br i1 %lcmp.mod.not, label %.prol.loopexit, label %.prol.loopexit.unr-lcssa

.prol.loopexit.unr-lcssa:                         ; preds = %.lr.ph327
  %21 = add i64 %18, -1
  %22 = add i64 %18, -1
  %23 = getelementptr i128, ptr %.unpack265, i64 %22
  %24 = load i128, ptr %23, align 8, !tbaa !3
  %25 = add i64 %18, -1
  %26 = getelementptr i128, ptr %.unpack313, i64 %25
  %27 = load i128, ptr %26, align 8, !tbaa !3
  %28 = add i128 %27, %24
  %29 = add i64 %18, -2
  %30 = getelementptr i128, ptr %.unpack265, i64 %29
  store i128 %28, ptr %30, align 8, !tbaa !3
  %31 = add i64 %18, -2
  br label %.prol.loopexit

.prol.loopexit:                                   ; preds = %.prol.loopexit.unr-lcssa, %.lr.ph327
  %.unr = phi i64 [ %19, %.lr.ph327 ], [ %31, %.prol.loopexit.unr-lcssa ]
  %.in.unr = phi i64 [ %18, %.lr.ph327 ], [ %21, %.prol.loopexit.unr-lcssa ]
  %32 = icmp eq i64 %18, 2
  br i1 %32, label %._crit_edge328, label %.lr.ph327.new

.lr.ph327.new:                                    ; preds = %.prol.loopexit, %.lr.ph327.new
  %33 = phi i64 [ %53, %.lr.ph327.new ], [ %.unr, %.prol.loopexit ]
  %.in = phi i64 [ %43, %.lr.ph327.new ], [ %.in.unr, %.prol.loopexit ]
  %34 = add i64 %.in, -1
  %35 = getelementptr i128, ptr %.unpack265, i64 %34
  %36 = load i128, ptr %35, align 8, !tbaa !3
  %37 = add i64 %.in, -1
  %38 = getelementptr i128, ptr %.unpack313, i64 %37
  %39 = load i128, ptr %38, align 8, !tbaa !3
  %40 = add i128 %39, %36
  %41 = add i64 %.in, -2
  %42 = getelementptr i128, ptr %.unpack265, i64 %41
  store i128 %40, ptr %42, align 8, !tbaa !3
  %43 = add i64 %.in, -2
  %44 = add i64 %.in, -2
  %45 = getelementptr i128, ptr %.unpack265, i64 %44
  %46 = load i128, ptr %45, align 8, !tbaa !3
  %47 = add i64 %.in, -2
  %48 = getelementptr i128, ptr %.unpack313, i64 %47
  %49 = load i128, ptr %48, align 8, !tbaa !3
  %50 = add i128 %49, %46
  %51 = add i64 %.in, -3
  %52 = getelementptr i128, ptr %.unpack265, i64 %51
  store i128 %50, ptr %52, align 8, !tbaa !3
  %53 = add nsw i64 %33, -2
  %.not338.1 = icmp eq i64 %53, 0
  br i1 %.not338.1, label %._crit_edge328, label %.lr.ph327.new

._crit_edge328:                                   ; preds = %.lr.ph327.new, %.prol.loopexit
  %.pre = load i128, ptr %2, align 8, !tbaa !3
  %.pre333 = trunc i128 %.pre to i64
  %.pre334 = add i64 %.pre333, -1
  %54 = icmp sgt i64 %.pre334, 0
  br i1 %54, label %.lr.ph331, label %._crit_edge332

.lr.ph331:                                        ; preds = %._crit_edge328
  %.unpack277 = load ptr, ptr @_QFEa.0, align 8, !tbaa !7
  %xtraiter339 = and i64 %.pre334, 1
  %55 = icmp eq i64 %.pre333, 2
  br i1 %55, label %._crit_edge332.loopexit.unr-lcssa, label %.lr.ph331.new

.lr.ph331.new:                                    ; preds = %.lr.ph331
  %unroll_iter = and i64 %.pre334, -2
  br label %56

56:                                               ; preds = %56, %.lr.ph331.new
  %57 = phi i64 [ 1, %.lr.ph331.new ], [ %72, %56 ]
  %.0329 = phi i128 [ 0, %.lr.ph331.new ], [ %71, %56 ]
  %niter = phi i64 [ 0, %.lr.ph331.new ], [ %niter.next.1, %56 ]
  %58 = add nsw i64 %57, -1
  %59 = getelementptr i128, ptr %.unpack277, i64 %58
  %60 = load i128, ptr %59, align 8, !tbaa !3
  %61 = add nsw i64 %57, -1
  %62 = getelementptr i128, ptr %.unpack265, i64 %61
  %63 = load i128, ptr %62, align 8, !tbaa !3
  %64 = mul i128 %63, %60
  %65 = add i128 %64, %.0329
  %66 = getelementptr i128, ptr %.unpack277, i64 %57
  %67 = load i128, ptr %66, align 8, !tbaa !3
  %68 = getelementptr i128, ptr %.unpack265, i64 %57
  %69 = load i128, ptr %68, align 8, !tbaa !3
  %70 = mul i128 %69, %67
  %71 = add i128 %70, %65
  %72 = add nuw i64 %57, 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_edge332.loopexit.unr-lcssa.loopexit, label %56

._crit_edge332.loopexit.unr-lcssa.loopexit:       ; preds = %56
  %73 = add i64 %57, 1
  br label %._crit_edge332.loopexit.unr-lcssa

._crit_edge332.loopexit.unr-lcssa:                ; preds = %._crit_edge332.loopexit.unr-lcssa.loopexit, %.lr.ph331
  %.lcssa.ph = phi i128 [ undef, %.lr.ph331 ], [ %71, %._crit_edge332.loopexit.unr-lcssa.loopexit ]
  %.unr340 = phi i64 [ 0, %.lr.ph331 ], [ %73, %._crit_edge332.loopexit.unr-lcssa.loopexit ]
  %.0329.unr = phi i128 [ 0, %.lr.ph331 ], [ %71, %._crit_edge332.loopexit.unr-lcssa.loopexit ]
  %lcmp.mod341.not = icmp eq i64 %xtraiter339, 0
  br i1 %lcmp.mod341.not, label %._crit_edge332.loopexit, label %._crit_edge332.loopexit.epilog-lcssa

._crit_edge332.loopexit.epilog-lcssa:             ; preds = %._crit_edge332.loopexit.unr-lcssa
  %74 = getelementptr i128, ptr %.unpack277, i64 %.unr340
  %75 = load i128, ptr %74, align 8, !tbaa !3
  %76 = getelementptr i128, ptr %.unpack265, i64 %.unr340
  %77 = load i128, ptr %76, align 8, !tbaa !3
  %78 = mul i128 %77, %75
  %79 = add i128 %78, %.0329.unr
  br label %._crit_edge332.loopexit

._crit_edge332.loopexit:                          ; preds = %._crit_edge332.loopexit.unr-lcssa, %._crit_edge332.loopexit.epilog-lcssa
  %.lcssa = phi i128 [ %.lcssa.ph, %._crit_edge332.loopexit.unr-lcssa ], [ %79, %._crit_edge332.loopexit.epilog-lcssa ]
  %80 = srem i128 %.lcssa, 1000000007
  br label %._crit_edge332

._crit_edge332:                                   ; preds = %._crit_edge, %._crit_edge332.loopexit, %._crit_edge328
  %.0.lcssa = phi i128 [ 0, %._crit_edge328 ], [ %80, %._crit_edge332.loopexit ], [ 0, %._crit_edge ]
  %81 = call ptr @_FortranAioBeginExternalListOutput(i32 -1, ptr nonnull @_QQcl.787e73395c7380c6f74b1a1b025d5184, i32 27)
  %82 = call i1 @_FortranAioOutputInteger128(ptr %81, i128 %.0.lcssa)
  %83 = call i32 @_FortranAioEndIoStatement(ptr %81)
  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 @_FortranAioBeginExternalListOutput(i32, ptr, i32) local_unnamed_addr

declare i1 @_FortranAioOutputInteger128(ptr, i128) 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 nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #2

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) }

!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}
