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


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x3ce9f0,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xeb7(%rip),%rdi
lea    -0x10(%rbp),%rsi
mov    $0x0,%al
call   1050 <scanf@plt>
mov    $0x1,%al
cmpl   $0x3,-0x10(%rbp)
mov    %al,-0x3ce9e1(%rbp)
jl     1176 <main+0x46>
cmpl   $0x3e7,-0x10(%rbp)
setg   %al
mov    %al,-0x3ce9e1(%rbp)
mov    -0x3ce9e1(%rbp),%al
test   $0x1,%al
jne    1142 <main+0x12>
movl   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%eax
cmp    -0x10(%rbp),%eax
jge    11f5 <main+0xc5>
movl   $0x0,-0xc(%rbp)
mov    -0xc(%rbp),%eax
cmp    -0x10(%rbp),%eax
jge    11e2 <main+0xb2>
movslq -0x8(%rbp),%rcx
lea    -0x3ce9e0(%rbp),%rax
imul   $0xf9c,%rcx,%rcx
add    %rcx,%rax
movslq -0xc(%rbp),%rcx
mov    (%rax,%rcx,4),%esi
lea    0xe33(%rip),%rdi
mov    $0x0,%al
call   1050 <scanf@plt>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    119e <main+0x6e>
jmp    11e7 <main+0xb7>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    118b <main+0x5b>
lea    -0x3ce9e0(%rbp),%rdi
mov    -0x10(%rbp),%esi
call   1040 <magiic@plt>
cmp    $0x0,%rax
jne    121f <main+0xef>
lea    0xdee(%rip),%rdi
call   1030 <printf@plt>
jmp    122b <main+0xfb>
lea    0xde0(%rip),%rdi
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x3ce9f0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x3ce9d8,%rsp
lea    0xebb(%rip),%r14
lea    0xc(%rsp),%rbx
nopw   0x0(%rax,%rax,1)
mov    %r14,%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1050 <scanf@plt>
mov    0xc(%rsp),%esi
lea    -0x3e8(%rsi),%eax
cmp    $0xfffffc1b,%eax
jb     1150 <main+0x20>
lea    0x10(%rsp),%r12
lea    0xe86(%rip),%r14
xor    %r15d,%r15d
jmp    1193 <main+0x63>
nop
movslq %esi,%rax
add    $0x1,%r15
add    $0xf9c,%r12
cmp    %rax,%r15
jge    11be <main+0x8e>
test   %esi,%esi
jle    1180 <main+0x50>
xor    %ebx,%ebx
nopl   0x0(%rax)
mov    (%r12,%rbx,4),%esi
mov    %r14,%rdi
xor    %eax,%eax
call   1050 <scanf@plt>
add    $0x1,%rbx
movslq 0xc(%rsp),%rsi
cmp    %rsi,%rbx
jl     11a0 <main+0x70>
jmp    1180 <main+0x50>
lea    0x10(%rsp),%rdi
call   1040 <magiic@plt>
test   %rax,%rax
lea    0xe31(%rip),%rax
lea    0xe2d(%rip),%rdi
cmove  %rax,%rdi
call   1030 <puts@plt>
xor    %eax,%eax
add    $0x3ce9d8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

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

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