// File: /workspace/github_c_makefile_star2_O1/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 $0x4b8, %rsp            # imm = 0x4B8
movq %rdx, %r15
movq %rsi, %r14
movq %rdi, %rbx
movl $0x0, (%rsi)
movq $0x0, (%rdx)
leaq 0x3d841(%rip), %rsi     # 0x44c6f
callq 0x36f0
testq %rax, %rax
je 0x754f
movq %rax, %r12
movq %r15, 0x10(%rsp)
movq %r14, 0x18(%rsp)
movq %rbx, (%rsp)
xorl %r14d, %r14d
movl $0x8, %esi
xorl %edi, %edi
callq 0x3610
movq %rax, 0x8(%rsp)
leaq 0xb0(%rsp), %rbp
movq %rbp, %rdi
movl $0x400, %esi            # imm = 0x400
movq %r12, %rdx
callq 0x3280
testq %rax, %rax
je 0x7519
movq %rbp, %rdi
callq 0x3360
movq %rax, %rbx
movl %ebx, %r15d
movl %ebx, %r13d
sarl $0x1f, %r13d
andl %ebx, %r13d
incl %ebx
testl %r15d, %r15d
jle 0x74c0
callq 0x33c0
movq (%rax), %rax
movsbq 0xaf(%rsp,%r15), %rcx
decq %r15
decl %ebx
testb $0x20, 0x1(%rax,%rcx,2)
jne 0x749c
jmp 0x74c3
movl %r13d, %ebx
testl %ebx, %ebx
je 0x7469
movslq %ebx, %rax
movb $0x0, 0xb0(%rsp,%rax)
movq %rbp, %rdi
leaq 0x20(%rsp), %rsi
callq 0x3380
testl %eax, %eax
jne 0x757c
leaq 0x1(%r14), %rbx
leaq 0x8(,%r14,8), %rsi
movq 0x8(%rsp), %rdi
callq 0x3720
movq %rax, %r15
movq %rbp, %rdi
callq 0x3570
movq %r15, 0x8(%rsp)
movq %rax, (%r15,%r14,8)
movq %rbx, %r14
jmp 0x7469
movq %r12, %rdi
callq 0x3640
testq %r14, %r14
je 0x7559
movq 0x10(%rsp), %rax
movq 0x8(%rsp), %rcx
movq %rcx, (%rax)
movq 0x18(%rsp), %rax
movl %r14d, (%rax)
xorl %eax, %eax
addq $0x4b8, %rsp            # imm = 0x4B8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rbx, %rdi
callq 0x38d3
jmp 0x7575
movq 0x47a88(%rip), %rax     # 0x4efe8
movq (%rax), %rdi
leaq 0x36f54(%rip), %rsi     # 0x3e4be
movq (%rsp), %rdx
xorl %eax, %eax
callq 0x3750
movl $0x1, %eax
jmp 0x753d
testl %ebx, %ebx
jle 0x75a4
callq 0x33c0
movq (%rax), %rax
movl %ebx, %ecx
xorl %edx, %edx
movsbq 0xb0(%rsp,%rdx), %rsi
testb $0x40, 0x1(%rax,%rsi,2)
je 0x75ca
incq %rdx
cmpq %rdx, %rcx
jne 0x758c
movq 0x47a3d(%rip), %rax     # 0x4efe8
movq (%rax), %rdi
leaq 0x36e8b(%rip), %rsi     # 0x3e440
leaq 0xb0(%rsp), %rcx
movq (%rsp), %rdx
xorl %eax, %eax
callq 0x3750
jmp 0x7575
movq 0x47a17(%rip), %rax     # 0x4efe8
movq (%rax), %rdi
leaq 0x36e9e(%rip), %rsi     # 0x3e479
jmp 0x756a