// File: sundale[P]gcode/rs274ngc/interp_read.cc
// Function: Interp::add_named_param(char*)
int Interp::add_named_param(
    char *nameBuf //!< pointer to name to be added
    )   
{
  static char name[] = "add_named_param";
  struct named_parameters_struct *nameList;
  int findStatus;
  double value;
  int level;
  char *dup;

  // look it up to see if already exists
  CHP(find_named_param(nameBuf, &findStatus, &value));

  if(findStatus)
  {
      logDebug("%s: parameter:|%s| already exists", name, nameBuf);
      return INTERP_OK;
  }

  // must do an add
  if(nameBuf[0] != '_') // local scope
  {
      level = _setup.call_level;
  }
  else
  {
      // call level zero is global scope
      level = 0;
  }

  nameList = &_setup.sub_context[level].named_parameters;

  if(nameList->named_parameter_used_size >=
     nameList->named_parameter_alloc_size)
  {
      // must realloc space
      nameList->named_parameter_alloc_size += NAMED_PARAMETERS_ALLOC_UNIT;

      logDebug("realloc space level[%d] size:%d",
               level, nameList->named_parameter_alloc_size);

      nameList->named_parameters =
          (char **)realloc((void *)nameList->named_parameters,
                      sizeof(char *)*nameList->named_parameter_alloc_size);

      nameList->named_param_values =
          (double *)realloc((void *)nameList->named_param_values,
                      sizeof(double)*nameList->named_parameter_alloc_size);

      if((nameList->named_parameters == 0) ||
         (nameList->named_param_values == 0))
      {
          ERS(NCE_OUT_OF_MEMORY);
      }
  }

  dup = strdup(nameBuf);
  if(dup == 0)
  {
      ERS(NCE_OUT_OF_MEMORY);
  }
  logDebug("%s strdup[0x%x]:|%s|", name, dup, dup);
  nameList->named_parameters[nameList->named_parameter_used_size++] = dup;

  return INTERP_OK;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x70, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0x50(%rbp)
movq -0x50(%rbp), %rdi
movq -0x18(%rbp), %rsi
leaq -0x24(%rbp), %rdx
leaq -0x30(%rbp), %rcx
callq 0x10830
movl %eax, -0x44(%rbp)
cmpl $0x0, -0x44(%rbp)
je 0x655c7
jmp 0x6550c
movq 0x21a4d(%rip), %rax     # 0x86f60
cmpl $0x31, 0xd670(%rax)
jge 0x655bc
movq 0x21a39(%rip), %rax     # 0x86f60
movslq 0xd670(%rax), %rax
movq 0x21a2b(%rip), %rdi     # 0x86f60
addq $0xc6d0, %rdi           # imm = 0xC6D0
imulq $0x50, %rax, %rax
addq %rax, %rdi
leaq 0x18ce3(%rip), %rsi     # 0x7e22d
movl $0x50, %edx
callq 0x10840
movq 0x21a05(%rip), %rax     # 0x86f60
movslq 0xd670(%rax), %rcx
movq 0x219f7(%rip), %rax     # 0x86f60
addq $0xc6d0, %rax           # imm = 0xC6D0
imulq $0x50, %rcx, %rcx
addq %rcx, %rax
movb $0x0, 0x4f(%rax)
movq 0x219df(%rip), %rax     # 0x86f60
movl 0xd670(%rax), %ecx
addl $0x1, %ecx
movq 0x219cf(%rip), %rax     # 0x86f60
movl %ecx, 0xd670(%rax)
movq 0x219c2(%rip), %rax     # 0x86f60
movslq 0xd670(%rax), %rcx
movq 0x219b4(%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 0x65988
jmp 0x655c9
cmpl $0x0, -0x24(%rbp)
je 0x6562c
jmp 0x655d1
xorl %eax, %eax
movq 0x21986(%rip), %rcx     # 0x86f60
cmpl 0x1b6b4(%rcx), %eax
jge 0x6561e
callq 0x11950
movq -0x50(%rbp), %rdi
movl %eax, %ecx
movq -0x18(%rbp), %rax
leaq 0x18c59(%rip), %rsi     # 0x7e251
xorl %edx, %edx
leaq 0x187c8(%rip), %r8      # 0x7ddc9
movl $0x75b, %r9d            # imm = 0x75B
leaq 0x22c02(%rip), %r10     # 0x88210
movq %r10, (%rsp)
movq %rax, 0x8(%rsp)
movb $0x0, %al
callq 0x12050
jmp 0x65620
movl $0x0, -0x4(%rbp)
jmp 0x65988
movq -0x18(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x5f, %eax
je 0x6564a
movq 0x21921(%rip), %rax     # 0x86f60
movl 0xef90(%rax), %eax
movl %eax, -0x34(%rbp)
jmp 0x65651
movl $0x0, -0x34(%rbp)
movslq -0x34(%rbp), %rcx
movq 0x21904(%rip), %rax     # 0x86f60
addq $0xef98, %rax           # imm = 0xEF98
imulq $0x128, %rcx, %rcx      # imm = 0x128
addq %rcx, %rax
addq $0x110, %rax            # imm = 0x110
movq %rax, -0x20(%rbp)
movq -0x20(%rbp), %rax
movl 0x4(%rax), %eax
movq -0x20(%rbp), %rcx
cmpl (%rcx), %eax
jl 0x65818
movq -0x20(%rbp), %rax
movl (%rax), %ecx
addl $0x14, %ecx
movl %ecx, (%rax)
xorl %eax, %eax
movq 0x218c3(%rip), %rcx     # 0x86f60
cmpl 0x1b6b4(%rcx), %eax
jge 0x656df
callq 0x11950
movq -0x50(%rbp), %rdi
movl %eax, %ecx
movl -0x34(%rbp), %r10d
movq -0x20(%rbp), %rax
movl (%rax), %eax
leaq 0x18bc5(%rip), %rsi     # 0x7e286
xorl %edx, %edx
leaq 0x186ff(%rip), %r8      # 0x7ddc9
movl $0x773, %r9d            # imm = 0x773
movl %r10d, (%rsp)
movl %eax, 0x8(%rsp)
movb $0x0, %al
callq 0x12050
jmp 0x656e1
movq -0x20(%rbp), %rax
movq 0x8(%rax), %rdi
movq -0x20(%rbp), %rax
movslq (%rax), %rsi
shlq $0x3, %rsi
callq 0x11ce0
movq %rax, %rcx
movq -0x20(%rbp), %rax
movq %rcx, 0x8(%rax)
movq -0x20(%rbp), %rax
movq 0x10(%rax), %rdi
movq -0x20(%rbp), %rax
movslq (%rax), %rsi
shlq $0x3, %rsi
callq 0x11ce0
movq %rax, %rcx
movq -0x20(%rbp), %rax
movq %rcx, 0x10(%rax)
movq -0x20(%rbp), %rax
cmpq $0x0, 0x8(%rax)
je 0x65741
movq -0x20(%rbp), %rax
cmpq $0x0, 0x10(%rax)
jne 0x65816
jmp 0x65743
leaq 0x18b6f(%rip), %rdi     # 0x7e2b9
callq 0x10380
movq -0x50(%rbp), %rdi
movq %rax, %rsi
movb $0x0, %al
callq 0x10df0
movq 0x217fc(%rip), %rax     # 0x86f60
movl $0x0, 0xd670(%rax)
movq 0x217eb(%rip), %rax     # 0x86f60
movslq 0xd670(%rax), %rax
movq 0x217dd(%rip), %rdi     # 0x86f60
addq $0xc6d0, %rdi           # imm = 0xC6D0
imulq $0x50, %rax, %rax
addq %rax, %rdi
leaq 0x18a95(%rip), %rsi     # 0x7e22d
movl $0x50, %edx
callq 0x10840
movq 0x217b7(%rip), %rax     # 0x86f60
movslq 0xd670(%rax), %rcx
movq 0x217a9(%rip), %rax     # 0x86f60
addq $0xc6d0, %rax           # imm = 0xC6D0
imulq $0x50, %rcx, %rcx
addq %rcx, %rax
movb $0x0, 0x4f(%rax)
movq 0x21791(%rip), %rax     # 0x86f60
movl 0xd670(%rax), %ecx
addl $0x1, %ecx
movq 0x21781(%rip), %rax     # 0x86f60
movl %ecx, 0xd670(%rax)
movq 0x21774(%rip), %rax     # 0x86f60
movslq 0xd670(%rax), %rcx
movq 0x21766(%rip), %rax     # 0x86f60
addq $0xc6d0, %rax           # imm = 0xC6D0
imulq $0x50, %rcx, %rcx
addq %rcx, %rax
movb $0x0, (%rax)
movl $0x5, -0x4(%rbp)
jmp 0x65988
jmp 0x65818
movq -0x18(%rbp), %rdi
callq 0x120d0
movq %rax, -0x40(%rbp)
cmpq $0x0, -0x40(%rbp)
jne 0x65905
jmp 0x65832
leaq 0x18a80(%rip), %rdi     # 0x7e2b9
callq 0x10380
movq -0x50(%rbp), %rdi
movq %rax, %rsi
movb $0x0, %al
callq 0x10df0
movq 0x2170d(%rip), %rax     # 0x86f60
movl $0x0, 0xd670(%rax)
movq 0x216fc(%rip), %rax     # 0x86f60
movslq 0xd670(%rax), %rax
movq 0x216ee(%rip), %rdi     # 0x86f60
addq $0xc6d0, %rdi           # imm = 0xC6D0
imulq $0x50, %rax, %rax
addq %rax, %rdi
leaq 0x189a6(%rip), %rsi     # 0x7e22d
movl $0x50, %edx
callq 0x10840
movq 0x216c8(%rip), %rax     # 0x86f60
movslq 0xd670(%rax), %rcx
movq 0x216ba(%rip), %rax     # 0x86f60
addq $0xc6d0, %rax           # imm = 0xC6D0
imulq $0x50, %rcx, %rcx
addq %rcx, %rax
movb $0x0, 0x4f(%rax)
movq 0x216a2(%rip), %rax     # 0x86f60
movl 0xd670(%rax), %ecx
addl $0x1, %ecx
movq 0x21692(%rip), %rax     # 0x86f60
movl %ecx, 0xd670(%rax)
movq 0x21685(%rip), %rax     # 0x86f60
movslq 0xd670(%rax), %rcx
movq 0x21677(%rip), %rax     # 0x86f60
addq $0xc6d0, %rax           # imm = 0xC6D0
imulq $0x50, %rcx, %rcx
addq %rcx, %rax
movb $0x0, (%rax)
movl $0x5, -0x4(%rbp)
jmp 0x65988
jmp 0x65907
xorl %eax, %eax
movq 0x21650(%rip), %rcx     # 0x86f60
cmpl 0x1b6b4(%rcx), %eax
jge 0x6595d
callq 0x11950
movq -0x50(%rbp), %rdi
movl %eax, %ecx
movq -0x40(%rbp), %r10
movq -0x40(%rbp), %rax
leaq 0x18995(%rip), %rsi     # 0x7e2c7
xorl %edx, %edx
leaq 0x1848e(%rip), %r8      # 0x7ddc9
movl $0x789, %r9d            # imm = 0x789
leaq 0x228c8(%rip), %r11     # 0x88210
movq %r11, (%rsp)
movq %r10, 0x8(%rsp)
movq %rax, 0x10(%rsp)
movb $0x0, %al
callq 0x12050
jmp 0x6595f
movq -0x40(%rbp), %rdx
movq -0x20(%rbp), %rax
movq 0x8(%rax), %rax
movq -0x20(%rbp), %rsi
movl 0x4(%rsi), %ecx
movl %ecx, %edi
addl $0x1, %edi
movl %edi, 0x4(%rsi)
movslq %ecx, %rcx
movq %rdx, (%rax,%rcx,8)
movl $0x0, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x70, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)