// File: /workspace/github_c_makefile_star2_O1/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 $0x668, %rsp            # imm = 0x668
xorps %xmm0, %xmm0
movaps %xmm0, 0x50(%rsp)
movaps %xmm0, 0x30(%rsp)
cmpl $0x3, %edi
jne 0x6410
movq %rsi, %r14
movq 0x8(%rsi), %rdi
callq 0x65b7
movl %eax, 0x1c(%rsp)
testl %eax, %eax
je 0x6417
movq 0x10(%r14), %rdi
callq 0x65b7
testl %eax, %eax
je 0x6425
movl %eax, %ebx
movq 0xa3d83(%rip), %rax     # 0xa9fd8
movq (%rax), %rcx
leaq 0x160(%rsp), %rdi
movl $0x1, %esi
movl $0x100, %edx            # imm = 0x100
callq 0x6030
testl %eax, %eax
jle 0x639a
leaq 0x260(%rsp), %r13
leaq 0x48(%rsp), %r15
leaq 0x24(%rsp), %r12
leaq 0x60(%rsp), %r14
leaq 0x30(%rsp), %rbp
movl %eax, 0x20(%rsp)
leaq 0x160(%rsp), %rax
movq %rax, 0x28(%rsp)
movl $0x0, 0x8(%rsp)
movq $0x0, (%rsp)
leaq 0x28(%rsp), %rdi
leaq 0x20(%rsp), %rsi
movq %r13, %rdx
movl $0x100, %ecx            # imm = 0x100
movl 0x1c(%rsp), %r8d
leaq 0x50(%rsp), %r9
callq 0x67a8
testl %eax, %eax
jle 0x6371
movl %eax, 0x24(%rsp)
movq %r13, 0x48(%rsp)
movq $0x0, (%rsp)
movq %r15, %rdi
movq %r12, %rsi
movq %r14, %rdx
movl $0x100, %ecx            # imm = 0x100
movl %ebx, %r8d
movq %rbp, %r9
callq 0x644c
testl %eax, %eax
movq 0xa3cc0(%rip), %r13     # 0xa9fd0
jle 0x634a
movl %eax, %edx
movq (%r13), %rcx
movl $0x1, %esi
movq %r14, %rdi
callq 0x6080
movq $0x0, (%rsp)
movq %r15, %rdi
movq %r12, %rsi
movq %r14, %rdx
movl $0x100, %ecx            # imm = 0x100
movl %ebx, %r8d
movq %rbp, %r9
callq 0x644c
testl %eax, %eax
jg 0x6312
movl $0x0, 0x8(%rsp)
movq $0x0, (%rsp)
leaq 0x28(%rsp), %rdi
leaq 0x20(%rsp), %rsi
leaq 0x260(%rsp), %r13
jmp 0x62be
movq 0xa3c60(%rip), %rax     # 0xa9fd8
movq (%rax), %rcx
movl $0x1, %esi
movl $0x100, %edx            # imm = 0x100
leaq 0x160(%rsp), %rdi
callq 0x6030
testl %eax, %eax
jg 0x6293
movq $0x0, (%rsp)
xorl %r14d, %r14d
leaq 0x60(%rsp), %rdx
leaq 0x30(%rsp), %r9
xorl %edi, %edi
xorl %esi, %esi
movl $0x100, %ecx            # imm = 0x100
movl %ebx, %r8d
callq 0x644c
testl %eax, %eax
jle 0x6437
movq 0xa3c05(%rip), %r13     # 0xa9fd0
leaq 0x60(%rsp), %r15
leaq 0x30(%rsp), %r12
movl %eax, %edx
movq (%r13), %rcx
movl $0x1, %esi
movq %r15, %rdi
callq 0x6080
movq $0x0, (%rsp)
xorl %r14d, %r14d
xorl %edi, %edi
xorl %esi, %esi
movq %r15, %rdx
movl $0x100, %ecx            # imm = 0x100
movl %ebx, %r8d
movq %r12, %r9
callq 0x644c
testl %eax, %eax
jg 0x63d5
jmp 0x6437
callq 0x60b0
jmp 0x6431
addq $0x8, %r14
movq %r14, %rdi
callq 0x60ea
jmp 0x6431
addq $0x10, %r14
movq %r14, %rdi
callq 0x60cc
movl $0x1, %r14d
movl %r14d, %eax
addq $0x668, %rsp            # imm = 0x668
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq