// File: /workspace/github_c_makefile_star2_O3/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, %rbp
movq %rsi, %r13
movq 0x280(%rsi), %rbx
movq $0x0, (%rsp)
cmpl $0x4, %edx
jne 0x10199
leaq 0x5fda(%rip), %r14      # 0x15f5d
movl $0x18, %esi
movq %rbx, %rdi
movq %r14, %rdx
movl $0x47, %ecx
callq 0x44d0
movq %rax, %r12
movq %r13, (%rax)
movq 0x18(%rbp), %rdi
callq 0x41d0
leal 0x1(%rax), %esi
movq %rbx, %rdi
movq %r14, %rdx
movl $0x4a, %ecx
callq 0x44d0
movq %rax, 0x8(%r12)
movq 0x18(%rbp), %rsi
movq %rax, %rdi
callq 0x40f0
movq $0x0, 0x10(%r12)
movq %r12, %r15
addq $0x10, %r15
movq 0x10(%rbp), %rsi
leaq 0xc(%rsp), %rdx
movq %rsp, %rcx
movq %r13, %rdi
callq 0x4530
movq %rbp, %rcx
movl %eax, %ebp
testl %eax, %eax
jne 0x1023e
movq %rcx, 0x20(%rsp)
movq %r13, 0x10(%rsp)
movq %r12, 0x28(%rsp)
cmpl $0x0, 0xc(%rsp)
jle 0x10154
xorl %r14d, %r14d
xorl %r13d, %r13d
movq (%rsp), %rax
movq (%rax,%r14,8), %rsi
movq 0x10(%rsp), %rdi
leaq 0x8(%rsp), %rdx
leaq 0x18(%rsp), %rcx
callq 0x4530
testl %eax, %eax
jne 0x101f2
movl 0x8(%rsp), %r12d
cmpl $0x3, %r12d
jge 0x101f6
movq %r14, 0x30(%rsp)
movq 0x18(%rsp), %r14
testl %r12d, %r12d
je 0x101c2
movq (%r14), %rdi
cmpb $0x0, (%rdi)
je 0x101c2
callq 0x41d0
movq %rax, %rbp
cmpl $0x2, %r12d
jne 0x1009c
movq 0x8(%r14), %rdi
callq 0x41d0
shlq $0x20, %rax
movabsq $0x100000000, %rcx      # imm = 0x100000000
addq %rcx, %rax
sarq $0x20, %rax
jmp 0x100a8
xorl %eax, %eax
movabsq $0x100000000, %rcx      # imm = 0x100000000
shlq $0x20, %rbp
addq %rcx, %rbp
sarq $0x20, %rbp
leal (%rax,%rbp), %esi
addl $0x14, %esi
movq %rbx, %rdi
leaq 0x5e9a(%rip), %rdx      # 0x15f5d
movl $0x7c, %ecx
callq 0x44d0
movq %rax, %r12
testq %r13, %r13
cmoveq %r15, %r13
movq %rax, (%r13)
movq $0x0, (%rax)
movq %rax, %r13
addq $0x10, %r13
movq 0x18(%rsp), %r14
movq (%r14), %rsi
movq %r13, %rdi
callq 0x40f0
cmpl $0x2, 0x8(%rsp)
jne 0x1011b
addq %rbp, %r13
movq %r13, 0x8(%r12)
movq 0x8(%r14), %rsi
movq %r13, %rdi
callq 0x40f0
movq 0x18(%rsp), %r14
jmp 0x10124
movq $0x0, 0x8(%r12)
movq %rbx, %rdi
movq %r14, %rsi
leaq 0x5e2c(%rip), %rdx      # 0x15f5d
movl $0x8b, %ecx
callq 0x4280
movq 0x30(%rsp), %r14
incq %r14
movslq 0xc(%rsp), %rax
movq %r12, %r13
cmpq %rax, %r14
jl 0x1001c
movq 0x20(%rsp), %rax
movq 0x8(%rax), %rsi
leaq 0x167(%rip), %rdx       # 0x102cb
leaq 0x3d4(%rip), %r8        # 0x1053f
movq 0x10(%rsp), %rdi
movq 0x28(%rsp), %rcx
callq 0x4030
movq (%rsp), %rsi
leaq 0x5dd8(%rip), %rdx      # 0x15f5d
movq %rbx, %rdi
movl $0x90, %ecx
callq 0x4280
xorl %ebp, %ebp
jmp 0x102ba
movq (%rbp), %rdx
leaq 0x46bc(%rip), %rsi      # 0x14860
leaq 0x5da1(%rip), %rcx      # 0x15f4c
movq %r13, %rdi
xorl %r8d, %r8d
xorl %eax, %eax
callq 0x4510
movl $0x1, %ebp
jmp 0x102ba
leaq 0x5d94(%rip), %rdx      # 0x15f5d
movq %rbx, %rdi
movq %r14, %rsi
movl $0x6e, %ecx
callq 0x4280
movq 0x20(%rsp), %rax
movq 0x8(%rax), %rdx
leaq 0x4aed(%rip), %rsi      # 0x14cd6
leaq 0x5d9f(%rip), %rcx      # 0x15f8f
jmp 0x10225
movl %eax, %ebp
jmp 0x10239
movq 0x18(%rsp), %rsi
leaq 0x5d5b(%rip), %rdx      # 0x15f5d
movq %rbx, %rdi
movl $0x66, %ecx
callq 0x4280
movq (%rsp), %rax
movq (%rax,%r14,8), %rdx
leaq 0x5d49(%rip), %rsi      # 0x15f67
leaq 0x408a(%rip), %rcx      # 0x142af
movq 0x10(%rsp), %rdi
xorl %r8d, %r8d
xorl %eax, %eax
callq 0x4510
movl $0x1, %ebp
movq 0x28(%rsp), %r12
movq 0x8(%r12), %rsi
leaq 0x5d13(%rip), %rdx      # 0x15f5d
movq %rbx, %rdi
movl $0x94, %ecx
callq 0x4280
movq 0x10(%r12), %rsi
testq %rsi, %rsi
je 0x10286
leaq 0x5cf5(%rip), %r14      # 0x15f5d
movq (%rsi), %rax
movq %rax, (%r15)
movq %rbx, %rdi
movq %r14, %rdx
movl $0x98, %ecx
callq 0x4280
movq (%r15), %rsi
testq %rsi, %rsi
jne 0x10268
leaq 0x5cd0(%rip), %rdx      # 0x15f5d
movq %rbx, %rdi
movq %r12, %rsi
movl $0x9a, %ecx
callq 0x4280
movq (%rsp), %rsi
testq %rsi, %rsi
je 0x102ba
leaq 0x5cb0(%rip), %rdx      # 0x15f5d
movq %rbx, %rdi
movl $0x9c, %ecx
callq 0x4280
movl %ebp, %eax
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq