// File: /workspace/github_c_makefile_star2_O0/mloar[P]charset/confuse.c
// Function: main
int main(int argc, char **argv)
{
    wchar_t *chars;
    struct enc { char string[MAXENCLEN]; int len; } *encodings;
    int nchars;
    int i, j, k, cs;
    const char *sep;

    setlocale(LC_ALL, "");

    chars = malloc(argc * sizeof(wchar_t));
    if (!chars) {
        fprintf(stderr, "out of memory\n");
        return 1;
    }

    nchars = 0;

    while (--argc) {
        char *p = *++argv;
        char *orig = p;
        char *end;
        int base = 16, semi_ok = 0;
        wchar_t ch;

        if ((p[0] == 'U' || p[0] == 'u') &&
            (p[1] == '-' || p[1] == '+')) {
            p += 2;
        } else if (p[0] == '0' && (p[1] == 'x' || p[1] == 'X')) {
            p += 2;
        } else if (p[0] == '&' && p[1] == '#') {
            p += 2;
            if (p[0] == 'x' || p[0] == 'X')
                p++;
            else
                base = 10;
            semi_ok = 1;
        } else if (mbtowc(&ch, p, strlen(p)) == strlen(p)) {
            chars[nchars++] = ch;
            continue;
        }

        chars[nchars++] = strtoul(p, &end, base);
        if (!*end || (semi_ok && !strcmp(end, ";")))
            continue;
        else {
            fprintf(stderr, "unable to parse '%s' as a Unicode code point\n",
                    orig);
            return 1;
        }
    }

    encodings = malloc(nchars * CS_LIMIT * sizeof(struct enc));
    for (cs = 0; cs < CS_LIMIT; cs++) {
        for (i = 0; i < nchars; i++) {
            wchar_t inbuf[1];
            const wchar_t *inptr;
            int inlen, error, ret;

            if (!charset_exists(cs)) {
                encodings[i*CS_LIMIT+cs].len = 0;
                continue;
            }

            inbuf[0] = chars[i];
            inptr = inbuf;
            inlen = 1;
            error = 0;
            ret = charset_from_unicode(&inptr, &inlen,
                                       encodings[i*CS_LIMIT+cs].string,
                                       MAXENCLEN, cs, NULL, &error);
            if (error || inlen > 0)
                encodings[i*CS_LIMIT+cs].len = 0;
            else
                encodings[i*CS_LIMIT+cs].len = ret;
        }
    }

    /*
     * Really simple and slow approach to finding each distinct string
     * and outputting it.
     */
    for (i = 0; i < nchars*CS_LIMIT; i++) {
        const char *thisstr = encodings[i].string;
        int thislen = encodings[i].len;

        if (thislen == 0)
            continue;
        for (j = 0; j < i; j++)
            if (encodings[j].len == thislen &&
                !memcmp(encodings[j].string, thisstr, thislen))
                break;
        if (j < i)
            continue;        /* not the first instance of this encoding */

        /*
         * See if every character is encoded like this somewhere.
         */
        for (j = 0; j < nchars; j++) {
            for (cs = 0; cs < CS_LIMIT; cs++) {
                if (encodings[j*CS_LIMIT+cs].len == thislen &&
                    !memcmp(encodings[j*CS_LIMIT+cs].string, thisstr, thislen))
                    break;
            }
            if (cs == CS_LIMIT)
                break;                 /* this char not in any cs */
        }
        if (j < nchars)
            continue;                  /* some char not in any cs */

        /*
         * Match! Print the encoding, then all charsets.
         */
        for (j = 0; j < nchars; j++) {
            for (k = 0; k < thislen; k++)
                printf("%s%02X", k>0?" ":"", (unsigned)(thisstr[k] & 0xFF));
            printf(" = ");
            if (chars[j] >= 0x10000)
                printf("U-%08X", (unsigned)chars[j]);
            else
                printf("U+%04X", (unsigned)chars[j]);
            printf(" in:");
            sep = " ";
            for (cs = 0; cs < CS_LIMIT; cs++)
                if (encodings[j*CS_LIMIT+cs].len == thislen &&
                    !memcmp(encodings[j*CS_LIMIT+cs].string, thisstr, thislen))
                {
                    printf("%s%s", sep, charset_to_localenc(cs));
                    sep = ", ";
                }
            printf("\n");
        }
        printf("\n");
    }

    return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xb0, %rsp
movl $0x0, -0x4(%rbp)
movl %edi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movl $0x6, %edi
leaq 0x20b91(%rip), %rsi     # 0x26da6
callq 0x60d0
movslq -0x8(%rbp), %rdi
shlq $0x2, %rdi
callq 0x60c0
movq %rax, -0x18(%rbp)
cmpq $0x0, -0x18(%rbp)
jne 0x6256
movq 0xa5dbf(%rip), %rax     # 0xabff8
movq (%rax), %rdi
leaq 0x7dc1(%rip), %rsi      # 0xe004
movb $0x0, %al
callq 0x6090
movl $0x1, -0x4(%rbp)
jmp 0x6893
movl $0x0, -0x24(%rbp)
movl -0x8(%rbp), %eax
addl $-0x1, %eax
movl %eax, -0x8(%rbp)
cmpl $0x0, %eax
je 0x6454
movq -0x10(%rbp), %rax
movq %rax, %rcx
addq $0x8, %rcx
movq %rcx, -0x10(%rbp)
movq 0x8(%rax), %rax
movq %rax, -0x48(%rbp)
movq -0x48(%rbp), %rax
movq %rax, -0x50(%rbp)
movl $0x10, -0x5c(%rbp)
movl $0x0, -0x60(%rbp)
movq -0x48(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x55, %eax
je 0x62b4
movq -0x48(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x75, %eax
jne 0x62df
movq -0x48(%rbp), %rax
movsbl 0x1(%rax), %eax
cmpl $0x2d, %eax
je 0x62ce
movq -0x48(%rbp), %rax
movsbl 0x1(%rax), %eax
cmpl $0x2b, %eax
jne 0x62df
movq -0x48(%rbp), %rax
addq $0x2, %rax
movq %rax, -0x48(%rbp)
jmp 0x63dc
movq -0x48(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x30, %eax
jne 0x6316
movq -0x48(%rbp), %rax
movsbl 0x1(%rax), %eax
cmpl $0x78, %eax
je 0x6305
movq -0x48(%rbp), %rax
movsbl 0x1(%rax), %eax
cmpl $0x58, %eax
jne 0x6316
movq -0x48(%rbp), %rax
addq $0x2, %rax
movq %rax, -0x48(%rbp)
jmp 0x63da
movq -0x48(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x26, %eax
jne 0x6371
movq -0x48(%rbp), %rax
movsbl 0x1(%rax), %eax
cmpl $0x23, %eax
jne 0x6371
movq -0x48(%rbp), %rax
addq $0x2, %rax
movq %rax, -0x48(%rbp)
movq -0x48(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x78, %eax
je 0x6353
movq -0x48(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x58, %eax
jne 0x6361
movq -0x48(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x48(%rbp)
jmp 0x6368
movl $0xa, -0x5c(%rbp)
movl $0x1, -0x60(%rbp)
jmp 0x63d8
movq -0x48(%rbp), %rax
movq %rax, -0xa0(%rbp)
movq -0x48(%rbp), %rdi
callq 0x6030
movq -0xa0(%rbp), %rsi
movq %rax, %rdx
leaq -0x64(%rbp), %rdi
callq 0x60a0
cltq
movq %rax, -0x98(%rbp)
movq -0x48(%rbp), %rdi
callq 0x6030
movq %rax, %rcx
movq -0x98(%rbp), %rax
cmpq %rcx, %rax
jne 0x63d6
movl -0x64(%rbp), %edx
movq -0x18(%rbp), %rax
movl -0x24(%rbp), %ecx
movl %ecx, %esi
addl $0x1, %esi
movl %esi, -0x24(%rbp)
movslq %ecx, %rcx
movl %edx, (%rax,%rcx,4)
jmp 0x625d
jmp 0x63d8
jmp 0x63da
jmp 0x63dc
movq -0x48(%rbp), %rdi
movl -0x5c(%rbp), %edx
leaq -0x58(%rbp), %rsi
callq 0x60e0
movl %eax, %edx
movq -0x18(%rbp), %rax
movl -0x24(%rbp), %ecx
movl %ecx, %esi
addl $0x1, %esi
movl %esi, -0x24(%rbp)
movslq %ecx, %rcx
movl %edx, (%rax,%rcx,4)
movq -0x58(%rbp), %rax
cmpb $0x0, (%rax)
je 0x6427
cmpl $0x0, -0x60(%rbp)
je 0x642c
movq -0x58(%rbp), %rdi
leaq 0x7bf6(%rip), %rsi      # 0xe013
callq 0x6080
cmpl $0x0, %eax
jne 0x642c
jmp 0x625d
movq 0xa5bc5(%rip), %rax     # 0xabff8
movq (%rax), %rdi
movq -0x50(%rbp), %rdx
leaq 0x7bd4(%rip), %rsi      # 0xe015
movb $0x0, %al
callq 0x6090
movl $0x1, -0x4(%rbp)
jmp 0x6893
imull $0x51, -0x24(%rbp), %eax
cltq
imulq $0x18, %rax, %rdi
callq 0x60c0
movq %rax, -0x20(%rbp)
movl $0x0, -0x34(%rbp)
cmpl $0x51, -0x34(%rbp)
jge 0x657c
movl $0x0, -0x28(%rbp)
movl -0x28(%rbp), %eax
cmpl -0x24(%rbp), %eax
jge 0x656c
movl -0x34(%rbp), %edi
callq 0x6eb0
cmpl $0x0, %eax
jne 0x64b9
movq -0x20(%rbp), %rax
imull $0x51, -0x28(%rbp), %ecx
addl -0x34(%rbp), %ecx
movslq %ecx, %rcx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movl $0x0, 0x14(%rax)
jmp 0x655e
movq -0x18(%rbp), %rax
movslq -0x28(%rbp), %rcx
movl (%rax,%rcx,4), %eax
movl %eax, -0x68(%rbp)
leaq -0x68(%rbp), %rax
movq %rax, -0x70(%rbp)
movl $0x1, -0x74(%rbp)
movl $0x0, -0x78(%rbp)
movq -0x20(%rbp), %rdx
imull $0x51, -0x28(%rbp), %eax
addl -0x34(%rbp), %eax
cltq
imulq $0x18, %rax, %rax
addq %rax, %rdx
movl -0x34(%rbp), %r8d
leaq -0x70(%rbp), %rdi
leaq -0x74(%rbp), %rsi
movl $0x14, %ecx
xorl %eax, %eax
movl %eax, %r9d
leaq -0x78(%rbp), %rax
movq %rax, (%rsp)
callq 0x68a0
movl %eax, -0x7c(%rbp)
cmpl $0x0, -0x78(%rbp)
jne 0x6523
cmpl $0x0, -0x74(%rbp)
jle 0x6541
movq -0x20(%rbp), %rax
imull $0x51, -0x28(%rbp), %ecx
addl -0x34(%rbp), %ecx
movslq %ecx, %rcx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movl $0x0, 0x14(%rax)
jmp 0x655c
movl -0x7c(%rbp), %ecx
movq -0x20(%rbp), %rax
imull $0x51, -0x28(%rbp), %edx
addl -0x34(%rbp), %edx
movslq %edx, %rdx
imulq $0x18, %rdx, %rdx
addq %rdx, %rax
movl %ecx, 0x14(%rax)
jmp 0x655e
movl -0x28(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x28(%rbp)
jmp 0x647f
jmp 0x656e
movl -0x34(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x34(%rbp)
jmp 0x646e
movl $0x0, -0x28(%rbp)
movl -0x28(%rbp), %eax
imull $0x51, -0x24(%rbp), %ecx
cmpl %ecx, %eax
jge 0x688c
movq -0x20(%rbp), %rax
movslq -0x28(%rbp), %rcx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movq %rax, -0x88(%rbp)
movq -0x20(%rbp), %rax
movslq -0x28(%rbp), %rcx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movl 0x14(%rax), %eax
movl %eax, -0x8c(%rbp)
cmpl $0x0, -0x8c(%rbp)
jne 0x65ce
jmp 0x687e
movl $0x0, -0x2c(%rbp)
movl -0x2c(%rbp), %eax
cmpl -0x28(%rbp), %eax
jge 0x662d
movq -0x20(%rbp), %rax
movslq -0x2c(%rbp), %rcx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movl 0x14(%rax), %eax
cmpl -0x8c(%rbp), %eax
jne 0x6620
movq -0x20(%rbp), %rdi
movslq -0x2c(%rbp), %rax
imulq $0x18, %rax, %rax
addq %rax, %rdi
movq -0x88(%rbp), %rsi
movslq -0x8c(%rbp), %rdx
callq 0x6070
cmpl $0x0, %eax
jne 0x6620
jmp 0x662d
jmp 0x6622
movl -0x2c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x2c(%rbp)
jmp 0x65d5
movl -0x2c(%rbp), %eax
cmpl -0x28(%rbp), %eax
jge 0x663a
jmp 0x687e
movl $0x0, -0x2c(%rbp)
movl -0x2c(%rbp), %eax
cmpl -0x24(%rbp), %eax
jge 0x66cd
movl $0x0, -0x34(%rbp)
cmpl $0x51, -0x34(%rbp)
jge 0x66b5
movq -0x20(%rbp), %rax
imull $0x51, -0x2c(%rbp), %ecx
addl -0x34(%rbp), %ecx
movslq %ecx, %rcx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movl 0x14(%rax), %eax
cmpl -0x8c(%rbp), %eax
jne 0x66a8
movq -0x20(%rbp), %rdi
imull $0x51, -0x2c(%rbp), %eax
addl -0x34(%rbp), %eax
cltq
imulq $0x18, %rax, %rax
addq %rax, %rdi
movq -0x88(%rbp), %rsi
movslq -0x8c(%rbp), %rdx
callq 0x6070
cmpl $0x0, %eax
jne 0x66a8
jmp 0x66b5
jmp 0x66aa
movl -0x34(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x34(%rbp)
jmp 0x6654
cmpl $0x51, -0x34(%rbp)
jne 0x66bd
jmp 0x66cd
jmp 0x66bf
movl -0x2c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x2c(%rbp)
jmp 0x6641
movl -0x2c(%rbp), %eax
cmpl -0x24(%rbp), %eax
jge 0x66da
jmp 0x687e
movl $0x0, -0x2c(%rbp)
movl -0x2c(%rbp), %eax
cmpl -0x24(%rbp), %eax
jge 0x6870
movl $0x0, -0x30(%rbp)
movl -0x30(%rbp), %eax
cmpl -0x8c(%rbp), %eax
jge 0x6745
movl -0x30(%rbp), %ecx
leaq 0x2069d(%rip), %rsi     # 0x26da6
leaq 0x7957(%rip), %rax      # 0xe067
cmpl $0x0, %ecx
cmovgq %rax, %rsi
movq -0x88(%rbp), %rax
movslq -0x30(%rbp), %rcx
movsbl (%rax,%rcx), %edx
andl $0xff, %edx
leaq 0x7910(%rip), %rdi      # 0xe043
movb $0x0, %al
callq 0x6040
movl -0x30(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x30(%rbp)
jmp 0x66f4
leaq 0x78fe(%rip), %rdi      # 0xe04a
movb $0x0, %al
callq 0x6040
movq -0x18(%rbp), %rax
movslq -0x2c(%rbp), %rcx
cmpl $0x10000, (%rax,%rcx,4) # imm = 0x10000
jl 0x677f
movq -0x18(%rbp), %rax
movslq -0x2c(%rbp), %rcx
movl (%rax,%rcx,4), %esi
leaq 0x78d8(%rip), %rdi      # 0xe04e
movb $0x0, %al
callq 0x6040
jmp 0x6798
movq -0x18(%rbp), %rax
movslq -0x2c(%rbp), %rcx
movl (%rax,%rcx,4), %esi
leaq 0x78c4(%rip), %rdi      # 0xe055
movb $0x0, %al
callq 0x6040
leaq 0x78bd(%rip), %rdi      # 0xe05c
movb $0x0, %al
callq 0x6040
leaq 0x78ba(%rip), %rax      # 0xe067
movq %rax, -0x40(%rbp)
movl $0x0, -0x34(%rbp)
cmpl $0x51, -0x34(%rbp)
jge 0x6854
movq -0x20(%rbp), %rax
imull $0x51, -0x2c(%rbp), %ecx
addl -0x34(%rbp), %ecx
movslq %ecx, %rcx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movl 0x14(%rax), %eax
cmpl -0x8c(%rbp), %eax
jne 0x6844
movq -0x20(%rbp), %rdi
imull $0x51, -0x2c(%rbp), %eax
addl -0x34(%rbp), %eax
cltq
imulq $0x18, %rax, %rax
addq %rax, %rdi
movq -0x88(%rbp), %rsi
movslq -0x8c(%rbp), %rdx
callq 0x6070
cmpl $0x0, %eax
jne 0x6844
movq -0x40(%rbp), %rax
movq %rax, -0xa8(%rbp)
movl -0x34(%rbp), %edi
callq 0x6ab0
movq -0xa8(%rbp), %rsi
movq %rax, %rdx
leaq 0x782f(%rip), %rdi      # 0xe061
movb $0x0, %al
callq 0x6040
leaq 0x7826(%rip), %rax      # 0xe066
movq %rax, -0x40(%rbp)
jmp 0x6846
movl -0x34(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x34(%rbp)
jmp 0x67b8
leaq 0x77e6(%rip), %rdi      # 0xe041
movb $0x0, %al
callq 0x6040
movl -0x2c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x2c(%rbp)
jmp 0x66e1
leaq 0x77ca(%rip), %rdi      # 0xe041
movb $0x0, %al
callq 0x6040
movl -0x28(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x28(%rbp)
jmp 0x6583
movl $0x0, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0xb0, %rsp
popq %rbp
retq
nop