// File: /workspace/github_c_makefile_star2_O0/bmottershead[P]DBF2TSV/dbf2tsv.c
// Function: main
int main(int argc, char **argv){
  DBFHandle dbf_file = NULL; 
  int       width, decimals, i, r;
  char      title[12];
  char      fmt[12];

  // Check that there is one argument, the input filename
  if (argc!=2) {
    fprintf(stderr, "Usage: dbf2tsv dbf-file\n");
    return EXIT_FAILURE;
  }

  // Open the DBF file.
  dbf_file = DBFOpen(argv[1], "rb");
  if (dbf_file == NULL) {
    fprintf(stderr, "%s can't be read or is not a DBF file\n", argv[1]);
    return EXIT_FAILURE;
  }
    
  // Header row. Prints names of fields, tab-separated.
  for (i = 0; i < DBFGetFieldCount(dbf_file); i++ ) {
    DBFGetFieldInfo(dbf_file, i, title, &width, &decimals);
    if (i>0)
      printf(FS);
    printf("%s", title);
  }
  printf(RS);

  // Data rows. Prints values of fields, tab-separated.
  for (r = 0; r < DBFGetRecordCount(dbf_file); r++) {
    for (i = 0; i < DBFGetFieldCount(dbf_file); i++) {
      if (i>0)
        printf(FS);
      if (!DBFIsAttributeNULL(dbf_file, r, i)) {
        switch (DBFGetFieldInfo(dbf_file, i, title, &width, &decimals)) {
        case FTString:
          // String values not quoted, which will be a problem if 
          // a field value includes a tab.
          printf("%s", DBFReadStringAttribute(dbf_file,r,i));
          break;
        case FTInteger:
          printf("%d", DBFReadIntegerAttribute(dbf_file,r,i));
          break;
        case FTDouble:
          sprintf(fmt,"%%%d.%df",width, decimals);
          printf(fmt, DBFReadDoubleAttribute(dbf_file,r,i));
          break;
        default:
          break;
        }
      }
    }
    printf(RS);
    fflush( stdout );
  }

  // Finished
  DBFClose(dbf_file);
  return EXIT_SUCCESS;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x60, %rsp
movl $0x0, -0x4(%rbp)
movl %edi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq $0x0, -0x18(%rbp)
cmpl $0x2, -0x8(%rbp)
je 0x1328
movq 0x5ced(%rip), %rax      # 0x6ff8
movq (%rax), %rdi
leaq 0x3cef(%rip), %rsi      # 0x5004
movb $0x0, %al
callq 0x1120
movl $0x1, -0x4(%rbp)
jmp 0x1560
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rdi
leaq 0x3ce6(%rip), %rsi      # 0x501d
callq 0x18a0
movq %rax, -0x18(%rbp)
cmpq $0x0, -0x18(%rbp)
jne 0x1373
movq 0x5caa(%rip), %rax      # 0x6ff8
movq (%rax), %rdi
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rdx
leaq 0x3cc0(%rip), %rsi      # 0x5020
movb $0x0, %al
callq 0x1120
movl $0x1, -0x4(%rbp)
jmp 0x1560
movl $0x0, -0x24(%rbp)
movl -0x24(%rbp), %eax
movl %eax, -0x44(%rbp)
movq -0x18(%rbp), %rdi
callq 0x2e70
movl %eax, %ecx
movl -0x44(%rbp), %eax
cmpl %ecx, %eax
jge 0x13db
movq -0x18(%rbp), %rdi
movl -0x24(%rbp), %esi
leaq -0x34(%rbp), %rdx
leaq -0x1c(%rbp), %rcx
leaq -0x20(%rbp), %r8
callq 0x2eb0
cmpl $0x0, -0x24(%rbp)
jle 0x13be
leaq 0x3c90(%rip), %rdi      # 0x5047
movb $0x0, %al
callq 0x10d0
leaq -0x34(%rbp), %rsi
leaq 0x3c80(%rip), %rdi      # 0x5049
movb $0x0, %al
callq 0x10d0
movl -0x24(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x24(%rbp)
jmp 0x137a
leaq 0x3da6(%rip), %rdi      # 0x5188
movb $0x0, %al
callq 0x10d0
movl $0x0, -0x28(%rbp)
movl -0x28(%rbp), %eax
movl %eax, -0x48(%rbp)
movq -0x18(%rbp), %rdi
callq 0x2e90
movl %eax, %ecx
movl -0x48(%rbp), %eax
cmpl %ecx, %eax
jge 0x1550
movl $0x0, -0x24(%rbp)
movl -0x24(%rbp), %eax
movl %eax, -0x4c(%rbp)
movq -0x18(%rbp), %rdi
callq 0x2e70
movl %eax, %ecx
movl -0x4c(%rbp), %eax
cmpl %ecx, %eax
jge 0x1525
cmpl $0x0, -0x24(%rbp)
jle 0x1443
leaq 0x3c0b(%rip), %rdi      # 0x5047
movb $0x0, %al
callq 0x10d0
movq -0x18(%rbp), %rdi
movl -0x28(%rbp), %esi
movl -0x24(%rbp), %edx
callq 0x2d00
cmpl $0x0, %eax
jne 0x1515
movq -0x18(%rbp), %rdi
movl -0x24(%rbp), %esi
leaq -0x34(%rbp), %rdx
leaq -0x1c(%rbp), %rcx
leaq -0x20(%rbp), %r8
callq 0x2eb0
movl %eax, %ecx
movl %ecx, -0x50(%rbp)
testl %eax, %eax
je 0x1492
jmp 0x147e
movl -0x50(%rbp), %eax
subl $0x1, %eax
je 0x14b4
jmp 0x1488
movl -0x50(%rbp), %eax
subl $0x2, %eax
je 0x14d5
jmp 0x1511
movq -0x18(%rbp), %rdi
movl -0x28(%rbp), %esi
movl -0x24(%rbp), %edx
callq 0x2ca0
movq %rax, %rsi
leaq 0x3b9e(%rip), %rdi      # 0x5049
movb $0x0, %al
callq 0x10d0
jmp 0x1513
movq -0x18(%rbp), %rdi
movl -0x28(%rbp), %esi
movl -0x24(%rbp), %edx
callq 0x2990
movl %eax, %esi
leaq 0x3c41(%rip), %rdi      # 0x510d
movb $0x0, %al
callq 0x10d0
jmp 0x1513
leaq -0x40(%rbp), %rdi
movl -0x1c(%rbp), %edx
movl -0x20(%rbp), %ecx
leaq 0x3b66(%rip), %rsi      # 0x504c
movb $0x0, %al
callq 0x11b0
leaq -0x40(%rbp), %rax
movq %rax, -0x58(%rbp)
movq -0x18(%rbp), %rdi
movl -0x28(%rbp), %esi
movl -0x24(%rbp), %edx
callq 0x2c40
movq -0x58(%rbp), %rdi
movb $0x1, %al
callq 0x10d0
jmp 0x1513
jmp 0x1513
jmp 0x1515
jmp 0x1517
movl -0x24(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x24(%rbp)
jmp 0x1413
leaq 0x3c5c(%rip), %rdi      # 0x5188
movb $0x0, %al
callq 0x10d0
movq 0x5a9e(%rip), %rax      # 0x6fd8
movq (%rax), %rdi
callq 0x1150
movl -0x28(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x28(%rbp)
jmp 0x13f0
movq -0x18(%rbp), %rdi
callq 0x2030
movl $0x0, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x60, %rsp
popq %rbp
retq
nopl (%rax)