// File: /workspace/github_c_makefile_star2_O0/lecram[P]congif/gif.c
// Function: put_image
static void
put_image(GIF *gif, uint16_t w, uint16_t h, uint16_t x, uint16_t y)
{
    int nkeys, key_size, i, j;
    Node *node, *child, *root;
    uint8_t id_packed = 0x00;

    if (gif->plt) {
        id_packed &= ~0x7;
        id_packed |= 0x83; /* Local clut, 4 bits. */
    }

    root = malloc(sizeof(*root));
    write(gif->fd, ",", 1);
    write_num(gif->fd, x);
    write_num(gif->fd, y);
    write_num(gif->fd, w);
    write_num(gif->fd, h);
    write(gif->fd, &id_packed, 1);
    if (id_packed & 0x80)
        write(gif->fd, gif->plt, 3<<((id_packed & 0x7)+1));

    write(gif->fd, "\x04", 1); /* Min code size */
    root = node = new_trie(&nkeys);
    key_size = 5;
    put_key(gif, 0x10, key_size); /* clear code */
    for (i = y; i < y+h; i++) {
        for (j = x; j < x+w; j++) {
            uint8_t pixel = gif->cur[i*gif->w+j];
            child = node->children[pixel];
            if (child) {
                node = child;
            } else {
                put_key(gif, node->key, key_size);
                if (nkeys < 0x1000) {
                    if (nkeys == (1 << key_size))
                        key_size++;
                    node->children[pixel] = new_node(nkeys++);
                } else {
                    put_key(gif, 0x10, key_size); /* clear code */
                    del_trie(root);
                    root = node = new_trie(&nkeys);
                    key_size = 5;
                }
                node = root->children[pixel];
            }
        }
    }
    put_key(gif, node->key, key_size);
    put_key(gif, 0x11, key_size); /* stop code */
    end_key(gif);
    del_trie(root);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x50, %rsp
movw %r8w, %ax
movq %rdi, -0x8(%rbp)
movw %si, -0xa(%rbp)
movw %dx, -0xc(%rbp)
movw %cx, -0xe(%rbp)
movw %ax, -0x10(%rbp)
movb $0x0, -0x39(%rbp)
movq -0x8(%rbp), %rax
cmpq $0x0, 0x20(%rax)
je 0x4e55
movzbl -0x39(%rbp), %eax
andl $-0x8, %eax
movb %al, -0x39(%rbp)
movzbl -0x39(%rbp), %eax
orl $0x83, %eax
movb %al, -0x39(%rbp)
movl $0x88, %edi
callq 0x1170
movq %rax, -0x38(%rbp)
movq -0x8(%rbp), %rax
movl 0x4(%rax), %edi
leaq 0x290c(%rip), %rsi      # 0x777d
movl $0x1, %edx
callq 0x1080
movq -0x8(%rbp), %rax
movl 0x4(%rax), %edi
movzwl -0xe(%rbp), %eax
andl $0xff, %eax
movb %al, -0x3b(%rbp)
movzwl -0xe(%rbp), %eax
sarl $0x8, %eax
movb %al, -0x3a(%rbp)
leaq -0x3b(%rbp), %rsi
movl $0x2, %edx
callq 0x1080
movq -0x8(%rbp), %rax
movl 0x4(%rax), %edi
movzwl -0x10(%rbp), %eax
andl $0xff, %eax
movb %al, -0x3d(%rbp)
movzwl -0x10(%rbp), %eax
sarl $0x8, %eax
movb %al, -0x3c(%rbp)
leaq -0x3d(%rbp), %rsi
movl $0x2, %edx
callq 0x1080
movq -0x8(%rbp), %rax
movl 0x4(%rax), %edi
movzwl -0xa(%rbp), %eax
andl $0xff, %eax
movb %al, -0x3f(%rbp)
movzwl -0xa(%rbp), %eax
sarl $0x8, %eax
movb %al, -0x3e(%rbp)
leaq -0x3f(%rbp), %rsi
movl $0x2, %edx
callq 0x1080
movq -0x8(%rbp), %rax
movl 0x4(%rax), %edi
movzwl -0xc(%rbp), %eax
andl $0xff, %eax
movb %al, -0x41(%rbp)
movzwl -0xc(%rbp), %eax
sarl $0x8, %eax
movb %al, -0x40(%rbp)
leaq -0x41(%rbp), %rsi
movl $0x2, %edx
callq 0x1080
movq -0x8(%rbp), %rax
movl 0x4(%rax), %edi
leaq -0x39(%rbp), %rsi
movl $0x1, %edx
callq 0x1080
movzbl -0x39(%rbp), %eax
andl $0x80, %eax
cmpl $0x0, %eax
je 0x4f72
movq -0x8(%rbp), %rax
movl 0x4(%rax), %edi
movq -0x8(%rbp), %rax
movq 0x20(%rax), %rsi
movzbl -0x39(%rbp), %ecx
andl $0x7, %ecx
addl $0x1, %ecx
movl $0x3, %eax
shll %cl, %eax
movslq %eax, %rdx
callq 0x1080
movq -0x8(%rbp), %rax
movl 0x4(%rax), %edi
leaq 0x27ff(%rip), %rsi      # 0x777f
movl $0x1, %edx
callq 0x1080
leaq -0x14(%rbp), %rdi
callq 0x5180
movq %rax, -0x28(%rbp)
movq %rax, -0x38(%rbp)
movl $0x5, -0x18(%rbp)
movq -0x8(%rbp), %rdi
movl -0x18(%rbp), %edx
movl $0x10, %esi
callq 0x51f0
movzwl -0x10(%rbp), %eax
movl %eax, -0x1c(%rbp)
movl -0x1c(%rbp), %eax
movzwl -0x10(%rbp), %ecx
movzwl -0xc(%rbp), %edx
addl %edx, %ecx
cmpl %ecx, %eax
jge 0x50f4
movzwl -0xe(%rbp), %eax
movl %eax, -0x20(%rbp)
movl -0x20(%rbp), %eax
movzwl -0xe(%rbp), %ecx
movzwl -0xa(%rbp), %edx
addl %edx, %ecx
cmpl %ecx, %eax
jge 0x50e4
movq -0x8(%rbp), %rax
movq 0x10(%rax), %rax
movl -0x1c(%rbp), %ecx
movq -0x8(%rbp), %rdx
movzwl (%rdx), %edx
imull %edx, %ecx
addl -0x20(%rbp), %ecx
movslq %ecx, %rcx
movb (%rax,%rcx), %al
movb %al, -0x42(%rbp)
movq -0x28(%rbp), %rax
movzbl -0x42(%rbp), %ecx
movq 0x8(%rax,%rcx,8), %rax
movq %rax, -0x30(%rbp)
cmpq $0x0, -0x30(%rbp)
je 0x5031
movq -0x30(%rbp), %rax
movq %rax, -0x28(%rbp)
jmp 0x50d4
movq -0x8(%rbp), %rdi
movq -0x28(%rbp), %rax
movw (%rax), %ax
movl -0x18(%rbp), %edx
movzwl %ax, %esi
callq 0x51f0
cmpl $0x1000, -0x14(%rbp)    # imm = 0x1000
jge 0x5091
movl -0x14(%rbp), %eax
movl -0x18(%rbp), %ecx
movl $0x1, %edx
shll %cl, %edx
movl %edx, %ecx
cmpl %ecx, %eax
jne 0x506c
movl -0x18(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x18(%rbp)
movl -0x14(%rbp), %eax
movl %eax, %ecx
addl $0x1, %ecx
movl %ecx, -0x14(%rbp)
movzwl %ax, %edi
callq 0x5300
movq %rax, %rdx
movq -0x28(%rbp), %rax
movzbl -0x42(%rbp), %ecx
movq %rdx, 0x8(%rax,%rcx,8)
jmp 0x50c3
movq -0x8(%rbp), %rdi
movl -0x18(%rbp), %edx
movl $0x10, %esi
callq 0x51f0
movq -0x38(%rbp), %rdi
callq 0x5340
leaq -0x14(%rbp), %rdi
callq 0x5180
movq %rax, -0x28(%rbp)
movq %rax, -0x38(%rbp)
movl $0x5, -0x18(%rbp)
movq -0x38(%rbp), %rax
movzbl -0x42(%rbp), %ecx
movq 0x8(%rax,%rcx,8), %rax
movq %rax, -0x28(%rbp)
jmp 0x50d6
movl -0x20(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x20(%rbp)
jmp 0x4fd6
jmp 0x50e6
movl -0x1c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x1c(%rbp)
jmp 0x4fba
movq -0x8(%rbp), %rdi
movq -0x28(%rbp), %rax
movw (%rax), %ax
movl -0x18(%rbp), %edx
movzwl %ax, %esi
callq 0x51f0
movq -0x8(%rbp), %rdi
movl -0x18(%rbp), %edx
movl $0x11, %esi
callq 0x51f0
movq -0x8(%rbp), %rdi
callq 0x5390
movq -0x38(%rbp), %rdi
callq 0x5340
addq $0x50, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)