program main
  implicit none
  integer :: h,w,i,j
  integer,allocatable :: x(:,:) 
  character(50) :: s,t
  character :: a

  read(*,*) h,w
  allocate(x(0:h+1,0:w+1))
  x(:,:)=0
  
  do i=1,h
     read(*,*) s

     do j=1,w
        if(s(j:j)=='#')then
           x(i,j)=-10
           x(i,j+1)=x(i,j+1)+1
           x(i,j-1)=x(i,j-1)+1
           x(i-1,j)=x(i-1,j)+1
           x(i-1,j+1)=x(i-1,j+1)+1
           x(i-1,j-1)=x(i-1,j-1)+1
           x(i+1,j)=x(i+1,j)+1
           x(i+1,j+1)=x(i+1,j+1)+1
           x(i+1,j-1)=x(i+1,j-1)+1
        endif
     enddo
  enddo
  
  do i=1,h
     t='0'
     do j=1,w
        if(x(i,j)<0)then
           t(j:j)='#'
        else
           write(a,'(i1)') x(i,j)
           t(j:j)=a
        endif
     enddo
     write(*,*) t
  enddo

end program main
        
        

     

  


; 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"

@_QFEs = internal global [50 x i8] undef
@_QFEt = internal global [50 x i8] undef
@_QFEx.0 = internal unnamed_addr global ptr null
@_QFEx.7 = internal unnamed_addr global i64 1
@_QFEx.8 = internal unnamed_addr global i64 0
@_QFEx.10 = internal unnamed_addr global i64 1
@_QQcl.c919fb5ff145c762e72f86504d7aa490 = linkonce constant [73 x i8] c"/home/ubuntu/Downloads/TheStack_IR/Collated/Fortran/Source_6823/source.f\00"
@_QQcl.23 = linkonce constant [1 x i8] c"#"
@_QQcl.30 = linkonce local_unnamed_addr constant [1 x i8] c"0"
@_QQcl.28693129 = linkonce constant [4 x i8] c"(i1)"
@_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 [1 x i8], align 1
  %2 = alloca i32, align 4
  %3 = alloca i32, align 4
  %4 = tail call ptr @_FortranAioBeginExternalListInput(i32 -1, ptr nonnull @_QQcl.c919fb5ff145c762e72f86504d7aa490, i32 8)
  %5 = call i1 @_FortranAioInputInteger(ptr %4, ptr nonnull %2, i32 4)
  %6 = call i1 @_FortranAioInputInteger(ptr %4, ptr nonnull %3, i32 4)
  %7 = call i32 @_FortranAioEndIoStatement(ptr %4)
  %8 = load i32, ptr %2, align 4, !tbaa !3
  %9 = add i32 %8, 1
  %10 = load i32, ptr %3, align 4, !tbaa !3
  %11 = add i32 %10, 1
  %12 = call i32 @llvm.smax.i32(i32 %9, i32 -1)
  %13 = sext i32 %12 to i64
  %14 = add nsw i64 %13, 1
  %15 = call i32 @llvm.smax.i32(i32 %11, i32 -1)
  %16 = sext i32 %15 to i64
  %17 = add nsw i64 %16, 1
  %18 = shl nuw nsw i64 %14, 2
  %19 = mul i64 %18, %17
  %20 = call ptr @malloc(i64 %19)
  %21 = icmp eq i64 %14, 0
  %22 = zext i1 %21 to i64
  %23 = icmp eq i64 %17, 0
  %24 = zext i1 %23 to i64
  store ptr %20, ptr @_QFEx.0, align 8, !tbaa !7
  store i64 %22, ptr @_QFEx.7, align 8, !tbaa !7
  store i64 %14, ptr @_QFEx.8, align 8, !tbaa !7
  store i64 %24, ptr @_QFEx.10, align 8, !tbaa !7
  %25 = icmp sgt i32 %11, -1
  %26 = icmp sgt i32 %9, -1
  %or.cond = select i1 %25, i1 %26, i1 false
  br i1 %or.cond, label %.preheader.us.preheader, label %._crit_edge545

