// File: /workspace/github_cpp_makefile_star2_O3/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
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movl %ecx, %r12d
movq %rsi, %r15
movl %edx, -0x2c(%rbp)
movslq %edx, %rbx
leaq (,%rbx,8), %rax
testl %ebx, %ebx
movq $-0x1, %rdi
cmovnsq %rax, %rdi
callq 0x1030
movq %rbx, %rcx
movq %rax, %r14
movb $0x1, %al
testl %ecx, %ecx
jle 0x28b4
movq %r15, -0x38(%rbp)
leaq (,%rcx,4), %r13
movq %rcx, -0x40(%rbp)
movl %ecx, %r15d
xorl %ebx, %ebx
movq %r13, %rdi
callq 0x1030
movq %rax, (%r14,%rbx,8)
incq %rbx
cmpq %rbx, %r15
jne 0x27ce
movl -0x2c(%rbp), %r10d
testl %r10d, %r10d
jle 0x28bb
movq -0x38(%rbp), %rax
movq (%rax), %rax
leaq (,%r15,4), %rcx
xorl %edx, %edx
movq -0x40(%rbp), %r11
movq (%r14,%rdx,8), %rsi
xorl %edi, %edi
movl (%rax,%rdi,4), %r8d
movl %r8d, (%rsi,%rdi,4)
incq %rdi
cmpq %rdi, %r15
jne 0x280a
incq %rdx
addq %rcx, %rax
cmpq %r15, %rdx
jne 0x2804
leaq (%r14,%r11,8), %rax
xorl %ecx, %ecx
movq $0x0, -0x38(%rbp)
xorl %r13d, %r13d
xorl %ebx, %ebx
movq (%r14,%rcx,8), %rsi
xorl %edi, %edi
xorl %edx, %edx
xorl %r8d, %r8d
addl (%rsi,%rdi,4), %r8d
movq (%r14,%rdi,8), %r9
addl (%r9,%rcx,4), %edx
incq %rdi
cmpq %rdi, %r15
jne 0x2843
cmpl %r12d, %r8d
jne 0x2888
cmpl %r12d, %edx
jne 0x2888
movq (%r14,%rcx,8), %rdx
addl (%rdx,%rcx,4), %ebx
movq %rcx, %rdx
notq %rdx
movq (%rax,%rdx,8), %rdx
addl (%rdx,%rcx,4), %r13d
incq %rcx
cmpq %r11, %rcx
setge %dl
movq %rdx, -0x38(%rbp)
cmpq %r15, %rcx
jne 0x2838
testl %r10d, %r10d
jle 0x28ae
movl %r12d, -0x2c(%rbp)
xorl %r12d, %r12d
movq (%r14,%r12,8), %rdi
testq %rdi, %rdi
je 0x28a2
callq 0x1130
incq %r12
cmpq %r12, %r15
jne 0x2894
movl -0x2c(%rbp), %r12d
movq -0x38(%rbp), %rax
jmp 0x28c2
xorl %r13d, %r13d
xorl %ebx, %ebx
jmp 0x28c2
xorl %r13d, %r13d
xorl %ebx, %ebx
movb $0x1, %al
xorl %r12d, %ebx
xorl %r12d, %r13d
orl %ebx, %r13d
sete %bl
andb %al, %bl
movq %r14, %rdi
callq 0x1130
movl %ebx, %eax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nop