#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 IsNoRepeat(int **);
int IsSameColumnSum(int **);
int IsSameDiagonalSum(int **);
int IsSameRowSum(int **);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ scanf(char *, int *);
int main() {
  int n;
  printf("Please input an integer n:\n");
  scanf("%d", &n);
  int a[n][n];
  printf("Please input the elements of the nxn matrix:\n");
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++)
      scanf("%d", &a[i][j]);
  }
  if (IsNoRepeat(a) == 1 && IsSameDiagonalSum(a) == 1 &&
      IsSameColumnSum(a) == 1 && IsSameRowSum(a) == 1)
    printf("It's a magic square.\n");
  else
    printf("It's not a magic square.\n");
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xe8a(%rip),%rdi
call   1050 <printf@plt>
lea    0xe9a(%rip),%rdi
lea    -0x8(%rbp),%rsi
call   1080 <scanf@plt>
mov    -0x8(%rbp),%eax
mov    %eax,%ecx
mov    %rcx,%rax
mov    %rax,-0x38(%rbp)
mov    %rsp,%rdx
mov    %rdx,-0x10(%rbp)
mov    %rcx,%rdx
imul   %rdx,%rdx
lea    0xf(,%rdx,4),%rsi
and    $0xfffffffffffffff0,%rsi
mov    %rsp,%rdx
sub    %rsi,%rdx
mov    %rdx,-0x30(%rbp)
mov    %rdx,%rsp
mov    %rcx,-0x18(%rbp)
mov    %rax,-0x20(%rbp)
lea    0xe52(%rip),%rdi
call   1050 <printf@plt>
movl   $0x0,-0x24(%rbp)
mov    -0x24(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    1247 <main+0xe7>
movl   $0x0,-0x28(%rbp)
mov    -0x28(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    1234 <main+0xd4>
mov    -0x30(%rbp),%rsi
mov    -0x38(%rbp),%rcx
movslq -0x24(%rbp),%rax
imul   %rcx,%rax
shl    $0x2,%rax
add    %rax,%rsi
movslq -0x28(%rbp),%rax
shl    $0x2,%rax
add    %rax,%rsi
lea    0xdfb(%rip),%rdi
call   1080 <scanf@plt>
mov    -0x28(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x28(%rbp)
jmp    11ec <main+0x8c>
jmp    1239 <main+0xd9>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    11d9 <main+0x79>
mov    -0x30(%rbp),%rdi
call   1070 <IsNoRepeat@plt>
cmp    $0x1,%eax
jne    12a0 <main+0x140>
mov    -0x30(%rbp),%rdi
call   1060 <IsSameDiagonalSum@plt>
cmp    $0x1,%eax
jne    12a0 <main+0x140>
mov    -0x30(%rbp),%rdi
call   1030 <IsSameColumnSum@plt>
cmp    $0x1,%eax
jne    12a0 <main+0x140>
mov    -0x30(%rbp),%rdi
call   1040 <IsSameRowSum@plt>
cmp    $0x1,%eax
jne    12a0 <main+0x140>
lea    0xdb7(%rip),%rdi
call   1050 <printf@plt>
jmp    12ac <main+0x14c>
lea    0xdbc(%rip),%rdi
call   1050 <printf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x10(%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    $0x28,%rsp
lea    0xe8b(%rip),%rdi
call   1030 <puts@plt>
lea    0xe7c(%rip),%rdi
lea    -0x2c(%rbp),%rsi
call   1080 <scanf@plt>
mov    %rsp,-0x48(%rbp)
mov    -0x2c(%rbp),%eax
mov    %rax,-0x40(%rbp)
imul   %rax,%rax
mov    %rsp,%rcx
lea    0xf(,%rax,4),%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%rcx
mov    %rcx,-0x38(%rbp)
mov    %rcx,%rsp
lea    0xe62(%rip),%rdi
call   1030 <puts@plt>
mov    -0x2c(%rbp),%eax
test   %eax,%eax
jle    121e <main+0xbe>
shlq   $0x2,-0x40(%rbp)
xor    %r12d,%r12d
lea    0xe29(%rip),%r15
mov    -0x38(%rbp),%r14
jmp    11f0 <main+0x90>
nopl   (%rax)
movslq %eax,%rcx
add    $0x1,%r12
add    -0x40(%rbp),%r14
cmp    %rcx,%r12
jge    121e <main+0xbe>
test   %eax,%eax
jle    11e0 <main+0x80>
mov    %r14,%rbx
xor    %r13d,%r13d
nopw   0x0(%rax,%rax,1)
mov    %r15,%rdi
mov    %rbx,%rsi
call   1080 <scanf@plt>
add    $0x1,%r13
movslq -0x2c(%rbp),%rax
add    $0x4,%rbx
cmp    %rax,%r13
jl     1200 <main+0xa0>
jmp    11e0 <main+0x80>
mov    -0x38(%rbp),%rbx
mov    %rbx,%rdi
call   1070 <IsNoRepeat@plt>
cmp    $0x1,%eax
jne    125f <main+0xff>
mov    %rbx,%rdi
call   1060 <IsSameDiagonalSum@plt>
cmp    $0x1,%eax
jne    125f <main+0xff>
mov    %rbx,%rdi
call   1040 <IsSameColumnSum@plt>
cmp    $0x1,%eax
jne    125f <main+0xff>
mov    %rbx,%rdi
call   1050 <IsSameRowSum@plt>
cmp    $0x1,%eax
jne    125f <main+0xff>
lea    0xe07(%rip),%rdi
jmp    1266 <main+0x106>
lea    0xde5(%rip),%rdi
call   1030 <puts@plt>
mov    -0x48(%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 = [28 x i8] c"Please input an integer n:\0A\00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [46 x i8] c"Please input the elements of the nxn matrix:\0A\00"
@.str.3 = [22 x i8] c"It's a magic square.\0A\00"
@.str.4 = [26 x i8] c"It's not a magic square.\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i64
%5 = alloca i64
%6 = alloca i32
%7 = alloca i32
store i32 0, i32* %1
%8 = call i32 @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str, i64 0, i64 0))
%9 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %2)
%10 = load i32, i32* %2
%11 = zext i32 %10 to i64
%12 = load i32, i32* %2
%13 = zext i32 %12 to i64
%14 = call i8* @llvm.stacksave()
store i8* %14, i8** %3
%15 = mul nuw i64 %11, %13
%16 = alloca i32, i64 %15
store i64 %11, i64* %4
store i64 %13, i64* %5
%17 = call i32 @printf(i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str.2, i64 0, i64 0))
store i32 0, i32* %6
br label %18
18: ; preds = %40, %0
%19 = load i32, i32* %6
%20 = load i32, i32* %2
%21 = icmp slt i32 %19, %20
br i1 %21, label %22, label %43
22: ; preds = %18
store i32 0, i32* %7
br label %23
23: ; preds = %36, %22
%24 = load i32, i32* %7
%25 = load i32, i32* %2
%26 = icmp slt i32 %24, %25
br i1 %26, label %27, label %39
27: ; preds = %23
%28 = load i32, i32* %6
%29 = sext i32 %28 to i64
%30 = mul nsw i64 %29, %13
%31 = getelementptr inbounds i32, i32* %16, i64 %30
%32 = load i32, i32* %7
%33 = sext i32 %32 to i64
%34 = getelementptr inbounds i32, i32* %31, i64 %33
%35 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %34)
br label %36
36: ; preds = %27
%37 = load i32, i32* %7
%38 = add nsw i32 %37, 1
store i32 %38, i32* %7
br label %23
39: ; preds = %23
br label %40
40: ; preds = %39
%41 = load i32, i32* %6
%42 = add nsw i32 %41, 1
store i32 %42, i32* %6
br label %18
43: ; preds = %18
%44 = bitcast i32* %16 to i32**
%45 = call i32 @IsNoRepeat(i32** %44)
%46 = icmp eq i32 %45, 1
br i1 %46, label %47, label %61
47: ; preds = %43
%48 = bitcast i32* %16 to i32**
%49 = call i32 @IsSameDiagonalSum(i32** %48)
%50 = icmp eq i32 %49, 1
br i1 %50, label %51, label %61
51: ; preds = %47
%52 = bitcast i32* %16 to i32**
%53 = call i32 @IsSameColumnSum(i32** %52)
%54 = icmp eq i32 %53, 1
br i1 %54, label %55, label %61
55: ; preds = %51
%56 = bitcast i32* %16 to i32**
%57 = call i32 @IsSameRowSum(i32** %56)
%58 = icmp eq i32 %57, 1
br i1 %58, label %59, label %61
59: ; preds = %55
%60 = call i32 @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.3, i64 0, i64 0))
br label %63
61: ; preds = %55, %51, %47, %43
%62 = call i32 @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.4, i64 0, i64 0))
br label %63
63: ; preds = %61, %59
store i32 0, i32* %1
%64 = load i8*, i8** %3
%65 = load i32, i32* %1
ret i32 %65
}

