#define NULL ((void *)0)
typedef unsigned long size_t; // Customize by platform.
typedef long intptr_t;
typedef unsigned long uintptr_t;
typedef long scalar_t__; // Either arithmetic or pointer type.
/* By default, we understand bool (as a convenience). */
typedef int bool;
#define false 0
#define true 1

/* Forward declarations */

/* Type definitions */

/* Variables and functions */
scalar_t__ magic(int *, int);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ scanf(char *, int *);
int main() {
  int size, i, i2;
  do {
    scanf("%d", &size);
  } while (size < 1 || size > 999);
  int sq[size * size];
  for (i2 = size - 1; i2 >= 0; i2--) {
    for (i = 0; i < size; i++) {
      scanf("%d", &sq[i + i2 * size]);
    }
  }
  if (magic(sq, size))
    printf("MAGIC");
  else
    printf("NO MAGIC");
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xeba(%rip),%rdi
lea    -0x8(%rbp),%rsi
call   1050 <scanf@plt>
mov    $0x1,%al
cmpl   $0x1,-0x8(%rbp)
mov    %al,-0x21(%rbp)
jl     116b <main+0x3b>
cmpl   $0x3e7,-0x8(%rbp)
setg   %al
mov    %al,-0x21(%rbp)
mov    -0x21(%rbp),%al
test   $0x1,%al
jne    113f <main+0xf>
mov    -0x8(%rbp),%eax
imul   %eax,%eax
mov    %rsp,%rcx
mov    %rcx,-0x18(%rbp)
lea    0xf(,%rax,4),%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x30(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x20(%rbp)
mov    -0x8(%rbp),%eax
sub    $0x1,%eax
mov    %eax,-0x10(%rbp)
cmpl   $0x0,-0x10(%rbp)
jl     120c <main+0xdc>
movl   $0x0,-0xc(%rbp)
mov    -0xc(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    11f9 <main+0xc9>
mov    -0x30(%rbp),%rsi
mov    -0xc(%rbp),%eax
mov    -0x10(%rbp),%ecx
imul   -0x8(%rbp),%ecx
add    %ecx,%eax
cltq
shl    $0x2,%rax
add    %rax,%rsi
lea    0xe1a(%rip),%rdi
call   1050 <scanf@plt>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    11ba <main+0x8a>
jmp    11fe <main+0xce>
mov    -0x10(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x10(%rbp)
jmp    11a9 <main+0x79>
mov    -0x30(%rbp),%rdi
mov    -0x8(%rbp),%esi
call   1030 <magic@plt>
cmp    $0x0,%rax
je     1233 <main+0x103>
lea    0xddd(%rip),%rdi
call   1040 <printf@plt>
jmp    123f <main+0x10f>
lea    0xdc9(%rip),%rdi
call   1040 <printf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,%rsp
mov    -0x4(%rbp),%eax
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
lea    0xeb8(%rip),%r14
lea    -0x2c(%rbp),%rbx
nopl   0x0(%rax)
mov    %r14,%rdi
mov    %rbx,%rsi
call   1050 <scanf@plt>
mov    -0x2c(%rbp),%eax
lea    -0x3e8(%rax),%ecx
cmp    $0xfffffc19,%ecx
jb     1150 <main+0x20>
mov    %rsp,-0x38(%rbp)
imul   %rax,%rax
mov    %rsp,%r12
lea    0xf(,%rax,4),%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%r12
mov    %r12,%rsp
mov    -0x2c(%rbp),%esi
test   %esi,%esi
jle    11e3 <main+0xb3>
lea    -0x1(%rsi),%ebx
lea    0xe66(%rip),%r14
mov    %esi,%r13d
jmp    11b0 <main+0x80>
nop
lea    -0x1(%r13),%eax
add    $0xffffffff,%ebx
cmp    $0x2,%r13d
mov    %eax,%r13d
jl     11e3 <main+0xb3>
test   %esi,%esi
jle    11a0 <main+0x70>
xor    %r15d,%r15d
nopw   0x0(%rax,%rax,1)
imul   %ebx,%esi
movslq %esi,%rax
add    %r15,%rax
lea    (%r12,%rax,4),%rsi
mov    %r14,%rdi
call   1050 <scanf@plt>
mov    -0x2c(%rbp),%esi
add    $0x1,%r15
cmp    %esi,%r15d
jl     11c0 <main+0x90>
jmp    11a0 <main+0x70>
mov    %r12,%rdi
call   1030 <magic@plt>
test   %rax,%rax
lea    0xe0e(%rip),%rax
lea    0xe0a(%rip),%rdi
cmove  %rax,%rdi
call   1040 <printf@plt>
mov    -0x38(%rbp),%rsp
xor    %eax,%eax
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [3 x i8] c"%d\00"
@.str.1 = [6 x i8] c"MAGIC\00"
@.str.2 = [9 x i8] c"NO MAGIC\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i64
store i32 0, i32* %1
br label %7
7: ; preds = %15, %0
%8 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %2)
br label %9
9: ; preds = %7
%10 = load i32, i32* %2
%11 = icmp slt i32 %10, 1
br i1 %11, label %15, label %12
12: ; preds = %9
%13 = load i32, i32* %2
%14 = icmp sgt i32 %13, 999
br label %15
15: ; preds = %12, %9
%16 = phi i1 [ true, %9 ], [ %14, %12 ]
br i1 %16, label %7, label %17
17: ; preds = %15
%18 = load i32, i32* %2
%19 = load i32, i32* %2
%20 = mul nsw i32 %18, %19
%21 = zext i32 %20 to i64
%22 = call i8* @llvm.stacksave()
store i8* %22, i8** %5
%23 = alloca i32, i64 %21
store i64 %21, i64* %6
%24 = load i32, i32* %2
%25 = sub nsw i32 %24, 1
store i32 %25, i32* %4
br label %26
26: ; preds = %47, %17
%27 = load i32, i32* %4
%28 = icmp sge i32 %27, 0
br i1 %28, label %29, label %50
29: ; preds = %26
store i32 0, i32* %3
br label %30
30: ; preds = %43, %29
%31 = load i32, i32* %3
%32 = load i32, i32* %2
%33 = icmp slt i32 %31, %32
br i1 %33, label %34, label %46
34: ; preds = %30
%35 = load i32, i32* %3
%36 = load i32, i32* %4
%37 = load i32, i32* %2
%38 = mul nsw i32 %36, %37
%39 = add nsw i32 %35, %38
%40 = sext i32 %39 to i64
%41 = getelementptr inbounds i32, i32* %23, i64 %40
%42 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %41)
br label %43
43: ; preds = %34
%44 = load i32, i32* %3
%45 = add nsw i32 %44, 1
store i32 %45, i32* %3
br label %30
46: ; preds = %30
br label %47
47: ; preds = %46
%48 = load i32, i32* %4
%49 = add nsw i32 %48, -1
store i32 %49, i32* %4
br label %26
50: ; preds = %26
%51 = load i32, i32* %2
%52 = call i64 @magic(i32* %23, i32 %51)
%53 = icmp ne i64 %52, 0
br i1 %53, label %54, label %56
54: ; preds = %50
%55 = call i32 @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0))
br label %58
56: ; preds = %50
%57 = call i32 @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0))
br label %58
58: ; preds = %56, %54
store i32 0, i32* %1
%59 = load i8*, i8** %5
%60 = load i32, i32* %1
ret i32 %60
}

LLVM IR (-O2):
@.str = [3 x i8] c"%d\00"
@.str.1 = [6 x i8] c"MAGIC\00"
@.str.2 = [9 x i8] c"NO MAGIC\00"
define i32 @main() {
%1 = alloca i32
%2 = bitcast i32* %1 to i8*
br label %3
3: ; preds = %3, %0
%4 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %1)
%5 = load i32, i32* %1
%6 = add i32 %5, -1000
%7 = icmp ult i32 %6, -999
br i1 %7, label %3, label %8
8: ; preds = %3
%9 = mul nuw nsw i32 %5, %5
%10 = zext i32 %9 to i64
%11 = call i8* @llvm.stacksave()
%12 = alloca i32, i64 %10
%13 = load i32, i32* %1
%14 = icmp sgt i32 %13, 0
br i1 %14, label %18, label %34
15: ; preds = %23, %18
%16 = phi i32 [ %19, %18 ], [ %32, %23 ]
%17 = icmp sgt i32 %20, 1
br i1 %17, label %18, label %34
18: ; preds = %8, %15
%19 = phi i32 [ %16, %15 ], [ %13, %8 ]
%20 = phi i32 [ %21, %15 ], [ %13, %8 ]
%21 = add nsw i32 %20, -1
%22 = icmp sgt i32 %19, 0
br i1 %22, label %23, label %15
23: ; preds = %18, %23
%24 = phi i32 [ %32, %23 ], [ %19, %18 ]
%25 = phi i32 [ %31, %23 ], [ 0, %18 ]
%26 = mul nsw i32 %24, %21
%27 = add nsw i32 %26, %25
%28 = sext i32 %27 to i64
%29 = getelementptr inbounds i32, i32* %12, i64 %28
%30 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %29)
%31 = add nuw nsw i32 %25, 1
%32 = load i32, i32* %1
%33 = icmp slt i32 %31, %32
br i1 %33, label %23, label %15
34: ; preds = %15, %8
%35 = phi i32 [ %13, %8 ], [ %16, %15 ]
%36 = call i64 @magic(i32* %12, i32 %35)
%37 = icmp eq i64 %36, 0
%38 = select i1 %37, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0)
%39 = call i32 @printf(i8* dereferenceable(1) %38)
ret i32 0
}