// File: enferex[P]fnplot/main.cc
// Function: main
int main(int argc, char **argv)
{
    int opt;
    FILE *out;
    bool do_callees, do_callers;
    const char *fname, *fn_name, *out_fname;
    CS *cs;
    CSDB *db;
    int depth = 2;

    do_callers = do_callees = false;
    fname = out_fname = fn_name = NULL;

    while ((opt = getopt(argc, argv, "c:d:f:o:hxy")) != -1) {
        switch (opt) {
        case 'c': fname = optarg; break;
        case 'd': depth = atoi(optarg); break;
        case 'f': fn_name = optarg; break;
        case 'o': out_fname = optarg; break;
        case 'x': do_callers = true; break;
        case 'y': do_callees = true; break;
        case 'h': usage(argv[0]); break;
        default: return EXIT_FAILURE;
        }
    }

    if (!fname || !fn_name || depth < 0) {
        fprintf(stderr, "Invalid options, see '-h'\n");
        return EXIT_FAILURE;
    }

    // If the user did not specify callers or callees, do so for them!
    if (!do_callers && !do_callees)
      do_callees = true;

    if (out_fname && !(out = fopen(out_fname, "w"))) {
        fprintf(stderr, "Error opening output file %s: %s\n",
                out_fname, strerror(errno));
        exit(errno);
    }
    else if (!out_fname)
      out = stdout;

    // Load
    try {
        cs = new CS(fname);
    } 
    catch (const char *err) {
        fprintf(stderr, "Error loading cscope database: %s\n", err);
        exit(EXIT_FAILURE);
    }
    db = cs->buildDatabase();

    // Go!
    if (do_callers)
      csPrintCallers(out, db, fn_name, depth);
    if (do_callees)
      csPrintCallees(out, db, fn_name, depth);

    fclose(out);
    return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x90, %rsp
movl $0x0, -0x4(%rbp)
movl %edi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movl $0x2, -0x54(%rbp)
movb $0x0, -0x21(%rbp)
movb $0x0, -0x22(%rbp)
movq $0x0, -0x38(%rbp)
movq $0x0, -0x40(%rbp)
movq $0x0, -0x30(%rbp)
movl -0x8(%rbp), %edi
movq -0x10(%rbp), %rsi
leaq 0x7aa2(%rip), %rdx      # 0xa060
callq 0x2090
movl %eax, -0x14(%rbp)
cmpl $-0x1, %eax
je 0x2663
movl -0x14(%rbp), %eax
addl $-0x63, %eax
movl %eax, %ecx
movq %rcx, -0x78(%rbp)
subl $0x16, %eax
ja 0x2652
movq -0x78(%rbp), %rax
leaq 0x7a19(%rip), %rcx      # 0xa004
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movq 0xd9b5(%rip), %rax      # 0xffb0
movq (%rax), %rax
movq %rax, -0x30(%rbp)
jmp 0x265e
movq 0xd9a5(%rip), %rax      # 0xffb0
movq (%rax), %rdi
callq 0x2380
movl %eax, -0x54(%rbp)
jmp 0x265e
movq 0xd991(%rip), %rax      # 0xffb0
movq (%rax), %rax
movq %rax, -0x38(%rbp)
jmp 0x265e
movq 0xd981(%rip), %rax      # 0xffb0
movq (%rax), %rax
movq %rax, -0x40(%rbp)
jmp 0x265e
movb $0x1, -0x22(%rbp)
jmp 0x265e
movb $0x1, -0x21(%rbp)
jmp 0x265e
movq -0x10(%rbp), %rax
movq (%rax), %rdi
callq 0x2840
jmp 0x265e
movl $0x1, -0x4(%rbp)
jmp 0x2821
jmp 0x25b0
cmpq $0x0, -0x30(%rbp)
je 0x2677
cmpq $0x0, -0x38(%rbp)
je 0x2677
cmpl $0x0, -0x54(%rbp)
jge 0x269b
movq 0xd95a(%rip), %rax      # 0xffd8
movq (%rax), %rdi
leaq 0x79e4(%rip), %rsi      # 0xa06c
movb $0x0, %al
callq 0x2340
movl $0x1, -0x4(%rbp)
jmp 0x2821
testb $0x1, -0x22(%rbp)
jne 0x26ab
testb $0x1, -0x21(%rbp)
jne 0x26ab
movb $0x1, -0x21(%rbp)
cmpq $0x0, -0x40(%rbp)
je 0x2719
movq -0x40(%rbp), %rdi
leaq 0x79ca(%rip), %rsi      # 0xa087
callq 0x22c0
movq %rax, -0x20(%rbp)
cmpq $0x0, %rax
jne 0x2719
movq 0xd905(%rip), %rax      # 0xffd8
movq (%rax), %rax
movq %rax, -0x88(%rbp)
movq -0x40(%rbp), %rax
movq %rax, -0x80(%rbp)
callq 0x2030
movl (%rax), %edi
callq 0x20b0
movq -0x88(%rbp), %rdi
movq -0x80(%rbp), %rdx
movq %rax, %rcx
leaq 0x7983(%rip), %rsi      # 0xa089
movb $0x0, %al
callq 0x2340
callq 0x2030
movl (%rax), %edi
callq 0x22e0
cmpq $0x0, -0x40(%rbp)
jne 0x272e
movq 0xd871(%rip), %rax      # 0xff98
movq (%rax), %rax
movq %rax, -0x20(%rbp)
jmp 0x2730
movl $0x78, %edi
callq 0x2230
movq %rax, -0x90(%rbp)
jmp 0x2743
movq -0x90(%rbp), %rdi
movq -0x30(%rbp), %rsi
callq 0x2870
jmp 0x2755
movq -0x90(%rbp), %rax
movq %rax, -0x48(%rbp)
jmp 0x27d0
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x60(%rbp)
movl %eax, -0x64(%rbp)
jmp 0x278d
movq -0x90(%rbp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x60(%rbp)
movl %eax, -0x64(%rbp)
movl $0x78, %esi
callq 0x2240
movl -0x64(%rbp), %eax
movl $0x1, %ecx
cmpl %ecx, %eax
jne 0x282d
movq -0x60(%rbp), %rdi
callq 0x20d0
movq %rax, -0x70(%rbp)
movq 0xd827(%rip), %rax      # 0xffd8
movq (%rax), %rdi
movq -0x70(%rbp), %rdx
leaq 0x78ec(%rip), %rsi      # 0xa0ab
movb $0x0, %al
callq 0x2340
movl $0x1, %edi
callq 0x22e0
movq -0x48(%rbp), %rdi
callq 0x2fa0
movq %rax, -0x50(%rbp)
testb $0x1, -0x22(%rbp)
je 0x27f7
movq -0x20(%rbp), %rdi
movq -0x50(%rbp), %rsi
movq -0x38(%rbp), %rdx
movl -0x54(%rbp), %ecx
callq 0x32e0
testb $0x1, -0x21(%rbp)
je 0x2811
movq -0x20(%rbp), %rdi
movq -0x50(%rbp), %rsi
movq -0x38(%rbp), %rdx
movl -0x54(%rbp), %ecx
callq 0x34b0
movq -0x20(%rbp), %rdi
callq 0x2220
movl $0x0, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x90, %rsp
popq %rbp
retq
movq -0x60(%rbp), %rdi
callq 0x23e0
nopw %cs:(%rax,%rax)