// File: /workspace/github_cpp_makefile_star2_O2/qema[P]orca-py/liborca.cpp
// Function: motif_counts(char const*, int, char const*, char const*, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>&)
int motif_counts(const char* orbit_type, int graphlet_size, 
        const char* input_str, const char* output_filename, string &out_str) {
    common2.clear();
    common3.clear();
    bool use_adj_matrix;
    //fstream fin; // input and output files
    stringstream fin(input_str);
    // open input, output files
    if (strcmp(orbit_type, "node")!=0 && strcmp(orbit_type, "edge")!=0) {
        cerr << "Incorrect orbit type '" << orbit_type << "'. Should be 'node' or 'edge'." << endl;
        return 0;
    }
    if (graphlet_size!=4 && graphlet_size!=5) {
        cerr << "Incorrect graphlet size " << graphlet_size << ". Should be 4 or 5." << endl;
        return 0;
    }
    //fin.open(input_filename, fstream::in);
    if (fin.fail()) {
        //cerr << "Failed to open file " << input_filename << endl;
        cerr << "Failed to open string stream" << endl;
        return 0;
    }
    // read input graph
    fin >> n >> m;
    //cout << n << " " << m;
    int d_max=0;
    edges = (PAIR*)malloc(m*sizeof(PAIR));
    deg = (int*)calloc(n,sizeof(int));
    for (int i=0;i<m;i++) {
        int a,b;
        fin >> a >> b;
        if (!(0<=a && a<n) || !(0<=b && b<n)) {
            cerr << "Node ids should be between 1 and n-1." << endl;
            return 0;
        }
        if (a==b) {
            cerr << "Self loops (edge from x to x) are not allowed." << endl;
            return 0;
        }
        deg[a]++; deg[b]++;
        edges[i]=PAIR(a,b);
    }
    for (int i=0;i<n;i++) d_max=max(d_max,deg[i]);
    //printf("nodes: %d\n",n);
    //printf("edges: %d\n",m);
    //printf("max degree: %d\n",d_max);
    //fin.close();
    if ((int)(set<PAIR>(edges,edges+m).size())!=m) {
        cerr << "Input file contains duplicate undirected edges." << endl;
        return 0;
    }
    // set up adjacency matrix if it's smaller than 100MB
    if ((int64)n*n < 100LL*1024*1024*8) {
        use_adj_matrix = true;
        adjacent = adjacent_matrix;
        adj_matrix = (int*)calloc((n*n)/adj_chunk+1,sizeof(int));
        for (int i=0;i<m;i++) {
            int a=edges[i].a, b=edges[i].b;
            adj_matrix[(a*n+b)/adj_chunk]|=(1<<((a*n+b)%adj_chunk));
            adj_matrix[(b*n+a)/adj_chunk]|=(1<<((b*n+a)%adj_chunk));
        }
    } else {
        use_adj_matrix = false;
        adjacent = adjacent_list;
    }
    // set up adjacency, incidence lists
    adj = (int**)malloc(n*sizeof(int*));
    for (int i=0;i<n;i++) adj[i] = (int*)malloc(deg[i]*sizeof(int));
    inc = (PII**)malloc(n*sizeof(PII*));
    for (int i=0;i<n;i++) inc[i] = (PII*)malloc(deg[i]*sizeof(PII));
    int *d = (int*)calloc(n,sizeof(int));
    for (int i=0;i<m;i++) {
        int a=edges[i].a, b=edges[i].b;
        adj[a][d[a]]=b; adj[b][d[b]]=a;
        inc[a][d[a]]=PII(b,i); inc[b][d[b]]=PII(a,i);
        d[a]++; d[b]++;
    }
    for (int i=0;i<n;i++) {
        sort(adj[i],adj[i]+deg[i]);
        sort(inc[i],inc[i]+deg[i]);
    }
    // initialize orbit counts
    orbit = (int64**)malloc(n*sizeof(int64*));
    for (int i=0;i<n;i++) orbit[i] = (int64*)calloc(73,sizeof(int64));
    // initialize edge orbit counts
    eorbit = (int64**)malloc(m*sizeof(int64*));
    for (int i=0;i<m;i++) eorbit[i] = (int64*)calloc(68,sizeof(int64));

    if (strcmp(orbit_type,"node") == 0) {
        //printf("Counting NODE orbits of graphlets on %d nodes.\n\n",graphlet_size);
        if (graphlet_size==4) count4();
        if (graphlet_size==5) count5();
        if (strcmp(output_filename, "std") == 0) {
            cout << "orbit counts: \n" << writeResultsString(graphlet_size) << endl;
        } else {
            //out_str = writeResults(graphlet_size, output_filename);
            out_str = writeResultsString(graphlet_size);
        }
    } else {
        //printf("Counting EDGE orbits of graphlets on %d nodes.\n\n",graphlet_size);
        if (graphlet_size==4) ecount4();
        if (graphlet_size==5) ecount5();
        if (strcmp(output_filename, "std") == 0) {
            cout << "orbit counts: \n" << writeEdgeResultsString(graphlet_size) << endl;
        } else {
            //out_str = writeEdgeResults(graphlet_size, output_filename);
            out_str = writeEdgeResultsString(graphlet_size);
        }
    }

    free(edges);
    free(deg);
    free(d);
    if (use_adj_matrix) {
        free(adj_matrix);
    } else {
        for (int i=0;i<n;i++) free(adj[i]);
        free(adj);
    }
    for (int i=0;i<n;i++) free(inc[i]);
    free(inc);
    for (int i=0;i<n;i++) free(orbit[i]);
    free(orbit);
    for (int i=0;i<m;i++) free(eorbit[i]);
    free(eorbit);
    return 1;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x1e8, %rsp            # imm = 0x1E8
movq %r8, %r12
movq %rcx, %r13
movq %rdx, %r14
movl %esi, %r15d
movq %rdi, %rbx
movq %fs:0x28, %rax
movq %rax, 0x1e0(%rsp)
movq 0x6c30(%rip), %rdi      # 0x15fb0
callq 0xfe78
movq 0x6bf4(%rip), %rdi      # 0x15f80
callq 0xff2c
leaq 0x28(%rsp), %rdi
leaq 0x24(%rsp), %rdx
movq %r14, %rsi
callq 0xfddc
leaq 0x58(%rsp), %rdi
leaq 0x28(%rsp), %rsi
pushq $0x18
popq %rdx
callq 0x72c0
leaq 0x28(%rsp), %rdi
callq 0x7338
leaq 0x2c9f(%rip), %rsi      # 0x12065
movq %rbx, %rdi
callq 0x7270
testl %eax, %eax
je 0xf40f
leaq 0x2c91(%rip), %rsi      # 0x1206a
movq %rbx, %rdi
callq 0x7270
testl %eax, %eax
je 0xf40f
movq 0x6c04(%rip), %rdi      # 0x15ff0
leaq 0x2c7c(%rip), %rsi      # 0x1206f
callq 0x71c0
movq %rax, %rdi
movq %rbx, %rsi
callq 0x71c0
movq %rax, %rdi
leaq 0x2c79(%rip), %rsi      # 0x12086
jmp 0xf460
leal -0x6(%r15), %eax
cmpl $-0x3, %eax
ja 0xf442
movq 0x6bd1(%rip), %rdi      # 0x15ff0
leaq 0x2c7f(%rip), %rsi      # 0x120a5
callq 0x71c0
movq %rax, %rdi
movl %r15d, %esi
callq 0x72f0
movq %rax, %rdi
leaq 0x2c7e(%rip), %rsi      # 0x120be
jmp 0xf460
movq 0x58(%rsp), %rax
movq -0x18(%rax), %rax
testb $0x5, 0x78(%rsp,%rax)
je 0xf4a4
leaq 0x2c79(%rip), %rsi      # 0x120d2
movq 0x6b90(%rip), %rdi      # 0x15ff0
callq 0x71c0
movq %rax, %rdi
callq 0x70c0
xorl %ebp, %ebp
leaq 0x58(%rsp), %rdi
callq 0x7140
movq %fs:0x28, %rax
cmpq 0x1e0(%rsp), %rax
jne 0xfbc8
movl %ebp, %eax
addq $0x1e8, %rsp            # imm = 0x1E8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %r13, 0x8(%rsp)
movq %r12, 0x10(%rsp)
movq 0x6aeb(%rip), %r12      # 0x15fa0
leaq 0x58(%rsp), %rdi
movq %r12, %rsi
callq 0x70e0
movq 0x6a87(%rip), %r14      # 0x15f50
movq %rax, %rdi
movq %r14, %rsi
callq 0x70e0
movq %r15, (%rsp)
movslq (%r14), %r15
movq %r15, %rdi
shlq $0x3, %rdi
callq 0x7260
movq 0x6aca(%rip), %rcx      # 0x15fb8
movq %rax, (%rcx)
movslq (%r12), %rdi
pushq $0x4
popq %rsi
callq 0x7100
movq 0x6ac4(%rip), %rcx      # 0x15fc8
movq %rax, (%rcx)
xorl %r12d, %r12d
leaq 0x58(%rsp), %rbp
leaq 0x28(%rsp), %r13
leaq 0x24(%rsp), %r14
movslq %r15d, %rax
cmpq %rax, %r12
jge 0xf5c0
movq %rbp, %rdi
movq %r13, %rsi
callq 0x70e0
movq 0x6a19(%rip), %r15      # 0x15f50
movq %rax, %rdi
movq %r14, %rsi
callq 0x70e0
movslq 0x28(%rsp), %rax
testq %rax, %rax
js 0xf5b4
movq 0x6a4d(%rip), %rcx      # 0x15fa0
movl (%rcx), %edx
cmpl %edx, %eax
jge 0xf5b4
movl 0x24(%rsp), %ecx
testl %ecx, %ecx
js 0xf5b4
cmpl %edx, %ecx
jge 0xf5b4
cmpl %ecx, %eax
je 0xf6b9
movq 0x6a54(%rip), %rcx      # 0x15fc8
movq (%rcx), %rcx
incl (%rcx,%rax,4)
movslq 0x24(%rsp), %rax
incl (%rcx,%rax,4)
movl 0x28(%rsp), %eax
movl 0x24(%rsp), %ecx
cmpl %eax, %ecx
movl %eax, %edx
cmovll %ecx, %edx
cmovll %eax, %ecx
movq 0x6a1d(%rip), %rax      # 0x15fb8
movq (%rax), %rax
shlq $0x20, %rcx
orq %rcx, %rdx
movq %rdx, (%rax,%r12,8)
incq %r12
movl (%r15), %r15d
jmp 0xf519
leaq 0x2b34(%rip), %rsi      # 0x120ef
jmp 0xf6c0
movq 0x69f1(%rip), %rcx      # 0x15fb8
movq (%rcx), %rsi
leaq (%rsi,%rax,8), %rdx
leaq 0x28(%rsp), %rdi
callq 0xfe18
movq 0x6971(%rip), %r15      # 0x15f50
movl (%r15), %ebp
leaq 0x28(%rsp), %rdi
movl 0x28(%rdi), %r14d
callq 0xffb8
cmpl %r14d, %ebp
jne 0xf6d9
movq 0x69a0(%rip), %rax      # 0x15fa0
movslq (%rax), %r12
movq %r12, %rax
imulq %r12, %rax
movq %rax, 0x18(%rsp)
cmpq $0x31ffffff, %rax       # imm = 0x31FFFFFF
ja 0xf6f9
leaq -0x807b(%rip), %rax     # 0x75a7
movq 0x697f(%rip), %rcx      # 0x15fa8
movq %rax, (%rcx)
movl %r12d, %eax
imull %r12d, %eax
pushq $0x20
popq %rbp
cltd
idivl %ebp
incl %eax
movslq %eax, %rdi
pushq $0x4
popq %rsi
callq 0x7100
movq %rax, %rsi
movq 0x6938(%rip), %rax      # 0x15f88
movq %rsi, (%rax)
movl (%r15), %r8d
movq 0x695b(%rip), %rax      # 0x15fb8
movq (%rax), %r9
xorl %r10d, %r10d
testl %r8d, %r8d
cmovlel %r10d, %r8d
pushq $0x1
popq %r11
cmpq %r10, %r8
je 0xf70a
movl (%r9,%r10,8), %r14d
movl 0x4(%r9,%r10,8), %edi
movl %r12d, %eax
imull %r14d, %eax
addl %edi, %eax
movl %r11d, %r15d
movl %eax, %ecx
shll %cl, %r15d
cltd
idivl %ebp
cltq
orl %r15d, (%rsi,%rax,4)
imull %r12d, %edi
addl %r14d, %edi
movl %r11d, %r14d
movl %edi, %ecx
shll %cl, %r14d
movl %edi, %eax
cltd
idivl %ebp
cltq
orl %r14d, (%rsi,%rax,4)
incq %r10
jmp 0xf66e
leaq 0x2a55(%rip), %rsi      # 0x12115
movq 0x6929(%rip), %rdi      # 0x15ff0
callq 0x71c0
movq %rax, %rdi
callq 0x70c0
jmp 0xf46d
movq 0x6910(%rip), %rdi      # 0x15ff0
leaq 0x2a5d(%rip), %rsi      # 0x12144
callq 0x71c0
movq %rax, %rdi
callq 0x70c0
jmp 0xf46d
leaq -0x81b4(%rip), %rax     # 0x754c
movq 0x68a1(%rip), %rcx      # 0x15fa8
movq %rax, (%rcx)
leaq (,%r12,8), %r14
movq %r14, %rdi
callq 0x7260
movq 0x6877(%rip), %rcx      # 0x15f98
movq %rax, (%rcx)
xorl %r15d, %r15d
testl %r12d, %r12d
movl $0x0, %r13d
cmovgl %r12d, %r13d
cmpq %r15, %r13
je 0xf763
movq 0x6888(%rip), %rax      # 0x15fc8
movq (%rax), %rax
movslq (%rax,%r15,4), %rdi
shlq $0x2, %rdi
callq 0x7260
movq 0x6841(%rip), %rcx      # 0x15f98
movq (%rcx), %rcx
movq %rax, (%rcx,%r15,8)
incq %r15
jmp 0xf734
movq %r14, %rdi
callq 0x7260
movq 0x681e(%rip), %rcx      # 0x15f90
movq %rax, (%rcx)
xorl %r14d, %r14d
movq 0x67d1(%rip), %r15      # 0x15f50
movq 0x681a(%rip), %rbp      # 0x15fa0
cmpq %r14, %r13
je 0xf7b5
movq 0x6836(%rip), %rax      # 0x15fc8
movq (%rax), %rax
movslq (%rax,%r14,4), %rdi
shlq $0x3, %rdi
callq 0x7260
movq 0x67e7(%rip), %rcx      # 0x15f90
movq (%rcx), %rcx
movq %rax, (%rcx,%r14,8)
incq %r14
jmp 0xf786
pushq $0x4
popq %rsi
movq %r12, %rdi
callq 0x7100
movq %rax, %r12
movq 0x67ee(%rip), %rax      # 0x15fb8
movq (%rax), %rax
movq 0x67c4(%rip), %rcx      # 0x15f98
movq (%rcx), %rcx
movq 0x67b2(%rip), %rdx      # 0x15f90
movq (%rdx), %rdx
xorl %esi, %esi
movslq (%r15), %rdi
cmpq %rdi, %rsi
jge 0xf837
movslq (%rax,%rsi,8), %rdi
movslq 0x4(%rax,%rsi,8), %r8
movq (%rcx,%rdi,8), %r9
movslq (%r12,%rdi,4), %r10
movl %r8d, (%r9,%r10,4)
movq (%rcx,%r8,8), %r9
movslq (%r12,%r8,4), %r11
movl %edi, (%r9,%r11,4)
movq (%rdx,%rdi,8), %r9
movl %r8d, (%r9,%r10,8)
movl %esi, 0x4(%r9,%r10,8)
movq (%rdx,%r8,8), %r9
movl %edi, (%r9,%r11,8)
movl %esi, 0x4(%r9,%r11,8)
leal 0x1(%r10), %r9d
movl %r9d, (%r12,%rdi,4)
incl (%r12,%r8,4)
incq %rsi
jmp 0xf7e3
xorl %r14d, %r14d
movq 0x6787(%rip), %r15      # 0x15fc8
movslq (%rbp), %r13
cmpq %r13, %r14
jge 0xf88b
movq 0x6747(%rip), %rax      # 0x15f98
movq (%rax), %rax
movq (%rax,%r14,8), %rdi
movq (%r15), %rax
movslq (%rax,%r14,4), %rax
leaq (%rdi,%rax,4), %rsi
callq 0x10cc1
movq 0x6721(%rip), %rax      # 0x15f90
movq (%rax), %rax
movq (%rax,%r14,8), %rdi
movq (%r15), %rax
movslq (%rax,%r14,4), %rax
leaq (%rdi,%rax,8), %rsi
callq 0x11138
incq %r14
jmp 0xf841
movq %r13, %rdi
shlq $0x3, %rdi
callq 0x7260
movq 0x66a2(%rip), %rcx      # 0x15f40
movq %rax, (%rcx)
xorl %r15d, %r15d
testl %r13d, %r13d
movl $0x0, %ebp
cmovgl %r13d, %ebp
pushq $0x49
popq %r14
pushq $0x8
popq %r13
cmpq %r15, %rbp
je 0xf8db
movq %r14, %rdi
movq %r13, %rsi
callq 0x7100
movq 0x6671(%rip), %rcx      # 0x15f40
movq (%rcx), %rcx
movq %rax, (%rcx,%r15,8)
incq %r15
jmp 0xf8b8
movq 0x666e(%rip), %rax      # 0x15f50
movslq (%rax), %r14
movq %r14, %rdi
shlq $0x3, %rdi
callq 0x7260
movq 0x6668(%rip), %rcx      # 0x15f60
movq %rax, (%rcx)
xorl %r15d, %r15d
testl %r14d, %r14d
movl $0x0, %ebp
cmovgl %r14d, %ebp
pushq $0x44
popq %r14
pushq $0x8
popq %r13
cmpq %r15, %rbp
je 0xf935
movq %r14, %rdi
movq %r13, %rsi
callq 0x7100
movq 0x6637(%rip), %rcx      # 0x15f60
movq (%rcx), %rcx
movq %rax, (%rcx,%r15,8)
incq %r15
jmp 0xf912
leaq 0x2729(%rip), %rsi      # 0x12065
movq %rbx, %rdi
callq 0x7270
testl %eax, %eax
je 0xf972
movq (%rsp), %r13
cmpl $0x5, %r13d
movq 0x65f9(%rip), %r14      # 0x15f50
movq 0x6642(%rip), %r15      # 0x15fa0
movq 0x10(%rsp), %rbp
je 0xf99c
cmpl $0x4, %r13d
jne 0xf9a1
callq 0x7d9d
jmp 0xf9a1
movq (%rsp), %r13
cmpl $0x5, %r13d
movq 0x65cf(%rip), %r14      # 0x15f50
movq 0x6618(%rip), %r15      # 0x15fa0
movq 0x10(%rsp), %rbp
je 0xf9ff
cmpl $0x4, %r13d
jne 0xfa04
callq 0x7650
jmp 0xfa04
callq 0xb63f
leaq 0x27cc(%rip), %rsi      # 0x12174
movq 0x8(%rsp), %rdi
callq 0x7270
testl %eax, %eax
je 0xf9c5
leaq 0x28(%rsp), %rdi
movl %r13d, %esi
callq 0xf1e0
jmp 0xfa26
movq 0x65f4(%rip), %rdi      # 0x15fc0
leaq 0x27a5(%rip), %rsi      # 0x12178
callq 0x71c0
movq %rax, %rbx
leaq 0x28(%rsp), %rdi
movl %r13d, %esi
callq 0xf1e0
leaq 0x28(%rsp), %rsi
movq %rbx, %rdi
callq 0x7190
movq %rax, %rdi
callq 0x70c0
jmp 0xfa73
callq 0x869d
leaq 0x2769(%rip), %rsi      # 0x12174
movq 0x8(%rsp), %rdi
callq 0x7270
testl %eax, %eax
je 0xfa3b
leaq 0x28(%rsp), %rdi
movl %r13d, %esi
callq 0xef19
leaq 0x28(%rsp), %rbx
movq %rbp, %rdi
movq %rbx, %rsi
callq 0x7230
movq %rbx, %rdi
jmp 0xfa78
movq 0x657e(%rip), %rdi      # 0x15fc0
leaq 0x272f(%rip), %rsi      # 0x12178
callq 0x71c0
movq %rax, %rbx
leaq 0x28(%rsp), %rdi
movl %r13d, %esi
callq 0xef19
leaq 0x28(%rsp), %rsi
movq %rbx, %rdi
callq 0x7190
movq %rax, %rdi
callq 0x70c0
leaq 0x28(%rsp), %rdi
callq 0x7338
movq 0x6534(%rip), %rax      # 0x15fb8
movq (%rax), %rdi
callq 0x7220
movq 0x6535(%rip), %rax      # 0x15fc8
movq (%rax), %rdi
callq 0x7220
movq %r12, %rdi
callq 0x7220
cmpq $0x32000000, 0x18(%rsp) # imm = 0x32000000
jae 0xfb3e
movq 0x64cf(%rip), %rax      # 0x15f88
movq (%rax), %rdi
pushq $0x1
popq %rbp
callq 0x7220
xorl %ebx, %ebx
movslq (%r15), %rax
movq 0x64c0(%rip), %rcx      # 0x15f90
movq (%rcx), %rdi
cmpq %rax, %rbx
jge 0xfae6
movq (%rdi,%rbx,8), %rdi
callq 0x7220
incq %rbx
jmp 0xfac6
callq 0x7220
xorl %ebx, %ebx
movslq (%r15), %rax
movq 0x6449(%rip), %rcx      # 0x15f40
movq (%rcx), %rdi
cmpq %rax, %rbx
jge 0xfb0d
movq (%rdi,%rbx,8), %rdi
callq 0x7220
incq %rbx
jmp 0xfaed
callq 0x7220
xorl %ebx, %ebx
movslq (%r14), %rax
movq 0x6442(%rip), %rcx      # 0x15f60
movq (%rcx), %rdi
cmpq %rax, %rbx
jge 0xfb34
movq (%rdi,%rbx,8), %rdi
callq 0x7220
incq %rbx
jmp 0xfb14
callq 0x7220
jmp 0xf46f
xorl %ebx, %ebx
pushq $0x1
popq %rbp
movslq (%r15), %rax
movq 0x644b(%rip), %rcx      # 0x15f98
movq (%rcx), %rdi
cmpq %rax, %rbx
jge 0xfabf
movq (%rdi,%rbx,8), %rdi
callq 0x7220
incq %rbx
jmp 0xfb43
jmp 0xfba0
jmp 0xfba0
jmp 0xfba0
jmp 0xfb71
jmp 0xfba0
movq %rax, %rbx
leaq 0x28(%rsp), %rdi
callq 0x7338
jmp 0xfba3
jmp 0xfba0
jmp 0xfba0
jmp 0xfba0
jmp 0xfba0
jmp 0xfba0
movq %rax, %rbx
leaq 0x28(%rsp), %rdi
callq 0x7338
jmp 0xfbad
movq %rax, %rbx
jmp 0xfbad
jmp 0xfba0
movq %rax, %rbx
leaq 0x58(%rsp), %rdi
callq 0x7140
movq %fs:0x28, %rax
cmpq 0x1e0(%rsp), %rax
jne 0xfbc8
movq %rbx, %rdi
callq 0x7300
callq 0x7200