#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 sqr[99];
  int counter, size;
  printf("Enter square size");
  scanf("%d", &size);
  for (counter = 0; counter < (size * size); counter++) {
    printf("Enter element:\n");
    scanf("%d", &sqr[counter]);
  }
  switch (magic(sqr, &size)) {
  case 0:
    printf("MAGIC\n");
    break;
  case 1:
    printf("NOT MAGIC columns\n");
    break;
  case 2:
    printf("NOT MAGIC rows\n");
    break;
  case 3:
    printf("NOT MAGIC diagonal 1\n");
    break;
  case 4:
    printf("NOT MAGIC diagonal 2\n");
    break;
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x1a0,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xecb(%rip),%rdi
call   1040 <printf@plt>
lea    0xed1(%rip),%rdi
lea    -0x198(%rbp),%rsi
call   1050 <scanf@plt>
movl   $0x0,-0x194(%rbp)
mov    -0x194(%rbp),%eax
mov    -0x198(%rbp),%ecx
imul   -0x198(%rbp),%ecx
cmp    %ecx,%eax
jge    11c7 <main+0x97>
lea    0xe9c(%rip),%rdi
call   1040 <printf@plt>
movslq -0x194(%rbp),%rax
lea    -0x190(%rbp),%rsi
shl    $0x2,%rax
add    %rax,%rsi
lea    0xe78(%rip),%rdi
call   1050 <scanf@plt>
mov    -0x194(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x194(%rbp)
jmp    116b <main+0x3b>
lea    -0x190(%rbp),%rdi
lea    -0x198(%rbp),%rsi
call   1030 <magic@plt>
mov    %eax,%ecx
mov    %rcx,-0x1a0(%rbp)
sub    $0x4,%eax
ja     1253 <main+0x123>
mov    -0x1a0(%rbp),%rax
lea    0xe06(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
lea    0xe2f(%rip),%rdi
call   1040 <printf@plt>
jmp    1253 <main+0x123>
lea    0xe25(%rip),%rdi
call   1040 <printf@plt>
jmp    1253 <main+0x123>
lea    0xe27(%rip),%rdi
call   1040 <printf@plt>
jmp    1253 <main+0x123>
lea    0xe26(%rip),%rdi
call   1040 <printf@plt>
jmp    1253 <main+0x123>
lea    0xe2b(%rip),%rdi
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x1a0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x1a8,%rsp
lea    0xeab(%rip),%rdi
call   1050 <printf@plt>
lea    0xeb1(%rip),%rdi
lea    0xc(%rsp),%rsi
call   1060 <scanf@plt>
mov    0xc(%rsp),%eax
imul   %eax,%eax
test   %eax,%eax
je     11b7 <main+0x77>
lea    0x10(%rsp),%r12
xor    %ebx,%ebx
lea    0xee2(%rip),%r14
lea    0xe87(%rip),%r15
nopl   0x0(%rax,%rax,1)
mov    %r14,%rdi
call   1040 <puts@plt>
mov    %r15,%rdi
mov    %r12,%rsi
call   1060 <scanf@plt>
add    $0x1,%rbx
mov    0xc(%rsp),%eax
imul   %eax,%eax
add    $0x4,%r12
cmp    %rax,%rbx
jb     1190 <main+0x50>
lea    0x10(%rsp),%rdi
lea    0xc(%rsp),%rsi
call   1030 <magic@plt>
cmp    $0x4,%eax
ja     11e0 <main+0xa0>
cltq
lea    0xea4(%rip),%rcx
movslq (%rcx,%rax,4),%rdi
add    %rcx,%rdi
call   1040 <puts@plt>
xor    %eax,%eax
add    $0x1a8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [18 x i8] c"Enter square size\00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [16 x i8] c"Enter element:\0A\00"
@.str.3 = [7 x i8] c"MAGIC\0A\00"
@.str.4 = [19 x i8] c"NOT MAGIC columns\0A\00"
@.str.5 = [16 x i8] c"NOT MAGIC rows\0A\00"
@.str.6 = [22 x i8] c"NOT MAGIC diagonal 1\0A\00"
@.str.7 = [22 x i8] c"NOT MAGIC diagonal 2\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [99 x i32]
%3 = alloca i32
%4 = alloca i32
store i32 0, i32* %1
%5 = call i32 @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0))
%6 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %4)
store i32 0, i32* %3
br label %7
7: ; preds = %19, %0
%8 = load i32, i32* %3
%9 = load i32, i32* %4
%10 = load i32, i32* %4
%11 = mul nsw i32 %9, %10
%12 = icmp slt i32 %8, %11
br i1 %12, label %13, label %22
13: ; preds = %7
%14 = call i32 @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0))
%15 = load i32, i32* %3
%16 = sext i32 %15 to i64
%17 = getelementptr inbounds [99 x i32], [99 x i32]* %2, i64 0, i64 %16
%18 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %17)
br label %19
19: ; preds = %13
%20 = load i32, i32* %3
%21 = add nsw i32 %20, 1
store i32 %21, i32* %3
br label %7
22: ; preds = %7
%23 = getelementptr inbounds [99 x i32], [99 x i32]* %2, i64 0, i64 0
%24 = call i32 @magic(i32* %23, i32* %4)
switch i32 %24, label %35 [
i32 0, label %25
i32 1, label %27
i32 2, label %29
i32 3, label %31
i32 4, label %33
]
25: ; preds = %22
%26 = call i32 @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0))
br label %35
27: ; preds = %22
%28 = call i32 @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.4, i64 0, i64 0))
br label %35
29: ; preds = %22
%30 = call i32 @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.5, i64 0, i64 0))
br label %35
31: ; preds = %22
%32 = call i32 @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.6, i64 0, i64 0))
br label %35
33: ; preds = %22
%34 = call i32 @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.7, i64 0, i64 0))
br label %35
35: ; preds = %22, %33, %31, %29, %27, %25
ret i32 0
}

