// File: /workspace/github_cpp_makefile_star2_O1/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 0x2ca1d
movq 0x1758e(%rip), %rax     # 0x43f60
cmpl $0x0, 0x1b6b4(%rax)
jle 0x2cb3f
callq 0xaf80
leaq 0x181a5(%rip), %r10     # 0x44b90
leaq 0xfe92(%rip), %rsi      # 0x3c884
leaq 0xfabd(%rip), %r8       # 0x3c4b6
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 0x2cb9b
xorl %r13d, %r13d
cmpb $0x5f, (%r14)
movq 0x17535(%rip), %r15     # 0x43f60
je 0x2ca34
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 0x2cad3
addl $0x14, %eax
movl %eax, (%r12)
cmpl $0x0, 0x1b6b4(%r15)
jle 0x2ca98
callq 0xaf80
movl (%r12), %r10d
leaq 0xfe44(%rip), %rsi      # 0x3c8b9
leaq 0xfa3a(%rip), %r8       # 0x3c4b6
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
movq 0x8(%r12), %rdi
movslq (%r12), %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 0x2cb44
cmpq $0x0, 0x8(%r12)
je 0x2cb44
movq %r14, %rdi
callq 0xb4e0
testq %rax, %rax
je 0x2cb44
movq %rax, %r14
cmpl $0x0, 0x1b6b4(%r15)
jle 0x2cb29
callq 0xaf80
subq $0x8, %rsp
leaq 0x18093(%rip), %r10     # 0x44b90
leaq 0xfdf6(%rip), %rsi      # 0x3c8fa
leaq 0xf9ab(%rip), %r8       # 0x3c4b6
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 0x2cb9b
leaq 0xfda1(%rip), %rdi      # 0x3c8ec
callq 0xa1f0
movq %rbx, %rdi
movq %rax, %rsi
xorl %eax, %eax
callq 0xa850
movl $0x0, 0xd670(%r15)
leaq 0xc6d0(%r15), %rdi
leaq 0xed47(%rip), %rsi      # 0x3b8bd
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