// File: /workspace/github_cpp_makefile_star2_O3/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 $0x68, %rsp
movq %r8, %r10
movq %rcx, %r8
movq %rdx, %r11
movq %rdi, %rbp
movq %rcx, %rax
subq %rsi, %rax
movq %rax, %r12
negq %r12
cmovsq %rax, %r12
leaq 0x1(%r12), %rdi
movq %r10, %rax
subq %rdx, %rax
movq %rax, %rbx
negq %rbx
cmovsq %rax, %rbx
leaq 0x1(%rbx), %rdx
cmpq %r12, %rbx
movq %rdx, 0x40(%rsp)
jbe 0xc352
xorl %eax, %eax
cmpq %r11, %r10
setge %al
leaq (%r10,%rax,2), %rcx
decq %rcx
movq %rcx, 0x50(%rsp)
cmpq %r11, %rcx
je 0xc366
leaq -0x1(,%rax,2), %rax
movq %rax, 0x48(%rsp)
xorl %eax, %eax
cmpq %rsi, %r8
setge %al
leaq -0x1(,%rax,2), %r12
movq %rsi, %r14
xorl %r15d, %r15d
movq %r11, %r13
movq %r9, 0x38(%rsp)
movq %r10, 0x30(%rsp)
movq %r8, 0x18(%rsp)
movq %r11, 0x28(%rsp)
movq %rsi, 0x10(%rsp)
movq %rdi, 0x20(%rsp)
testq %r14, %r14
js 0xc2ab
testq %r13, %r13
js 0xc2ab
movq (%rbp), %rax
cmpq %r14, %rax
jle 0xc2ab
cmpq %r13, 0x8(%rbp)
jle 0xc2ab
imulq %r13, %rax
addq %r14, %rax
movq 0x10(%rbp), %rcx
addq %rax, %rcx
addq %rax, %rcx
movb (%r9), %dl
movb %dl, (%rcx,%rax)
movb 0x1(%r9), %dl
movb %dl, 0x1(%rcx,%rax)
movb 0x2(%r9), %dl
movb %dl, 0x2(%rcx,%rax)
movq 0x40(%rsp), %rdx
xorl %eax, %eax
xorl %ecx, %ecx
cmpq %r8, %r14
setg %al
setl %cl
cmpq %rsi, %r8
cmovll %ecx, %eax
cmpb $0x1, %al
je 0xc2f2
addq %rdi, %r15
cmpq %rbx, %r15
movl $0x0, %eax
cmovgq %rdx, %rax
movl $0x0, %ecx
cmovgq %r12, %rcx
subq %rax, %r15
addq %rcx, %r14
addq 0x48(%rsp), %r13
cmpq %r13, 0x50(%rsp)
jne 0xc266
jmp 0xc366
movq 0x6ce7(%rip), %rax      # 0x12fe0
movq (%rax), %rdi
movq %r14, (%rsp)
leaq 0x18ce(%rip), %rsi      # 0xdbd5
movq 0x10(%rsp), %rdx
movq %r11, %rcx
movq 0x18(%rsp), %r8
movq %r10, %r9
xorl %eax, %eax
callq 0x4280
leaq 0x18cd(%rip), %rdi      # 0xdbf2
callq 0xab5c
movq 0x40(%rsp), %rdx
movq 0x20(%rsp), %rdi
movq 0x10(%rsp), %rsi
movq 0x28(%rsp), %r11
movq 0x18(%rsp), %r8
movq 0x30(%rsp), %r10
movq 0x38(%rsp), %r9
jmp 0xc2c2
xorl %eax, %eax
cmpq %rsi, %r8
setge %al
leaq (%r8,%rax,2), %rcx
decq %rcx
cmpq %rsi, %rcx
jne 0xc375
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq -0x1(,%rax,2), %rcx
xorl %eax, %eax
cmpq %r11, %r10
setge %al
leaq -0x1(,%rax,2), %rax
movq %rax, 0x48(%rsp)
leaq (%rcx,%r8), %rax
subq %rsi, %rax
movq %rax, 0x60(%rsp)
leaq (%rsi,%rsi,2), %rbx
incq %rbx
movq %rcx, 0x50(%rsp)
leaq (%rcx,%rcx,2), %rax
movq %rax, 0x58(%rsp)
xorl %r14d, %r14d
xorl %r15d, %r15d
movq %r11, %r13
movq %r9, 0x38(%rsp)
movq %r10, 0x30(%rsp)
movq %r8, 0x18(%rsp)
movq %r11, 0x28(%rsp)
movq %rsi, 0x10(%rsp)
movq %rdi, 0x20(%rsp)
movq %rsi, %rcx
addq %r14, %rcx
js 0xc418
testq %r13, %r13
js 0xc418
movq (%rbp), %rax
cmpq %rcx, %rax
jle 0xc418
cmpq %r13, 0x8(%rbp)
jle 0xc418
imulq %r13, %rax
leaq (%rax,%rax,2), %rax
addq 0x10(%rbp), %rax
movb (%r9), %cl
movb %cl, -0x1(%rbx,%rax)
movb 0x1(%r9), %cl
movb %cl, (%rbx,%rax)
movb 0x2(%r9), %cl
movb %cl, 0x1(%rbx,%rax)
xorl %eax, %eax
xorl %ecx, %ecx
cmpq %r10, %r13
setg %al
setl %cl
cmpq %r11, %r10
cmovll %ecx, %eax
cmpb $0x1, %al
je 0xc469
addq %rdx, %r15
cmpq %r12, %r15
movl $0x0, %eax
cmovgq 0x48(%rsp), %rax
movl $0x0, %ecx
cmovgq %rdi, %rcx
addq %rax, %r13
subq %rcx, %r15
addq 0x50(%rsp), %r14
addq 0x58(%rsp), %rbx
cmpq %r14, 0x60(%rsp)
jne 0xc3da
jmp 0xc366
movq 0x6b70(%rip), %rax      # 0x12fe0
movq (%rax), %rdi
movq %r13, (%rsp)
leaq 0x1778(%rip), %rsi      # 0xdbf6
movq 0x10(%rsp), %rdx
movq %r11, %rcx
movq 0x18(%rsp), %r8
movq %r10, %r9
xorl %eax, %eax
callq 0x4280
leaq 0x1756(%rip), %rdi      # 0xdbf2
callq 0xab5c
movq 0x40(%rsp), %rdx
movq 0x20(%rsp), %rdi
movq 0x10(%rsp), %rsi
movq 0x28(%rsp), %r11
movq 0x30(%rsp), %r10
movq 0x38(%rsp), %r9
jmp 0xc42f