// File: cloudinary[P]fuif/./import/read_gif.h
// Function: read_image_data(gd_GIF*)
static int
read_image_data(gd_GIF *gif)
{
    uint8_t sub_len, shift, byte;
    int init_key_size, key_size, table_is_full;
    int frm_off, str_len, p;
    uint16_t key, clear, stop;
    int ret;
    Table *table;
    Entry entry;
    off_t start, end;

    read(gif->fd, &byte, 1);
    key_size = (int) byte;
    start = lseek(gif->fd, 0, SEEK_CUR);
    discard_sub_blocks(gif);
    end = lseek(gif->fd, 0, SEEK_CUR);
    lseek(gif->fd, start, SEEK_SET);
    clear = 1 << key_size;
    stop = clear + 1;
    table = new_table(key_size);
    key_size++;
    init_key_size = key_size;
    sub_len = shift = 0;
    key = get_key(gif, key_size, &sub_len, &shift, &byte); /* clear code */
    frm_off = 0;
    ret = 0;
    while (1) {
        if (key == clear) {
            key_size = init_key_size;
            table->nentries = (1 << (key_size - 1)) + 2;
            table_is_full = 0;
        } else if (!table_is_full) {
            ret = add_entry(&table, str_len + 1, key, entry.suffix);
            if (ret == -1) {
                free(table);
                return -1;
            }
            if (table->nentries == 0x1000) {
                ret = 0;
                table_is_full = 1;
            }
        }
        key = get_key(gif, key_size, &sub_len, &shift, &byte);
        if (key == clear) continue;
        if (key == stop) break;
        if (ret == 1) key_size++;
        entry = table->entries[key];
        str_len = entry.length;
        while (1) {
            p = frm_off + entry.length - 1;
            gif->frame[(gif->fy + p / gif->fw) * gif->width + gif->fx + p % gif->fw] = entry.suffix;
            if (entry.prefix == 0xFFF)
                break;
            else
                entry = table->entries[entry.prefix];
        }
        frm_off += str_len;
        if (key < table->nentries - 1 && !table_is_full)
            table->entries[table->nentries - 1].suffix = entry.suffix;
    }
    free(table);
    read(gif->fd, &sub_len, 1); /* Must be zero! */
    lseek(gif->fd, end, SEEK_SET);
    return 0;
}

