#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__ checkForMagic(int **, int);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ scanf(char *, int *);
int main() {
  int n;
  scanf("%d", &n);
  if (n > 999)
    return 0;
  int square[999][999];
  int i, j;
  for (i = 0; i < n; i++) {
    for (j = 0; j < n; j++) {
      scanf("%d", &square[i][j]);
    }
  }
  if (checkForMagic(square, n) != 0)
    printf("MAGIC\n");
  else
    printf("NO MAGIC\n");
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x3ce9e0,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xeb7(%rip),%rdi
lea    -0x8(%rbp),%rsi
call   1040 <scanf@plt>
cmpl   $0x3e7,-0x8(%rbp)
jle    116b <main+0x3b>
movl   $0x0,-0x4(%rbp)
jmp    1239 <main+0x109>
movl   $0x0,-0x3ce9d4(%rbp)
mov    -0x3ce9d4(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    11fc <main+0xcc>
movl   $0x0,-0x3ce9d8(%rbp)
mov    -0x3ce9d8(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    11e3 <main+0xb3>
movslq -0x3ce9d4(%rbp),%rax
lea    -0x3ce9d0(%rbp),%rsi
imul   $0xf9c,%rax,%rax
add    %rax,%rsi
movslq -0x3ce9d8(%rbp),%rax
shl    $0x2,%rax
add    %rax,%rsi
lea    0xe36(%rip),%rdi
call   1040 <scanf@plt>
mov    -0x3ce9d8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x3ce9d8(%rbp)
jmp    118e <main+0x5e>
jmp    11e8 <main+0xb8>
mov    -0x3ce9d4(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x3ce9d4(%rbp)
jmp    1175 <main+0x45>
lea    -0x3ce9d0(%rbp),%rdi
mov    -0x8(%rbp),%esi
call   1050 <checkForMagic@plt>
cmp    $0x0,%rax
je     1226 <main+0xf6>
lea    0xdea(%rip),%rdi
call   1030 <printf@plt>
jmp    1232 <main+0x102>
lea    0xdd6(%rip),%rdi
call   1030 <printf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x3ce9e0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x3ce9e0,%rsp
lea    0xeb9(%rip),%rdi
lea    0xc(%rsp),%rsi
call   1040 <scanf@plt>
mov    0xc(%rsp),%esi
cmp    $0x3e7,%esi
jg     11e3 <main+0xb3>
test   %esi,%esi
jle    11bf <main+0x8f>
lea    0x10(%rsp),%r15
xor    %r12d,%r12d
lea    0xe8c(%rip),%r14
jmp    1193 <main+0x63>
cs nopw 0x0(%rax,%rax,1)
movslq %esi,%rax
add    $0x1,%r12
add    $0xf9c,%r15
cmp    %rax,%r12
jge    11bf <main+0x8f>
test   %esi,%esi
jle    1180 <main+0x50>
mov    %r15,%r13
xor    %ebx,%ebx
nopl   0x0(%rax)
mov    %r14,%rdi
mov    %r13,%rsi
call   1040 <scanf@plt>
add    $0x1,%rbx
movslq 0xc(%rsp),%rsi
add    $0x4,%r13
cmp    %rsi,%rbx
jl     11a0 <main+0x70>
jmp    1180 <main+0x50>
lea    0x10(%rsp),%rdi
call   1050 <checkForMagic@plt>
test   %rax,%rax
lea    0xe30(%rip),%rax
lea    0xe2c(%rip),%rdi
cmove  %rax,%rdi
call   1030 <puts@plt>
xor    %eax,%eax
add    $0x3ce9e0,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

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

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