// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x30, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movl %edx, -0x14(%rbp)
movl $0x0, -0x18(%rbp)
movl $0x0, -0x1c(%rbp)
movl $0x0, -0x20(%rbp)
movb $0x0, -0x21(%rbp)
movl $0x1, -0x28(%rbp)
movq -0x10(%rbp), %rax
cmpq $0x0, (%rax)
jne 0x1b81
movl $0x1e168, %edi          # imm = 0x1E168
callq 0x1140
movq %rax, %rcx
movq -0x10(%rbp), %rax
movq %rcx, (%rax)
movq -0x10(%rbp), %rax
movq (%rax), %rdi
xorl %esi, %esi
movl $0x1e168, %edx          # imm = 0x1E168
callq 0x10d0
movq -0x8(%rbp), %rdi
callq 0x11d0
movb %al, -0x21(%rbp)
movsbl %al, %ecx
xorl %eax, %eax
cmpl $0x0, %ecx
movb %al, -0x29(%rbp)
je 0x1bda
movq -0x8(%rbp), %rdi
callq 0x1120
movl %eax, %ecx
xorl %eax, %eax
cmpl $0x0, %ecx
movb %al, -0x29(%rbp)
jne 0x1bda
xorl %eax, %eax
cmpl $0x1000, -0x1c(%rbp)    # imm = 0x1000
movb %al, -0x29(%rbp)
jge 0x1bda
cmpl $0x1e, -0x18(%rbp)
setl %al
movb %al, -0x29(%rbp)
movb -0x29(%rbp), %al
testb $0x1, %al
jne 0x1be6
jmp 0x1d0b
movsbl -0x21(%rbp), %eax
cmpl $0xa, %eax
je 0x1bfc
movsbl -0x21(%rbp), %eax
cmpl $0x9, %eax
jne 0x1c83
movl -0x28(%rbp), %ecx
movq -0x10(%rbp), %rax
movq (%rax), %rax
movslq -0x18(%rbp), %rdx
imulq $0x100c, %rdx, %rdx     # imm = 0x100C
addq %rdx, %rax
movl %ecx, (%rax)
movl -0x1c(%rbp), %ecx
movq -0x10(%rbp), %rax
movq (%rax), %rax
movslq -0x18(%rbp), %rdx
imulq $0x100c, %rdx, %rdx     # imm = 0x100C
addq %rdx, %rax
movl %ecx, 0x4(%rax)
cmpl $0x2, -0x28(%rbp)
jne 0x1c52
movl -0x20(%rbp), %ecx
movq -0x10(%rbp), %rax
movq (%rax), %rax
movslq -0x18(%rbp), %rdx
imulq $0x100c, %rdx, %rdx     # imm = 0x100C
addq %rdx, %rax
movl %ecx, 0x8(%rax)
movl -0x18(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x18(%rbp)
movl $0x1, -0x28(%rbp)
movl $0x0, -0x1c(%rbp)
movl $0x0, -0x20(%rbp)
movsbl -0x21(%rbp), %eax
cmpl $0xa, %eax
jne 0x1c7e
jmp 0x1d0b
jmp 0x1d06
movb -0x21(%rbp), %dl
movq -0x10(%rbp), %rax
movq (%rax), %rax
movslq -0x18(%rbp), %rcx
imulq $0x100c, %rcx, %rcx     # imm = 0x100C
addq %rcx, %rax
movl -0x1c(%rbp), %ecx
movl %ecx, %esi
addl $0x1, %esi
movl %esi, -0x1c(%rbp)
movslq %ecx, %rcx
movb %dl, 0xc(%rax,%rcx)
callq 0x11e0
movq (%rax), %rax
movsbl -0x21(%rbp), %ecx
movslq %ecx, %rcx
movzwl (%rax,%rcx,2), %eax
andl $0x800, %eax            # imm = 0x800
cmpl $0x0, %eax
je 0x1cdb
cmpl $0x2, -0x28(%rbp)
jne 0x1cd9
movl -0x20(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x20(%rbp)
jmp 0x1d04
movl -0x28(%rbp), %eax
subl $0x1, %eax
jne 0x1cfb
jmp 0x1ce5
movsbl -0x21(%rbp), %edx
xorl %eax, %eax
movl $0x2, %ecx
cmpl $0x2e, %edx
cmovel %ecx, %eax
movl %eax, -0x28(%rbp)
jmp 0x1d02
movl $0x0, -0x28(%rbp)
jmp 0x1d04
jmp 0x1d06
jmp 0x1b94
cmpl $0x1000, -0x1c(%rbp)    # imm = 0x1000
jl 0x1d2f
movq 0x62dd(%rip), %rax      # 0x7ff8
movq (%rax), %rdi
movl -0x14(%rbp), %edx
leaq 0x442a(%rip), %rsi      # 0x6152
movb $0x0, %al
callq 0x1110
cmpl $0x1e, -0x18(%rbp)
jl 0x1d50
movq 0x62bc(%rip), %rax      # 0x7ff8
movq (%rax), %rdi
movl -0x14(%rbp), %edx
leaq 0x4431(%rip), %rsi      # 0x617a
movb $0x0, %al
callq 0x1110
movl -0x18(%rbp), %eax
addq $0x30, %rsp
popq %rbp
retq
nopl (%rax)