// Assembly:
subq $0x68, %rsp
movq %rdi, 0x58(%rsp)
movq 0x58(%rsp), %rax
movl (%rax), %edi
leaq 0x55(%rsp), %rsi
movl $0x1, %edx
callq 0x3520
movzbl 0x55(%rsp), %eax
movl %eax, 0x4c(%rsp)
movq 0x58(%rsp), %rax
movl (%rax), %edi
xorl %eax, %eax
movl %eax, %esi
movl $0x1, %edx
callq 0x36d0
movq %rax, 0x18(%rsp)
movq 0x58(%rsp), %rdi
callq 0x44b50
movq 0x58(%rsp), %rax
movl (%rax), %edi
xorl %eax, %eax
movl %eax, %esi
movl $0x1, %edx
callq 0x36d0
movq %rax, 0x10(%rsp)
movq 0x58(%rsp), %rax
movl (%rax), %edi
movq 0x18(%rsp), %rsi
xorl %edx, %edx
callq 0x36d0
movl 0x4c(%rsp), %ecx
movl $0x1, %eax
shll %cl, %eax
movw %ax, 0x38(%rsp)
movzwl 0x38(%rsp), %eax
addl $0x1, %eax
movw %ax, 0x36(%rsp)
movl 0x4c(%rsp), %edi
callq 0x44f20
movq %rax, 0x28(%rsp)
movl 0x4c(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x4c(%rsp)
movl 0x4c(%rsp), %eax
movl %eax, 0x50(%rsp)
movb $0x0, 0x56(%rsp)
movb $0x0, 0x57(%rsp)
movq 0x58(%rsp), %rdi
movl 0x4c(%rsp), %esi
leaq 0x57(%rsp), %rdx
leaq 0x56(%rsp), %rcx
leaq 0x55(%rsp), %r8
callq 0x45030
movw %ax, 0x3a(%rsp)
movl $0x0, 0x44(%rsp)
movl $0x0, 0x30(%rsp)
movzwl 0x3a(%rsp), %eax
movzwl 0x38(%rsp), %ecx
cmpl %ecx, %eax
jne 0x44cce
movl 0x50(%rsp), %eax
movl %eax, 0x4c(%rsp)
movl 0x4c(%rsp), %ecx
subl $0x1, %ecx
movl $0x1, %eax
shll %cl, %eax
movl %eax, %ecx
addl $0x2, %ecx
movq 0x28(%rsp), %rax
movl %ecx, 0x4(%rax)
movl $0x0, 0x48(%rsp)
jmp 0x44d3d
cmpl $0x0, 0x48(%rsp)
jne 0x44d3b
movl 0x40(%rsp), %eax
addl $0x1, %eax
movw %ax, %cx
movw 0x3a(%rsp), %ax
leaq 0x28(%rsp), %rdi
movzwl %cx, %esi
movzwl %ax, %edx
movzbl 0x26(%rsp), %ecx
callq 0x45180
movl %eax, 0x30(%rsp)
cmpl $-0x1, 0x30(%rsp)
jne 0x44d1b
movq 0x28(%rsp), %rdi
callq 0x3470
movl $0xffffffff, 0x64(%rsp) # imm = 0xFFFFFFFF
jmp 0x44f11
movq 0x28(%rsp), %rax
cmpl $0x1000, 0x4(%rax)      # imm = 0x1000
jne 0x44d39
movl $0x0, 0x30(%rsp)
movl $0x1, 0x48(%rsp)
jmp 0x44d3b
jmp 0x44d3d
movq 0x58(%rsp), %rdi
movl 0x4c(%rsp), %esi
leaq 0x57(%rsp), %rdx
leaq 0x56(%rsp), %rcx
leaq 0x55(%rsp), %r8
callq 0x45030
movw %ax, 0x3a(%rsp)
movzwl 0x3a(%rsp), %eax
movzwl 0x38(%rsp), %ecx
cmpl %ecx, %eax
jne 0x44d72
jmp 0x44c93
movzwl 0x3a(%rsp), %eax
movzwl 0x36(%rsp), %ecx
cmpl %ecx, %eax
jne 0x44d85
jmp 0x44ed6
cmpl $0x1, 0x30(%rsp)
jne 0x44d97
movl 0x4c(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x4c(%rsp)
movq 0x28(%rsp), %rax
movq 0x8(%rax), %rax
movzwl 0x3a(%rsp), %ecx
imulq $0x6, %rcx, %rcx
addq %rcx, %rax
movl (%rax), %ecx
movl %ecx, 0x22(%rsp)
movw 0x4(%rax), %ax
movw %ax, 0x26(%rsp)
movzwl 0x22(%rsp), %eax
movl %eax, 0x40(%rsp)
movl 0x44(%rsp), %eax
movzwl 0x22(%rsp), %ecx
addl %ecx, %eax
subl $0x1, %eax
movl %eax, 0x3c(%rsp)
movb 0x26(%rsp), %al
movb %al, 0xf(%rsp)
movq 0x58(%rsp), %rax
movq 0x668(%rax), %rax
movq %rax, (%rsp)
movq 0x58(%rsp), %rax
movzwl 0x652(%rax), %ecx
movl 0x3c(%rsp), %eax
movq 0x58(%rsp), %rdx
movzwl 0x654(%rdx), %esi
cltd
idivl %esi
addl %eax, %ecx
movq 0x58(%rsp), %rax
movzwl 0x10(%rax), %eax
imull %eax, %ecx
movq 0x58(%rsp), %rax
movzwl 0x650(%rax), %eax
addl %eax, %ecx
movl 0x3c(%rsp), %eax
movq 0x58(%rsp), %rdx
movzwl 0x654(%rdx), %esi
cltd
idivl %esi
movq (%rsp), %rax
movl %edx, %esi
movb 0xf(%rsp), %dl
addl %esi, %ecx
movslq %ecx, %rcx
movb %dl, (%rax,%rcx)
movzwl 0x24(%rsp), %eax
cmpl $0xfff, %eax            # imm = 0xFFF
jne 0x44e5c
jmp 0x44e85
movq 0x28(%rsp), %rax
movq 0x8(%rax), %rax
movzwl 0x24(%rsp), %ecx
imulq $0x6, %rcx, %rcx
addq %rcx, %rax
movl (%rax), %ecx
movl %ecx, 0x22(%rsp)
movw 0x4(%rax), %ax
movw %ax, 0x26(%rsp)
jmp 0x44dc4
movl 0x40(%rsp), %eax
addl 0x44(%rsp), %eax
movl %eax, 0x44(%rsp)
movzwl 0x3a(%rsp), %eax
movq 0x28(%rsp), %rcx
movl 0x4(%rcx), %ecx
subl $0x1, %ecx
cmpl %ecx, %eax
jge 0x44ed1
cmpl $0x0, 0x48(%rsp)
jne 0x44ed1
movb 0x26(%rsp), %cl
movq 0x28(%rsp), %rax
movq 0x8(%rax), %rax
movq 0x28(%rsp), %rdx
movl 0x4(%rdx), %edx
subl $0x1, %edx
movslq %edx, %rdx
imulq $0x6, %rdx, %rdx
addq %rdx, %rax
movb %cl, 0x4(%rax)
jmp 0x44c93
movq 0x28(%rsp), %rdi
callq 0x3470
movq 0x58(%rsp), %rax
movl (%rax), %edi
leaq 0x57(%rsp), %rsi
movl $0x1, %edx
callq 0x3520
movq 0x58(%rsp), %rax
movl (%rax), %edi
movq 0x10(%rsp), %rsi
xorl %edx, %edx
callq 0x36d0
movl $0x0, 0x64(%rsp)
movl 0x64(%rsp), %eax
addq $0x68, %rsp
retq
nopw (%rax,%rax)