// File: /workspace/github_c_makefile_star2_O0/bmottershead[P]DBF2TSV/dbf.c
// Function: DBFDeleteField
int  DBFDeleteField(DBFHandle psDBF, int iField) {
  int nOldRecordLength, nOldHeaderLength;
  int nDeletedFieldOffset, nDeletedFieldSize;
  unsigned long nRecordOffset;
  char *pszRecord;
  int i, iRecord;

  if (iField < 0 || iField >= psDBF->nFields)
    return FALSE;

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

  /* get information about field to be deleted */
  nOldRecordLength = psDBF->nRecordLength;
  nOldHeaderLength = psDBF->nHeaderLength;
  nDeletedFieldOffset = psDBF->panFieldOffset[iField];
  nDeletedFieldSize = psDBF->panFieldSize[iField];

  /* update fields info */
  for (i = iField + 1; i < psDBF->nFields; i++) {
    psDBF->panFieldOffset[i - 1] =
      psDBF->panFieldOffset[i] - nDeletedFieldSize;
    psDBF->panFieldSize[i - 1] = psDBF->panFieldSize[i];
    psDBF->panFieldDecimals[i - 1] = psDBF->panFieldDecimals[i];
    psDBF->pachFieldType[i - 1] = psDBF->pachFieldType[i];
  }

  /* resize fields arrays */
  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);

  /* update header information */
  psDBF->nHeaderLength -= 32;
  psDBF->nRecordLength -= nDeletedFieldSize;
  memmove(psDBF->pszHeader + iField * 32, psDBF->pszHeader + (iField + 1) * 32,
          sizeof(char) * (psDBF->nFields - iField) * 32);
  psDBF->pszHeader = (char *) SfRealloc(psDBF->pszHeader, psDBF->nFields * 32);

  /* update size of current record appropriately */
  psDBF->pszCurrentRecord = (char *) SfRealloc(psDBF->pszCurrentRecord,psDBF->nRecordLength);

  /* we're done if we're dealing with not yet created .dbf */
  if (psDBF->bNoHeader && psDBF->nRecords == 0)
    return TRUE;

  /* force update of header with new header and record length */
  psDBF->bNoHeader = TRUE;
  DBFUpdateHeader(psDBF);

  /* shift records to their new positions */
  pszRecord = (char *) malloc(sizeof(char) * nOldRecordLength);
  for (iRecord = 0; iRecord < psDBF->nRecords; iRecord++) {
    /* load record */
    nRecordOffset = nOldRecordLength * (unsigned long) iRecord + nOldHeaderLength;
    fseek(psDBF->fp, nRecordOffset, 0);
    fread(pszRecord, nOldRecordLength, 1, psDBF->fp);

    /* move record in two steps */
    nRecordOffset = psDBF->nRecordLength * (unsigned long) iRecord + psDBF->nHeaderLength;
    fseek(psDBF->fp, nRecordOffset, 0);
    fwrite(pszRecord, nDeletedFieldOffset, 1, psDBF->fp);
    fwrite(pszRecord + nDeletedFieldOffset +  nDeletedFieldSize,
           nOldRecordLength - nDeletedFieldOffset -
           nDeletedFieldSize, 1, psDBF->fp);
  }

  /* free record */
  free(pszRecord);
  psDBF->nCurrentRecord = -1;
  psDBF->bCurrentRecordModified = FALSE;
  return TRUE;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x40, %rsp
