// File: /workspace/github_c_makefile_star2_O0/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:
subq $0xf8, %rsp
movq %rdi, 0xf0(%rsp)
movq %rsi, 0xe8(%rsp)
movq %rdx, 0xe0(%rsp)
movl $0x0, 0xdc(%rsp)
movq 0xf0(%rsp), %rdi
leaq 0x6652(%rip), %rsi      # 0x1fd7b
leaq 0xd0(%rsp), %rdx
callq 0x2180
movq %rax, 0xc8(%rsp)
cmpq $0x0, 0xc8(%rsp)
je 0x19a0f
movq 0xc8(%rsp), %rdi
leaq 0xc0(%rsp), %rsi
callq 0x194c0
andb $0x1, %al
movb %al, 0xbf(%rsp)
movq 0xe8(%rsp), %rdi
movb 0xbf(%rsp), %al
movq 0xc0(%rsp), %rdx
movl $0xfff0, %esi           # imm = 0xFFF0
andb $0x1, %al
movzbl %al, %ecx
callq 0x2a20
cmpq $0x0, %rax
je 0x19999
movq 0xe8(%rsp), %rdi
leaq 0x655a(%rip), %rsi      # 0x1fd04
callq 0x2280
movq %rax, 0xb0(%rsp)
cmpq $0x0, 0xb0(%rsp)
jne 0x197db
movq 0xe8(%rsp), %rdi
movl $0x1c, %esi
callq 0x2840
movl %eax, %edi
callq 0x22b0
movl $0x0, 0xa4(%rsp)
cmpl $0x2, 0xa4(%rsp)
jge 0x19879
movl 0xa4(%rsp), %ecx
leaq 0x6502(%rip), %rsi      # 0x1fd04
leaq 0x6025(%rip), %rax      # 0x1f82e
cmpl $0x0, %ecx
cmovneq %rax, %rsi
xorl %eax, %eax
movl %eax, %edi
callq 0x2280
movq %rax, 0x98(%rsp)
cmpq $0x0, 0x98(%rsp)
jne 0x19845
movq 0xe8(%rsp), %rdi
movl $0x1c, %esi
callq 0x2840
movl %eax, %edi
callq 0x22b0
movq 0x98(%rsp), %rdi
callq 0x2980
movl %eax, %ecx
movslq 0xa4(%rsp), %rax
movl %ecx, 0xa8(%rsp,%rax,4)
movl 0xa4(%rsp), %eax
addl $0x1, %eax
movl %eax, 0xa4(%rsp)
jmp 0x197e6
movl 0xac(%rsp), %eax
cmpl 0xa8(%rsp), %eax
jle 0x1989d
cmpl $0x0, 0xa8(%rsp)
jl 0x1989d
cmpl $0x0, 0xac(%rsp)
jge 0x198dd
leaq 0x10(%rsp), %rdi
movq 0xb0(%rsp), %rdx
movl 0xa8(%rsp), %ecx
movl 0xac(%rsp), %r8d
leaq 0x64be(%rip), %rsi      # 0x1fd7e
movb $0x0, %al
callq 0x22a0
leaq 0x10(%rsp), %rdi
movl $0x1c, %esi
callq 0x2840
movl %eax, %edi
callq 0x22b0
movq 0xe0(%rsp), %rax
movq (%rax), %rdi
movl 0xdc(%rsp), %eax
addl $0x1, %eax
movslq %eax, %rsi
shlq $0x4, %rsi
callq 0x28e0
movq %rax, %rcx
movq 0xe0(%rsp), %rax
movq %rcx, (%rax)
movq 0xe0(%rsp), %rax
movq (%rax), %rax
movslq 0xdc(%rsp), %rcx
shlq $0x4, %rcx
addq %rcx, %rax
movq %rax, 0x8(%rsp)
movq 0xb0(%rsp), %rdi
callq 0x20f0
movq %rax, %rdi
addq $0x1, %rdi
callq 0x2890
movq %rax, %rcx
movq 0x8(%rsp), %rax
movq %rcx, 0x8(%rax)
movq 0x8(%rsp), %rax
movq 0x8(%rax), %rdi
movq 0xb0(%rsp), %rsi
callq 0x2070
movl 0xa8(%rsp), %ecx
movq 0x8(%rsp), %rax
movl %ecx, (%rax)
movl 0xac(%rsp), %ecx
movq 0x8(%rsp), %rax
movl %ecx, 0x4(%rax)
movl 0xdc(%rsp), %eax
addl $0x1, %eax
movl %eax, 0xdc(%rsp)
jmp 0x1976b
testb $0x1, 0xbf(%rsp)
je 0x199b5
movq 0xc0(%rsp), %rdi
callq 0x2030
cmpl $0x0, %eax
jne 0x199d1
testb $0x1, 0xbf(%rsp)
jne 0x199ea
movq 0xc0(%rsp), %rdi
callq 0x20d0
cmpl $0x0, %eax
je 0x199ea
movq 0xc8(%rsp), %rdi
movl $0x3, %esi
callq 0x2840
movl %eax, %edi
callq 0x22b0
xorl %eax, %eax
movl %eax, %edi
leaq 0x6386(%rip), %rsi      # 0x1fd7b
leaq 0xd0(%rsp), %rdx
callq 0x2180
movq %rax, 0xc8(%rsp)
jmp 0x1973e
movl 0xdc(%rsp), %eax
addq $0xf8, %rsp
retq
nop