// File: /workspace/github_c_makefile_star2_O1/bmottershead[P]DBF2TSV/tsv2dbf.c
// Function: get_columns
int get_columns(FILE* tsv_file, column** columns, int row) {
  int n=0, width=0, decimals=0;
  char c = 0;
  DBFFieldType type = FTInteger;

  // Initialize columns array.
  if (*columns==NULL)
    *columns = malloc(MAX_COLUMNS*sizeof(column));
  memset(*columns, 0, MAX_COLUMNS*sizeof(column));

  // Split line of TSV file into columns and set type, decimals, and width.
  while ((c=getc(tsv_file)) 
         && !feof(tsv_file) 
         && width<MAX_COLUMN_WIDTH 
         && n<MAX_COLUMNS) {
    if (c==RS || c==FS) {
      (*columns)[n].type = type;
      (*columns)[n].width = width;
      if (type==FTDouble) 
        (*columns)[n].decimals = decimals;
      n++;
      type = FTInteger;
      width = 0;
      decimals = 0;
      if (c==RS)
        break;
    } else {
      (*columns)[n].value[width++] = c;
      if (isdigit(c)) {
        if (type==FTDouble)
          decimals++;
      } else {
        switch(type) {
        case FTInteger:
          type = (c=='.'? FTDouble: FTString);
          break;
        default:
          type = FTString;
        }
      }
    }
  }
  
  if (width>=MAX_COLUMN_WIDTH)
    fprintf(stderr,"Column exceeds maximum width at row %d\n", row);
  if (n>=MAX_COLUMNS)
    fprintf(stderr,"Too many columns at row %d\n", row);
  return  n;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movl %edx, 0xc(%rsp)
movq %rsi, %r14
movq %rdi, %rbx
cmpq $0x0, (%rsi)
jne 0x1919
movl $0x1e168, %edi          # imm = 0x1E168
callq 0x1150
movq %rax, (%r14)
movq (%r14), %rdi
movl $0x1e168, %edx          # imm = 0x1E168
xorl %esi, %esi
callq 0x10d0
movq %rbx, %rdi
callq 0x11e0
movl %eax, %r12d
shll $0x18, %r12d
je 0x1a6f
movl %eax, %r15d
movq %r14, 0x10(%rsp)
movl $0x0, 0x8(%rsp)
movl $0x1, %r14d
xorl %r13d, %r13d
movl $0x0, 0x4(%rsp)
movq %rbx, %rbp
movq %rbx, %rdi
callq 0x1130
testl %eax, %eax
jne 0x1a63
cmpl $0xfff, %r13d           # imm = 0xFFF
jg 0x1a63
movl 0x4(%rsp), %edx
cmpl $0x1d, %edx
jg 0x1a63
movslq %edx, %rax
cmpl $0xa000000, %r12d       # imm = 0xA000000
je 0x19a0
cmpl $0x9000000, %r12d       # imm = 0x9000000
jne 0x19eb
movq 0x10(%rsp), %rcx
movq (%rcx), %rcx
imulq $0x100c, %rax, %rax     # imm = 0x100C
movl %r14d, (%rcx,%rax)
movl %r13d, 0x4(%rcx,%rax)
cmpl $0x2, %r14d
jne 0x19c6
movl 0x8(%rsp), %esi
movl %esi, 0x8(%rcx,%rax)
incl %edx
movl %edx, 0x4(%rsp)
xorl %r13d, %r13d
movl $0x1, %r14d
movl $0x0, 0x8(%rsp)
cmpl $0xa000000, %r12d       # imm = 0xA000000
movq %rbp, %rbx
jne 0x1a4b
jmp 0x1a63
movl %r12d, %ebx
sarl $0x18, %ebx
movslq %r13d, %rcx
incl %r13d
imulq $0x100c, %rax, %rax     # imm = 0x100C
movq 0x10(%rsp), %rdx
addq (%rdx), %rax
movb %r15b, 0xc(%rcx,%rax)
callq 0x11f0
movq (%rax), %rax
movslq %ebx, %rcx
testb $0x8, 0x1(%rax,%rcx,2)
jne 0x1a36
cmpl $0x1, %r14d
jne 0x1a45
xorl %r14d, %r14d
cmpl $0x2e000000, %r12d      # imm = 0x2E000000
sete %r14b
addl %r14d, %r14d
jmp 0x1a48
xorl %eax, %eax
cmpl $0x2, %r14d
sete %al
addl %eax, 0x8(%rsp)
jmp 0x1a48
xorl %r14d, %r14d
movq %rbp, %rbx
movq %rbx, %rdi
callq 0x11e0
movl %eax, %r15d
movl %eax, %r12d
shll $0x18, %r12d
jne 0x195e
cmpl $0x1000, %r13d          # imm = 0x1000
setge %al
jmp 0x1a79
movl $0x0, 0x4(%rsp)
xorl %eax, %eax
testb %al, %al
movl 0x4(%rsp), %ebx
jne 0x1a97
cmpl $0x1e, %ebx
jge 0x1ab5
movl %ebx, %eax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x455a(%rip), %rax      # 0x5ff8
movq (%rax), %rdi
leaq 0x2682(%rip), %rsi      # 0x412a
movl 0xc(%rsp), %edx
xorl %eax, %eax
callq 0x1120
jmp 0x1a81
movq 0x453c(%rip), %rax      # 0x5ff8
movq (%rax), %rdi
leaq 0x268c(%rip), %rsi      # 0x4152
movl 0xc(%rsp), %edx
xorl %eax, %eax
callq 0x1120
jmp 0x1a86