// File: /workspace/github_c_makefile_star2_O0/Nealsbo[P]C-Software-Renderer/src/raster.c
// Function: Raster_DrawLine
void Raster_DrawLine(vec4 v0, vec4 v1, SDL_Surface *image, color_t color) {
    mat4 sst;
	mat4_screen ( sst, WINDOW_WIDTH / 2, WINDOW_HEIGHT / 2 );
    
    vec2i p0 = vec4_toVec2i( vec4_pdiv( vec4_byMat4( v0, sst ) ) );
    vec2i p1 = vec4_toVec2i( vec4_pdiv( vec4_byMat4( v1, sst ) ) );

    int x0 = p0.x;
    int y0 = p0.y;
    int x1 = p1.x;
    int y1 = p1.y;

    int deltax = abs( x1 - x0 );
    int deltay = abs( y1 - y0 );
    int signx = x0 < x1 ? 1 : -1;
    int signy = y0 < y1 ? 1 : -1;
    int error2, error = ( deltax > deltay ? deltax : -deltay ) / 2;

    while(1) {
        if( x0 >= 0 && y0 >= 0 && x0 < image->w && y0 < image->h )
            renderer_->PutPixel( image, x0, y0, Color_ToUInt32( color ) );
        if( x0 == x1 && y0 == y1 )
            break;

        error2 = error;
        if ( error2 >- deltax ){
            error -= deltay;
            x0    += signx;
        }
        if ( error2 <  deltay ){
            error += deltax;
            y0    += signy;
        }
    }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x110, %rsp            # imm = 0x110
movlpd %xmm0, -0x10(%rbp)
movlpd %xmm1, -0x8(%rbp)
movlpd %xmm2, -0x20(%rbp)
movlpd %xmm3, -0x18(%rbp)
movl %esi, -0x24(%rbp)
movq %rdi, -0x30(%rbp)
leaq -0x70(%rbp), %rdi
movq %rdi, -0xf0(%rbp)
movss 0x4067(%rip), %xmm0     # 0xebc0
movss 0x4063(%rip), %xmm1     # 0xebc4
callq 0x79c0
movq -0xf0(%rbp), %rdi
movsd -0x10(%rbp), %xmm0
movsd -0x8(%rbp), %xmm1
callq 0x55d0
movlpd %xmm0, -0x98(%rbp)
movlpd %xmm1, -0x90(%rbp)
movsd -0x98(%rbp), %xmm0
movsd -0x90(%rbp), %xmm1
callq 0x4ea0
movlpd %xmm0, -0x88(%rbp)
movlpd %xmm1, -0x80(%rbp)
movsd -0x88(%rbp), %xmm0
movsd -0x80(%rbp), %xmm1
callq 0x5560
movq -0xf0(%rbp), %rdi
movq %rax, -0x78(%rbp)
movsd -0x20(%rbp), %xmm0
movsd -0x18(%rbp), %xmm1
callq 0x55d0
movlpd %xmm0, -0xc0(%rbp)
movlpd %xmm1, -0xb8(%rbp)
movsd -0xc0(%rbp), %xmm0
movsd -0xb8(%rbp), %xmm1
callq 0x4ea0
movlpd %xmm0, -0xb0(%rbp)
movlpd %xmm1, -0xa8(%rbp)
movsd -0xb0(%rbp), %xmm0
movsd -0xa8(%rbp), %xmm1
callq 0x5560
movq %rax, -0xa0(%rbp)
movl -0x78(%rbp), %eax
movl %eax, -0xc4(%rbp)
movl -0x74(%rbp), %eax
movl %eax, -0xc8(%rbp)
movl -0xa0(%rbp), %eax
movl %eax, -0xcc(%rbp)
movl -0x9c(%rbp), %eax
movl %eax, -0xd0(%rbp)
movl -0xcc(%rbp), %eax
subl -0xc4(%rbp), %eax
movl %eax, %ecx
negl %ecx
cmovnsl %ecx, %eax
movl %eax, -0xd4(%rbp)
movl -0xd0(%rbp), %eax
subl -0xc8(%rbp), %eax
movl %eax, %ecx
negl %ecx
cmovnsl %ecx, %eax
movl %eax, -0xd8(%rbp)
movl -0xc4(%rbp), %edx
movl -0xcc(%rbp), %esi
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
movl $0x1, %ecx
cmpl %esi, %edx
cmovll %ecx, %eax
movl %eax, -0xdc(%rbp)
movl -0xc8(%rbp), %edx
movl -0xd0(%rbp), %esi
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
movl $0x1, %ecx
cmpl %esi, %edx
cmovll %ecx, %eax
movl %eax, -0xe0(%rbp)
movl -0xd4(%rbp), %eax
cmpl -0xd8(%rbp), %eax
jle 0xace5
movl -0xd4(%rbp), %eax
movl %eax, -0xf4(%rbp)
jmp 0xacf3
xorl %eax, %eax
subl -0xd8(%rbp), %eax
movl %eax, -0xf4(%rbp)
movl -0xf4(%rbp), %eax
movl $0x2, %ecx
cltd
idivl %ecx
movl %eax, -0xe8(%rbp)
cmpl $0x0, -0xc4(%rbp)
jl 0xad99
cmpl $0x0, -0xc8(%rbp)
jl 0xad99
movl -0xc4(%rbp), %eax
movq -0x30(%rbp), %rcx
cmpl 0x10(%rcx), %eax
jge 0xad99
movl -0xc8(%rbp), %eax
movq -0x30(%rbp), %rcx
cmpl 0x14(%rcx), %eax
jge 0xad99
leaq 0x84ee(%rip), %rax      # 0x13230
movq (%rax), %rax
movq 0x28(%rax), %rax
movq %rax, -0x100(%rbp)
movq -0x30(%rbp), %rax
movq %rax, -0x110(%rbp)
movl -0xc4(%rbp), %eax
movl %eax, -0x108(%rbp)
movl -0xc8(%rbp), %eax
movl %eax, -0x104(%rbp)
movl -0x24(%rbp), %edi
callq 0x3010
movq -0x110(%rbp), %rdi
movl -0x108(%rbp), %esi
movl -0x104(%rbp), %edx
movl %eax, %ecx
movq -0x100(%rbp), %rax
callq *%rax
movl -0xc4(%rbp), %eax
cmpl -0xcc(%rbp), %eax
jne 0xadb7
movl -0xc8(%rbp), %eax
cmpl -0xd0(%rbp), %eax
jne 0xadb7
jmp 0xae32
movl -0xe8(%rbp), %eax
movl %eax, -0xe4(%rbp)
movl -0xe4(%rbp), %eax
xorl %ecx, %ecx
subl -0xd4(%rbp), %ecx
cmpl %ecx, %eax
jle 0xadfb
movl -0xd8(%rbp), %ecx
movl -0xe8(%rbp), %eax
subl %ecx, %eax
movl %eax, -0xe8(%rbp)
movl -0xdc(%rbp), %eax
addl -0xc4(%rbp), %eax
movl %eax, -0xc4(%rbp)
movl -0xe4(%rbp), %eax
cmpl -0xd8(%rbp), %eax
jge 0xae2d
movl -0xd4(%rbp), %eax
addl -0xe8(%rbp), %eax
movl %eax, -0xe8(%rbp)
movl -0xe0(%rbp), %eax
addl -0xc8(%rbp), %eax
movl %eax, -0xc8(%rbp)
jmp 0xad07
addq $0x110, %rsp            # imm = 0x110
popq %rbp
retq
nopl (%rax,%rax)