// File: /workspace/github_c_makefile_star2_O0/lecram[P]congif/term.c
// Function: set_default_palette
void
set_default_palette(char * pname)
{
    static struct {
        char * name;
        uint8_t * plt;
    } pal[] = {
        { "xterm", plt_xterm },
        { "vga", plt_vga_ansi },
        { "sol_ansi", plt_solarized_like_ansi },
        { "solarized", plt_solarized },
        { "putty", plt_putty },
        { 0, 0}
    };

    if (pname[0] == '@') {
        int i;
        for(i=0; pal[i].name; i++) {
            if (strcasecmp(pname+1, pal[i].name) == 0) {
                def_plt = pal[i].plt;
                return;
            }
        }
        fprintf(stderr, "Known standard palette names are:\n");
        for(i=0; pal[i].name; i++)
            fprintf(stderr, "    @%s\n", pal[i].name);
        exit(2);
    } else {
        FILE * fd;
        char buf[BUFSIZ];
        Term * term = 0;
        uint8_t * plt = malloc(sizeof(term->plt));
        memcpy(plt, def_plt, sizeof(term->plt));
        def_plt = plt;

        if ((fd = fopen(pname, "r")) == 0) {
            perror(pname); exit(1);
        }
        while (fgets(buf, sizeof(buf), fd) != 0) {
            char * s = buf, *e;
            long cno = 0, colour = 0;

            while (*s == ' ' || *s == '\t') s++;
            if (*s == '#') continue;

            if (strncasecmp(s, "color", 5) == 0) {
                s += 5;
            } else if (strncasecmp(s, "colour", 6) == 0) {
                s += 6;
            } else continue;

            // Only lines that match /^ *colou?r[0-9]+/i
            if (*s < '0' || *s > '9') continue;

            cno = strtol(s, &e, 0);
            if (s == e) goto bad_line;
            if (cno < 0 || cno > 16) goto bad_line;

            s = e;
            while (*s == ' ' || *s == '\t' || *s == '#' || *s == '=') s++;
            colour = strtol(s, &e, 16);
            if (e-s != 6) goto bad_line;

            plt[cno*3+0] = ((colour>>16) & 0xFF);
            plt[cno*3+1] = ((colour>> 8) & 0xFF);
            plt[cno*3+2] = ((colour    ) & 0xFF);
            continue;
bad_line:
            fprintf(stderr, "Bad line in colour file: %s", buf);
            exit(2);
        }

        fclose(fd);
    }
    return;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x2060, %rsp           # imm = 0x2060
movq %rdi, -0x8(%rbp)
movq -0x8(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x40, %eax
jne 0x145d
movl $0x0, -0xc(%rbp)
movslq -0xc(%rbp), %rcx
leaq 0x8daf(%rip), %rax      # 0xa130
shlq $0x4, %rcx
addq %rcx, %rax
cmpq $0x0, (%rax)
je 0x13e4
movq -0x8(%rbp), %rdi
addq $0x1, %rdi
movslq -0xc(%rbp), %rcx
leaq 0x8d8f(%rip), %rax      # 0xa130
shlq $0x4, %rcx
addq %rcx, %rax
movq (%rax), %rsi
callq 0x1050
cmpl $0x0, %eax
jne 0x13d7
movslq -0xc(%rbp), %rcx
leaq 0x8d70(%rip), %rax      # 0xa130
shlq $0x4, %rcx
addq %rcx, %rax
movq 0x8(%rax), %rax
movq %rax, 0x8eae(%rip)      # 0xa280
jmp 0x17af
jmp 0x13d9
movl -0xc(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xc(%rbp)
jmp 0x1376
movq 0x8c0d(%rip), %rax      # 0x9ff8
movq (%rax), %rdi
leaq 0x613e(%rip), %rsi      # 0x7533
movb $0x0, %al
callq 0x1140
movl $0x0, -0xc(%rbp)
movslq -0xc(%rbp), %rcx
leaq 0x8d22(%rip), %rax      # 0xa130
shlq $0x4, %rcx
addq %rcx, %rax
cmpq $0x0, (%rax)
je 0x1453
movq 0x8bd6(%rip), %rax      # 0x9ff8
movq (%rax), %rdi
movslq -0xc(%rbp), %rcx
leaq 0x8d00(%rip), %rax      # 0xa130
shlq $0x4, %rcx
addq %rcx, %rax
movq (%rax), %rdx
leaq 0x6115(%rip), %rsi      # 0x7556
movb $0x0, %al
callq 0x1140
movl -0xc(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xc(%rbp)
jmp 0x1403
movl $0x2, %edi
callq 0x1210
movq $0x0, -0x2028(%rbp)
movl $0x30, %edi
callq 0x1170
movq %rax, -0x2030(%rbp)
movq -0x2030(%rbp), %rdi
movq 0x8df9(%rip), %rsi      # 0xa280
movl $0x30, %edx
callq 0x1160
movq -0x2030(%rbp), %rax
movq %rax, 0x8de1(%rip)      # 0xa280
movq -0x8(%rbp), %rdi
leaq 0x60b9(%rip), %rsi      # 0x7563
callq 0x11b0
movq %rax, -0x18(%rbp)
cmpq $0x0, %rax
jne 0x14cc
movq -0x8(%rbp), %rdi
callq 0x11c0
movl $0x1, %edi
callq 0x1210
jmp 0x14ce
leaq -0x2020(%rbp), %rdi
movq -0x18(%rbp), %rdx
movl $0x2000, %esi           # imm = 0x2000
callq 0x1110
cmpq $0x0, %rax
je 0x17a4
leaq -0x2020(%rbp), %rax
movq %rax, -0x2038(%rbp)
movq $0x0, -0x2048(%rbp)
movq $0x0, -0x2050(%rbp)
movq -0x2038(%rbp), %rax
movsbl (%rax), %ecx
movb $0x1, %al
cmpl $0x20, %ecx
movb %al, -0x2051(%rbp)
je 0x153e
movq -0x2038(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x9, %eax
sete %al
movb %al, -0x2051(%rbp)
movb -0x2051(%rbp), %al
testb $0x1, %al
jne 0x154a
jmp 0x155e
movq -0x2038(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x2038(%rbp)
jmp 0x1511
movq -0x2038(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x23, %eax
jne 0x1572
jmp 0x14ce
movq -0x2038(%rbp), %rdi
leaq 0x5fdf(%rip), %rsi      # 0x755f
movl $0x5, %edx
callq 0x1180
cmpl $0x0, %eax
jne 0x15a3
movq -0x2038(%rbp), %rax
addq $0x5, %rax
movq %rax, -0x2038(%rbp)
jmp 0x15db
movq -0x2038(%rbp), %rdi
leaq 0x5fb4(%rip), %rsi      # 0x7565
movl $0x6, %edx
callq 0x1180
cmpl $0x0, %eax
jne 0x15d4
movq -0x2038(%rbp), %rax
addq $0x6, %rax
movq %rax, -0x2038(%rbp)
jmp 0x15d9
jmp 0x14ce
jmp 0x15db
movq -0x2038(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x30, %eax
jl 0x15f9
movq -0x2038(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x39, %eax
jle 0x15fe
jmp 0x14ce
movq -0x2038(%rbp), %rdi
leaq -0x2040(%rbp), %rsi
xorl %edx, %edx
callq 0x1150
movq %rax, -0x2048(%rbp)
movq -0x2038(%rbp), %rax
cmpq -0x2040(%rbp), %rax
jne 0x162f
jmp 0x177b
cmpq $0x0, -0x2048(%rbp)
jl 0x1643
cmpq $0x10, -0x2048(%rbp)
jle 0x1648
jmp 0x177b
movq -0x2040(%rbp), %rax
movq %rax, -0x2038(%rbp)
movq -0x2038(%rbp), %rax
movsbl (%rax), %ecx
movb $0x1, %al
cmpl $0x20, %ecx
movb %al, -0x2052(%rbp)
je 0x16b1
movq -0x2038(%rbp), %rax
movsbl (%rax), %ecx
movb $0x1, %al
cmpl $0x9, %ecx
movb %al, -0x2052(%rbp)
je 0x16b1
movq -0x2038(%rbp), %rax
movsbl (%rax), %ecx
movb $0x1, %al
cmpl $0x23, %ecx
movb %al, -0x2052(%rbp)
je 0x16b1
movq -0x2038(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x3d, %eax
sete %al
movb %al, -0x2052(%rbp)
movb -0x2052(%rbp), %al
testb $0x1, %al
jne 0x16bd
jmp 0x16d1
movq -0x2038(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x2038(%rbp)
jmp 0x1656
movq -0x2038(%rbp), %rdi
leaq -0x2040(%rbp), %rsi
movl $0x10, %edx
callq 0x1150
movq %rax, -0x2050(%rbp)
movq -0x2040(%rbp), %rax
movq -0x2038(%rbp), %rcx
subq %rcx, %rax
cmpq $0x6, %rax
je 0x1709
jmp 0x177b
movq -0x2050(%rbp), %rax
sarq $0x10, %rax
andq $0xff, %rax
movb %al, %dl
movq -0x2030(%rbp), %rax
imulq $0x3, -0x2048(%rbp), %rcx
movb %dl, (%rax,%rcx)
movq -0x2050(%rbp), %rax
sarq $0x8, %rax
andq $0xff, %rax
movb %al, %dl
movq -0x2030(%rbp), %rax
imulq $0x3, -0x2048(%rbp), %rcx
movb %dl, 0x1(%rax,%rcx)
movq -0x2050(%rbp), %rax
andq $0xff, %rax
movb %al, %dl
movq -0x2030(%rbp), %rax
imulq $0x3, -0x2048(%rbp), %rcx
movb %dl, 0x2(%rax,%rcx)
jmp 0x14ce
movq 0x8876(%rip), %rax      # 0x9ff8
movq (%rax), %rdi
leaq -0x2020(%rbp), %rdx
leaq 0x5dd9(%rip), %rsi      # 0x756c
movb $0x0, %al
callq 0x1140
movl $0x2, %edi
callq 0x1210
movq -0x18(%rbp), %rdi
callq 0x1090
jmp 0x17af
addq $0x2060, %rsp           # imm = 0x2060
popq %rbp
retq
nopl (%rax,%rax)