// File: /workspace/github_c_makefile_star2_O0/mloar[P]charset/shiftjis.c
// Function: read_sjis
static void read_sjis(charset_spec const *charset, long int input_chr,
		      charset_state *state,
		      void (*emit)(void *ctx, long int output), void *emitctx)
{
    UNUSEDARG(charset);

    /*
     * For reading Shift-JIS, state->s0 simply contains the single
     * stored lead byte when we are half way through a double-byte
     * character, or 0 if we aren't.
     */

    if (state->s0 == 0) {
	if ((input_chr >= 0x81 && input_chr <= 0x9F) ||
	    (input_chr >= 0xE0 && input_chr <= 0xEF)) {
	    /*
	     * Lead byte. Just store it.
	     */
	    state->s0 = input_chr;
	} else {
	    /*
	     * Anything else we translate through JIS X 0201.
	     */
	    if (input_chr == 0x5C)
		input_chr = 0xA5;
	    else if (input_chr == 0x7E)
		input_chr = 0x203E;
	    else if (input_chr >= 0xA1 && input_chr <= 0xDF)
		input_chr += 0xFF61 - 0xA1;
	    else if (input_chr < 0x80)
		/* do nothing */;
	    else
		input_chr = ERROR;
	    emit(emitctx, input_chr);
	}
    } else {
	/*
	 * We have a stored lead byte. We expect a valid followup
	 * byte.
	 */
	if (input_chr >= 0x40 && input_chr <= 0xFC && input_chr != 0x7F) {
	    int r, c;
	    r = state->s0;
	    if (r >= 0xE0) r -= (0xE0 - 0xA0);
	    r -= 0x81;
	    c = input_chr;
	    if (c > 0x7F) c--;
	    c -= 0x40;
	    r *= 2;
	    if (c >= 94)
		r++, c -= 94;
	    emit(emitctx, jisx0208_to_unicode(r, c));
	} else {
	    emit(emitctx, ERROR);
	}
	state->s0 = 0;
    }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x40, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq %rcx, -0x20(%rbp)
movq %r8, -0x28(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x8(%rbp)
movq -0x18(%rbp), %rax
cmpq $0x0, (%rax)
jne 0xb4aa
cmpq $0x81, -0x10(%rbp)
jl 0xb416
cmpq $0x9f, -0x10(%rbp)
jle 0xb42a
cmpq $0xe0, -0x10(%rbp)
jl 0xb437
cmpq $0xef, -0x10(%rbp)
jg 0xb437
movq -0x10(%rbp), %rcx
movq -0x18(%rbp), %rax
movq %rcx, (%rax)
jmp 0xb4a5
cmpq $0x5c, -0x10(%rbp)
jne 0xb448
movq $0xa5, -0x10(%rbp)
jmp 0xb497
cmpq $0x7e, -0x10(%rbp)
jne 0xb459
movq $0x203e, -0x10(%rbp)    # imm = 0x203E
jmp 0xb495
cmpq $0xa1, -0x10(%rbp)
jl 0xb47d
cmpq $0xdf, -0x10(%rbp)
jg 0xb47d
movq -0x10(%rbp), %rax
addq $0xfec0, %rax           # imm = 0xFEC0
movq %rax, -0x10(%rbp)
jmp 0xb493
cmpq $0x80, -0x10(%rbp)
jge 0xb489
jmp 0xb491
movq $0xffff, -0x10(%rbp)    # imm = 0xFFFF
jmp 0xb493
jmp 0xb495
jmp 0xb497
movq -0x20(%rbp), %rax
movq -0x28(%rbp), %rdi
movq -0x10(%rbp), %rsi
callq *%rax
jmp 0xb578
cmpq $0x40, -0x10(%rbp)
jl 0xb55e
cmpq $0xfc, -0x10(%rbp)
jg 0xb55e
cmpq $0x7f, -0x10(%rbp)
je 0xb55e
movq -0x18(%rbp), %rax
movq (%rax), %rax
movl %eax, -0x2c(%rbp)
cmpl $0xe0, -0x2c(%rbp)
jl 0xb4ea
movl -0x2c(%rbp), %eax
subl $0x40, %eax
movl %eax, -0x2c(%rbp)
movl -0x2c(%rbp), %eax
subl $0x81, %eax
movl %eax, -0x2c(%rbp)
movq -0x10(%rbp), %rax
movl %eax, -0x30(%rbp)
cmpl $0x7f, -0x30(%rbp)
jle 0xb50b
movl -0x30(%rbp), %eax
addl $-0x1, %eax
movl %eax, -0x30(%rbp)
movl -0x30(%rbp), %eax
subl $0x40, %eax
movl %eax, -0x30(%rbp)
movl -0x2c(%rbp), %eax
shll %eax
movl %eax, -0x2c(%rbp)
cmpl $0x5e, -0x30(%rbp)
jl 0xb534
movl -0x2c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x2c(%rbp)
movl -0x30(%rbp), %eax
subl $0x5e, %eax
movl %eax, -0x30(%rbp)
movq -0x20(%rbp), %rax
movq %rax, -0x38(%rbp)
movq -0x28(%rbp), %rax
movq %rax, -0x40(%rbp)
movl -0x2c(%rbp), %edi
movl -0x30(%rbp), %esi
callq 0xa8f0
movq -0x40(%rbp), %rdi
movq %rax, %rsi
movq -0x38(%rbp), %rax
callq *%rax
jmp 0xb56d
movq -0x20(%rbp), %rax
movq -0x28(%rbp), %rdi
movl $0xffff, %esi           # imm = 0xFFFF
callq *%rax
movq -0x18(%rbp), %rax
movq $0x0, (%rax)
addq $0x40, %rsp
popq %rbp
retq
nop