program c174

implicit none
integer(16) :: k, i, a, b, m, f

i = 1

read *, k

if (mod(k, 2) == 0) then
 print *, -1
 stop
else if (k == 7) then
 print *, 1
 stop
end if

f = mod(7, k)
a = mod(7, k)

do while(f > 0)
 i = i + 1
 b = a * 10
 a = mod(b, k)
 m =  f + a
 f = mod(m, k)
 !print '(4(I3))', i, a, b, f
 
 if(i > 1919810) then
 print *, -1
 stop
 end if
 
end do

print *, i

end program c174
; 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"

@_QQcl.3413a182f1e5bd0de09bd377e91be649 = linkonce constant [72 x i8] c"/home/ubuntu/Downloads/TheStack_IR/Collated/Fortran/Source_867/source.f\00"
@_QQEnvironmentDefaults = local_unnamed_addr constant ptr null

define void @_QQmain() local_unnamed_addr {
  %1 = alloca i128, align 8
  %2 = tail call ptr @_FortranAioBeginExternalListInput(i32 -1, ptr nonnull @_QQcl.3413a182f1e5bd0de09bd377e91be649, i32 8)
  %3 = call i1 @_FortranAioInputInteger(ptr %2, ptr nonnull %1, i32 16)
  %4 = call i32 @_FortranAioEndIoStatement(ptr %2)
  %5 = load i128, ptr %1, align 8, !tbaa !3
  %6 = and i128 %5, 1
  %7 = icmp eq i128 %6, 0
  br i1 %7, label %8, label %13

8:                                                ; preds = %0
  %9 = call ptr @_FortranAioBeginExternalListOutput(i32 -1, ptr nonnull @_QQcl.3413a182f1e5bd0de09bd377e91be649, i32 11)
  %10 = call i1 @_FortranAioOutputInteger32(ptr %9, i32 -1)
  %11 = call i32 @_FortranAioEndIoStatement(ptr %9)
  %12 = call {} @_FortranAStopStatement(i32 0, i1 false, i1 false)
  unreachable

13:                                               ; preds = %0
  %14 = icmp eq i128 %5, 7
  br i1 %14, label %15, label %20

15:                                               ; preds = %13
  %16 = call ptr @_FortranAioBeginExternalListOutput(i32 -1, ptr nonnull @_QQcl.3413a182f1e5bd0de09bd377e91be649, i32 14)
  %17 = call i1 @_FortranAioOutputInteger32(ptr %16, i32 1)
  %18 = call i32 @_FortranAioEndIoStatement(ptr %16)
  %19 = call {} @_FortranAStopStatement(i32 0, i1 false, i1 false)
  unreachable

20:                                               ; preds = %13
  %21 = srem i128 7, %5
  br label %22

22:                                               ; preds = %30, %20
  %.010 = phi i128 [ %21, %20 ], [ %35, %30 ]
  %.09 = phi i128 [ 1, %20 ], [ %31, %30 ]
  %.0 = phi i128 [ %21, %20 ], [ %33, %30 ]
  %23 = icmp sgt i128 %.010, 0
  br i1 %23, label %24, label %.split.loop.exit18

24:                                               ; preds = %22
  %25 = mul i128 %.0, 10
  %26 = srem i128 %25, %5
  %27 = add i128 %26, %.010
  %28 = srem i128 %27, %5
  %29 = icmp sgt i128 %28, 0
  br i1 %29, label %30, label %.split.loop.exit

30:                                               ; preds = %24
  %31 = add nuw nsw i128 %.09, 2
  %32 = mul i128 %26, 10
  %33 = srem i128 %32, %5
  %34 = add i128 %33, %28
  %35 = srem i128 %34, %5
  %36 = icmp ugt i128 %.09, 1919808
  br i1 %36, label %37, label %22

37:                                               ; preds = %30
  %38 = call ptr @_FortranAioBeginExternalListOutput(i32 -1, ptr nonnull @_QQcl.3413a182f1e5bd0de09bd377e91be649, i32 30)
  %39 = call i1 @_FortranAioOutputInteger32(ptr %38, i32 -1)
  %40 = call i32 @_FortranAioEndIoStatement(ptr %38)
  %41 = call {} @_FortranAStopStatement(i32 0, i1 false, i1 false)
  unreachable

.split.loop.exit:                                 ; preds = %24
  %42 = add nuw nsw i128 %.09, 1
  br label %.split.loop.exit18

.split.loop.exit18:                               ; preds = %22, %.split.loop.exit
  %.09.lcssa = phi i128 [ %42, %.split.loop.exit ], [ %.09, %22 ]
  %43 = call ptr @_FortranAioBeginExternalListOutput(i32 -1, ptr nonnull @_QQcl.3413a182f1e5bd0de09bd377e91be649, i32 36)
  %44 = call i1 @_FortranAioOutputInteger128(ptr %43, i128 %.09.lcssa)
  %45 = call i32 @_FortranAioEndIoStatement(ptr %43)
  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 @_FortranAioOutputInteger32(ptr, i32) local_unnamed_addr

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

declare i1 @_FortranAioOutputInteger128(ptr, i128) local_unnamed_addr

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