// File: /workspace/github_c_makefile_star2_O1/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 0xa965
movq (%rbx), %rdx
leaq 0xaf25(%rip), %rsi      # 0x15874
leaq 0xbac5(%rip), %rcx      # 0x1641b
xorl %r8d, %r8d
xorl %eax, %eax
callq 0x4500
jmp 0xab29
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 0xa9b1
testl %eax, %eax
jne 0xaa9d
jmp 0xaabe
leaq 0x1(%r15), %rax
movb 0x1(%r15), %bl
addq $0x2, %r15
cmpb $0x2a, %bl
cmovneq %rax, %r15
callq 0x4640
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 0xa9d1
cmpb $0x2a, %bl
je 0xaa9d
cmpl $0x14, %r14d
je 0xab1a
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 0xaa41
cmpl $0x6e, %r8d
jg 0xaa5b
addl $-0x58, %r8d
cmpl $0xe, %r8d
ja 0xad67
leaq 0xb756(%rip), %r9       # 0x16188
movslq (%r9,%r8,4), %r8
addq %r9, %r8
jmpq *%r8
movb $0x66, %sil
jmp 0xaa90
leal -0x45(%r8), %edi
cmpl $0x2, %edi
jb 0xaa79
cmpl $0x44, %r8d
je 0xaa90
cmpl $0x4f, %r8d
je 0xaa90
jmp 0xad67
cmpl $0x6f, %r8d
je 0xaa90
cmpl $0x78, %r8d
je 0xaa90
cmpl $0x73, %r8d
jne 0xad67
movb $0x73, %sil
movl %r12d, %ecx
jmp 0xaa90
movl $0x8, %ecx
movb $0x46, %sil
jmp 0xaa90
movb $0x63, %sil
testb $0x1, %dil
je 0xad5b
movb %sil, (%rax)
movl %ecx, 0x4(%rax)
incl %r14d
addl 0x4(%rax), %r13d
incq %r15
jmp 0xa99b
movb $0x73, (%rax)
movl %r12d, 0x4(%rax)
movq %r15, %rcx
leaq 0x1(%rcx), %r15
cmpb $0x5d, 0x1(%rcx)
movq %r15, %rcx
jne 0xaaaf
jmp 0xaa96
addl $-0x3, %ebp
cmpl %ebp, %r14d
jne 0xab11
movl %r13d, %esi
leaq 0xb812(%rip), %rdx      # 0x162e2
movq 0x18(%rsp), %rdi
movl $0x2a5, %ecx            # imm = 0x2A5
callq 0x44c0
movq %rax, %r12
testl %r14d, %r14d
jle 0xab42
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 0xaaf6
movl %r14d, %ecx
jmp 0xab4e
leaq 0xb996(%rip), %rax      # 0x164ae
jmp 0xab21
leaq 0xb920(%rip), %rax      # 0x16441
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
xorl %ecx, %ecx
leaq 0x20(%rsp), %rax
movq 0x10(%rsp), %r8
cmpl $0x13, %ecx
ja 0xab69
addl $-0x14, %ecx
addq $0x8, %rax
movq $0x0, (%rax)
addq $0x10, %rax
incl %ecx
jne 0xab5a
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 0x4430
addq $0x80, %rsp
movl %eax, %r13d
cmpl %r14d, %eax
cmovll %eax, %r14d
testl %r14d, %r14d
jle 0xacdf
movl %r14d, %ebx
shlq $0x3, %rbx
leaq 0x160(%rsp), %r14
xorl %r15d, %r15d
movzbl 0x20(%rsp,%r15,2), %eax
cmpl $0x63, %eax
jle 0xac51
cmpl $0x73, %eax
je 0xac76
cmpl $0x66, %eax
je 0xac8c
cmpl $0x64, %eax
jne 0xacd2
movq 0x28(%rsp,%r15,2), %rax
movl (%rax), %edx
jmp 0xac63
cmpl $0x46, %eax
je 0xac9a
cmpl $0x63, %eax
jne 0xacd2
movq 0x28(%rsp,%r15,2), %rax
movzbl (%rax), %edx
movq %r14, %rdi
leaq 0xa6a6(%rip), %rsi      # 0x15313
xorl %eax, %eax
callq 0x45d0
jmp 0xacb4
movq 0x10(%rsp), %rax
movq 0x18(%rax,%r15), %rsi
movq 0x28(%rsp,%r15,2), %rdx
movq 0x8(%rsp), %rdi
jmp 0xacc6
movq 0x28(%rsp,%r15,2), %rax
xorps %xmm0, %xmm0
cvtss2sd (%rax), %xmm0
jmp 0xaca3
movq 0x28(%rsp,%r15,2), %rax
movsd (%rax), %xmm0
movq %r14, %rdi
leaq 0xb83a(%rip), %rsi      # 0x164e7
movb $0x1, %al
callq 0x45d0
movq 0x10(%rsp), %rax
movq 0x18(%rax,%r15), %rsi
movq 0x8(%rsp), %rdi
movq %r14, %rdx
xorl %ecx, %ecx
callq 0x4450
testq %rax, %rax
je 0xad16
addq $0x8, %r15
cmpq %r15, %rbx
jne 0xac2a
leaq 0xb5fc(%rip), %rdx      # 0x162e2
movq 0x18(%rsp), %rdi
movq %r12, %rsi
movl $0x2f7, %ecx            # imm = 0x2F7
callq 0x4280
movq 0x8(%rsp), %rax
movq (%rax), %rdi
leaq 0xa60c(%rip), %rsi      # 0x15313
movl %r13d, %edx
xorl %eax, %eax
callq 0x45d0
jmp 0xab2e
movq 0x10(%rsp), %rax
movq 0x18(%rax,%r15), %rdx
leaq 0xb610(%rip), %rsi      # 0x16337
leaq 0xa581(%rip), %rcx      # 0x152af
movq 0x8(%rsp), %rdi
xorl %r8d, %r8d
xorl %eax, %eax
callq 0x4500
leaq 0xb59e(%rip), %rdx      # 0x162e2
movq 0x18(%rsp), %rdi
movq %r12, %rsi
movl $0x2d5, %ecx            # imm = 0x2D5
callq 0x4280
jmp 0xab29
leaq 0xb6f7(%rip), %rax      # 0x16459
jmp 0xab21
movq 0x8(%rsp), %rax
movq (%rax), %rdi
leaq 0xb715(%rip), %rsi      # 0x1648b
xorl %eax, %eax
callq 0x45d0
jmp 0xab29