// File: /workspace/github_cpp_makefile_star2_O3/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 0xa520
cmpl $0x0, (%r15)
je 0x29401
movq 0x17baa(%rip), %rax     # 0x40f60
cmpl $0x0, 0x1b6b4(%rax)
jle 0x2952a
callq 0xaf80
leaq 0x187c1(%rip), %r10     # 0x41b90
leaq 0x104a3(%rip), %rsi     # 0x39879
leaq 0x100d1(%rip), %r8      # 0x394ae
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 0xb470
addq $0x10, %rsp
jmp 0x2957b
xorl %r13d, %r13d
cmpb $0x5f, (%r14)
movq 0x17b51(%rip), %r15     # 0x40f60
je 0x29418
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 0x294be
addl $0x14, %eax
movl %eax, (%r12)
cmpl $0x0, 0x1b6b4(%r15)
jle 0x29484
callq 0xaf80
movl (%r12), %r10d
leaq 0x10451(%rip), %rsi     # 0x398ae
leaq 0x1004a(%rip), %r8      # 0x394ae
movq %rbx, %rdi
xorl %edx, %edx
movl %eax, %ecx
movl $0x773, %r9d            # imm = 0x773
xorl %eax, %eax
pushq %r10
pushq %r13
callq 0xb470
addq $0x10, %rsp
movl (%r12), %eax
movq 0x8(%r12), %rdi
movslq %eax, %rsi
shlq $0x3, %rsi
callq 0xb1c0
movq %rax, 0x8(%r12)
movq 0x10(%r12), %rdi
movslq (%r12), %rsi
shlq $0x3, %rsi
callq 0xb1c0
movq %rax, 0x10(%r12)
testq %rax, %rax
je 0x2952f
cmpq $0x0, 0x8(%r12)
je 0x2952f
movq %r14, %rdi
callq 0xb4e0
testq %rax, %rax
je 0x2952f
movq %rax, %r14
cmpl $0x0, 0x1b6b4(%r15)
jle 0x29514
callq 0xaf80
subq $0x8, %rsp
leaq 0x186a8(%rip), %r10     # 0x41b90
leaq 0x10400(%rip), %rsi     # 0x398ef
leaq 0xffb8(%rip), %r8       # 0x394ae
movq %rbx, %rdi
xorl %edx, %edx
movl %eax, %ecx
movl $0x789, %r9d            # imm = 0x789
xorl %eax, %eax
pushq %r14
pushq %r14
pushq %r10
callq 0xb470
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 0x2957b
leaq 0x103ab(%rip), %rdi     # 0x398e1
callq 0xa1f0
movq %rbx, %rdi
movq %rax, %rsi
xorl %eax, %eax
callq 0xa850
leaq 0xc6d0(%r15), %rdi
leaq 0xf367(%rip), %rsi      # 0x388bd
movl $0x50, %edx
callq 0xa8a0
movw $0x0, 0xc71f(%r15)
movl $0x1, 0xd670(%r15)
movl $0x5, %r15d
movl %r15d, %eax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nop