#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 */
int magicBaDka(int **, int);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ scanf(char *, int *);
int main() {
  int i1, i2, n;
  do {
    scanf("%d", &n);
  } while (n < 1 || n > 999);
  int madafakinsquare[999][999];
  for (i1 = 0; i1 < n; i1++) {
    for (i2 = 0; i2 < n; i2++) {
      scanf("%d", &madafakinsquare[i1][i2]);
    }
  }
  if (magicBaDka(madafakinsquare, n) == 505)
    printf("MAGIC\n");
  else
    printf("NO 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
call   1050 <scanf@plt>
mov    $0x1,%al
cmpl   $0x1,-0x10(%rbp)
mov    %al,-0x3ce9e1(%rbp)
jl     1174 <main+0x44>
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),%rax
lea    -0x3ce9e0(%rbp),%rsi
imul   $0xf9c,%rax,%rax
add    %rax,%rsi
movslq -0xc(%rbp),%rax
shl    $0x2,%rax
add    %rax,%rsi
lea    0xe31(%rip),%rdi
call   1050 <scanf@plt>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    119c <main+0x6c>
jmp    11e7 <main+0xb7>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    1189 <main+0x59>
lea    -0x3ce9e0(%rbp),%rdi
mov    -0x10(%rbp),%esi
call   1040 <magicBaDka@plt>
cmp    $0x1f9,%eax
jne    1220 <main+0xf0>
lea    0xdf0(%rip),%rdi
call   1030 <printf@plt>
jmp    122c <main+0xfc>
lea    0xddc(%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   %r13
push   %r12
push   %rbx
sub    $0x3ce9e0,%rsp
lea    0xeb9(%rip),%r14
lea    0xc(%rsp),%rbx
nopl   0x0(%rax)
mov    %r14,%rdi
mov    %rbx,%rsi
call   1050 <scanf@plt>
mov    0xc(%rsp),%esi
lea    -0x3e8(%rsi),%eax
cmp    $0xfffffc19,%eax
jb     1150 <main+0x20>
lea    0x10(%rsp),%r15
xor    %r12d,%r12d
lea    0xe85(%rip),%r14
jmp    1193 <main+0x63>
nopl   (%rax)
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   1050 <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   1040 <magicBaDka@plt>
cmp    $0x1f9,%eax
lea    0xe31(%rip),%rax
lea    0xe27(%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 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 @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, 1
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 = %38, %16
%18 = load i32, i32* %2
%19 = load i32, i32* %4
%20 = icmp slt i32 %18, %19
br i1 %20, label %21, label %41
21: ; preds = %17
store i32 0, i32* %3
br label %22
22: ; preds = %34, %21
%23 = load i32, i32* %3
%24 = load i32, i32* %4
%25 = icmp slt i32 %23, %24
br i1 %25, label %26, label %37
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 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %32)
br label %34
34: ; preds = %26
%35 = load i32, i32* %3
%36 = add nsw i32 %35, 1
store i32 %36, i32* %3
br label %22
37: ; preds = %22
br label %38
38: ; preds = %37
%39 = load i32, i32* %2
%40 = add nsw i32 %39, 1
store i32 %40, i32* %2
br label %17
41: ; preds = %17
%42 = getelementptr inbounds [999 x [999 x i32]], [999 x [999 x i32]]* %5, i64 0, i64 0
%43 = bitcast [999 x i32]* %42 to i32**
%44 = load i32, i32* %4
%45 = call i32 @magicBaDka(i32** %43, i32 %44)
%46 = icmp eq i32 %45, 505
br i1 %46, label %47, label %49
47: ; preds = %41
%48 = call i32 @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
br label %51
49: ; preds = %41
%50 = call i32 @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0))
br label %51
51: ; preds = %49, %47
ret i32 0
}

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*
br label %4
4: ; preds = %4, %0
%5 = call i32 @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, -999
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, %23
%12 = phi i32 [ %6, %9 ], [ %24, %23 ]
%13 = phi i64 [ 0, %9 ], [ %26, %23 ]
%14 = icmp sgt i32 %12, 0
br i1 %14, label %15, label %23
15: ; preds = %11, %15
%16 = phi i64 [ %19, %15 ], [ 0, %11 ]
%17 = getelementptr inbounds [999 x [999 x i32]], [999 x [999 x i32]]* %2, i64 0, i64 %13, i64 %16
%18 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %17)
%19 = add nuw nsw i64 %16, 1
%20 = load i32, i32* %1
%21 = sext i32 %20 to i64
%22 = icmp slt i64 %19, %21
br i1 %22, label %15, label %23
23: ; preds = %15, %11
%24 = phi i32 [ %12, %11 ], [ %20, %15 ]
%25 = sext i32 %24 to i64
%26 = add nuw nsw i64 %13, 1
%27 = icmp slt i64 %26, %25
br i1 %27, label %11, label %28
28: ; preds = %23
%29 = bitcast [999 x [999 x i32]]* %2 to i32**
%30 = call i32 @magicBaDka(i32** %29, i32 %24)
%31 = icmp eq i32 %30, 505
%32 = select i1 %31, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @str.3, i64 0, i64 0), i8* getelementptr inbounds ([9 x i8], [9 x i8]* @str, i64 0, i64 0)
%33 = call i32 @puts(i8* dereferenceable(1) %32)
ret i32 0
}