// File: /workspace/github_cpp_makefile_star2_O2/qema[P]orca-py/liborca.cpp
// Function: count4()
void count4() {
    clock_t startTime, endTime;
    startTime = clock();
    clock_t startTime_all, endTime_all;
    startTime_all = startTime;
    int frac,frac_prev;

    // precompute triangles that span over edges
    //printf("stage 1 - precomputing common nodes\n");
    int *tri = (int*)calloc(m,sizeof(int));
    frac_prev=-1;
    for (int i=0;i<m;i++) {
        frac = 100LL*i/m;
        if (frac!=frac_prev) {
            //printf("%d%%\r",frac);
            frac_prev=frac;
        }
        int x=edges[i].a, y=edges[i].b;
        for (int xi=0,yi=0; xi<deg[x] && yi<deg[y]; ) {
            if (adj[x][xi]==adj[y][yi]) { tri[i]++; xi++; yi++; }
            else if (adj[x][xi]<adj[y][yi]) { xi++; }
            else { yi++; }
        }
    }
    endTime = clock();
    //printf("%.2f\n", (double)(endTime-startTime)/CLOCKS_PER_SEC);
    startTime = endTime;

    // count full graphlets
    //printf("stage 2 - counting full graphlets\n");
    int64 *C4 = (int64*)calloc(n,sizeof(int64));
    int *neigh = (int*)malloc(n*sizeof(int)), nn;
    frac_prev=-1;
    for (int x=0;x<n;x++) {
        frac = 100LL*x/n;
        if (frac!=frac_prev) {
            //printf("%d%%\r",frac);
            frac_prev=frac;
        }
        for (int nx=0;nx<deg[x];nx++) {
            int y=adj[x][nx];
            if (y >= x) break;
            nn=0;
            for (int ny=0;ny<deg[y];ny++) {
                int z=adj[y][ny];
                if (z >= y) break;
                if (adjacent(x,z)==0) continue;
                neigh[nn++]=z;
            }
            for (int i=0;i<nn;i++) {
                int z = neigh[i];
                for (int j=i+1;j<nn;j++) {
                    int zz = neigh[j];
                    if (adjacent(z,zz)) {
                        C4[x]++; C4[y]++; C4[z]++; C4[zz]++;
                    }
                }
            }
        }
    }
    endTime = clock();
    //printf("%.2f\n", (double)(endTime-startTime)/CLOCKS_PER_SEC);
    startTime = endTime;

    // set up a system of equations relating orbits for every node
    //printf("stage 3 - building systems of equations\n");
    int *common = (int*)calloc(n,sizeof(int));
    int *common_list = (int*)malloc(n*sizeof(int)), nc=0;
    frac_prev=-1;
    for (int x=0;x<n;x++) {
        frac = 100LL*x/n;
        if (frac!=frac_prev) {
            //printf("%d%%\r",frac);
            frac_prev=frac;
        }

        int64 f_12_14=0, f_10_13=0;
        int64 f_13_14=0, f_11_13=0;
        int64 f_7_11=0, f_5_8=0;
        int64 f_6_9=0, f_9_12=0, f_4_8=0, f_8_12=0;
        int64 f_14=C4[x];

        for (int i=0;i<nc;i++) common[common_list[i]]=0;
        nc=0;

        orbit[x][0]=deg[x];
        // x - middle node
        for (int nx1=0;nx1<deg[x];nx1++) {
            int y=inc[x][nx1].first, ey=inc[x][nx1].second;
            for (int ny=0;ny<deg[y];ny++) {
                int z=inc[y][ny].first, ez=inc[y][ny].second;
                if (adjacent(x,z)) { // triangle
                    if (z<y) {
                        f_12_14 += tri[ez]-1;
                        f_10_13 += (deg[y]-1-tri[ez])+(deg[z]-1-tri[ez]);
                    }
                } else {
                    if (common[z]==0) common_list[nc++]=z;
                    common[z]++;
                }
            }
            for (int nx2=nx1+1;nx2<deg[x];nx2++) {
                int z=inc[x][nx2].first, ez=inc[x][nx2].second;
                if (adjacent(y,z)) { // triangle
                    orbit[x][3]++;
                    f_13_14 += (tri[ey]-1)+(tri[ez]-1);
                    f_11_13 += (deg[x]-1-tri[ey])+(deg[x]-1-tri[ez]);
                } else { // path
                    orbit[x][2]++;
                    f_7_11 += (deg[x]-1-tri[ey]-1)+(deg[x]-1-tri[ez]-1);
                    f_5_8 += (deg[y]-1-tri[ey])+(deg[z]-1-tri[ez]);
                }
            }
        }
        // x - side node
        for (int nx1=0;nx1<deg[x];nx1++) {
            int y=inc[x][nx1].first, ey=inc[x][nx1].second;
            for (int ny=0;ny<deg[y];ny++) {
                int z=inc[y][ny].first, ez=inc[y][ny].second;
                if (x==z) continue;
                if (!adjacent(x,z)) { // path
                    orbit[x][1]++;
                    f_6_9 += (deg[y]-1-tri[ey]-1);
                    f_9_12 += tri[ez];
                    f_4_8 += (deg[z]-1-tri[ez]);
                    f_8_12 += (common[z]-1);
                }
            }
        }

        // solve system of equations
        orbit[x][14]=(f_14);
        orbit[x][13]=(f_13_14-6*f_14)/2;
        orbit[x][12]=(f_12_14-3*f_14);
        orbit[x][11]=(f_11_13-f_13_14+6*f_14)/2;
        orbit[x][10]=(f_10_13-f_13_14+6*f_14);
        orbit[x][9]=(f_9_12-2*f_12_14+6*f_14)/2;
        orbit[x][8]=(f_8_12-2*f_12_14+6*f_14)/2;
        orbit[x][7]=(f_13_14+f_7_11-f_11_13-6*f_14)/6;
        orbit[x][6]=(2*f_12_14+f_6_9-f_9_12-6*f_14)/2;
        orbit[x][5]=(2*f_12_14+f_5_8-f_8_12-6*f_14);
        orbit[x][4]=(2*f_12_14+f_4_8-f_8_12-6*f_14);
    }

    endTime = clock();
    //printf("%.2f\n", (double)(endTime-startTime)/CLOCKS_PER_SEC);

    endTime_all = endTime;
    //printf("total: %.2f\n", (double)(endTime_all-startTime_all)/CLOCKS_PER_SEC);

    free(tri);
    free(C4);
    free(neigh);
    free(common);
    free(common_list);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x98, %rsp
callq 0x7110
movq 0xe8e3(%rip), %rax      # 0x15f50
movslq (%rax), %r14
pushq $0x4
popq %rsi
movq %r14, %rdi
callq 0x7100
movq %rax, 0x18(%rsp)
movq 0xe931(%rip), %rax      # 0x15fb8
movq (%rax), %rax
movq 0xe937(%rip), %rcx      # 0x15fc8
movq (%rcx), %rcx
movq 0xe8fd(%rip), %rdx      # 0x15f98
movq (%rdx), %rdx
xorl %esi, %esi
testl %r14d, %r14d
movl $0x0, %edi
cmovgl %r14d, %edi
cmpq %rdi, %rsi
je 0x7702
movslq (%rax,%rsi,8), %r8
movslq 0x4(%rax,%rsi,8), %r9
movl (%rcx,%r8,4), %r10d
xorl %r11d, %r11d
xorl %ebx, %ebx
movslq %r11d, %r14
movslq %ebx, %rbx
cmpl %r10d, %ebx
jge 0x76fd
cmpl (%rcx,%r9,4), %r11d
jge 0x76fd
movq (%rdx,%r8,8), %r15
movq (%rdx,%r9,8), %r12
movl (%r12,%r14,4), %ebp
cmpl %ebp, (%r15,%rbx,4)
je 0x76ed
jge 0x76f8
incq %rbx
jmp 0x76c9
movq 0x18(%rsp), %r14
incl (%r14,%rsi,4)
incl %ebx
incl %r11d
jmp 0x76c3
incq %rsi
jmp 0x76ac
callq 0x7110
movq 0xe892(%rip), %rax      # 0x15fa0
movl (%rax), %ebx
movslq %ebx, %r15
pushq $0x8
popq %rsi
movq %r15, %rdi
callq 0x7100
movq %rax, 0x50(%rsp)
shlq $0x2, %r15
movq %r15, %rdi
callq 0x7260
movq %rax, 0x40(%rsp)
xorl %r12d, %r12d
movslq %ebx, %rax
cmpq %rax, %r12
jge 0x7869
xorl %esi, %esi
movq 0xe87c(%rip), %rax      # 0x15fc8
movq (%rax), %rax
cmpl (%rax,%r12,4), %esi
jge 0x7858
movq 0xe838(%rip), %rcx      # 0x15f98
movq (%rcx), %rcx
movq (%rcx,%r12,8), %rcx
movslq %esi, %rdx
movslq (%rcx,%rdx,4), %rbx
cmpq %rbx, %r12
jle 0x7858
movl %esi, 0x38(%rsp)
xorl %r13d, %r13d
xorl %r15d, %r15d
movslq (%rax,%rbx,4), %rax
cmpq %rax, %r13
jge 0x77cf
movq 0xe807(%rip), %rax      # 0x15f98
movq (%rax), %rax
movq (%rax,%rbx,8), %rax
movl (%rax,%r13,4), %ebp
cmpl %ebx, %ebp
jge 0x77cf
movl %r12d, %edi
movl %ebp, %esi
movq 0xe7fc(%rip), %rax      # 0x15fa8
callq *(%rax)
testb %al, %al
je 0x77c0
movslq %r15d, %rax
incl %r15d
movq 0x40(%rsp), %rcx
movl %ebp, (%rcx,%rax,4)
incq %r13
movq 0xe7fe(%rip), %rax      # 0x15fc8
movq (%rax), %rax
jmp 0x7781
testl %r15d, %r15d
movl $0x0, %eax
cmovgl %r15d, %eax
movq %rax, 0x8(%rsp)
xorl %ecx, %ecx
pushq $0x1
popq %r14
cmpq 0x8(%rsp), %rcx
je 0x784d
movq 0x40(%rsp), %rax
movq %rcx, (%rsp)
movslq (%rax,%rcx,4), %r13
movq %r14, 0x10(%rsp)
cmpl %r14d, %r15d
jle 0x783c
movq 0x40(%rsp), %rax
movl (%rax,%r14,4), %ebp
movl %r13d, %edi
movl %ebp, %esi
movq 0xe78f(%rip), %rax      # 0x15fa8
callq *(%rax)
testb %al, %al
je 0x7837
movq 0x50(%rsp), %rcx
incq (%rcx,%r12,8)
incq (%rcx,%rbx,8)
incq (%rcx,%r13,8)
movslq %ebp, %rax
incq (%rcx,%rax,8)
incq %r14
jmp 0x77ff
movq (%rsp), %rcx
incq %rcx
movq 0x10(%rsp), %r14
incq %r14
jmp 0x77e6
movl 0x38(%rsp), %esi
incl %esi
jmp 0x7745
incq %r12
movq 0xe73e(%rip), %rax      # 0x15fa0
movl (%rax), %ebx
jmp 0x7737
callq 0x7110
movq 0xe72b(%rip), %rax      # 0x15fa0
movl (%rax), %ebx
movslq %ebx, %r12
pushq $0x4
popq %rsi
movq %r12, %rdi
callq 0x7100
movq %rax, 0x10(%rsp)
shlq $0x2, %r12
movq %r12, %rdi
callq 0x7260
movq %rax, 0x48(%rsp)
movq 0xe6ee(%rip), %rbp      # 0x15f90
xorl %edi, %edi
movq $0x0, 0x30(%rsp)
movslq %ebx, %rax
cmpq %rax, %rdi
jge 0x7d55
movq 0x50(%rsp), %rax
movq (%rax,%rdi,8), %rax
movq %rax, 0x88(%rsp)
movq 0x30(%rsp), %rsi
testl %esi, %esi
movl $0x0, %eax
cmovlel %eax, %esi
xorl %eax, %eax
cmpq %rax, %rsi
je 0x78f7
movq 0x48(%rsp), %rcx
movslq (%rcx,%rax,4), %rcx
movq 0x10(%rsp), %rdx
andl $0x0, (%rdx,%rcx,4)
incq %rax
jmp 0x78db
movq 0xe6ca(%rip), %rax      # 0x15fc8
movq (%rax), %rcx
movslq (%rcx,%rdi,4), %rax
movq 0xe634(%rip), %rdx      # 0x15f40
movq (%rdx), %rdx
movq (%rdx,%rdi,8), %rdx
movq %rax, (%rdx)
xorl %esi, %esi
pushq $0x1
popq %r8
movq $0x0, 0x30(%rsp)
movq $0x0, 0x68(%rsp)
movq $0x0, 0x60(%rsp)
movq $0x0, 0x80(%rsp)
movq $0x0, 0x70(%rsp)
movq $0x0, 0x78(%rsp)
movq $0x0, 0x38(%rsp)
movq %rdi, (%rsp)
movslq %eax, %rdx
cmpq %rdx, %rsi
jge 0x7b49
movl %r8d, 0x20(%rsp)
movslq %r8d, %rbx
movq (%rbp), %rax
movq (%rax,%rdi,8), %rax
movslq (%rax,%rsi,8), %r13
movq %rsi, 0x28(%rsp)
movslq 0x4(%rax,%rsi,8), %rax
movq %rax, 0x8(%rsp)
xorl %ebp, %ebp
movslq (%rcx,%r13,4), %rax
cmpq %rax, %rbp
jge 0x7a52
movq 0xe5e9(%rip), %rax      # 0x15f90
movq (%rax), %rax
movq (%rax,%r13,8), %rax
movl (%rax,%rbp,8), %r14d
movslq %r14d, %r12
movslq 0x4(%rax,%rbp,8), %r15
movl %r12d, %esi
movq 0xe5e4(%rip), %rax      # 0x15fa8
callq *(%rax)
testb %al, %al
je 0x7a0c
movq 0xe5f7(%rip), %rax      # 0x15fc8
movq (%rax), %rcx
cmpl %r13d, %r14d
jge 0x7a06
movq 0x18(%rsp), %rax
movl (%rax,%r15,4), %eax
leal -0x1(%rax), %edx
movslq %edx, %rdx
addq %rdx, 0x68(%rsp)
movl (%rcx,%r13,4), %edx
movl (%rcx,%r12,4), %esi
addl %eax, %eax
subl %eax, %edx
leal (%rdx,%rsi), %eax
addl $-0x2, %eax
cltq
addq %rax, 0x60(%rsp)
movq (%rsp), %rdi
jmp 0x7a4a
movq 0x10(%rsp), %rax
movl (%rax,%r12,4), %eax
testl %eax, %eax
jne 0x7a31
movq 0x30(%rsp), %rdx
movslq %edx, %rcx
incl %edx
movq %rdx, 0x30(%rsp)
movq 0x48(%rsp), %rdx
movl %r14d, (%rdx,%rcx,4)
movq (%rsp), %rdi
incl %eax
movq 0x10(%rsp), %rcx
movl %eax, (%rcx,%r12,4)
movq 0xe581(%rip), %rax      # 0x15fc8
movq (%rax), %rcx
incq %rbp
jmp 0x7993
movq 0xe537(%rip), %rbp      # 0x15f90
movslq (%rcx,%rdi,4), %rax
cmpq %rax, %rbx
jge 0x7b34
movq (%rbp), %rax
movq (%rax,%rdi,8), %rax
movl (%rax,%rbx,8), %r12d
movslq 0x4(%rax,%rbx,8), %r14
movl %r13d, %edi
movl %r12d, %esi
movq 0xe524(%rip), %rax      # 0x15fa8
callq *(%rax)
movq (%rsp), %rdi
movq 0xe4af(%rip), %rcx      # 0x15f40
movq (%rcx), %rcx
movq (%rcx,%rdi,8), %rcx
testb %al, %al
je 0x7ae2
incq 0x18(%rcx)
movq 0x18(%rsp), %rcx
movq 0x8(%rsp), %rax
movl (%rcx,%rax,4), %eax
movl (%rcx,%r14,4), %edx
leal (%rdx,%rax), %ecx
addl $-0x2, %ecx
movslq %ecx, %rcx
addq %rcx, 0x80(%rsp)
movq 0xe4ff(%rip), %rcx      # 0x15fc8
movq (%rcx), %rcx
movl (%rcx,%rdi,4), %esi
addl %esi, %esi
addl %eax, %edx
subl %edx, %esi
addl $-0x2, %esi
movslq %esi, %rax
addq %rax, 0x70(%rsp)
jmp 0x7b2c
movslq %r12d, %rax
incq 0x10(%rcx)
movq 0xe4d8(%rip), %rcx      # 0x15fc8
movq (%rcx), %rcx
movl (%rcx,%rdi,4), %edx
movq 0x18(%rsp), %r8
movq 0x8(%rsp), %rsi
movl (%r8,%rsi,4), %esi
addl %edx, %edx
addl (%r8,%r14,4), %esi
subl %esi, %edx
addl $-0x4, %edx
movslq %edx, %rdx
addq %rdx, 0x78(%rsp)
movl (%rcx,%r13,4), %edx
movl (%rcx,%rax,4), %eax
subl %esi, %edx
addl %edx, %eax
addl $-0x2, %eax
cltq
addq %rax, 0x38(%rsp)
incq %rbx
jmp 0x7a59
movq 0x28(%rsp), %rsi
incq %rsi
movl 0x20(%rsp), %r8d
incl %r8d
jmp 0x7962
xorl %edx, %edx
movq $0x0, 0x58(%rsp)
movq $0x0, 0x20(%rsp)
movq $0x0, 0x28(%rsp)
movq $0x0, 0x8(%rsp)
cltq
cmpq %rax, %rdx
jge 0x7c51
movq (%rbp), %rax
movq (%rax,%rdi,8), %rax
movslq (%rax,%rdx,8), %rbx
movq %rdx, 0x90(%rsp)
movslq 0x4(%rax,%rdx,8), %rax
movq %rax, (%rsp)
xorl %r13d, %r13d
movslq (%rcx,%rbx,4), %rax
cmpq %rax, %r13
jge 0x7c3e
movq (%rbp), %rax
movq (%rax,%rbx,8), %rax
movl (%rax,%r13,8), %r12d
cmpq %r12, %rdi
je 0x7c36
movslq 0x4(%rax,%r13,8), %r14
movl %r12d, %esi
movq 0xe3e1(%rip), %rax      # 0x15fa8
movq %rdi, %r15
callq *(%rax)
movq 0xe3f5(%rip), %rcx      # 0x15fc8
movq (%rcx), %rcx
testb %al, %al
jne 0x7c33
movslq %r12d, %rax
movq 0xe35c(%rip), %rdx      # 0x15f40
movq (%rdx), %rdx
movq (%rdx,%r15,8), %rdx
incq 0x8(%rdx)
movl (%rcx,%rbx,4), %edx
movq 0x18(%rsp), %rdi
movq (%rsp), %rsi
movl (%rdi,%rsi,4), %esi
notl %esi
addl %esi, %edx
decl %edx
movslq %edx, %rdx
addq %rdx, 0x58(%rsp)
movslq (%rdi,%r14,4), %rdx
addq %rdx, 0x20(%rsp)
notl %edx
addl (%rcx,%rax,4), %edx
movslq %edx, %rdx
addq %rdx, 0x28(%rsp)
movq 0x10(%rsp), %rdx
movl (%rdx,%rax,4), %eax
decl %eax
cltq
addq %rax, 0x8(%rsp)
movq %r15, %rdi
incq %r13
jmp 0x7b9a
movq 0x90(%rsp), %rdx
incq %rdx
movl (%rcx,%rdi,4), %eax
jmp 0x7b6f
movq 0xe2e8(%rip), %rax      # 0x15f40
movq (%rax), %rax
movq (%rax,%rdi,8), %rsi
movq 0x88(%rsp), %rcx
movq %rcx, 0x70(%rsi)
imulq $0x6, %rcx, %r9
movq 0x80(%rsp), %r11
movq %r11, %rax
subq %r9, %rax
cqto
pushq $0x2
popq %r8
idivq %r8
movq %rax, 0x68(%rsi)
imulq $-0x3, %rcx, %rax
movq 0x68(%rsp), %r10
addq %r10, %rax
movq %rax, 0x60(%rsi)
movq %r9, %rax
subq %r11, %rax
movq 0x70(%rsp), %rbx
addq %rbx, %rax
cqto
idivq %r8
movq %rax, 0x58(%rsi)
movq 0x60(%rsp), %rax
addq %r9, %rax
subq %r11, %rax
movq %rax, 0x50(%rsi)
movq %r9, %rcx
subq %r10, %rcx
subq %r10, %rcx
movq 0x20(%rsp), %r15
leaq (%rcx,%r15), %rax
cqto
idivq %r8
movq %rax, 0x48(%rsi)
movq 0x8(%rsp), %r14
addq %r14, %rcx
movq %rcx, %rax
cqto
idivq %r8
movq %rax, 0x40(%rsi)
addq %r9, %rbx
subq %rbx, %r11
addq 0x78(%rsp), %r11
movq %r11, %rax
cqto
pushq $0x6
popq %rcx
idivq %rcx
movq %rax, 0x38(%rsi)
movq 0x58(%rsp), %rax
leaq (%rax,%r10,2), %rax
addq %r9, %r15
subq %r15, %rax
cqto
idivq %r8
movq %rax, 0x30(%rsi)
addq %r9, %r14
movq 0x38(%rsp), %rax
leaq (%rax,%r10,2), %rax
subq %r14, %rax
movq %rax, 0x28(%rsi)
movq 0x28(%rsp), %rax
leaq (%rax,%r10,2), %rax
subq %r14, %rax
movq %rax, 0x20(%rsi)
incq %rdi
movq 0xe252(%rip), %rax      # 0x15fa0
movl (%rax), %ebx
jmp 0x78ad
callq 0x7110
movq 0x18(%rsp), %rdi
callq 0x7220
movq 0x50(%rsp), %rdi
callq 0x7220
movq 0x40(%rsp), %rdi
callq 0x7220
movq 0x10(%rsp), %rdi
callq 0x7220
movq 0x48(%rsp), %rdi
addq $0x98, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x7220