// File: /workspace/github_c_makefile_star2_O3/xiongxu[P]bam2bedGraph2/samtools-0.1.19/bam_plcmd.c
// Function: read_file_list
int read_file_list(const char *file_list,int *n,char **argv[])
{
    char buf[MAX_PATH_LEN];
    int len, nfiles = 0;
    char **files = NULL;
    struct stat sb;

    *n = 0;
    *argv = NULL;

    FILE *fh = fopen(file_list,"r");
    if ( !fh )
    {
        fprintf(stderr,"%s: %s\n", file_list,strerror(errno));
        return 1;
    }

    files = calloc(nfiles,sizeof(char*));
    nfiles = 0;
    while ( fgets(buf,MAX_PATH_LEN,fh) ) 
    {
        // allow empty lines and trailing spaces
        len = strlen(buf);
        while ( len>0 && isspace(buf[len-1]) ) len--;
        if ( !len ) continue;

        // check sanity of the file list
        buf[len] = 0;
        if (stat(buf, &sb) != 0)
        {
            // no such file, check if it is safe to print its name
            int i, safe_to_print = 1;
            for (i=0; i<len; i++)
                if (!isprint(buf[i])) { safe_to_print = 0; break; } 
            if ( safe_to_print )
                fprintf(stderr,"The file list \"%s\" appears broken, could not locate: %s\n", file_list,buf);
            else
                fprintf(stderr,"Does the file \"%s\" really contain a list of files and do all exist?\n", file_list);
            return 1;
        }

        nfiles++;
        files = realloc(files,nfiles*sizeof(char*));
        files[nfiles-1] = strdup(buf);
    }
    fclose(fh);
    if ( !nfiles )
    {
        fprintf(stderr,"No files read from %s\n", file_list);
        return 1;
    }
    *argv = files;
    *n    = nfiles;
    return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x4c8, %rsp            # imm = 0x4C8
movq %rdx, %r15
movq %rsi, %r14
movq %rdi, %rbx
movl $0x0, (%rsi)
movq $0x0, (%rdx)
leaq 0x3e74d(%rip), %rsi     # 0x45d4f
callq 0x36f0
movq %rax, 0x18(%rsp)
testq %rax, %rax
je 0x7733
movq %r15, 0x20(%rsp)
movq %r14, 0x28(%rsp)
movq %rbx, 0x8(%rsp)
xorl %r14d, %r14d
movl $0x8, %esi
xorl %edi, %edi
callq 0x3610
movq %rax, 0x10(%rsp)
leaq 0xc0(%rsp), %rbp
movabsq $-0x100000000, %r15     # imm = 0xFFFFFFFF00000000
movq %rbp, %rdi
movl $0x400, %esi            # imm = 0x400
movq 0x18(%rsp), %rdx
callq 0x3280
testq %rax, %rax
je 0x76fb
movq %rbp, %rdi
callq 0x3360
movl %eax, %ebx
shlq $0x20, %rax
movq %rax, %r13
movl %ebx, %r12d
testl %ebx, %ebx
jle 0x76f0
callq 0x33c0
movq (%rax), %rcx
movsbq 0xbf(%rsp,%rbx), %rdx
decq %rbx
leaq (%r15,%r13), %rax
testb $0x20, 0x1(%rcx,%rdx,2)
jne 0x7673
sarq $0x20, %r13
movb $0x0, 0xc0(%rsp,%r13)
movq %rbp, %rdi
leaq 0x30(%rsp), %rsi
callq 0x3380
testl %eax, %eax
jne 0x775c
leaq 0x1(%r14), %rbx
leaq 0x8(,%r14,8), %rsi
movq 0x10(%rsp), %rdi
callq 0x3720
movq %rax, %r12
movq %rbp, %rdi
callq 0x3570
movq %r12, 0x10(%rsp)
movq %rax, (%r12,%r14,8)
movq %rbx, %r14
jmp 0x764a
testq %rbx, %rbx
je 0x764a
jmp 0x769c
movq 0x18(%rsp), %rdi
callq 0x3640
testq %r14, %r14
je 0x773d
movq 0x20(%rsp), %rax
movq 0x10(%rsp), %rcx
movq %rcx, (%rax)
movq 0x28(%rsp), %rax
movl %r14d, (%rax)
xorl %eax, %eax
addq $0x4c8, %rsp            # imm = 0x4C8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rbx, %rdi
callq 0x38d3
jmp 0x77af
movq 0x488a4(%rip), %rax     # 0x4ffe8
movq (%rax), %rdi
leaq 0x37da8(%rip), %rsi     # 0x3f4f6
movq 0x8(%rsp), %rdx
xorl %eax, %eax
callq 0x3750
jmp 0x77af
testl %r12d, %r12d
jle 0x778a
callq 0x33c0
movq (%rax), %rax
andl $0x7fffffff, %r12d      # imm = 0x7FFFFFFF
xorl %ecx, %ecx
movsbq 0xc0(%rsp,%rcx), %rdx
testb $0x40, 0x1(%rax,%rdx,2)
je 0x77b9
incq %rcx
cmpq %rcx, %r12
jne 0x7772
movq 0x48857(%rip), %rax     # 0x4ffe8
movq (%rax), %rdi
leaq 0x37cdd(%rip), %rsi     # 0x3f478
leaq 0xc0(%rsp), %rcx
movq 0x8(%rsp), %rdx
xorl %eax, %eax
callq 0x3750
movl $0x1, %eax
jmp 0x7721
movq 0x48828(%rip), %rax     # 0x4ffe8
movq (%rax), %rdi
leaq 0x37ce7(%rip), %rsi     # 0x3f4b1
jmp 0x774e