// File: sundale[P]gcode/rs274ngc/interp_read.cc
// Function: Interp::read_g(char*, int*, block_struct*, double*)
int Interp::read_g(char *line,   //!< string: line of RS274/NGC code being processed
                  int *counter, //!< pointer to a counter for position on the line 
                  block_pointer block,  //!< pointer to a block being filled from the line 
                  double *parameters)   //!< array of system parameters                    
{
  double value_read;
  int value;
  int mode;

  CHKS((line[*counter] != 'g'), NCE_BUG_FUNCTION_SHOULD_NOT_HAVE_BEEN_CALLED);
  *counter = (*counter + 1);
  CHP(read_real_value(line, counter, &value_read, parameters));
  value_read = (10.0 * value_read);
  value = (int) floor(value_read);

  if ((value_read - value) > 0.999)
    value = (int) ceil(value_read);
  else if ((value_read - value) > 0.001)
    ERS(NCE_G_CODE_OUT_OF_RANGE);

  CHKS((value > 999), NCE_G_CODE_OUT_OF_RANGE);
  CHKS((value < 0), NCE_NEGATIVE_G_CODE_USED);
  mode = _gees[value];
  CHKS((mode == -1), NCE_UNKNOWN_G_CODE_USED);
  if ((value == G_80) && (block->g_modes[mode] != -1));
  else {
    if (block->g_modes[mode] == G_80);
    else {
      CHKS((block->g_modes[mode] != -1),
          NCE_TWO_G_CODES_USED_FROM_SAME_MODAL_GROUP);
    }
    block->g_modes[mode] = value;
  }
  return INTERP_OK;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x50, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq %rdx, -0x20(%rbp)
movq %rcx, -0x28(%rbp)
movq %r8, -0x30(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0x50(%rbp)
movq -0x18(%rbp), %rax
movq -0x20(%rbp), %rcx
movslq (%rcx), %rcx
movsbl (%rax,%rcx), %eax
cmpl $0x67, %eax
je 0x5ed71
jmp 0x5ec9e
leaq 0x1d740(%rip), %rdi     # 0x7c3e5
callq 0x10380
movq -0x50(%rbp), %rdi
movq %rax, %rsi
movb $0x0, %al
callq 0x10df0
movq 0x282a1(%rip), %rax     # 0x86f60
movl $0x0, 0xd670(%rax)
movq 0x28290(%rip), %rax     # 0x86f60
movslq 0xd670(%rax), %rax
movq 0x28282(%rip), %rdi     # 0x86f60
addq $0xc6d0, %rdi           # imm = 0xC6D0
imulq $0x50, %rax, %rax
addq %rax, %rdi
leaq 0x1e8de(%rip), %rsi     # 0x7d5d1
movl $0x50, %edx
callq 0x10840
movq 0x2825c(%rip), %rax     # 0x86f60
movslq 0xd670(%rax), %rcx
movq 0x2824e(%rip), %rax     # 0x86f60
addq $0xc6d0, %rax           # imm = 0xC6D0
imulq $0x50, %rcx, %rcx
addq %rcx, %rax
movb $0x0, 0x4f(%rax)
movq 0x28236(%rip), %rax     # 0x86f60
movl 0xd670(%rax), %ecx
addl $0x1, %ecx
movq 0x28226(%rip), %rax     # 0x86f60
movl %ecx, 0xd670(%rax)
movq 0x28219(%rip), %rax     # 0x86f60
movslq 0xd670(%rax), %rcx
movq 0x2820b(%rip), %rax     # 0x86f60
addq $0xc6d0, %rax           # imm = 0xC6D0
imulq $0x50, %rcx, %rcx
addq %rcx, %rax
movb $0x0, (%rax)
movl $0x5, -0x4(%rbp)
jmp 0x5f3af
jmp 0x5ed73
movq -0x20(%rbp), %rax
movl (%rax), %ecx
addl $0x1, %ecx
movq -0x20(%rbp), %rax
movl %ecx, (%rax)
movq -0x50(%rbp), %rdi
movq -0x18(%rbp), %rsi
movq -0x20(%rbp), %rdx
movq -0x30(%rbp), %r8
leaq -0x38(%rbp), %rcx
callq 0x118a0
movl %eax, -0x44(%rbp)
cmpl $0x0, -0x44(%rbp)
je 0x5ee65
jmp 0x5edaa
movq 0x281af(%rip), %rax     # 0x86f60
cmpl $0x31, 0xd670(%rax)
jge 0x5ee5a
movq 0x2819b(%rip), %rax     # 0x86f60
movslq 0xd670(%rax), %rax
movq 0x2818d(%rip), %rdi     # 0x86f60
addq $0xc6d0, %rdi           # imm = 0xC6D0
imulq $0x50, %rax, %rax
addq %rax, %rdi
leaq 0x1e7e9(%rip), %rsi     # 0x7d5d1
movl $0x50, %edx
callq 0x10840
movq 0x28167(%rip), %rax     # 0x86f60
movslq 0xd670(%rax), %rcx
movq 0x28159(%rip), %rax     # 0x86f60
addq $0xc6d0, %rax           # imm = 0xC6D0
imulq $0x50, %rcx, %rcx
addq %rcx, %rax
movb $0x0, 0x4f(%rax)
movq 0x28141(%rip), %rax     # 0x86f60
movl 0xd670(%rax), %ecx
addl $0x1, %ecx
movq 0x28131(%rip), %rax     # 0x86f60
movl %ecx, 0xd670(%rax)
movq 0x28124(%rip), %rax     # 0x86f60
movslq 0xd670(%rax), %rcx
movq 0x28116(%rip), %rax     # 0x86f60
addq $0xc6d0, %rax           # imm = 0xC6D0
imulq $0x50, %rcx, %rcx
addq %rcx, %rax
movb $0x0, (%rax)
movl -0x44(%rbp), %eax
movl %eax, -0x4(%rbp)
jmp 0x5f3af
jmp 0x5ee67
movsd 0x19fd1(%rip), %xmm0    # 0x78e40
mulsd -0x38(%rbp), %xmm0
movsd %xmm0, -0x38(%rbp)
movsd -0x38(%rbp), %xmm0
callq 0x11e50
cvttsd2si %xmm0, %eax
movl %eax, -0x3c(%rbp)
movsd -0x38(%rbp), %xmm0
cvtsi2sdl -0x3c(%rbp), %xmm1
subsd %xmm1, %xmm0
movsd 0x1e1b8(%rip), %xmm1    # 0x7d058
ucomisd %xmm1, %xmm0
jbe 0x5eebc
movsd -0x38(%rbp), %xmm0
callq 0x10250
cvttsd2si %xmm0, %eax
movl %eax, -0x3c(%rbp)
jmp 0x5efb3
movsd -0x38(%rbp), %xmm0
cvtsi2sdl -0x3c(%rbp), %xmm1
subsd %xmm1, %xmm0
movsd 0x1c676(%rip), %xmm1    # 0x7b548
ucomisd %xmm1, %xmm0
jbe 0x5efb1
jmp 0x5eede
leaq 0x1e727(%rip), %rdi     # 0x7d60c
callq 0x10380
movq -0x50(%rbp), %rdi
movq %rax, %rsi
movb $0x0, %al
callq 0x10df0
movq 0x28061(%rip), %rax     # 0x86f60
movl $0x0, 0xd670(%rax)
movq 0x28050(%rip), %rax     # 0x86f60
movslq 0xd670(%rax), %rax
movq 0x28042(%rip), %rdi     # 0x86f60
addq $0xc6d0, %rdi           # imm = 0xC6D0
imulq $0x50, %rax, %rax
addq %rax, %rdi
leaq 0x1e69e(%rip), %rsi     # 0x7d5d1
movl $0x50, %edx
callq 0x10840
movq 0x2801c(%rip), %rax     # 0x86f60
movslq 0xd670(%rax), %rcx
movq 0x2800e(%rip), %rax     # 0x86f60
addq $0xc6d0, %rax           # imm = 0xC6D0
imulq $0x50, %rcx, %rcx
addq %rcx, %rax
movb $0x0, 0x4f(%rax)
movq 0x27ff6(%rip), %rax     # 0x86f60
movl 0xd670(%rax), %ecx
addl $0x1, %ecx
movq 0x27fe6(%rip), %rax     # 0x86f60
movl %ecx, 0xd670(%rax)
movq 0x27fd9(%rip), %rax     # 0x86f60
movslq 0xd670(%rax), %rcx
movq 0x27fcb(%rip), %rax     # 0x86f60
addq $0xc6d0, %rax           # imm = 0xC6D0
imulq $0x50, %rcx, %rcx
addq %rcx, %rax
movb $0x0, (%rax)
movl $0x5, -0x4(%rbp)
jmp 0x5f3af
jmp 0x5efb3
jmp 0x5efb5
cmpl $0x3e7, -0x3c(%rbp)     # imm = 0x3E7
jle 0x5f097
jmp 0x5efc4
leaq 0x1e641(%rip), %rdi     # 0x7d60c
callq 0x10380
movq -0x50(%rbp), %rdi
movq %rax, %rsi
movb $0x0, %al
callq 0x10df0
movq 0x27f7b(%rip), %rax     # 0x86f60
movl $0x0, 0xd670(%rax)
movq 0x27f6a(%rip), %rax     # 0x86f60
movslq 0xd670(%rax), %rax
movq 0x27f5c(%rip), %rdi     # 0x86f60
addq $0xc6d0, %rdi           # imm = 0xC6D0
imulq $0x50, %rax, %rax
addq %rax, %rdi
leaq 0x1e5b8(%rip), %rsi     # 0x7d5d1
movl $0x50, %edx
callq 0x10840
movq 0x27f36(%rip), %rax     # 0x86f60
movslq 0xd670(%rax), %rcx
movq 0x27f28(%rip), %rax     # 0x86f60
addq $0xc6d0, %rax           # imm = 0xC6D0
imulq $0x50, %rcx, %rcx
addq %rcx, %rax
movb $0x0, 0x4f(%rax)
movq 0x27f10(%rip), %rax     # 0x86f60
movl 0xd670(%rax), %ecx
addl $0x1, %ecx
movq 0x27f00(%rip), %rax     # 0x86f60
movl %ecx, 0xd670(%rax)
movq 0x27ef3(%rip), %rax     # 0x86f60
movslq 0xd670(%rax), %rcx
movq 0x27ee5(%rip), %rax     # 0x86f60
addq $0xc6d0, %rax           # imm = 0xC6D0
imulq $0x50, %rcx, %rcx
addq %rcx, %rax
movb $0x0, (%rax)
movl $0x5, -0x4(%rbp)
jmp 0x5f3af
jmp 0x5f099
jmp 0x5f09b
cmpl $0x0, -0x3c(%rbp)
jge 0x5f17a
jmp 0x5f0a7
leaq 0x1e572(%rip), %rdi     # 0x7d620
callq 0x10380
movq -0x50(%rbp), %rdi
movq %rax, %rsi
movb $0x0, %al
callq 0x10df0
movq 0x27e98(%rip), %rax     # 0x86f60
movl $0x0, 0xd670(%rax)
movq 0x27e87(%rip), %rax     # 0x86f60
movslq 0xd670(%rax), %rax
movq 0x27e79(%rip), %rdi     # 0x86f60
addq $0xc6d0, %rdi           # imm = 0xC6D0
imulq $0x50, %rax, %rax
addq %rax, %rdi
leaq 0x1e4d5(%rip), %rsi     # 0x7d5d1
movl $0x50, %edx
callq 0x10840
movq 0x27e53(%rip), %rax     # 0x86f60
movslq 0xd670(%rax), %rcx
movq 0x27e45(%rip), %rax     # 0x86f60
addq $0xc6d0, %rax           # imm = 0xC6D0
imulq $0x50, %rcx, %rcx
addq %rcx, %rax
movb $0x0, 0x4f(%rax)
movq 0x27e2d(%rip), %rax     # 0x86f60
movl 0xd670(%rax), %ecx
addl $0x1, %ecx
movq 0x27e1d(%rip), %rax     # 0x86f60
movl %ecx, 0xd670(%rax)
movq 0x27e10(%rip), %rax     # 0x86f60
movslq 0xd670(%rax), %rcx
movq 0x27e02(%rip), %rax     # 0x86f60
addq $0xc6d0, %rax           # imm = 0xC6D0
imulq $0x50, %rcx, %rcx
addq %rcx, %rax
movb $0x0, (%rax)
movl $0x5, -0x4(%rbp)
jmp 0x5f3af
jmp 0x5f17c
movslq -0x3c(%rbp), %rcx
movq 0x27e09(%rip), %rax     # 0x86f90
movl (%rax,%rcx,4), %eax
movl %eax, -0x40(%rbp)
cmpl $-0x1, -0x40(%rbp)
jne 0x5f26c
jmp 0x5f199
leaq 0x1e495(%rip), %rdi     # 0x7d635
callq 0x10380
movq -0x50(%rbp), %rdi
movq %rax, %rsi
movb $0x0, %al
callq 0x10df0
movq 0x27da6(%rip), %rax     # 0x86f60
movl $0x0, 0xd670(%rax)
movq 0x27d95(%rip), %rax     # 0x86f60
movslq 0xd670(%rax), %rax
movq 0x27d87(%rip), %rdi     # 0x86f60
addq $0xc6d0, %rdi           # imm = 0xC6D0
imulq $0x50, %rax, %rax
addq %rax, %rdi
leaq 0x1e3e3(%rip), %rsi     # 0x7d5d1
movl $0x50, %edx
callq 0x10840
movq 0x27d61(%rip), %rax     # 0x86f60
movslq 0xd670(%rax), %rcx
movq 0x27d53(%rip), %rax     # 0x86f60
addq $0xc6d0, %rax           # imm = 0xC6D0
imulq $0x50, %rcx, %rcx
addq %rcx, %rax
movb $0x0, 0x4f(%rax)
movq 0x27d3b(%rip), %rax     # 0x86f60
movl 0xd670(%rax), %ecx
addl $0x1, %ecx
movq 0x27d2b(%rip), %rax     # 0x86f60
movl %ecx, 0xd670(%rax)
movq 0x27d1e(%rip), %rax     # 0x86f60
movslq 0xd670(%rax), %rcx
movq 0x27d10(%rip), %rax     # 0x86f60
addq $0xc6d0, %rax           # imm = 0xC6D0
imulq $0x50, %rcx, %rcx
addq %rcx, %rax
movb $0x0, (%rax)
movl $0x5, -0x4(%rbp)
jmp 0x5f3af
jmp 0x5f26e
cmpl $0x320, -0x3c(%rbp)     # imm = 0x320
jne 0x5f28e
movq -0x28(%rbp), %rax
movslq -0x40(%rbp), %rcx
cmpl $-0x1, 0x150(%rax,%rcx,4)
je 0x5f28e
jmp 0x5f3a8
movq -0x28(%rbp), %rax
movslq -0x40(%rbp), %rcx
cmpl $0x320, 0x150(%rax,%rcx,4) # imm = 0x320
jne 0x5f2a8
jmp 0x5f396
jmp 0x5f2aa
movq -0x28(%rbp), %rax
movslq -0x40(%rbp), %rcx
cmpl $-0x1, 0x150(%rax,%rcx,4)
je 0x5f392
jmp 0x5f2c2
leaq 0x1e380(%rip), %rdi     # 0x7d649
callq 0x10380
movq -0x50(%rbp), %rdi
movq %rax, %rsi
movb $0x0, %al
callq 0x10df0
movq 0x27c7d(%rip), %rax     # 0x86f60
movl $0x0, 0xd670(%rax)
movq 0x27c6c(%rip), %rax     # 0x86f60
movslq 0xd670(%rax), %rax
movq 0x27c5e(%rip), %rdi     # 0x86f60
addq $0xc6d0, %rdi           # imm = 0xC6D0
imulq $0x50, %rax, %rax
addq %rax, %rdi
leaq 0x1e2ba(%rip), %rsi     # 0x7d5d1
movl $0x50, %edx
callq 0x10840
movq 0x27c38(%rip), %rax     # 0x86f60
movslq 0xd670(%rax), %rcx
movq 0x27c2a(%rip), %rax     # 0x86f60
addq $0xc6d0, %rax           # imm = 0xC6D0
imulq $0x50, %rcx, %rcx
addq %rcx, %rax
movb $0x0, 0x4f(%rax)
movq 0x27c12(%rip), %rax     # 0x86f60
movl 0xd670(%rax), %ecx
addl $0x1, %ecx
movq 0x27c02(%rip), %rax     # 0x86f60
movl %ecx, 0xd670(%rax)
movq 0x27bf5(%rip), %rax     # 0x86f60
movslq 0xd670(%rax), %rcx
movq 0x27be7(%rip), %rax     # 0x86f60
addq $0xc6d0, %rax           # imm = 0xC6D0
imulq $0x50, %rcx, %rcx
addq %rcx, %rax
movb $0x0, (%rax)
movl $0x5, -0x4(%rbp)
jmp 0x5f3af
jmp 0x5f394
jmp 0x5f396
movl -0x3c(%rbp), %edx
movq -0x28(%rbp), %rax
movslq -0x40(%rbp), %rcx
movl %edx, 0x150(%rax,%rcx,4)
movl $0x0, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x50, %rsp
popq %rbp
retq
nopl (%rax,%rax)