int main() {
  int x, y, n, m;
  for (scanf("%d", &n), m = y = 0; y < n; y++, printf("\n"))
    for (x = 0; x < n; x++, printf("%d ", m++ % 5 * 2 + 1))
      ;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xeca(%rip),%rdi
lea    -0x10(%rbp),%rsi
mov    $0x0,%al
call   1040 <scanf@plt>
movl   $0x0,-0xc(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0xc(%rbp),%eax
cmp    -0x10(%rbp),%eax
jge    11cb <main+0xab>
movl   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%eax
cmp    -0x10(%rbp),%eax
jge    11aa <main+0x8a>
jmp    1173 <main+0x53>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
mov    -0x14(%rbp),%eax
mov    %eax,%ecx
add    $0x1,%ecx
mov    %ecx,-0x14(%rbp)
mov    $0x5,%ecx
cltd
idiv   %ecx
mov    %edx,%esi
shl    $0x1,%esi
add    $0x1,%esi
lea    0xe65(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    1162 <main+0x42>
jmp    11af <main+0x8f>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
lea    0xe48(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    114f <main+0x2f>
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
lea    0xec2(%rip),%rdi
lea    0x4(%rsp),%rsi
xor    %eax,%eax
call   1050 <scanf@plt>
mov    0x4(%rsp),%eax
test   %eax,%eax
jle    11bb <main+0x8b>
lea    0xeaa(%rip),%r14
xor    %ebx,%ebx
xor    %r15d,%r15d
jmp    1177 <main+0x47>
add    $0x1,%r15d
mov    $0xa,%edi
call   1030 <putchar@plt>
mov    0x4(%rsp),%eax
cmp    %eax,%r15d
jge    11bb <main+0x8b>
test   %eax,%eax
jle    1160 <main+0x30>
xor    %ebp,%ebp
nopl   (%rax)
lea    (%rbx,%rbp,1),%eax
add    $0x1,%ebp
cltq
imul   $0x66666667,%rax,%rcx
mov    %rcx,%rdx
shr    $0x3f,%rdx
sar    $0x21,%rcx
add    %edx,%ecx
lea    (%rcx,%rcx,4),%ecx
sub    %ecx,%eax
lea    (%rax,%rax,1),%esi
add    $0x1,%esi
mov    %r14,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
cmp    0x4(%rsp),%ebp
jl     1180 <main+0x50>
add    %ebp,%ebx
jmp    1160 <main+0x30>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [3 x i8] c"%d\00"
@.str.1 = [4 x i8] c"%d \00"
@.str.2 = [2 x i8] c"\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
store i32 0, i32* %1
%6 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %4)
store i32 0, i32* %3
store i32 0, i32* %5
br label %7
7: ; preds = %27, %0
%8 = load i32, i32* %3
%9 = load i32, i32* %4
%10 = icmp slt i32 %8, %9
br i1 %10, label %11, label %31
11: ; preds = %7
store i32 0, i32* %2
br label %12
12: ; preds = %17, %11
%13 = load i32, i32* %2
%14 = load i32, i32* %4
%15 = icmp slt i32 %13, %14
br i1 %15, label %16, label %26
16: ; preds = %12
br label %17
17: ; preds = %16
%18 = load i32, i32* %2
%19 = add nsw i32 %18, 1
store i32 %19, i32* %2
%20 = load i32, i32* %5
%21 = add nsw i32 %20, 1
store i32 %21, i32* %5
%22 = srem i32 %20, 5
%23 = mul nsw i32 %22, 2
%24 = add nsw i32 %23, 1
%25 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %24)
br label %12
26: ; preds = %12
br label %27
27: ; preds = %26
%28 = load i32, i32* %3
%29 = add nsw i32 %28, 1
store i32 %29, i32* %3
%30 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
br label %7
31: ; preds = %7
%32 = load i32, i32* %1
ret i32 %32
}

LLVM IR (-O2):
@.str = [3 x i8] c"%d\00"
@.str.1 = [4 x i8] c"%d \00"
define i32 @main() {
%1 = alloca i32
%2 = bitcast i32* %1 to i8*
%3 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %1)
%4 = load i32, i32* %1
%5 = icmp sgt i32 %4, 0
br i1 %5, label %6, label %28
6: ; preds = %0, %22
%7 = phi i32 [ %26, %22 ], [ %4, %0 ]
%8 = phi i32 [ %23, %22 ], [ 0, %0 ]
%9 = phi i32 [ %24, %22 ], [ 0, %0 ]
%10 = icmp sgt i32 %7, 0
br i1 %10, label %11, label %22
11: ; preds = %6, %11
%12 = phi i32 [ %15, %11 ], [ %8, %6 ]
%13 = phi i32 [ %14, %11 ], [ 0, %6 ]
%14 = add nuw nsw i32 %13, 1
%15 = add nsw i32 %12, 1
%16 = srem i32 %12, 5
%17 = shl nsw i32 %16, 1
%18 = or i32 %17, 1
%19 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %18)
%20 = load i32, i32* %1
%21 = icmp slt i32 %14, %20
br i1 %21, label %11, label %22
22: ; preds = %11, %6
%23 = phi i32 [ %8, %6 ], [ %15, %11 ]
%24 = add nuw nsw i32 %9, 1
%25 = call i32 @putchar(i32 10)
%26 = load i32, i32* %1
%27 = icmp slt i32 %24, %26
br i1 %27, label %6, label %28
28: ; preds = %22, %0
ret i32 0
}