// File: /workspace/github_c_makefile_star2_O2/jsh58[P]Genrich/Genrich.c
// Function: loadBED
int loadBED(char* xFile, char* line, Bed** xBed) {

  // loop through BED files
  int count = 0;  // count of intervals saved
  char* end;
  char* filename = strtok_r(xFile, COM, &end);
  while (filename) {

    // open BED file
    File in;
    bool gz = openRead(filename, &in);

    // load BED records
    while (getLine(line, MAX_SIZE, in, gz) != NULL) {

      // parse BED record
      char* name = strtok(line, TAB);
      if (name == NULL)
        exit(error(line, ERRBED));
      int pos[2];
      for (int i = 0; i < 2; i++) {
        char* val = strtok(NULL, i ? TABN : TAB);
        if (val == NULL)
          exit(error(line, ERRBED));
        pos[i] = getInt(val);
      }
      if (pos[1] <= pos[0] || pos[0] < 0 || pos[1] < 0) {
        char msg[MAX_ALNS];
        sprintf(msg, "%s, %d - %d", name, pos[0], pos[1]);
        exit(error(msg, ERRBED));
      }

      // save info to xBed array
      *xBed = (Bed*) memrealloc(*xBed, (count + 1) * sizeof(Bed));
      Bed* b = *xBed + count;
      b->name = memalloc(1 + strlen(name));
      strcpy(b->name, name);
      b->pos[0] = pos[0];
      b->pos[1] = pos[1];
      count++;
    }

    // close file
    if ( (gz && gzclose(in.gzf) != Z_OK)
        || (! gz && fclose(in.f)) )
      exit(error(filename, ERRCLOSE));

    filename = strtok_r(NULL, COM, &end);
  }

  return count;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xe8, %rsp
movq %rdx, 0x30(%rsp)
movq %rsi, %r14
leaq 0x442b(%rip), %rsi      # 0x11b18
leaq 0x58(%rsp), %rdx
callq 0x2180
xorl %ebp, %ebp
leaq 0x43b1(%rip), %r15      # 0x11ab1
leaq 0x3ef7(%rip), %r13      # 0x115fe
movq %r14, 0x38(%rsp)
testq %rax, %rax
je 0xd872
movq %rax, 0x28(%rsp)
movq %rax, %rdi
leaq 0x50(%rsp), %rsi
callq 0xd585
movl %eax, %ecx
movq 0x50(%rsp), %rax
movq %rax, 0x10(%rsp)
movslq %ebp, %rbp
movb %cl, 0xf(%rsp)
movzbl %cl, %eax
movl %eax, 0x18(%rsp)
movq %r14, %rdi
movl $0xfff0, %esi           # imm = 0xFFF0
movq 0x10(%rsp), %rdx
movl 0x18(%rsp), %ecx
callq 0x283f
testq %rax, %rax
je 0xd839
movq %r14, %rdi
movq %r15, %rsi
callq 0x2280
testq %rax, %rax
je 0xd8a1
movq %rax, %r12
xorl %ebx, %ebx
cmpq $0x2, %rbx
je 0xd7aa
testq %rbx, %rbx
movq %r13, %rsi
cmoveq %r15, %rsi
xorl %edi, %edi
callq 0x2280
testq %rax, %rax
je 0xd8a1
movq %rax, %rdi
callq 0x27cf
movl %eax, 0x20(%rsp,%rbx,4)
incq %rbx
jmp 0xd779
movl 0x20(%rsp), %ebx
movl 0x24(%rsp), %r8d
cmpl %ebx, %r8d
jle 0xd886
movl %ebx, %eax
orl %r8d, %eax
js 0xd886
movq %r12, 0x40(%rsp)
movq 0x30(%rsp), %r12
movq (%r12), %rdi
leaq 0x1(%rbp), %rsi
movq %rsi, 0x48(%rsp)
shlq $0x4, %rsi
movl %r8d, 0x1c(%rsp)
callq 0x2776
movq %rax, %r14
movq %rax, (%r12)
shlq $0x4, %rbp
movq 0x40(%rsp), %r12
movq %r12, %rdi
callq 0x20f0
leaq 0x1(%rax), %rdi
callq 0x2752
movq %rax, 0x8(%r14,%rbp)
movq %rax, %rdi
movq %r12, %rsi
callq 0x2070
movl %ebx, (%r14,%rbp)
movl 0x1c(%rsp), %eax
movl %eax, 0x4(%r14,%rbp)
movq 0x38(%rsp), %r14
movq 0x48(%rsp), %rbp
jmp 0xd741
cmpb $0x0, 0xf(%rsp)
je 0xd84c
movq 0x10(%rsp), %rdi
callq 0x2030
jmp 0xd856
movq 0x10(%rsp), %rdi
callq 0x20d0
testl %eax, %eax
jne 0xd8b4
xorl %edi, %edi
leaq 0x42b5(%rip), %rsi      # 0x11b18
leaq 0x58(%rsp), %rdx
callq 0x2180
jmp 0xd70c
movl %ebp, %eax
addq $0xe8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x428e(%rip), %rsi      # 0x11b1b
leaq 0x60(%rsp), %r14
movq %r14, %rdi
movq %r12, %rdx
movl %ebx, %ecx
xorl %eax, %eax
callq 0x2290
pushq $0x1c
popq %rsi
movq %r14, %rdi
callq 0x2724
pushq $0x1
popq %rdi
callq 0x22a0
pushq $0x3
popq %rsi
movq 0x28(%rsp), %rdi
jmp 0xd8a7