// File: /workspace/github_c_makefile_star2_O3/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, 0x58(%rsp)
movq $0x0, 0x38(%rsp)
movl %edx, 0x10(%rsp)
cmpl $0x1, %edx
jg 0x7ea6
movq (%rcx), %rdx
leaq 0xc9d5(%rip), %rsi      # 0x14860
leaq 0xcbaa(%rip), %rcx      # 0x14a3c
xorl %r8d, %r8d
xorl %eax, %eax
callq 0x4510
movl $0x1, %ebx
jmp 0x8411
movq %rdi, 0x18(%rsp)
movq 0x8(%rcx), %rbx
cmpb $0x0, (%rbx)
je 0x83f0
movq 0x18(%rsp), %rax
movq (%rax), %rax
movq %rax, 0x40(%rsp)
addl $-0x2, 0x10(%rsp)
addq $0x10, %rcx
movq %rcx, 0x20(%rsp)
movl $0xc7, 0x14(%rsp)
leaq 0x2c(%rsp), %r15
xorl %r13d, %r13d
xorl %eax, %eax
movl %eax, 0x30(%rsp)
movl %eax, 0x34(%rsp)
cmpb $0x25, (%rbx)
movq %r13, 0x60(%rsp)
jne 0x7f12
movb 0x1(%rbx), %r12b
cmpb $0x25, %r12b
jne 0x7f67
movq %rbx, 0x38(%rsp)
addq $0x2, %rbx
movl $0x1, %r14d
jmp 0x7f5b
movq %rbx, 0x38(%rsp)
movq %rbx, %r14
movzbl (%rbx), %eax
cmpl $0x5c, %eax
je 0x7f38
testl %eax, %eax
je 0x7f56
cmpl $0x25, %eax
je 0x7f56
movb %al, (%r14)
incq %r14
movl $0x1, %eax
jmp 0x7f51
movq %rbx, %rdi
movq %r15, %rsi
callq 0x42c0
movb %al, (%r14)
cmpb $0x1, %al
sbbq $-0x1, %r14
movslq 0x2c(%rsp), %rax
addq %rax, %rbx
jmp 0x7f1a
subl 0x38(%rsp), %r14d
movb $0x1, %sil
xorl %edx, %edx
movb $0x1, %cl
jmp 0x827d
movb $0x25, 0x70(%rsp)
addq $0x2, %rbx
leaq 0x70(%rsp), %r15
movq %rbx, %r13
leaq 0x71(%rsp), %r14
movabsq $0x1280900000000, %rcx  # imm = 0x1280900000000
cmpb $0x30, %r12b
ja 0x7fa9
movzbl %r12b, %eax
btq %rax, %rcx
jae 0x7fa9
movb %r12b, (%r14)
movb (%r13), %r12b
incq %r14
incq %r13
incq %r15
jmp 0x7f87
callq 0x4650
movq %rax, 0x50(%rsp)
movq (%rax), %rbp
movsbq %r12b, %rax
leaq -0x1(%r13), %rbx
testb $0x8, 0x1(%rbp,%rax,2)
jne 0x800c
cmpb $0x2a, %r12b
jne 0x8057
cmpl $0x0, 0x10(%rsp)
jle 0x8425
movq 0x20(%rsp), %rbx
movq (%rbx), %rsi
movq 0x18(%rsp), %rdi
leaq 0x34(%rsp), %rdx
callq 0x41c0
testl %eax, %eax
jne 0x8434
decl 0x10(%rsp)
addq $0x8, %rbx
movq %rbx, 0x20(%rsp)
movl 0x34(%rsp), %eax
jmp 0x802a
movq %rbx, %rdi
callq 0x4590
movl %eax, 0x34(%rsp)
movsbq 0x1(%rbx), %rcx
incq %rbx
testb $0x8, 0x1(%rbp,%rcx,2)
jne 0x8018
movq %rbx, %r13
testl %eax, %eax
je 0x8054
movq %r14, %rdi
leaq 0xc2db(%rip), %rsi      # 0x14313
movl %eax, %edx
xorl %eax, %eax
callq 0x45e0
cmpb $0x0, 0x1(%r15)
leaq 0x1(%r15), %r15
jne 0x8041
movq %r13, %rbx
movq %r15, %r14
jmp 0x8057
movq %r13, %rbx
movb (%rbx), %al
cmpb $0x2e, %al
jne 0x806a
movb $0x2e, (%r14)
incq %r14
movb 0x1(%rbx), %al
incq %rbx
movq 0x50(%rsp), %rcx
movq (%rcx), %r15
movsbq %al, %rcx
testb $0x8, 0x1(%r15,%rcx,2)
jne 0x80be
cmpb $0x2a, %al
jne 0x80da
cmpl $0x0, 0x10(%rsp)
jle 0x8425
movq 0x20(%rsp), %r15
movq (%r15), %rsi
movq 0x18(%rsp), %rdi
leaq 0x30(%rsp), %rdx
callq 0x41c0
testl %eax, %eax
jne 0x8434
decl 0x10(%rsp)
addq $0x8, %r15
movq %r15, 0x20(%rsp)
incq %rbx
jmp 0x80da
movq %rbx, %rdi
callq 0x4590
movl %eax, 0x30(%rsp)
movsbq 0x1(%rbx), %rax
incq %rbx
testb $0x8, 0x1(%r15,%rax,2)
jne 0x80ca
movl 0x30(%rsp), %edx
testl %edx, %edx
je 0x8106
movq %r14, %rdi
leaq 0xc227(%rip), %rsi      # 0x14313
xorl %eax, %eax
callq 0x45e0
decq %r14
movq %r14, %rax
leaq 0x1(%rax), %r14
cmpb $0x0, 0x1(%rax)
movq %r14, %rax
jne 0x80f9
movzbl (%rbx), %eax
cmpl $0x68, %eax
je 0x811d
xorl %ebp, %ebp
movb $0x1, %r12b
cmpl $0x6c, %eax
jne 0x812f
incq %rbx
jmp 0x812f
movb $0x68, (%r14)
incq %r14
incq %rbx
movl $0x1, %ebp
xorl %r12d, %r12d
movsbq (%rbx), %r15
movb %r15b, (%r14)
movb $0x0, 0x1(%r14)
cmpl $0x0, 0x10(%rsp)
jle 0x8425
movzbl (%rbx), %r13d
cmpl $0x57, %r13d
jle 0x8197
leal -0x63(%r13), %eax
cmpl $0x15, %eax
ja 0x822d
leaq 0xc6a4(%rip), %rcx      # 0x14808
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movq 0x20(%rsp), %rax
movq (%rax), %rsi
movq 0x18(%rsp), %rdi
leaq 0x38(%rsp), %rdx
callq 0x44c0
testl %eax, %eax
jne 0x8434
movl $0x1, %r14d
jmp 0x825c
leal -0x44(%r13), %eax
cmpl $0xb, %eax
ja 0x81f6
leaq 0xc631(%rip), %rcx      # 0x147d8
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
callq 0x4640
movq (%rax), %rax
movb (%rax,%r15,4), %al
movb %al, (%r14)
movq 0x20(%rsp), %rax
movq (%rax), %rsi
movq 0x18(%rsp), %rdi
leaq 0x68(%rsp), %rdx
callq 0x45b0
testl %eax, %eax
jne 0x8434
movl 0x30(%rsp), %eax
movl $0x140, %ecx            # imm = 0x140
leal (%rax,%rcx), %r14d
cmpl $0xb, %eax
cmovll %ecx, %r14d
xorl %ecx, %ecx
jmp 0x825e
cmpl $0x55, %r13d
jne 0x8460
callq 0x4640
movq (%rax), %rax
movb (%rax,%r13,4), %al
movzbl %r12b, %ecx
movb %al, (%r14,%rcx)
movl %ecx, %eax
xorb $0x1, %al
movzbl %al, %eax
negq %rax
movb $0x6c, (%r14,%rax)
movb $0x0, 0x1(%r14,%rcx)
xorl %ebp, %ebp
jmp 0x8237
cmpl $0x58, %r13d
jne 0x846e
movq 0x20(%rsp), %rax
movq (%rax), %rsi
movq 0x18(%rsp), %rdi
leaq 0x38(%rsp), %rdx
callq 0x44c0
testl %eax, %eax
jne 0x8434
movl $0x28, %r14d
movb $0x1, %cl
decl 0x10(%rsp)
addq $0x8, 0x20(%rsp)
incq %rbx
testl %ebp, %ebp
sete %sil
movb $0x1, %dl
leaq 0x2c(%rsp), %r15
movq 0x60(%rsp), %r13
movl 0x34(%rsp), %eax
cmpl %r14d, %eax
cmovgl %eax, %r14d
leal (%r14,%r13), %ebp
movslq %r13d, %r12
cmpl 0x14(%rsp), %ebp
jle 0x8325
movl %edx, 0x4c(%rsp)
movb %sil, 0xf(%rsp)
movl %ecx, 0x50(%rsp)
leal 0x1(,%rbp,2), %esi
movq 0x58(%rsp), %rdi
leaq 0xc617(%rip), %rdx      # 0x148d0
movl $0x370, %ecx            # imm = 0x370
callq 0x44d0
movq %rax, %r15
testl %r13d, %r13d
movq 0x40(%rsp), %r13
je 0x82de
movq %r15, %rdi
movq %r13, %rsi
movq %r12, %rdx
callq 0x43b0
movq %r13, %rsi
leal (,%rbp,2), %r13d
cmpl $0xc7, 0x14(%rsp)
je 0x8309
movq 0x58(%rsp), %rdi
leaq 0xc5d1(%rip), %rdx      # 0x148d0
movl $0x375, %ecx            # imm = 0x375
callq 0x4280
movl %r13d, 0x14(%rsp)
movq %r15, %r13
leaq 0x2c(%rsp), %r15
movl 0x50(%rsp), %ecx
movb 0xf(%rsp), %sil
movl 0x4c(%rsp), %edx
jmp 0x832a
movq 0x40(%rsp), %r13
addq %r13, %r12
testb %dl, %dl
movq %r13, 0x40(%rsp)
je 0x835a
testb %cl, %cl
je 0x8375
movq 0x38(%rsp), %rdx
testb %sil, %sil
movq 0x60(%rsp), %r13
je 0x8391
movq %r12, %rdi
leaq 0x70(%rsp), %rsi
xorl %eax, %eax
callq 0x45e0
jmp 0x83a3
movq 0x38(%rsp), %rsi
movslq %r14d, %rdx
movq %r12, %rdi
callq 0x43b0
movslq %ebp, %rax
movb $0x0, (%r13,%rax)
jmp 0x83b1
movsd 0x68(%rsp), %xmm0
movq %r12, %rdi
leaq 0x70(%rsp), %rsi
movb $0x1, %al
callq 0x45e0
movq 0x60(%rsp), %r13
jmp 0x83a3
movswl %dx, %edx
movq %r12, %rdi
leaq 0x70(%rsp), %rsi
xorl %eax, %eax
callq 0x45e0
movq %r12, %rdi
callq 0x41d0
addl %eax, %r13d
movl %r13d, %ebp
cmpb $0x0, (%rbx)
movl %ebp, %r13d
jne 0x7ee3
jmp 0x83d9
movq 0x20(%rsp), %rax
movq (%rax), %rdi
movq %rdi, 0x38(%rsp)
callq 0x41d0
movq %rax, %r14
jmp 0x825c
movq 0x18(%rsp), %rax
movq 0x40(%rsp), %rcx
movq %rcx, (%rax)
cmpl $0xc7, 0x14(%rsp)
jne 0x83ff
movq 0x18(%rsp), %rax
movq $0x0, 0x8(%rax)
jmp 0x840f
movq 0x12b9a(%rip), %rax     # 0x1afa0
movq 0x18(%rsp), %rcx
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
leaq 0xc677(%rip), %rax      # 0x14aa3
movq 0x18(%rsp), %rcx
movq %rax, (%rcx)
movl $0x1, %ebx
cmpl $0xc7, 0x14(%rsp)
je 0x8411
leaq 0xc486(%rip), %rdx      # 0x148d0
movq 0x58(%rsp), %rdi
movq 0x40(%rsp), %rsi
movl $0x39c, %ecx            # imm = 0x39C
callq 0x4280
jmp 0x8411
testl %r13d, %r13d
jne 0x846e
leaq 0xc5ed(%rip), %rax      # 0x14a59
jmp 0x842c
movsbl %r13b, %edx
movq 0x18(%rsp), %rax
movq (%rax), %rdi
leaq 0xc609(%rip), %rsi      # 0x14a8a
xorl %eax, %eax
callq 0x45e0
jmp 0x8434
nop