// File: EverybodyHops[P]Permutations/magic_square.cpp
// Function: magic_square::get_magic_square(int)
vector<vector<int>> get_magic_square(int rank){
        int rank_2;
        rank_2 = rank * rank;

        // initialize
        vector<int> p;
        for(int i = 0; i < rank_2; i++){
            p.push_back(i + 1);
        }
        int k = 0;
        int magic_sum = rank * (rank_2 + 1) / 2;

        // start algorithm
        vector<vector<int>> ans;
        dic_order<int> *dop;
        bool flag = true;
        while(flag){
            if(add(p, k, rank) == magic_sum){
                k += rank;
                if(k == rank_2){
                    k = 0;
                    if(if_magic_square(p, rank, magic_sum)){
                        ans.push_back(p);
                    }
                    dop = new dic_order<int>(p);
                    flag = dop->next_one();
                    p = dop->get_permutation();
                    delete dop;
                }
            }else{
                sort(p.begin() + k + rank, p.end(), greater<int>());
                dop = new dic_order<int>(p);
                flag = dop->next_one();
                p = dop->get_permutation();
                delete dop;
            }
        }
        return ans;
    }

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x190, %rsp            # imm = 0x190
movq %rdi, -0x140(%rbp)
movq %rdi, %rax
movq %rax, -0x138(%rbp)
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movl %edx, -0x14(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0x130(%rbp)
movl -0x14(%rbp), %eax
imull -0x14(%rbp), %eax
movl %eax, -0x18(%rbp)
leaq -0x30(%rbp), %rdi
callq 0x20d0
movl $0x0, -0x34(%rbp)
movl -0x34(%rbp), %eax
cmpl -0x18(%rbp), %eax
jge 0x3c49
movl -0x34(%rbp), %eax
incl %eax
movl %eax, -0x38(%rbp)
leaq -0x30(%rbp), %rdi
leaq -0x38(%rbp), %rsi
callq 0x2160
jmp 0x3c2b
jmp 0x3c2d
movl -0x34(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x34(%rbp)
jmp 0x3c0c
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
jmp 0x407c
movq -0x140(%rbp), %rdi
movl $0x0, -0x48(%rbp)
movl -0x14(%rbp), %eax
movl -0x18(%rbp), %ecx
addl $0x1, %ecx
imull %ecx, %eax
movl $0x2, %ecx
cltd
idivl %ecx
movl %eax, -0x4c(%rbp)
movb $0x0, -0x4d(%rbp)
callq 0x4360
movb $0x1, -0x59(%rbp)
testb $0x1, -0x59(%rbp)
je 0x4041
leaq -0x78(%rbp), %rdi
leaq -0x30(%rbp), %rsi
callq 0x1f10
jmp 0x3c94
movq -0x130(%rbp), %rdi
movl -0x48(%rbp), %edx
movl -0x14(%rbp), %ecx
leaq -0x78(%rbp), %rsi
callq 0x4380
movl %eax, -0x144(%rbp)
jmp 0x3cb2
movl -0x4c(%rbp), %eax
movl %eax, -0x148(%rbp)
leaq -0x78(%rbp), %rdi
callq 0x2030
movl -0x148(%rbp), %ecx
movl -0x144(%rbp), %eax
cmpl %ecx, %eax
jne 0x3eb9
movl -0x14(%rbp), %eax
addl -0x48(%rbp), %eax
movl %eax, -0x48(%rbp)
movl -0x48(%rbp), %eax
cmpl -0x18(%rbp), %eax
jne 0x3eb4
movl $0x0, -0x48(%rbp)
leaq -0x90(%rbp), %rdi
leaq -0x30(%rbp), %rsi
callq 0x1f10
jmp 0x3d06
movq -0x130(%rbp), %rdi
movl -0x14(%rbp), %edx
movl -0x4c(%rbp), %ecx
leaq -0x90(%rbp), %rsi
callq 0x43e0
movb %al, -0x149(%rbp)
jmp 0x3d27
leaq -0x90(%rbp), %rdi
callq 0x2030
movb -0x149(%rbp), %al
testb $0x1, %al
jne 0x3d3f
jmp 0x3d9b
movq -0x140(%rbp), %rdi
leaq -0x30(%rbp), %rsi
callq 0x4620
jmp 0x3d51
jmp 0x3d9b
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
jmp 0x4070
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
leaq -0x78(%rbp), %rdi
callq 0x2030
jmp 0x4070
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
leaq -0x90(%rbp), %rdi
callq 0x2030
jmp 0x4070
movl $0x28, %edi
callq 0x10e0
movq %rax, -0x158(%rbp)
jmp 0x3dae
movb $0x1, -0xa9(%rbp)
leaq -0xa8(%rbp), %rdi
leaq -0x30(%rbp), %rsi
callq 0x1f10
jmp 0x3dc7
movq -0x158(%rbp), %rdi
leaq -0xa8(%rbp), %rsi
callq 0x4690
jmp 0x3ddc
movq -0x158(%rbp), %rax
movb $0x0, -0xa9(%rbp)
movq %rax, -0x58(%rbp)
leaq -0xa8(%rbp), %rdi
callq 0x2030
movq -0x58(%rbp), %rdi
callq 0x4920
movb %al, -0x159(%rbp)
jmp 0x3e0b
movb -0x159(%rbp), %al
andb $0x1, %al
movb %al, -0x59(%rbp)
movq -0x58(%rbp), %rsi
movq (%rsi), %rax
movq (%rax), %rax
leaq -0xc8(%rbp), %rdi
callq *%rax
jmp 0x3e2b
leaq -0x30(%rbp), %rdi
leaq -0xc8(%rbp), %rsi
callq 0x4950
leaq -0xc8(%rbp), %rdi
callq 0x2030
movq -0x58(%rbp), %rax
movq %rax, -0x168(%rbp)
cmpq $0x0, %rax
je 0x3e70
movq -0x168(%rbp), %rdi
callq 0x4980
movq -0x168(%rbp), %rdi
callq 0x10c0
jmp 0x3eb4
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
jmp 0x3e98
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
leaq -0xa8(%rbp), %rdi
callq 0x2030
testb $0x1, -0xa9(%rbp)
jne 0x3ea3
jmp 0x3eaf
movq -0x158(%rbp), %rdi
callq 0x10c0
jmp 0x4070
jmp 0x403c
leaq -0x30(%rbp), %rdi
movq %rdi, -0x170(%rbp)
callq 0x2230
movq %rax, -0xe0(%rbp)
movslq -0x48(%rbp), %rsi
leaq -0xe0(%rbp), %rdi
callq 0x49e0
movq %rax, -0xd8(%rbp)
movslq -0x14(%rbp), %rsi
leaq -0xd8(%rbp), %rdi
callq 0x49e0
movq -0x170(%rbp), %rdi
movq %rax, -0xd0(%rbp)
callq 0x2260
movq %rax, -0xe8(%rbp)
movq -0xd0(%rbp), %rdi
movq -0xe8(%rbp), %rsi
callq 0x49a0
jmp 0x3f26
movl $0x28, %edi
callq 0x10e0
movq %rax, -0x178(%rbp)
jmp 0x3f39
movb $0x1, -0x109(%rbp)
leaq -0x108(%rbp), %rdi
leaq -0x30(%rbp), %rsi
callq 0x1f10
jmp 0x3f52
movq -0x178(%rbp), %rdi
leaq -0x108(%rbp), %rsi
callq 0x4690
jmp 0x3f67
movq -0x178(%rbp), %rax
movb $0x0, -0x109(%rbp)
movq %rax, -0x58(%rbp)
leaq -0x108(%rbp), %rdi
callq 0x2030
movq -0x58(%rbp), %rdi
callq 0x4920
movb %al, -0x179(%rbp)
jmp 0x3f96
movb -0x179(%rbp), %al
andb $0x1, %al
movb %al, -0x59(%rbp)
movq -0x58(%rbp), %rsi
movq (%rsi), %rax
movq (%rax), %rax
leaq -0x128(%rbp), %rdi
callq *%rax
jmp 0x3fb6
leaq -0x30(%rbp), %rdi
leaq -0x128(%rbp), %rsi
callq 0x4950
leaq -0x128(%rbp), %rdi
callq 0x2030
movq -0x58(%rbp), %rax
movq %rax, -0x188(%rbp)
cmpq $0x0, %rax
je 0x3ffb
movq -0x188(%rbp), %rdi
callq 0x4980
movq -0x188(%rbp), %rdi
callq 0x10c0
jmp 0x403c
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
jmp 0x4023
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
leaq -0x108(%rbp), %rdi
callq 0x2030
testb $0x1, -0x109(%rbp)
jne 0x402e
jmp 0x403a
movq -0x178(%rbp), %rdi
callq 0x10c0
jmp 0x4070
jmp 0x3c7b
movb $0x1, -0x4d(%rbp)
testb $0x1, -0x4d(%rbp)
jne 0x4057
movq -0x140(%rbp), %rdi
callq 0x4300
leaq -0x30(%rbp), %rdi
callq 0x2030
movq -0x138(%rbp), %rax
addq $0x190, %rsp            # imm = 0x190
popq %rbp
retq
movq -0x140(%rbp), %rdi
callq 0x4300
leaq -0x30(%rbp), %rdi
callq 0x2030
movq -0x40(%rbp), %rdi
callq 0x1160
nop