// File: shinerd[P]BriefRenderer/main.cpp
// Function: line(Vec2<int>, Vec2<int>, TGAImage&, TGAColor)
void line(Vec2i p0, Vec2i p1, TGAImage &image, TGAColor color) {
    bool steep = false;
    if (std::abs(p0.x-p1.x)<std::abs(p0.y-p1.y)) {
        std::swap(p0.x, p0.y);
        std::swap(p1.x, p1.y);
        steep = true;
    }
    if (p0.x>p1.x) {
        std::swap(p0, p1);
    }
    
    if (p0.x != p1.x) {
        for (int x=p0.x; x<=p1.x; x++) {
            float t = (x-p0.x)/(float)(p1.x-p0.x);
            int y = p0.y*(1.-t) + p1.y*t +0.5;
            if (steep) {
                image.set(y, x, color);
            } else {
                image.set(x, y, color);
            }
        }
    } else {
        for (int y=p0.y; y<=p1.y; y++) {
            image.set(p0.x, y, color);
        }
    }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x90, %rsp
movq %rcx, -0x58(%rbp)
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq %rcx, -0x20(%rbp)
movb $0x0, -0x21(%rbp)
movl -0x8(%rbp), %eax
subl -0x10(%rbp), %eax
movl %eax, %ecx
negl %ecx
cmovnsl %ecx, %eax
movl -0x4(%rbp), %ecx
subl -0xc(%rbp), %ecx
movl %ecx, %edx
negl %edx
cmovnsl %edx, %ecx
cmpl %ecx, %eax
jge 0x2707
leaq -0x8(%rbp), %rdi
leaq -0x8(%rbp), %rsi
addq $0x4, %rsi
callq 0x2f70
leaq -0x10(%rbp), %rdi
leaq -0x10(%rbp), %rsi
addq $0x4, %rsi
callq 0x2f70
movb $0x1, -0x21(%rbp)
movl -0x8(%rbp), %eax
cmpl -0x10(%rbp), %eax
jle 0x271c
leaq -0x8(%rbp), %rdi
leaq -0x10(%rbp), %rsi
callq 0x2fa0
movl -0x8(%rbp), %eax
cmpl -0x10(%rbp), %eax
je 0x281c
movl -0x8(%rbp), %eax
movl %eax, -0x28(%rbp)
movl -0x28(%rbp), %eax
cmpl -0x10(%rbp), %eax
jg 0x281a
movl -0x28(%rbp), %eax
subl -0x8(%rbp), %eax
cvtsi2ss %eax, %xmm0
movl -0x10(%rbp), %eax
subl -0x8(%rbp), %eax
cvtsi2ss %eax, %xmm1
divss %xmm1, %xmm0
movss %xmm0, -0x2c(%rbp)
cvtsi2sdl -0x4(%rbp), %xmm0
movss -0x2c(%rbp), %xmm1
cvtss2sd %xmm1, %xmm1
movsd 0x58a3(%rip), %xmm2     # 0x8010
subsd %xmm1, %xmm2
cvtsi2ssl -0xc(%rbp), %xmm1
mulss -0x2c(%rbp), %xmm1
cvtss2sd %xmm1, %xmm1
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
movsd 0x5879(%rip), %xmm1     # 0x8008
addsd %xmm1, %xmm0
cvttsd2si %xmm0, %eax
movl %eax, -0x30(%rbp)
testb $0x1, -0x21(%rbp)
je 0x27d6
movq -0x58(%rbp), %rsi
movq -0x18(%rbp), %rax
movq %rax, -0x68(%rbp)
movl -0x30(%rbp), %eax
movl %eax, -0x60(%rbp)
movl -0x28(%rbp), %eax
movl %eax, -0x5c(%rbp)
leaq -0x38(%rbp), %rdi
callq 0x2fe0
movq -0x68(%rbp), %rdi
movl -0x60(%rbp), %esi
movl -0x5c(%rbp), %edx
leaq -0x38(%rbp), %rcx
callq 0x7730
jmp 0x280a
movq -0x58(%rbp), %rsi
movq -0x18(%rbp), %rax
movq %rax, -0x78(%rbp)
movl -0x28(%rbp), %eax
movl %eax, -0x70(%rbp)
movl -0x30(%rbp), %eax
movl %eax, -0x6c(%rbp)
leaq -0x40(%rbp), %rdi
callq 0x2fe0
movq -0x78(%rbp), %rdi
movl -0x70(%rbp), %esi
movl -0x6c(%rbp), %edx
leaq -0x40(%rbp), %rcx
callq 0x7730
jmp 0x280c
movl -0x28(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x28(%rbp)
jmp 0x272e
jmp 0x2871
movl -0x4(%rbp), %eax
movl %eax, -0x44(%rbp)
movl -0x44(%rbp), %eax
cmpl -0xc(%rbp), %eax
jg 0x286f
movq -0x58(%rbp), %rsi
movq -0x18(%rbp), %rax
movq %rax, -0x88(%rbp)
movl -0x8(%rbp), %eax
movl %eax, -0x80(%rbp)
movl -0x44(%rbp), %eax
movl %eax, -0x7c(%rbp)
leaq -0x4c(%rbp), %rdi
callq 0x2fe0
movq -0x88(%rbp), %rdi
movl -0x80(%rbp), %esi
movl -0x7c(%rbp), %edx
leaq -0x4c(%rbp), %rcx
callq 0x7730
movl -0x44(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x44(%rbp)
jmp 0x2822
jmp 0x2871
addq $0x90, %rsp
popq %rbp
retq
nopw (%rax,%rax)