// File: EverybodyHops[P]Permutations/magic_square.cpp
// Function: magic_square::if_magic_square(std::vector<int, std::allocator<int>>, int, int)
bool if_magic_square(vector<int> p, int rank, int magic_sum){
        int **array2D = new int *[rank];
        for(int i = 0; i < rank; i++){
            array2D[i] = new int[rank];
        }

        for(int i = 0; i < rank; i++){
            for(int j = 0; j < rank; j++){
                array2D[i][j] = p[i * rank + j];
            }
        }
        
        bool flag = true;
        int t1, t2, t3, t4;
        t3 = 0; t4 = 0;
        for(int i = 0; i < rank; i++){
            t1 = 0; t2 = 0;
            for(int j = 0; j < rank; j++){
                t1 += array2D[i][j];
                t2 += array2D[j][i];
            }
            if(t1 != magic_sum || t2 != magic_sum){
                flag = false;
                break;
            }
            t3 += array2D[i][i];
            t4 += array2D[rank - i - 1][i];
        }
        if(t3 != magic_sum || t4 != magic_sum){
            flag = false;
        }

        for(int i = 0; i < rank; i++){
            delete[] array2D[i];
        }
        delete[] array2D;
        return flag;
    }

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x70, %rsp
movq %rsi, -0x58(%rbp)
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movl %edx, -0x14(%rbp)
movl %ecx, -0x18(%rbp)
movslq -0x14(%rbp), %rax
movl $0x8, %ecx
mulq %rcx
movq %rax, %rdi
seto %cl
movq $-0x1, %rax
testb $0x1, %cl
cmovneq %rax, %rdi
callq 0x1030
movq %rax, -0x20(%rbp)
movl $0x0, -0x24(%rbp)
movl -0x24(%rbp), %eax
cmpl -0x14(%rbp), %eax
jge 0x4471
movslq -0x14(%rbp), %rax
movl $0x4, %ecx
mulq %rcx
movq %rax, %rdi
seto %cl
movq $-0x1, %rax
testb $0x1, %cl
cmovneq %rax, %rdi
callq 0x1030
movq %rax, %rdx
movq -0x20(%rbp), %rax
movslq -0x24(%rbp), %rcx
movq %rdx, (%rax,%rcx,8)
movl -0x24(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x24(%rbp)
jmp 0x442a
movl $0x0, -0x28(%rbp)
movl -0x28(%rbp), %eax
cmpl -0x14(%rbp), %eax
jge 0x44d2
movl $0x0, -0x2c(%rbp)
movl -0x2c(%rbp), %eax
cmpl -0x14(%rbp), %eax
jge 0x44c5
movq -0x58(%rbp), %rdi
movl -0x28(%rbp), %eax
imull -0x14(%rbp), %eax
addl -0x2c(%rbp), %eax
movslq %eax, %rsi
callq 0x20b0
movl (%rax), %edx
movq -0x20(%rbp), %rax
movslq -0x28(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movslq -0x2c(%rbp), %rcx
movl %edx, (%rax,%rcx,4)
movl -0x2c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x2c(%rbp)
jmp 0x4487
jmp 0x44c7
movl -0x28(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x28(%rbp)
jmp 0x4478
movb $0x1, -0x2d(%rbp)
movl $0x0, -0x3c(%rbp)
movl $0x0, -0x40(%rbp)
movl $0x0, -0x44(%rbp)
movl -0x44(%rbp), %eax
cmpl -0x14(%rbp), %eax
jge 0x45af
movl $0x0, -0x34(%rbp)
movl $0x0, -0x38(%rbp)
movl $0x0, -0x48(%rbp)
movl -0x48(%rbp), %eax
cmpl -0x14(%rbp), %eax
jge 0x4551
movq -0x20(%rbp), %rax
movslq -0x44(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movslq -0x48(%rbp), %rcx
movl (%rax,%rcx,4), %eax
addl -0x34(%rbp), %eax
movl %eax, -0x34(%rbp)
movq -0x20(%rbp), %rax
movslq -0x48(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movslq -0x44(%rbp), %rcx
movl (%rax,%rcx,4), %eax
addl -0x38(%rbp), %eax
movl %eax, -0x38(%rbp)
movl -0x48(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x48(%rbp)
jmp 0x450c
movl -0x34(%rbp), %eax
cmpl -0x18(%rbp), %eax
jne 0x4561
movl -0x38(%rbp), %eax
cmpl -0x18(%rbp), %eax
je 0x4567
movb $0x0, -0x2d(%rbp)
jmp 0x45af
movq -0x20(%rbp), %rax
movslq -0x44(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movslq -0x44(%rbp), %rcx
movl (%rax,%rcx,4), %eax
addl -0x3c(%rbp), %eax
movl %eax, -0x3c(%rbp)
movq -0x20(%rbp), %rax
movl -0x14(%rbp), %ecx
subl -0x44(%rbp), %ecx
subl $0x1, %ecx
movslq %ecx, %rcx
movq (%rax,%rcx,8), %rax
movslq -0x44(%rbp), %rcx
movl (%rax,%rcx,4), %eax
addl -0x40(%rbp), %eax
movl %eax, -0x40(%rbp)
movl -0x44(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x44(%rbp)
jmp 0x44eb
movl -0x3c(%rbp), %eax
cmpl -0x18(%rbp), %eax
jne 0x45bf
movl -0x40(%rbp), %eax
cmpl -0x18(%rbp), %eax
je 0x45c3
movb $0x0, -0x2d(%rbp)
movl $0x0, -0x4c(%rbp)
movl -0x4c(%rbp), %eax
cmpl -0x14(%rbp), %eax
jge 0x45fe
movq -0x20(%rbp), %rax
movslq -0x4c(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movq %rax, -0x60(%rbp)
cmpq $0x0, %rax
je 0x45f1
movq -0x60(%rbp), %rdi
callq 0x1100
jmp 0x45f3
movl -0x4c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x4c(%rbp)
jmp 0x45ca
movq -0x20(%rbp), %rax
movq %rax, -0x68(%rbp)
cmpq $0x0, %rax
je 0x4615
movq -0x68(%rbp), %rdi
callq 0x1100
movb -0x2d(%rbp), %al
andb $0x1, %al
addq $0x70, %rsp
popq %rbp
retq