movq %rdi, -0x10(%rbp)
movl %esi, -0x14(%rbp)
cmpl $0x0, -0x14(%rbp)
jl 0x3ef1
movl -0x14(%rbp), %eax
movq -0x10(%rbp), %rcx
cmpl 0x14(%rcx), %eax
jl 0x3efd
movl $0x0, -0x4(%rbp)
jmp 0x4295
movq -0x10(%rbp), %rdi
callq 0x17b0
cmpl $0x0, %eax
jne 0x3f17
movl $0x0, -0x4(%rbp)
jmp 0x4295
movq -0x10(%rbp), %rax
movl 0xc(%rax), %eax
movl %eax, -0x18(%rbp)
movq -0x10(%rbp), %rax
movl 0x10(%rax), %eax
movl %eax, -0x1c(%rbp)
movq -0x10(%rbp), %rax
movq 0x18(%rax), %rax
movslq -0x14(%rbp), %rcx
movl (%rax,%rcx,4), %eax
movl %eax, -0x20(%rbp)
movq -0x10(%rbp), %rax
movq 0x20(%rax), %rax
movslq -0x14(%rbp), %rcx
movl (%rax,%rcx,4), %eax
movl %eax, -0x24(%rbp)
movl -0x14(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x3c(%rbp)
movl -0x3c(%rbp), %eax
movq -0x10(%rbp), %rcx
cmpl 0x14(%rcx), %eax
jge 0x4005
movq -0x10(%rbp), %rax
movq 0x18(%rax), %rax
movslq -0x3c(%rbp), %rcx
movl (%rax,%rcx,4), %edx
subl -0x24(%rbp), %edx
movq -0x10(%rbp), %rax
movq 0x18(%rax), %rax
movl -0x3c(%rbp), %ecx
subl $0x1, %ecx
movslq %ecx, %rcx
movl %edx, (%rax,%rcx,4)
movq -0x10(%rbp), %rax
movq 0x20(%rax), %rax
movslq -0x3c(%rbp), %rcx
movl (%rax,%rcx,4), %edx
movq -0x10(%rbp), %rax
movq 0x20(%rax), %rax
movl -0x3c(%rbp), %ecx
subl $0x1, %ecx
movslq %ecx, %rcx
movl %edx, (%rax,%rcx,4)
movq -0x10(%rbp), %rax
movq 0x28(%rax), %rax
movslq -0x3c(%rbp), %rcx
movl (%rax,%rcx,4), %edx
movq -0x10(%rbp), %rax
movq 0x28(%rax), %rax
movl -0x3c(%rbp), %ecx
subl $0x1, %ecx
movslq %ecx, %rcx
movl %edx, (%rax,%rcx,4)
movq -0x10(%rbp), %rax
movq 0x30(%rax), %rax
movslq -0x3c(%rbp), %rcx
movb (%rax,%rcx), %dl
movq -0x10(%rbp), %rax
movq 0x30(%rax), %rax
movl -0x3c(%rbp), %ecx
subl $0x1, %ecx
movslq %ecx, %rcx
movb %dl, (%rax,%rcx)
movl -0x3c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x3c(%rbp)
jmp 0x3f58
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 0x10(%rax), %ecx
subl $0x20, %ecx
movl %ecx, 0x10(%rax)
movl -0x24(%rbp), %edx
movq -0x10(%rbp), %rax
movl 0xc(%rax), %ecx
subl %edx, %ecx
movl %ecx, 0xc(%rax)
movq -0x10(%rbp), %rax
movq 0x38(%rax), %rdi
movl -0x14(%rbp), %eax
shll $0x5, %eax
cltq
addq %rax, %rdi
movq -0x10(%rbp), %rax
movq 0x38(%rax), %rsi
movl -0x14(%rbp), %eax
addl $0x1, %eax
shll $0x5, %eax
cltq
addq %rax, %rsi
movq -0x10(%rbp), %rax
movl 0x14(%rax), %eax
subl -0x14(%rbp), %eax
movslq %eax, %rdx
shlq $0x0, %rdx
shlq $0x5, %rdx
callq 0x1180
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 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 0x416a
movq -0x10(%rbp), %rax
cmpl $0x0, 0x8(%rax)
jne 0x416a
movl $0x1, -0x4(%rbp)
jmp 0x4295
movq -0x10(%rbp), %rax
movl $0x1, 0x60(%rax)
movq -0x10(%rbp), %rdi
callq 0x1570
movslq -0x18(%rbp), %rdi
shlq $0x0, %rdi
callq 0x1140
movq %rax, -0x38(%rbp)
movl $0x0, -0x40(%rbp)
movl -0x40(%rbp), %eax
movq -0x10(%rbp), %rcx
cmpl 0x8(%rcx), %eax
jge 0x426f
movslq -0x18(%rbp), %rax
movslq -0x40(%rbp), %rcx
imulq %rcx, %rax
movslq -0x1c(%rbp), %rcx
addq %rcx, %rax
movq %rax, -0x30(%rbp)
movq -0x10(%rbp), %rax
movq (%rax), %rdi
movq -0x30(%rbp), %rsi
xorl %edx, %edx
callq 0x1160
movq -0x38(%rbp), %rdi
movslq -0x18(%rbp), %rsi
movq -0x10(%rbp), %rax
movq (%rax), %rcx
movl $0x1, %edx
callq 0x1090
movq -0x10(%rbp), %rax
movslq 0xc(%rax), %rax
movslq -0x40(%rbp), %rcx
imulq %rcx, %rax
movq -0x10(%rbp), %rcx
movslq 0x10(%rcx), %rcx
addq %rcx, %rax
movq %rax, -0x30(%rbp)
movq -0x10(%rbp), %rax
movq (%rax), %rdi
movq -0x30(%rbp), %rsi
xorl %edx, %edx
callq 0x1160
movq -0x38(%rbp), %rdi
movslq -0x20(%rbp), %rsi
movq -0x10(%rbp), %rax
movq (%rax), %rcx
movl $0x1, %edx
callq 0x11c0
movq -0x38(%rbp), %rdi
movslq -0x20(%rbp), %rax
addq %rax, %rdi
movslq -0x24(%rbp), %rax
addq %rax, %rdi
movl -0x18(%rbp), %eax
subl -0x20(%rbp), %eax
subl -0x24(%rbp), %eax
movslq %eax, %rsi
movq -0x10(%rbp), %rax
movq (%rax), %rcx
movl $0x1, %edx
callq 0x11c0
movl -0x40(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x40(%rbp)
jmp 0x4196
movq -0x38(%rbp), %rdi
callq 0x1030
movq -0x10(%rbp), %rax
movl $0xffffffff, 0x40(%rax) # imm = 0xFFFFFFFF
movq -0x10(%rbp), %rax
movl $0x0, 0x44(%rax)
movl $0x1, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x40, %rsp
popq %rbp
retq
nop