program main
      implicit none
      integer :: k, i, j
      integer(16) :: qu(10000000)

      read *, k
      qu(:) = 0
      j = 0
      do i = 1, 9
        j = j + 1
        qu(j) = i
      end do
      do i = 1, k
        if ( mod(qu(i),10) /= 0 ) then
          j = j + 1
          qu(j) = 10 * qu(i) + mod(qu(i),10) - 1
        end if
        j = j + 1
        qu(j) = 10 * qu(i) + mod(qu(i),10)
        if ( mod(qu(i),10) /= 9 ) then
          j = j + 1
          qu(j) = 10 * qu(i) + mod(qu(i),10) + 1
        end if
      end do
      print *, qu(k)
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"

@_QFEqu = internal unnamed_addr global [10000000 x i128] undef
@_QQcl.4428d94f2e8f0856bed21e763e3012c3 = linkonce constant [73 x i8] c"/home/ubuntu/Downloads/TheStack_IR/Collated/Fortran/Source_1903/source.f\00"
@_QQEnvironmentDefaults = local_unnamed_addr constant ptr null

define void @_QQmain() local_unnamed_addr {
.preheader.preheader:
  %0 = alloca i32, align 4
  %1 = tail call ptr @_FortranAioBeginExternalListInput(i32 -1, ptr nonnull @_QQcl.4428d94f2e8f0856bed21e763e3012c3, i32 6)
  %2 = call i1 @_FortranAioInputInteger(ptr %1, ptr nonnull %0, i32 4)
  %3 = call i32 @_FortranAioEndIoStatement(ptr %1)
  call void @llvm.memset.p0.i64(ptr noundef nonnull align 16 dereferenceable(160000000) getelementptr inbounds ([10000000 x i128], ptr @_QFEqu, i64 0, i64 9), i8 0, i64 159999856, i1 false), !tbaa !3
  store i128 1, ptr @_QFEqu, align 16, !tbaa !3
  store i128 2, ptr getelementptr inbounds ([10000000 x i128], ptr @_QFEqu, i64 0, i64 1), align 16, !tbaa !3
  store i128 3, ptr getelementptr inbounds ([10000000 x i128], ptr @_QFEqu, i64 0, i64 2), align 16, !tbaa !3
  store i128 4, ptr getelementptr inbounds ([10000000 x i128], ptr @_QFEqu, i64 0, i64 3), align 16, !tbaa !3
  store i128 5, ptr getelementptr inbounds ([10000000 x i128], ptr @_QFEqu, i64 0, i64 4), align 16, !tbaa !3
  store i128 6, ptr getelementptr inbounds ([10000000 x i128], ptr @_QFEqu, i64 0, i64 5), align 16, !tbaa !3
  store i128 7, ptr getelementptr inbounds ([10000000 x i128], ptr @_QFEqu, i64 0, i64 6), align 16, !tbaa !3
  store i128 8, ptr getelementptr inbounds ([10000000 x i128], ptr @_QFEqu, i64 0, i64 7), align 16, !tbaa !3
  store i128 9, ptr getelementptr inbounds ([10000000 x i128], ptr @_QFEqu, i64 0, i64 8), align 16, !tbaa !3
  %4 = load i32, ptr %0, align 4, !tbaa !3
  %5 = icmp sgt i32 %4, 0
  br i1 %5, label %.lr.ph.preheader, label %._crit_edge

.lr.ph.preheader:                                 ; preds = %.preheader.preheader
  %6 = zext i32 %4 to i64
  br label %.lr.ph

.lr.ph:                                           ; preds = %.lr.ph.preheader, %37
  %indvars.iv = phi i64 [ 1, %.lr.ph.preheader ], [ %indvars.iv.next, %37 ]
  %.123 = phi i32 [ 9, %.lr.ph.preheader ], [ %.3, %37 ]
  %7 = add nsw i64 %indvars.iv, -1
  %8 = getelementptr [10000000 x i128], ptr @_QFEqu, i64 0, i64 %7
  %9 = load i128, ptr %8, align 16, !tbaa !3
  %10 = srem i128 %9, 10
  %.not = icmp eq i128 %10, 0
  br i1 %.not, label %19, label %11

11:                                               ; preds = %.lr.ph
  %12 = add i32 %.123, 1
  %13 = mul i128 %9, 10
  %14 = add nsw i128 %10, -1
  %15 = add i128 %14, %13
  %16 = sext i32 %12 to i64
  %17 = add nsw i64 %16, -1
  %18 = getelementptr [10000000 x i128], ptr @_QFEqu, i64 0, i64 %17
  store i128 %15, ptr %18, align 16, !tbaa !3
  %.pre = load i128, ptr %8, align 16, !tbaa !3
  %.pre26 = srem i128 %.pre, 10
  br label %19

19:                                               ; preds = %11, %.lr.ph
  %.pre-phi = phi i128 [ %.pre26, %11 ], [ 0, %.lr.ph ]
  %20 = phi i128 [ %.pre, %11 ], [ %9, %.lr.ph ]
  %.2 = phi i32 [ %12, %11 ], [ %.123, %.lr.ph ]
  %21 = add i32 %.2, 1
  %22 = mul i128 %20, 10
  %23 = add i128 %22, %.pre-phi
  %24 = sext i32 %21 to i64
  %25 = add nsw i64 %24, -1
  %26 = getelementptr [10000000 x i128], ptr @_QFEqu, i64 0, i64 %25
  store i128 %23, ptr %26, align 16, !tbaa !3
  %27 = load i128, ptr %8, align 16, !tbaa !3
  %28 = srem i128 %27, 10
  %.not21 = icmp eq i128 %28, 9
  br i1 %.not21, label %37, label %29

29:                                               ; preds = %19
  %30 = add i32 %.2, 2
  %31 = mul i128 %27, 10
  %32 = add nsw i128 %28, 1
  %33 = add i128 %32, %31
  %34 = sext i32 %30 to i64
  %35 = add nsw i64 %34, -1
  %36 = getelementptr [10000000 x i128], ptr @_QFEqu, i64 0, i64 %35
  store i128 %33, ptr %36, align 16, !tbaa !3
  br label %37

37:                                               ; preds = %29, %19
  %.3 = phi i32 [ %30, %29 ], [ %21, %19 ]
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %exitcond.not = icmp eq i64 %indvars.iv, %6
  br i1 %exitcond.not, label %._crit_edge, label %.lr.ph

._crit_edge:                                      ; preds = %37, %.preheader.preheader
  %38 = call ptr @_FortranAioBeginExternalListOutput(i32 -1, ptr nonnull @_QQcl.4428d94f2e8f0856bed21e763e3012c3, i32 25)
  %39 = load i32, ptr %0, align 4, !tbaa !3
  %40 = sext i32 %39 to i64
  %41 = add nsw i64 %40, -1
  %42 = getelementptr [10000000 x i128], ptr @_QFEqu, i64 0, i64 %41
  %43 = load i128, ptr %42, align 16, !tbaa !3
  %44 = call i1 @_FortranAioOutputInteger128(ptr %38, i128 %43)
  %45 = call i32 @_FortranAioEndIoStatement(ptr %38)
  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 @_FortranAioOutputInteger128(ptr, i128) 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) #0

attributes #0 = { 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"}
