// File: /workspace/github_c_makefile_star2_O3/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, 0x38(%rsp)
movq %rsi, %r13
leaq 0x4c85(%rip), %rsi      # 0x13bc8
leaq 0x58(%rsp), %rdx
callq 0x2190
xorl %ebx, %ebx
testq %rax, %rax
je 0xf0f5
leaq 0x4c02(%rip), %rbp      # 0x13b61
leaq 0x4748(%rip), %r15      # 0x136ae
leaq 0x18(%rsp), %r12
movq %r13, 0x30(%rsp)
movq %rax, 0x28(%rsp)
movq %rax, %rdi
leaq 0x50(%rsp), %rsi
callq 0xedce
movb %al, 0x7(%rsp)
movq 0x50(%rsp), %rax
movq %rax, 0x8(%rsp)
movslq %ebx, %rbx
cmpb $0x0, 0x7(%rsp)
je 0xefb6
movq 0x8(%rsp), %rdi
movq %r13, %rsi
movl $0xfff0, %edx           # imm = 0xFFF0
callq 0x2090
testq %rax, %rax
jne 0xefd1
jmp 0xf0cb
movq %r13, %rdi
movl $0xfff0, %esi           # imm = 0xFFF0
movq 0x8(%rsp), %rdx
callq 0x21a0
testq %rax, %rax
je 0xf0bf
movq %r13, %rdi
movq %rbp, %rsi
callq 0x2280
testq %rax, %rax
je 0xf111
movq %rax, 0x20(%rsp)
movq %rbx, 0x48(%rsp)
movb $0x1, %bl
leaq 0x1c(%rsp), %r14
testb $0x1, %bl
movq %r15, %rsi
cmovneq %rbp, %rsi
xorl %edi, %edi
callq 0x2280
testq %rax, %rax
je 0xf109
movq %rax, %rdi
callq 0x3961
movl %eax, (%r14)
movq %r12, %r14
testb $0x1, %bl
movl $0x0, %ebx
jne 0xeff6
movl 0x18(%rsp), %r8d
movl 0x1c(%rsp), %ecx
cmpl %ecx, %r8d
jle 0xf119
movl %ecx, %eax
orl %r8d, %eax
js 0xf119
movq 0x38(%rsp), %r13
movq (%r13), %rdi
movq 0x48(%rsp), %r14
leaq 0x1(%r14), %rsi
movq %rsi, 0x40(%rsp)
shlq $0x4, %rsi
movl %r8d, 0x14(%rsp)
movl %ecx, 0x10(%rsp)
callq 0x3925
movq %rax, %rbx
movq %rax, (%r13)
shlq $0x4, %r14
movq 0x20(%rsp), %r13
movq %r13, %rdi
callq 0x20f0
leaq 0x1(%rax), %rdi
callq 0x3913
movq %rax, 0x8(%rbx,%r14)
movq %rax, %rdi
movq %r13, %rsi
callq 0x2070
movl 0x10(%rsp), %eax
movl %eax, (%rbx,%r14)
movl 0x14(%rsp), %eax
movl %eax, 0x4(%rbx,%r14)
movq 0x40(%rsp), %rbx
movq 0x30(%rsp), %r13
jmp 0xef93
movq 0x8(%rsp), %rdi
callq 0x20d0
jmp 0xf0d5
movq 0x8(%rsp), %rdi
callq 0x2030
testl %eax, %eax
jne 0xf14b
xorl %edi, %edi
leaq 0x4ae6(%rip), %rsi      # 0x13bc8
leaq 0x58(%rsp), %rdx
callq 0x2190
testq %rax, %rax
jne 0xef70
movl %ebx, %eax
addq $0xe8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %r13, %rdi
callq 0x32f4
movq %r13, %rdi
callq 0x3305
leaq 0x4aab(%rip), %rsi      # 0x13bcb
leaq 0x60(%rsp), %rbx
movq %rbx, %rdi
movq 0x20(%rsp), %rdx
xorl %eax, %eax
callq 0x2290
movq %rbx, %rdi
movl $0x1c, %esi
callq 0x22f0
movl $0x1, %edi
callq 0x22a0
movq 0x28(%rsp), %rdi
callq 0x3316