// File: /workspace/github_cpp_makefile_star2_O2/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
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x58, %rsp
movq %r9, 0x50(%rsp)
movq %rcx, %r15
movq %rdx, %r12
movq %rsi, %r13
movq %rdi, 0x48(%rsp)
movq %rcx, %rax
subq %rsi, %rax
movq %rax, %rbx
negq %rbx
cmovsq %rax, %rbx
leaq 0x1(%rbx), %rax
movq %rax, 0x40(%rsp)
movq %r8, %rax
subq %rdx, %rax
movq %rax, %rbp
negq %rbp
cmovsq %rax, %rbp
leaq 0x1(%rbp), %rax
movq %rax, 0x38(%rsp)
cmpq %rbx, %rbp
movq %r8, 0x28(%rsp)
movq %rsi, 0x30(%rsp)
jbe 0xb440
xorl %eax, %eax
cmpq %r12, %r8
setge %al
xorl %ecx, %ecx
cmpq %r13, %r15
setge %cl
leaq -0x1(,%rax,2), %r14
leaq (%r8,%rax,2), %rax
decq %rax
movq %rax, 0x20(%rsp)
leaq -0x1(,%rcx,2), %rax
movq %rax, 0x18(%rsp)
movq %r12, 0x10(%rsp)
xorl %ebx, %ebx
cmpq %r12, 0x20(%rsp)
je 0xb51c
movq 0x48(%rsp), %rdi
movq %r13, %rsi
movq %r12, %rdx
movq 0x50(%rsp), %rcx
callq 0xb8cc
xorl %eax, %eax
xorl %ecx, %ecx
cmpq %r15, %r13
setg %al
setl %cl
movq 0x30(%rsp), %rdx
cmpq %rdx, %r15
cmovll %ecx, %eax
cmpb $0x1, %al
je 0xb409
addq 0x40(%rsp), %rbx
cmpq %rbp, %rbx
movl $0x0, %eax
cmovgq 0x38(%rsp), %rax
movl $0x0, %ecx
cmovgq 0x18(%rsp), %rcx
subq %rax, %rbx
addq %rcx, %r13
addq %r14, %r12
jmp 0xb3a4
movq 0x6bd0(%rip), %rax      # 0x11fe0
movq (%rax), %rdi
movq %r13, (%rsp)
leaq 0x1757(%rip), %rsi      # 0xcb75
movq 0x10(%rsp), %rcx
movq %r15, %r8
movq 0x28(%rsp), %r9
xorl %eax, %eax
callq 0x42b0
leaq 0x1759(%rip), %rdi      # 0xcb92
callq 0x9e20
jmp 0xb3e0
xorl %eax, %eax
cmpq %r12, %r8
setge %al
xorl %ecx, %ecx
cmpq %r13, %r15
setge %cl
leaq -0x1(,%rcx,2), %rdi
movq %rdi, 0x18(%rsp)
leaq (%r15,%rcx,2), %rcx
decq %rcx
movq %rcx, 0x20(%rsp)
leaq -0x1(,%rax,2), %rax
movq %rax, 0x10(%rsp)
movq %r12, %r14
xorl %ebp, %ebp
cmpq %r13, 0x20(%rsp)
je 0xb51c
movq 0x48(%rsp), %rdi
movq %r13, %rsi
movq %r12, %rdx
movq 0x50(%rsp), %rcx
callq 0xb8cc
xorl %eax, %eax
xorl %ecx, %ecx
movq 0x28(%rsp), %rdx
cmpq %rdx, %r12
setg %al
setl %cl
cmpq %r14, %rdx
cmovll %ecx, %eax
cmpb $0x1, %al
je 0xb4e2
addq 0x38(%rsp), %rbp
cmpq %rbx, %rbp
movl $0x0, %eax
cmovgq 0x10(%rsp), %rax
movl $0x0, %ecx
cmovgq 0x40(%rsp), %rcx
addq %rax, %r12
subq %rcx, %rbp
addq 0x18(%rsp), %r13
jmp 0xb47b
movq 0x6af7(%rip), %rax      # 0x11fe0
movq (%rax), %rdi
movq %r12, (%rsp)
leaq 0x169f(%rip), %rsi      # 0xcb96
movq 0x30(%rsp), %rdx
movq %r14, %rcx
movq %r15, %r8
movq 0x28(%rsp), %r9
xorl %eax, %eax
callq 0x42b0
leaq 0x167d(%rip), %rdi      # 0xcb92
callq 0x9e20
jmp 0xb4b7
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nop