// File: /workspace/github_cpp_makefile_star2_O2/matthewarcus[P]mmps/testimage.cpp
// Function: main
int main(int argc, char* argv[])
{
  int width = 360;
  int height = 180;
  int equalarea = false;

  char *progname = argv[0];
  argc--;argv++;
  while (argc > 0) {
    if (strcmp(argv[0],"-w") == 0) {
      argc--; argv++;
      if (argc == 0) { error(usage, progname); };
      width = atoi(argv[0]);
    } else if (strcmp(argv[0], "-h") == 0) {
      argc--; argv++;
      if (argc == 0) { error(usage, progname); };
      height = atoi(argv[0]);
    } else if (strcmp(argv[0], "-bg") == 0) {
      argc--; argv++;
      if (argc == 0) { error(usage, progname); };
      int r,g,b;
      sscanf(argv[0],"%d:%d:%d",&r,&g,&b);
      background.r = r;
      background.g = g;
      background.b = b;
    } else if (strcmp(argv[0], "-fg") == 0) {
      argc--; argv++;
      if (argc == 0) { error(usage, progname); };
      int r,g,b;
      sscanf(argv[0],"%d:%d:%d",&r,&g,&b);
      foreground.r = r;
      foreground.g = g;
      foreground.b = b;
    } else if (strcmp(argv[0], "-equalarea") == 0) {
      equalarea = true;
    } else {
      error(usage, progname);
    }
    argc--; argv++;
  }

  Image outImage;
  outImage.Create(width, height);
  outImage.Fill(0); // Set to all black

#if 0
  for (int i = 0; i < 62; i+=1) {
    double x0 = cos(i * 2 * pi/64);
    double y0 = sin(i * 2 * pi/64);
    double x1 = cos((i + 1) * 2 * pi/64);
    double y1 = sin((i + 1) * 2 * pi/64);
    x0 *= 200;
    y0 *= 200;
    x1 *= 200;
    y1 *= 200;

    if (i%2 == 1) {
      x0 += 200;
      y0 += 200;
      x1 += 200;
      y1 += 200;
    } else {
      x0 += 196;
      y0 += 196;
      x1 += 196;
      y1 += 196;
    }

    outImage.DrawLine(x0,y0,x1,y1,Rgb(255,0,0));
  }
#endif
#if 0
  SpiralPlotter plotter;
  CirclePlotter plotter2;
  TanPlotter plotter3;
  ThingPlotter plotter4(10,11);
  ThingPlotter plotter5(9,17);
  outImage.PlotLine(0, pi/2, plotter, Rgb(0,0,255));
  outImage.PlotLine(0, 2 * pi, plotter2, Rgb(0,255,0));
  outImage.PlotLine(-2*pi, 2*pi, plotter3, Rgb(255,0,0));
  outImage.PlotLine(0, 2 * pi, plotter4, Rgb(0,255,255), 197);
  outImage.PlotLine(0, 2 * pi, plotter5, Rgb(255,0,255), 197);
#endif
#if 0
  for (int i = 0; i < 20; i++) {
    outImage.DrawLine(0, 0, 200, i * 10, Rgb(255,0,0));
    outImage.DrawLine(i * 10, 0, 0, 200, Rgb(0,255,0));
  }
#endif

#if 1
  if (equalarea) {
    double xsize = width / 36.0;
    int ysize = height / 18;
    int index, x, y;
    for (index = 0, y = 0; y < height; y++) {
      double k = cos (pi * (0.5 * height - y)/height);
      for (x = 0; x < width; x++, index++) {
	double realx = k * (0.5 * width - x);
	bool neg = (realx < 0.0);
	realx = fabs(realx);
	int i = int(floor(realx/xsize))%2;
	if (neg) i = 1 - i;
	if (i == (y/ysize)%2){
	  outImage.SetRgb(index,foreground);
	} else {
	  outImage.SetRgb(index,background);
	}
    }
    }
  } else {
    int xsize = width / 36;
    int ysize = height / 18;
    int index = 0;
    for (int y = 0; y < height; y++) {
      for (int x = 0; x < width; x++, index++) {
	if ((x/xsize)%2 == (y/ysize)%2) {
	  outImage.SetRgb(index,foreground);
	} else {
	  outImage.SetRgb(index,background);
	}
      }
    }
  }
#endif
  outImage.Write(NULL);
  return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xd8, %rsp
movq %rsi, %r13
movl %edi, %r14d
movq (%rsi), %r15
movl $0x168, %ebx            # imm = 0x168
movl $0xb4, 0x1c(%rsp)
movb $0x1, %al
movl %eax, 0x28(%rsp)
movq %r13, %rbp
cmpl $0x2, %r14d
jl 0x46bc
leaq 0x8(%rbp), %r13
movq (%r13), %r12
cmpb $0x2d, (%r12)
jne 0x454d
cmpb $0x77, 0x1(%r12)
jne 0x4539
cmpb $0x0, 0x2(%r12)
je 0x4631
cmpb $0x68, 0x1(%r12)
jne 0x454d
cmpb $0x0, 0x2(%r12)
je 0x465a
movq %r12, %rdi
leaq 0x7b02(%rip), %rsi      # 0xc059
callq 0x4280
testl %eax, %eax
je 0x45d4
movq %r12, %rdi
leaq 0x7afc(%rip), %rsi      # 0xc066
callq 0x4280
testl %eax, %eax
jne 0x4685
addl $-0x2, %r14d
jne 0x458c
movq 0xdc6c(%rip), %rdi      # 0x121f0
movq %r15, %rsi
callq 0x4a0b
addq $0x10, %rbp
movq (%rbp), %rdi
leaq 0x7ac2(%rip), %rsi      # 0xc05d
leaq 0x38(%rsp), %rdx
leaq 0x24(%rsp), %rcx
leaq 0x20(%rsp), %r8
xorl %eax, %eax
callq 0x4200
movb 0x38(%rsp), %al
movb %al, 0xdc4e(%rip)       # 0x12209
movb 0x24(%rsp), %al
movb %al, 0xdc45(%rip)       # 0x1220a
movb 0x20(%rsp), %al
movb %al, 0xdc3c(%rip)       # 0x1220b
jmp 0x450c
addl $-0x2, %r14d
jne 0x45e9
movq 0xdc0f(%rip), %rdi      # 0x121f0
movq %r15, %rsi
callq 0x4a0b
addq $0x10, %rbp
movq (%rbp), %rdi
leaq 0x7a65(%rip), %rsi      # 0xc05d
leaq 0x38(%rsp), %rdx
leaq 0x24(%rsp), %rcx
leaq 0x20(%rsp), %r8
xorl %eax, %eax
callq 0x4200
movb 0x38(%rsp), %al
movb %al, 0xdbd0(%rip)       # 0x121e8
movb 0x24(%rsp), %al
movb %al, 0xdbc7(%rip)       # 0x121e9
movb 0x20(%rsp), %al
movb %al, 0xdbbe(%rip)       # 0x121ea
jmp 0x450c
addl $-0x2, %r14d
jne 0x4646
movq 0xdbb2(%rip), %rdi      # 0x121f0
movq %r15, %rsi
callq 0x4a0b
addq $0x10, %rbp
movq (%rbp), %rdi
callq 0x42c0
movl %eax, %ebx
jmp 0x450c
addl $-0x2, %r14d
jne 0x466f
movq 0xdb89(%rip), %rdi      # 0x121f0
movq %r15, %rsi
callq 0x4a0b
addq $0x10, %rbp
movq (%rbp), %rdi
callq 0x42c0
movl %eax, 0x1c(%rsp)
jmp 0x450c
decl %r14d
movq %r12, %rdi
leaq 0x79d8(%rip), %rsi      # 0xc06a
callq 0x4280
testl %eax, %eax
je 0x46af
movq 0xdb4e(%rip), %rdi      # 0x121f0
movq %r15, %rsi
callq 0x4a0b
jmp 0x4509
movl $0x0, 0x28(%rsp)
jmp 0x4509
leaq 0x38(%rsp), %r14
movq %r14, %rdi
xorl %esi, %esi
xorl %edx, %edx
callq 0xa346
movslq %ebx, %rsi
movslq 0x1c(%rsp), %rdx
movq %r14, %rdi
callq 0xa360
movq 0x40(%rsp), %rax
movq 0x48(%rsp), %rdi
imulq 0x38(%rsp), %rax
leaq (%rax,%rax,2), %rdx
xorl %r14d, %r14d
xorl %esi, %esi
callq 0x4100
testb $0x1, 0x28(%rsp)
je 0x47de
pushq $0x24
popq %rcx
movl %ebx, %eax
cltd
idivl %ecx
movl %eax, %ecx
pushq $0x12
popq %rsi
movl 0x1c(%rsp), %edi
movl %edi, %eax
cltd
idivl %esi
movl %eax, %esi
xorl %eax, %eax
testl %ebx, %ebx
cmovlel %eax, %ebx
testl %edi, %edi
cmovlel %eax, %edi
movl %edi, 0x1c(%rsp)
pushq $0x2
popq %r11
leaq 0xdaaf(%rip), %r14      # 0x121e8
leaq 0xdaca(%rip), %r15      # 0x1220a
leaq 0xdaa2(%rip), %r12      # 0x121e9
leaq 0xdabd(%rip), %r13      # 0x1220b
leaq 0xda95(%rip), %rbp      # 0x121ea
xorl %edi, %edi
cmpl 0x1c(%rsp), %edi
je 0x49cc
cltq
movq %rax, 0x28(%rsp)
leaq (%rax,%rax,2), %r10
addq $0x2, %r10
xorl %r8d, %r8d
cmpl %r8d, %ebx
je 0x47cf
movl %r8d, %eax
cltd
idivl %ecx
cltd
idivl %r11d
movl %edx, %r9d
movl %edi, %eax
cltd
idivl %esi
cltd
idivl %r11d
cmpl %edx, %r9d
movq 0x48(%rsp), %rax
movq %r14, %rdx
leaq 0xda69(%rip), %r9       # 0x12209
cmoveq %r9, %rdx
movb (%rdx), %dl
movb %dl, -0x2(%rax,%r10)
movq %r12, %rdx
cmoveq %r15, %rdx
movb (%rdx), %dl
movb %dl, -0x1(%rax,%r10)
movq %rbp, %rdx
cmoveq %r13, %rdx
movb (%rdx), %dl
movb %dl, (%rax,%r10)
incq %r8
addq $0x3, %r10
jmp 0x4773
incl %edi
movq 0x28(%rsp), %rax
addq %r8, %rax
jmp 0x4757
cvtsi2sd %ebx, %xmm0
movapd %xmm0, %xmm1
divsd 0x781a(%rip), %xmm1     # 0xc008
movsd %xmm1, 0x88(%rsp)
pushq $0x12
popq %rcx
movl 0x1c(%rsp), %esi
movl %esi, %eax
cltd
idivl %ecx
movl %eax, %r15d
cvtsi2sd %esi, %xmm1
movl %esi, 0x34(%rsp)
fildl 0x34(%rsp)
fstpt 0xb4(%rsp)
testl %ebx, %ebx
cmovlel %r14d, %ebx
movq %rbx, 0x70(%rsp)
testl %esi, %esi
cmovlel %r14d, %esi
movl %esi, 0x1c(%rsp)
mulsd 0x77da(%rip), %xmm1     # 0xc010
movsd %xmm1, 0x68(%rsp)
mulsd 0x77cc(%rip), %xmm0     # 0xc010
movsd %xmm0, 0x90(%rsp)
pushq $0x2
popq %rbp
leaq 0xd993(%rip), %rbx      # 0x121ea
xorl %r12d, %r12d
xorpd %xmm1, %xmm1
cmpl 0x1c(%rsp), %r14d
je 0x49cc
movsd 0x68(%rsp), %xmm0
movsd %xmm1, 0x78(%rsp)
subsd %xmm1, %xmm0
movsd %xmm0, 0xa8(%rsp)
fldl 0xa8(%rsp)
fmull 0x7789(%rip)            # 0xc018
fldt 0xb4(%rsp)
fdivrp %st, %st(1)
fstpt (%rsp)
callq 0x4230
fstpl 0xa0(%rsp)
movsd 0xa0(%rsp), %xmm0
movsd %xmm0, 0x98(%rsp)
movslq %r12d, %r12
leaq (%r12,%r12,2), %r13
addq $0x2, %r13
movq 0x70(%rsp), %rax
addq %rax, %r12
movq %r12, 0x80(%rsp)
xorpd %xmm0, %xmm0
movl %eax, %r12d
subl $0x1, %r12d
jb 0x49ae
movsd 0x90(%rsp), %xmm1
subsd %xmm0, %xmm1
mulsd 0x98(%rsp), %xmm1
movapd %xmm1, 0xc0(%rsp)
movsd %xmm0, 0x28(%rsp)
movapd %xmm1, %xmm0
andpd 0x771a(%rip), %xmm0     # 0xc030
divsd 0x88(%rsp), %xmm0
callq 0x4320
cvttsd2si %xmm0, %eax
cltd
idivl %ebp
pushq $0x1
popq %rcx
subl %edx, %ecx
xorpd %xmm0, %xmm0
ucomisd 0xc0(%rsp), %xmm0
movsd 0x28(%rsp), %xmm0
cmovbel %edx, %ecx
movl %r14d, %eax
cltd
idivl %r15d
cltd
idivl %ebp
cmpl %edx, %ecx
movq 0x48(%rsp), %rax
leaq 0xd88a(%rip), %rcx      # 0x121e8
leaq 0xd8a4(%rip), %rdx      # 0x12209
cmoveq %rdx, %rcx
movb (%rcx), %cl
movb %cl, -0x2(%rax,%r13)
leaq 0xd872(%rip), %rcx      # 0x121e9
leaq 0xd88c(%rip), %rdx      # 0x1220a
cmoveq %rdx, %rcx
movb (%rcx), %cl
movb %cl, -0x1(%rax,%r13)
movq %rbx, %rcx
leaq 0xd878(%rip), %rdx      # 0x1220b
cmoveq %rdx, %rcx
movb (%rcx), %cl
movb %cl, (%rax,%r13)
addsd 0x767b(%rip), %xmm0     # 0xc020
addq $0x3, %r13
jmp 0x48db
movsd 0x78(%rsp), %xmm1
addsd 0x7664(%rip), %xmm1     # 0xc020
incl %r14d
movq 0x80(%rsp), %r12
jmp 0x485e
leaq 0x38(%rsp), %rdi
xorl %esi, %esi
callq 0xa6d2
leaq 0x38(%rsp), %rdi
callq 0xa37e
xorl %eax, %eax
addq $0xd8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %rbx
leaq 0x38(%rsp), %rdi
callq 0xa37e
movq %rbx, %rdi
callq 0x4340