// File: /workspace/github_c_makefile_star2_O0/adelciotto[P]scg/examples/../scg.h
// Function: scg_image_draw_line
void scg_image_draw_line(scg_image_t *image, int x0, int y0, int x1, int y1,
                         scg_pixel_t color) {
    // Line is vertical
    if (x0 == x1) {
        if (y1 < y0) {
            int tmp = y1;
            y1 = y0;
            y0 = tmp;
        }

        for (int y = y0; y <= y1; y++) {
            scg_image_set_pixel(image, x0, y, color);
        }

        return;
    }

    // Line is horizontal
    if (y0 == y1) {
        if (x1 < x0) {
            int tmp = x1;
            x1 = x0;
            x0 = tmp;
        }

        for (int x = x0; x <= x1; x++) {
            scg_image_set_pixel(image, x, y0, color);
        }

        return;
    }

    int dx = abs(x1 - x0);
    int dy = abs(y1 - y0);

    int step_x = x0 < x1 ? 1 : -1;
    int step_y = y0 < y1 ? 1 : -1;
    int err = (dx > dy ? dx : -dy) / 2;
    int e2 = 0;

    for (;;) {
        scg_image_set_pixel(image, x0, y0, color);

        if (x0 == x1 && y0 == y1) {
            break;
        }

        e2 = err;
        if (e2 > -dx) {
            err -= dy;
            x0 += step_x;
        }
        if (e2 < dy) {
            err += dx;
            y0 += step_y;
        }
    }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x50, %rsp
movl %r9d, -0x4(%rbp)
movq %rdi, -0x10(%rbp)
movl %esi, -0x14(%rbp)
movl %edx, -0x18(%rbp)
movl %ecx, -0x1c(%rbp)
movl %r8d, -0x20(%rbp)
movl -0x14(%rbp), %eax
cmpl -0x1c(%rbp), %eax
jne 0x3aef
movl -0x20(%rbp), %eax
cmpl -0x18(%rbp), %eax
jge 0x3abf
movl -0x20(%rbp), %eax
movl %eax, -0x24(%rbp)
movl -0x18(%rbp), %eax
movl %eax, -0x20(%rbp)
movl -0x24(%rbp), %eax
movl %eax, -0x18(%rbp)
movl -0x18(%rbp), %eax
movl %eax, -0x28(%rbp)
movl -0x28(%rbp), %eax
cmpl -0x20(%rbp), %eax
jg 0x3aea
movq -0x10(%rbp), %rdi
movl -0x14(%rbp), %esi
movl -0x28(%rbp), %edx
movl -0x4(%rbp), %ecx
callq 0x2f60
movl -0x28(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x28(%rbp)
jmp 0x3ac5
jmp 0x3c24
movl -0x18(%rbp), %eax
cmpl -0x20(%rbp), %eax
jne 0x3b41
movl -0x1c(%rbp), %eax
cmpl -0x14(%rbp), %eax
jge 0x3b11
movl -0x1c(%rbp), %eax
movl %eax, -0x2c(%rbp)
movl -0x14(%rbp), %eax
movl %eax, -0x1c(%rbp)
movl -0x2c(%rbp), %eax
movl %eax, -0x14(%rbp)
movl -0x14(%rbp), %eax
movl %eax, -0x30(%rbp)
movl -0x30(%rbp), %eax
cmpl -0x1c(%rbp), %eax
jg 0x3b3c
movq -0x10(%rbp), %rdi
movl -0x30(%rbp), %esi
movl -0x18(%rbp), %edx
movl -0x4(%rbp), %ecx
callq 0x2f60
movl -0x30(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x30(%rbp)
jmp 0x3b17
jmp 0x3c24
movl -0x1c(%rbp), %eax
subl -0x14(%rbp), %eax
movl %eax, %ecx
negl %ecx
cmovnsl %ecx, %eax
movl %eax, -0x34(%rbp)
movl -0x20(%rbp), %eax
subl -0x18(%rbp), %eax
movl %eax, %ecx
negl %ecx
cmovnsl %ecx, %eax
movl %eax, -0x38(%rbp)
movl -0x14(%rbp), %edx
movl -0x1c(%rbp), %esi
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
movl $0x1, %ecx
cmpl %esi, %edx
cmovll %ecx, %eax
movl %eax, -0x3c(%rbp)
movl -0x18(%rbp), %edx
movl -0x20(%rbp), %esi
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
movl $0x1, %ecx
cmpl %esi, %edx
cmovll %ecx, %eax
movl %eax, -0x40(%rbp)
movl -0x34(%rbp), %eax
cmpl -0x38(%rbp), %eax
jle 0x3ba1
movl -0x34(%rbp), %eax
movl %eax, -0x4c(%rbp)
jmp 0x3ba9
xorl %eax, %eax
subl -0x38(%rbp), %eax
movl %eax, -0x4c(%rbp)
movl -0x4c(%rbp), %eax
movl $0x2, %ecx
cltd
idivl %ecx
movl %eax, -0x44(%rbp)
movl $0x0, -0x48(%rbp)
movq -0x10(%rbp), %rdi
movl -0x14(%rbp), %esi
movl -0x18(%rbp), %edx
movl -0x4(%rbp), %ecx
callq 0x2f60
movl -0x14(%rbp), %eax
cmpl -0x1c(%rbp), %eax
jne 0x3be2
movl -0x18(%rbp), %eax
cmpl -0x20(%rbp), %eax
jne 0x3be2
jmp 0x3c24
movl -0x44(%rbp), %eax
movl %eax, -0x48(%rbp)
movl -0x48(%rbp), %eax
xorl %ecx, %ecx
subl -0x34(%rbp), %ecx
cmpl %ecx, %eax
jle 0x3c08
movl -0x38(%rbp), %ecx
movl -0x44(%rbp), %eax
subl %ecx, %eax
movl %eax, -0x44(%rbp)
movl -0x3c(%rbp), %eax
addl -0x14(%rbp), %eax
movl %eax, -0x14(%rbp)
movl -0x48(%rbp), %eax
cmpl -0x38(%rbp), %eax
jge 0x3c22
movl -0x34(%rbp), %eax
addl -0x44(%rbp), %eax
movl %eax, -0x44(%rbp)
movl -0x40(%rbp), %eax
addl -0x18(%rbp), %eax
movl %eax, -0x18(%rbp)
jmp 0x3bbe
addq $0x50, %rsp
popq %rbp
retq
nopw (%rax,%rax)