// File: essarrdee[P]mutantaliens/mutantaliens.cpp
// Function: draw_line(int, int, int, int, char)
void draw_line(int x1, int y1, int x2, int y2, char ch)
{
    // if x1 == x2 or y1 == y2, then it does not matter what we set here
	int col = COLOR_BLUE;
	if(on_map(x2,y2))
	{
		if(map_occupants[x2][y2] != NULL && sym_los_in_range(x1,y1,x2,y2,blocks_shots))
		{
			col = COLOR_CYAN;
		}
	}
    int delta_x(x2 - x1);
    signed char ix((delta_x > 0) - (delta_x < 0));
    delta_x = std::abs(delta_x) << 1;

 
    int delta_y(y2 - y1);
    signed char iy((delta_y > 0) - (delta_y < 0));
    delta_y = std::abs(delta_y) << 1;

 
    if (delta_x >= delta_y)
    {
        // error may go below zero
        int error(delta_y - (delta_x >> 1));
 
        while (x1 != x2)
        {
            if (error >= 0)
            {
                if (error || (ix > 0))
                {
                    y1 += iy;
                    error -= delta_x;
                }
                // else do nothing
            }
            // else do nothing
 
            x1 += ix;
            error += delta_y;
			if (blocks_shots(x1,y1)) {col = COLOR_RED;}
			draw_ch(x1,y1,ch,col);
        }
    }
    else
    {
        // error may go below zero
        int error(delta_x - (delta_y >> 1));
 
        while (y1 != y2)
        {
            if (error >= 0)
            {
                if (error || (iy > 0))
                {
                    x1 += ix;
                    error -= delta_y;
                }
                // else do nothing
            }
            // else do nothing
 
            y1 += iy;
            error += delta_x;
			if (blocks_shots(x1,y1)) {col = COLOR_RED;}
			draw_ch(x1,y1,ch,col);
        }
    }
	move(y2,x2-1);
}

