// File: /workspace/github_c_makefile_star2_O2/haxlang[P]hax/haxCmdMZ.c
// Function: Hax_ScanCmd
int
Hax_ScanCmd(
    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;
    int arg1Length;			/* Number of bytes in argument to be
					 * scanned.  This gives an upper limit
					 * on string field sizes. */
#   define MAX_FIELDS 20
    typedef struct {
	char fmt;			/* Format for field. */
	int size;			/* How many bytes to allow for
					 * field. */
	char *location;			/* Where field will be stored. */
    } Field;
    Field fields[MAX_FIELDS];		/* Info about all the fields in the
					 * format string. */
    Field *curField;
    int numFields = 0;			/* Number of fields actually
					 * specified. */
    int suppress;			/* Current field is assignment-
					 * suppressed. */
    int totalSize = 0;			/* Number of bytes needed to store
					 * all results combined. */
    char *results;			/* Where scanned output goes.  */
    int numScanned;			/* sscanf's result. */
    char *fmt;
    int i, widthSpecified;

    if (argc < 3) {
	Hax_AppendResult(interp, "wrong # args: should be \"", argv[0],
		" string format ?varName varName ...?\"", (char *) NULL);
	return HAX_ERROR;
    }

    /*
     * This procedure operates in four stages:
     * 1. Scan the format string, collecting information about each field.
     * 2. Allocate an array to hold all of the scanned fields.
     * 3. Call sscanf to do all the dirty work, and have it store the
     *    parsed fields in the array.
     * 4. Pick off the fields from the array and assign them to variables.
     */

    arg1Length = (strlen(argv[1]) + 4) & ~03;
    for (fmt = argv[2]; *fmt != 0; fmt++) {
	if (*fmt != '%') {
	    continue;
	}
	fmt++;
	if (*fmt == '*') {
	    suppress = 1;
	    fmt++;
	} else {
	    suppress = 0;
	}
	widthSpecified = 0;
	while (isdigit(*fmt)) {
	    widthSpecified = 1;
	    fmt++;
	}
	if (suppress) {
	    continue;
	}
	if (numFields == MAX_FIELDS) {
	    interp->result = (char *) "too many fields to scan";
	    return HAX_ERROR;
	}
	curField = &fields[numFields];
	numFields++;
	switch (*fmt) {
	    case 'D':
	    case 'O':
	    case 'X':
	    case 'd':
	    case 'o':
	    case 'x':
		curField->fmt = 'd';
		curField->size = sizeof(int);
		break;

	    case 's':
		curField->fmt = 's';
		curField->size = arg1Length;
		break;

	    case 'c':
                if (widthSpecified) {
                    interp->result =
                         (char *) "field width may not be specified in %c "
			    "conversion";
                    return HAX_ERROR;
                }
		curField->fmt = 'c';
		curField->size = sizeof(int);
		break;

	    case 'E':
	    case 'F':
		curField->fmt = 'F';
		curField->size = sizeof(double);
		break;

	    case 'e':
	    case 'f':
		curField->fmt = 'f';
		curField->size = sizeof(float);
		break;

	    case '[':
		curField->fmt = 's';
		curField->size = arg1Length;
		do {
		    fmt++;
		} while (*fmt != ']');
		break;

	    default:
		sprintf(interp->result, "bad scan conversion character \"%c\"",
			*fmt);
		return HAX_ERROR;
	}
	totalSize += curField->size;
    }

    if (numFields != (argc-3)) {
	interp->result =
		(char *) "different numbers of variable names and field "
		    "specifiers";
	return HAX_ERROR;
    }

    /*
     * Step 2:
     */

    results = (char *) ckalloc(memoryp, (unsigned) totalSize);
    for (i = 0, totalSize = 0, curField = fields;
	    i < numFields; i++, curField++) {
	curField->location = results + totalSize;
	totalSize += curField->size;
    }

    /*
     * Fill in the remaining fields with NULL;  the only purpose of
     * this is to keep some memory analyzers, like Purify, from
     * complaining.
     */

    for ( ; i < MAX_FIELDS; i++, curField++) {
	curField->location = NULL;
    }

    /*
     * Step 3:
     */

    numScanned = sscanf(argv[1], argv[2],
	    fields[0].location, fields[1].location, fields[2].location,
	    fields[3].location, fields[4].location, fields[5].location,
	    fields[6].location, fields[7].location, fields[8].location,
	    fields[9].location, fields[10].location, fields[11].location,
	    fields[12].location, fields[13].location, fields[14].location,
	    fields[15].location, fields[16].location, fields[17].location,
	    fields[18].location, fields[19].location);

    /*
     * Step 4:
     */

    if (numScanned < numFields) {
	numFields = numScanned;
    }
    for (i = 0, curField = fields; i < numFields; i++, curField++) {
	switch (curField->fmt) {
	    char string[120];

	    case 'd':
		sprintf(string, "%d", *((int *) curField->location));
		if (Hax_SetVar(interp, argv[i+3], string, 0) == NULL) {
		    storeError:
		    Hax_AppendResult(interp,
			    "couldn't set variable \"", argv[i+3], "\"",
			    (char *) NULL);
		    ckfree(memoryp, (char *) results);
		    return HAX_ERROR;
		}
		break;

	    case 'c':
		sprintf(string, "%d", *((char *) curField->location) & 0xff);
		if (Hax_SetVar(interp, argv[i+3], string, 0) == NULL) {
		    goto storeError;
		}
		break;

	    case 's':
		if (Hax_SetVar(interp, argv[i+3], curField->location, 0)
			== NULL) {
		    goto storeError;
		}
		break;

	    case 'F':
		sprintf(string, "%g", *((double *) curField->location));
		if (Hax_SetVar(interp, argv[i+3], string, 0) == NULL) {
		    goto storeError;
		}
		break;

	    case 'f':
		sprintf(string, "%g", *((float *) curField->location));
		if (Hax_SetVar(interp, argv[i+3], string, 0) == NULL) {
		    goto storeError;
		}
		break;
	}
    }
    ckfree(memoryp, results);
    sprintf(interp->result, "%d", numScanned);
    return HAX_OK;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x1d8, %rsp            # imm = 0x1D8
movq %rcx, %rbx
movq %rsi, %rdi
cmpl $0x2, %edx
jg 0x9d26
movq (%rbx), %rdx
leaq 0x9b50(%rip), %rsi      # 0x13860
leaq 0xa4e4(%rip), %rcx      # 0x141fb
xorl %r8d, %r8d
xorl %eax, %eax
callq 0x4520
jmp 0xa056
movl %edx, 0xc(%rsp)
movq %rdi, 0x10(%rsp)
movq 0x280(%rdi), %rax
movq %rax, 0x18(%rsp)
movq 0x8(%rbx), %rdi
callq 0x41d0
movq %rax, %r12
andl $-0x4, %r12d
addl $0x4, %r12d
movq %rbx, (%rsp)
movq 0x10(%rbx), %r15
xorl %r13d, %r13d
pushq $0x4
popq %rbx
xorl %r14d, %r14d
movzbl (%r15), %eax
cmpl $0x25, %eax
je 0x9d76
testl %eax, %eax
jne 0x9e48
jmp 0x9e67
leaq 0x1(%r15), %rax
movb 0x1(%r15), %bpl
addq $0x2, %r15
cmpb $0x2a, %bpl
cmovneq %rax, %r15
callq 0x4660
movq (%rax), %rax
decq %r15
movb $0x1, %cl
movl %ecx, %esi
movsbq 0x1(%r15), %rdx
incq %r15
xorl %ecx, %ecx
testb $0x8, 0x1(%rax,%rdx,2)
jne 0x9d97
cmpb $0x2a, %bpl
je 0x9e48
cmpl $0x14, %r13d
je 0xa047
movslq %r13d, %rax
shlq $0x4, %rax
addq %rsp, %rax
addq $0x20, %rax
movzbl %dl, %r8d
movb $0x64, %cl
leal -0x58(%r8), %edi
cmpl $0xe, %edi
jbe 0x9e0f
leal -0x45(%r8), %esi
cmpl $0x2, %esi
jb 0x9e28
cmpl $0x44, %r8d
je 0x9e24
cmpl $0x4f, %r8d
je 0x9e24
cmpl $0x6f, %r8d
je 0x9e24
movl %ebx, %edi
cmpl $0x78, %r8d
je 0x9e3d
cmpl $0x73, %r8d
jne 0xa0e1
movb $0x73, %cl
movl %r12d, %edi
jmp 0x9e3d
leaq 0xa1ce(%rip), %r9       # 0x13fe4
movslq (%r9,%rdi,4), %r8
addq %r9, %r8
movl %ebx, %edi
jmpq *%r8
movb $0x66, %cl
movl %ebx, %edi
jmp 0x9e3d
movb $0x46, %cl
pushq $0x8
popq %rdi
jmp 0x9e3d
movb $0x63, %cl
movl %ebx, %edi
testb $0x1, %sil
je 0xa0fc
movb %cl, (%rax)
movl %edi, 0x4(%rax)
incl %r13d
addl %edi, %r14d
incq %r15
jmp 0x9d60
movb $0x73, (%rax)
movl %r12d, 0x4(%rax)
cmpb $0x5d, 0x1(%r15)
leaq 0x1(%r15), %r15
jne 0x9e57
movl %r12d, %edi
jmp 0x9e42
movl 0xc(%rsp), %eax
addl $-0x3, %eax
cmpl %eax, %r13d
jne 0xa03e
movl %r14d, %esi
leaq 0xa241(%rip), %rdx      # 0x140c2
movq 0x18(%rsp), %rdi
movl $0x2a5, %ecx            # imm = 0x2A5
callq 0x44e0
movq %rax, %r12
xorl %edx, %edx
testl %r13d, %r13d
movl $0x0, %eax
cmovgl %r13d, %eax
leaq 0x28(%rsp), %rcx
movl %eax, %esi
movq 0x10(%rsp), %r15
movq (%rsp), %r8
subl $0x1, %esi
jb 0x9ed3
movslq %edx, %rdx
leaq (%r12,%rdx), %rdi
movq %rdi, (%rcx)
addl -0x4(%rcx), %edx
addq $0x10, %rcx
jmp 0x9eb1
andq $0x0, (%rcx)
incl %eax
addq $0x10, %rcx
cmpl $0x13, %eax
jbe 0x9ec9
movq 0x8(%r8), %rdi
movq 0x10(%r8), %rsi
movq 0x28(%rsp), %rdx
movq 0x38(%rsp), %rcx
movq 0x48(%rsp), %r8
movq 0x58(%rsp), %r9
xorl %ebx, %ebx
xorl %eax, %eax
pushq 0x158(%rsp)
pushq 0x150(%rsp)
pushq 0x148(%rsp)
pushq 0x140(%rsp)
pushq 0x138(%rsp)
pushq 0x130(%rsp)
pushq 0x128(%rsp)
pushq 0x120(%rsp)
pushq 0x118(%rsp)
pushq 0x110(%rsp)
pushq 0x108(%rsp)
pushq 0x100(%rsp)
pushq 0xf8(%rsp)
pushq 0xf0(%rsp)
pushq 0xe8(%rsp)
pushq 0xe0(%rsp)
callq 0x4450
addq $0x80, %rsp
cmpl %r13d, %eax
movl %eax, 0xc(%rsp)
cmovll %eax, %r13d
testl %r13d, %r13d
cmovlel %ebx, %r13d
shlq $0x3, %r13
leaq 0x160(%rsp), %r14
leaq 0x937a(%rip), %rbp      # 0x13313
xorl %ebx, %ebx
cmpq %rbx, %r13
je 0xa06d
movzbl 0x20(%rsp,%rbx,2), %eax
cmpl $0x46, %eax
je 0xa000
cmpl $0x63, %eax
je 0x9fcb
cmpl $0x73, %eax
je 0x9fed
cmpl $0x66, %eax
je 0x9fe2
cmpl $0x64, %eax
jne 0xa035
movq 0x28(%rsp,%rbx,2), %rax
movl (%rax), %edx
jmp 0x9fd3
movq 0x28(%rsp,%rbx,2), %rax
movzbl (%rax), %edx
movq %r14, %rdi
movq %rbp, %rsi
xorl %eax, %eax
callq 0x45f0
jmp 0xa01a
movq 0x28(%rsp,%rbx,2), %rax
cvtss2sd (%rax), %xmm0
jmp 0xa009
movq (%rsp), %rax
movq 0x18(%rax,%rbx), %rsi
movq 0x28(%rsp,%rbx,2), %rdx
movq %r15, %rdi
jmp 0xa029
movq 0x28(%rsp,%rbx,2), %rax
movsd (%rax), %xmm0
movq %r14, %rdi
leaq 0xa2b4(%rip), %rsi      # 0x142c7
movb $0x1, %al
callq 0x45f0
movq (%rsp), %rax
movq 0x18(%rax,%rbx), %rsi
movq %r15, %rdi
movq %r14, %rdx
xorl %ecx, %ecx
callq 0x4470
testq %rax, %rax
je 0xa09f
addq $0x8, %rbx
jmp 0x9f9b
leaq 0xa249(%rip), %rax      # 0x1428e
jmp 0xa04e
leaq 0xa1d3(%rip), %rax      # 0x14221
movq 0x10(%rsp), %rcx
movq %rax, (%rcx)
pushq $0x1
popq %rbx
movl %ebx, %eax
addq $0x1d8, %rsp            # imm = 0x1D8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0xa04e(%rip), %rdx      # 0x140c2
movq 0x18(%rsp), %rdi
movq %r12, %rsi
movl $0x2f7, %ecx            # imm = 0x2F7
callq 0x4280
movq (%r15), %rdi
leaq 0x9283(%rip), %rsi      # 0x13313
xorl %ebx, %ebx
movl 0xc(%rsp), %edx
xorl %eax, %eax
callq 0x45f0
jmp 0xa059
movq (%rsp), %rax
movq 0x18(%rax,%rbx), %rdx
leaq 0xa068(%rip), %rsi      # 0x14117
leaq 0x91f9(%rip), %rcx      # 0x132af
movq %r15, %rdi
xorl %r8d, %r8d
xorl %eax, %eax
callq 0x4520
leaq 0x9ff8(%rip), %rdx      # 0x140c2
movq 0x18(%rsp), %rdi
movq %r12, %rsi
movl $0x2d5, %ecx            # imm = 0x2D5
callq 0x4280
jmp 0xa056
movq 0x10(%rsp), %rax
movq (%rax), %rdi
leaq 0xa17b(%rip), %rsi      # 0x1426b
xorl %eax, %eax
callq 0x45f0
jmp 0xa056
leaq 0xa136(%rip), %rax      # 0x14239
jmp 0xa04e