// File: /workspace/github_c_makefile_star2_O1/bmottershead[P]DBF2TSV/dbf.c
// Function: DBFWriteAttribute
static int DBFWriteAttribute(DBFHandle psDBF, int hEntity, int iField, void *pValue) {
  int i, j, nRetResult = TRUE;
  unsigned char *pabyRec;
  char szSField[400], szFormat[20];

  /* Is this a valid record? */
  if (hEntity < 0 || hEntity > psDBF->nRecords)
    return (FALSE);
  if (psDBF->bNoHeader)
    DBFWriteHeader(psDBF);

  /* Is this a brand new record? */
  if (hEntity == psDBF->nRecords) {
    if (!DBFFlushRecord(psDBF))
      return FALSE;
    psDBF->nRecords++;
    for (i = 0; i < psDBF->nRecordLength; i++)
      psDBF->pszCurrentRecord[i] = ' ';
    psDBF->nCurrentRecord = hEntity;
  }

  /* Is this an existing record, but different than the last one */
  /* we accessed? */
  if (!DBFLoadRecord(psDBF, hEntity))
    return FALSE;
  pabyRec = (unsigned char *) psDBF->pszCurrentRecord;
  psDBF->bCurrentRecordModified = TRUE;
  psDBF->bUpdated = TRUE;

  /* Translate NULL value to valid DBF file representation. */
  if (pValue == NULL) {
    memset((char *) (pabyRec + psDBF->panFieldOffset[iField]),
           DBFGetNullCharacter(psDBF->pachFieldType[iField]),
           psDBF->panFieldSize[iField]);
    return TRUE;
  }

  /* Assign all the record fields. */
  switch (psDBF->pachFieldType[iField]) {
  case 'D':
  case 'N':
  case 'F':
    if (psDBF->panFieldDecimals[iField] == 0) {
      int nWidth = psDBF->panFieldSize[iField];
      if ((int) sizeof(szSField) - 2 < nWidth)
        nWidth = sizeof(szSField) - 2;
      sprintf(szFormat, "%%%dd", nWidth);
      sprintf(szSField, szFormat, (int) *((double *) pValue));
      if ((int) strlen(szSField) > psDBF->panFieldSize[iField]) {
        szSField[psDBF->panFieldSize[iField]] = '\0';
        nRetResult = FALSE;
      }
      strncpy((char *) (pabyRec + psDBF->panFieldOffset[iField]),szSField, strlen(szSField));
    } else {
      int nWidth = psDBF->panFieldSize[iField];
      if ((int) sizeof(szSField) - 2 < nWidth)
        nWidth = sizeof(szSField) - 2;
      sprintf(szFormat, "%%%d.%df",
              nWidth, psDBF->panFieldDecimals[iField]);
      sprintf(szSField, szFormat, *((double *) pValue));
      if ((int) strlen(szSField) > psDBF->panFieldSize[iField]) {
        szSField[psDBF->panFieldSize[iField]] = '\0';
        nRetResult = FALSE;
      }
      strncpy((char *) (pabyRec + psDBF->panFieldOffset[iField]),szSField, strlen(szSField));
    }
    break;

  case 'L':
    if (psDBF->panFieldSize[iField] >= 1 &&
        (*(char *) pValue == 'F' || *(char *) pValue == 'T'))
      *(pabyRec + psDBF->panFieldOffset[iField]) = *(char *) pValue;
    break;

  default:
    if ((int) strlen((char *) pValue) > psDBF->panFieldSize[iField]) {
      j = psDBF->panFieldSize[iField];
      nRetResult = FALSE;
    } else {
      memset(pabyRec + psDBF->panFieldOffset[iField], ' ',psDBF->panFieldSize[iField]);
      j = strlen((char *) pValue);
    }
    strncpy((char *) (pabyRec + psDBF->panFieldOffset[iField]), (char *) pValue, j);
    break;
  }

  return (nRetResult);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x1b8, %rsp            # imm = 0x1B8
xorl %ebp, %ebp
testl %esi, %esi
js 0x2873
movl %esi, %r14d
movq %rdi, %rbx
cmpl %esi, 0x8(%rdi)
jl 0x2873
movq %rcx, %r15
movl %edx, %r12d
cmpl $0x0, 0x60(%rbx)
je 0x2667
movq %rbx, %rdi
callq 0x163a
cmpl %r14d, 0x8(%rbx)
jne 0x26a0
movq %rbx, %rdi
callq 0x16fc
testl %eax, %eax
je 0x2873
incl 0x8(%rbx)
cmpl $0x0, 0xc(%rbx)
jle 0x269c
xorl %eax, %eax
movq 0x48(%rbx), %rcx
movb $0x20, (%rcx,%rax)
incq %rax
movslq 0xc(%rbx), %rcx
cmpq %rcx, %rax
jl 0x2688
movl %r14d, 0x40(%rbx)
movq %rbx, %rdi
movl %r14d, %esi
callq 0x2559
testl %eax, %eax
je 0x2873
movq 0x48(%rbx), %r14
movl $0x1, %ebp
movl %ebp, 0x44(%rbx)
movl %ebp, 0x64(%rbx)
movslq %r12d, %r13
testq %r15, %r15
je 0x273a
movq 0x30(%rbx), %rax
movsbl (%rax,%r13), %eax
addl $-0x44, %eax
rorl %eax
cmpl $0x2, %eax
jb 0x26ef
cmpl $0x4, %eax
je 0x27f5
cmpl $0x5, %eax
jne 0x281c
movq 0x20(%rbx), %rax
movq 0x28(%rbx), %rcx
movl (%rcx,%r13,4), %ecx
movl (%rax,%r13,4), %eax
movl $0x18e, %edx            # imm = 0x18E
cmpl %edx, %eax
cmovll %eax, %edx
testl %ecx, %ecx
je 0x2787
leaq 0x1936(%rip), %rsi      # 0x404a
movq %rsp, %r12
movq %r12, %rdi
xorl %eax, %eax
callq 0x11d0
movsd (%r15), %xmm0
leaq 0x20(%rsp), %r15
movq %r15, %rdi
movq %r12, %rsi
movb $0x1, %al
callq 0x11d0
jmp 0x27b2
movq 0x18(%rbx), %rax
movq 0x20(%rbx), %rdx
movslq (%rax,%r13,4), %rax
movq 0x30(%rbx), %rcx
movsbl (%rcx,%r13), %esi
addl $-0x44, %esi
rorl %esi
addq %rax, %r14
leal (,%rsi,8), %ecx
movabsq $0x2a3f20202a30, %rax   # imm = 0x2A3F20202A30
shrq %cl, %rax
cmpl $0x6, %esi
movl $0x20, %esi
cmovbl %eax, %esi
movslq (%rdx,%r13,4), %rdx
movq %r14, %rdi
callq 0x10f0
jmp 0x2873
leaq 0x198c(%rip), %rsi      # 0x411a
movq %rsp, %r12
movq %r12, %rdi
xorl %eax, %eax
callq 0x11d0
cvttsd2si (%r15), %edx
leaq 0x20(%rsp), %r15
movq %r15, %rdi
movq %r12, %rsi
xorl %eax, %eax
callq 0x11d0
movq %r15, %rdi
callq 0x10d0
movq 0x20(%rbx), %rcx
movslq (%rcx,%r13,4), %rcx
movl $0x1, %ebp
cmpl %eax, %ecx
jge 0x27d2
movb $0x0, 0x20(%rsp,%rcx)
xorl %ebp, %ebp
movq 0x18(%rbx), %rax
movslq (%rax,%r13,4), %rax
addq %rax, %r14
leaq 0x20(%rsp), %rbx
movq %rbx, %rdi
callq 0x10d0
movq %r14, %rdi
movq %rbx, %rsi
movq %rax, %rdx
jmp 0x286e
movq 0x20(%rbx), %rax
cmpl $0x0, (%rax,%r13,4)
jle 0x2873
movzbl (%r15), %eax
cmpl $0x54, %eax
je 0x280e
cmpl $0x46, %eax
jne 0x2873
movq 0x18(%rbx), %rcx
movslq (%rcx,%r13,4), %rcx
movb %al, (%r14,%rcx)
jmp 0x2873
movq %r15, %rdi
callq 0x10d0
movq %rax, %rcx
movq 0x20(%rbx), %rax
movl (%rax,%r13,4), %eax
xorl %ebp, %ebp
cmpl %ecx, %eax
jl 0x285a
movslq %eax, %rdx
movq 0x18(%rbx), %rax
movslq (%rax,%r13,4), %rdi
addq %r14, %rdi
movl $0x20, %esi
callq 0x10f0
movq %r15, %rdi
callq 0x10d0
movl $0x1, %ebp
movq 0x18(%rbx), %rcx
movslq (%rcx,%r13,4), %rcx
addq %rcx, %r14
movslq %eax, %rdx
movq %r14, %rdi
movq %r15, %rsi
callq 0x1050
movl %ebp, %eax
addq $0x1b8, %rsp            # imm = 0x1B8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq