// File: /workspace/github_cpp_makefile_star2_O2/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
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movq %rsi, %r14
movq %rdi, %rbx
leaq -0x2c(%rbp), %r15
leaq -0x38(%rbp), %rcx
movq %r15, %rdx
callq 0xb570
cmpl $0x0, (%r15)
je 0x26a15
movq 0x16594(%rip), %rax     # 0x3cf60
cmpl $0x0, 0x1b6b4(%rax)
jle 0x26b3c
callq 0xc0b0
leaq 0x1726b(%rip), %r10     # 0x3dc50
leaq 0xee8d(%rip), %rsi      # 0x35879
leaq 0xeabb(%rip), %r8       # 0x354ae
xorl %r15d, %r15d
movq %rbx, %rdi
xorl %edx, %edx
movl %eax, %ecx
movl $0x75b, %r9d            # imm = 0x75B
xorl %eax, %eax
pushq %r14
pushq %r10
callq 0xc5e0
popq %rax
popq %rcx
jmp 0x26b88
xorl %r13d, %r13d
cmpb $0x5f, (%r14)
movq 0x1653d(%rip), %r15     # 0x3cf60
je 0x26a2c
movl 0xef90(%r15), %r13d
movslq %r13d, %rax
imulq $0x128, %rax, %rax      # imm = 0x128
leaq (%r15,%rax), %r12
addq $0xf0a8, %r12           # imm = 0xF0A8
movl (%r12), %eax
cmpl %eax, 0x4(%r12)
jl 0x26ad0
addl $0x14, %eax
movl %eax, (%r12)
cmpl $0x0, 0x1b6b4(%r15)
jle 0x26a96
callq 0xc0b0
movl (%r12), %r10d
leaq 0xee3d(%rip), %rsi      # 0x358ae
leaq 0xea36(%rip), %r8       # 0x354ae
movq %rbx, %rdi
xorl %edx, %edx
movl %eax, %ecx
movl $0x773, %r9d            # imm = 0x773
xorl %eax, %eax
pushq %r10
pushq %r13
callq 0xc5e0
popq %rax
popq %rcx
movl (%r12), %eax
movq 0x8(%r12), %rdi
movslq %eax, %rsi
shlq $0x3, %rsi
callq 0xc320
movq %rax, 0x8(%r12)
movq 0x10(%r12), %rdi
movslq (%r12), %rsi
shlq $0x3, %rsi
callq 0xc320
movq %rax, 0x10(%r12)
testq %rax, %rax
je 0x26b41
cmpq $0x0, 0x8(%r12)
je 0x26b41
movq %r14, %rdi
callq 0xc650
testq %rax, %rax
je 0x26b41
movq %rax, %r14
cmpl $0x0, 0x1b6b4(%r15)
jle 0x26b26
callq 0xc0b0
subq $0x8, %rsp
leaq 0x17156(%rip), %r10     # 0x3dc50
leaq 0xedee(%rip), %rsi      # 0x358ef
leaq 0xe9a6(%rip), %r8       # 0x354ae
movq %rbx, %rdi
xorl %edx, %edx
movl %eax, %ecx
movl $0x789, %r9d            # imm = 0x789
xorl %eax, %eax
pushq %r14
pushq %r14
pushq %r10
callq 0xc5e0
addq $0x20, %rsp
movq 0x8(%r12), %rax
movslq 0x4(%r12), %rcx
leal 0x1(%rcx), %edx
movl %edx, 0x4(%r12)
movq %r14, (%rax,%rcx,8)
xorl %r15d, %r15d
jmp 0x26b88
leaq 0xed99(%rip), %rdi      # 0x358e1
callq 0xb220
movq %rbx, %rdi
movq %rax, %rsi
xorl %eax, %eax
callq 0xb8e0
leaq 0xc6d0(%r15), %rdi
leaq 0xdd55(%rip), %rsi      # 0x348bd
pushq $0x50
popq %rdx
callq 0xb940
andw $0x0, 0xc71f(%r15)
movl $0x1, 0xd670(%r15)
pushq $0x5
popq %r15
movl %r15d, %eax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq