// File: /workspace/github_c_makefile_star2_O2/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)
andq $0x0, 0x38(%rsp)
cmpl $0x1, %edx
jg 0x7873
movq (%rcx), %rdx
leaq 0xc006(%rip), %rsi      # 0x13860
leaq 0xc1db(%rip), %rcx      # 0x13a3c
xorl %r8d, %r8d
xorl %eax, %eax
callq 0x4520
pushq $0x1
popq %rbx
jmp 0x7df1
movq %rdi, 0x18(%rsp)
movq (%rdi), %rax
movq %rax, 0x40(%rsp)
addl $-0x2, %edx
movl %edx, 0x10(%rsp)
movq 0x8(%rcx), %r14
addq $0x10, %rcx
movq %rcx, 0x20(%rsp)
movl $0xc7, 0x14(%rsp)
leaq 0x2c(%rsp), %r15
pushq $0x1
popq %r12
xorl %r13d, %r13d
cmpb $0x0, (%r14)
je 0x7d8d
andl $0x0, 0x30(%rsp)
andl $0x0, 0x34(%rsp)
cmpb $0x25, (%r14)
movq %r13, 0x60(%rsp)
jne 0x78ea
movb 0x1(%r14), %r12b
cmpb $0x25, %r12b
jne 0x793a
movq %r14, 0x38(%rsp)
addq $0x2, %r14
movb $0x1, %cl
xorl %esi, %esi
movb $0x1, %dl
pushq $0x1
popq %rax
movl %eax, %ebx
jmp 0x7c31
movq %r14, 0x38(%rsp)
movq %r14, %rbx
movzbl (%r14), %eax
cmpl $0x5c, %eax
je 0x790e
testl %eax, %eax
je 0x792b
cmpl $0x25, %eax
je 0x792b
movb %al, (%rbx)
incq %rbx
movq %r12, %rax
jmp 0x7926
movq %r14, %rdi
movq %r15, %rsi
callq 0x42c0
movb %al, (%rbx)
cmpb $0x1, %al
sbbq $-0x1, %rbx
movslq 0x2c(%rsp), %rax
addq %rax, %r14
jmp 0x78f2
subl 0x38(%rsp), %ebx
movb $0x1, %cl
xorl %esi, %esi
movb $0x1, %dl
jmp 0x7c31
movb $0x25, 0x70(%rsp)
addq $0x2, %r14
leaq 0x70(%rsp), %r15
movq %r14, %r13
leaq 0x71(%rsp), %rbx
movabsq $0x1280900000000, %rcx  # imm = 0x1280900000000
cmpb $0x30, %r12b
ja 0x797c
movzbl %r12b, %eax
btq %rax, %rcx
jae 0x797c
movb %r12b, (%rbx)
movb (%r13), %r12b
incq %rbx
incq %r13
incq %r15
jmp 0x795a
callq 0x4660
movq %rax, 0x50(%rsp)
movq (%rax), %rbp
movsbq %r12b, %rax
leaq -0x1(%r13), %r14
testb $0x8, 0x1(%rbp,%rax,2)
jne 0x79df
cmpb $0x2a, %r12b
jne 0x7a2a
cmpl $0x0, 0x10(%rsp)
jle 0x7dba
movq 0x20(%rsp), %r14
movq (%r14), %rsi
movq 0x18(%rsp), %rdi
leaq 0x34(%rsp), %rdx
callq 0x41c0
testl %eax, %eax
jne 0x7dc9
decl 0x10(%rsp)
addq $0x8, %r14
movq %r14, 0x20(%rsp)
movl 0x34(%rsp), %eax
jmp 0x79fd
movq %r14, %rdi
callq 0x45a0
movl %eax, 0x34(%rsp)
movsbq 0x1(%r14), %rcx
incq %r14
testb $0x8, 0x1(%rbp,%rcx,2)
jne 0x79eb
movq %r14, %r13
testl %eax, %eax
je 0x7a27
movq %rbx, %rdi
leaq 0xb908(%rip), %rsi      # 0x13313
movl %eax, %edx
xorl %eax, %eax
callq 0x45f0
cmpb $0x0, 0x1(%r15)
leaq 0x1(%r15), %r15
jne 0x7a14
movq %r13, %r14
movq %r15, %rbx
jmp 0x7a2a
movq %r13, %r14
movb (%r14), %al
cmpb $0x2e, %al
jne 0x7a3e
movb $0x2e, (%rbx)
incq %rbx
movb 0x1(%r14), %al
incq %r14
movq 0x50(%rsp), %rcx
movq (%rcx), %r15
movsbq %al, %rcx
testb $0x8, 0x1(%r15,%rcx,2)
jne 0x7a92
cmpb $0x2a, %al
jne 0x7aae
cmpl $0x0, 0x10(%rsp)
jle 0x7dba
movq 0x20(%rsp), %r15
movq (%r15), %rsi
movq 0x18(%rsp), %rdi
leaq 0x30(%rsp), %rdx
callq 0x41c0
testl %eax, %eax
jne 0x7dc9
decl 0x10(%rsp)
addq $0x8, %r15
movq %r15, 0x20(%rsp)
incq %r14
jmp 0x7aae
movq %r14, %rdi
callq 0x45a0
movl %eax, 0x30(%rsp)
movsbq 0x1(%r14), %rax
incq %r14
testb $0x8, 0x1(%r15,%rax,2)
jne 0x7a9e
movl 0x30(%rsp), %edx
testl %edx, %edx
je 0x7ada
movq %rbx, %rdi
leaq 0xb853(%rip), %rsi      # 0x13313
xorl %eax, %eax
callq 0x45f0
decq %rbx
movq %rbx, %rax
leaq 0x1(%rax), %rbx
cmpb $0x0, 0x1(%rax)
movq %rbx, %rax
jne 0x7acd
movzbl (%r14), %eax
cmpl $0x68, %eax
je 0x7af2
xorl %ebp, %ebp
movb $0x1, %r12b
cmpl $0x6c, %eax
jne 0x7b01
incq %r14
jmp 0x7b01
movb $0x68, (%rbx)
incq %rbx
incq %r14
xorl %r12d, %r12d
pushq $0x1
popq %rbp
movsbq (%r14), %r15
movb %r15b, (%rbx)
movb $0x0, 0x1(%rbx)
cmpl $0x0, 0x10(%rsp)
jle 0x7dba
movzbl (%r14), %r13d
leal -0x63(%r13), %eax
cmpl $0x15, %eax
ja 0x7b54
leaq 0xbcdd(%rip), %rcx      # 0x13808
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movq 0x20(%rsp), %r15
movq (%r15), %rsi
movq 0x18(%rsp), %rdi
leaq 0x38(%rsp), %rdx
callq 0x44d0
movb $0x1, %dl
pushq $0x1
jmp 0x7c04
leal -0x44(%r13), %eax
cmpl $0xb, %eax
ja 0x7bb0
leaq 0xbc74(%rip), %rcx      # 0x137d8
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
callq 0x4650
movq (%rax), %rax
movb (%rax,%r15,4), %al
movb %al, (%rbx)
movq 0x20(%rsp), %r15
movq (%r15), %rsi
movq 0x18(%rsp), %rdi
leaq 0x68(%rsp), %rdx
callq 0x45c0
testl %eax, %eax
jne 0x7dc9
movl 0x30(%rsp), %eax
movl $0x140, %ecx            # imm = 0x140
leal (%rax,%rcx), %ebx
cmpl $0xb, %eax
cmovll %ecx, %ebx
xorl %edx, %edx
jmp 0x7c0f
cmpl $0x55, %r13d
je 0x7bc1
cmpl $0x58, %r13d
je 0x7be9
jmp 0x7e05
callq 0x4650
movq (%rax), %rax
movb (%rax,%r13,4), %al
movzbl %r12b, %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 %ebp, %ebp
movq 0x20(%rsp), %r15
movq (%r15), %rsi
movq 0x18(%rsp), %rdi
leaq 0x38(%rsp), %rdx
callq 0x44d0
movb $0x1, %dl
pushq $0x28
popq %rcx
movl %ecx, %ebx
testl %eax, %eax
jne 0x7dc9
decl 0x10(%rsp)
addq $0x8, %r15
movq %r15, 0x20(%rsp)
incq %r14
testl %ebp, %ebp
sete %cl
movb $0x1, %sil
leaq 0x2c(%rsp), %r15
movq 0x60(%rsp), %r13
movl 0x34(%rsp), %eax
cmpl %ebx, %eax
cmovgl %eax, %ebx
leal (%rbx,%r13), %ebp
movslq %r13d, %r12
cmpl 0x14(%rsp), %ebp
jle 0x7cd5
movl %esi, 0x4c(%rsp)
movb %cl, 0xf(%rsp)
movl %edx, 0x50(%rsp)
leal 0x1(,%rbp,2), %esi
movq 0x58(%rsp), %rdi
leaq 0xbc66(%rip), %rdx      # 0x138d0
movl $0x370, %ecx            # imm = 0x370
callq 0x44e0
movq %rax, %r15
testl %r13d, %r13d
movq 0x40(%rsp), %r13
je 0x7c8f
movq %r15, %rdi
movq %r13, %rsi
movq %r12, %rdx
callq 0x43c0
movq %r13, %rsi
leal (,%rbp,2), %r13d
cmpl $0xc7, 0x14(%rsp)
je 0x7cba
movq 0x58(%rsp), %rdi
leaq 0xbc20(%rip), %rdx      # 0x138d0
movl $0x375, %ecx            # imm = 0x375
callq 0x4280
movl %r13d, 0x14(%rsp)
movq %r15, %r13
leaq 0x2c(%rsp), %r15
movl 0x50(%rsp), %edx
movb 0xf(%rsp), %cl
movl 0x4c(%rsp), %esi
jmp 0x7cda
movq 0x40(%rsp), %r13
addq %r13, %r12
testb %sil, %sil
movq %r13, 0x40(%rsp)
je 0x7d0a
testb %dl, %dl
je 0x7d2f
movq 0x38(%rsp), %rdx
testb %cl, %cl
movq 0x60(%rsp), %r13
je 0x7d4b
movq %r12, %rdi
leaq 0x70(%rsp), %rsi
xorl %eax, %eax
callq 0x45f0
jmp 0x7d5d
movq 0x38(%rsp), %rsi
movslq %ebx, %rdx
movq %r12, %rdi
callq 0x43c0
movslq %ebp, %rax
movb $0x0, (%r13,%rax)
movl %ebp, %r13d
pushq $0x1
popq %r12
jmp 0x78a8
movsd 0x68(%rsp), %xmm0
movq %r12, %rdi
leaq 0x70(%rsp), %rsi
movb $0x1, %al
callq 0x45f0
movq 0x60(%rsp), %r13
jmp 0x7d5d
movswl %dx, %edx
movq %r12, %rdi
leaq 0x70(%rsp), %rsi
xorl %eax, %eax
callq 0x45f0
movq %r12, %rdi
callq 0x41d0
addl %eax, %r13d
pushq $0x1
popq %r12
jmp 0x78a8
movq 0x20(%rsp), %r15
movq (%r15), %rdi
movq %rdi, 0x38(%rsp)
callq 0x41d0
movq %rax, %rbx
movb $0x1, %dl
jmp 0x7c0f
movq 0x18(%rsp), %rcx
movq 0x40(%rsp), %rax
movq %rax, (%rcx)
cmpl $0xc7, 0x14(%rsp)
jne 0x7dab
andq $0x0, 0x8(%rcx)
jmp 0x7db6
movq 0x131ee(%rip), %rax     # 0x1afa0
movq %rax, 0x8(%rcx)
xorl %ebx, %ebx
jmp 0x7df1
leaq 0xbce2(%rip), %rax      # 0x13aa3
movq 0x18(%rsp), %rcx
movq %rax, (%rcx)
pushq $0x1
popq %rbx
cmpl $0xc7, 0x14(%rsp)
je 0x7df1
leaq 0xbaf3(%rip), %rdx      # 0x138d0
movq 0x58(%rsp), %rdi
movq 0x40(%rsp), %rsi
movl $0x39c, %ecx            # imm = 0x39C
callq 0x4280
movl %ebx, %eax
addq $0x98, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
testl %r13d, %r13d
jne 0x7e13
leaq 0xbc48(%rip), %rax      # 0x13a59
jmp 0x7dc1
movsbl %r13b, %edx
movq 0x18(%rsp), %rax
movq (%rax), %rdi
leaq 0xbc64(%rip), %rsi      # 0x13a8a
xorl %eax, %eax
callq 0x45f0
jmp 0x7dc9
nop