// File: /workspace/github_cpp_makefile_star2_O2/cloudinary[P]fuif/./import/read_gif.h
// Function: read_GIF_file(char const*)
Image read_GIF_file(const char *filename) {
    gd_GIF *gif;
    gif = gd_open_gif(filename);
    if (!gif) {
//        v_printf(3,"%s could not be loaded as GIF\n",filename);
        return Image();
    }
    int w = gif->width;
    int h = gif->height;
    uint8_t *frame = (uint8_t*) calloc(1, w * h * 4);

    Image image(w, h, 255, 4);
    image.den=100;
    int ret = 1;
    int f = 0;
    while (ret) {
        ret = gd_get_frame(gif);
        if (ret < 1) break;

        // make room
        image.channel[0].resize(w, h+h*f);
        image.channel[1].resize(w, h+h*f);
        image.channel[2].resize(w, h+h*f);
        image.channel[3].resize(w, h+h*f);

        gd_render_frame(gif, frame);
        image.num.push_back(gif->gce.delay);
//        printf("Frame %i: ret=%i, delay=%i\n",f,ret,gif->gce.delay);

        for (int y=0; y<h; y++) {
            for (int x=0; x<w; x++) {
                image.channel[0].value(y+h*f,x) = frame[y*4*w+x*4];
                image.channel[1].value(y+h*f,x) = frame[y*4*w+x*4+1];
                image.channel[2].value(y+h*f,x) = frame[y*4*w+x*4+2];
                image.channel[3].value(y+h*f,x) = frame[y*4*w+x*4+3];
            }
        }
        f++;
    }
    free(frame);
    gd_close_gif(gif);
    image.nb_frames = f;
    image.h = h*f;

    return image;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x58, %rsp
movq %rdi, %rbx
movq %rsi, %rdi
callq 0x17003
testq %rax, %rax
je 0x16fd2
movzwl 0x10(%rax), %r12d
movq %rax, 0x10(%rsp)
movzwl 0x12(%rax), %r14d
leal (,%r12,4), %eax
movl %eax, 0x20(%rsp)
movl %eax, %esi
imull %r14d, %esi
pushq $0x1
popq %rdi
callq 0x3220
movq %rax, %r15
pushq $0x4
popq %r8
movq $0x0, 0x8(%rsp)
movq %rbx, %rdi
movl %r12d, %esi
movq %r14, 0x18(%rsp)
movl %r14d, %edx
movl $0xff, %ecx
xorl %r9d, %r9d
callq 0xfe5a
movl $0x64, 0x3c(%rbx)
leaq 0x40(%rbx), %rax
movq %rax, 0x30(%rsp)
movq %r15, 0x28(%rsp)
addq $0x3, %r15
movq %r15, 0x38(%rsp)
movq 0x10(%rsp), %rdi
callq 0x1720f
testl %eax, %eax
jle 0x16fa9
movq (%rbx), %rdi
movq 0x8(%rsp), %rcx
movq 0x18(%rsp), %rax
imulq %rax, %rcx
movq %rcx, 0x40(%rsp)
leal (%rax,%rcx), %ebp
movl %r12d, 0x18(%rdi)
movl %ebp, 0x1c(%rdi)
callq 0xa72e
movq (%rbx), %rax
leaq 0x40(%rax), %rdi
movl %r12d, 0x58(%rax)
movl %ebp, 0x5c(%rax)
callq 0xa72e
movq (%rbx), %rax
leaq 0x80(%rax), %rdi
movl %r12d, 0x98(%rax)
movl %ebp, 0x9c(%rax)
callq 0xa72e
movq (%rbx), %rax
leaq 0xc0(%rax), %rdi
movl %r12d, 0xd8(%rax)
movl %ebp, 0xdc(%rax)
callq 0xa72e
movq 0x10(%rsp), %r14
movq %r14, %rdi
movq 0x28(%rsp), %rsi
callq 0x17a4a
movzwl 0x18(%r14), %eax
movl %eax, 0x24(%rsp)
movq 0x30(%rsp), %rdi
leaq 0x24(%rsp), %rsi
callq 0xb266
xorl %eax, %eax
xorl %ecx, %ecx
cmpq 0x18(%rsp), %rcx
je 0x16f9f
movq %rax, 0x50(%rsp)
movslq %eax, %r15
addq 0x38(%rsp), %r15
movq 0x40(%rsp), %rax
movq %rcx, 0x48(%rsp)
leal (%rcx,%rax), %r13d
xorl %ebp, %ebp
cmpq %rbp, %r12
je 0x16f89
movzbl -0x3(%r15,%rbp,4), %r14d
movq (%rbx), %rdi
movl %r13d, %esi
movl %ebp, %edx
callq 0xa44a
movw %r14w, (%rax)
movzbl -0x2(%r15,%rbp,4), %r14d
movq (%rbx), %rdi
addq $0x40, %rdi
movl %r13d, %esi
movl %ebp, %edx
callq 0xa44a
movw %r14w, (%rax)
movzbl -0x1(%r15,%rbp,4), %r14d
movq (%rbx), %rdi
subq $-0x80, %rdi
movl %r13d, %esi
movl %ebp, %edx
callq 0xa44a
movw %r14w, (%rax)
movzbl (%r15,%rbp,4), %r14d
movq (%rbx), %rdi
movl $0xc0, %eax
addq %rax, %rdi
movl %r13d, %esi
movl %ebp, %edx
callq 0xa44a
movw %r14w, (%rax)
incq %rbp
jmp 0x16f14
movq 0x48(%rsp), %rcx
incq %rcx
movq 0x50(%rsp), %rax
addl 0x20(%rsp), %eax
jmp 0x16eec
incq 0x8(%rsp)
jmp 0x16e3c
movq 0x28(%rsp), %rdi
callq 0x33b0
movq 0x10(%rsp), %rdi
callq 0x17a80
movq 0x8(%rsp), %rcx
movl %ecx, 0x38(%rbx)
movq 0x18(%rsp), %rax
imull %ecx, %eax
movl %eax, 0x34(%rbx)
jmp 0x16fda
movq %rbx, %rdi
callq 0xd18a
movq %rbx, %rax
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x16ff0
jmp 0x16ff0
movq %rax, %r14
movq %rbx, %rdi
callq 0xa776
movq %r14, %rdi
callq 0x35d0