// File: GenisGE[P]evalAdmix/Cinterface.cpp
// Function: readDoubleGZ(double**, int, int, char const*, int)
void readDoubleGZ(double **d,int x,int y,const char*fname,int neg){
  fprintf(stderr,"opening : %s with x=%d y=%d\n",fname,x,y);
  const char*delims=" \n";
  gzFile fp = NULL;
  if((fp=gzopen(fname,"r"))==NULL){
    fprintf(stderr,"cant open:%s\n",fname);
    exit(0);
  }
  int lens=1000000 ;
  char buf[lens];
  for(int i=0;i<x;i++){
    if(NULL==gzgets(fp,buf,lens)){
      fprintf(stderr,"Error: Only %d sites in frequency file, expected %d sites from plink/beagle file\n",i, x);
	exit(0);
    }
    if(neg)
      d[i][0] = 1-atof(strtok(buf,delims));
    else
      d[i][0] = atof(strtok(buf,delims));
    for(int j=1;j<y;j++){
      //      fprintf(stderr,"i=%d j=%d\n",i,j);
      if(neg)
	d[i][j] = 1-atof(strtok(NULL,delims));
      else
	d[i][j] = atof(strtok(NULL,delims));
    }
  }
  if(NULL!=gzgets(fp,buf,lens)){
    fprintf(stderr,"Error: Too many sites in frequency file. Only %d sites in plink/beagle file\n",x);
    exit(0);

  }
  gzclose(fp);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x60, %rsp
movq %rdi, -0x8(%rbp)
movl %esi, -0xc(%rbp)
movl %edx, -0x10(%rbp)
movq %rcx, -0x18(%rbp)
movl %r8d, -0x1c(%rbp)
movq 0x1a1d7(%rip), %rax     # 0x1efd8
movq (%rax), %rdi
movq -0x18(%rbp), %rdx
movl -0xc(%rbp), %ecx
movl -0x10(%rbp), %r8d
leaq 0x133a6(%rip), %rsi     # 0x181bc
movb $0x0, %al
callq 0x33c0
leaq 0x132d3(%rip), %rax     # 0x180f7
movq %rax, -0x28(%rbp)
movq $0x0, -0x30(%rbp)
movq -0x18(%rbp), %rdi
leaq 0x132bf(%rip), %rsi     # 0x180fa
callq 0x33f0
movq %rax, -0x30(%rbp)
cmpq $0x0, %rax
jne 0x4e6d
movq 0x1a187(%rip), %rax     # 0x1efd8
movq (%rax), %rdi
movq -0x18(%rbp), %rdx
leaq 0x1337a(%rip), %rsi     # 0x181d9
movb $0x0, %al
callq 0x33c0
xorl %edi, %edi
callq 0x3340
movl $0xf4240, -0x34(%rbp)   # imm = 0xF4240
movl -0x34(%rbp), %eax
movq %rsp, %rcx
movq %rcx, -0x40(%rbp)
movq %rax, %rdx
addq $0xf, %rdx
andq $-0x10, %rdx
movq %rsp, %rcx
subq %rdx, %rcx
movq %rcx, -0x58(%rbp)
movq %rcx, %rsp
movq %rax, -0x48(%rbp)
movl $0x0, -0x4c(%rbp)
movl -0x4c(%rbp), %eax
cmpl -0xc(%rbp), %eax
jge 0x4fe4
movq -0x58(%rbp), %rsi
movq -0x30(%rbp), %rdi
movl -0x34(%rbp), %edx
callq 0x34d0
movq %rax, %rcx
xorl %eax, %eax
cmpq %rcx, %rax
jne 0x4eec
movq 0x1a10a(%rip), %rax     # 0x1efd8
movq (%rax), %rdi
movl -0x4c(%rbp), %edx
movl -0xc(%rbp), %ecx
leaq 0x13309(%rip), %rsi     # 0x181e7
movb $0x0, %al
callq 0x33c0
xorl %edi, %edi
callq 0x3340
cmpl $0x0, -0x1c(%rbp)
je 0x4f28
movq -0x58(%rbp), %rdi
movq -0x28(%rbp), %rsi
callq 0x3470
movq %rax, %rdi
callq 0x3370
movaps %xmm0, %xmm1
movsd 0x130f6(%rip), %xmm0    # 0x18008
subsd %xmm1, %xmm0
movq -0x8(%rbp), %rax
movslq -0x4c(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movsd %xmm0, (%rax)
jmp 0x4f4d
movq -0x58(%rbp), %rdi
movq -0x28(%rbp), %rsi
callq 0x3470
movq %rax, %rdi
callq 0x3370
movq -0x8(%rbp), %rax
movslq -0x4c(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movsd %xmm0, (%rax)
movl $0x1, -0x50(%rbp)
movl -0x50(%rbp), %eax
cmpl -0x10(%rbp), %eax
jge 0x4fd4
cmpl $0x0, -0x1c(%rbp)
je 0x4f9d
movq -0x28(%rbp), %rsi
xorl %eax, %eax
movl %eax, %edi
callq 0x3470
movq %rax, %rdi
callq 0x3370
movaps %xmm0, %xmm1
movsd 0x13086(%rip), %xmm0    # 0x18008
subsd %xmm1, %xmm0
movq -0x8(%rbp), %rax
movslq -0x4c(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movslq -0x50(%rbp), %rcx
movsd %xmm0, (%rax,%rcx,8)
jmp 0x4fc7
movq -0x28(%rbp), %rsi
xorl %eax, %eax
movl %eax, %edi
callq 0x3470
movq %rax, %rdi
callq 0x3370
movq -0x8(%rbp), %rax
movslq -0x4c(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movslq -0x50(%rbp), %rcx
movsd %xmm0, (%rax,%rcx,8)
jmp 0x4fc9
movl -0x50(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x50(%rbp)
jmp 0x4f54
jmp 0x4fd6
movl -0x4c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x4c(%rbp)
jmp 0x4ea1
movq -0x58(%rbp), %rsi
movq -0x30(%rbp), %rdi
movl -0x34(%rbp), %edx
callq 0x34d0
movq %rax, %rcx
xorl %eax, %eax
cmpq %rcx, %rax
je 0x5020
movq 0x19fd3(%rip), %rax     # 0x1efd8
movq (%rax), %rdi
movl -0xc(%rbp), %edx
leaq 0x13227(%rip), %rsi     # 0x18239
movb $0x0, %al
callq 0x33c0
xorl %edi, %edi
callq 0x3340
movq -0x30(%rbp), %rdi
callq 0x34c0
movq -0x40(%rbp), %rax
movq %rax, %rsp
movq %rbp, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)