// File: /workspace/github_c_makefile_star2_O1/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 0x663d
leaq 0x14(%rsp), %rdi
movl $0x4, %esi
movl $0x1, %edx
movq %r13, %rcx
callq 0x10b0
cmpq $0x1, %rax
jne 0x67a8
leaq 0x10(%rsp), %rdi
movl $0x4, %esi
movl $0x1, %edx
movq %r13, %rcx
callq 0x10b0
cmpq $0x1, %rax
jne 0x67a8
leaq 0x18(%rsp), %rdi
movl $0x4, %esi
movl $0x1, %edx
movq %r13, %rcx
callq 0x10b0
cmpq $0x1, %rax
jne 0x67a8
movslq 0x18(%rsp), %rbp
testq %r12, %r12
je 0x6659
movq %rbx, 0x20(%rsp)
leaq 0x1(%rbp), %rdi
leaq 0x556f(%rip), %rsi      # 0xbaa9
callq 0x2b85
movq %rax, %r14
movl 0x14(%rsp), %ebx
movslq %ebx, %r15
leaq (,%r15,8), %rdi
leaq 0x5567(%rip), %rsi      # 0xbabf
callq 0x2b85
movq %r14, %rdi
movq %rax, %r14
testq %rdi, %rdi
je 0x6819
testq %r14, %r14
je 0x6819
movl $0x1, %esi
movq %rdi, 0x8(%rsp)
movq %rbp, %rdx
movq %r13, %rcx
callq 0x10b0
cmpq %rbp, %rax
jne 0x67d1
movl $0x8, %esi
movq %r14, %rdi
movq %r15, %rdx
movq %r13, %rcx
callq 0x10b0
cmpq %r15, %rax
jne 0x67d1
movq 0x8(%rsp), %rdi
movb $0x0, (%rdi,%rbp)
movl 0x4(%r12), %eax
movl 0x1c(%rsp), %ebp
testl %eax, %eax
je 0x6687
cmpl (%r12), %ebp
jne 0x6728
cmpl %eax, %ebx
jne 0x6732
movl 0x10(%rsp), %r13d
cmpl 0x8(%r12), %r13d
jne 0x673c
movq 0x10(%r12), %r15
movq %r15, %rsi
callq 0x1190
testl %eax, %eax
jne 0x6746
movq 0x18(%r12), %rax
testl %ebp, %ebp
je 0x66a5
testl %r13d, %r13d
je 0x66c2
testl %ebx, %ebx
jle 0x6705
xorl %ecx, %ecx
movsd (%r14,%rcx,8), %xmm0
addsd (%rax,%rcx,8), %xmm0
movsd %xmm0, (%rax,%rcx,8)
incq %rcx
cmpq %rcx, %rbx
jne 0x6620
jmp 0x6705
movq %r13, %rdi
callq 0x10a0
movl %eax, %ecx
movl $0x1, %eax
testl %ecx, %ecx
je 0x6719
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 0x6719
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 0x6717
testl %r13d, %r13d
je 0x66e9
testl %ebx, %ebx
jle 0x6705
xorl %ecx, %ecx
movq (%r14,%rcx,8), %rdx
addq %rdx, (%rax,%rcx,8)
incq %rcx
cmpq %rcx, %rbx
jne 0x66b0
jmp 0x6705
testl %ebx, %ebx
jle 0x6705
xorl %ecx, %ecx
movsd (%rax,%rcx,8), %xmm0
ucomisd (%r14,%rcx,8), %xmm0
jne 0x678a
jp 0x678a
incq %rcx
cmpq %rcx, %rbx
jne 0x66c8
jmp 0x6705
testl %ebx, %ebx
jle 0x6705
xorl %ecx, %ecx
movq (%rax,%rcx,8), %rdx
cmpq (%r14,%rcx,8), %rdx
jne 0x6799
incq %rcx
cmpq %rcx, %rbx
jne 0x66ef
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 0x6770
movq %rdi, %rbx
callq 0x1b92
jmp 0x6770
movq %rdi, %rbx
callq 0x1bb4
jmp 0x6770
movq 0x98ab(%rip), %rax      # 0xfff8
movq (%rax), %rdi
movq 0xc191(%rip), %rdx      # 0x128e8
leaq 0x5458(%rip), %rsi      # 0xbbb6
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 0x6770
movq 0x8(%rsp), %rbx
movq %rbx, %rdi
callq 0x1bf8
jmp 0x6770
movq %r13, %rdi
callq 0x10a0
movq 0x9841(%rip), %rcx      # 0xfff8
movq (%rcx), %rdi
movq 0xc127(%rip), %rdx      # 0x128e8
testl %eax, %eax
jne 0x6806
leaq 0x52bf(%rip), %rsi      # 0xba8b
movq %rbx, %rcx
jmp 0x67fa
movq %r13, %rdi
callq 0x10a0
movq 0x9818(%rip), %rcx      # 0xfff8
movq (%rcx), %rdi
movq 0xc0fe(%rip), %rdx      # 0x128e8
testl %eax, %eax
jne 0x6806
leaq 0x5296(%rip), %rsi      # 0xba8b
movq 0x20(%rsp), %rcx
xorl %eax, %eax
callq 0x11a0
jmp 0x6780
leaq 0x4810(%rip), %rsi      # 0xb01d
xorl %eax, %eax
callq 0x11a0
jmp 0x6780
callq 0x1030
movq %r14, %rdi
jmp 0x677b