.preheader.us.preheader:                          ; preds = %0
  %27 = shl nsw i64 %13, 2
  %28 = add nsw i64 %27, 4
  %29 = add nsw i64 %13, 2
  %smin = call i64 @llvm.smin.i64(i64 %14, i64 1)
  %30 = sub nuw nsw i64 %29, %smin
  %31 = shl nuw nsw i64 %30, 2
  br label %.preheader.us

.preheader.us:                                    ; preds = %.preheader.us.preheader, %.preheader.us
  %32 = phi i64 [ %36, %.preheader.us ], [ %17, %.preheader.us.preheader ]
  %33 = phi i64 [ %35, %.preheader.us ], [ 0, %.preheader.us.preheader ]
  %34 = mul i64 %28, %33
  %uglygep = getelementptr i8, ptr %20, i64 %34
  call void @llvm.memset.p0.i64(ptr align 4 %uglygep, i8 0, i64 %31, i1 false), !tbaa !3
  %35 = add nuw nsw i64 %33, 1
  %36 = add nsw i64 %32, -1
  %37 = icmp ugt i64 %32, 1
  br i1 %37, label %.preheader.us, label %._crit_edge545

._crit_edge545:                                   ; preds = %.preheader.us, %0
  %38 = icmp sgt i32 %8, 0
  br i1 %38, label %.lr.ph547.preheader, label %._crit_edge554

.lr.ph547.preheader:                              ; preds = %._crit_edge545
  %39 = zext i32 %8 to i64
  %40 = add nuw nsw i64 %39, 1
  br label %.lr.ph547

.lr.ph547:                                        ; preds = %.lr.ph547.preheader, %._crit_edge
  %indvars.iv557 = phi i64 [ 1, %.lr.ph547.preheader ], [ %indvars.iv.next558.pre-phi, %._crit_edge ]
  %41 = call ptr @_FortranAioBeginExternalListInput(i32 -1, ptr nonnull @_QQcl.c919fb5ff145c762e72f86504d7aa490, i32 13)
  %42 = call i1 @_FortranAioInputAscii(ptr %41, ptr nonnull @_QFEs, i64 50)
  %43 = call i32 @_FortranAioEndIoStatement(ptr %41)
  %44 = load i32, ptr %3, align 4, !tbaa !3
  %45 = icmp sgt i32 %44, 0
  br i1 %45, label %.lr.ph, label %.lr.ph547.._crit_edge_crit_edge

.lr.ph547.._crit_edge_crit_edge:                  ; preds = %.lr.ph547
  %.pre583 = add nuw nsw i64 %indvars.iv557, 1
  br label %._crit_edge

.lr.ph:                                           ; preds = %.lr.ph547
  %46 = zext i32 %44 to i64
  %47 = add nuw nsw i64 %indvars.iv557, 1
  %sext = shl i64 %47, 32
  %48 = ashr exact i64 %sext, 32
  %49 = add nuw nsw i64 %46, 1
  br label %50

50:                                               ; preds = %.lr.ph, %102
  %indvars.iv = phi i64 [ 1, %.lr.ph ], [ %indvars.iv.next.pre-phi, %102 ]
  %51 = add nsw i64 %indvars.iv, -1
  %52 = getelementptr [50 x [1 x i8]], ptr @_QFEs, i64 0, i64 %51
  %53 = call i32 @_FortranACharacterCompareScalar1(ptr %52, ptr nonnull @_QQcl.23, i64 1, i64 1)
  %54 = icmp eq i32 %53, 0
  br i1 %54, label %55, label %._crit_edge581

._crit_edge581:                                   ; preds = %50
  %.pre582 = add nuw nsw i64 %indvars.iv, 1
  br label %102

55:                                               ; preds = %50
  %.unpack401 = load ptr, ptr @_QFEx.0, align 8, !tbaa !7
  %.unpack408.unpack.unpack = load i64, ptr @_QFEx.7, align 8, !tbaa !7
  %.unpack408.unpack.unpack411 = load i64, ptr @_QFEx.8, align 8, !tbaa !7
  %.unpack408.unpack409.unpack = load i64, ptr @_QFEx.10, align 8, !tbaa !7
  %56 = sub i64 %indvars.iv557, %.unpack408.unpack.unpack
  %57 = sub i64 %indvars.iv, %.unpack408.unpack409.unpack
  %58 = mul i64 %57, %.unpack408.unpack.unpack411
  %59 = add i64 %58, %56
  %60 = getelementptr i32, ptr %.unpack401, i64 %59
  store i32 -10, ptr %60, align 4, !tbaa !3
  %61 = add nuw nsw i64 %indvars.iv, 1
  %sext584 = shl i64 %61, 32
  %62 = ashr exact i64 %sext584, 32
  %63 = sub i64 %62, %.unpack408.unpack409.unpack
  %64 = mul i64 %63, %.unpack408.unpack.unpack411
  %65 = add i64 %64, %56
  %66 = getelementptr i32, ptr %.unpack401, i64 %65
  %67 = load i32, ptr %66, align 4, !tbaa !3
  %68 = add i32 %67, 1
  store i32 %68, ptr %66, align 4, !tbaa !3
  %69 = sub i64 %51, %.unpack408.unpack409.unpack
  %70 = mul i64 %69, %.unpack408.unpack.unpack411
  %71 = add i64 %70, %56
  %72 = getelementptr i32, ptr %.unpack401, i64 %71
  %73 = load i32, ptr %72, align 4, !tbaa !3
  %74 = add i32 %73, 1
  store i32 %74, ptr %72, align 4, !tbaa !3
  %75 = xor i64 %.unpack408.unpack.unpack, -1
  %76 = add i64 %indvars.iv557, %75
  %77 = add i64 %58, %76
  %78 = getelementptr i32, ptr %.unpack401, i64 %77
  %79 = load i32, ptr %78, align 4, !tbaa !3
  %80 = add i32 %79, 1
  store i32 %80, ptr %78, align 4, !tbaa !3
  %81 = add i64 %64, %76
  %82 = getelementptr i32, ptr %.unpack401, i64 %81
  %83 = load i32, ptr %82, align 4, !tbaa !3
  %84 = add i32 %83, 1
  store i32 %84, ptr %82, align 4, !tbaa !3
  %85 = add i64 %70, %76
  %86 = getelementptr i32, ptr %.unpack401, i64 %85
  %87 = load i32, ptr %86, align 4, !tbaa !3
  %88 = add i32 %87, 1
  store i32 %88, ptr %86, align 4, !tbaa !3
  %89 = sub i64 %48, %.unpack408.unpack.unpack
  %90 = add i64 %58, %89
  %91 = getelementptr i32, ptr %.unpack401, i64 %90
  %92 = load i32, ptr %91, align 4, !tbaa !3
  %93 = add i32 %92, 1
  store i32 %93, ptr %91, align 4, !tbaa !3
  %94 = add i64 %64, %89
  %95 = getelementptr i32, ptr %.unpack401, i64 %94
  %96 = load i32, ptr %95, align 4, !tbaa !3
  %97 = add i32 %96, 1
  store i32 %97, ptr %95, align 4, !tbaa !3
  %98 = add i64 %70, %89
  %99 = getelementptr i32, ptr %.unpack401, i64 %98
  %100 = load i32, ptr %99, align 4, !tbaa !3
  %101 = add i32 %100, 1
  store i32 %101, ptr %99, align 4, !tbaa !3
  br label %102

102:                                              ; preds = %._crit_edge581, %55
  %indvars.iv.next.pre-phi = phi i64 [ %.pre582, %._crit_edge581 ], [ %61, %55 ]
  %exitcond.not = icmp eq i64 %indvars.iv.next.pre-phi, %49
  br i1 %exitcond.not, label %._crit_edge, label %50

._crit_edge:                                      ; preds = %102, %.lr.ph547.._crit_edge_crit_edge
  %indvars.iv.next558.pre-phi = phi i64 [ %.pre583, %.lr.ph547.._crit_edge_crit_edge ], [ %47, %102 ]
  %exitcond560.not = icmp eq i64 %indvars.iv.next558.pre-phi, %40
  br i1 %exitcond560.not, label %._crit_edge548, label %.lr.ph547

