// File: /workspace/github_c_makefile_star2_O2/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 $0x4f48, %rsp           # imm = 0x4F48
movl %esi, %ebp
movq %rdi, %rbx
leaq 0x78eb(%rip), %rsi      # 0x9d51
callq 0x1ccb
movq %rax, 0x20(%rsp)
testq %rax, %rax
je 0x27fe
movq %rbx, 0x40(%rsp)
leaq 0x6f5a(%rip), %rsi      # 0x93df
pushq $0x48
popq %rdi
callq 0x1bad
testq %rax, %rax
je 0x27f4
xorps %xmm0, %xmm0
movups %xmm0, 0x8(%rax)
andq $0x0, 0x18(%rax)
movq %rax, 0x10(%rsp)
movups %xmm0, 0x38(%rax)
leaq 0x6f47(%rip), %rsi      # 0x93f9
leaq 0xc(%rsp), %rdx
movq 0x20(%rsp), %rdi
xorl %eax, %eax
callq 0x1090
cmpl $0x1, %eax
jne 0x27c6
testb $0x1, %bpl
jne 0x24dd
movq $0x0, 0x38(%rsp)
jmp 0x251a
movq 0x10(%rsp), %rbx
addq $0x8, %rbx
movslq 0xc(%rsp), %rax
leaq 0x4(,%rax,4), %rdi
leaq 0x6ee5(%rip), %rsi      # 0x93df
callq 0x1bad
movq %rax, (%rbx)
testq %rax, %rax
je 0x27ea
movq %rax, %rcx
addq $0x4, %rcx
movq %rcx, 0x38(%rsp)
movq %rcx, (%rbx)
testb $0x2, %bpl
jne 0x2685
xorl %r13d, %r13d
testb $0x4, %bpl
jne 0x26e1
leaq 0x27d0(%rsp), %r14
leaq 0x50(%rsp), %rbx
leaq 0x6ece(%rip), %r15      # 0x9413
xorl %r12d, %r12d
movslq 0xc(%rsp), %rax
cmpq %rax, %r12
jge 0x25ea
movq 0x20(%rsp), %rdi
leaq 0x6ea4(%rip), %rsi      # 0x9406
leaq 0x34(%rsp), %rdx
movq %r14, %rcx
movq %rbx, %r8
xorl %eax, %eax
callq 0x1090
cmpl $0x3, %eax
jne 0x27c6
testb $0x1, %bpl
je 0x2590
movl 0x34(%rsp), %eax
movq 0x38(%rsp), %rcx
movl %eax, (%rcx,%r12,4)
testb $0x2, %bpl
je 0x25bb
movq %r14, %rdi
movq %r15, %rsi
callq 0x1c68
movq %rax, (%r13,%r12,8)
movq 0x10(%rsp), %rax
movq 0x10(%rax), %r13
cmpq $0x0, (%r13,%r12,8)
je 0x27ea
testb $0x4, %bpl
je 0x25e2
movq %rbx, %rdi
movq %r15, %rsi
callq 0x1c68
movq 0x10(%rsp), %rcx
movq 0x18(%rcx), %rcx
movq %rax, (%rcx,%r12,8)
testq %rax, %rax
je 0x27ea
incq %r12
jmp 0x2548
leaq 0x6e3c(%rip), %rsi      # 0x942d
leaq 0x1c(%rsp), %rdx
movq 0x20(%rsp), %rdi
xorl %eax, %eax
callq 0x1090
cmpl $0x1, %eax
jne 0x27c6
leaq 0x6e29(%rip), %rsi      # 0x943b
leaq 0x48(%rsp), %rdx
leaq 0x2c(%rsp), %rcx
leaq 0x30(%rsp), %r8
movq 0x20(%rsp), %rdi
xorl %eax, %eax
callq 0x1090
cmpl $0x3, %eax
jne 0x27c6
testb $0x8, %bpl
jne 0x2737
movq 0x20(%rsp), %rdi
callq 0x10c0
movl 0xc(%rsp), %ecx
movq 0x10(%rsp), %rax
movl %ecx, (%rax)
movl 0x30(%rsp), %ecx
movl %ecx, 0x20(%rax)
movl 0x2c(%rsp), %ecx
movl %ecx, 0x24(%rax)
movq 0x48(%rsp), %rcx
movq %rcx, 0x28(%rax)
movl 0x1c(%rsp), %ecx
movl %ecx, 0x30(%rax)
addq $0x4f48, %rsp           # imm = 0x4F48
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movslq 0xc(%rsp), %rax
leaq 0x8(,%rax,8), %rdi
leaq 0x6d46(%rip), %rsi      # 0x93df
callq 0x1bad
movq %rax, %r13
movq 0x10(%rsp), %rax
movq %r13, 0x10(%rax)
testq %r13, %r13
je 0x27ea
addq $0x8, %r13
movq 0x10(%rsp), %rcx
movq %r13, 0x10(%rcx)
movl 0xc(%rsp), %eax
movl %eax, (%rcx)
xorl %ecx, %ecx
testl %eax, %eax
cmovlel %ecx, %eax
cmpq %rcx, %rax
je 0x2527
andq $0x0, (%r13,%rcx,8)
incq %rcx
jmp 0x26cd
movslq 0xc(%rsp), %rax
leaq 0x8(,%rax,8), %rdi
leaq 0x6cea(%rip), %rsi      # 0x93df
callq 0x1bad
movq 0x10(%rsp), %rcx
movq %rax, 0x18(%rcx)
testq %rax, %rax
je 0x27ea
addq $0x8, %rax
movq 0x10(%rsp), %rcx
movq %rax, 0x18(%rcx)
movl 0xc(%rsp), %ecx
xorl %edx, %edx
testl %ecx, %ecx
cmovlel %edx, %ecx
cmpq %rdx, %rcx
je 0x2531
andq $0x0, (%rax,%rdx,8)
incq %rdx
jmp 0x2724
movslq 0x1c(%rsp), %rax
leaq 0x4(,%rax,4), %rdi
leaq 0x6c94(%rip), %r14      # 0x93df
movq %r14, %rsi
callq 0x1bad
movq %rax, %rbx
movq 0x10(%rsp), %r15
movq %rax, 0x38(%r15)
movslq 0x1c(%rsp), %rax
leaq 0x4(,%rax,4), %rdi
movq %r14, %rsi
callq 0x1bad
movq %rax, 0x40(%r15)
testq %rax, %rax
je 0x27ea
testq %rbx, %rbx
je 0x27ea
movq %rax, %rcx
pushq $-0x1
popq %r15
leaq 0x6cd1(%rip), %r14      # 0x9461
movslq 0x1c(%rsp), %rax
incq %r15
cmpq %rax, %r15
jg 0x2640
leaq 0x4(%rcx), %r12
leaq 0x4(%rbx), %r13
movq 0x20(%rsp), %rdi
movq %r14, %rsi
movq %rbx, %rdx
xorl %eax, %eax
callq 0x1090
movq %r13, %rbx
movq %r12, %rcx
cmpl $0x2, %eax
je 0x2790
movq 0xb82b(%rip), %rax      # 0xdff8
movq (%rax), %rdi
movq 0xe111(%rip), %rdx      # 0x108e8
leaq 0x6c8d(%rip), %rsi      # 0x946b
movq 0x40(%rsp), %rcx
xorl %eax, %eax
callq 0x11a0
movq 0x10(%rsp), %rdi
callq 0x2806
movq 0x20(%rsp), %rdi
callq 0x10c0
pushq $0x1
popq %rdi
callq 0x1270