LLVM IR (-O2):
@.str.1 = [3 x i8] c"%d\00"
@str = [27 x i8] c"Please input an integer n:\00"
@str.5 = [45 x i8] c"Please input the elements of the nxn matrix:\00"
@str.6 = [25 x i8] c"It's not a magic square.\00"
@str.7 = [21 x i8] c"It's a magic square.\00"
define i32 @main() {
%1 = alloca i32
%2 = bitcast i32* %1 to i8*
%3 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @str, i64 0, i64 0))
%4 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %1)
%5 = load i32, i32* %1
%6 = zext i32 %5 to i64
%7 = call i8* @llvm.stacksave()
%8 = mul nuw i64 %6, %6
%9 = alloca i32, i64 %8
%10 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([45 x i8], [45 x i8]* @str.5, i64 0, i64 0))
%11 = load i32, i32* %1
%12 = icmp sgt i32 %11, 0
br i1 %12, label %13, label %20
13: ; preds = %0, %24
%14 = phi i32 [ %25, %24 ], [ %11, %0 ]
%15 = phi i64 [ %27, %24 ], [ 0, %0 ]
%16 = icmp sgt i32 %14, 0
br i1 %16, label %17, label %24
17: ; preds = %13
%18 = mul nuw nsw i64 %15, %6
%19 = getelementptr inbounds i32, i32* %9, i64 %18
br label %29
20: ; preds = %24, %0
%21 = bitcast i32* %9 to i32**
%22 = call i32 @IsNoRepeat(i32** %21)
%23 = icmp eq i32 %22, 1
br i1 %23, label %37, label %46
24: ; preds = %29, %13
%25 = phi i32 [ %14, %13 ], [ %34, %29 ]
%26 = sext i32 %25 to i64
%27 = add nuw nsw i64 %15, 1
%28 = icmp slt i64 %27, %26
br i1 %28, label %13, label %20
29: ; preds = %17, %29
%30 = phi i64 [ 0, %17 ], [ %33, %29 ]
%31 = getelementptr inbounds i32, i32* %19, i64 %30
%32 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %31)
%33 = add nuw nsw i64 %30, 1
%34 = load i32, i32* %1
%35 = sext i32 %34 to i64
%36 = icmp slt i64 %33, %35
br i1 %36, label %29, label %24
37: ; preds = %20
%38 = call i32 @IsSameDiagonalSum(i32** %21)
%39 = icmp eq i32 %38, 1
br i1 %39, label %40, label %46
40: ; preds = %37
%41 = call i32 @IsSameColumnSum(i32** %21)
%42 = icmp eq i32 %41, 1
br i1 %42, label %43, label %46
43: ; preds = %40
%44 = call i32 @IsSameRowSum(i32** %21)
%45 = icmp eq i32 %44, 1
br i1 %45, label %47, label %46
46: ; preds = %43, %40, %37, %20
br label %47
47: ; preds = %43, %46
%48 = phi i8* [ getelementptr inbounds ([25 x i8], [25 x i8]* @str.6, i64 0, i64 0), %46 ], [ getelementptr inbounds ([21 x i8], [21 x i8]* @str.7, i64 0, i64 0), %43 ]
%49 = call i32 @puts(i8* dereferenceable(1) %48)
ret i32 0
}