#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*/ printf(char *, ...);
int /*<<< orphan*/ scanf(char *, int *);
int magic(int h) {
  int i = 0, j = 0, lol = 0, sum = 0, s, random = 0;
  printf("Note: coordinates - \(row:number square\)\n");
  for (i; i < h; i++) {
    for (j; j < h; j++) {
      printf("Enter number in coordinates %d:%d ", i + 1, j + 1);
      scanf("%d", &lol);
      sum = sum + lol;
    }
    j = 0;
    if (i == 0)
      s = sum;
    if (sum == s)
      random = 1;
    else
      random = 0;
    sum = 0;
  }
  if (random == 1)
    printf("The square is indeed magical!");
  else
    printf("The square ain't magical at all!");
  return 0;
}


x86 assembly (clang, -O0):
<magic>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
movl   $0x0,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
movl   $0x0,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
movl   $0x0,-0x1c(%rbp)
lea    0xeab(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x8(%rbp),%eax
cmp    -0x4(%rbp),%eax
jge    1200 <magic+0xe0>
mov    -0xc(%rbp),%eax
cmp    -0x4(%rbp),%eax
jge    11b5 <magic+0x95>
mov    -0x8(%rbp),%esi
add    $0x1,%esi
mov    -0xc(%rbp),%edx
add    $0x1,%edx
lea    0xea2(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xeb7(%rip),%rdi
lea    -0x10(%rbp),%rsi
call   1040 <scanf@plt>
mov    -0x14(%rbp),%eax
add    -0x10(%rbp),%eax
mov    %eax,-0x14(%rbp)
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    1168 <magic+0x48>
movl   $0x0,-0xc(%rbp)
cmpl   $0x0,-0x8(%rbp)
jne    11cc <magic+0xac>
mov    -0x14(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x18(%rbp),%eax
jne    11e4 <magic+0xc4>
movl   $0x1,-0x1c(%rbp)
jmp    11eb <magic+0xcb>
movl   $0x0,-0x1c(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    115c <magic+0x3c>
cmpl   $0x1,-0x1c(%rbp)
jne    121d <magic+0xfd>
lea    0xe3e(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    122b <magic+0x10b>
lea    0xe49(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<magic>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %edi,%ebx
movl   $0x0,0x4(%rsp)
lea    0xf16(%rip),%rdi
call   1030 <puts@plt>
test   %ebx,%ebx
jle    11ea <magic+0xba>
mov    %ebx,%r14d
neg    %r14d
lea    0xe97(%rip),%r12
xor    %ecx,%ecx
mov    %ebx,0x8(%rsp)
nop
mov    %eax,0xc(%rsp)
mov    %rcx,0x10(%rsp)
lea    0x1(%rcx),%ebp
mov    $0x1,%ebx
xor    %r15d,%r15d
lea    0x4(%rsp),%r13
nopl   0x0(%rax)
mov    %r12,%rdi
mov    %ebp,%esi
mov    %ebx,%edx
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xe7e(%rip),%rdi
mov    %r13,%rsi
call   1050 <scanf@plt>
add    0x4(%rsp),%r15d
lea    (%r14,%rbx,1),%eax
add    $0x1,%eax
mov    %ebx,%ecx
add    $0x1,%ecx
mov    %ecx,%ebx
cmp    $0x1,%eax
jne    1190 <magic+0x60>
cmpl   $0x0,0x10(%rsp)
mov    0xc(%rsp),%eax
cmove  %r15d,%eax
mov    %ebp,%ecx
mov    0x8(%rsp),%ebx
cmp    %ebx,%ebp
jne    1170 <magic+0x40>
cmp    %eax,%r15d
jne    11ea <magic+0xba>
lea    0xe3e(%rip),%rdi
jmp    11f1 <magic+0xc1>
lea    0xe53(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [41 x i8] c"Note: coordinates - (row:number square)\0A\00"
@.str.1 = [35 x i8] c"Enter number in coordinates %d:%d \00"
@.str.2 = [3 x i8] c"%d\00"
@.str.3 = [30 x i8] c"The square is indeed magical!\00"
@.str.4 = [33 x i8] c"The square ain't magical at all!\00"
define i32 @magic(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
store i32 %0, i32* %2
store i32 0, i32* %3
store i32 0, i32* %4
store i32 0, i32* %5
store i32 0, i32* %6
store i32 0, i32* %8
%9 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str, i64 0, i64 0))
%10 = load i32, i32* %3
br label %11
11: ; preds = %46, %1
%12 = load i32, i32* %3
%13 = load i32, i32* %2
%14 = icmp slt i32 %12, %13
br i1 %14, label %15, label %49
15: ; preds = %11
%16 = load i32, i32* %4
br label %17
17: ; preds = %31, %15
%18 = load i32, i32* %4
%19 = load i32, i32* %2
%20 = icmp slt i32 %18, %19
br i1 %20, label %21, label %34
21: ; preds = %17
%22 = load i32, i32* %3
%23 = add nsw i32 %22, 1
%24 = load i32, i32* %4
%25 = add nsw i32 %24, 1
%26 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.1, i64 0, i64 0), i32 %23, i32 %25)
%27 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %5)
%28 = load i32, i32* %6
%29 = load i32, i32* %5
%30 = add nsw i32 %28, %29
store i32 %30, i32* %6
br label %31
31: ; preds = %21
%32 = load i32, i32* %4
%33 = add nsw i32 %32, 1
store i32 %33, i32* %4
br label %17
34: ; preds = %17
store i32 0, i32* %4
%35 = load i32, i32* %3
%36 = icmp eq i32 %35, 0
br i1 %36, label %37, label %39
37: ; preds = %34
%38 = load i32, i32* %6
store i32 %38, i32* %7
br label %39
39: ; preds = %37, %34
%40 = load i32, i32* %6
%41 = load i32, i32* %7
%42 = icmp eq i32 %40, %41
br i1 %42, label %43, label %44
43: ; preds = %39
store i32 1, i32* %8
br label %45
44: ; preds = %39
store i32 0, i32* %8
br label %45
45: ; preds = %44, %43
store i32 0, i32* %6
br label %46
46: ; preds = %45
%47 = load i32, i32* %3
%48 = add nsw i32 %47, 1
store i32 %48, i32* %3
br label %11
49: ; preds = %11
%50 = load i32, i32* %8
%51 = icmp eq i32 %50, 1
br i1 %51, label %52, label %54
52: ; preds = %49
%53 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.3, i64 0, i64 0))
br label %56
54: ; preds = %49
%55 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.4, i64 0, i64 0))
br label %56
56: ; preds = %54, %52
ret i32 0
}

LLVM IR (-O2):
@.str.1 = [35 x i8] c"Enter number in coordinates %d:%d \00"
@.str.2 = [3 x i8] c"%d\00"
@.str.3 = [30 x i8] c"The square is indeed magical!\00"
@.str.4 = [33 x i8] c"The square ain't magical at all!\00"
@str = [40 x i8] c"Note: coordinates - (row:number square)\00"
define i32 @magic(i32 %0) {
%2 = alloca i32
%3 = bitcast i32* %2 to i8*
store i32 0, i32* %2
%4 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([40 x i8], [40 x i8]* @str, i64 0, i64 0))
%5 = icmp sgt i32 %0, 0
br i1 %5, label %6, label %25
6: ; preds = %1, %19
%7 = phi i32 [ %21, %19 ], [ undef, %1 ]
%8 = phi i32 [ %9, %19 ], [ 0, %1 ]
%9 = add nuw nsw i32 %8, 1
br label %10
10: ; preds = %6, %10
%11 = phi i32 [ 0, %6 ], [ %17, %10 ]
%12 = phi i32 [ 0, %6 ], [ %13, %10 ]
%13 = add nuw nsw i32 %12, 1
%14 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([35 x i8], [35 x i8]* @.str.1, i64 0, i64 0), i32 %9, i32 %13)
%15 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %2)
%16 = load i32, i32* %2
%17 = add nsw i32 %16, %11
%18 = icmp eq i32 %13, %0
br i1 %18, label %19, label %10
19: ; preds = %10
%20 = icmp eq i32 %8, 0
%21 = select i1 %20, i32 %17, i32 %7
%22 = icmp eq i32 %9, %0
br i1 %22, label %23, label %6
23: ; preds = %19
%24 = icmp eq i32 %17, %21
br i1 %24, label %26, label %25
25: ; preds = %1, %23
br label %26
26: ; preds = %23, %25
%27 = phi i8* [ getelementptr inbounds ([33 x i8], [33 x i8]* @.str.4, i64 0, i64 0), %25 ], [ getelementptr inbounds ([30 x i8], [30 x i8]* @.str.3, i64 0, i64 0), %23 ]
%28 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) %27)
ret i32 0
}