LLVM IR (-O2):
@.str = [18 x i8] c"Enter square size\00"
@.str.1 = [3 x i8] c"%d\00"
@str = [21 x i8] c"NOT MAGIC diagonal 2\00"
@str.8 = [21 x i8] c"NOT MAGIC diagonal 1\00"
@str.9 = [15 x i8] c"NOT MAGIC rows\00"
@str.10 = [18 x i8] c"NOT MAGIC columns\00"
@str.11 = [6 x i8] c"MAGIC\00"
@str.12 = [15 x i8] c"Enter element:\00"
@reltable.main = [5 x i32] [i32 trunc (i64 sub (i64 ptrtoint ([6 x i8]* @str.11 to i64), i64 ptrtoint ([5 x i32]* @reltable.main to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([18 x i8]* @str.10 to i64), i64 ptrtoint ([5 x i32]* @reltable.main to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([15 x i8]* @str.9 to i64), i64 ptrtoint ([5 x i32]* @reltable.main to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([21 x i8]* @str.8 to i64), i64 ptrtoint ([5 x i32]* @reltable.main to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([21 x i8]* @str to i64), i64 ptrtoint ([5 x i32]* @reltable.main to i64)) to i32)]
define i32 @main() {
%1 = alloca [99 x i32]
%2 = alloca i32
%3 = bitcast [99 x i32]* %1 to i8*
%4 = bitcast i32* %2 to i8*
%5 = tail call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0))
%6 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %2)
%7 = load i32, i32* %2
%8 = mul nsw i32 %7, %7
%9 = icmp eq i32 %8, 0
br i1 %9, label %20, label %10
10: ; preds = %0, %10
%11 = phi i64 [ %15, %10 ], [ 0, %0 ]
%12 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @str.12, i64 0, i64 0))
%13 = getelementptr inbounds [99 x i32], [99 x i32]* %1, i64 0, i64 %11
%14 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %13)
%15 = add nuw nsw i64 %11, 1
%16 = load i32, i32* %2
%17 = mul nsw i32 %16, %16
%18 = zext i32 %17 to i64
%19 = icmp ult i64 %15, %18
br i1 %19, label %10, label %20
20: ; preds = %10, %0
%21 = getelementptr inbounds [99 x i32], [99 x i32]* %1, i64 0, i64 0
%22 = call i32 @magic(i32* %21, i32* %2)
%23 = icmp ult i32 %22, 5
br i1 %23, label %24, label %29
24: ; preds = %20
%25 = sext i32 %22 to i64
%26 = shl i64 %25, 2
%27 = call i8* @llvm.load.relative.i64(i8* bitcast ([5 x i32]* @reltable.main to i8*), i64 %26)
%28 = call i32 @puts(i8* dereferenceable(1) %27)
br label %29
29: ; preds = %20, %24
ret i32 0
}