// File: /workspace/github_c_makefile_star2_O0/jsummers[P]deark/src/deark-ucstring.c
// Function: append_bytes_cp932
static void append_bytes_cp932(deark *c, de_ucstring *s,
	const u8 *cbuf, i64 buflen,
	UI conv_flags, struct de_encconv_state *es)
{
	i64 pos = 0;

	for(pos=0; pos<buflen; pos++) {
		u8 n = cbuf[pos];
		de_rune ch1, ch2;

		if(CP932_NBYTES_SAVED>0) {
			u16 tmpch;
			int nrunes;

			tmpch = (u16)es->buf[0]<<8;
			tmpch |= n;
			nrunes = de_cp932_lookup(c, tmpch, 0, &ch1, &ch2);
			if(nrunes==0 || ch1==0) {
				ch1 = 0xfffd;
			}
			ucstring_append_char(s, ch1);
			if(nrunes==2) {
				ucstring_append_char(s, ch2);
			}
			CP932_NBYTES_SAVED = 0;
		}
		else if((n>=0x81 && n<=0x9f) ||
			(n>=0xe0 && n<=0xfc))
		{
			es->buf[0] = n;
			CP932_NBYTES_SAVED = 1;
		}
		else {
			if(n<=0x7f || (n>=0xa1 && n<=0xdf)) {
				(void)de_cp932_lookup(c, (u16)n, 0, &ch1, &ch2);
			}
			else {
				ch1 = 0xfffd;
			}
			ucstring_append_char(s, ch1);
		}
	}

	// Deal with unprocessed bytes at the end of the string.
	if(CP932_NBYTES_SAVED!=0 && !(conv_flags & DE_CONVFLAG_PARTIAL_DATA)) {
		handle_invalid_bytes(s, es->buf, (UI)CP932_NBYTES_SAVED);
		CP932_NBYTES_SAVED = 0;
	}
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x50, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq %rcx, -0x20(%rbp)
movl %r8d, -0x24(%rbp)
movq %r9, -0x30(%rbp)
movq $0x0, -0x38(%rbp)
movq $0x0, -0x38(%rbp)
movq -0x38(%rbp), %rax
cmpq -0x20(%rbp), %rax
jge 0x171f24
movq -0x18(%rbp), %rax
movq -0x38(%rbp), %rcx
movb (%rax,%rcx), %al
movb %al, -0x39(%rbp)
movq -0x30(%rbp), %rax
movzbl 0x1e(%rax), %eax
cmpl $0x0, %eax
jle 0x171e81
movq -0x30(%rbp), %rax
movzbl 0x18(%rax), %eax
movzwl %ax, %eax
shll $0x8, %eax
movw %ax, -0x46(%rbp)
movzbl -0x39(%rbp), %ecx
movzwl -0x46(%rbp), %eax
orl %ecx, %eax
movw %ax, -0x46(%rbp)
movq -0x8(%rbp), %rdi
xorl %edx, %edx
leaq -0x40(%rbp), %rcx
leaq -0x44(%rbp), %r8
movzwl -0x46(%rbp), %esi
callq 0x19a7d0
movl %eax, -0x4c(%rbp)
cmpl $0x0, -0x4c(%rbp)
je 0x171e4f
cmpl $0x0, -0x40(%rbp)
jne 0x171e56
movl $0xfffd, -0x40(%rbp)    # imm = 0xFFFD
movq -0x10(%rbp), %rdi
movl -0x40(%rbp), %esi
callq 0x1714c0
cmpl $0x2, -0x4c(%rbp)
jne 0x171e74
movq -0x10(%rbp), %rdi
movl -0x44(%rbp), %esi
callq 0x1714c0
movq -0x30(%rbp), %rax
movb $0x0, 0x1e(%rax)
jmp 0x171f11
movzbl -0x39(%rbp), %eax
cmpl $0x81, %eax
jl 0x171e97
movzbl -0x39(%rbp), %eax
cmpl $0x9f, %eax
jle 0x171ead
movzbl -0x39(%rbp), %eax
cmpl $0xe0, %eax
jl 0x171ec1
movzbl -0x39(%rbp), %eax
cmpl $0xfc, %eax
jg 0x171ec1
movb -0x39(%rbp), %cl
movq -0x30(%rbp), %rax
movb %cl, 0x18(%rax)
movq -0x30(%rbp), %rax
movb $0x1, 0x1e(%rax)
jmp 0x171f0f
movzbl -0x39(%rbp), %eax
cmpl $0x7f, %eax
jle 0x171ee0
movzbl -0x39(%rbp), %eax
cmpl $0xa1, %eax
jl 0x171efc
movzbl -0x39(%rbp), %eax
cmpl $0xdf, %eax
jg 0x171efc
movq -0x8(%rbp), %rdi
movzbl -0x39(%rbp), %eax
xorl %edx, %edx
leaq -0x40(%rbp), %rcx
leaq -0x44(%rbp), %r8
movzwl %ax, %esi
callq 0x19a7d0
jmp 0x171f03
movl $0xfffd, -0x40(%rbp)    # imm = 0xFFFD
movq -0x10(%rbp), %rdi
movl -0x40(%rbp), %esi
callq 0x1714c0
jmp 0x171f11
jmp 0x171f13
movq -0x38(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x38(%rbp)
jmp 0x171de0
movq -0x30(%rbp), %rax
movzbl 0x1e(%rax), %eax
cmpl $0x0, %eax
je 0x171f5d
movl -0x24(%rbp), %eax
andl $0x40, %eax
cmpl $0x0, %eax
jne 0x171f5d
movq -0x10(%rbp), %rdi
movq -0x30(%rbp), %rsi
addq $0x18, %rsi
movq -0x30(%rbp), %rax
movzbl 0x1e(%rax), %edx
callq 0x172c10
movq -0x30(%rbp), %rax
movb $0x0, 0x1e(%rax)
addq $0x50, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)