program test
implicit none
integer(8) :: n,k,tmp,list1(100000)=0,list2(100000)=0,i,ii,j,answer=0,big=1000000007,kenzan=0
integer(8) :: aa,bb,now_power,ans
read(*,*) n,k



do i=1,k
  tmp = int(k/i)
  
  aa = tmp
  bb = n
  now_power = 0
  ans = 1
  
  do while(bb > 0)
    do while(mod(bb,2**(now_power+1)) > 0)
      bb = bb - 2**(now_power)
      ans = mod(ans * aa,big)
    enddo
    now_power = now_power + 1
    aa = mod(aa * aa,big)
  enddo
  
  list1(i) = ans
enddo

list2 = list1

do i=k,1,-1
 ii=2*i
 do while(ii<=k)
   list2(i) = list2(i) - list2(ii)
   ii = ii + i
 enddo
enddo

do i=1,k
 answer = mod(answer+i*list2(i),big)
enddo

write(*,*) answer

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"

@_QFEanswer = internal unnamed_addr global i64 0
@_QFElist1 = internal unnamed_addr global [100000 x i64] zeroinitializer
@_QFElist2 = internal unnamed_addr global [100000 x i64] zeroinitializer
@_QQcl.c9e4bcc72f4390185430296632debacf = linkonce constant [73 x i8] c"/home/ubuntu/Downloads/TheStack_IR/Collated/Fortran/Source_1828/source.f\00"
@_QQEnvironmentDefaults = local_unnamed_addr constant ptr null

define void @_QQmain() local_unnamed_addr {
  %1 = alloca i64, align 8
  %2 = alloca i64, align 8
  %3 = tail call ptr @_FortranAioBeginExternalListInput(i32 -1, ptr nonnull @_QQcl.c9e4bcc72f4390185430296632debacf, i32 5)
  %4 = call i1 @_FortranAioInputInteger(ptr %3, ptr nonnull %2, i32 8)
  %5 = call i1 @_FortranAioInputInteger(ptr %3, ptr nonnull %1, i32 8)
  %6 = call i32 @_FortranAioEndIoStatement(ptr %3)
  %7 = load i64, ptr %1, align 8, !tbaa !3
  %8 = icmp sgt i64 %7, 0
  br i1 %8, label %.lr.ph148, label %.preheader52.thread

.preheader52.thread:                              ; preds = %0
  call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 16 dereferenceable(800000) @_QFElist2, ptr noundef nonnull align 16 dereferenceable(800000) @_QFElist1, i64 800000, i1 false), !tbaa !3
  br label %.preheader.thread

.lr.ph148:                                        ; preds = %0
  %9 = load i64, ptr %2, align 8, !tbaa !3
  %10 = icmp sgt i64 %9, 0
  br i1 %10, label %.preheader53.lr.ph.us, label %.lr.ph148.split.preheader

.lr.ph148.split.preheader:                        ; preds = %.lr.ph148
  %min.iters.check = icmp ult i64 %7, 4
  br i1 %min.iters.check, label %.lr.ph148.split.preheader238, label %vector.ph

vector.ph:                                        ; preds = %.lr.ph148.split.preheader
  %n.vec = and i64 %7, -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 ]
  %11 = getelementptr [100000 x i64], ptr @_QFElist1, i64 0, i64 %index
  store <2 x i64> <i64 1, i64 1>, ptr %11, align 16, !tbaa !3
  %12 = getelementptr i64, ptr %11, i64 2
  store <2 x i64> <i64 1, i64 1>, ptr %12, align 16, !tbaa !3
  %index.next = add nuw i64 %index, 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
  %cmp.n = icmp eq i64 %7, %n.vec
  br i1 %cmp.n, label %.preheader52, label %.lr.ph148.split.preheader238

.lr.ph148.split.preheader238:                     ; preds = %.lr.ph148.split.preheader, %middle.block
  %.029146.ph = phi i64 [ 1, %.lr.ph148.split.preheader ], [ %ind.end, %middle.block ]
  br label %.lr.ph148.split

.preheader53.lr.ph.us:                            ; preds = %.lr.ph148, %._crit_edge.us
  %.029146.us = phi i64 [ %56, %._crit_edge.us ], [ 1, %.lr.ph148 ]
  %14 = sdiv i64 %7, %.029146.us
  %sext.us = shl i64 %14, 32
  %15 = ashr exact i64 %sext.us, 32
  br label %.preheader53.us

.preheader.i.us:                                  ; preds = %.preheader.i.us.preheader, %__mlir_math_ipowi_i64.exit45.us158
  %.13155.us = phi i64 [ %31, %__mlir_math_ipowi_i64.exit45.us158 ], [ %.030142.us, %.preheader.i.us.preheader ]
  %.13354.us = phi i64 [ %33, %__mlir_math_ipowi_i64.exit45.us158 ], [ %.032141.us, %.preheader.i.us.preheader ]
  br label %.lr.ph.i.us149

.lr.ph.i.us149:                                   ; preds = %.lr.ph.i.us149, %.preheader.i.us
  %spec.select4.i.us150 = phi i64 [ %spec.select.i.us152, %.lr.ph.i.us149 ], [ %43, %.preheader.i.us ]
  %16 = phi i64 [ %18, %.lr.ph.i.us149 ], [ %39, %.preheader.i.us ]
  %17 = phi i64 [ %19, %.lr.ph.i.us149 ], [ 2, %.preheader.i.us ]
  %18 = lshr i64 %16, 1
  %19 = mul i64 %17, %17
  %20 = and i64 %16, 2
  %.not.i.us151 = icmp eq i64 %20, 0
  %21 = select i1 %.not.i.us151, i64 1, i64 %19
  %spec.select.i.us152 = mul i64 %21, %spec.select4.i.us150
  %22 = icmp ult i64 %16, 4
  br i1 %22, label %__mlir_math_ipowi_i64.exit.loopexit.us163, label %.lr.ph.i.us149

23:                                               ; preds = %__mlir_math_ipowi_i64.exit.loopexit.us163
  br i1 %or.cond, label %__mlir_math_ipowi_i64.exit45.us158, label %.lr.ph.i44.us154

.lr.ph.i44.us154:                                 ; preds = %23, %.lr.ph.i44.us154
  %spec.select4.i41.us155 = phi i64 [ %spec.select.i43.us157, %.lr.ph.i44.us154 ], [ %45, %23 ]
  %24 = phi i64 [ %26, %.lr.ph.i44.us154 ], [ %.027143.us, %23 ]
  %25 = phi i64 [ %27, %.lr.ph.i44.us154 ], [ 2, %23 ]
  %26 = lshr i64 %24, 1
  %27 = mul i64 %25, %25
  %28 = and i64 %24, 2
  %.not.i42.us156 = icmp eq i64 %28, 0
  %29 = select i1 %.not.i42.us156, i64 1, i64 %27
  %spec.select.i43.us157 = mul i64 %29, %spec.select4.i41.us155
  %30 = icmp ult i64 %24, 4
  br i1 %30, label %__mlir_math_ipowi_i64.exit45.us158, label %.lr.ph.i44.us154

__mlir_math_ipowi_i64.exit45.us158:               ; preds = %.lr.ph.i44.us154, %23
  %common.ret.op.i38.us159 = phi i64 [ %45, %23 ], [ %spec.select.i43.us157, %.lr.ph.i44.us154 ]
  %31 = sub i64 %.13155.us, %common.ret.op.i38.us159
  %32 = mul i64 %.13354.us, %.034134.us
  %33 = srem i64 %32, 1000000007
  br label %.preheader.i.us

