// File: /workspace/github_c_makefile_star2_O0/yahya-tamur[P]Visualising-Complex-Functions/gifenc.c
// Function: put_image
static void put_image(ge_GIF *gif, uint16_t w, uint16_t h, uint16_t x, uint16_t y) {
    int nkeys, key_size, i, j;
    Node *node, *child, *root;
    int degree = 1 << gif->depth;

    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, (uint8_t[]) { 0x00, gif->depth }, 2);
    root = node = new_trie(degree, &nkeys);
    key_size = gif->depth + 1;
    put_key(gif, degree, key_size); /* clear code */
    for (i = y; i < y + h; i++) {
        for (j = x; j < x + w; j++) {
            uint8_t pixel = gif->frame[i * gif->w + j] & (degree - 1);
            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++, degree);
                } else {
                    put_key(gif, degree, key_size); /* clear code */
                    del_trie(root, degree);
                    root = new_trie(degree, &nkeys);
                    key_size = gif->depth + 1;
                }
                node = root->children[pixel];
            }
        }
    }
    put_key(gif, node->key, key_size);
    put_key(gif, degree + 1, key_size); /* stop code */
    end_key(gif);
    del_trie(root, degree);
}

// 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)
movq -0x8(%rbp), %rax
movl 0x4(%rax), %ecx
movl $0x1, %eax
shll %cl, %eax
movl %eax, -0x3c(%rbp)
movq -0x8(%rbp), %rax
movl 0x8(%rax), %edi
leaq 0x385a(%rip), %rsi      # 0x6019
movl $0x1, %edx
callq 0x2070
movq -0x8(%rbp), %rax
movl 0x8(%rax), %edi
movzwl -0xe(%rbp), %eax
andl $0xff, %eax
movb %al, -0x3e(%rbp)
movzwl -0xe(%rbp), %eax
sarl $0x8, %eax
movb %al, -0x3d(%rbp)
leaq -0x3e(%rbp), %rsi
movl $0x2, %edx
callq 0x2070
movq -0x8(%rbp), %rax
movl 0x8(%rax), %edi
movzwl -0x10(%rbp), %eax
andl $0xff, %eax
movb %al, -0x40(%rbp)
movzwl -0x10(%rbp), %eax
sarl $0x8, %eax
movb %al, -0x3f(%rbp)
leaq -0x40(%rbp), %rsi
movl $0x2, %edx
callq 0x2070
movq -0x8(%rbp), %rax
movl 0x8(%rax), %edi
movzwl -0xa(%rbp), %eax
andl $0xff, %eax
movb %al, -0x42(%rbp)
movzwl -0xa(%rbp), %eax
sarl $0x8, %eax
movb %al, -0x41(%rbp)
leaq -0x42(%rbp), %rsi
movl $0x2, %edx
callq 0x2070
movq -0x8(%rbp), %rax
movl 0x8(%rax), %edi
movzwl -0xc(%rbp), %eax
andl $0xff, %eax
movb %al, -0x44(%rbp)
movzwl -0xc(%rbp), %eax
sarl $0x8, %eax
movb %al, -0x43(%rbp)
leaq -0x44(%rbp), %rsi
movl $0x2, %edx
callq 0x2070
movq -0x8(%rbp), %rax
movl 0x8(%rax), %edi
movb $0x0, -0x46(%rbp)
movq -0x8(%rbp), %rax
movl 0x4(%rax), %eax
movb %al, -0x45(%rbp)
leaq -0x46(%rbp), %rsi
movl $0x2, %edx
callq 0x2070
movl -0x3c(%rbp), %edi
leaq -0x14(%rbp), %rsi
callq 0x2ab0
movq %rax, -0x28(%rbp)
movq %rax, -0x38(%rbp)
movq -0x8(%rbp), %rax
movl 0x4(%rax), %eax
addl $0x1, %eax
movl %eax, -0x18(%rbp)
movq -0x8(%rbp), %rdi
movl -0x3c(%rbp), %eax
movl -0x18(%rbp), %edx
movzwl %ax, %esi
callq 0x2b30
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 0x2a21
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 0x2a11
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rax
movl -0x1c(%rbp), %ecx
movq -0x8(%rbp), %rdx
movzwl (%rdx), %edx
imull %edx, %ecx
addl -0x20(%rbp), %ecx
movslq %ecx, %rcx
movzbl (%rax,%rcx), %eax
movl -0x3c(%rbp), %ecx
subl $0x1, %ecx
andl %ecx, %eax
movb %al, -0x47(%rbp)
movq -0x28(%rbp), %rax
movzbl -0x47(%rbp), %ecx
movq 0x8(%rax,%rcx,8), %rax
movq %rax, -0x30(%rbp)
cmpq $0x0, -0x30(%rbp)
je 0x2952
movq -0x30(%rbp), %rax
movq %rax, -0x28(%rbp)
jmp 0x2a01
movq -0x8(%rbp), %rdi
movq -0x28(%rbp), %rax
movw (%rax), %ax
movl -0x18(%rbp), %edx
movzwl %ax, %esi
callq 0x2b30
cmpl $0x1000, -0x14(%rbp)    # imm = 0x1000
jge 0x29b5
movl -0x14(%rbp), %eax
movl -0x18(%rbp), %ecx
movl $0x1, %edx
shll %cl, %edx
movl %edx, %ecx
cmpl %ecx, %eax
jne 0x298d
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)
movl -0x3c(%rbp), %esi
movzwl %ax, %edi
callq 0x2c40
movq %rax, %rdx
movq -0x28(%rbp), %rax
movzbl -0x47(%rbp), %ecx
movq %rdx, 0x8(%rax,%rcx,8)
jmp 0x29f0
movq -0x8(%rbp), %rdi
movl -0x3c(%rbp), %eax
movl -0x18(%rbp), %edx
movzwl %ax, %esi
callq 0x2b30
movq -0x38(%rbp), %rdi
movl -0x3c(%rbp), %esi
callq 0x2c90
movl -0x3c(%rbp), %edi
leaq -0x14(%rbp), %rsi
callq 0x2ab0
movq %rax, -0x38(%rbp)
movq -0x8(%rbp), %rax
movl 0x4(%rax), %eax
addl $0x1, %eax
movl %eax, -0x18(%rbp)
movq -0x38(%rbp), %rax
movzbl -0x47(%rbp), %ecx
movq 0x8(%rax,%rcx,8), %rax
movq %rax, -0x28(%rbp)
jmp 0x2a03
movl -0x20(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x20(%rbp)
jmp 0x28ee
jmp 0x2a13
movl -0x1c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x1c(%rbp)
jmp 0x28d2
movq -0x8(%rbp), %rdi
movq -0x28(%rbp), %rax
movw (%rax), %ax
movl -0x18(%rbp), %edx
movzwl %ax, %esi
callq 0x2b30
movq -0x8(%rbp), %rdi
movl -0x3c(%rbp), %eax
addl $0x1, %eax
movl -0x18(%rbp), %edx
movzwl %ax, %esi
callq 0x2b30
movq -0x8(%rbp), %rdi
callq 0x2cf0
movq -0x38(%rbp), %rdi
movl -0x3c(%rbp), %esi
callq 0x2c90
addq $0x50, %rsp
popq %rbp
retq
nopw (%rax,%rax)