// File: /workspace/github_c_makefile_star2_O3/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 0xa50b
movq (%rbx), %rdx
leaq 0xa36b(%rip), %rsi      # 0x14860
leaq 0xad2b(%rip), %rcx      # 0x15227
xorl %r8d, %r8d
xorl %eax, %eax
callq 0x4510
jmp 0xa6d5
movl %edx, %ebp
movq %rdi, 0x8(%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, 0x10(%rsp)
movq 0x10(%rbx), %r15
xorl %r14d, %r14d
xorl %r13d, %r13d
movzbl (%r15), %eax
cmpl $0x25, %eax
je 0xa557
testl %eax, %eax
jne 0xa642
jmp 0xa661
leaq 0x1(%r15), %rax
movb 0x1(%r15), %bl
addq $0x2, %r15
cmpb $0x2a, %bl
cmovneq %rax, %r15
callq 0x4650
movq (%rax), %rax
decq %r15
movb $0x1, %cl
movl %ecx, %edi
movsbq 0x1(%r15), %rdx
incq %r15
xorl %ecx, %ecx
testb $0x8, 0x1(%rax,%rdx,2)
jne 0xa577
cmpb $0x2a, %bl
je 0xa642
cmpl $0x14, %r14d
je 0xa6c6
movslq %r14d, %rax
shlq $0x4, %rax
addq %rsp, %rax
addq $0x20, %rax
movzbl %dl, %r8d
movl $0x4, %ecx
movb $0x64, %sil
cmpl $0x57, %r8d
jle 0xa5e7
cmpl $0x6e, %r8d
jg 0xa601
addl $-0x58, %r8d
cmpl $0xe, %r8d
ja 0xa996
leaq 0xaa38(%rip), %r9       # 0x15010
movslq (%r9,%r8,4), %r8
addq %r9, %r8
jmpq *%r8
movb $0x66, %sil
jmp 0xa636
leal -0x45(%r8), %edi
cmpl $0x2, %edi
jb 0xa61f
cmpl $0x44, %r8d
je 0xa636
cmpl $0x4f, %r8d
je 0xa636
jmp 0xa996
cmpl $0x6f, %r8d
je 0xa636
cmpl $0x78, %r8d
je 0xa636
cmpl $0x73, %r8d
jne 0xa996
movb $0x73, %sil
movl %r12d, %ecx
jmp 0xa636
movl $0x8, %ecx
movb $0x46, %sil
jmp 0xa636
movb $0x63, %sil
testb $0x1, %dil
je 0xa98a
movb %sil, (%rax)
movl %ecx, 0x4(%rax)
incl %r14d
addl %ecx, %r13d
incq %r15
jmp 0xa541
movb $0x73, (%rax)
movl %r12d, 0x4(%rax)
cmpb $0x5d, 0x1(%r15)
leaq 0x1(%r15), %r15
jne 0xa651
movl %r12d, %ecx
jmp 0xa63c
addl $-0x3, %ebp
cmpl %ebp, %r14d
jne 0xa6bd
movl %r13d, %esi
leaq 0xaa7b(%rip), %rdx      # 0x150ee
movq 0x18(%rsp), %rdi
movl $0x2a5, %ecx            # imm = 0x2A5
callq 0x44d0
movq %rax, %r12
testl %r14d, %r14d
jle 0xa6ee
xorl %ecx, %ecx
leaq 0x20(%rsp), %rax
movl %r14d, %edx
movq 0x10(%rsp), %r8
movslq %ecx, %rcx
leaq (%r12,%rcx), %rsi
movq %rsi, 0x8(%rax)
addl 0x4(%rax), %ecx
addq $0x10, %rax
decl %edx
jne 0xa699
movl %r14d, %ecx
cmpl $0x13, %r14d
jbe 0xa6fa
jmp 0xa798
leaq 0xabf6(%rip), %rax      # 0x152ba
jmp 0xa6cd
leaq 0xab80(%rip), %rax      # 0x1524d
movq 0x8(%rsp), %rcx
movq %rax, (%rcx)
movl $0x1, %ebp
movl %ebp, %eax
addq $0x1d8, %rsp            # imm = 0x1D8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x20(%rsp), %rax
xorl %ecx, %ecx
movq 0x10(%rsp), %r8
movl $0x13, %edx
subl %ecx, %edx
leaq 0x2(%rdx), %rcx
andq $-0x2, %rcx
movq %rdx, %xmm0
pshufd $0x44, %xmm0, %xmm0     # xmm0 = xmm0[0,1,0,1]
addq $0x18, %rax
xorl %edx, %edx
movdqa 0xa8cf(%rip), %xmm1     # 0x14ff0
movdqa 0xa8d7(%rip), %xmm2     # 0x15000
pxor %xmm2, %xmm0
pcmpeqd %xmm3, %xmm3
movq %rdx, %xmm4
pshufd $0x44, %xmm4, %xmm4     # xmm4 = xmm4[0,1,0,1]
por %xmm1, %xmm4
pxor %xmm2, %xmm4
movdqa %xmm4, %xmm5
pcmpgtd %xmm0, %xmm5
pcmpeqd %xmm0, %xmm4
pshufd $0xf5, %xmm4, %xmm6     # xmm6 = xmm4[1,1,3,3]
pand %xmm5, %xmm6
pshufd $0xf5, %xmm5, %xmm4     # xmm4 = xmm5[1,1,3,3]
por %xmm6, %xmm4
movd %xmm4, %esi
notl %esi
testb $0x1, %sil
je 0xa775
movq $0x0, -0x10(%rax)
pxor %xmm3, %xmm4
pextrw $0x4, %xmm4, %esi
testb $0x1, %sil
je 0xa78b
movq $0x0, (%rax)
addq $0x2, %rdx
addq $0x20, %rax
cmpq %rdx, %rcx
jne 0xa731
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 %ebp, %ebp
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 0x4440
addq $0x80, %rsp
movl %eax, %r13d
cmpl %r14d, %eax
cmovll %eax, %r14d
testl %r14d, %r14d
jle 0xa90e
movl %r14d, %ebx
shlq $0x3, %rbx
leaq 0x160(%rsp), %r14
xorl %r15d, %r15d
movzbl 0x20(%rsp,%r15,2), %eax
cmpl $0x63, %eax
jle 0xa880
cmpl $0x73, %eax
je 0xa8a5
cmpl $0x66, %eax
je 0xa8bb
cmpl $0x64, %eax
jne 0xa901
movq 0x28(%rsp,%r15,2), %rax
movl (%rax), %edx
jmp 0xa892
cmpl $0x46, %eax
je 0xa8c9
cmpl $0x63, %eax
jne 0xa901
movq 0x28(%rsp,%r15,2), %rax
movzbl (%rax), %edx
movq %r14, %rdi
leaq 0x9a77(%rip), %rsi      # 0x14313
xorl %eax, %eax
callq 0x45e0
jmp 0xa8e3
movq 0x10(%rsp), %rax
movq 0x18(%rax,%r15), %rsi
movq 0x28(%rsp,%r15,2), %rdx
movq 0x8(%rsp), %rdi
jmp 0xa8f5
movq 0x28(%rsp,%r15,2), %rax
xorps %xmm0, %xmm0
cvtss2sd (%rax), %xmm0
jmp 0xa8d2
movq 0x28(%rsp,%r15,2), %rax
movsd (%rax), %xmm0
movq %r14, %rdi
leaq 0xaa17(%rip), %rsi      # 0x152f3
movb $0x1, %al
callq 0x45e0
movq 0x10(%rsp), %rax
movq 0x18(%rax,%r15), %rsi
movq 0x8(%rsp), %rdi
movq %r14, %rdx
xorl %ecx, %ecx
callq 0x4460
testq %rax, %rax
je 0xa945
addq $0x8, %r15
cmpq %r15, %rbx
jne 0xa859
leaq 0xa7d9(%rip), %rdx      # 0x150ee
movq 0x18(%rsp), %rdi
movq %r12, %rsi
movl $0x2f7, %ecx            # imm = 0x2F7
callq 0x4280
movq 0x8(%rsp), %rax
movq (%rax), %rdi
leaq 0x99dd(%rip), %rsi      # 0x14313
movl %r13d, %edx
xorl %eax, %eax
callq 0x45e0
jmp 0xa6da
movq 0x10(%rsp), %rax
movq 0x18(%rax,%r15), %rdx
leaq 0xa7ed(%rip), %rsi      # 0x15143
leaq 0x9952(%rip), %rcx      # 0x142af
movq 0x8(%rsp), %rdi
xorl %r8d, %r8d
xorl %eax, %eax
callq 0x4510
leaq 0xa77b(%rip), %rdx      # 0x150ee
movq 0x18(%rsp), %rdi
movq %r12, %rsi
movl $0x2d5, %ecx            # imm = 0x2D5
callq 0x4280
jmp 0xa6d5
leaq 0xa8d4(%rip), %rax      # 0x15265
jmp 0xa6cd
movq 0x8(%rsp), %rax
movq (%rax), %rdi
leaq 0xa8f2(%rip), %rsi      # 0x15297
xorl %eax, %eax
callq 0x45e0
jmp 0xa6d5