// File: /workspace/github_c_makefile_star2_O0/kilobyte[P]colormatch/rate.c
// Function: main
int main(int argc, char **argv)
{
    if (argc!=2)
        fprintf(stderr, "Usage: rate file.rgb\n"), exit(1);

    int fd = open(argv[1], O_RDONLY);
    if (read(fd, nt, sizeof(nt))!=sizeof(nt))
        perror("Can't read table file"), exit(1);
    close(fd);

    int maxe=0;
    long long ss=0;
    int worst=0;

    for (int i = 0; i < 16777216; ++i)
    {
        int d = color_diff(i, col256_to_rgb(nt[i]));
        if (d > maxe)
            maxe = d, worst = i;
        ss += ((long long)d) * d / 16777216;
    }

    printf("%-15s maxd=%#-7.6g (\e[38;2;%d;%d;%dm#%06X\e[0m vs \e[38;5;%dm%3d\e[0m:\e[38;2;%d;%d;%dm#%06X\e[0m) Σd²=%#-8.6g\n",
        argv[1],
        maxe/16777216.0,
        (worst>>16)&0xff, (worst>>8)&0xff, worst&0xff, worst,
        nt[worst], nt[worst],
        (col256_to_rgb(nt[worst])>>16)&0xff, (col256_to_rgb(nt[worst])>>8)&0xff, col256_to_rgb(nt[worst])&0xff,
        col256_to_rgb(nt[worst]),
        ss/16777216.0);

    return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %rbx
subq $0x88, %rsp
movl $0x0, -0x1c(%rbp)
movl %edi, -0x20(%rbp)
movq %rsi, -0x28(%rbp)
cmpl $0x2, -0x20(%rbp)
je 0x1256
movq 0x3dbd(%rip), %rax      # 0x4ff8
movq (%rax), %rdi
leaq 0x1dcb(%rip), %rsi      # 0x3010
movb $0x0, %al
callq 0x1090
movl $0x1, %edi
callq 0x10e0
movq -0x28(%rbp), %rax
movq 0x8(%rax), %rdi
xorl %esi, %esi
movb $0x0, %al
callq 0x10b0
movl %eax, -0x2c(%rbp)
movl -0x2c(%rbp), %edi
leaq 0x3e3c(%rip), %rsi      # 0x50b0
movl $0x1000000, %edx        # imm = 0x1000000
callq 0x1080
cmpq $0x1000000, %rax        # imm = 0x1000000
je 0x129c
leaq 0x1d99(%rip), %rdi      # 0x3026
callq 0x10c0
movl $0x1, %edi
callq 0x10e0
movl -0x2c(%rbp), %edi
callq 0x1060
movl $0x0, -0x30(%rbp)
movq $0x0, -0x38(%rbp)
movl $0x0, -0x3c(%rbp)
movl $0x0, -0x40(%rbp)
cmpl $0x1000000, -0x40(%rbp) # imm = 0x1000000
jge 0x132e
movl -0x40(%rbp), %eax
movl %eax, -0x48(%rbp)
movslq -0x40(%rbp), %rcx
leaq 0x3dd5(%rip), %rax      # 0x50b0
movzbl (%rax,%rcx), %edi
callq 0x2110
movl -0x48(%rbp), %edi
movl %eax, %esi
callq 0x20c0
movl %eax, -0x44(%rbp)
movl -0x44(%rbp), %eax
cmpl -0x30(%rbp), %eax
jle 0x1305
movl -0x44(%rbp), %eax
movl %eax, -0x30(%rbp)
movl -0x40(%rbp), %eax
movl %eax, -0x3c(%rbp)
movslq -0x44(%rbp), %rax
movslq -0x44(%rbp), %rcx
imulq %rcx, %rax
movl $0x1000000, %ecx        # imm = 0x1000000
cqto
idivq %rcx
addq -0x38(%rbp), %rax
movq %rax, -0x38(%rbp)
movl -0x40(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x40(%rbp)
jmp 0x12c1
movq -0x28(%rbp), %rax
movq 0x8(%rax), %rax
movq %rax, -0x70(%rbp)
cvtsi2sdl -0x30(%rbp), %xmm0
movsd 0x1cc1(%rip), %xmm1     # 0x3008
divsd %xmm1, %xmm0
movsd %xmm0, -0x68(%rbp)
movl -0x3c(%rbp), %eax
sarl $0x10, %eax
andl $0xff, %eax
movl %eax, -0x60(%rbp)
movl -0x3c(%rbp), %eax
sarl $0x8, %eax
andl $0xff, %eax
movl %eax, -0x5c(%rbp)
movl -0x3c(%rbp), %eax
andl $0xff, %eax
movl %eax, -0x58(%rbp)
movl -0x3c(%rbp), %eax
movl %eax, -0x54(%rbp)
movslq -0x3c(%rbp), %rcx
leaq 0x3d28(%rip), %rax      # 0x50b0
movzbl (%rax,%rcx), %r15d
movslq -0x3c(%rbp), %rcx
leaq 0x3d18(%rip), %rax      # 0x50b0
movzbl (%rax,%rcx), %r14d
movslq -0x3c(%rbp), %rcx
leaq 0x3d08(%rip), %rax      # 0x50b0
movzbl (%rax,%rcx), %edi
callq 0x2110
movl %eax, %ebx
sarl $0x10, %ebx
andl $0xff, %ebx
movslq -0x3c(%rbp), %rcx
leaq 0x3ce9(%rip), %rax      # 0x50b0
movzbl (%rax,%rcx), %edi
callq 0x2110
sarl $0x8, %eax
andl $0xff, %eax
movl %eax, -0x50(%rbp)
movslq -0x3c(%rbp), %rcx
leaq 0x3cca(%rip), %rax      # 0x50b0
movzbl (%rax,%rcx), %edi
callq 0x2110
andl $0xff, %eax
movl %eax, -0x4c(%rbp)
movslq -0x3c(%rbp), %rcx
leaq 0x3cae(%rip), %rax      # 0x50b0
movzbl (%rax,%rcx), %edi
callq 0x2110
movq -0x70(%rbp), %rsi
movsd -0x68(%rbp), %xmm0
movl -0x60(%rbp), %edx
movl -0x5c(%rbp), %ecx
movl -0x58(%rbp), %r8d
movl -0x54(%rbp), %r9d
movl -0x50(%rbp), %r11d
movl -0x4c(%rbp), %r10d
cvtsi2sdq -0x38(%rbp), %xmm1
movsd 0x1bd0(%rip), %xmm2     # 0x3008
divsd %xmm2, %xmm1
leaq 0x1bf9(%rip), %rdi      # 0x303c
movl %r15d, (%rsp)
movl %r14d, 0x8(%rsp)
movl %ebx, 0x10(%rsp)
movl %r11d, 0x18(%rsp)
movl %r10d, 0x20(%rsp)
movl %eax, 0x28(%rsp)
movb $0x2, %al
callq 0x1050
xorl %eax, %eax
addq $0x88, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
retq
nopw %cs:(%rax,%rax)
nop