// File: /workspace/github_c_makefile_star2_O1/haxlang[P]hax/haxCmdAH.c
// Function: Hax_FormatCmd
int
Hax_FormatCmd(
    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;
    char *format;	/* Used to read characters from the format
				 * string. */
    char newFormat[40];		/* A new format specifier is generated here. */
    int width;			/* Field width from field specifier, or 0 if
				 * no width given. */
    int precision;		/* Field precision from field specifier, or 0
				 * if no precision given. */
    int size;			/* Number of bytes needed for result of
				 * conversion, based on type of conversion
				 * ("e", "s", etc.) and width from above. */
    char *oneWordValue = NULL;	/* Used to hold value to pass to sprintf, if
				 * it's a one-word value. */
    double twoWordValue;	/* Used to hold value to pass to sprintf if
				 * it's a two-word value. */
    int useTwoWords;		/* 0 means use oneWordValue, 1 means use
				 * twoWordValue. */
    char *dst = interp->result;	/* Where result is stored.  Starts off at
				 * interp->resultSpace, but may get dynamically
				 * re-allocated if this isn't enough. */
    int dstSize = 0;		/* Number of non-null characters currently
				 * stored at dst. */
    int dstSpace = HAX_RESULT_SIZE;
				/* Total amount of storage space available
				 * in dst (not including null terminator. */
    int noPercent;		/* Special case for speed:  indicates there's
				 * no field specifier, just a string to copy. */
    char **curArg;		/* Remainder of argv array. */
    int useShort;		/* Value to be printed is short (half word). */

    /*
     * This procedure is a bit nasty.  The goal is to use sprintf to
     * do most of the dirty work.  There are several problems:
     * 1. this procedure can't trust its arguments.
     * 2. we must be able to provide a large enough result area to hold
     *    whatever's generated.  This is hard to estimate.
     * 2. there's no way to move the arguments from argv to the call
     *    to sprintf in a reasonable way.  This is particularly nasty
     *    because some of the arguments may be two-word values (doubles).
     * So, what happens here is to scan the format string one % group
     * at a time, making many individual calls to sprintf.
     */

    if (argc < 2) {
	Hax_AppendResult(interp, "wrong # args: should be \"", argv[0],
		" formatString ?arg arg ...?\"", (char *) NULL);
	return HAX_ERROR;
    }
    curArg = argv+2;
    argc -= 2;
    for (format = argv[1]; *format != 0; ) {
	char *newPtr = newFormat;

	width = precision = useTwoWords = noPercent = useShort = 0;

	/*
	 * Get rid of any characters before the next field specifier.
	 * Collapse backslash sequences found along the way.
	 */

	if (*format != '%') {
	    char *p;
	    int bsSize;

	    oneWordValue = p = format;
	    while ((*format != '%') && (*format != 0)) {
		if (*format == '\\') {
		    *p = Hax_Backslash(format, &bsSize);
		    if (*p != 0) {
			p++;
		    }
		    format += bsSize;
		} else {
		    *p = *format;
		    p++;
		    format++;
		}
	    }
	    size = p - oneWordValue;
	    noPercent = 1;
	    goto doField;
	}

	if (format[1] == '%') {
	    oneWordValue = format;
	    size = 1;
	    noPercent = 1;
	    format += 2;
	    goto doField;
	}

	/*
	 * Parse off a field specifier, compute how many characters
	 * will be needed to store the result, and substitute for
	 * "*" size specifiers.
	 */

	*newPtr = '%';
	newPtr++;
	format++;
	while ((*format == '-') || (*format == '#') || (*format == '0')
		|| (*format == ' ') || (*format == '+')) {
	    *newPtr = *format;
	    newPtr++;
	    format++;
	}
	if (isdigit(*format)) {
	    width = atoi(format);
	    do {
		format++;
	    } while (isdigit(*format));
	} else if (*format == '*') {
	    if (argc <= 0) {
		goto notEnoughArgs;
	    }
	    if (Hax_GetInt(interp, *curArg, &width) != HAX_OK) {
		goto fmtError;
	    }
	    argc--;
	    curArg++;
	    format++;
	}
	if (width != 0) {
	    sprintf(newPtr, "%d", width);
	    while (*newPtr != 0) {
		newPtr++;
	    }
	}
	if (*format == '.') {
	    *newPtr = '.';
	    newPtr++;
	    format++;
	}
	if (isdigit(*format)) {
	    precision = atoi(format);
	    do {
		format++;
	    } while (isdigit(*format));
	} else if (*format == '*') {
	    if (argc <= 0) {
		goto notEnoughArgs;
	    }
	    if (Hax_GetInt(interp, *curArg, &precision) != HAX_OK) {
		goto fmtError;
	    }
	    argc--;
	    curArg++;
	    format++;
	}
	if (precision != 0) {
	    sprintf(newPtr, "%d", precision);
	    while (*newPtr != 0) {
		newPtr++;
	    }
	}
	if (*format == 'l') {
	    format++;
	} else if (*format == 'h') {
	    useShort = 1;
	    *newPtr = 'h';
	    newPtr++;
	    format++;
	}
	*newPtr = *format;
	newPtr++;
	*newPtr = 0;
	if (argc <= 0) {
	    goto notEnoughArgs;
	}
	switch (*format) {
	    case 'D':
	    case 'O':
	    case 'U':
		if (!useShort) {
		    newPtr++;
		} else {
		    useShort = 0;
		}
		newPtr[-1] = tolower(*format);
		newPtr[-2] = 'l';
		*newPtr = 0;
	    case 'd':
	    case 'o':
	    case 'u':
	    case 'x':
	    case 'X':
		if (Hax_GetLong(interp, *curArg, (long *) &oneWordValue)
			!= HAX_OK) {
		    goto fmtError;
		}
		size = 40;
		break;
	    case 's':
		oneWordValue = *curArg;
		size = strlen(*curArg);
		break;
	    case 'c':
		if (Hax_GetLong(interp, *curArg, (long *) &oneWordValue)
			!= HAX_OK) {
		    goto fmtError;
		}
		size = 1;
		break;
	    case 'F':
		newPtr[-1] = tolower(newPtr[-1]);
	    case 'e':
	    case 'E':
	    case 'f':
	    case 'g':
	    case 'G':
		if (Hax_GetDouble(interp, *curArg, &twoWordValue) != HAX_OK) {
		    goto fmtError;
		}
		useTwoWords = 1;
		size = 320;
		if (precision > 10) {
		    size += precision;
		}
		break;
	    case 0:
		interp->result =
			(char *) "format string ended in middle of field "
			    "specifier";
		goto fmtError;
	    default:
		sprintf(interp->result, "bad field specifier \"%c\"", *format);
		goto fmtError;
	}
	argc--;
	curArg++;
	format++;

	/*
	 * Make sure that there's enough space to hold the formatted
	 * result, then format it.
	 */

	doField:
	if (width > size) {
	    size = width;
	}
	if ((dstSize + size) > dstSpace) {
	    char *newDst;
	    int newSpace;

	    newSpace = 2*(dstSize + size);
	    newDst = (char *) ckalloc(memoryp, (unsigned) newSpace+1);
	    if (dstSize != 0) {
		memcpy(newDst, dst, dstSize);
	    }
	    if (dstSpace != HAX_RESULT_SIZE) {
		ckfree(memoryp, dst);
	    }
	    dst = newDst;
	    dstSpace = newSpace;
	}
	if (noPercent) {
	    memcpy((dst+dstSize), oneWordValue, size);
	    dstSize += size;
	    dst[dstSize] = 0;
	} else {
	    if (useTwoWords) {
		sprintf(dst+dstSize, newFormat, twoWordValue);
	    } else if (useShort) {
		/*
		 * The double cast below is needed for a few machines
		 * (e.g. Pyramids as of 1/93) that don't like casts
		 * directly from pointers to shorts.
		 */

		sprintf(dst+dstSize, newFormat, (short) (long) oneWordValue);
	    } else {
		sprintf(dst+dstSize, newFormat, (char *) oneWordValue);
	    }
	    dstSize += strlen(dst+dstSize);
	}
    }

    interp->result = dst;
    if (dstSpace != HAX_RESULT_SIZE) {
	interp->freeProc = (Hax_FreeProc *) free;
    } else {
	interp->freeProc = 0;
    }
    return HAX_OK;

    notEnoughArgs:
    interp->result = (char *) "not enough arguments for all format specifiers";
    fmtError:
    if (dstSpace != HAX_RESULT_SIZE) {
	ckfree(memoryp, dst);
    }
    return HAX_ERROR;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x98, %rsp
movq %rsi, %rdi
movq 0x280(%rsi), %rax
movq %rax, 0x60(%rsp)
movq $0x0, 0x38(%rsp)
cmpl $0x1, %edx
jg 0x8057
movq (%rcx), %rdx
leaq 0xd838(%rip), %rsi      # 0x15874
leaq 0xda0d(%rip), %rcx      # 0x15a50
xorl %r8d, %r8d
xorl %eax, %eax
callq 0x4500
movl $0x1, %ebx
jmp 0x86c3
movq %rdi, 0x28(%rsp)
movq (%rdi), %rax
movq %rax, 0x40(%rsp)
addl $-0x2, %edx
movl %edx, 0x8(%rsp)
movq 0x8(%rcx), %r12
addq $0x10, %rcx
movq %rcx, 0x20(%rsp)
movl $0xc7, 0x1c(%rsp)
movabsq $0x1280900000000, %rbp  # imm = 0x1280900000000
leaq 0x54(%rsp), %rbx
xorl %r13d, %r13d
cmpb $0x0, (%r12)
je 0x865a
xorl %eax, %eax
movl %eax, 0x30(%rsp)
movl %eax, 0x34(%rsp)
cmpb $0x25, (%r12)
movq %r13, 0x10(%rsp)
jne 0x80d3
cmpb $0x25, 0x1(%r12)
jne 0x81b8
movq %r12, 0x38(%rsp)
movq %r12, %r14
addq $0x2, %r14
movl $0x1, %r12d
jmp 0x811f
movq %r12, 0x38(%rsp)
movq %r12, %r14
movzbl (%r14), %eax
cmpl $0x5c, %eax
je 0x80fb
testl %eax, %eax
je 0x811a
cmpl $0x25, %eax
je 0x811a
movb %al, (%r12)
incq %r12
movl $0x1, %eax
jmp 0x8115
movq %r14, %rdi
movq %rbx, %rsi
callq 0x42c0
movb %al, (%r12)
cmpb $0x1, %al
sbbq $-0x1, %r12
movslq 0x54(%rsp), %rax
addq %rax, %r14
jmp 0x80db
subl 0x38(%rsp), %r12d
movb $0x1, %sil
xorl %edx, %edx
movb $0x1, %cl
movl 0x34(%rsp), %eax
cmpl %r12d, %eax
cmovgl %eax, %r12d
leal (%r12,%r13), %r15d
movslq %r13d, %rbx
cmpl 0x1c(%rsp), %r15d
jle 0x81ae
movl %edx, 0x50(%rsp)
movb %sil, 0xf(%rsp)
movl %ecx, 0x48(%rsp)
leal 0x1(,%r15,2), %esi
movq 0x60(%rsp), %rdi
leaq 0xd784(%rip), %rdx      # 0x158e4
movl $0x370, %ecx            # imm = 0x370
callq 0x44c0
testl %r13d, %r13d
movq 0x40(%rsp), %r13
movq %rax, 0x58(%rsp)
je 0x818c
movq %rax, %rdi
movq %r13, %rsi
movq %rbx, %rdx
callq 0x43a0
movq 0x58(%rsp), %rax
movq %r13, %rsi
leal (%r15,%r15), %r13d
cmpl $0xc7, 0x1c(%rsp)
jne 0x826b
movl %r13d, 0x1c(%rsp)
movq %rax, %r13
jmp 0x828b
movq 0x40(%rsp), %r13
jmp 0x8298
incq %r12
movb $0x25, 0x70(%rsp)
leaq 0x70(%rsp), %r15
leaq 0x71(%rsp), %rbx
movq %r12, %r14
movzbl (%r14), %r13d
cmpq $0x30, %r13
ja 0x81eb
btq %r13, %rbp
jae 0x81eb
movb %r13b, (%rbx)
incq %r14
incq %rbx
incq %r15
jmp 0x81cd
movsbq %r13b, %rax
movq %rax, 0x58(%rsp)
callq 0x4640
movq (%rax), %r12
movq 0x58(%rsp), %rcx
testb $0x8, 0x1(%r12,%rcx,2)
movq %rax, 0x48(%rsp)
jne 0x830e
cmpb $0x2a, %r13b
jne 0x832a
cmpl $0x0, 0x8(%rsp)
movq 0x10(%rsp), %r13
jle 0x8556
movq 0x20(%rsp), %r12
movq (%r12), %rsi
movq 0x28(%rsp), %rdi
leaq 0x34(%rsp), %rdx
callq 0x41c0
movl $0xc, %ecx
testl %eax, %eax
jne 0x85fc
movl 0x8(%rsp), %eax
decl %eax
addq $0x8, %r12
movq %r12, 0x20(%rsp)
movl %eax, %r12d
incq %r14
jmp 0x8334
movq 0x60(%rsp), %rdi
leaq 0xd66d(%rip), %rdx      # 0x158e4
movl $0x375, %ecx            # imm = 0x375
callq 0x4280
movl %r13d, 0x1c(%rsp)
movq 0x58(%rsp), %r13
movl 0x48(%rsp), %ecx
movb 0xf(%rsp), %sil
movl 0x50(%rsp), %edx
addq %r13, %rbx
testb %dl, %dl
movq %r13, 0x40(%rsp)
je 0x82cf
testb %cl, %cl
je 0x82f2
movq 0x38(%rsp), %rdx
testb %sil, %sil
movq 0x10(%rsp), %r13
je 0x8362
movq %rbx, %rdi
leaq 0x70(%rsp), %rsi
xorl %eax, %eax
callq 0x45d0
jmp 0x8374
movq 0x38(%rsp), %rsi
movslq %r12d, %rdx
movq %rbx, %rdi
callq 0x43a0
movslq %r15d, %rax
movb $0x0, (%r13,%rax)
xorl %ecx, %ecx
movl %r15d, %r13d
jmp 0x85fc
movsd 0x68(%rsp), %xmm0
movq %rbx, %rdi
leaq 0x70(%rsp), %rsi
movb $0x1, %al
callq 0x45d0
movq 0x10(%rsp), %r13
jmp 0x8374
movq %r14, %rdi
callq 0x4580
movl %eax, 0x34(%rsp)
movsbq 0x1(%r14), %rax
incq %r14
testb $0x8, 0x1(%r12,%rax,2)
jne 0x831a
movl 0x8(%rsp), %r12d
movq 0x10(%rsp), %r13
movl 0x34(%rsp), %edx
testl %edx, %edx
je 0x8386
movq %rbx, %rdi
leaq 0xcfcd(%rip), %rsi      # 0x15313
xorl %eax, %eax
callq 0x45d0
movq 0x48(%rsp), %rax
leaq 0x1(%r15), %rbx
cmpb $0x0, 0x1(%r15)
movq %rbx, %r15
jne 0x8352
jmp 0x838b
movswl %dx, %edx
movq %rbx, %rdi
leaq 0x70(%rsp), %rsi
xorl %eax, %eax
callq 0x45d0
movq %rbx, %rdi
callq 0x41d0
addl %eax, %r13d
xorl %ecx, %ecx
jmp 0x85fc
movq 0x48(%rsp), %rax
cmpb $0x2e, (%r14)
jne 0x839a
movb $0x2e, (%rbx)
incq %rbx
incq %r14
movq (%rax), %r15
movsbq (%r14), %rax
testb $0x8, 0x1(%r15,%rax,2)
jne 0x83f7
cmpb $0x2a, %al
jne 0x8413
testl %r12d, %r12d
jle 0x8556
movl %r12d, 0x8(%rsp)
movq 0x20(%rsp), %r12
movq (%r12), %rsi
movq 0x28(%rsp), %rdi
leaq 0x30(%rsp), %rdx
callq 0x41c0
movl $0xc, %ecx
testl %eax, %eax
jne 0x85fc
movl 0x8(%rsp), %eax
decl %eax
addq $0x8, %r12
movq %r12, 0x20(%rsp)
movl %eax, %r12d
incq %r14
jmp 0x8413
movq %r14, %rdi
callq 0x4580
movl %eax, 0x30(%rsp)
movsbq 0x1(%r14), %rax
incq %r14
testb $0x8, 0x1(%r15,%rax,2)
jne 0x8403
movl 0x30(%rsp), %edx
testl %edx, %edx
je 0x843f
movq %rbx, %rdi
leaq 0xceee(%rip), %rsi      # 0x15313
xorl %eax, %eax
callq 0x45d0
decq %rbx
movq %rbx, %rax
leaq 0x1(%rax), %rbx
cmpb $0x0, 0x1(%rax)
movq %rbx, %rax
jne 0x8432
movzbl (%r14), %eax
cmpl $0x68, %eax
je 0x8457
xorl %esi, %esi
movb $0x1, %r13b
cmpl $0x6c, %eax
jne 0x8468
incq %r14
jmp 0x8468
movb $0x68, (%rbx)
incq %rbx
incq %r14
movl $0x1, %esi
xorl %r13d, %r13d
movsbq (%r14), %r15
movb %r15b, (%rbx)
movb $0x0, 0x1(%rbx)
testl %r12d, %r12d
jle 0x84d7
movl %r12d, 0x8(%rsp)
movzbl (%r14), %eax
movsbq %al, %r12
cmpl $0x57, %eax
jle 0x84e9
leal -0x63(%rax), %ecx
cmpl $0x15, %ecx
ja 0x85c3
leaq 0xd37f(%rip), %rdx      # 0x1581c
movslq (%rdx,%rcx,4), %rax
addq %rdx, %rax
jmpq *%rax
movl %esi, %ebx
movq 0x20(%rsp), %rax
movq (%rax), %rsi
movq 0x28(%rsp), %rdi
leaq 0x38(%rsp), %rdx
callq 0x44b0
movl $0xc, %ecx
testl %eax, %eax
jne 0x85f7
movl $0x1, %r12d
jmp 0x8628
movl $0x0, 0x8(%rsp)
movl $0xb, %ecx
jmp 0x85f7
leal -0x44(%rax), %ecx
cmpl $0xb, %ecx
ja 0x8568
leaq 0xd2f4(%rip), %rdx      # 0x157ec
movslq (%rdx,%rcx,4), %rax
addq %rdx, %rax
jmpq *%rax
movl %esi, %r12d
callq 0x4630
movl %r12d, %esi
movq (%rax), %rax
movb (%rax,%r15,4), %al
movb %al, (%rbx)
movl %esi, %ebx
movq 0x20(%rsp), %rax
movq (%rax), %rsi
movq 0x28(%rsp), %rdi
leaq 0x68(%rsp), %rdx
callq 0x45a0
movl $0xc, %ecx
testl %eax, %eax
jne 0x85f7
movl 0x30(%rsp), %eax
movl $0x140, %ecx            # imm = 0x140
leal (%rax,%rcx), %r12d
cmpl $0xb, %eax
cmovll %ecx, %r12d
xorl %ecx, %ecx
jmp 0x862a
movl $0x0, 0x8(%rsp)
movl $0xb, %ecx
jmp 0x85fc
testl %eax, %eax
je 0x85e3
cmpl $0x55, %eax
jne 0x85c8
callq 0x4630
movq (%rax), %rax
movb (%rax,%r12,4), %al
movzbl %r13b, %ecx
movb %al, (%rbx,%rcx)
movl %ecx, %eax
xorb $0x1, %al
movzbl %al, %eax
negq %rax
movb $0x6c, (%rbx,%rax)
movb $0x0, 0x1(%rbx,%rcx)
xorl %esi, %esi
movl %esi, %ebx
movq 0x20(%rsp), %rax
movq (%rax), %rsi
movq 0x28(%rsp), %rdi
leaq 0x38(%rsp), %rdx
callq 0x44b0
movl $0xc, %ecx
testl %eax, %eax
jne 0x85f7
movl $0x28, %r12d
jmp 0x8628
cmpl $0x58, %eax
je 0x8599
movq 0x28(%rsp), %rax
movq (%rax), %rdi
leaq 0xd4c7(%rip), %rsi      # 0x15a9e
movl %r12d, %edx
xorl %eax, %eax
callq 0x45d0
jmp 0x85f2
movq 0x28(%rsp), %rax
leaq 0xd47e(%rip), %rcx      # 0x15a6d
movq %rcx, (%rax)
movl $0xc, %ecx
movq 0x10(%rsp), %r13
movq %r14, %r12
testl %ecx, %ecx
leaq 0x54(%rsp), %rbx
je 0x8092
jmp 0x8649
movl %esi, %ebx
movq 0x20(%rsp), %rcx
movq (%rcx), %rax
movq %rax, 0x38(%rsp)
movq (%rcx), %rdi
callq 0x41d0
movq %rax, %r12
movb $0x1, %cl
movq 0x10(%rsp), %r13
decl 0x8(%rsp)
addq $0x8, 0x20(%rsp)
incq %r14
testl %ebx, %ebx
sete %sil
movb $0x1, %dl
jmp 0x8126
cmpl $0xb, %ecx
je 0x867b
cmpl $0xc, %ecx
movq 0x40(%rsp), %rsi
je 0x868f
jmp 0x86c3
movq 0x28(%rsp), %rcx
movq 0x40(%rsp), %rax
movq %rax, (%rcx)
cmpl $0xc7, 0x1c(%rsp)
jne 0x86b6
movq $0x0, 0x8(%rcx)
jmp 0x86c1
leaq 0xd435(%rip), %rax      # 0x15ab7
movq 0x28(%rsp), %rcx
movq %rax, (%rcx)
movq 0x40(%rsp), %rsi
movl $0x1, %ebx
cmpl $0xc7, 0x1c(%rsp)
je 0x86c3
leaq 0xd23f(%rip), %rdx      # 0x158e4
movq 0x60(%rsp), %rdi
movl $0x39c, %ecx            # imm = 0x39C
callq 0x4280
jmp 0x86c3
movq 0x138e3(%rip), %rax     # 0x1bfa0
movq %rax, 0x8(%rcx)
xorl %ebx, %ebx
movl %ebx, %eax
addq $0x98, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nop