#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 magic(int **, int);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ scanf(char *, int *);
int main() {
  int square[999][999];
  int length;
  int counter, v2, m;
  scanf("%d", &length);
  while (length >= 1000) {
    printf("<1000 baluk\n");
    scanf("%d", &length);
  }
  for (counter = 0; counter < length; counter++) {
    for (v2 = 0; v2 < length; v2++) {
      scanf("%d", &square[counter][v2]);
    }
  }
  m = magic(square, length);
  if (m) {
    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    -0x3ce9d4(%rbp),%rsi
call   1050 <scanf@plt>
cmpl   $0x3e8,-0x3ce9d4(%rbp)
jl     1189 <main+0x59>
lea    0xe97(%rip),%rdi
call   1040 <printf@plt>
lea    0xe88(%rip),%rdi
lea    -0x3ce9d4(%rbp),%rsi
call   1050 <scanf@plt>
jmp    1155 <main+0x25>
movl   $0x0,-0x3ce9d8(%rbp)
mov    -0x3ce9d8(%rbp),%eax
cmp    -0x3ce9d4(%rbp),%eax
jge    1220 <main+0xf0>
movl   $0x0,-0x3ce9dc(%rbp)
mov    -0x3ce9dc(%rbp),%eax
cmp    -0x3ce9d4(%rbp),%eax
jge    1207 <main+0xd7>
movslq -0x3ce9d8(%rbp),%rax
lea    -0x3ce9d0(%rbp),%rsi
imul   $0xf9c,%rax,%rax
add    %rax,%rsi
movslq -0x3ce9dc(%rbp),%rax
shl    $0x2,%rax
add    %rax,%rsi
lea    0xe12(%rip),%rdi
call   1050 <scanf@plt>
mov    -0x3ce9dc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x3ce9dc(%rbp)
jmp    11af <main+0x7f>
jmp    120c <main+0xdc>
mov    -0x3ce9d8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x3ce9d8(%rbp)
jmp    1193 <main+0x63>
lea    -0x3ce9d0(%rbp),%rdi
mov    -0x3ce9d4(%rbp),%esi
call   1030 <magic@plt>
mov    %eax,-0x3ce9e0(%rbp)
cmpl   $0x0,-0x3ce9e0(%rbp)
je     1256 <main+0x126>
lea    0xdc7(%rip),%rdi
call   1040 <printf@plt>
jmp    1262 <main+0x132>
lea    0xdb3(%rip),%rdi
call   1040 <printf@plt>
xor    %eax,%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   1050 <scanf@plt>
mov    0xc(%rsp),%esi
cmp    $0x3e8,%esi
jl     118f <main+0x5f>
lea    0xea8(%rip),%r14
lea    0xe95(%rip),%r15
lea    0xc(%rsp),%rbx
mov    %r14,%rdi
call   1040 <puts@plt>
mov    %r15,%rdi
mov    %rbx,%rsi
call   1050 <scanf@plt>
mov    0xc(%rsp),%esi
cmp    $0x3e7,%esi
jg     1170 <main+0x40>
test   %esi,%esi
jle    11ef <main+0xbf>
lea    0x10(%rsp),%r15
xor    %r12d,%r12d
lea    0xe5e(%rip),%r14
jmp    11c3 <main+0x93>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
movslq %esi,%rax
add    $0x1,%r12
add    $0xf9c,%r15
cmp    %rax,%r12
jge    11ef <main+0xbf>
test   %esi,%esi
jle    11b0 <main+0x80>
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     11d0 <main+0xa0>
jmp    11b0 <main+0x80>
lea    0x10(%rsp),%rdi
call   1030 <magic@plt>
test   %eax,%eax
lea    0xe01(%rip),%rax
lea    0xdfd(%rip),%rdi
cmove  %rax,%rdi
call   1040 <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 = [13 x i8] c"<1000 baluk\0A\00"
@.str.2 = [7 x i8] c"MAGIC\0A\00"
@.str.3 = [10 x i8] c"NO MAGIC\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [999 x [999 x i32]]
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
store i32 0, i32* %1
%7 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %3)
br label %8
8: ; preds = %11, %0
%9 = load i32, i32* %3
%10 = icmp sge i32 %9, 1000
br i1 %10, label %11, label %14
11: ; preds = %8
%12 = call i32 @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0))
%13 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %3)
br label %8
14: ; preds = %8
store i32 0, i32* %4
br label %15
15: ; preds = %36, %14
%16 = load i32, i32* %4
%17 = load i32, i32* %3
%18 = icmp slt i32 %16, %17
br i1 %18, label %19, label %39
19: ; preds = %15
store i32 0, i32* %5
br label %20
20: ; preds = %32, %19
%21 = load i32, i32* %5
%22 = load i32, i32* %3
%23 = icmp slt i32 %21, %22
br i1 %23, label %24, label %35
24: ; preds = %20
%25 = load i32, i32* %4
%26 = sext i32 %25 to i64
%27 = getelementptr inbounds [999 x [999 x i32]], [999 x [999 x i32]]* %2, i64 0, i64 %26
%28 = load i32, i32* %5
%29 = sext i32 %28 to i64
%30 = getelementptr inbounds [999 x i32], [999 x i32]* %27, i64 0, i64 %29
%31 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %30)
br label %32
32: ; preds = %24
%33 = load i32, i32* %5
%34 = add nsw i32 %33, 1
store i32 %34, i32* %5
br label %20
35: ; preds = %20
br label %36
36: ; preds = %35
%37 = load i32, i32* %4
%38 = add nsw i32 %37, 1
store i32 %38, i32* %4
br label %15
39: ; preds = %15
%40 = getelementptr inbounds [999 x [999 x i32]], [999 x [999 x i32]]* %2, i64 0, i64 0
%41 = bitcast [999 x i32]* %40 to i32**
%42 = load i32, i32* %3
%43 = call i32 @magic(i32** %41, i32 %42)
store i32 %43, i32* %6
%44 = load i32, i32* %6
%45 = icmp ne i32 %44, 0
br i1 %45, label %46, label %48
46: ; preds = %39
%47 = call i32 @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0))
br label %50
48: ; preds = %39
%49 = call i32 @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.3, i64 0, i64 0))
br label %50
50: ; preds = %48, %46
ret i32 0
}

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