// File: /workspace/github_c_makefile_star2_O0/bmottershead[P]DBF2TSV/dbf.c
// Function: DBFAddNativeFieldType
int  DBFAddNativeFieldType(DBFHandle psDBF, const char *pszFieldName,
                           char chType, int nWidth, int nDecimals) {
  char *pszFInfo;
  int i;
  int nOldRecordLength, nOldHeaderLength;
  char *pszRecord;
  char chFieldFill;
  unsigned long nRecordOffset;

  /* make sure that everything is written in .dbf */
  if (!DBFFlushRecord(psDBF))
    return -1;

  /* Do some checking to ensure we can add records to this file. */
  if (nWidth < 1)
    return -1;

  if (nWidth > 255)
    nWidth = 255;
  nOldRecordLength = psDBF->nRecordLength;
  nOldHeaderLength = psDBF->nHeaderLength;

  /* SfRealloc all the arrays larger to hold the additional fields */
  psDBF->nFields++;
  psDBF->panFieldOffset = (int *)SfRealloc(psDBF->panFieldOffset, sizeof(int) * psDBF->nFields);
  psDBF->panFieldSize = (int *) SfRealloc(psDBF->panFieldSize, sizeof(int) * psDBF->nFields);
  psDBF->panFieldDecimals = (int *)SfRealloc(psDBF->panFieldDecimals, sizeof(int) * psDBF->nFields);
  psDBF->pachFieldType = (char *)SfRealloc(psDBF->pachFieldType, sizeof(char) * psDBF->nFields);

  /* Assign the new field information fields. */
  psDBF->panFieldOffset[psDBF->nFields - 1] = psDBF->nRecordLength;
  psDBF->nRecordLength += nWidth;
  psDBF->panFieldSize[psDBF->nFields - 1] = nWidth;
  psDBF->panFieldDecimals[psDBF->nFields - 1] = nDecimals;
  psDBF->pachFieldType[psDBF->nFields - 1] = chType;

  /* Extend the required header information. */
  psDBF->nHeaderLength += 32;
  psDBF->bUpdated = FALSE;
  psDBF->pszHeader = (char *) SfRealloc(psDBF->pszHeader, psDBF->nFields * 32);
  pszFInfo = psDBF->pszHeader + 32 * (psDBF->nFields - 1);
  for (i = 0; i < 32; i++)
    pszFInfo[i] = '\0';
  if ((int) strlen(pszFieldName) < 10)
    strncpy(pszFInfo, pszFieldName, strlen(pszFieldName));
  else
    strncpy(pszFInfo, pszFieldName, 10);
  pszFInfo[11] = psDBF->pachFieldType[psDBF->nFields - 1];
  if (chType == 'C') {
    pszFInfo[16] = (unsigned char) (nWidth % 256);
    pszFInfo[17] = (unsigned char) (nWidth / 256);
  } else {
    pszFInfo[16] = (unsigned char) nWidth;
    pszFInfo[17] = (unsigned char) nDecimals;
  }

  /* Make the current record buffer appropriately larger. */
  psDBF->pszCurrentRecord = (char *) SfRealloc(psDBF->pszCurrentRecord,psDBF->nRecordLength);

  /* we're done if dealing with new .dbf */
  if (psDBF->bNoHeader)
    return (psDBF->nFields - 1);

  /* For existing .dbf file, shift records */
  pszRecord = (char *) malloc(sizeof(char) * psDBF->nRecordLength);
  chFieldFill = DBFGetNullCharacter(chType);

  for (i = psDBF->nRecords - 1; i >= 0; --i) {
    nRecordOffset = nOldRecordLength * (unsigned long) i + nOldHeaderLength;
    fseek(psDBF->fp, nRecordOffset, 0);
    fread(pszRecord, nOldRecordLength, 1, psDBF->fp);
    memset(pszRecord + nOldRecordLength, chFieldFill, nWidth);
    nRecordOffset = psDBF->nRecordLength * (unsigned long) i + psDBF->nHeaderLength;
    fseek(psDBF->fp, nRecordOffset, 0);
    fread(pszRecord, psDBF->nRecordLength, 1, psDBF->fp);
  }

  /* force update of header with new header, record length and new field */
  free(pszRecord);
  psDBF->bNoHeader = TRUE;
  DBFUpdateHeader(psDBF);
  psDBF->nCurrentRecord = -1;
  psDBF->bCurrentRecordModified = FALSE;
  return (psDBF->nFields - 1);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x70, %rsp
movb %dl, %al
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movb %al, -0x19(%rbp)
movl %ecx, -0x20(%rbp)
movl %r8d, -0x24(%rbp)
movq -0x10(%rbp), %rdi
callq 0x17b0
cmpl $0x0, %eax
jne 0x2536
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x292c
cmpl $0x1, -0x20(%rbp)
jge 0x2548
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x292c
cmpl $0xff, -0x20(%rbp)
jle 0x2558
movl $0xff, -0x20(%rbp)
movq -0x10(%rbp), %rax
movl 0xc(%rax), %eax
movl %eax, -0x38(%rbp)
movq -0x10(%rbp), %rax
movl 0x10(%rax), %eax
movl %eax, -0x3c(%rbp)
movq -0x10(%rbp), %rax
movl 0x14(%rax), %ecx
addl $0x1, %ecx
movl %ecx, 0x14(%rax)
movq -0x10(%rbp), %rax
movq 0x18(%rax), %rdi
movq -0x10(%rbp), %rax
movslq 0x14(%rax), %rax
shlq $0x2, %rax
movl %eax, %esi
callq 0x1ff0
movq %rax, %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x18(%rax)
movq -0x10(%rbp), %rax
movq 0x20(%rax), %rdi
movq -0x10(%rbp), %rax
movslq 0x14(%rax), %rax
shlq $0x2, %rax
movl %eax, %esi
callq 0x1ff0
movq %rax, %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x20(%rax)
movq -0x10(%rbp), %rax
movq 0x28(%rax), %rdi
movq -0x10(%rbp), %rax
movslq 0x14(%rax), %rax
shlq $0x2, %rax
movl %eax, %esi
callq 0x1ff0
movq %rax, %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x28(%rax)
movq -0x10(%rbp), %rax
movq 0x30(%rax), %rdi
movq -0x10(%rbp), %rax
movslq 0x14(%rax), %rax
shlq $0x0, %rax
movl %eax, %esi
callq 0x1ff0
movq %rax, %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x30(%rax)
movq -0x10(%rbp), %rax
movl 0xc(%rax), %edx
movq -0x10(%rbp), %rax
movq 0x18(%rax), %rax
movq -0x10(%rbp), %rcx
movl 0x14(%rcx), %ecx
subl $0x1, %ecx
movslq %ecx, %rcx
movl %edx, (%rax,%rcx,4)
movl -0x20(%rbp), %ecx
movq -0x10(%rbp), %rax
addl 0xc(%rax), %ecx
movl %ecx, 0xc(%rax)
movl -0x20(%rbp), %edx
movq -0x10(%rbp), %rax
movq 0x20(%rax), %rax
movq -0x10(%rbp), %rcx
movl 0x14(%rcx), %ecx
subl $0x1, %ecx
movslq %ecx, %rcx
movl %edx, (%rax,%rcx,4)
movl -0x24(%rbp), %edx
movq -0x10(%rbp), %rax
movq 0x28(%rax), %rax
movq -0x10(%rbp), %rcx
movl 0x14(%rcx), %ecx
subl $0x1, %ecx
movslq %ecx, %rcx
movl %edx, (%rax,%rcx,4)
movb -0x19(%rbp), %dl
movq -0x10(%rbp), %rax
movq 0x30(%rax), %rax
movq -0x10(%rbp), %rcx
movl 0x14(%rcx), %ecx
subl $0x1, %ecx
movslq %ecx, %rcx
movb %dl, (%rax,%rcx)
movq -0x10(%rbp), %rax
movl 0x10(%rax), %ecx
addl $0x20, %ecx
movl %ecx, 0x10(%rax)
movq -0x10(%rbp), %rax
movl $0x0, 0x64(%rax)
movq -0x10(%rbp), %rax
movq 0x38(%rax), %rdi
movq -0x10(%rbp), %rax
movl 0x14(%rax), %esi
shll $0x5, %esi
callq 0x1ff0
movq %rax, %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x38(%rax)
movq -0x10(%rbp), %rax
movq 0x38(%rax), %rax
movq -0x10(%rbp), %rcx
movl 0x14(%rcx), %ecx
subl $0x1, %ecx
shll $0x5, %ecx
movslq %ecx, %rcx
addq %rcx, %rax
movq %rax, -0x30(%rbp)
movl $0x0, -0x34(%rbp)
cmpl $0x20, -0x34(%rbp)
jge 0x270b
movq -0x30(%rbp), %rax
movslq -0x34(%rbp), %rcx
movb $0x0, (%rax,%rcx)
movl -0x34(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x34(%rbp)
jmp 0x26ee
movq -0x18(%rbp), %rdi
callq 0x10c0
cmpl $0xa, %eax
jge 0x2744
movq -0x30(%rbp), %rax
movq %rax, -0x68(%rbp)
movq -0x18(%rbp), %rax
movq %rax, -0x60(%rbp)
movq -0x18(%rbp), %rdi
callq 0x10c0
movq -0x68(%rbp), %rdi
movq -0x60(%rbp), %rsi
movq %rax, %rdx
callq 0x1040
jmp 0x2756
movq -0x30(%rbp), %rdi
movq -0x18(%rbp), %rsi
movl $0xa, %edx
callq 0x1040
movq -0x10(%rbp), %rax
movq 0x30(%rax), %rax
movq -0x10(%rbp), %rcx
movl 0x14(%rcx), %ecx
subl $0x1, %ecx
movslq %ecx, %rcx
movb (%rax,%rcx), %cl
movq -0x30(%rbp), %rax
movb %cl, 0xb(%rax)
movsbl -0x19(%rbp), %eax
cmpl $0x43, %eax
jne 0x27a8
movl -0x20(%rbp), %eax
movl $0x100, %ecx            # imm = 0x100
cltd
idivl %ecx
movb %dl, %cl
movq -0x30(%rbp), %rax
movb %cl, 0x10(%rax)
movl -0x20(%rbp), %eax
movl $0x100, %ecx            # imm = 0x100
cltd
idivl %ecx
movb %al, %cl
movq -0x30(%rbp), %rax
movb %cl, 0x11(%rax)
jmp 0x27c0
movl -0x20(%rbp), %eax
movb %al, %cl
movq -0x30(%rbp), %rax
movb %cl, 0x10(%rax)
movl -0x24(%rbp), %eax
movb %al, %cl
movq -0x30(%rbp), %rax
movb %cl, 0x11(%rax)
movq -0x10(%rbp), %rax
movq 0x48(%rax), %rdi
movq -0x10(%rbp), %rax
movl 0xc(%rax), %esi
callq 0x1ff0
movq %rax, %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x48(%rax)
movq -0x10(%rbp), %rax
cmpl $0x0, 0x60(%rax)
je 0x27fb
movq -0x10(%rbp), %rax
movl 0x14(%rax), %eax
subl $0x1, %eax
movl %eax, -0x4(%rbp)
jmp 0x292c
movq -0x10(%rbp), %rax
movslq 0xc(%rax), %rdi
shlq $0x0, %rdi
callq 0x1140
movq %rax, -0x48(%rbp)
movsbl -0x19(%rbp), %edi
callq 0x2940
movb %al, -0x49(%rbp)
movq -0x10(%rbp), %rax
movl 0x8(%rax), %eax
subl $0x1, %eax
movl %eax, -0x34(%rbp)
cmpl $0x0, -0x34(%rbp)
jl 0x28ec
movslq -0x38(%rbp), %rax
movslq -0x34(%rbp), %rcx
imulq %rcx, %rax
movslq -0x3c(%rbp), %rcx
addq %rcx, %rax
movq %rax, -0x58(%rbp)
movq -0x10(%rbp), %rax
movq (%rax), %rdi
movq -0x58(%rbp), %rsi
xorl %edx, %edx
callq 0x1160
movq -0x48(%rbp), %rdi
movslq -0x38(%rbp), %rsi
movq -0x10(%rbp), %rax
movq (%rax), %rcx
movl $0x1, %edx
callq 0x1090
movq -0x48(%rbp), %rdi
movslq -0x38(%rbp), %rax
addq %rax, %rdi
movsbl -0x49(%rbp), %eax
movslq -0x20(%rbp), %rdx
movzbl %al, %esi
callq 0x10e0
movq -0x10(%rbp), %rax
movslq 0xc(%rax), %rax
movslq -0x34(%rbp), %rcx
imulq %rcx, %rax
movq -0x10(%rbp), %rcx
movslq 0x10(%rcx), %rcx
addq %rcx, %rax
movq %rax, -0x58(%rbp)
movq -0x10(%rbp), %rax
movq (%rax), %rdi
movq -0x58(%rbp), %rsi
xorl %edx, %edx
callq 0x1160
movq -0x48(%rbp), %rdi
movq -0x10(%rbp), %rax
movslq 0xc(%rax), %rsi
movq -0x10(%rbp), %rax
movq (%rax), %rcx
movl $0x1, %edx
callq 0x1090
movl -0x34(%rbp), %eax
addl $-0x1, %eax
movl %eax, -0x34(%rbp)
jmp 0x2829
movq -0x48(%rbp), %rdi
callq 0x1030
movq -0x10(%rbp), %rax
movl $0x1, 0x60(%rax)
movq -0x10(%rbp), %rdi
callq 0x1570
movq -0x10(%rbp), %rax
movl $0xffffffff, 0x40(%rax) # imm = 0xFFFFFFFF
movq -0x10(%rbp), %rax
movl $0x0, 0x44(%rax)
movq -0x10(%rbp), %rax
movl 0x14(%rax), %eax
subl $0x1, %eax
movl %eax, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x70, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)