// File: /workspace/github_c_makefile_star2_O3/thegenemyers[P]DASCRUBBER/DB.c
// Function: Read_Extra
int Read_Extra(FILE *afile, char *aname, DAZZ_EXTRA *extra)
{ int   vtype, nelem, accum, slen;
  char *name;
  void *value;

#define EREAD(v,s,n,file,ret)                                                           \
  { if (fread(v,s,n,file) != (size_t) n)                                                \
      { if (ferror(file))                                                               \
          EPRINTF(EPLACE,"%s: System error, read failed!\n",Prog_Name);       		\
        else if (ret)                                                                   \
          return (1);									\
        else										\
          EPRINTF(EPLACE,"%s: The file %s is corrupted\n",Prog_Name,aname);		\
        EXIT(-1);									\
      }                                                                                 \
  }

  EREAD(&vtype,sizeof(int),1,afile,1)
  EREAD(&nelem,sizeof(int),1,afile,0)
  EREAD(&accum,sizeof(int),1,afile,0)
  EREAD(&slen,sizeof(int),1,afile,0)

  if (extra == NULL)
    { if (fseeko(afile,slen+8*nelem,SEEK_CUR) < 0)
        { EPRINTF(EPLACE,"%s: System error, read failed!\n",Prog_Name);
          EXIT(-1);
        }
      return (0);
    }

  name  = (char *) Malloc(slen+1,"Allocating extra name");
  value = Malloc(8*nelem,"Allocating extra value");
  if (value == NULL || name == NULL)
    { free(name);
      free(value);
      EXIT(-1);
    }

  EREAD(name,1,slen,afile,0);
  EREAD(value,8,nelem,afile,0);
  name[slen] = '\0';
  
  if (extra->nelem == 0)
    { extra->vtype = vtype;
      extra->nelem = nelem;
      extra->accum = accum;
      extra->name  = name;
      extra->value = value;
      return (0);
    }

  if (vtype != extra->vtype)
    { EPRINTF(EPLACE,"%s: Type of extra %s does not agree with previous .anno block files\n",
                     Prog_Name,name);
      goto error;
    }
  if (nelem != extra->nelem)
    { EPRINTF(EPLACE,"%s: Length of extra %s does not agree with previous .anno block files\n",
                     Prog_Name,name);
      goto error;
    }
  if (accum != extra->accum)
    { EPRINTF(EPLACE,
           "%s: Reduction indicator of extra %s does not agree with previous .anno block files\n",
           Prog_Name,name);
      goto error;
    }
  if (strcmp(name,extra->name) != 0)
    { EPRINTF(EPLACE,"%s: Expecting extra %s in .anno block file, not %s\n",
                     Prog_Name,extra->name,name);
      goto error;
    }

  if (vtype == DB_INT)
    { int64 *ival = (int64 *) value;
      int64 *eval = (int64 *) (extra->value);
      int    j;

      if (accum == DB_EXACT)
        { for (j = 0; j < nelem; j++)
            if (eval[j] != ival[j])
              { EPRINTF(EPLACE,
                    "%s: Value of extra %s doe not agree with previous .anno block files\n",
                    Prog_Name,name);
                goto error;
              }
        }
      else
        { for (j = 0; j < nelem; j++)
            eval[j] += ival[j];
        }
    }

  else
    { double *ival = (double *) value;
      double *eval = (double *) (extra->value);
      int     j;

      if (accum == DB_EXACT)
        { for (j = 0; j < nelem; j++)
            if (eval[j] != ival[j])
              { EPRINTF(EPLACE,
                    "%s: Value of extra %s doe not agree with previous .anno block files\n",
                    Prog_Name,name);
                goto error;
              }
        }
      else
        { for (j = 0; j < nelem; j++)
            eval[j] += ival[j];
        }
    }

  free(value);
  free(name);
  return (0);

error:
  free(value);
  free(name);
  EXIT(-2);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movq %rdx, %r12
movq %rsi, %rbx
movq %rdi, %r13
leaq 0x1c(%rsp), %rdi
movl $0x4, %esi
movl $0x1, %edx
movq %r13, %rcx
callq 0x10b0
cmpq $0x1, %rax
jne 0x664b
leaq 0x14(%rsp), %rdi
movl $0x4, %esi
movl $0x1, %edx
movq %r13, %rcx
callq 0x10b0
cmpq $0x1, %rax
jne 0x67b6
leaq 0x10(%rsp), %rdi
movl $0x4, %esi
movl $0x1, %edx
movq %r13, %rcx
callq 0x10b0
cmpq $0x1, %rax
jne 0x67b6
leaq 0x18(%rsp), %rdi
movl $0x4, %esi
movl $0x1, %edx
movq %r13, %rcx
callq 0x10b0
cmpq $0x1, %rax
jne 0x67b6
movslq 0x18(%rsp), %rbp
testq %r12, %r12
je 0x6667
movq %rbx, 0x20(%rsp)
leaq 0x1(%rbp), %rdi
leaq 0x55c1(%rip), %rsi      # 0xbb09
callq 0x2af5
movq %rax, %r14
movl 0x14(%rsp), %ebx
movslq %ebx, %r15
leaq (,%r15,8), %rdi
leaq 0x55b9(%rip), %rsi      # 0xbb1f
callq 0x2af5
movq %r14, %rdi
movq %rax, %r14
testq %rdi, %rdi
je 0x6827
testq %r14, %r14
je 0x6827
movl $0x1, %esi
movq %rdi, 0x8(%rsp)
movq %rbp, %rdx
movq %r13, %rcx
callq 0x10b0
cmpq %rbp, %rax
jne 0x67df
movl $0x8, %esi
movq %r14, %rdi
movq %r15, %rdx
movq %r13, %rcx
callq 0x10b0
cmpq %r15, %rax
jne 0x67df
movq 0x8(%rsp), %rdi
movb $0x0, (%rdi,%rbp)
movl 0x4(%r12), %eax
movl 0x1c(%rsp), %ebp
testl %eax, %eax
je 0x6695
cmpl (%r12), %ebp
jne 0x6736
cmpl %eax, %ebx
jne 0x6740
movl 0x10(%rsp), %r13d
cmpl 0x8(%r12), %r13d
jne 0x674a
movq 0x10(%r12), %r15
movq %r15, %rsi
callq 0x1190
testl %eax, %eax
jne 0x6754
movq 0x18(%r12), %rax
testl %ebp, %ebp
je 0x66b3
testl %r13d, %r13d
je 0x66d0
testl %ebx, %ebx
jle 0x6713
xorl %ecx, %ecx
movsd (%r14,%rcx,8), %xmm0
addsd (%rax,%rcx,8), %xmm0
movsd %xmm0, (%rax,%rcx,8)
incq %rcx
cmpq %rcx, %rbx
jne 0x662e
jmp 0x6713
movq %r13, %rdi
callq 0x10a0
movl %eax, %ecx
movl $0x1, %eax
testl %ecx, %ecx
je 0x6727
callq 0x1b48
movslq 0x14(%rsp), %rax
leaq (,%rax,8), %rsi
addq %rbp, %rsi
movq %r13, %rdi
movl $0x1, %edx
callq 0x1230
movl %eax, %ecx
xorl %eax, %eax
testl %ecx, %ecx
jns 0x6727
callq 0x1c1a
movl %ebp, (%r12)
movl %ebx, 0x4(%r12)
movl 0x10(%rsp), %eax
movl %eax, 0x8(%r12)
movq %rdi, 0x10(%r12)
movq %r14, 0x18(%r12)
jmp 0x6725
testl %r13d, %r13d
je 0x66f7
testl %ebx, %ebx
jle 0x6713
xorl %ecx, %ecx
movq (%r14,%rcx,8), %rdx
addq %rdx, (%rax,%rcx,8)
incq %rcx
cmpq %rcx, %rbx
jne 0x66be
jmp 0x6713
testl %ebx, %ebx
jle 0x6713
xorl %ecx, %ecx
movsd (%rax,%rcx,8), %xmm0
ucomisd (%r14,%rcx,8), %xmm0
jne 0x6798
jp 0x6798
incq %rcx
cmpq %rcx, %rbx
jne 0x66d6
jmp 0x6713
testl %ebx, %ebx
jle 0x6713
xorl %ecx, %ecx
movq (%rax,%rcx,8), %rdx
cmpq (%r14,%rcx,8), %rdx
jne 0x67a7
incq %rcx
cmpq %rcx, %rbx
jne 0x66fd
movq %r14, %rdi
callq 0x1030
movq 0x8(%rsp), %rdi
callq 0x1030
xorl %eax, %eax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rdi, %rbx
callq 0x1b70
jmp 0x677e
movq %rdi, %rbx
callq 0x1b92
jmp 0x677e
movq %rdi, %rbx
callq 0x1bb4
jmp 0x677e
movq 0x989d(%rip), %rax      # 0xfff8
movq (%rax), %rdi
movq 0xc183(%rip), %rdx      # 0x128e8
leaq 0x54aa(%rip), %rsi      # 0xbc16
movq %r15, %rcx
movq 0x8(%rsp), %rbx
movq %rbx, %r8
xorl %eax, %eax
callq 0x11a0
movq %r14, %rdi
callq 0x1030
movq %rbx, %rdi
callq 0x1030
movl $0x1, %edi
callq 0x1270
movq 0x8(%rsp), %rbx
movq %rbx, %rdi
callq 0x1bd6
jmp 0x677e
movq 0x8(%rsp), %rbx
movq %rbx, %rdi
callq 0x1bf8
jmp 0x677e
movq %r13, %rdi
callq 0x10a0
movq 0x9833(%rip), %rcx      # 0xfff8
movq (%rcx), %rdi
movq 0xc119(%rip), %rdx      # 0x128e8
testl %eax, %eax
jne 0x6814
leaq 0x5311(%rip), %rsi      # 0xbaeb
movq %rbx, %rcx
jmp 0x6808
movq %r13, %rdi
callq 0x10a0
movq 0x980a(%rip), %rcx      # 0xfff8
movq (%rcx), %rdi
movq 0xc0f0(%rip), %rdx      # 0x128e8
testl %eax, %eax
jne 0x6814
leaq 0x52e8(%rip), %rsi      # 0xbaeb
movq 0x20(%rsp), %rcx
xorl %eax, %eax
callq 0x11a0
jmp 0x678e
leaq 0x4802(%rip), %rsi      # 0xb01d
xorl %eax, %eax
callq 0x11a0
jmp 0x678e
callq 0x1030
movq %r14, %rdi
jmp 0x6789