// File: /workspace/github_c_makefile_star2_O3/josch[P]stride/rdmap.c
// Function: ReadPhiPsiMap
int ReadPhiPsiMap(char *MapFile, float ***PhiPsiMap, COMMAND *Cmd)
{

  int i, j, NFields, Cnt=0;
  FILE *fi;
  BUFFER Buffer;
  char *Fields[MAX_FIELD];

  Cmd->NPixel = 0;

  if( (fi = fopen(MapFile,"r")) != 0 ) {

    while( fgets(Buffer,BUFSZ,fi) != NULL ) {
      if( !(NFields = SplitString(Buffer,Fields,MAX_FIELD)) ) continue;
      if( Cmd->NPixel == 0 ) {
	if( !strcmp(tolostr(Fields[0]),"npixel") ) {
	  Cmd->NPixel = atoi(Fields[1]);
	  if( Cmd->NPixel < 1 || Cmd->NPixel > 1000 ) 
	    die("Wrong number of pixels in the PhiPsi Map file %s\n",MapFile);
	  *PhiPsiMap = FloatMatrix(Cmd->NPixel,Cmd->NPixel);
	}
      }
      else  {
	if( !strcmp(tolostr(Fields[0]),"pixel") ) {
	  if( (i = atoi(Fields[1])) >= 0 && i < Cmd->NPixel &&
	      (j = atoi(Fields[2])) >= 0 && j < Cmd->NPixel &&
	     Cnt ==  i*Cmd->NPixel+j &&  NFields >= 4 ) {
	    (*PhiPsiMap)[i][j] = atof(Fields[5]);
	    Cnt++;
	  }
	  else die("Error in the PhiPsi Map file %s\n",MapFile);
	}
      }
    }
    fclose(fi);
    Cmd->PhiPsiStep = (MAXPHIPSI - MINPHIPSI)/(float)Cmd->NPixel;
  }
  
  if( !Cmd->NPixel ) die("Error reading PhiPsiMap file %s\n",MapFile);

  return(Cmd->NPixel);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x5b8, %rsp            # imm = 0x5B8
movq %rdx, %rbx
movq %rsi, %r15
movq %rdi, %r14
movl $0x0, 0x1cf4(%rdx)
leaq 0x12d16(%rip), %rsi     # 0x1aaa5
callq 0x21b0
testq %rax, %rax
je 0x7f4f
movq %rax, %r12
movq %r15, 0x18(%rsp)
movq %rbx, 0x8(%rsp)
leaq 0x1b0(%rsp), %r13
leaq 0x20(%rsp), %rbp
movl $0x0, 0x4(%rsp)
movq %r13, %rdi
movl $0x400, %esi            # imm = 0x400
movq %r12, %rdx
callq 0x2130
testq %rax, %rax
je 0x7f1f
movq %r13, %rdi
movq %rbp, %rsi
movl $0x32, %edx
callq 0x36c4
testl %eax, %eax
je 0x7dbf
movl %eax, %r15d
movq %r14, %rbx
movq 0x8(%rsp), %rax
movl 0x1cf4(%rax), %r14d
movq 0x20(%rsp), %rdi
callq 0x4de8
movq %rax, %rdi
testl %r14d, %r14d
je 0x7e89
leaq 0x11efa(%rip), %rsi     # 0x19d11
callq 0x2150
testl %eax, %eax
movq %rbx, %r14
jne 0x7dbf
movq 0x28(%rsp), %rdi
callq 0x21f0
testl %eax, %eax
js 0x7e73
movl %eax, %ebx
movq 0x8(%rsp), %rax
movl 0x1cf4(%rax), %eax
cmpl %eax, %ebx
jge 0x7e73
movq 0x30(%rsp), %rdi
movl %eax, 0x14(%rsp)
callq 0x21f0
movl 0x14(%rsp), %esi
testl %eax, %eax
sets %dl
cmpl %esi, %eax
setge %cl
orb %dl, %cl
jne 0x7e73
cmpl $0x4, %r15d
jl 0x7e73
imull %ebx, %esi
addl %eax, %esi
cmpl %esi, 0x4(%rsp)
je 0x7eef
leaq 0x11ecf(%rip), %rdi     # 0x19d49
movq %r14, %rsi
xorl %eax, %eax
callq 0x87c8
jmp 0x7dbf
leaq 0x11e80(%rip), %rsi     # 0x19d10
callq 0x2150
testl %eax, %eax
movq %rbx, %r14
jne 0x7dbf
movq 0x28(%rsp), %rdi
callq 0x21f0
movq 0x8(%rsp), %rbx
movl %eax, 0x1cf4(%rbx)
movl %eax, %ecx
movl $0xfffffc17, %edx       # imm = 0xFFFFFC17
addl %edx, %ecx
cmpl %edx, %ecx
ja 0x7ed9
leaq 0x11e4e(%rip), %rdi     # 0x19d17
movq %r14, %rsi
xorl %eax, %eax
callq 0x87c8
movl 0x1cf4(%rbx), %eax
movl %eax, %edi
movl %eax, %esi
callq 0x58a1
movq 0x18(%rsp), %rcx
movq %rax, (%rcx)
jmp 0x7dbf
movq 0x48(%rsp), %rdi
movl %eax, %r15d
callq 0x2080
cvtsd2ss %xmm0, %xmm0
movq 0x18(%rsp), %rax
movq (%rax), %rax
movl %ebx, %ecx
movq (%rax,%rcx,8), %rax
movl %r15d, %ecx
movss %xmm0, (%rax,%rcx,4)
incl 0x4(%rsp)
jmp 0x7dbf
movq %r12, %rdi
callq 0x20a0
movq 0x8(%rsp), %rbx
movl 0x1cf4(%rbx), %eax
xorps %xmm0, %xmm0
cvtsi2ss %eax, %xmm0
movss 0x11d93(%rip), %xmm1    # 0x19cd4
divss %xmm0, %xmm1
movss %xmm1, 0x1d08(%rbx)
jmp 0x7f55
movl 0x1cf4(%rbx), %eax
testl %eax, %eax
jne 0x7f70
leaq 0x11e0a(%rip), %rdi     # 0x19d6a
movq %r14, %rsi
xorl %eax, %eax
callq 0x87c8
movl 0x1cf4(%rbx), %eax
addq $0x5b8, %rsp            # imm = 0x5B8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq