// File: /workspace/github_c_makefile_star2_O1/thegenemyers[P]DASCRUBBER/DB.c
// Function: Read_DB_Stub
DAZZ_STUB *Read_DB_Stub(char *path, int what)
{ FILE      *dbfile;
  DAZZ_STUB *stub;

  char  buf1[MAX_NAME+100];
  char  buf2[MAX_NAME+100];
  int   nread;

  int   i;
  int   nfiles;
  int   nblocks;
  int64 size;
  int   all, cutoff;

  dbfile = Fopen(path,"r");
  if (dbfile == NULL)
    EXIT(NULL);

  stub = Malloc(sizeof(DAZZ_STUB),"Allocating DB stub record");
  if (stub == NULL)
    { fclose(dbfile);
      EXIT(NULL);
    }

  stub->nreads  = NULL;
  stub->fname   = NULL;
  stub->prolog  = NULL;
  stub->ublocks = NULL;
  stub->tblocks = NULL;

  if (fscanf(dbfile,DB_NFILE,&nfiles) != 1)
    goto stub_trash;

  if (what & DB_STUB_NREADS)
    { stub->nreads = (int *) Malloc(sizeof(int)*(nfiles+1),"Allocating DB stub record");
      if (stub->nreads == NULL)
        goto stub_error;
      stub->nreads += 1;
    }

  if (what & DB_STUB_FILES)
    { stub->fname = (char **) Malloc(sizeof(char *)*(nfiles+1),"Allocating DB stub record");
      if (stub->fname == NULL)
        goto stub_error;
      stub->fname += 1;

      stub->nfiles  = nfiles;
      for (i = 0; i < nfiles; i++)
        stub->fname[i] = NULL;
    }

  if (what & DB_STUB_PROLOGS)
    { stub->prolog = (char **) Malloc(sizeof(char *)*(nfiles+1),"Allocating DB stub record");
      if (stub->prolog == NULL)
        goto stub_error;
      stub->prolog += 1;

      for (i = 0; i < nfiles; i++)
        stub->prolog[i] = NULL;
    }

  for (i = 0; i < nfiles; i++)
    { if (fscanf(dbfile,DB_FDATA,&nread,buf1,buf2) != 3)
        goto stub_trash;
      if (what & DB_STUB_NREADS)
        stub->nreads[i] = nread;
      if (what & DB_STUB_FILES)
        { stub->fname[i]   = Strdup(buf1,"Alloacting DB stub record");
          if (stub->fname[i] == NULL)
            goto stub_error;
        }
      if (what & DB_STUB_PROLOGS)
        { stub->prolog[i] = Strdup(buf2,"Alloacting DB stub record");
          if (stub->prolog[i] == NULL)
            goto stub_error;
        }
    }

  if (fscanf(dbfile,DB_NBLOCK,&nblocks) != 1)
    goto stub_trash;

  if (fscanf(dbfile,DB_PARAMS,&size,&cutoff,&all) != 3)
    goto stub_trash;

  if (what & DB_STUB_BLOCKS)
    { stub->ublocks  = (int *) Malloc(sizeof(int)*(nblocks+1),"Allocating DB stub record");
      stub->tblocks  = (int *) Malloc(sizeof(int)*(nblocks+1),"Allocating DB stub record");
      if (stub->ublocks == NULL || stub->tblocks == NULL)
        goto stub_error;

      for (i = 0; i <= nblocks; i++)
        if (fscanf(dbfile,DB_BDATA,stub->ublocks+i,stub->tblocks+i) != 2)
          goto stub_trash;
    }

  fclose(dbfile);

  stub->nfiles  = nfiles;
  stub->all     = all;
  stub->cutoff  = cutoff;
  stub->bsize   = size;
  stub->nblocks = nblocks;
  return (stub);

stub_trash:
  EPRINTF(EPLACE,"%s: Stub file %s is junk\n",Prog_Name,path);
stub_error:
  Free_DB_Stub(stub);
  fclose(dbfile);
  EXIT(NULL);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x4f38, %rsp           # imm = 0x4F38
movl %esi, %ebp
movq %rdi, %rbx
leaq 0x87e6(%rip), %rsi      # 0xbd51
callq 0x2ca1
movq %rax, 0x10(%rsp)
testq %rax, %rax
je 0x38d8
movq %rbx, 0x30(%rsp)
leaq 0x7e55(%rip), %rsi      # 0xb3df
movl $0x48, %edi
callq 0x2b85
testq %rax, %rax
je 0x38ce
movq %rax, %r14
xorps %xmm0, %xmm0
movups %xmm0, 0x8(%rax)
movq $0x0, 0x18(%rax)
movups %xmm0, 0x38(%rax)
leaq 0x7e3f(%rip), %rsi      # 0xb3f9
leaq 0x8(%rsp), %rdx
movq 0x10(%rsp), %rdi
xorl %eax, %eax
callq 0x1090
cmpl $0x1, %eax
jne 0x38bc
movq %r14, %rax
addq $0x8, %rax
movq %rax, 0x18(%rsp)
testb $0x1, %bpl
je 0x361c
movslq 0x8(%rsp), %rax
leaq 0x4(,%rax,4), %rdi
leaq 0x7de5(%rip), %rsi      # 0xb3df
callq 0x2b85
movq 0x18(%rsp), %rcx
movq %rax, (%rcx)
testq %rax, %rax
je 0x38c6
addq $0x4, %rax
movq 0x18(%rsp), %rcx
movq %rax, (%rcx)
testb $0x2, %bpl
je 0x3673
movslq 0x8(%rsp), %rax
leaq 0x8(,%rax,8), %rdi
leaq 0x7da9(%rip), %rsi      # 0xb3df
callq 0x2b85
movq %rax, 0x10(%r14)
testq %rax, %rax
je 0x38c6
addq $0x8, %rax
movq %rax, 0x10(%r14)
movslq 0x8(%rsp), %rax
movl %eax, (%r14)
testq %rax, %rax
jle 0x3673
xorl %ecx, %ecx
movq 0x10(%r14), %rdx
movq $0x0, (%rdx,%rcx,8)
incq %rcx
cmpq %rcx, %rax
jne 0x365f
testb $0x4, %bpl
je 0x36c7
movslq 0x8(%rsp), %rax
leaq 0x8(,%rax,8), %rdi
leaq 0x7d52(%rip), %rsi      # 0xb3df
callq 0x2b85
movq %rax, 0x18(%r14)
testq %rax, %rax
je 0x38c6
addq $0x8, %rax
movq %rax, 0x18(%r14)
movslq 0x8(%rsp), %rax
testq %rax, %rax
jle 0x36c7
xorl %ecx, %ecx
movq 0x18(%r14), %rdx
movq $0x0, (%rdx,%rcx,8)
incq %rcx
cmpq %rcx, %rax
jne 0x36b3
cmpl $0x0, 0x8(%rsp)
jle 0x3787
leaq 0x27c0(%rsp), %r15
leaq 0x40(%rsp), %rbx
leaq 0x7d2d(%rip), %r12      # 0xb413
xorl %r13d, %r13d
movq 0x10(%rsp), %rdi
leaq 0x7d11(%rip), %rsi      # 0xb406
leaq 0x2c(%rsp), %rdx
movq %r15, %rcx
movq %rbx, %r8
xorl %eax, %eax
callq 0x1090
cmpl $0x3, %eax
jne 0x38bc
testb $0x1, %bpl
je 0x3726
movl 0x2c(%rsp), %eax
movq 0x18(%rsp), %rcx
movq (%rcx), %rcx
movl %eax, (%rcx,%r13,4)
testb $0x2, %bpl
je 0x374e
movq %r15, %rdi
movq %r12, %rsi
callq 0x2c42
movq 0x10(%r14), %rcx
movq %rax, (%rcx,%r13,8)
movq 0x10(%r14), %rax
cmpq $0x0, (%rax,%r13,8)
je 0x38c6
testb $0x4, %bpl
je 0x3776
movq %rbx, %rdi
movq %r12, %rsi
callq 0x2c42
movq 0x18(%r14), %rcx
movq %rax, (%rcx,%r13,8)
movq 0x18(%r14), %rax
cmpq $0x0, (%rax,%r13,8)
je 0x38c6
incq %r13
movslq 0x8(%rsp), %rax
cmpq %rax, %r13
jl 0x36e9
leaq 0x7c9f(%rip), %rsi      # 0xb42d
leaq 0xc(%rsp), %rdx
movq 0x10(%rsp), %rdi
xorl %eax, %eax
callq 0x1090
cmpl $0x1, %eax
jne 0x38bc
leaq 0x7c8c(%rip), %rsi      # 0xb43b
leaq 0x38(%rsp), %rdx
leaq 0x24(%rsp), %rcx
leaq 0x28(%rsp), %r8
movq 0x10(%rsp), %rdi
xorl %eax, %eax
callq 0x1090
cmpl $0x3, %eax
jne 0x38bc
testb $0x8, %bpl
je 0x3875
movslq 0xc(%rsp), %rax
leaq 0x4(,%rax,4), %rdi
leaq 0x7bee(%rip), %rbx      # 0xb3df
movq %rbx, %rsi
callq 0x2b85
movq %rax, 0x38(%r14)
movslq 0xc(%rsp), %rax
leaq 0x4(,%rax,4), %rdi
movq %rbx, %rsi
callq 0x2b85
movq %rax, 0x40(%r14)
testq %rax, %rax
je 0x38c6
cmpq $0x0, 0x38(%r14)
je 0x38c6
cmpl $0x0, 0xc(%rsp)
js 0x3875
movq $-0x1, %r15
leaq 0x7c22(%rip), %rbx      # 0xb461
xorl %r12d, %r12d
movq 0x38(%r14), %rdx
addq %r12, %rdx
movq 0x40(%r14), %rcx
addq %r12, %rcx
movq 0x10(%rsp), %rdi
movq %rbx, %rsi
xorl %eax, %eax
callq 0x1090
cmpl $0x2, %eax
jne 0x38bc
movslq 0xc(%rsp), %rax
incq %r15
addq $0x4, %r12
cmpq %rax, %r15
jl 0x3842
movq 0x10(%rsp), %rdi
callq 0x10c0
movl 0x8(%rsp), %eax
movl %eax, (%r14)
movl 0x28(%rsp), %eax
movl %eax, 0x20(%r14)
movl 0x24(%rsp), %eax
movl %eax, 0x24(%r14)
movq 0x38(%rsp), %rax
movq %rax, 0x28(%r14)
movl 0xc(%rsp), %eax
movl %eax, 0x30(%r14)
movq %r14, %rax
addq $0x4f38, %rsp           # imm = 0x4F38
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x30(%rsp), %rdi
callq 0x1384
movq %r14, %rdi
callq 0x38e2
movq 0x10(%rsp), %rdi
callq 0x10c0
movl $0x1, %edi
callq 0x1270