__mlir_math_ipowi_i64.exit.thread.us:             ; preds = %__mlir_math_ipowi_i64.exit.loopexit.us163, %__mlir_math_ipowi_i64.exit45.us71.us183, %.lr.ph.split.split.us.split.us187, %.preheader53.us
  %.133.lcssa.us = phi i64 [ %.032141.us, %.preheader53.us ], [ %.032141.us, %.lr.ph.split.split.us.split.us187 ], [ %49, %__mlir_math_ipowi_i64.exit45.us71.us183 ], [ %.13354.us, %__mlir_math_ipowi_i64.exit.loopexit.us163 ]
  %.131.lcssa.us = phi i64 [ %.030142.us, %.preheader53.us ], [ %.030142.us, %.lr.ph.split.split.us.split.us187 ], [ %47, %__mlir_math_ipowi_i64.exit45.us71.us183 ], [ %.13155.us, %__mlir_math_ipowi_i64.exit.loopexit.us163 ]
  %34 = mul nsw i64 %.034134.us, %.034134.us
  %35 = urem i64 %34, 1000000007
  %36 = icmp sgt i64 %.131.lcssa.us, 0
  br i1 %36, label %.preheader53.us, label %._crit_edge.us

__mlir_math_ipowi_i64.exit.loopexit.us163:        ; preds = %.lr.ph.i.us149
  %37 = srem i64 %.13155.us, %spec.select.i.us152
  %38 = icmp sgt i64 %37, 0
  br i1 %38, label %23, label %__mlir_math_ipowi_i64.exit.thread.us

.preheader53.us:                                  ; preds = %.preheader53.lr.ph.us, %__mlir_math_ipowi_i64.exit.thread.us
  %.027143.us = phi i64 [ 0, %.preheader53.lr.ph.us ], [ %39, %__mlir_math_ipowi_i64.exit.thread.us ]
  %.030142.us = phi i64 [ %9, %.preheader53.lr.ph.us ], [ %.131.lcssa.us, %__mlir_math_ipowi_i64.exit.thread.us ]
  %.032141.us = phi i64 [ 1, %.preheader53.lr.ph.us ], [ %.133.lcssa.us, %__mlir_math_ipowi_i64.exit.thread.us ]
  %.034134.us = phi i64 [ %15, %.preheader53.lr.ph.us ], [ %35, %__mlir_math_ipowi_i64.exit.thread.us ]
  %39 = add i64 %.027143.us, 1
  %40 = icmp eq i64 %39, 0
  br i1 %40, label %__mlir_math_ipowi_i64.exit.thread.us, label %.lr.ph.us

.lr.ph.us:                                        ; preds = %.preheader53.us
  %41 = icmp ult i64 %.027143.us, 9223372036854775807
  %42 = and i64 %39, 1
  %.not3.i.us = icmp eq i64 %42, 0
  %43 = select i1 %.not3.i.us, i64 1, i64 2
  %44 = and i64 %.027143.us, 1
  %.not3.i39.us = icmp eq i64 %44, 0
  %45 = select i1 %.not3.i39.us, i64 1, i64 2
  call void @llvm.assume(i1 %41)
  %46 = icmp eq i64 %.027143.us, 0
  br i1 %46, label %.lr.ph.split.split.us.split.us187, label %.preheader.i.us.preheader

.preheader.i.us.preheader:                        ; preds = %.lr.ph.us
  %or.cond = icmp eq i64 %.027143.us, 1
  br label %.preheader.i.us

__mlir_math_ipowi_i64.exit45.us71.us183:          ; preds = %.lr.ph.split.split.us.split.us187, %__mlir_math_ipowi_i64.exit45.us71.us183
  %.13354.us70114.us = phi i64 [ %49, %__mlir_math_ipowi_i64.exit45.us71.us183 ], [ %.032141.us, %.lr.ph.split.split.us.split.us187 ]
  %.13155.us69113.us = phi i64 [ %47, %__mlir_math_ipowi_i64.exit45.us71.us183 ], [ %.030142.us, %.lr.ph.split.split.us.split.us187 ]
  %47 = add i64 %.13155.us69113.us, -1
  %48 = mul i64 %.13354.us70114.us, %.034134.us
  %49 = srem i64 %48, 1000000007
  %50 = srem i64 %47, %43
  %51 = icmp sgt i64 %50, 0
  br i1 %51, label %__mlir_math_ipowi_i64.exit45.us71.us183, label %__mlir_math_ipowi_i64.exit.thread.us

.lr.ph.split.split.us.split.us187:                ; preds = %.lr.ph.us
  %52 = srem i64 %.030142.us, %43
  %53 = icmp sgt i64 %52, 0
  br i1 %53, label %__mlir_math_ipowi_i64.exit45.us71.us183, label %__mlir_math_ipowi_i64.exit.thread.us

._crit_edge.us:                                   ; preds = %__mlir_math_ipowi_i64.exit.thread.us
  %54 = add i64 %.029146.us, -1
  %55 = getelementptr [100000 x i64], ptr @_QFElist1, i64 0, i64 %54
  store i64 %.133.lcssa.us, ptr %55, align 8, !tbaa !3
  %56 = add nuw i64 %.029146.us, 1
  %exitcond225.not = icmp eq i64 %.029146.us, %7
  br i1 %exitcond225.not, label %.preheader52, label %.preheader53.lr.ph.us

.preheader52:                                     ; preds = %.lr.ph148.split, %._crit_edge.us, %middle.block
  call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 16 dereferenceable(800000) @_QFElist2, ptr noundef nonnull align 16 dereferenceable(800000) @_QFElist1, i64 800000, i1 false), !tbaa !3
  br i1 %8, label %.lr.ph197, label %.preheader.thread

.lr.ph148.split:                                  ; preds = %.lr.ph148.split.preheader238, %.lr.ph148.split
  %.029146 = phi i64 [ %59, %.lr.ph148.split ], [ %.029146.ph, %.lr.ph148.split.preheader238 ]
  %57 = add i64 %.029146, -1
  %58 = getelementptr [100000 x i64], ptr @_QFElist1, i64 0, i64 %57
  store i64 1, ptr %58, align 8, !tbaa !3
  %59 = add nuw i64 %.029146, 1
  %exitcond.not = icmp eq i64 %.029146, %7
  br i1 %exitcond.not, label %.preheader52, label %.lr.ph148.split, !llvm.loop !10

.preheader:                                       ; preds = %._crit_edge
  br i1 %8, label %.lr.ph198.preheader, label %.preheader.thread

.lr.ph198.preheader:                              ; preds = %.preheader
  %_QFEanswer.promoted = load i64, ptr @_QFEanswer, align 8, !tbaa !3
  %xtraiter = and i64 %7, 1
  %60 = icmp eq i64 %7, 1
  br i1 %60, label %._crit_edge199.unr-lcssa, label %.lr.ph198.preheader.new

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

.lr.ph197:                                        ; preds = %.preheader52, %._crit_edge
  %.0196 = phi i64 [ %.pre, %._crit_edge ], [ %7, %.preheader52 ]
  %61 = shl nuw i64 %.0196, 1
  %.not193 = icmp sgt i64 %61, %7
  %.pre = add nsw i64 %.0196, -1
  br i1 %.not193, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %.lr.ph197
  %62 = getelementptr [100000 x i64], ptr @_QFElist2, i64 0, i64 %.pre
  %.promoted = load i64, ptr %62, align 8, !tbaa !3
  br label %63

63:                                               ; preds = %.lr.ph, %63
  %64 = phi i64 [ %.promoted, %.lr.ph ], [ %68, %63 ]
  %.028194 = phi i64 [ %61, %.lr.ph ], [ %69, %63 ]
  %65 = add i64 %.028194, -1
  %66 = getelementptr [100000 x i64], ptr @_QFElist2, i64 0, i64 %65
  %67 = load i64, ptr %66, align 8, !tbaa !3
  %68 = sub i64 %64, %67
  store i64 %68, ptr %62, align 8, !tbaa !3
  %69 = add i64 %.028194, %.0196
  %.not = icmp sgt i64 %69, %7
  br i1 %.not, label %._crit_edge, label %63

._crit_edge:                                      ; preds = %63, %.lr.ph197
  %70 = icmp sgt i64 %.0196, 1
  br i1 %70, label %.lr.ph197, label %.preheader

