// File: matthewarcus[P]mmps/image.cpp
// Function: Image::DrawLine(long, long, long, long, Rgb const&)
void Image::DrawLine(long x0, long y0, long x1, long y1, const Rgb& rgb)
{
  long nx = abs(x1 - x0) + 1;
  long ny = abs(y1 - y0) + 1;
  if (ny > nx) {
    int xinc = (x0 > x1) ? -1 : 1;
    int yinc = (y0 > y1) ? -1 : 1;
    long x = x0;
    long c = 0;
    for (long y = y0; y != y1+yinc; y+=yinc) {
      CheckSetRgb(x,y,rgb);
      if ((xinc == 1 && x > x1) || (xinc == -1 && x < x1) ) {
	fprintf(stderr, "Oops 1: %ld %ld %ld %ld %ld\n", x0, y0, x1, y1, x);
	error("Foo");
      }
      c += nx;
      if (c >= ny) {
	c -= ny;
	x += xinc;
      }
    }
  } else {
    int xinc = (x0 > x1) ? -1 : 1;
    int yinc = (y0 > y1) ? -1 : 1;
    long y = y0;
    long c = 0;
    for (long x = x0; x != x1+xinc; x+=xinc) {
      CheckSetRgb(x,y,rgb);
      if ((yinc == 1 && y > y1) || (yinc == -1 && y < y1) ) {
	fprintf(stderr, "Oops 2: %ld %ld %ld %ld %ld\n", x0, y0, x1, y1, y);
	error("Foo");
      }
      c += ny;
      if (c >= nx) {
	c -= nx;
	y += yinc;
      }
    }
  }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x90, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq %rcx, -0x20(%rbp)
movq %r8, -0x28(%rbp)
movq %r9, -0x30(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x88(%rbp)
movq -0x20(%rbp), %rdi
subq -0x10(%rbp), %rdi
callq 0x14310
addq $0x1, %rax
movq %rax, -0x38(%rbp)
movq -0x28(%rbp), %rdi
subq -0x18(%rbp), %rdi
callq 0x14310
addq $0x1, %rax
movq %rax, -0x40(%rbp)
movq -0x40(%rbp), %rax
cmpq -0x38(%rbp), %rax
jle 0x13c69
movq -0x10(%rbp), %rdx
movq -0x20(%rbp), %rsi
movl $0x1, %eax
movl $0xffffffff, %ecx       # imm = 0xFFFFFFFF
cmpq %rsi, %rdx
cmovgl %ecx, %eax
movl %eax, -0x44(%rbp)
movq -0x18(%rbp), %rdx
movq -0x28(%rbp), %rsi
movl $0x1, %eax
movl $0xffffffff, %ecx       # imm = 0xFFFFFFFF
cmpq %rsi, %rdx
cmovgl %ecx, %eax
movl %eax, -0x48(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0x50(%rbp)
movq $0x0, -0x58(%rbp)
movq -0x18(%rbp), %rax
movq %rax, -0x60(%rbp)
movq -0x60(%rbp), %rax
movq -0x28(%rbp), %rcx
movslq -0x48(%rbp), %rdx
addq %rdx, %rcx
cmpq %rcx, %rax
je 0x13c64
movq -0x88(%rbp), %rdi
movq -0x50(%rbp), %rsi
movq -0x60(%rbp), %rdx
movq -0x30(%rbp), %rcx
callq 0x14330
cmpl $0x1, -0x44(%rbp)
jne 0x13bd4
movq -0x50(%rbp), %rax
cmpq -0x20(%rbp), %rax
jg 0x13be4
cmpl $-0x1, -0x44(%rbp)
jne 0x13c20
movq -0x50(%rbp), %rax
cmpq -0x20(%rbp), %rax
jge 0x13c20
movq 0x93f5(%rip), %rax      # 0x1cfe0
movq (%rax), %rdi
movq -0x10(%rbp), %rdx
movq -0x18(%rbp), %rcx
movq -0x20(%rbp), %r8
movq -0x28(%rbp), %r9
movq -0x50(%rbp), %rax
leaq 0x1ec9(%rip), %rsi      # 0x15ad2
movq %rax, (%rsp)
movb $0x0, %al
callq 0x5370
leaq 0x1ed4(%rip), %rdi      # 0x15aef
callq 0xfea0
movq -0x38(%rbp), %rax
addq -0x58(%rbp), %rax
movq %rax, -0x58(%rbp)
movq -0x58(%rbp), %rax
cmpq -0x40(%rbp), %rax
jl 0x13c51
movq -0x40(%rbp), %rcx
movq -0x58(%rbp), %rax
subq %rcx, %rax
movq %rax, -0x58(%rbp)
movslq -0x44(%rbp), %rax
addq -0x50(%rbp), %rax
movq %rax, -0x50(%rbp)
jmp 0x13c53
movslq -0x48(%rbp), %rax
addq -0x60(%rbp), %rax
movq %rax, -0x60(%rbp)
jmp 0x13b94
jmp 0x13d89
movq -0x10(%rbp), %rdx
movq -0x20(%rbp), %rsi
movl $0x1, %eax
movl $0xffffffff, %ecx       # imm = 0xFFFFFFFF
cmpq %rsi, %rdx
cmovgl %ecx, %eax
movl %eax, -0x64(%rbp)
movq -0x18(%rbp), %rdx
movq -0x28(%rbp), %rsi
movl $0x1, %eax
movl $0xffffffff, %ecx       # imm = 0xFFFFFFFF
cmpq %rsi, %rdx
cmovgl %ecx, %eax
movl %eax, -0x68(%rbp)
movq -0x18(%rbp), %rax
movq %rax, -0x70(%rbp)
movq $0x0, -0x78(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0x80(%rbp)
movq -0x80(%rbp), %rax
movq -0x20(%rbp), %rcx
movslq -0x64(%rbp), %rdx
addq %rdx, %rcx
cmpq %rcx, %rax
je 0x13d87
movq -0x88(%rbp), %rdi
movq -0x80(%rbp), %rsi
movq -0x70(%rbp), %rdx
movq -0x30(%rbp), %rcx
callq 0x14330
cmpl $0x1, -0x68(%rbp)
jne 0x13cf7
movq -0x70(%rbp), %rax
cmpq -0x28(%rbp), %rax
jg 0x13d07
cmpl $-0x1, -0x68(%rbp)
jne 0x13d43
movq -0x70(%rbp), %rax
cmpq -0x28(%rbp), %rax
jge 0x13d43
movq 0x92d2(%rip), %rax      # 0x1cfe0
movq (%rax), %rdi
movq -0x10(%rbp), %rdx
movq -0x18(%rbp), %rcx
movq -0x20(%rbp), %r8
movq -0x28(%rbp), %r9
movq -0x70(%rbp), %rax
leaq 0x1dc7(%rip), %rsi      # 0x15af3
movq %rax, (%rsp)
movb $0x0, %al
callq 0x5370
leaq 0x1db1(%rip), %rdi      # 0x15aef
callq 0xfea0
movq -0x40(%rbp), %rax
addq -0x78(%rbp), %rax
movq %rax, -0x78(%rbp)
movq -0x78(%rbp), %rax
cmpq -0x38(%rbp), %rax
jl 0x13d74
movq -0x38(%rbp), %rcx
movq -0x78(%rbp), %rax
subq %rcx, %rax
movq %rax, -0x78(%rbp)
movslq -0x68(%rbp), %rax
addq -0x70(%rbp), %rax
movq %rax, -0x70(%rbp)
jmp 0x13d76
movslq -0x64(%rbp), %rax
addq -0x80(%rbp), %rax
movq %rax, -0x80(%rbp)
jmp 0x13cb7
jmp 0x13d89
addq $0x90, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)