// File: /workspace/github_cpp_makefile_star2_O3/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 0x4871
movq %rsi, %r14
movl %edi, %r15d
movq (%rsi), %rax
movq %rax, 0x18(%rsp)
movl $0xb4, %ebp
movl $0x168, %ebx            # imm = 0x168
leaq 0xa0(%rsp), %r13
movl $0x0, 0x40(%rsp)
movq 0x8(%r14), %r12
cmpb $0x2d, (%r12)
jne 0x4691
cmpb $0x77, 0x1(%r12)
jne 0x467d
cmpb $0x0, 0x2(%r12)
je 0x47ea
cmpb $0x68, 0x1(%r12)
jne 0x4691
cmpb $0x0, 0x2(%r12)
je 0x4823
movq %r12, %rdi
leaq 0x89be(%rip), %rsi      # 0xd059
callq 0x4250
testl %eax, %eax
je 0x4701
movq %r12, %rdi
leaq 0x89b8(%rip), %rsi      # 0xd066
callq 0x4250
testl %eax, %eax
je 0x4772
addq $0x8, %r14
decl %r15d
movq %r12, %rdi
leaq 0x899e(%rip), %rsi      # 0xd06a
callq 0x4250
testl %eax, %eax
je 0x47e0
movq 0xeaf8(%rip), %rdx      # 0x131d8
movl $0x400, %esi            # imm = 0x400
movq %r13, %rdi
movq 0x18(%rsp), %rcx
xorl %eax, %eax
callq 0x42a0
movq %r13, %rdi
callq 0xa2cc
jmp 0x485a
addl $-0x2, %r15d
jne 0x472a
movq 0xeaca(%rip), %rdx      # 0x131d8
movl $0x400, %esi            # imm = 0x400
movq %r13, %rdi
movq 0x18(%rsp), %rcx
xorl %eax, %eax
callq 0x42a0
movq %r13, %rdi
callq 0xa2cc
addq $0x10, %r14
movq (%r14), %rdi
leaq 0x8925(%rip), %rsi      # 0xd05d
movq %r13, %rdx
leaq 0x2c(%rsp), %rcx
leaq 0x28(%rsp), %r8
xorl %eax, %eax
callq 0x41f0
movb 0xa0(%rsp), %al
movb %al, 0xea77(%rip)       # 0x131d0
movb 0x2c(%rsp), %al
movb %al, 0xea6e(%rip)       # 0x131d1
movb 0x28(%rsp), %al
movb %al, 0xea65(%rip)       # 0x131d2
jmp 0x485a
addl $-0x2, %r15d
jne 0x479b
movq 0xea59(%rip), %rdx      # 0x131d8
movl $0x400, %esi            # imm = 0x400
movq %r13, %rdi
movq 0x18(%rsp), %rcx
xorl %eax, %eax
callq 0x42a0
movq %r13, %rdi
callq 0xa2cc
addq $0x10, %r14
movq (%r14), %rdi
leaq 0x88b4(%rip), %rsi      # 0xd05d
movq %r13, %rdx
leaq 0x2c(%rsp), %rcx
leaq 0x28(%rsp), %r8
xorl %eax, %eax
callq 0x41f0
movb 0xa0(%rsp), %al
movb %al, 0xea27(%rip)       # 0x131f1
movb 0x2c(%rsp), %al
movb %al, 0xea1e(%rip)       # 0x131f2
movb 0x28(%rsp), %al
movb %al, 0xea15(%rip)       # 0x131f3
jmp 0x485a
movl $0x1, 0x40(%rsp)
jmp 0x485a
addl $-0x2, %r15d
jne 0x4813
movq 0xe9e1(%rip), %rdx      # 0x131d8
movl $0x400, %esi            # imm = 0x400
movq %r13, %rdi
movq 0x18(%rsp), %rcx
xorl %eax, %eax
callq 0x42a0
movq %r13, %rdi
callq 0xa2cc
addq $0x10, %r14
movq (%r14), %rdi
callq 0x4290
movl %eax, %ebx
jmp 0x485a
addl $-0x2, %r15d
jne 0x484c
movq 0xe9a8(%rip), %rdx      # 0x131d8
movl $0x400, %esi            # imm = 0x400
movq %r13, %rdi
movq 0x18(%rsp), %rcx
xorl %eax, %eax
callq 0x42a0
movq %r13, %rdi
callq 0xa2cc
addq $0x10, %r14
movq (%r14), %rdi
callq 0x4290
movl %eax, %ebp
cmpl $0x1, %r15d
jg 0x465e
cmpl $0x0, 0x40(%rsp)
movl %ebx, %r14d
sete %bl
jmp 0x487e
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 0xb168
movl %r14d, 0x20(%rsp)
movslq %r14d, %r15
movslq %ebp, %r14
movq %r12, %rdi
movq %r15, %rsi
movq %r14, %rdx
callq 0xb19e
movq 0xa8(%rsp), %rax
movq 0xb0(%rsp), %rdi
imulq 0xa0(%rsp), %rax
leaq (%rax,%rax,2), %rdx
xorl %esi, %esi
callq 0x40f0
testb %bl, %bl
movl %ebp, 0x24(%rsp)
je 0x49b9
testl %ebp, %ebp
jle 0x4bb5
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 0x20(%rsp), %r10d
xorl %ecx, %ecx
leaq 0xe8d2(%rip), %r11      # 0x131f1
leaq 0xe8aa(%rip), %rbx      # 0x131d0
leaq 0xe8c5(%rip), %r14      # 0x131f2
leaq 0xe89d(%rip), %r15      # 0x131d1
leaq 0xe8b8(%rip), %r12      # 0x131f3
leaq 0xe890(%rip), %r13      # 0x131d2
xorl %ebp, %ebp
cmpl $0x0, 0x20(%rsp)
jle 0x49ac
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 0x4962
addl %edi, %ebp
incl %ecx
cmpl 0x24(%rsp), %ecx
jne 0x4944
jmp 0x4bb5
testl %ebp, %ebp
jle 0x4bb5
movl 0x20(%rsp), %r13d
cvtsi2sd %r13d, %xmm0
movapd %xmm0, %xmm1
divsd 0x8631(%rip), %xmm1     # 0xd008
imulq $0x38e38e39, %r14, %rcx # imm = 0x38E38E39
movq %rcx, %rax
shrq $0x3f, %rax
sarq $0x22, %rcx
addl %eax, %ecx
movq %rcx, 0x50(%rsp)
movl 0x24(%rsp), %eax
cvtsi2sd %eax, %xmm2
movl %eax, 0x3c(%rsp)
fildl 0x3c(%rsp)
fstpt 0x94(%rsp)
movl %r13d, %ebx
negl %ebx
xorl %ebp, %ebp
mulsd 0x85fa(%rip), %xmm2     # 0xd010
movsd %xmm2, 0x58(%rsp)
mulsd 0x85ec(%rip), %xmm0     # 0xd010
leaq 0xe7a6(%rip), %r13      # 0x131d1
leaq 0xe7c1(%rip), %r15      # 0x131f3
leaq 0xe799(%rip), %r12      # 0x131d2
xorpd %xmm2, %xmm2
movl $0x0, 0x30(%rsp)
movsd %xmm0, 0x70(%rsp)
movsd %xmm1, 0x68(%rsp)
movl %ebx, 0x38(%rsp)
movsd 0x58(%rsp), %xmm0
movsd %xmm2, 0x60(%rsp)
subsd %xmm2, %xmm0
movsd %xmm0, 0x88(%rsp)
fldl 0x88(%rsp)
fmull 0x859d(%rip)            # 0xd018
fldt 0x94(%rsp)
fdivrp %st, %st(1)
fstpt (%rsp)
callq 0x4220
fstpl 0x80(%rsp)
cmpl $0x0, 0x20(%rsp)
jle 0x4b93
movsd 0x80(%rsp), %xmm0
movsd %xmm0, 0x78(%rsp)
xorl %ebx, %ebx
movl %ebp, 0x34(%rsp)
movl %ebp, %eax
xorl %edx, %edx
divl 0x50(%rsp)
movl %eax, %r14d
andl $0x1, %r14d
movslq 0x30(%rsp), %rax
leaq (%rax,%rax,2), %rbp
addq $0x2, %rbp
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 0x8535(%rip), %xmm0     # 0xd030
divsd 0x68(%rsp), %xmm0
callq 0x42f0
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 0xe68e(%rip), %rcx      # 0x131d0
leaq 0xe6a8(%rip), %rdx      # 0x131f1
cmoveq %rdx, %rcx
movb (%rcx), %cl
movq %r13, %rdx
leaq 0xe699(%rip), %rsi      # 0x131f2
cmoveq %rsi, %rdx
movb %cl, -0x2(%rax,%rbp)
movb (%rdx), %cl
movb %cl, -0x1(%rax,%rbp)
movq %r12, %rcx
cmoveq %r15, %rcx
movb (%rcx), %cl
movb %cl, (%rax,%rbp)
addsd 0x84a5(%rip), %xmm0     # 0xd020
addq $0x3, %rbp
decl %ebx
cmpl %ebx, 0x38(%rsp)
jne 0x4ad3
subl %ebx, 0x30(%rsp)
movl 0x34(%rsp), %ebp
movsd 0x8485(%rip), %xmm2     # 0xd020
movsd 0x60(%rsp), %xmm3
addsd %xmm2, %xmm3
movapd %xmm3, %xmm2
incl %ebp
cmpl 0x24(%rsp), %ebp
jne 0x4a55
leaq 0xa0(%rsp), %rdi
xorl %esi, %esi
callq 0xb57a
leaq 0xa0(%rsp), %rdi
callq 0xb1bc
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 0xb1bc
movq %rbx, %rdi
callq 0x4310
nopl (%rax)