// File: /workspace/github_c_makefile_star2_O0/mloar[P]charset/iso2022s.c
// Function: write_iso2022s
static int write_iso2022s(charset_spec const *charset, long int input_chr,
			  charset_state *state,
			  void (*emit)(void *ctx, long int output),
			  void *emitctx)
{
    struct iso2022 const *iso = (struct iso2022 *)charset->data;
    int subcharset, len, i, j, cont, topbit = 0;
    unsigned long bytes;

    /*
     * For output, our s1 state variable contains most of the same
     * stuff as it did for input - initial-state indicator bit,
     * current container, and current subcharset selected in each
     * container.
     */

    /*
     * Analyse the character and find out what subcharset it needs
     * to go in.
     */
    if (input_chr >= 0 && !iso->from_ucs(input_chr, &subcharset, &bytes))
	return FALSE;

    if (!(state->s1 & 0x80000000)) {
	state->s1 = iso->s1;
	if (iso->initial_sequence)
	    for (i = 0; iso->initial_sequence[i]; i++)
		emit(emitctx, iso->initial_sequence[i]);
    }

    if (input_chr == -1) {
	unsigned long oldstate;
	int k;

	/*
	 * Special case: reset encoding state.
	 */
	for (i = 0; iso->reset[i]; i++) {
	    j = iso->reset[i] - 1;
	    oldstate = state->s1;
	    state->s1 &= iso->escapes[j].andbits;
	    state->s1 ^= iso->escapes[j].xorbits;
	    if (state->s1 != oldstate) {
		/* We must actually emit this sequence. */
		for (k = 0; iso->escapes[j].sequence[k]; k++)
		    emit(emitctx, iso->escapes[j].sequence[k]);
	    }
	}

	return TRUE;
    }

    /*
     * Now begins the fun. We now know what subcharset we want. So
     * we must find out which container we should select it into,
     * select it into it if necessary, select that _container_ if
     * necessary, and then output the given bytes.
     */
    for (i = 0; i < iso->nescapes; i++)
	if (iso->escapes[i].subcharset == subcharset &&
	    !(iso->escapes[i].container & RO))
	    break;
    assert(i < iso->nescapes);

    /*
     * We've found the escape sequence which would select this
     * subcharset into a container. However, that subcharset might
     * already _be_ selected in that container! Check before we go
     * to the effort of emitting the sequence.
     */
    cont = iso->escapes[i].container &~ RO;
    if (((state->s1 >> (6*cont)) & 0x3F) != (unsigned)subcharset) {
	for (j = 0; iso->escapes[i].sequence[j]; j++)
	    emit(emitctx, iso->escapes[i].sequence[j]);
	state->s1 &= iso->escapes[i].andbits;
	state->s1 ^= iso->escapes[i].xorbits;
    }

    /*
     * Now we know what container our subcharset is in, so we want
     * to select that container.
     */
    if (cont > 1) {
	/* SS2 or SS3; just output the sequence and be done. */
	emit(emitctx, ESC);
	emit(emitctx, 'L' + cont);     /* comes out to 'N' or 'O' */
    } else {
	/*
	 * Emit SI or SO, but only if the current container isn't already
	 * the right one.
	 * 
	 * Also, in an 8-bit subset, we need not do this; we'll
	 * just use 8-bit characters to output SO-container
	 * characters.
	 */
	if (iso->eightbit && cont == 1 && ((state->s1 >> 28) & 7) == 0) {
	    topbit = 0x80;
	} else if (((state->s1 >> 28) & 7) != (unsigned)cont) {
	    emit(emitctx, cont ? SO : SI);
	    state->s1 = (state->s1 & 0x8FFFFFFF) | (cont << 28);
	}
    }

    /*
     * We're done. Subcharset is selected in container, container
     * is selected. All we need now is to write out the bytes.
     */
    len = iso->nbytes[subcharset];
    while (len--)
	emit(emitctx, ((bytes >> (8*len)) & 0xFF) | topbit);

    return TRUE;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x70, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq %rdx, -0x20(%rbp)
movq %rcx, -0x28(%rbp)
movq %r8, -0x30(%rbp)
movq -0x10(%rbp), %rax
movq 0x18(%rax), %rax
movq %rax, -0x38(%rbp)
movl $0x0, -0x50(%rbp)
cmpq $0x0, -0x18(%rbp)
jl 0xa25d
movq -0x38(%rbp), %rax
movq 0x40(%rax), %rax
movq -0x18(%rbp), %rdi
leaq -0x3c(%rbp), %rsi
leaq -0x58(%rbp), %rdx
callq *%rax
cmpl $0x0, %eax
jne 0xa25d
movl $0x0, -0x4(%rbp)
jmp 0xa659
movq -0x20(%rbp), %rcx
movabsq $0x80000000, %rax       # imm = 0x80000000
andq 0x8(%rcx), %rax
cmpq $0x0, %rax
jne 0xa2d3
movq -0x38(%rbp), %rax
movq 0x20(%rax), %rcx
movq -0x20(%rbp), %rax
movq %rcx, 0x8(%rax)
movq -0x38(%rbp), %rax
cmpq $0x0, 0x28(%rax)
je 0xa2d1
movl $0x0, -0x44(%rbp)
movq -0x38(%rbp), %rax
movq 0x28(%rax), %rax
movslq -0x44(%rbp), %rcx
cmpb $0x0, (%rax,%rcx)
je 0xa2cf
movq -0x28(%rbp), %rax
movq -0x30(%rbp), %rdi
movq -0x38(%rbp), %rcx
movq 0x28(%rcx), %rcx
movslq -0x44(%rbp), %rdx
movsbq (%rcx,%rdx), %rsi
callq *%rax
movl -0x44(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x44(%rbp)
jmp 0xa297
jmp 0xa2d1
jmp 0xa2d3
cmpq $-0x1, -0x18(%rbp)
jne 0xa3e6
movl $0x0, -0x44(%rbp)
movq -0x38(%rbp), %rax
movq 0x18(%rax), %rax
movslq -0x44(%rbp), %rcx
cmpb $0x0, (%rax,%rcx)
je 0xa3da
movq -0x38(%rbp), %rax
movq 0x18(%rax), %rax
movslq -0x44(%rbp), %rcx
movsbl (%rax,%rcx), %eax
subl $0x1, %eax
movl %eax, -0x48(%rbp)
movq -0x20(%rbp), %rax
movq 0x8(%rax), %rax
movq %rax, -0x60(%rbp)
movq -0x38(%rbp), %rax
movq (%rax), %rax
movslq -0x48(%rbp), %rcx
shlq $0x5, %rcx
addq %rcx, %rax
movq 0x8(%rax), %rcx
movq -0x20(%rbp), %rax
andq 0x8(%rax), %rcx
movq %rcx, 0x8(%rax)
movq -0x38(%rbp), %rax
movq (%rax), %rax
movslq -0x48(%rbp), %rcx
shlq $0x5, %rcx
addq %rcx, %rax
movq 0x10(%rax), %rcx
movq -0x20(%rbp), %rax
xorq 0x8(%rax), %rcx
movq %rcx, 0x8(%rax)
movq -0x20(%rbp), %rax
movq 0x8(%rax), %rax
cmpq -0x60(%rbp), %rax
je 0xa3ca
movl $0x0, -0x64(%rbp)
movq -0x38(%rbp), %rax
movq (%rax), %rax
movslq -0x48(%rbp), %rcx
shlq $0x5, %rcx
addq %rcx, %rax
movq (%rax), %rax
movslq -0x64(%rbp), %rcx
cmpb $0x0, (%rax,%rcx)
je 0xa3c8
movq -0x28(%rbp), %rax
movq -0x30(%rbp), %rdi
movq -0x38(%rbp), %rcx
movq (%rcx), %rcx
movslq -0x48(%rbp), %rdx
shlq $0x5, %rdx
addq %rdx, %rcx
movq (%rcx), %rcx
movslq -0x64(%rbp), %rdx
movsbq (%rcx,%rdx), %rsi
callq *%rax
movl -0x64(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x64(%rbp)
jmp 0xa376
jmp 0xa3ca
jmp 0xa3cc
movl -0x44(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x44(%rbp)
jmp 0xa2e5
movl $0x1, -0x4(%rbp)
jmp 0xa659
movl $0x0, -0x44(%rbp)
movl -0x44(%rbp), %eax
movq -0x38(%rbp), %rcx
cmpl 0x8(%rcx), %eax
jge 0xa441
movq -0x38(%rbp), %rax
movq (%rax), %rax
movslq -0x44(%rbp), %rcx
shlq $0x5, %rcx
addq %rcx, %rax
movl 0x1c(%rax), %eax
cmpl -0x3c(%rbp), %eax
jne 0xa434
movq -0x38(%rbp), %rax
movq (%rax), %rax
movslq -0x44(%rbp), %rcx
shlq $0x5, %rcx
addq %rcx, %rax
movl 0x18(%rax), %eax
andl $0x80, %eax
cmpl $0x0, %eax
jne 0xa434
jmp 0xa441
jmp 0xa436
movl -0x44(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x44(%rbp)
jmp 0xa3ed
movl -0x44(%rbp), %eax
movq -0x38(%rbp), %rcx
cmpl 0x8(%rcx), %eax
jge 0xa44f
jmp 0xa46e
leaq 0x5493b(%rip), %rdi     # 0x5ed91
leaq 0x548c9(%rip), %rsi     # 0x5ed26
movl $0x187, %edx            # imm = 0x187
leaq 0x5493a(%rip), %rcx     # 0x5eda3
callq 0x6050
movq -0x38(%rbp), %rax
movq (%rax), %rax
movslq -0x44(%rbp), %rcx
shlq $0x5, %rcx
addq %rcx, %rax
movl 0x18(%rax), %eax
andl $0xffffff7f, %eax       # imm = 0xFFFFFF7F
movl %eax, -0x4c(%rbp)
movq -0x20(%rbp), %rax
movq 0x8(%rax), %rax
imull $0x6, -0x4c(%rbp), %ecx
movl %ecx, %ecx
shrq %cl, %rax
andq $0x3f, %rax
movl -0x3c(%rbp), %ecx
cmpq %rcx, %rax
je 0xa549
movl $0x0, -0x48(%rbp)
movq -0x38(%rbp), %rax
movq (%rax), %rax
movslq -0x44(%rbp), %rcx
shlq $0x5, %rcx
addq %rcx, %rax
movq (%rax), %rax
movslq -0x48(%rbp), %rcx
cmpb $0x0, (%rax,%rcx)
je 0xa505
movq -0x28(%rbp), %rax
movq -0x30(%rbp), %rdi
movq -0x38(%rbp), %rcx
movq (%rcx), %rcx
movslq -0x44(%rbp), %rdx
shlq $0x5, %rdx
addq %rdx, %rcx
movq (%rcx), %rcx
movslq -0x48(%rbp), %rdx
movsbq (%rcx,%rdx), %rsi
callq *%rax
movl -0x48(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x48(%rbp)
jmp 0xa4b3
movq -0x38(%rbp), %rax
movq (%rax), %rax
movslq -0x44(%rbp), %rcx
shlq $0x5, %rcx
addq %rcx, %rax
movq 0x8(%rax), %rcx
movq -0x20(%rbp), %rax
andq 0x8(%rax), %rcx
movq %rcx, 0x8(%rax)
movq -0x38(%rbp), %rax
movq (%rax), %rax
movslq -0x44(%rbp), %rcx
shlq $0x5, %rcx
addq %rcx, %rax
movq 0x10(%rax), %rcx
movq -0x20(%rbp), %rax
xorq 0x8(%rax), %rcx
movq %rcx, 0x8(%rax)
cmpl $0x1, -0x4c(%rbp)
jle 0xa576
movq -0x28(%rbp), %rax
movq -0x30(%rbp), %rdi
movl $0x1b, %esi
callq *%rax
movq -0x28(%rbp), %rax
movq -0x30(%rbp), %rdi
movl -0x4c(%rbp), %ecx
addl $0x4c, %ecx
movslq %ecx, %rsi
callq *%rax
jmp 0xa606
movq -0x38(%rbp), %rax
cmpl $0x0, 0x30(%rax)
je 0xa5a5
cmpl $0x1, -0x4c(%rbp)
jne 0xa5a5
movq -0x20(%rbp), %rax
movq 0x8(%rax), %rax
shrq $0x1c, %rax
andq $0x7, %rax
cmpq $0x0, %rax
jne 0xa5a5
movl $0x80, -0x50(%rbp)
jmp 0xa604
movq -0x20(%rbp), %rax
movq 0x8(%rax), %rax
shrq $0x1c, %rax
andq $0x7, %rax
movl -0x4c(%rbp), %ecx
cmpq %rcx, %rax
je 0xa602
movq -0x28(%rbp), %rax
movq -0x30(%rbp), %rdi
movl -0x4c(%rbp), %esi
movl $0xf, %ecx
movl $0xe, %edx
cmpl $0x0, %esi
cmovnel %edx, %ecx
movslq %ecx, %rsi
callq *%rax
movq -0x20(%rbp), %rax
movabsq $0x8fffffff, %rcx       # imm = 0x8FFFFFFF
andq 0x8(%rax), %rcx
movl -0x4c(%rbp), %eax
shll $0x1c, %eax
cltq
orq %rax, %rcx
movq -0x20(%rbp), %rax
movq %rcx, 0x8(%rax)
jmp 0xa604
jmp 0xa606
movq -0x38(%rbp), %rax
movq 0x10(%rax), %rax
movslq -0x3c(%rbp), %rcx
movsbl (%rax,%rcx), %eax
movl %eax, -0x40(%rbp)
movl -0x40(%rbp), %eax
movl %eax, %ecx
addl $-0x1, %ecx
movl %ecx, -0x40(%rbp)
cmpl $0x0, %eax
je 0xa652
movq -0x28(%rbp), %rax
movq -0x30(%rbp), %rdi
movq -0x58(%rbp), %rsi
movl -0x40(%rbp), %ecx
shll $0x3, %ecx
movl %ecx, %ecx
shrq %cl, %rsi
andq $0xff, %rsi
movslq -0x50(%rbp), %rcx
orq %rcx, %rsi
callq *%rax
jmp 0xa619
movl $0x1, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x70, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)