.lr.ph198:                                        ; preds = %.lr.ph198, %.lr.ph198.preheader.new
  %71 = phi i64 [ 1, %.lr.ph198.preheader.new ], [ %85, %.lr.ph198 ]
  %72 = phi i64 [ %_QFEanswer.promoted, %.lr.ph198.preheader.new ], [ %84, %.lr.ph198 ]
  %niter = phi i64 [ 0, %.lr.ph198.preheader.new ], [ %niter.next.1, %.lr.ph198 ]
  %73 = add nsw i64 %71, -1
  %74 = getelementptr [100000 x i64], ptr @_QFElist2, i64 0, i64 %73
  %75 = load i64, ptr %74, align 8, !tbaa !3
  %76 = mul i64 %75, %71
  %77 = add i64 %76, %72
  %78 = srem i64 %77, 1000000007
  %79 = add nuw i64 %71, 1
  %80 = getelementptr [100000 x i64], ptr @_QFElist2, i64 0, i64 %71
  %81 = load i64, ptr %80, align 8, !tbaa !3
  %82 = mul i64 %81, %79
  %83 = add i64 %82, %78
  %84 = srem i64 %83, 1000000007
  %85 = add nuw i64 %71, 2
  %niter.next.1 = add nuw i64 %niter, 2
  %niter.ncmp.1 = icmp eq i64 %niter.next.1, %unroll_iter
  br i1 %niter.ncmp.1, label %._crit_edge199.unr-lcssa, label %.lr.ph198

._crit_edge199.unr-lcssa:                         ; preds = %.lr.ph198, %.lr.ph198.preheader
  %.lcssa.ph = phi i64 [ undef, %.lr.ph198.preheader ], [ %84, %.lr.ph198 ]
  %.unr = phi i64 [ 1, %.lr.ph198.preheader ], [ %85, %.lr.ph198 ]
  %.unr240 = phi i64 [ %_QFEanswer.promoted, %.lr.ph198.preheader ], [ %84, %.lr.ph198 ]
  %lcmp.mod.not = icmp eq i64 %xtraiter, 0
  br i1 %lcmp.mod.not, label %._crit_edge199, label %.lr.ph198.epil

.lr.ph198.epil:                                   ; preds = %._crit_edge199.unr-lcssa
  %86 = add nsw i64 %.unr, -1
  %87 = getelementptr [100000 x i64], ptr @_QFElist2, i64 0, i64 %86
  %88 = load i64, ptr %87, align 8, !tbaa !3
  %89 = mul i64 %88, %.unr
  %90 = add i64 %89, %.unr240
  %91 = srem i64 %90, 1000000007
  br label %._crit_edge199

._crit_edge199:                                   ; preds = %._crit_edge199.unr-lcssa, %.lr.ph198.epil
  %.lcssa = phi i64 [ %.lcssa.ph, %._crit_edge199.unr-lcssa ], [ %91, %.lr.ph198.epil ]
  store i64 %.lcssa, ptr @_QFEanswer, align 8, !tbaa !3
  br label %.preheader.thread

.preheader.thread:                                ; preds = %.preheader52, %.preheader52.thread, %._crit_edge199, %.preheader
  %92 = call ptr @_FortranAioBeginExternalListOutput(i32 -1, ptr nonnull @_QQcl.c9e4bcc72f4390185430296632debacf, i32 43)
  %93 = load i64, ptr @_QFEanswer, align 8, !tbaa !3
  %94 = call i1 @_FortranAioOutputInteger64(ptr %92, i64 %93)
  %95 = call i32 @_FortranAioEndIoStatement(ptr %92)
  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 ptr @_FortranAioBeginExternalListOutput(i32, ptr, i32) local_unnamed_addr

declare i1 @_FortranAioOutputInteger64(ptr, i64) local_unnamed_addr

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #0

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(inaccessiblemem: readwrite)
declare void @llvm.assume(i1 noundef) #1

attributes #0 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { nocallback nofree nosync nounwind willreturn memory(inaccessiblemem: readwrite) }

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