._crit_edge548:                                   ; preds = %._crit_edge
  %.pre = load i32, ptr %2, align 4, !tbaa !3
  %103 = icmp sgt i32 %.pre, 0
  br i1 %103, label %.lr.ph553, label %._crit_edge554

.lr.ph553:                                        ; preds = %._crit_edge548
  %104 = zext i32 %.pre to i64
  %105 = load i8, ptr @_QQcl.30, align 1
  %106 = load i8, ptr @_QQcl.23, align 1
  br label %107

107:                                              ; preds = %.lr.ph553, %._crit_edge551
  %indvars.iv565 = phi i64 [ 1, %.lr.ph553 ], [ %indvars.iv.next566, %._crit_edge551 ]
  store i8 %105, ptr @_QFEt, align 16
  call void @llvm.memset.p0.i64(ptr noundef nonnull align 1 dereferenceable(49) getelementptr inbounds ([50 x i8], ptr @_QFEt, i64 0, i64 1), i8 32, i64 49, i1 false), !tbaa !3
  %108 = load i32, ptr %3, align 4, !tbaa !3
  %109 = icmp sgt i32 %108, 0
  br i1 %109, label %.lr.ph550, label %._crit_edge551

.lr.ph550:                                        ; preds = %107
  %110 = zext i32 %108 to i64
  %.unpack.pre569 = load ptr, ptr @_QFEx.0, align 8, !tbaa !7
  %.unpack376.unpack.unpack.pre572 = load i64, ptr @_QFEx.7, align 8, !tbaa !7
  %.unpack376.unpack.unpack379.pre575 = load i64, ptr @_QFEx.8, align 8, !tbaa !7
  %.unpack376.unpack377.unpack.pre578 = load i64, ptr @_QFEx.10, align 8, !tbaa !7
  br label %111

111:                                              ; preds = %.lr.ph550, %135
  %.unpack376.unpack377.unpack = phi i64 [ %.unpack376.unpack377.unpack.pre578, %.lr.ph550 ], [ %.unpack376.unpack377.unpack579, %135 ]
  %.unpack376.unpack.unpack379 = phi i64 [ %.unpack376.unpack.unpack379.pre575, %.lr.ph550 ], [ %.unpack376.unpack.unpack379576, %135 ]
  %.unpack376.unpack.unpack = phi i64 [ %.unpack376.unpack.unpack.pre572, %.lr.ph550 ], [ %.unpack376.unpack.unpack573, %135 ]
  %.unpack = phi ptr [ %.unpack.pre569, %.lr.ph550 ], [ %.unpack570, %135 ]
  %indvars.iv561 = phi i64 [ 1, %.lr.ph550 ], [ %indvars.iv.next562, %135 ]
  %112 = sub i64 %indvars.iv565, %.unpack376.unpack.unpack
  %113 = sub i64 %indvars.iv561, %.unpack376.unpack377.unpack
  %114 = mul i64 %113, %.unpack376.unpack.unpack379
  %115 = add i64 %112, %114
  %116 = getelementptr i32, ptr %.unpack, i64 %115
  %117 = load i32, ptr %116, align 4, !tbaa !3
  %118 = icmp slt i32 %117, 0
  br i1 %118, label %119, label %122

119:                                              ; preds = %111
  %120 = add nsw i64 %indvars.iv561, -1
  %121 = getelementptr [50 x [1 x i8]], ptr @_QFEt, i64 0, i64 %120
  store i8 %106, ptr %121, align 1
  br label %135

