#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 /*<<< orphan*/ isMagic(int **, int);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ scanf(char *, int *);
int main() {
  int n, i = 0, j;
  do
    scanf("%d", &n);
  while (n <= 2 || n >= 10);
  int square[n][n];
  printf("Farewell!Now enter the values of you own %d by %d square:\n", n, n);
  for (; i < n; i++) {
    for (j = 0; j < n; j++) {
      scanf("%d%*c", &square[i][j]);
    }
    printf("\n");
  }
  printf("Your \"magic square\" should look like this:\n");
  for (i = 0; i < n; i++) {
    for (j = 0; j < n; j++)
      printf("\t%d ", square[i][j]);
    printf("\n");
  }
  if (!isMagic((int **)square, n))
    printf("Your square indeed is magic!\n");
  else
    printf("Sorry but your square isn't magic!\n");
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0xc(%rbp)
lea    0xeb3(%rip),%rdi
lea    -0x8(%rbp),%rsi
call   1050 <scanf@plt>
mov    $0x1,%al
cmpl   $0x2,-0x8(%rbp)
mov    %al,-0x29(%rbp)
jle    116f <main+0x3f>
cmpl   $0xa,-0x8(%rbp)
setge  %al
mov    %al,-0x29(%rbp)
mov    -0x29(%rbp),%al
test   $0x1,%al
jne    1146 <main+0x16>
mov    -0x8(%rbp),%eax
mov    %eax,%ecx
mov    %rcx,%rax
mov    %rax,-0x40(%rbp)
mov    %rsp,%rdx
mov    %rdx,-0x18(%rbp)
mov    %rcx,%rdx
imul   %rdx,%rdx
lea    0xf(,%rdx,4),%rsi
and    $0xfffffffffffffff0,%rsi
mov    %rsp,%rdx
sub    %rsi,%rdx
mov    %rdx,-0x38(%rbp)
mov    %rdx,%rsp
mov    %rcx,-0x20(%rbp)
mov    %rax,-0x28(%rbp)
mov    -0x8(%rbp),%esi
mov    -0x8(%rbp),%edx
lea    0xe41(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0xc(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    1240 <main+0x110>
movl   $0x0,-0x10(%rbp)
mov    -0x10(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    1224 <main+0xf4>
mov    -0x38(%rbp),%rsi
mov    -0x40(%rbp),%rcx
movslq -0xc(%rbp),%rax
imul   %rcx,%rax
shl    $0x2,%rax
add    %rax,%rsi
movslq -0x10(%rbp),%rax
shl    $0x2,%rax
add    %rax,%rsi
lea    0xe2d(%rip),%rdi
call   1050 <scanf@plt>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    11dc <main+0xac>
lea    0xe66(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    11c9 <main+0x99>
lea    0xdfd(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0xc(%rbp)
mov    -0xc(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    12ca <main+0x19a>
movl   $0x0,-0x10(%rbp)
mov    -0x10(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    12ae <main+0x17e>
mov    -0x38(%rbp),%rax
mov    -0x40(%rbp),%rdx
movslq -0xc(%rbp),%rcx
imul   %rdx,%rcx
shl    $0x2,%rcx
add    %rcx,%rax
movslq -0x10(%rbp),%rcx
mov    (%rax,%rcx,4),%esi
lea    0xdd7(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    1268 <main+0x138>
lea    0xddc(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    1255 <main+0x125>
mov    -0x38(%rbp),%rdi
mov    -0x8(%rbp),%esi
call   1040 <isMagic@plt>
cmp    $0x0,%eax
jne    12f2 <main+0x1c2>
lea    0xd8f(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    1300 <main+0x1d0>
lea    0xd9a(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x18(%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    0xe98(%rip),%r14
lea    -0x2c(%rbp),%rbx
nopl   0x0(%rax)
mov    %r14,%rdi
mov    %rbx,%rsi
call   1070 <scanf@plt>
mov    -0x2c(%rbp),%ecx
lea    -0xa(%rcx),%eax
cmp    $0xfffffff9,%eax
jb     1170 <main+0x20>
mov    %rsp,-0x48(%rbp)
mov    %rcx,%rax
mov    %rcx,-0x40(%rbp)
imul   %rcx,%rax
mov    %rsp,%rcx
lea    0xf(,%rax,4),%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%rcx
mov    %rcx,-0x38(%rbp)
mov    %rcx,%rsp
mov    -0x2c(%rbp),%edx
lea    0xe4b(%rip),%rdi
mov    %edx,%esi
xor    %eax,%eax
call   1050 <printf@plt>
mov    -0x2c(%rbp),%eax
test   %eax,%eax
jle    123e <main+0xee>
mov    -0x40(%rbp),%rcx
lea    0x0(,%rcx,4),%rcx
mov    %rcx,-0x50(%rbp)
xor    %r14d,%r14d
lea    0xe5c(%rip),%r15
mov    -0x38(%rbp),%r12
jmp    120b <main+0xbb>
nopl   0x0(%rax,%rax,1)
mov    $0xa,%edi
call   1030 <putchar@plt>
add    $0x1,%r14
movslq -0x2c(%rbp),%rax
add    -0x50(%rbp),%r12
cmp    %rax,%r14
jge    123e <main+0xee>
test   %eax,%eax
jle    11f0 <main+0xa0>
mov    %r12,%rbx
xor    %r13d,%r13d
cs nopw 0x0(%rax,%rax,1)
nop
mov    %r15,%rdi
mov    %rbx,%rsi
call   1070 <scanf@plt>
add    $0x1,%r13
movslq -0x2c(%rbp),%rax
add    $0x4,%rbx
cmp    %rax,%r13
jl     1220 <main+0xd0>
jmp    11f0 <main+0xa0>
lea    0xe04(%rip),%rdi
call   1040 <puts@plt>
mov    -0x2c(%rbp),%esi
test   %esi,%esi
jle    12ad <main+0x15d>
mov    -0x40(%rbp),%r13
shl    $0x2,%r13
lea    0xde4(%rip),%r14
mov    -0x38(%rbp),%r12
xor    %r15d,%r15d
jmp    128a <main+0x13a>
nopl   0x0(%rax)
mov    $0xa,%edi
call   1030 <putchar@plt>
add    $0x1,%r15
movslq -0x2c(%rbp),%rsi
add    %r13,%r12
cmp    %rsi,%r15
jge    12ad <main+0x15d>
test   %esi,%esi
jle    1270 <main+0x120>
xor    %ebx,%ebx
mov    (%r12,%rbx,4),%esi
mov    %r14,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
add    $0x1,%rbx
movslq -0x2c(%rbp),%rax
cmp    %rax,%rbx
jl     1290 <main+0x140>
jmp    1270 <main+0x120>
mov    -0x38(%rbp),%rdi
call   1060 <isMagic@plt>
test   %eax,%eax
lea    0xdb5(%rip),%rax
lea    0xdcb(%rip),%rdi
cmove  %rax,%rdi
call   1040 <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 = [3 x i8] c"%d\00"
@.str.1 = [59 x i8] c"Farewell!Now enter the values of you own %d by %d square:\0A\00"
@.str.2 = [6 x i8] c"%d%*c\00"
@.str.3 = [2 x i8] c"\0A\00"
@.str.4 = [44 x i8] c"Your \22magic square\22 should look like this:\0A\00"
@.str.5 = [5 x i8] c"\09%d \00"
@.str.6 = [30 x i8] c"Your square indeed is magic!\0A\00"
@.str.7 = [36 x i8] c"Sorry but your square isn't magic!\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i64
%7 = alloca i64
store i32 0, i32* %1
store i32 0, i32* %3
br label %8
8: ; preds = %16, %0
%9 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %2)
br label %10
10: ; preds = %8
%11 = load i32, i32* %2
%12 = icmp sle i32 %11, 2
br i1 %12, label %16, label %13
13: ; preds = %10
%14 = load i32, i32* %2
%15 = icmp sge i32 %14, 10
br label %16
16: ; preds = %13, %10
%17 = phi i1 [ true, %10 ], [ %15, %13 ]
br i1 %17, label %8, label %18
18: ; preds = %16
%19 = load i32, i32* %2
%20 = zext i32 %19 to i64
%21 = load i32, i32* %2
%22 = zext i32 %21 to i64
%23 = call i8* @llvm.stacksave()
store i8* %23, i8** %5
%24 = mul nuw i64 %20, %22
%25 = alloca i32, i64 %24
store i64 %20, i64* %6
store i64 %22, i64* %7
%26 = load i32, i32* %2
%27 = load i32, i32* %2
%28 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([59 x i8], [59 x i8]* @.str.1, i64 0, i64 0), i32 %26, i32 %27)
br label %29
29: ; preds = %52, %18
%30 = load i32, i32* %3
%31 = load i32, i32* %2
%32 = icmp slt i32 %30, %31
br i1 %32, label %33, label %55
33: ; preds = %29
store i32 0, i32* %4
br label %34
34: ; preds = %47, %33
%35 = load i32, i32* %4
%36 = load i32, i32* %2
%37 = icmp slt i32 %35, %36
br i1 %37, label %38, label %50
38: ; preds = %34
%39 = load i32, i32* %3
%40 = sext i32 %39 to i64
%41 = mul nsw i64 %40, %22
%42 = getelementptr inbounds i32, i32* %25, i64 %41
%43 = load i32, i32* %4
%44 = sext i32 %43 to i64
%45 = getelementptr inbounds i32, i32* %42, i64 %44
%46 = call i32 @scanf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i32* %45)
br label %47
47: ; preds = %38
%48 = load i32, i32* %4
%49 = add nsw i32 %48, 1
store i32 %49, i32* %4
br label %34
50: ; preds = %34
%51 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
br label %52
52: ; preds = %50
%53 = load i32, i32* %3
%54 = add nsw i32 %53, 1
store i32 %54, i32* %3
br label %29
55: ; preds = %29
%56 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.4, i64 0, i64 0))
store i32 0, i32* %3
br label %57
57: ; preds = %81, %55
%58 = load i32, i32* %3
%59 = load i32, i32* %2
%60 = icmp slt i32 %58, %59
br i1 %60, label %61, label %84
61: ; preds = %57
store i32 0, i32* %4
br label %62
62: ; preds = %76, %61
%63 = load i32, i32* %4
%64 = load i32, i32* %2
%65 = icmp slt i32 %63, %64
br i1 %65, label %66, label %79
66: ; preds = %62
%67 = load i32, i32* %3
%68 = sext i32 %67 to i64
%69 = mul nsw i64 %68, %22
%70 = getelementptr inbounds i32, i32* %25, i64 %69
%71 = load i32, i32* %4
%72 = sext i32 %71 to i64
%73 = getelementptr inbounds i32, i32* %70, i64 %72
%74 = load i32, i32* %73
%75 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.5, i64 0, i64 0), i32 %74)
br label %76
76: ; preds = %66
%77 = load i32, i32* %4
%78 = add nsw i32 %77, 1
store i32 %78, i32* %4
br label %62
79: ; preds = %62
%80 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
br label %81
81: ; preds = %79
%82 = load i32, i32* %3
%83 = add nsw i32 %82, 1
store i32 %83, i32* %3
br label %57
84: ; preds = %57
%85 = bitcast i32* %25 to i32**
%86 = load i32, i32* %2
%87 = call i32 @isMagic(i32** %85, i32 %86)
%88 = icmp ne i32 %87, 0
br i1 %88, label %91, label %89
89: ; preds = %84
%90 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.6, i64 0, i64 0))
br label %93
91: ; preds = %84
%92 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.7, i64 0, i64 0))
br label %93
93: ; preds = %91, %89
store i32 0, i32* %1
%94 = load i8*, i8** %5
%95 = load i32, i32* %1
ret i32 %95
}

LLVM IR (-O2):
@.str = [3 x i8] c"%d\00"
@.str.1 = [59 x i8] c"Farewell!Now enter the values of you own %d by %d square:\0A\00"
@.str.2 = [6 x i8] c"%d%*c\00"
@.str.5 = [5 x i8] c"\09%d \00"
@str = [43 x i8] c"Your \22magic square\22 should look like this:\00"
@str.8 = [29 x i8] c"Your square indeed is magic!\00"
@str.9 = [35 x i8] c"Sorry but your square isn't magic!\00"
define i32 @main() {
%1 = alloca i32
%2 = bitcast i32* %1 to i8*
br label %3
3: ; preds = %3, %0
%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 = add i32 %5, -10
%7 = icmp ult i32 %6, -7
br i1 %7, label %3, label %8
8: ; preds = %3
%9 = zext i32 %5 to i64
%10 = call i8* @llvm.stacksave()
%11 = mul nuw nsw i64 %9, %9
%12 = alloca i32, i64 %11
%13 = load i32, i32* %1
%14 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([59 x i8], [59 x i8]* @.str.1, i64 0, i64 0), i32 %13, i32 %13)
%15 = load i32, i32* %1
%16 = icmp sgt i32 %15, 0
br i1 %16, label %17, label %38
17: ; preds = %8, %32
%18 = phi i32 [ %35, %32 ], [ %15, %8 ]
%19 = phi i64 [ %34, %32 ], [ 0, %8 ]
%20 = icmp sgt i32 %18, 0
br i1 %20, label %21, label %32
21: ; preds = %17
%22 = mul nuw nsw i64 %19, %9
%23 = getelementptr inbounds i32, i32* %12, i64 %22
br label %24
24: ; preds = %21, %24
%25 = phi i64 [ 0, %21 ], [ %28, %24 ]
%26 = getelementptr inbounds i32, i32* %23, i64 %25
%27 = call i32 @scanf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i32* %26)
%28 = add nuw nsw i64 %25, 1
%29 = load i32, i32* %1
%30 = sext i32 %29 to i64
%31 = icmp slt i64 %28, %30
br i1 %31, label %24, label %32
32: ; preds = %24, %17
%33 = call i32 @putchar(i32 10)
%34 = add nuw nsw i64 %19, 1
%35 = load i32, i32* %1
%36 = sext i32 %35 to i64
%37 = icmp slt i64 %34, %36
br i1 %37, label %17, label %38
38: ; preds = %32, %8
%39 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([43 x i8], [43 x i8]* @str, i64 0, i64 0))
%40 = load i32, i32* %1
%41 = icmp sgt i32 %40, 0
br i1 %41, label %42, label %64
42: ; preds = %38, %58
%43 = phi i32 [ %61, %58 ], [ %40, %38 ]
%44 = phi i64 [ %60, %58 ], [ 0, %38 ]
%45 = icmp sgt i32 %43, 0
br i1 %45, label %46, label %58
46: ; preds = %42
%47 = mul nuw nsw i64 %44, %9
%48 = getelementptr inbounds i32, i32* %12, i64 %47
br label %49
49: ; preds = %46, %49
%50 = phi i64 [ 0, %46 ], [ %54, %49 ]
%51 = getelementptr inbounds i32, i32* %48, i64 %50
%52 = load i32, i32* %51
%53 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.5, i64 0, i64 0), i32 %52)
%54 = add nuw nsw i64 %50, 1
%55 = load i32, i32* %1
%56 = sext i32 %55 to i64
%57 = icmp slt i64 %54, %56
br i1 %57, label %49, label %58
58: ; preds = %49, %42
%59 = call i32 @putchar(i32 10)
%60 = add nuw nsw i64 %44, 1
%61 = load i32, i32* %1
%62 = sext i32 %61 to i64
%63 = icmp slt i64 %60, %62
br i1 %63, label %42, label %64
64: ; preds = %58, %38
%65 = phi i32 [ %40, %38 ], [ %61, %58 ]
%66 = bitcast i32* %12 to i32**
%67 = call i32 @isMagic(i32** %66, i32 %65)
%68 = icmp eq i32 %67, 0
%69 = select i1 %68, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @str.8, i64 0, i64 0), i8* getelementptr inbounds ([35 x i8], [35 x i8]* @str.9, i64 0, i64 0)
%70 = call i32 @puts(i8* dereferenceable(1) %69)
ret i32 0
}