// File: /workspace/github_c_makefile_star2_O1/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 0x12bea(%rip), %rsi     # 0x1aab5
callq 0x21b0
testq %rax, %rax
je 0x807c
movq %rax, %r12
movq %r15, 0x10(%rsp)
leaq 0x1b0(%rsp), %r13
leaq 0x20(%rsp), %rbp
movl $0x0, 0x8(%rsp)
movq %r13, %rdi
movl $0x400, %esi            # imm = 0x400
movq %r12, %rdx
callq 0x2130
testq %rax, %rax
je 0x8055
movq %r13, %rdi
movq %rbp, %rsi
movl $0x32, %edx
callq 0x36b8
testl %eax, %eax
je 0x7ef6
movl %eax, %r15d
movq %r14, 0x18(%rsp)
movl 0x1cf4(%rbx), %r14d
movq 0x20(%rsp), %rdi
callq 0x4ec0
movq %rax, %rdi
testl %r14d, %r14d
je 0x7fc0
leaq 0x11db6(%rip), %rsi     # 0x19d01
callq 0x2150
testl %eax, %eax
movq 0x18(%rsp), %r14
jne 0x7ef6
movq 0x28(%rsp), %rdi
callq 0x21f0
testl %eax, %eax
js 0x7faa
movl 0x1cf4(%rbx), %ecx
cmpl %ecx, %eax
jge 0x7faa
movq 0x30(%rsp), %rdi
movl %eax, 0xc(%rsp)
movl %ecx, 0x4(%rsp)
callq 0x21f0
movl 0x4(%rsp), %esi
testl %eax, %eax
sets %dl
cmpl %esi, %eax
setge %cl
orb %dl, %cl
movl 0xc(%rsp), %ecx
jne 0x7faa
cmpl $0x4, %r15d
jl 0x7faa
imull %ecx, %esi
addl %eax, %esi
cmpl %esi, 0x8(%rsp)
je 0x801f
leaq 0x11d88(%rip), %rdi     # 0x19d39
movq %r14, %rsi
xorl %eax, %eax
callq 0x8900
jmp 0x7ef6
leaq 0x11d39(%rip), %rsi     # 0x19d00
callq 0x2150
testl %eax, %eax
movq 0x18(%rsp), %r14
jne 0x7ef6
movq 0x28(%rsp), %rdi
callq 0x21f0
movl %eax, 0x1cf4(%rbx)
movl $0xfffffc17, %ecx       # imm = 0xFFFFFC17
addl %ecx, %eax
cmpl %ecx, %eax
ja 0x8005
leaq 0x11d0c(%rip), %rdi     # 0x19d07
movq %r14, %rsi
xorl %eax, %eax
callq 0x8900
movl 0x1cf4(%rbx), %edi
movl %edi, %esi
callq 0x597d
movq 0x10(%rsp), %rcx
movq %rax, (%rcx)
jmp 0x7ef6
movq 0x48(%rsp), %rdi
movl %ecx, %r15d
movl %eax, 0x4(%rsp)
callq 0x2080
cvtsd2ss %xmm0, %xmm0
movq 0x10(%rsp), %rax
movq (%rax), %rax
movl %r15d, %ecx
movq (%rax,%rcx,8), %rax
movl 0x4(%rsp), %ecx
movss %xmm0, (%rax,%rcx,4)
incl 0x8(%rsp)
jmp 0x7ef6
movq %r12, %rdi
callq 0x20a0
xorps %xmm0, %xmm0
cvtsi2ssl 0x1cf4(%rbx), %xmm0
movss 0x11c54(%rip), %xmm1    # 0x19cc4
divss %xmm0, %xmm1
movss %xmm1, 0x1d08(%rbx)
cmpl $0x0, 0x1cf4(%rbx)
jne 0x8096
leaq 0x11cce(%rip), %rdi     # 0x19d5a
movq %r14, %rsi
xorl %eax, %eax
callq 0x8900
movl 0x1cf4(%rbx), %eax
addq $0x5b8, %rsp            # imm = 0x5B8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq