// File: /workspace/github_c_makefile_star2_O0/bmottershead[P]DBF2TSV/dbf.c
// Function: DBFCreateEx
DBFHandle  DBFCreateEx(const char *pszFilename, const char *pszCodePage) {
  DBFHandle psDBF;
  FILE* fp;
  char *pszFullname, *pszBasename;
  int i, ldid = -1;
  char chZero = '\0';

  /* Compute the base (layer) name.  If there is any extension */
  /* on the passed in filename we will strip it off. */
  pszBasename = (char *) malloc(strlen(pszFilename) + 5);
  strcpy(pszBasename, pszFilename);
  for (i = strlen(pszBasename) - 1; i > 0 && pszBasename[i] != '.' && pszBasename[i] != '/'
         && pszBasename[i] != '\\'; i--) {/* empty loop */ }
  if (pszBasename[i] == '.')
    pszBasename[i] = '\0';
  pszFullname = (char *) malloc(strlen(pszBasename) + 5);
  sprintf(pszFullname, "%s.dbf", pszBasename);

  /* Create the file. */
  fp = fopen(pszFullname, "wb");
  if (fp == NULL)
    return (NULL);
  fwrite(&chZero, 1, 1, fp);
  fclose(fp);

  fp = fopen(pszFullname, "rb+");
  if (fp == NULL)
    return (NULL);

  sprintf(pszFullname, "%s.cpg", pszBasename);
  if (pszCodePage != NULL) {
    if (strncmp(pszCodePage, "LDID/", 5) == 0) {
      ldid = atoi(pszCodePage + 5);
      if (ldid > 255)
        ldid = -1;  // don't use 0 to indicate out of range as LDID/0 is a valid one
    }
    if (ldid < 0) {
      FILE* fpCPG = fopen(pszFullname, "w");
      fwrite((char *) pszCodePage, strlen(pszCodePage), 1, fpCPG);
      fclose(fpCPG);
    }
  }
  if (pszCodePage == NULL || ldid >= 0)
    remove(pszFullname);
  free(pszBasename);
  free(pszFullname);

  /* Create the info structure. */
  psDBF = (DBFHandle) calloc(1, sizeof(DBFInfo));
  psDBF->fp = fp;
  psDBF->nRecords = 0;
  psDBF->nFields = 0;
  psDBF->nRecordLength = 1;
  psDBF->nHeaderLength = 33;
  psDBF->panFieldOffset = NULL;
  psDBF->panFieldSize = NULL;
  psDBF->panFieldDecimals = NULL;
  psDBF->pachFieldType = NULL;
  psDBF->pszHeader = NULL;
  psDBF->nCurrentRecord = -1;
  psDBF->bCurrentRecordModified = FALSE;
  psDBF->pszCurrentRecord = NULL;
  psDBF->bNoHeader = TRUE;
  psDBF->iLanguageDriver = ldid > 0 ? ldid : 0;
  psDBF->pszCodePage = NULL;
  if (pszCodePage) {
    psDBF->pszCodePage = (char *) malloc(strlen(pszCodePage) + 1);
    strcpy(psDBF->pszCodePage, pszCodePage);
  }
  return (psDBF);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x70, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movl $0xffffffff, -0x40(%rbp) # imm = 0xFFFFFFFF
movb $0x0, -0x41(%rbp)
movq -0x10(%rbp), %rdi
callq 0x10c0
movq %rax, %rdi
addq $0x5, %rdi
callq 0x1140
movq %rax, -0x38(%rbp)
movq -0x38(%rbp), %rdi
movq -0x10(%rbp), %rsi
callq 0x1070
movq -0x38(%rbp), %rdi
callq 0x10c0
subq $0x1, %rax
movl %eax, -0x3c(%rbp)
xorl %eax, %eax
cmpl $0x0, -0x3c(%rbp)
movb %al, -0x51(%rbp)
jle 0x21cd
movq -0x38(%rbp), %rax
movslq -0x3c(%rbp), %rcx
movsbl (%rax,%rcx), %ecx
xorl %eax, %eax
cmpl $0x2e, %ecx
movb %al, -0x51(%rbp)
je 0x21cd
movq -0x38(%rbp), %rax
movslq -0x3c(%rbp), %rcx
movsbl (%rax,%rcx), %ecx
xorl %eax, %eax
cmpl $0x2f, %ecx
movb %al, -0x51(%rbp)
je 0x21cd
movq -0x38(%rbp), %rax
movslq -0x3c(%rbp), %rcx
movsbl (%rax,%rcx), %eax
cmpl $0x5c, %eax
setne %al
movb %al, -0x51(%rbp)
movb -0x51(%rbp), %al
testb $0x1, %al
jne 0x21d6
jmp 0x21e3
jmp 0x21d8
movl -0x3c(%rbp), %eax
addl $-0x1, %eax
movl %eax, -0x3c(%rbp)
jmp 0x2181
movq -0x38(%rbp), %rax
movslq -0x3c(%rbp), %rcx
movsbl (%rax,%rcx), %eax
cmpl $0x2e, %eax
jne 0x2200
movq -0x38(%rbp), %rax
movslq -0x3c(%rbp), %rcx
movb $0x0, (%rax,%rcx)
movq -0x38(%rbp), %rdi
callq 0x10c0
movq %rax, %rdi
addq $0x5, %rdi
callq 0x1140
movq %rax, -0x30(%rbp)
movq -0x30(%rbp), %rdi
movq -0x38(%rbp), %rdx
leaq 0x2ec1(%rip), %rsi      # 0x50e9
movb $0x0, %al
callq 0x11b0
movq -0x30(%rbp), %rdi
leaq 0x2ede(%rip), %rsi      # 0x5118
callq 0x1190
movq %rax, -0x28(%rbp)
cmpq $0x0, -0x28(%rbp)
jne 0x2257
movq $0x0, -0x8(%rbp)
jmp 0x248b
movq -0x28(%rbp), %rcx
leaq -0x41(%rbp), %rdi
movl $0x1, %edx
movq %rdx, %rsi
callq 0x11c0
movq -0x28(%rbp), %rdi
callq 0x10b0
movq -0x30(%rbp), %rdi
leaq 0x2e61(%rip), %rsi      # 0x50e1
callq 0x1190
movq %rax, -0x28(%rbp)
cmpq $0x0, -0x28(%rbp)
jne 0x229d
movq $0x0, -0x8(%rbp)
jmp 0x248b
movq -0x30(%rbp), %rdi
movq -0x38(%rbp), %rdx
leaq 0x2e4b(%rip), %rsi      # 0x50f7
movb $0x0, %al
callq 0x11b0
cmpq $0x0, -0x18(%rbp)
je 0x2345
movq -0x18(%rbp), %rdi
leaq 0x2e52(%rip), %rsi      # 0x511b
movl $0x5, %edx
callq 0x1060
cmpl $0x0, %eax
jne 0x22fa
movq -0x18(%rbp), %rdi
addq $0x5, %rdi
callq 0x11a0
movl %eax, -0x40(%rbp)
cmpl $0xff, -0x40(%rbp)
jle 0x22f8
movl $0xffffffff, -0x40(%rbp) # imm = 0xFFFFFFFF
jmp 0x22fa
cmpl $0x0, -0x40(%rbp)
jge 0x2343
movq -0x30(%rbp), %rdi
leaq 0x2e16(%rip), %rsi      # 0x5121
callq 0x1190
movq %rax, -0x50(%rbp)
movq -0x18(%rbp), %rax
movq %rax, -0x60(%rbp)
movq -0x18(%rbp), %rdi
callq 0x10c0
movq -0x60(%rbp), %rdi
movq %rax, %rsi
movq -0x50(%rbp), %rcx
movl $0x1, %edx
callq 0x11c0
movq -0x50(%rbp), %rdi
callq 0x10b0
jmp 0x2345
cmpq $0x0, -0x18(%rbp)
je 0x2352
cmpl $0x0, -0x40(%rbp)
jl 0x235b
movq -0x30(%rbp), %rdi
callq 0x1050
movq -0x38(%rbp), %rdi
callq 0x1030
movq -0x30(%rbp), %rdi
callq 0x1030
movl $0x1, %edi
movl $0x80, %esi
callq 0x1100
movq %rax, -0x20(%rbp)
movq -0x28(%rbp), %rcx
movq -0x20(%rbp), %rax
movq %rcx, (%rax)
movq -0x20(%rbp), %rax
movl $0x0, 0x8(%rax)
movq -0x20(%rbp), %rax
movl $0x0, 0x14(%rax)
movq -0x20(%rbp), %rax
movl $0x1, 0xc(%rax)
movq -0x20(%rbp), %rax
movl $0x21, 0x10(%rax)
movq -0x20(%rbp), %rax
movq $0x0, 0x18(%rax)
movq -0x20(%rbp), %rax
movq $0x0, 0x20(%rax)
movq -0x20(%rbp), %rax
movq $0x0, 0x28(%rax)
movq -0x20(%rbp), %rax
movq $0x0, 0x30(%rax)
movq -0x20(%rbp), %rax
movq $0x0, 0x38(%rax)
movq -0x20(%rbp), %rax
movl $0xffffffff, 0x40(%rax) # imm = 0xFFFFFFFF
movq -0x20(%rbp), %rax
movl $0x0, 0x44(%rax)
movq -0x20(%rbp), %rax
movq $0x0, 0x48(%rax)
movq -0x20(%rbp), %rax
movl $0x1, 0x60(%rax)
cmpl $0x0, -0x40(%rbp)
jle 0x242e
movl -0x40(%rbp), %eax
movl %eax, -0x64(%rbp)
jmp 0x2435
xorl %eax, %eax
movl %eax, -0x64(%rbp)
jmp 0x2435
movl -0x64(%rbp), %ecx
movq -0x20(%rbp), %rax
movl %ecx, 0x70(%rax)
movq -0x20(%rbp), %rax
movq $0x0, 0x78(%rax)
cmpq $0x0, -0x18(%rbp)
je 0x2483
movq -0x18(%rbp), %rdi
callq 0x10c0
movq %rax, %rdi
addq $0x1, %rdi
callq 0x1140
movq %rax, %rcx
movq -0x20(%rbp), %rax
movq %rcx, 0x78(%rax)
movq -0x20(%rbp), %rax
movq 0x78(%rax), %rdi
movq -0x18(%rbp), %rsi
callq 0x1070
movq -0x20(%rbp), %rax
movq %rax, -0x8(%rbp)
movq -0x8(%rbp), %rax
addq $0x70, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)