// File: /workspace/github_c_makefile_star2_O2/mloar[P]charset/test.c
// Function: main
int main(int argc, char **argv)
{
    int srcset, dstset;
    charset_state instate = CHARSET_INIT_STATE;
    charset_state outstate = CHARSET_INIT_STATE;
    char inbuf[256], outbuf[256];
    wchar_t midbuf[256];
    const char *inptr;
    const wchar_t *midptr;
    int rdret, inlen, midlen, inret, midret;

    if (argc != 3) {
	fprintf(stderr, "usage: convcs <charset> <charset>\n");
	return 1;
    }

    srcset = charset_from_localenc(argv[1]);
    if (srcset == CS_NONE) {
	fprintf(stderr, "unknown source charset '%s'\n", argv[1]);
	return 1;
    }

    dstset = charset_from_localenc(argv[2]);
    if (dstset == CS_NONE) {
	fprintf(stderr, "unknown destination charset '%s'\n", argv[2]);
	return 1;
    }

    while (1) {

	rdret = fread(inbuf, 1, sizeof(inbuf), stdin);

	if (rdret <= 0)
	    break;		       /* EOF */

	inlen = rdret;
	inptr = inbuf;
	while ( (inret = charset_to_unicode(&inptr, &inlen, midbuf,
					    lenof(midbuf), srcset,
					    &instate, NULL, 0)) > 0) {
	    midlen = inret;
	    midptr = midbuf;
	    while ( (midret = charset_from_unicode(&midptr, &midlen, outbuf,
						   lenof(outbuf), dstset,
						   &outstate, NULL)) > 0) {
		fwrite(outbuf, 1, midret, stdout);
	    }
	}
    }

    /*
     * Reset encoding state.
     */
    while ( (midret = charset_from_unicode(NULL, NULL, outbuf,
					   lenof(outbuf), dstset,
					   &outstate, NULL)) > 0) {
	fwrite(outbuf, 1, midret, stdout);
    }

    return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x658, %rsp            # imm = 0x658
xorps %xmm0, %xmm0
movaps %xmm0, 0x40(%rsp)
movaps %xmm0, 0x30(%rsp)
cmpl $0x3, %edi
jne 0x6308
movq %rsi, %r14
movq 0x8(%rsi), %rdi
callq 0x64af
movl %eax, 0x14(%rsp)
testl %eax, %eax
je 0x6326
movq 0x10(%r14), %rdi
callq 0x64af
testl %eax, %eax
je 0x633d
movl %eax, %ebx
pushq $0x1
popq %r15
leaq 0x20(%rsp), %r13
leaq 0x18(%rsp), %r12
leaq 0x50(%rsp), %rbp
leaq 0x30(%rsp), %r14
movq 0xa2dcb(%rip), %rax     # 0xa8fd8
movq (%rax), %rcx
movl $0x100, %edx            # imm = 0x100
leaq 0x150(%rsp), %rdi
movq %r15, %rsi
callq 0x6030
testl %eax, %eax
jle 0x62be
movl %eax, 0x1c(%rsp)
leaq 0x150(%rsp), %rax
movq %rax, 0x28(%rsp)
andl $0x0, 0x8(%rsp)
andq $0x0, (%rsp)
leaq 0x28(%rsp), %rdi
leaq 0x1c(%rsp), %rsi
leaq 0x250(%rsp), %rdx
movl $0x100, %ecx            # imm = 0x100
movl 0x14(%rsp), %r8d
leaq 0x40(%rsp), %r9
callq 0x6674
testl %eax, %eax
jle 0x6206
movl %eax, 0x18(%rsp)
leaq 0x250(%rsp), %rax
movq %rax, 0x20(%rsp)
andq $0x0, (%rsp)
movq %r13, %rdi
movq %r12, %rsi
movq %rbp, %rdx
movl $0x100, %ecx            # imm = 0x100
movl %ebx, %r8d
movq %r14, %r9
callq 0x6374
testl %eax, %eax
jle 0x623e
movl %eax, %edx
movq 0xa2d22(%rip), %rax     # 0xa8fd0
movq (%rax), %rcx
movq %rbp, %rdi
movq %r15, %rsi
callq 0x6080
jmp 0x6283
leaq 0x50(%rsp), %r14
leaq 0x30(%rsp), %r15
pushq $0x1
popq %r12
andq $0x0, (%rsp)
xorl %r13d, %r13d
xorl %edi, %edi
xorl %esi, %esi
movq %r14, %rdx
movl $0x100, %ecx            # imm = 0x100
movl %ebx, %r8d
movq %r15, %r9
callq 0x6374
testl %eax, %eax
jle 0x635d
movl %eax, %edx
movq 0xa2cd8(%rip), %rax     # 0xa8fd0
movq (%rax), %rcx
movq %r14, %rdi
movq %r12, %rsi
callq 0x6080
jmp 0x62cc
movq 0xa2ce9(%rip), %rax     # 0xa8ff8
movq (%rax), %rcx
leaq 0x3ceb(%rip), %rdi      # 0xa004
pushq $0x22
popq %rsi
pushq $0x1
popq %rdx
callq 0x6080
jmp 0x6359
movq 0xa2ccb(%rip), %rax     # 0xa8ff8
movq (%rax), %rdi
movq 0x8(%r14), %rdx
leaq 0x3cec(%rip), %rsi      # 0xa027
jmp 0x6352
movq 0xa2cb4(%rip), %rax     # 0xa8ff8
movq (%rax), %rdi
movq 0x10(%r14), %rdx
leaq 0x3cf2(%rip), %rsi      # 0xa044
xorl %eax, %eax
callq 0x6060
pushq $0x1
popq %r13
movl %r13d, %eax
addq $0x658, %rsp            # imm = 0x658
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nop