// File: /workspace/github_c_makefile_star2_O0/lecram[P]congif/gif.c
// Function: new_gif
GIF *
new_gif(const char *fname, uint16_t w, uint16_t h, uint8_t *gct, int loop)
{
    GIF *gif = calloc(1, sizeof(*gif) + 2*w*h);
    if (!gif)
        goto no_gif;
    gif->w = w; gif->h = h;
    gif->cur = (uint8_t *) &gif[1];
    gif->old = &gif->cur[w*h];
    /* fill back-buffer with invalid pixels to force overwrite */
    memset(gif->old, 0x10, w*h);
    gif->fd = creat(fname, 0666);
    if (gif->fd == -1)
        goto no_fd;
    write(gif->fd, "GIF89a", 6);
    write_num(gif->fd, w);
    write_num(gif->fd, h);
    write(gif->fd, (uint8_t []) {0xF3, 0x00, 0x00}, 3);
    write(gif->fd, gct, 0x30);
    if (loop >= 0 && loop <= 0xFFFF)
        put_loop(gif, (uint16_t) loop);
    return gif;
no_fd:
    free(gif);
no_gif:
    return NULL;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x40, %rsp
movw %dx, %ax
movw %si, %dx
movq %rdi, -0x10(%rbp)
movw %dx, -0x12(%rbp)
movw %ax, -0x14(%rbp)
movq %rcx, -0x20(%rbp)
movl %r8d, -0x24(%rbp)
movzwl -0x12(%rbp), %eax
shll %eax
movzwl -0x14(%rbp), %ecx
imull %ecx, %eax
movslq %eax, %rsi
addq $0x130, %rsi            # imm = 0x130
movl $0x1, %edi
callq 0x1120
movq %rax, -0x30(%rbp)
cmpq $0x0, -0x30(%rbp)
jne 0x48e3
jmp 0x4a48
movw -0x12(%rbp), %cx
movq -0x30(%rbp), %rax
movw %cx, (%rax)
movw -0x14(%rbp), %cx
movq -0x30(%rbp), %rax
movw %cx, 0x2(%rax)
movq -0x30(%rbp), %rcx
addq $0x130, %rcx            # imm = 0x130
movq -0x30(%rbp), %rax
movq %rcx, 0x10(%rax)
movq -0x30(%rbp), %rax
movq 0x10(%rax), %rcx
movzwl -0x12(%rbp), %eax
movzwl -0x14(%rbp), %edx
imull %edx, %eax
cltq
addq %rax, %rcx
movq -0x30(%rbp), %rax
movq %rcx, 0x18(%rax)
movq -0x30(%rbp), %rax
movq 0x18(%rax), %rdi
movzwl -0x12(%rbp), %eax
movzwl -0x14(%rbp), %ecx
imull %ecx, %eax
movslq %eax, %rdx
movl $0x10, %esi
callq 0x10c0
movq -0x10(%rbp), %rdi
movl $0x1b6, %esi            # imm = 0x1B6
callq 0x1200
movl %eax, %ecx
movq -0x30(%rbp), %rax
movl %ecx, 0x4(%rax)
movq -0x30(%rbp), %rax
cmpl $-0x1, 0x4(%rax)
jne 0x4973
jmp 0x4a3f
movq -0x30(%rbp), %rax
movl 0x4(%rax), %edi
leaq 0x2de7(%rip), %rsi      # 0x7768
movl $0x6, %edx
callq 0x1080
movq -0x30(%rbp), %rax
movl 0x4(%rax), %edi
movzwl -0x12(%rbp), %eax
andl $0xff, %eax
movb %al, -0x32(%rbp)
movzwl -0x12(%rbp), %eax
sarl $0x8, %eax
movb %al, -0x31(%rbp)
leaq -0x32(%rbp), %rsi
movl $0x2, %edx
callq 0x1080
movq -0x30(%rbp), %rax
movl 0x4(%rax), %edi
movzwl -0x14(%rbp), %eax
andl $0xff, %eax
movb %al, -0x34(%rbp)
movzwl -0x14(%rbp), %eax
sarl $0x8, %eax
movb %al, -0x33(%rbp)
leaq -0x34(%rbp), %rsi
movl $0x2, %edx
callq 0x1080
movq -0x30(%rbp), %rax
movl 0x4(%rax), %edi
movb $-0xd, -0x37(%rbp)
movb $0x0, -0x36(%rbp)
movb $0x0, -0x35(%rbp)
leaq -0x37(%rbp), %rsi
movl $0x3, %edx
callq 0x1080
movq -0x30(%rbp), %rax
movl 0x4(%rax), %edi
movq -0x20(%rbp), %rsi
movl $0x30, %edx
callq 0x1080
cmpl $0x0, -0x24(%rbp)
jl 0x4a35
cmpl $0xffff, -0x24(%rbp)    # imm = 0xFFFF
jg 0x4a35
movq -0x30(%rbp), %rdi
movl -0x24(%rbp), %eax
movzwl %ax, %esi
callq 0x4a60
movq -0x30(%rbp), %rax
movq %rax, -0x8(%rbp)
jmp 0x4a50
movq -0x30(%rbp), %rdi
callq 0x1030
movq $0x0, -0x8(%rbp)
movq -0x8(%rbp), %rax
addq $0x40, %rsp
popq %rbp
retq
nopw (%rax,%rax)