// Assembly:
subq $0x38, %rsp
movb %r8b, %al
movl %edi, 0x34(%rsp)
movl %esi, 0x30(%rsp)
movl %edx, 0x2c(%rsp)
movl %ecx, 0x28(%rsp)
movb %al, 0x27(%rsp)
movl $0x4, 0x20(%rsp)
movl 0x2c(%rsp), %edi
movl 0x28(%rsp), %esi
callq 0x20770
testb $0x1, %al
jne 0x17266
jmp 0x172b4
movslq 0x2c(%rsp), %rcx
leaq 0x712ee(%rip), %rax     # 0x88560
imulq $0x4b0, %rcx, %rcx      # imm = 0x4B0
addq %rcx, %rax
movslq 0x28(%rsp), %rcx
cmpq $0x0, (%rax,%rcx,8)
je 0x172b2
movl 0x34(%rsp), %edi
movl 0x30(%rsp), %esi
movl 0x2c(%rsp), %edx
movl 0x28(%rsp), %ecx
leaq -0x3fcf(%rip), %r8      # 0x132d0
callq 0x213d0
testb $0x1, %al
jne 0x172aa
jmp 0x172b2
movl $0x6, 0x20(%rsp)
jmp 0x172b4
movl 0x2c(%rsp), %eax
subl 0x34(%rsp), %eax
movl %eax, 0x1c(%rsp)
cmpl $0x0, 0x1c(%rsp)
setg %al
andb $0x1, %al
movzbl %al, %eax
cmpl $0x0, 0x1c(%rsp)
setl %cl
andb $0x1, %cl
movzbl %cl, %ecx
subl %ecx, %eax
movb %al, 0x1b(%rsp)
movl 0x1c(%rsp), %eax
movl %eax, %ecx
negl %ecx
cmovnsl %ecx, %eax
shll %eax
movl %eax, 0x1c(%rsp)
movl 0x28(%rsp), %eax
subl 0x30(%rsp), %eax
movl %eax, 0x14(%rsp)
cmpl $0x0, 0x14(%rsp)
setg %al
andb $0x1, %al
movzbl %al, %eax
cmpl $0x0, 0x14(%rsp)
setl %cl
andb $0x1, %cl
movzbl %cl, %ecx
subl %ecx, %eax
movb %al, 0x13(%rsp)
movl 0x14(%rsp), %eax
movl %eax, %ecx
negl %ecx
cmovnsl %ecx, %eax
shll %eax
movl %eax, 0x14(%rsp)
movl 0x1c(%rsp), %eax
cmpl 0x14(%rsp), %eax
jl 0x173e7
movl 0x14(%rsp), %eax
movl 0x1c(%rsp), %ecx
sarl %ecx
subl %ecx, %eax
movl %eax, 0xc(%rsp)
movl 0x34(%rsp), %eax
cmpl 0x2c(%rsp), %eax
je 0x173e2
cmpl $0x0, 0xc(%rsp)
jl 0x17391
cmpl $0x0, 0xc(%rsp)
jne 0x17374
movsbl 0x1b(%rsp), %eax
cmpl $0x0, %eax
jle 0x1738f
movsbl 0x13(%rsp), %eax
addl 0x30(%rsp), %eax
movl %eax, 0x30(%rsp)
movl 0x1c(%rsp), %ecx
movl 0xc(%rsp), %eax
subl %ecx, %eax
movl %eax, 0xc(%rsp)
jmp 0x17391
movsbl 0x1b(%rsp), %eax
addl 0x34(%rsp), %eax
movl %eax, 0x34(%rsp)
movl 0x14(%rsp), %eax
addl 0xc(%rsp), %eax
movl %eax, 0xc(%rsp)
movl 0x34(%rsp), %edi
movl 0x30(%rsp), %esi
callq 0x132d0
testb $0x1, %al
jne 0x173bd
jmp 0x173c5
movl $0x1, 0x20(%rsp)
movl 0x34(%rsp), %edi
movl 0x30(%rsp), %esi
movb 0x27(%rsp), %al
movl 0x20(%rsp), %ecx
movsbl %al, %edx
callq 0x21460
jmp 0x1734e
jmp 0x1748d
movl 0x1c(%rsp), %eax
movl 0x14(%rsp), %ecx
sarl %ecx
subl %ecx, %eax
movl %eax, 0x8(%rsp)
movl 0x30(%rsp), %eax
cmpl 0x28(%rsp), %eax
je 0x1748b
cmpl $0x0, 0x8(%rsp)
jl 0x1743a
cmpl $0x0, 0x8(%rsp)
jne 0x1741d
movsbl 0x13(%rsp), %eax
cmpl $0x0, %eax
jle 0x17438
movsbl 0x1b(%rsp), %eax
addl 0x34(%rsp), %eax
movl %eax, 0x34(%rsp)
movl 0x14(%rsp), %ecx
movl 0x8(%rsp), %eax
subl %ecx, %eax
movl %eax, 0x8(%rsp)
jmp 0x1743a
movsbl 0x13(%rsp), %eax
addl 0x30(%rsp), %eax
movl %eax, 0x30(%rsp)
movl 0x1c(%rsp), %eax
addl 0x8(%rsp), %eax
movl %eax, 0x8(%rsp)
movl 0x34(%rsp), %edi
movl 0x30(%rsp), %esi
callq 0x132d0
testb $0x1, %al
jne 0x17466
jmp 0x1746e
movl $0x1, 0x20(%rsp)
movl 0x34(%rsp), %edi
movl 0x30(%rsp), %esi
movb 0x27(%rsp), %al
movl 0x20(%rsp), %ecx
movsbl %al, %edx
callq 0x21460
jmp 0x173f7
jmp 0x1748d
movl 0x28(%rsp), %edi
movl 0x2c(%rsp), %esi
subl $0x1, %esi
callq 0x5230
addq $0x38, %rsp
retq
nopw %cs:(%rax,%rax)