// File: /workspace/github_c_makefile_star2_O1/haxlang[P]hax/haxProc.c
// Function: Hax_ProcCmd
int
Hax_ProcCmd(
    ClientData dummy,			/* Not used. */
    Hax_Interp *interp,			/* Current interpreter. */
    int argc,				/* Number of arguments. */
    char **argv				/* Argument strings. */)
{
    Interp *iPtr = (Interp *) interp;
    Hax_Memoryp *memoryp = iPtr->memoryp;
    Proc *procPtr;
    int result, argCount, i;
    char **argArray = NULL;
    Arg *lastArgPtr;
    Arg *argPtr = NULL;	/* Initialization not needed, but
					 * prevents compiler warning. */

    if (argc != 4) {
	Hax_AppendResult(interp, "wrong # args: should be \"", argv[0],
		" name args body\"", (char *) NULL);
	return HAX_ERROR;
    }

    procPtr = (Proc *) ckalloc(memoryp, sizeof(Proc));
    procPtr->iPtr = iPtr;
    procPtr->command =
	(char *) ckalloc(memoryp, (unsigned) strlen(argv[3]) + 1);
    strcpy(procPtr->command, argv[3]);
    procPtr->argPtr = NULL;

    /*
     * Break up the argument list into argument specifiers, then process
     * each argument specifier.
     */

    result = Hax_SplitList(interp, argv[2], &argCount, &argArray);
    if (result != HAX_OK) {
	goto procError;
    }
    lastArgPtr = NULL;
    for (i = 0; i < argCount; i++) {
	int fieldCount, nameLength, valueLength;
	char **fieldValues;

	/*
	 * Now divide the specifier up into name and default.
	 */

	result = Hax_SplitList(interp, argArray[i], &fieldCount,
		&fieldValues);
	if (result != HAX_OK) {
	    goto procError;
	}
	if (fieldCount > 2) {
	    ckfree(memoryp, (char *) fieldValues);
	    Hax_AppendResult(interp,
		    "too many fields in argument specifier \"",
		    argArray[i], "\"", (char *) NULL);
	    result = HAX_ERROR;
	    goto procError;
	}
	if ((fieldCount == 0) || (*fieldValues[0] == 0)) {
	    ckfree(memoryp, (char *) fieldValues);
	    Hax_AppendResult(interp, "procedure \"", argv[1],
		    "\" has argument with no name", (char *) NULL);
	    result = HAX_ERROR;
	    goto procError;
	}
	nameLength = strlen(fieldValues[0]) + 1;
	if (fieldCount == 2) {
	    valueLength = strlen(fieldValues[1]) + 1;
	} else {
	    valueLength = 0;
	}
	argPtr = (Arg *) ckalloc(memoryp, (unsigned)
		(sizeof(Arg) - sizeof(argPtr->name) + nameLength
		+ valueLength));
	if (lastArgPtr == NULL) {
	    procPtr->argPtr = argPtr;
	} else {
	    lastArgPtr->nextPtr = argPtr;
	}
	lastArgPtr = argPtr;
	argPtr->nextPtr = NULL;
	strcpy(argPtr->name, fieldValues[0]);
	if (fieldCount == 2) {
	    argPtr->defValue = argPtr->name + nameLength;
	    strcpy(argPtr->defValue, fieldValues[1]);
	} else {
	    argPtr->defValue = NULL;
	}
	ckfree(memoryp, (char *) fieldValues);
    }

    Hax_CreateCommand(interp, argv[1], InterpProc, (ClientData) procPtr,
	    ProcDeleteProc);
    ckfree(memoryp, (char *) argArray);
    return HAX_OK;

    procError:
    ckfree(memoryp, procPtr->command);
    while (procPtr->argPtr != NULL) {
	argPtr = procPtr->argPtr;
	procPtr->argPtr = argPtr->nextPtr;
	ckfree(memoryp, (char *) argPtr);
    }
    ckfree(memoryp, (char *) procPtr);
    if (argArray != NULL) {
	ckfree(memoryp, (char *) argArray);
    }
    return result;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x38, %rsp
movq %rcx, %r13
movq %rsi, %r15
movq 0x280(%rsi), %rbx
movq $0x0, 0x10(%rsp)
cmpl $0x4, %edx
jne 0x10729
leaq 0x6c39(%rip), %r12      # 0x17259
movl $0x18, %esi
movq %rbx, %rdi
movq %r12, %rdx
movl $0x47, %ecx
callq 0x44c0
movq %rax, %r14
movq %r15, (%rax)
movq 0x18(%r13), %rdi
callq 0x41d0
leal 0x1(%rax), %esi
movq %rbx, %rdi
movq %r12, %rdx
movl $0x4a, %ecx
callq 0x44c0
movq %rax, 0x8(%r14)
movq 0x18(%r13), %rsi
movq %rax, %rdi
callq 0x40f0
movq $0x0, 0x10(%r14)
movq %r14, 0x28(%rsp)
addq $0x10, %r14
movq %r13, 0x30(%rsp)
movq 0x10(%r13), %rsi
leaq 0x1c(%rsp), %rdx
leaq 0x10(%rsp), %rcx
movq %r15, %rdi
callq 0x4520
movl %eax, %r13d
testl %eax, %eax
je 0x10753
movq 0x28(%rsp), %r15
movq 0x8(%r15), %rsi
leaq 0x6bab(%rip), %rdx      # 0x17259
movq %rbx, %rdi
movl $0x94, %ecx
callq 0x4280
movq 0x10(%r15), %rsi
testq %rsi, %rsi
je 0x106e9
leaq 0x6b8e(%rip), %r15      # 0x17259
movq (%rsi), %rax
movq %rax, (%r14)
movq %rbx, %rdi
movq %r15, %rdx
movl $0x98, %ecx
callq 0x4280
movq (%r14), %rsi
testq %rsi, %rsi
jne 0x106cb
leaq 0x6b69(%rip), %rdx      # 0x17259
movq %rbx, %rdi
movq 0x28(%rsp), %rsi
movl $0x9a, %ecx
callq 0x4280
movq 0x10(%rsp), %rsi
testq %rsi, %rsi
je 0x10982
leaq 0x6b42(%rip), %rdx      # 0x17259
movq %rbx, %rdi
movl $0x9c, %ecx
callq 0x4280
jmp 0x10982
movq (%r13), %rdx
leaq 0x5140(%rip), %rsi      # 0x15874
leaq 0x6b0d(%rip), %rcx      # 0x17248
movq %r15, %rdi
xorl %r8d, %r8d
xorl %eax, %eax
callq 0x4500
movl $0x1, %r13d
jmp 0x10982
cmpl $0x0, 0x1c(%rsp)
jle 0x10942
xorl %r12d, %r12d
movq $0x0, (%rsp)
movq 0x10(%rsp), %rax
movq (%rax,%r12,8), %rsi
movq %r15, %rdi
leaq 0x18(%rsp), %rdx
leaq 0x8(%rsp), %rcx
callq 0x4520
testl %eax, %eax
je 0x10792
movl %eax, %r13d
xorl %ebp, %ebp
jmp 0x10866
movl 0x18(%rsp), %ebp
cmpl $0x3, %ebp
jl 0x107d5
movq 0x8(%rsp), %rsi
movq %rbx, %rdi
leaq 0x6aaf(%rip), %rdx      # 0x17259
movl $0x66, %ecx
callq 0x4280
movq 0x10(%rsp), %rax
movq (%rax,%r12,8), %rdx
xorl %ebp, %ebp
movq %r15, %rdi
leaq 0x6a9a(%rip), %rsi      # 0x17263
leaq 0x4adf(%rip), %rcx      # 0x152af
jmp 0x10856
testl %ebp, %ebp
je 0x10821
movq 0x8(%rsp), %rax
movq (%rax), %rdi
cmpb $0x0, (%rdi)
je 0x10821
movq %rax, 0x20(%rsp)
callq 0x41d0
movq %rax, %r13
cmpl $0x2, %ebp
jne 0x10885
movq 0x20(%rsp), %rax
movq 0x8(%rax), %rdi
callq 0x41d0
shlq $0x20, %rax
movabsq $0x100000000, %rcx      # imm = 0x100000000
addq %rcx, %rax
sarq $0x20, %rax
jmp 0x10891
movq 0x8(%rsp), %rsi
movq %rbx, %rdi
leaq 0x6a29(%rip), %rdx      # 0x17259
movl $0x6e, %ecx
callq 0x4280
movq 0x30(%rsp), %rax
movq 0x8(%rax), %rdx
xorl %ebp, %ebp
movq %r15, %rdi
leaq 0x562b(%rip), %rsi      # 0x15e7a
leaq 0x6a35(%rip), %rcx      # 0x1728b
xorl %r8d, %r8d
xorl %eax, %eax
callq 0x4500
movl $0x1, %r13d
testb %bpl, %bpl
je 0x1069e
incq %r12
movslq 0x1c(%rsp), %rax
cmpq %rax, %r12
jl 0x10769
jmp 0x10942
xorl %eax, %eax
movabsq $0x100000000, %rcx      # imm = 0x100000000
movq (%rsp), %rbp
shlq $0x20, %r13
addq %rcx, %r13
sarq $0x20, %r13
leal (%rax,%r13), %esi
addl $0x14, %esi
movq %rbx, %rdi
leaq 0x69a8(%rip), %rdx      # 0x17259
movl $0x7c, %ecx
callq 0x44c0
testq %rbp, %rbp
cmoveq %r14, %rbp
movq %rax, (%rbp)
movq $0x0, (%rax)
movq %rax, (%rsp)
movq %rax, %rbp
addq $0x10, %rbp
movq 0x8(%rsp), %rax
movq %rax, 0x20(%rsp)
movq (%rax), %rsi
movq %rbp, %rdi
callq 0x40f0
cmpl $0x2, 0x18(%rsp)
jne 0x10912
addq %r13, %rbp
movq (%rsp), %rax
movq %rbp, 0x8(%rax)
movq 0x20(%rsp), %rax
movq 0x8(%rax), %rsi
movq %rbp, %rdi
callq 0x40f0
jmp 0x1091e
movq (%rsp), %rax
movq $0x0, 0x8(%rax)
movq 0x8(%rsp), %rsi
movq %rbx, %rdi
leaq 0x692c(%rip), %rdx      # 0x17259
movl $0x8b, %ecx
callq 0x4280
movb $0x1, %bpl
xorl %r13d, %r13d
jmp 0x10866
movq 0x30(%rsp), %rax
movq 0x8(%rax), %rsi
leaq 0x42(%rip), %rdx        # 0x10994
leaq 0x2a5(%rip), %r8        # 0x10bfe
movq %r15, %rdi
movq 0x28(%rsp), %rcx
callq 0x4030
movq 0x10(%rsp), %rsi
leaq 0x68e7(%rip), %rdx      # 0x17259
movq %rbx, %rdi
movl $0x90, %ecx
callq 0x4280
xorl %r13d, %r13d
movl %r13d, %eax
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq