// File: /workspace/github_c_makefile_star2_O3/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 0x893c(%rip), %rsi      # 0xbdb1
callq 0x2c15
movq %rax, 0x10(%rsp)
testq %rax, %rax
je 0x390f
movq %rbx, 0x30(%rsp)
leaq 0x7fab(%rip), %rsi      # 0xb43f
movl $0x48, %edi
callq 0x2af5
testq %rax, %rax
je 0x3905
pxor %xmm0, %xmm0
movdqu %xmm0, 0x8(%rax)
movq $0x0, 0x18(%rax)
movq %rax, 0x8(%rsp)
movdqu %xmm0, 0x38(%rax)
leaq 0x7f90(%rip), %rsi      # 0xb459
movq %rsp, %rdx
movq 0x10(%rsp), %rdi
xorl %eax, %eax
callq 0x1090
cmpl $0x1, %eax
jne 0x38f1
testb $0x1, %bpl
jne 0x34f2
movq $0x0, 0x28(%rsp)
jmp 0x352e
movq 0x8(%rsp), %rbx
addq $0x8, %rbx
movslq (%rsp), %rax
leaq 0x4(,%rax,4), %rdi
leaq 0x7f31(%rip), %rsi      # 0xb43f
callq 0x2af5
movq %rax, (%rbx)
testq %rax, %rax
je 0x38fb
movq %rax, %rcx
addq $0x4, %rcx
movq %rcx, 0x28(%rsp)
movq %rcx, (%rbx)
movq 0x8(%rsp), %rbx
movl (%rsp), %ecx
testb $0x2, %bpl
jne 0x3544
xorl %r13d, %r13d
jmp 0x361f
movslq %ecx, %rax
leaq 0x8(,%rax,8), %rdi
leaq 0x7ee9(%rip), %rsi      # 0xb43f
callq 0x2af5
movq %rax, 0x10(%rbx)
testq %rax, %rax
je 0x38fb
leaq 0x8(%rax), %r13
movq 0x8(%rsp), %rbx
movq %r13, 0x10(%rbx)
movslq (%rsp), %rcx
movl %ecx, (%rbx)
testq %rcx, %rcx
jle 0x361f
leal 0x1(%rcx), %edx
movq %rcx, %rsi
decq %rsi
movq %rsi, %xmm0
pshufd $0x44, %xmm0, %xmm0     # xmm0 = xmm0[0,1,0,1]
shrl %edx
shlq $0x4, %rdx
movdqa 0x7cab(%rip), %xmm1     # 0xb250
xorl %esi, %esi
movdqa 0x7cb1(%rip), %xmm2     # 0xb260
pxor %xmm2, %xmm0
pcmpeqd %xmm3, %xmm3
movdqa 0x7cb1(%rip), %xmm4     # 0xb270
movdqa %xmm1, %xmm5
pxor %xmm2, %xmm5
movdqa %xmm5, %xmm6
pcmpgtd %xmm0, %xmm6
pcmpeqd %xmm0, %xmm5
pshufd $0xf5, %xmm5, %xmm7     # xmm7 = xmm5[1,1,3,3]
pand %xmm6, %xmm7
pshufd $0xf5, %xmm6, %xmm5     # xmm5 = xmm6[1,1,3,3]
por %xmm7, %xmm5
movd %xmm5, %edi
notl %edi
testb $0x1, %dil
je 0x35fa
movq $0x0, 0x8(%rax,%rsi)
pxor %xmm3, %xmm5
pextrw $0x4, %xmm5, %edi
testb $0x1, %dil
je 0x3612
movq $0x0, 0x10(%rax,%rsi)
paddq %xmm4, %xmm1
addq $0x10, %rsi
cmpq %rsi, %rdx
jne 0x35bf
testb $0x4, %bpl
je 0x3702
movslq %ecx, %rax
leaq 0x8(,%rax,8), %rdi
leaq 0x7e04(%rip), %rsi      # 0xb43f
callq 0x2af5
movq %rax, 0x18(%rbx)
testq %rax, %rax
je 0x38fb
leaq 0x8(%rax), %rcx
movq 0x8(%rsp), %rdx
movq %rcx, 0x18(%rdx)
movslq (%rsp), %rcx
testq %rcx, %rcx
jle 0x37bd
leal 0x1(%rcx), %edx
movq %rcx, %rsi
decq %rsi
movq %rsi, %xmm0
pshufd $0x44, %xmm0, %xmm0     # xmm0 = xmm0[0,1,0,1]
shrl %edx
shlq $0x4, %rdx
movdqa 0x7bc8(%rip), %xmm1     # 0xb250
xorl %esi, %esi
movdqa 0x7bce(%rip), %xmm2     # 0xb260
pxor %xmm2, %xmm0
pcmpeqd %xmm3, %xmm3
movdqa 0x7bce(%rip), %xmm4     # 0xb270
movdqa %xmm1, %xmm5
pxor %xmm2, %xmm5
movdqa %xmm5, %xmm6
pcmpgtd %xmm0, %xmm6
pcmpeqd %xmm0, %xmm5
pshufd $0xf5, %xmm5, %xmm7     # xmm7 = xmm5[1,1,3,3]
pand %xmm6, %xmm7
pshufd $0xf5, %xmm6, %xmm5     # xmm5 = xmm6[1,1,3,3]
por %xmm7, %xmm5
movd %xmm5, %edi
notl %edi
testb $0x1, %dil
je 0x36dd
movq $0x0, 0x8(%rax,%rsi)
pxor %xmm3, %xmm5
pextrw $0x4, %xmm5, %edi
testb $0x1, %dil
je 0x36f5
movq $0x0, 0x10(%rax,%rsi)
paddq %xmm4, %xmm1
addq $0x10, %rsi
cmpq %rsi, %rdx
jne 0x36a2
testl %ecx, %ecx
jle 0x37bd
leaq 0x27c0(%rsp), %r12
leaq 0x40(%rsp), %rbx
leaq 0x7d55(%rip), %r14      # 0xb473
xorl %r15d, %r15d
movq 0x10(%rsp), %rdi
leaq 0x7d39(%rip), %rsi      # 0xb466
leaq 0x24(%rsp), %rdx
movq %r12, %rcx
movq %rbx, %r8
xorl %eax, %eax
callq 0x1090
cmpl $0x3, %eax
jne 0x38f1
testb $0x1, %bpl
je 0x375b
movl 0x24(%rsp), %eax
movq 0x28(%rsp), %rcx
movl %eax, (%rcx,%r15,4)
testb $0x2, %bpl
je 0x3786
movq %r12, %rdi
movq %r14, %rsi
callq 0x2bb2
movq %rax, (%r13,%r15,8)
movq 0x8(%rsp), %rax
movq 0x10(%rax), %r13
cmpq $0x0, (%r13,%r15,8)
je 0x38fb
testb $0x4, %bpl
je 0x37ad
movq %rbx, %rdi
movq %r14, %rsi
callq 0x2bb2
movq 0x8(%rsp), %rcx
movq 0x18(%rcx), %rcx
movq %rax, (%rcx,%r15,8)
testq %rax, %rax
je 0x38fb
incq %r15
movslq (%rsp), %rax
cmpq %rax, %r15
jl 0x3721
leaq 0x7cc9(%rip), %rsi      # 0xb48d
leaq 0x4(%rsp), %rdx
movq 0x10(%rsp), %rdi
xorl %eax, %eax
callq 0x1090
cmpl $0x1, %eax
jne 0x38f1
leaq 0x7cb6(%rip), %rsi      # 0xb49b
leaq 0x38(%rsp), %rdx
leaq 0x1c(%rsp), %rcx
leaq 0x20(%rsp), %r8
movq 0x10(%rsp), %rdi
xorl %eax, %eax
callq 0x1090
cmpl $0x3, %eax
jne 0x38f1
testb $0x8, %bpl
je 0x38ad
movslq 0x4(%rsp), %rax
leaq 0x4(,%rax,4), %rdi
leaq 0x7c18(%rip), %r14      # 0xb43f
movq %r14, %rsi
callq 0x2af5
movq %rax, %rbx
movq 0x8(%rsp), %r15
movq %rax, 0x38(%r15)
movslq 0x4(%rsp), %rax
leaq 0x4(,%rax,4), %rdi
movq %r14, %rsi
callq 0x2af5
movq %rax, 0x40(%r15)
testq %rax, %rax
je 0x38fb
testq %rbx, %rbx
je 0x38fb
cmpl $0x0, 0x4(%rsp)
js 0x38ad
movq %rax, %r14
movq $-0x1, %r12
leaq 0x7c43(%rip), %r15      # 0xb4c1
movq 0x10(%rsp), %rdi
movq %r15, %rsi
movq %rbx, %rdx
movq %r14, %rcx
xorl %eax, %eax
callq 0x1090
cmpl $0x2, %eax
jne 0x38f1
movslq 0x4(%rsp), %rax
incq %r12
addq $0x4, %r14
addq $0x4, %rbx
cmpq %rax, %r12
jl 0x387e
movq 0x10(%rsp), %rdi
callq 0x10c0
movl (%rsp), %ecx
movq 0x8(%rsp), %rax
movl %ecx, (%rax)
movl 0x20(%rsp), %ecx
movl %ecx, 0x20(%rax)
movl 0x1c(%rsp), %ecx
movl %ecx, 0x24(%rax)
movq 0x38(%rsp), %rcx
movq %rcx, 0x28(%rax)
movl 0x4(%rsp), %ecx
movl %ecx, 0x30(%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 0x8(%rsp), %rdi
callq 0x3919
movq 0x10(%rsp), %rdi
callq 0x10c0
movl $0x1, %edi
callq 0x1270