122:                                              ; preds = %111
  %123 = call ptr @_FortranAioBeginInternalFormattedOutput(ptr nonnull %1, i64 1, ptr nonnull @_QQcl.28693129, i64 4, ptr null, ptr null, i64 0, ptr nonnull @_QQcl.c919fb5ff145c762e72f86504d7aa490, i32 36)
  %.unpack385 = load ptr, ptr @_QFEx.0, align 8, !tbaa !7
  %.unpack392.unpack.unpack = load i64, ptr @_QFEx.7, align 8, !tbaa !7
  %.unpack392.unpack.unpack395 = load i64, ptr @_QFEx.8, align 8, !tbaa !7
  %.unpack392.unpack393.unpack = load i64, ptr @_QFEx.10, align 8, !tbaa !7
  %124 = sub i64 %indvars.iv565, %.unpack392.unpack.unpack
  %125 = sub i64 %indvars.iv561, %.unpack392.unpack393.unpack
  %126 = mul i64 %125, %.unpack392.unpack.unpack395
  %127 = add i64 %124, %126
  %128 = getelementptr i32, ptr %.unpack385, i64 %127
  %129 = load i32, ptr %128, align 4, !tbaa !3
  %130 = call i1 @_FortranAioOutputInteger32(ptr %123, i32 %129)
  %131 = call i32 @_FortranAioEndIoStatement(ptr %123)
  %132 = add nsw i64 %indvars.iv561, -1
  %133 = getelementptr [50 x [1 x i8]], ptr @_QFEt, i64 0, i64 %132
  %134 = load i8, ptr %1, align 1
  store i8 %134, ptr %133, align 1
  %.unpack.pre = load ptr, ptr @_QFEx.0, align 8, !tbaa !7
  %.unpack376.unpack.unpack.pre = load i64, ptr @_QFEx.7, align 8, !tbaa !7
  %.unpack376.unpack.unpack379.pre = load i64, ptr @_QFEx.8, align 8, !tbaa !7
  %.unpack376.unpack377.unpack.pre = load i64, ptr @_QFEx.10, align 8, !tbaa !7
  br label %135

135:                                              ; preds = %122, %119
  %.unpack376.unpack377.unpack579 = phi i64 [ %.unpack376.unpack377.unpack.pre, %122 ], [ %.unpack376.unpack377.unpack, %119 ]
  %.unpack376.unpack.unpack379576 = phi i64 [ %.unpack376.unpack.unpack379.pre, %122 ], [ %.unpack376.unpack.unpack379, %119 ]
  %.unpack376.unpack.unpack573 = phi i64 [ %.unpack376.unpack.unpack.pre, %122 ], [ %.unpack376.unpack.unpack, %119 ]
  %.unpack570 = phi ptr [ %.unpack.pre, %122 ], [ %.unpack, %119 ]
  %indvars.iv.next562 = add nuw nsw i64 %indvars.iv561, 1
  %exitcond564.not = icmp eq i64 %indvars.iv561, %110
  br i1 %exitcond564.not, label %._crit_edge551, label %111

._crit_edge551:                                   ; preds = %135, %107
  %136 = call ptr @_FortranAioBeginExternalListOutput(i32 -1, ptr nonnull @_QQcl.c919fb5ff145c762e72f86504d7aa490, i32 40)
  %137 = call i1 @_FortranAioOutputAscii(ptr %136, ptr nonnull @_QFEt, i64 50)
  %138 = call i32 @_FortranAioEndIoStatement(ptr %136)
  %indvars.iv.next566 = add nuw nsw i64 %indvars.iv565, 1
  %exitcond568.not = icmp eq i64 %indvars.iv565, %104
  br i1 %exitcond568.not, label %._crit_edge554, label %107

._crit_edge554:                                   ; preds = %._crit_edge551, %._crit_edge545, %._crit_edge548
  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 @_FortranAioInputAscii(ptr, ptr, i64) local_unnamed_addr

declare i32 @_FortranACharacterCompareScalar1(ptr, ptr, i64, i64) local_unnamed_addr

declare ptr @_FortranAioBeginInternalFormattedOutput(ptr, i64, ptr, i64, ptr, ptr, i64, ptr, i32) local_unnamed_addr

declare i1 @_FortranAioOutputInteger32(ptr, i32) local_unnamed_addr

declare ptr @_FortranAioBeginExternalListOutput(i32, ptr, i32) local_unnamed_addr

declare i1 @_FortranAioOutputAscii(ptr, ptr, i64) local_unnamed_addr

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i32 @llvm.smax.i32(i32, i32) #1

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i64 @llvm.smin.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}
