// File: /workspace/github_cpp_makefile_star2_O1/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 $0x4a8, %rsp            # imm = 0x4A8
cmpl $0x2, %edi
jl 0x4887
movq %rsi, %r14
movl %edi, %r15d
movq (%rsi), %rax
movq %rax, 0x18(%rsp)
movl $0xb4, %ebp
movl $0x168, %ebx            # imm = 0x168
leaq 0xa0(%rsp), %r12
movl $0x0, 0x40(%rsp)
movq 0x8(%r14), %r13
movq %r13, %rdi
leaq 0x79dd(%rip), %rsi      # 0xc059
callq 0x4260
testl %eax, %eax
je 0x4714
movq %r13, %rdi
leaq 0x79c9(%rip), %rsi      # 0xc05c
callq 0x4260
testl %eax, %eax
je 0x4750
movq %r13, %rdi
leaq 0x79b5(%rip), %rsi      # 0xc05f
callq 0x4260
testl %eax, %eax
je 0x478c
movq %r13, %rdi
leaq 0x79ab(%rip), %rsi      # 0xc06c
callq 0x4260
testl %eax, %eax
je 0x47fa
addq $0x8, %r14
decl %r15d
movq %r13, %rdi
leaq 0x7991(%rip), %rsi      # 0xc070
callq 0x4260
testl %eax, %eax
je 0x4868
movq 0xdaed(%rip), %rdx      # 0x121e0
movl $0x400, %esi            # imm = 0x400
movq %r12, %rdi
movq 0x18(%rsp), %rcx
xorl %eax, %eax
callq 0x42b0
movq %r12, %rdi
callq 0xa0d8
jmp 0x4870
addl $-0x2, %r15d
jne 0x473d
movq 0xdabf(%rip), %rdx      # 0x121e0
movl $0x400, %esi            # imm = 0x400
movq %r12, %rdi
movq 0x18(%rsp), %rcx
xorl %eax, %eax
callq 0x42b0
movq %r12, %rdi
callq 0xa0d8
addq $0x10, %r14
movq (%r14), %rdi
callq 0x42a0
movl %eax, %ebx
jmp 0x4870
addl $-0x2, %r15d
jne 0x4779
movq 0xda83(%rip), %rdx      # 0x121e0
movl $0x400, %esi            # imm = 0x400
movq %r12, %rdi
movq 0x18(%rsp), %rcx
xorl %eax, %eax
callq 0x42b0
movq %r12, %rdi
callq 0xa0d8
addq $0x10, %r14
movq (%r14), %rdi
callq 0x42a0
movl %eax, %ebp
jmp 0x4870
addl $-0x2, %r15d
jne 0x47b5
movq 0xda47(%rip), %rdx      # 0x121e0
movl $0x400, %esi            # imm = 0x400
movq %r12, %rdi
movq 0x18(%rsp), %rcx
xorl %eax, %eax
callq 0x42b0
movq %r12, %rdi
callq 0xa0d8
addq $0x10, %r14
movq (%r14), %rdi
leaq 0x78a0(%rip), %rsi      # 0xc063
movq %r12, %rdx
leaq 0x2c(%rsp), %rcx
leaq 0x28(%rsp), %r8
xorl %eax, %eax
callq 0x4200
movb 0xa0(%rsp), %al
movb %al, 0xd9f4(%rip)       # 0x121d8
movb 0x2c(%rsp), %al
movb %al, 0xd9eb(%rip)       # 0x121d9
movb 0x28(%rsp), %al
movb %al, 0xd9e2(%rip)       # 0x121da
jmp 0x4870
addl $-0x2, %r15d
jne 0x4823
movq 0xd9d9(%rip), %rdx      # 0x121e0
movl $0x400, %esi            # imm = 0x400
movq %r12, %rdi
movq 0x18(%rsp), %rcx
xorl %eax, %eax
callq 0x42b0
movq %r12, %rdi
callq 0xa0d8
addq $0x10, %r14
movq (%r14), %rdi
leaq 0x7832(%rip), %rsi      # 0xc063
movq %r12, %rdx
leaq 0x2c(%rsp), %rcx
leaq 0x28(%rsp), %r8
xorl %eax, %eax
callq 0x4200
movb 0xa0(%rsp), %al
movb %al, 0xd9a7(%rip)       # 0x121f9
movb 0x2c(%rsp), %al
movb %al, 0xd99e(%rip)       # 0x121fa
movb 0x28(%rsp), %al
movb %al, 0xd995(%rip)       # 0x121fb
jmp 0x4870
movl $0x1, 0x40(%rsp)
cmpl $0x1, %r15d
jg 0x466e
cmpl $0x0, 0x40(%rsp)
movl %ebx, %r14d
sete %bl
jmp 0x4894
movl $0x168, %r14d           # imm = 0x168
movl $0xb4, %ebp
movb $0x1, %bl
leaq 0xa0(%rsp), %r12
movq %r12, %rdi
xorl %esi, %esi
xorl %edx, %edx
callq 0xaf80
movl %r14d, 0x24(%rsp)
movslq %r14d, %r15
movl %ebp, 0x20(%rsp)
movslq %ebp, %r14
movq %r12, %rdi
movq %r15, %rsi
movq %r14, %rdx
callq 0xafb6
movq 0xa8(%rsp), %rax
movq 0xb0(%rsp), %rdi
imulq 0xa0(%rsp), %rax
leaq (%rax,%rax,2), %rdx
xorl %esi, %esi
callq 0x4100
testb %bl, %bl
je 0x49d5
movl 0x20(%rsp), %edx
testl %edx, %edx
jle 0x4bd4
imulq $0x38e38e39, %r15, %r8  # imm = 0x38E38E39
movq %r8, %rax
shrq $0x3f, %rax
sarq $0x23, %r8
addl %eax, %r8d
imulq $0x38e38e39, %r14, %rcx # imm = 0x38E38E39
movq %rcx, %rax
shrq $0x3f, %rax
sarq $0x22, %rcx
addl %eax, %ecx
movq %rcx, 0x18(%rsp)
movl 0x24(%rsp), %r10d
xorl %ecx, %ecx
leaq 0xd8c0(%rip), %r11      # 0x121f9
leaq 0xd898(%rip), %rbx      # 0x121d8
leaq 0xd8b3(%rip), %r14      # 0x121fa
leaq 0xd88b(%rip), %r15      # 0x121d9
leaq 0xd8a6(%rip), %r12      # 0x121fb
leaq 0xd87e(%rip), %r13      # 0x121da
xorl %ebp, %ebp
cmpl $0x0, 0x24(%rsp)
jle 0x49ca
movl %ecx, %eax
xorl %edx, %edx
divl 0x18(%rsp)
movl %eax, %esi
movslq %ebp, %rax
leaq (%rax,%rax,2), %r9
addq $0x2, %r9
xorl %edi, %edi
movl %edi, %eax
xorl %edx, %edx
divl %r8d
xorl %esi, %eax
testb $0x1, %al
movq %rbx, %rax
cmoveq %r11, %rax
movq 0xb0(%rsp), %rdx
movb (%rax), %al
movb %al, -0x2(%rdx,%r9)
movq %r15, %rax
cmoveq %r14, %rax
movb (%rax), %al
movb %al, -0x1(%rdx,%r9)
movq %r13, %rax
cmoveq %r12, %rax
movb (%rax), %al
movb %al, (%rdx,%r9)
addq $0x3, %r9
incq %rdi
cmpl %edi, %r10d
jne 0x497c
addl %edi, %ebp
movl 0x20(%rsp), %edx
incl %ecx
cmpl %edx, %ecx
jne 0x495e
jmp 0x4bd4
movl 0x20(%rsp), %ecx
testl %ecx, %ecx
jle 0x4bd4
movl 0x24(%rsp), %r13d
cvtsi2sd %r13d, %xmm0
movapd %xmm0, %xmm1
divsd 0x7611(%rip), %xmm1     # 0xc008
imulq $0x38e38e39, %r14, %rdx # imm = 0x38E38E39
movq %rdx, %rax
shrq $0x3f, %rax
sarq $0x22, %rdx
addl %eax, %edx
movq %rdx, 0x50(%rsp)
cvtsi2sd %ecx, %xmm2
movl %ecx, 0x3c(%rsp)
fildl 0x3c(%rsp)
fstpt 0x94(%rsp)
movl %r13d, %r14d
negl %r14d
xorl %ebx, %ebx
mulsd 0x75dd(%rip), %xmm2     # 0xc010
movsd %xmm2, 0x58(%rsp)
mulsd 0x75cf(%rip), %xmm0     # 0xc010
leaq 0xd7b2(%rip), %r13      # 0x121fa
leaq 0xd7ac(%rip), %r15      # 0x121fb
leaq 0xd784(%rip), %rbp      # 0x121da
xorpd %xmm2, %xmm2
movl $0x0, 0x30(%rsp)
movsd %xmm0, 0x70(%rsp)
movsd %xmm1, 0x68(%rsp)
movl %r14d, 0x38(%rsp)
movsd 0x58(%rsp), %xmm0
movsd %xmm2, 0x60(%rsp)
subsd %xmm2, %xmm0
movsd %xmm0, 0x88(%rsp)
fldl 0x88(%rsp)
fmull 0x757f(%rip)            # 0xc018
fldt 0x94(%rsp)
fdivrp %st, %st(1)
fstpt (%rsp)
callq 0x4230
fstpl 0x80(%rsp)
cmpl $0x0, 0x24(%rsp)
jle 0x4bb2
movsd 0x80(%rsp), %xmm0
movsd %xmm0, 0x78(%rsp)
xorl %r12d, %r12d
movl %ebx, 0x34(%rsp)
movl %ebx, %eax
xorl %edx, %edx
divl 0x50(%rsp)
movl %eax, %r14d
andl $0x1, %r14d
movslq 0x30(%rsp), %rax
leaq (%rax,%rax,2), %rbx
addq $0x2, %rbx
xorpd %xmm0, %xmm0
movsd %xmm0, 0x18(%rsp)
movsd 0x70(%rsp), %xmm1
subsd %xmm0, %xmm1
mulsd 0x78(%rsp), %xmm1
movapd %xmm1, 0x40(%rsp)
movapd %xmm1, %xmm0
andpd 0x7516(%rip), %xmm0     # 0xc030
divsd 0x68(%rsp), %xmm0
callq 0x4300
cvttsd2si %xmm0, %eax
movsd 0x18(%rsp), %xmm0
movl %eax, %ecx
shrl $0x1f, %ecx
addl %eax, %ecx
andl $-0x2, %ecx
subl %ecx, %eax
movl $0x1, %ecx
subl %eax, %ecx
xorpd %xmm1, %xmm1
ucomisd 0x40(%rsp), %xmm1
cmovbel %eax, %ecx
cmpl %r14d, %ecx
movq 0xb0(%rsp), %rax
leaq 0xd677(%rip), %rcx      # 0x121d8
leaq 0xd691(%rip), %rdx      # 0x121f9
cmoveq %rdx, %rcx
movb (%rcx), %cl
leaq 0xd664(%rip), %rdx      # 0x121d9
cmoveq %r13, %rdx
movb %cl, -0x2(%rax,%rbx)
movb (%rdx), %cl
movb %cl, -0x1(%rax,%rbx)
movq %rbp, %rcx
cmoveq %r15, %rcx
movb (%rcx), %cl
movb %cl, (%rax,%rbx)
addsd 0x7489(%rip), %xmm0     # 0xc020
addq $0x3, %rbx
decl %r12d
cmpl %r12d, 0x38(%rsp)
jne 0x4af2
subl %r12d, 0x30(%rsp)
movl 0x34(%rsp), %ebx
movsd 0x7466(%rip), %xmm2     # 0xc020
movsd 0x60(%rsp), %xmm3
addsd %xmm2, %xmm3
movapd %xmm3, %xmm2
incl %ebx
cmpl 0x20(%rsp), %ebx
jne 0x4a73
leaq 0xa0(%rsp), %rdi
xorl %esi, %esi
callq 0xb372
leaq 0xa0(%rsp), %rdi
callq 0xafd4
xorl %eax, %eax
addq $0x4a8, %rsp            # imm = 0x4A8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %rbx
leaq 0xa0(%rsp), %rdi
callq 0xafd4
movq %rbx, %rdi
callq 0x4320