// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x680, %rsp            # imm = 0x680
movl $0x0, -0x4(%rbp)
movl %edi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
leaq -0x28(%rbp), %rdi
xorl %esi, %esi
movl $0x10, %edx
callq 0x6060
leaq -0x38(%rbp), %rdi
xorl %esi, %esi
movl $0x10, %edx
callq 0x6060
cmpl $0x3, -0x8(%rbp)
je 0x6213
movq 0xa4e02(%rip), %rax     # 0xaaff8
movq (%rax), %rdi
leaq 0x6e04(%rip), %rsi      # 0xd004
movb $0x0, %al
callq 0x6080
movl $0x1, -0x4(%rbp)
jmp 0x6411
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rdi
callq 0x66a0
movl %eax, -0x14(%rbp)
cmpl $0x0, -0x14(%rbp)
jne 0x6255
movq 0xa4dc8(%rip), %rax     # 0xaaff8
movq (%rax), %rdi
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rdx
leaq 0x6de5(%rip), %rsi      # 0xd027
movb $0x0, %al
callq 0x6080
movl $0x1, -0x4(%rbp)
jmp 0x6411
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rdi
callq 0x66a0
movl %eax, -0x18(%rbp)
cmpl $0x0, -0x18(%rbp)
jne 0x6297
movq 0xa4d86(%rip), %rax     # 0xaaff8
movq (%rax), %rdi
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rdx
leaq 0x6dc0(%rip), %rsi      # 0xd044
movb $0x0, %al
callq 0x6080
movl $0x1, -0x4(%rbp)
jmp 0x6411
jmp 0x6299
leaq -0x140(%rbp), %rdi
movq 0xa4d31(%rip), %rax     # 0xaafd8
movq (%rax), %rcx
movl $0x1, %esi
movl $0x100, %edx            # imm = 0x100
callq 0x6030
movl %eax, -0x654(%rbp)
cmpl $0x0, -0x654(%rbp)
jg 0x62cd
jmp 0x63b1
movl -0x654(%rbp), %eax
movl %eax, -0x658(%rbp)
leaq -0x140(%rbp), %rax
movq %rax, -0x648(%rbp)
leaq -0x640(%rbp), %rdx
movl -0x14(%rbp), %r8d
leaq -0x648(%rbp), %rdi
leaq -0x658(%rbp), %rsi
movl $0x100, %ecx            # imm = 0x100
leaq -0x28(%rbp), %r9
xorl %eax, %eax
xorl %eax, %eax
movq $0x0, (%rsp)
movl $0x0, 0x8(%rsp)
callq 0x6a60
movl %eax, -0x660(%rbp)
cmpl $0x0, %eax
jle 0x63ac
movl -0x660(%rbp), %eax
movl %eax, -0x65c(%rbp)
leaq -0x640(%rbp), %rax
movq %rax, -0x650(%rbp)
leaq -0x240(%rbp), %rdx
movl -0x18(%rbp), %r8d
leaq -0x650(%rbp), %rdi
leaq -0x65c(%rbp), %rsi
movl $0x100, %ecx            # imm = 0x100
leaq -0x38(%rbp), %r9
xorl %eax, %eax
movq $0x0, (%rsp)
callq 0x6420
movl %eax, -0x664(%rbp)
cmpl $0x0, %eax
jle 0x63a7
leaq -0x240(%rbp), %rdi
movslq -0x664(%rbp), %rdx
movq 0xa4c38(%rip), %rax     # 0xaafd0
movq (%rax), %rcx
movl $0x1, %esi
callq 0x60a0
jmp 0x6347
jmp 0x62e7
jmp 0x6299
jmp 0x63b3
leaq -0x240(%rbp), %rdx
movl -0x18(%rbp), %r8d
xorl %eax, %eax
movl %eax, %esi
movl $0x100, %ecx            # imm = 0x100
leaq -0x38(%rbp), %r9
movq %rsi, %rdi
movq $0x0, (%rsp)
callq 0x6420
movl %eax, -0x664(%rbp)
cmpl $0x0, %eax
jle 0x640a
leaq -0x240(%rbp), %rdi
movslq -0x664(%rbp), %rdx
movq 0xa4bd5(%rip), %rax     # 0xaafd0
movq (%rax), %rcx
movl $0x1, %esi
callq 0x60a0
jmp 0x63b3
movl $0x0, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x680, %rsp            # imm = 0x680
popq %rbp
retq
nopl (%rax)