LLM4Binary/decompile-bench-makefile huggingface dataset:
// File: /workspace/github_cpp_makefile_star2_O3/tomfunkhouser[P]gaps/pkgs/R2Shapes/R2Image.cpp
// Function: gaps::R2Image::operator=(gaps::R2Image const&)
R2Image& R2Image::
operator=(const R2Image& image)
{
  // Assign values
  this->width = image.width;
  this->height = image.height;
  this->ncomponents = image.ncomponents;
  this->rowsize = image.rowsize;
  
  // Delete previous pixels
  if (this->pixels) delete [] pixels;
  this->pixels = NULL;

  // Copy pixels
  int nbytes = this->rowsize * this->height;
  if (nbytes > 0) {
    this->pixels = new unsigned char [nbytes];
    assert(this->pixels);
    unsigned char *p =this-> pixels;
    unsigned char *data = image.pixels;
    while (--nbytes) *(p++) = *(data++);
  }

  // Return this
  return *this;
}

// Assembly:
pushq %rbp
pushq %r14
pushq %rbx
movq %rsi, %r14
movq %rdi, %rbx
movups (%rsi), %xmm0
movl 0x4(%rsi), %ebp
movl 0xc(%rsi), %eax
movups %xmm0, (%rdi)
movq 0x10(%rdi), %rdi
testq %rdi, %rdi
je 0x68f7c
callq 0xe5b0
movl 0x4(%rbx), %ebp
movl 0xc(%rbx), %eax
imull %eax, %ebp
movq $0x0, 0x10(%rbx)
testl %ebp, %ebp
jle 0x68fb1
movl %ebp, %edi
callq 0xe030
movq %rax, 0x10(%rbx)
decl %ebp
je 0x68fb1
movq 0x10(%r14), %rcx
movl %ebp, %edx
xorl %esi, %esi
movb (%rcx,%rsi), %dil
movb %dil, (%rax,%rsi)
incq %rsi
cmpl %esi, %edx
jne 0x68fa2
movq %rbx, %rax
popq %rbx
popq %r14
popq %rbp
retq
nop
// File: /workspace/github_cpp_makefile_star2_O3/tomfunkhouser[P]gaps/pkgs/R2Shapes/R2Image.cpp
// Function: gaps::R2Image::Add(gaps::R2Image const&)
void R2Image::
Add(const R2Image& image)
{
  int nbytes = rowsize * height;
  unsigned char *p1 = pixels;
  unsigned char *p2 = image.pixels;
  while (--nbytes) {
    int value = *p1;
    value += *(p2++);
    if (value > 255) value = 255;
    *(p1++) = value;
  }
}

// Assembly:
movslq 0xc(%rdi), %rcx
movslq 0x4(%rdi), %rax
imulq %rcx, %rax
cmpl $0x1, %eax
je 0x691c6
movq 0x10(%rsi), %rcx
movq 0x10(%rdi), %rdx
decq %rax
xorl %esi, %esi
movl $0xff, %edi
movzbl (%rdx,%rsi), %r8d
movzbl (%rcx,%rsi), %r9d
addl %r8d, %r9d
cmpl %edi, %r9d
cmovael %edi, %r9d
movb %r9b, (%rdx,%rsi)
incq %rsi
cmpl %esi, %eax
jne 0x691a7
retq
nop
// File: /workspace/github_cpp_makefile_star2_O3/tomfunkhouser[P]gaps/pkgs/R2Shapes/R2Image.cpp
// Function: gaps::R2Image::Subtract(gaps::R2Image const&)
void R2Image::
Subtract(const R2Image& image)
{
  int nbytes = rowsize * height;
  unsigned char *p1 = pixels;
  unsigned char *p2 = image.pixels;
  while (--nbytes) {
    int value = *p1 - *p2 + 128;
    if (value < 0) value = 0;
    if (value > 255) value = 255;
    *p1 = value;
    p1++;
    p2++;
  }
}

// Assembly:
movslq 0xc(%rdi), %rcx
movslq 0x4(%rdi), %rax
imulq %rcx, %rax
cmpl $0x1, %eax
je 0x6921d
movq 0x10(%rsi), %rcx
movq 0x10(%rdi), %rdx
decq %rax
xorl %esi, %esi
movl $0xffffff80, %edi       # imm = 0xFFFFFF80
movl $0x7f, %r8d
movzbl (%rdx,%rsi), %r9d
movzbl (%rcx,%rsi), %r10d
subl %r10d, %r9d
cmpl $-0x7f, %r9d
cmovll %edi, %r9d
cmpl $0x7f, %r9d
cmovgel %r8d, %r9d
addb $-0x80, %r9b
movb %r9b, (%rdx,%rsi)
incq %rsi
cmpl %esi, %eax
jne 0x691f1
retq
// File: /workspace/github_cpp_makefile_star2_O3/tomfunkhouser[P]gaps/pkgs/R2Shapes/R2Image.cpp
// Function: gaps::R2Image::Capture()
void R2Image::
Capture(void)
{
  // Check image size
  GLint viewport[4];
  glGetIntegerv(GL_VIEWPORT, viewport);
  assert(width >= viewport[2]);
  assert(height >= viewport[3]);
  assert(pixels);

  // Set packing parameters for glReadPixels
  if ((ncomponents != 4) && ((width % 4) != 0)) glPixelStorei(GL_PACK_ALIGNMENT, 1);

  // Read pixels from frame buffer 
  switch (ncomponents) {
  case 1: glReadPixels(0, 0, width, height, GL_LUMINANCE, GL_UNSIGNED_BYTE, pixels); break;
  case 2: glReadPixels(0, 0, width, height, GL_LUMINANCE_ALPHA, GL_UNSIGNED_BYTE, pixels); break;
  case 3: glReadPixels(0, 0, width, height, GL_RGB, GL_UNSIGNED_BYTE, pixels); break;
  case 4: glReadPixels(0, 0, width, height, GL_RGBA, GL_UNSIGNED_BYTE, pixels); break;
  }

  // Reset packing parameters for glReadPixels
  if ((ncomponents != 4) && ((width % 4) != 0)) glPixelStorei(GL_PACK_ALIGNMENT, 4);
}

// Assembly:
pushq %rbx
subq $0x20, %rsp
movq %rdi, %rbx
leaq 0x10(%rsp), %rsi
movl $0xba2, %edi            # imm = 0xBA2
callq 0xe400
movl (%rbx), %edx
movl 0x8(%rbx), %eax
cmpl $0x4, %eax
jne 0x69745
movl 0x4(%rbx), %ecx
movq 0x10(%rbx), %rax
movq %rax, (%rsp)
xorl %edi, %edi
xorl %esi, %esi
movl $0x1908, %r8d           # imm = 0x1908
movl $0x1401, %r9d           # imm = 0x1401
callq 0xe200
cmpl $0x4, 0x8(%rbx)
je 0x6973f
testb $0x3, (%rbx)
je 0x6973f
movl $0xd05, %edi            # imm = 0xD05
movl $0x4, %esi
callq 0xe230
addq $0x20, %rsp
popq %rbx
retq
testb $0x3, %dl
je 0x6975c
movl $0xd05, %edi            # imm = 0xD05
movl $0x1, %esi
callq 0xe230
movl 0x8(%rbx), %eax
decl %eax
cmpl $0x3, %eax
ja 0x6972b
leaq 0x4035a(%rip), %rcx     # 0xa9ac4
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movl (%rbx), %edx
movl 0x4(%rbx), %ecx
movq 0x10(%rbx), %rax
movq %rax, (%rsp)
xorl %edi, %edi
xorl %esi, %esi
movl $0x1909, %r8d           # imm = 0x1909
jmp 0x6971a
movl (%rbx), %edx
movl 0x4(%rbx), %ecx
movq 0x10(%rbx), %rax
movq %rax, (%rsp)
xorl %edi, %edi
xorl %esi, %esi
movl $0x1907, %r8d           # imm = 0x1907
jmp 0x6971a
movl (%rbx), %edx
jmp 0x69705
movl (%rbx), %edx
movl 0x4(%rbx), %ecx
movq 0x10(%rbx), %rax
movq %rax, (%rsp)
xorl %edi, %edi
xorl %esi, %esi
movl $0x190a, %r8d           # imm = 0x190A
jmp 0x6971a
nop
// File: /workspace/github_cpp_makefile_star2_O3/tomfunkhouser[P]gaps/pkgs/R2Shapes/R2Image.cpp
// Function: gaps::R2Image::Draw(int, int) const
void R2Image::
Draw(int x, int y) const
{
  // Set projection matrix
  glMatrixMode(GL_PROJECTION);  
  glPushMatrix();
  glLoadIdentity();
  gluOrtho2D(0, width, 0, height);

  // Set model view matrix
  glMatrixMode(GL_MODELVIEW);
  glPushMatrix();
  glLoadIdentity();

  // Set position for image
  glRasterPos2i(x, y);

  // Draw pixels
  switch (ncomponents) {
  case 1: glDrawPixels(width, height, GL_LUMINANCE, GL_UNSIGNED_BYTE, pixels); break;
  case 2: glDrawPixels(width, height, GL_LUMINANCE_ALPHA, GL_UNSIGNED_BYTE, pixels); break;
  case 3: glDrawPixels(width, height, GL_RGB, GL_UNSIGNED_BYTE, pixels); break;
  case 4: glDrawPixels(width, height, GL_RGBA, GL_UNSIGNED_BYTE, pixels); break;
  default: RNFail("Unrecognized number of components in image: %d\n", ncomponents); break;
  }

  // Reset projection matrix
  glMatrixMode(GL_PROJECTION);
  glPopMatrix();

  // Reset model view matrix
  glMatrixMode(GL_MODELVIEW);
  glPopMatrix();
}

// Assembly:
pushq %rbp
pushq %r14
pushq %rbx
movl %edx, %ebp
movl %esi, %r14d
movq %rdi, %rbx
movl $0x1701, %edi           # imm = 0x1701
callq 0xe620
callq 0xe740
callq 0xe5c0
cvtsi2sdl (%rbx), %xmm1
cvtsi2sdl 0x4(%rbx), %xmm3
xorps %xmm0, %xmm0
xorps %xmm2, %xmm2
callq 0xe2b0
movl $0x1700, %edi           # imm = 0x1700
callq 0xe620
callq 0xe740
callq 0xe5c0
movl %r14d, %edi
movl %ebp, %esi
callq 0xe180
movl 0x8(%rbx), %esi
leal -0x1(%rsi), %eax
cmpl $0x3, %eax
ja 0x698a3
leaq 0x402a4(%rip), %rcx     # 0xa9ad4
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movl (%rbx), %edi
movl 0x4(%rbx), %esi
movq 0x10(%rbx), %r8
movl $0x1909, %edx           # imm = 0x1909
jmp 0x69877
movl (%rbx), %edi
movl 0x4(%rbx), %esi
movq 0x10(%rbx), %r8
movl $0x1907, %edx           # imm = 0x1907
jmp 0x69877
movl (%rbx), %edi
movl 0x4(%rbx), %esi
movq 0x10(%rbx), %r8
movl $0x1908, %edx           # imm = 0x1908
jmp 0x69877
movl (%rbx), %edi
movl 0x4(%rbx), %esi
movq 0x10(%rbx), %r8
movl $0x190a, %edx           # imm = 0x190A
movl $0x1401, %ecx           # imm = 0x1401
callq 0xe350
movl $0x1701, %edi           # imm = 0x1701
callq 0xe620
callq 0xe850
movl $0x1700, %edi           # imm = 0x1700
callq 0xe620
popq %rbx
popq %r14
popq %rbp
jmp 0xe850
leaq 0x402be(%rip), %rdi     # 0xa9b68
xorl %eax, %eax
callq 0x719d2
jmp 0x69881
nop
// File: /workspace/github_cpp_makefile_star2_O3/tomfunkhouser[P]gaps/pkgs/R2Shapes/R2Image.cpp
// Function: gaps::R2Image::ReadJPEGFile(char const*)
int R2Image::
ReadJPEGFile(const char *filename)
{
  // Open file
  FILE *fp = fopen(filename, "rb");
  if (!fp) {
    RNFail("Unable to open JPEG file %s\n", filename);
    return 0;
   }

  // Read file
  if (!ReadJPEGStream(fp)) {
    fclose(fp);
    return 0;
  }

  // Close the file 
  fclose(fp);

  // Return success 
  return 1;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %rbx
pushq %rax
movq %rsi, %rbx
movq %rdi, %r14
leaq 0x38ce3(%rip), %rsi     # 0xa25ab
movq %rbx, %rdi
callq 0xe530
testq %rax, %rax
je 0x698f2
movq %rax, %r15
movq %r14, %rdi
movq %rax, %rsi
callq 0x6b50a
movq %r15, %rdi
callq 0xe430
movl $0x1, %ebp
jmp 0x69905
leaq 0x404b2(%rip), %rdi     # 0xa9dab
xorl %ebp, %ebp
movq %rbx, %rsi
xorl %eax, %eax
callq 0x719d2
movl %ebp, %eax
addq $0x8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
retq
// File: /workspace/github_cpp_makefile_star2_O3/tomfunkhouser[P]gaps/pkgs/R2Shapes/R2Image.cpp
// Function: gaps::R2Image::WriteJPEGFile(char const*) const
int R2Image::
WriteJPEGFile(const char *filename) const
{
  // Open the file 
  FILE *fp = fopen(filename, "wb");
  if (fp == NULL) {
    RNFail("Unable to open JPEG file %s\n", filename);
    return 0;
  }
  
  // Write the file
  if (!WriteJPEGStream(fp)) {
    fclose(fp);
    return 0;
  }

  // Close the file 
  fclose(fp);

  // Return success
  return 1;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %rbx
pushq %rax
movq %rsi, %rbx
movq %rdi, %r14
leaq 0x37923(%rip), %rsi     # 0xa2a81
movq %rbx, %rdi
callq 0xe530
testq %rax, %rax
je 0x6b188
movq %rax, %r15
movq %r14, %rdi
movq %rax, %rsi
callq 0x6b61e
movq %r15, %rdi
callq 0xe430
movl $0x1, %ebp
jmp 0x6b19b
leaq 0x3ec1c(%rip), %rdi     # 0xa9dab
xorl %ebp, %ebp
movq %rbx, %rsi
xorl %eax, %eax
callq 0x719d2
movl %ebp, %eax
addq $0x8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
retq
// File: /workspace/github_cpp_makefile_star2_O3/tomfunkhouser[P]gaps/pkgs/R2Shapes/R2Image.cpp
// Function: gaps::R2Image::ReadJPEGStream(_IO_FILE*)
int R2Image::
ReadJPEGStream(FILE *fp)
{
#ifdef RN_USE_JPEG
  // Initialize decompression info
  struct jpeg_decompress_struct cinfo;
  struct jpeg_error_mgr jerr;
  cinfo.err = jpeg_std_error(&jerr);
  jpeg_create_decompress(&cinfo);
  jpeg_stdio_src(&cinfo, fp);
  jpeg_read_header(&cinfo, TRUE);
  jpeg_start_decompress(&cinfo);

  // Remember image attributes
  width = cinfo.output_width;
  height = cinfo.output_height;
  ncomponents = cinfo.output_components;
  rowsize = ncomponents * width;
  if ((rowsize % 4) != 0) rowsize = (rowsize / 4 + 1) * 4;

  // Allocate image pixels
  int nbytes = rowsize * height;
  this->pixels = new unsigned char [nbytes];
  if (!this->pixels) {
    RNFail("Unable to allocate memory for JPEG file");
    fclose(fp);
    return 0;
  }

  // Read scan lines 
  // First jpeg pixel is top-left, so read pixels in opposite scan-line order
  while (cinfo.output_scanline < cinfo.output_height) {
    int scanline = cinfo.output_height - cinfo.output_scanline - 1;
    unsigned char *row_pointer = &pixels[scanline * rowsize];
    jpeg_read_scanlines(&cinfo, &row_pointer, 1);
  }

  // Free everything
  jpeg_finish_decompress(&cinfo);
  jpeg_destroy_decompress(&cinfo);

  // Return success
  return 1;
#else
  RNFail("JPEG not supported");
  return 0;
#endif
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %rbx
subq $0x328, %rsp            # imm = 0x328
movq %rsi, %r14
movq %rdi, %rbx
leaq 0x280(%rsp), %rdi
callq 0x85d24
leaq 0x8(%rsp), %r15
movq %rax, (%r15)
movl $0x278, %edx            # imm = 0x278
movq %r15, %rdi
movl $0x3e, %esi
callq 0x7a98c
movq %r15, %rdi
movq %r14, %rsi
callq 0x7b228
movq %r15, %rdi
movl $0x1, %esi
callq 0x7aa88
movq %r15, %rdi
callq 0x7ae20
movl 0x88(%r15), %ecx
movl %ecx, (%rbx)
movl 0x8c(%r15), %ebp
movl %ebp, 0x4(%rbx)
movl 0x94(%r15), %eax
movl %eax, 0x8(%rbx)
imull %ecx, %eax
testb $0x3, %al
je 0x6b598
leal 0x3(%rax), %ecx
testl %eax, %eax
cmovnsl %eax, %ecx
andl $-0x4, %ecx
addl $0x4, %ecx
movl %ecx, %eax
movl %eax, 0xc(%rbx)
imull %ebp, %eax
movslq %eax, %rdi
callq 0xe030
movq %rax, 0x10(%rbx)
movl 0xb0(%rsp), %eax
cmpl %ebp, %eax
jae 0x6b5f5
leaq 0x8(%rsp), %r14
movq %rsp, %r15
notl %eax
addl %ebp, %eax
movslq 0xc(%rbx), %rcx
cltq
imulq %rcx, %rax
addq 0x10(%rbx), %rax
movq %rax, (%rsp)
movq %r14, %rdi
movq %r15, %rsi
movl $0x1, %edx
callq 0x7afe6
movl 0x94(%rsp), %ebp
movl 0xb0(%rsp), %eax
cmpl %ebp, %eax
jb 0x6b5bd
leaq 0x8(%rsp), %rbx
movq %rbx, %rdi
callq 0x7ad7f
movq %rbx, %rdi
callq 0x7aa7e
movl $0x1, %eax
addq $0x328, %rsp            # imm = 0x328
popq %rbx
popq %r14
popq %r15
popq %rbp
retq
nop
// File: /workspace/github_cpp_makefile_star2_O3/tomfunkhouser[P]gaps/pkgs/R2Shapes/R2Image.cpp
// Function: gaps::R2Image::WriteJPEGStream(_IO_FILE*) const
int R2Image::
WriteJPEGStream(FILE *fp) const
{
#ifdef RN_USE_JPEG
  // Initialize compression info
  struct jpeg_compress_struct cinfo;
  struct jpeg_error_mgr jerr;
  cinfo.err = jpeg_std_error(&jerr);
  jpeg_create_compress(&cinfo);
  jpeg_stdio_dest(&cinfo, fp);
  cinfo.image_width = width; 	/* image width and height, in pixels */
  cinfo.image_height = height;
  cinfo.input_components = ncomponents;		/* # of color components per pixel */
  if (ncomponents == 1) cinfo.in_color_space = JCS_GRAYSCALE;
  else if (ncomponents == 3) cinfo.in_color_space = JCS_RGB;
  else if (ncomponents == 4) cinfo.in_color_space = JCS_CMYK;
  else cinfo.in_color_space = JCS_UNKNOWN;
  cinfo.dct_method = JDCT_ISLOW;
  jpeg_set_defaults(&cinfo);
  cinfo.optimize_coding = TRUE;
  jpeg_set_quality(&cinfo, 75, TRUE);
  jpeg_start_compress(&cinfo, TRUE);
	
  // Output scan lines
  // First jpeg pixel is top-left, so write in opposite scan-line order
  while (cinfo.next_scanline < cinfo.image_height) {
    int scanline = cinfo.image_height - cinfo.next_scanline - 1;
    unsigned char *row_pointer = &pixels[scanline * rowsize];
    jpeg_write_scanlines(&cinfo, &row_pointer, 1);
  }

  // Free everything
  jpeg_finish_compress(&cinfo);
  jpeg_destroy_compress(&cinfo);

  // Return number of bytes written
  return 1;
#else
  RNFail("JPEG not supported");
  return 0;
#endif
}

// Assembly:
pushq %r15
pushq %r14
pushq %rbx
subq $0x2c0, %rsp            # imm = 0x2C0
movq %rsi, %r14
movq %rdi, %rbx
leaq 0x218(%rsp), %rdi
callq 0x85d24
leaq 0x10(%rsp), %r15
movq %rax, (%r15)
movl $0x208, %edx            # imm = 0x208
movq %r15, %rdi
movl $0x3e, %esi
callq 0x71b4c
movq %r15, %rdi
movq %r14, %rsi
callq 0x72b7c
movq (%rbx), %rax
movq %rax, 0x30(%r15)
movl 0x8(%rbx), %eax
movl %eax, 0x38(%r15)
decl %eax
xorl %ecx, %ecx
cmpl $0x3, %eax
ja 0x6b685
movl %eax, %eax
leaq 0x3e4ae(%rip), %rcx     # 0xa9b30
movl (%rcx,%rax,4), %ecx
leaq 0x10(%rsp), %r14
movl %ecx, 0x3c(%r14)
movl $0x0, 0x114(%r14)
movq %r14, %rdi
callq 0x72289
movl $0x1, 0x108(%r14)
movq %r14, %rdi
movl $0x4b, %esi
movl $0x1, %edx
callq 0x7221b
movq %r14, %rdi
movl $0x1, %esi
callq 0x71ebc
movl 0x34(%r14), %eax
movl 0x130(%r14), %ecx
cmpl %eax, %ecx
jae 0x6b71b
leaq 0x10(%rsp), %r14
leaq 0x8(%rsp), %r15
notl %ecx
addl %eax, %ecx
movslq 0xc(%rbx), %rax
movslq %ecx, %rcx
imulq %rax, %rcx
addq 0x10(%rbx), %rcx
movq %rcx, 0x8(%rsp)
movq %r14, %rdi
movq %r15, %rsi
movl $0x1, %edx
callq 0x71f39
movl 0x44(%rsp), %eax
movl 0x140(%rsp), %ecx
cmpl %eax, %ecx
jb 0x6b6e4
leaq 0x10(%rsp), %rbx
movq %rbx, %rdi
callq 0x71c8b
movq %rbx, %rdi
callq 0x71c33
movl $0x1, %eax
addq $0x2c0, %rsp            # imm = 0x2C0
popq %rbx
popq %r14
popq %r15
retq
// File: /workspace/github_cpp_makefile_star2_O3/tomfunkhouser[P]gaps/pkgs/R2Shapes/R2Image.cpp
// Function: gaps::R2Image::ReadJPEGBuffer(char const*, unsigned long)
int R2Image::
ReadJPEGBuffer(const char *buffer, size_t buffer_length)
{
  // Open stream
  FILE *fp = fmemopen((void *) buffer, buffer_length, "r");
  if (!fp) {
    RNFail("Unable to open JPEG stream\n");
    return 0;
   }

  // Read file
  if (!ReadJPEGStream(fp)) {
    fclose(fp);
    return 0;
  }

  // Close the file 
  fclose(fp);

  // Return success 
  return 1;
}

// Assembly:
pushq %r14
pushq %rbx
pushq %rax
movq %rdi, %rbx
leaq 0x40683(%rip), %rax     # 0xabdd3
movq %rsi, %rdi
movq %rdx, %rsi
movq %rax, %rdx
callq 0xe8a0
testq %rax, %rax
je 0x6b780
movq %rax, %r14
movq %rbx, %rdi
movq %rax, %rsi
callq 0x6b50a
movq %r14, %rdi
callq 0xe430
movl $0x1, %ebx
jmp 0x6b790
leaq 0x3e641(%rip), %rdi     # 0xa9dc8
xorl %ebx, %ebx
xorl %eax, %eax
callq 0x719d2
movl %ebx, %eax
addq $0x8, %rsp
popq %rbx
popq %r14
retq
// File: /workspace/github_cpp_makefile_star2_O3/tomfunkhouser[P]gaps/pkgs/R2Shapes/R2Image.cpp
// Function: gaps::R2Image::WriteJPEGBuffer(char**, unsigned long*) const
int R2Image::
WriteJPEGBuffer(char **buffer, size_t *buffer_length) const
{
  // Open the file 
  FILE *fp = open_memstream(buffer, buffer_length);
  if (fp == NULL) {
    RNFail("Unable to open JPEG stream\n");
    return 0;
  }
  
  // Write the file
  if (!WriteJPEGStream(fp)) {
    fclose(fp);
    return 0;
  }

  // Close the file 
  fclose(fp);

  // Return success
  return 1;
}

// Assembly:
pushq %r14
pushq %rbx
pushq %rax
movq %rdi, %rbx
movq %rsi, %rdi
movq %rdx, %rsi
callq 0xe490
testq %rax, %rax
je 0x6b7ce
movq %rax, %r14
movq %rbx, %rdi
movq %rax, %rsi
callq 0x6b61e
movq %r14, %rdi
callq 0xe430
movl $0x1, %ebx
jmp 0x6b7de
leaq 0x3e5f3(%rip), %rdi     # 0xa9dc8
xorl %ebx, %ebx
xorl %eax, %eax
callq 0x719d2
movl %ebx, %eax
addq $0x8, %rsp
popq %rbx
popq %r14
retq
// File: /workspace/github_cpp_makefile_star2_O3/tomfunkhouser[P]gaps/pkgs/R2Shapes/R2Image.cpp
// Function: gaps::R2Image::ReadPNGBuffer(char const*, unsigned long)
int R2Image::
ReadPNGBuffer(const char *buffer, size_t buffer_length)
{
  // Open stream
  FILE *fp = fmemopen((void *) buffer, buffer_length, "r");
  if (!fp) {
    RNFail("Unable to open PNG stream\n");
    return 0;
   }

  // Read file
  if (!ReadPNGStream(fp)) {
    fclose(fp);
    return 0;
  }

  // Close the file 
  fclose(fp);

  // Return success 
  return 1;
}

// Assembly:
pushq %r14
pushq %rbx
pushq %rax
movq %rdi, %rbx
leaq 0x400b1(%rip), %rax     # 0xabdd3
movq %rsi, %rdi
movq %rdx, %rsi
movq %rax, %rdx
callq 0xe8a0
testq %rax, %rax
je 0x6bd51
movq %rax, %r14
movq %rbx, %rdi
movq %rax, %rsi
callq 0x6b7e8
movl %eax, %ebx
movq %r14, %rdi
callq 0xe430
movl %ebx, %eax
jmp 0x6bd61
leaq 0x3da53(%rip), %rdi     # 0xa97ab
xorl %eax, %eax
callq 0x719d2
xorl %eax, %eax
addq $0x8, %rsp
popq %rbx
popq %r14
retq
nop
// File: /workspace/github_cpp_makefile_star2_O3/tomfunkhouser[P]gaps/pkgs/R2Shapes/R2Draw.cpp
// Function: gaps::R2Affine::Push() const
void R2Affine::
Push(void) const
{
    // Push matrix onto stack
    Matrix().Push();

    // Set mirror flag
    if (IsMirrored()) {}
}

// Assembly:
pushq %r14
pushq %rbx
pushq %rax
movq %rdi, %rbx
leaq 0x8(%rdi), %r14
callq 0xe740
movq %r14, %rdi
callq 0x6be32
movq (%rbx), %rax
movq %rbx, %rdi
addq $0x8, %rsp
popq %rbx
popq %r14
jmpq *0x10(%rax)
// File: /workspace/github_cpp_makefile_star2_O3/tomfunkhouser[P]gaps/pkgs/R2Shapes/R2Draw.cpp
// Function: gaps::R2Vector::Draw() const
void R2Vector::
Draw(void) const
{
    // Draw vector from (0,0,0)
    R2BeginLine();
    R2LoadPoint(R2zero_point);
    R2LoadPoint((R2zero_point + *this));
    R2EndLine();
}

// Assembly:
pushq %r15
pushq %r14
pushq %rbx
subq $0x10, %rsp
movq %rdi, %rbx
movl $0x3, %edi
callq 0xe110
leaq 0x47c333(%rip), %r14    # 0x4e8280
movq %r14, %rdi
callq 0xe590
movq %rsp, %r15
movq %r15, %rdi
movq %r14, %rsi
movq %rbx, %rdx
callq 0x682cf
movq %r15, %rdi
callq 0xe590
callq 0xe5d0
addq $0x10, %rsp
popq %rbx
popq %r14
popq %r15
retq
nop
// File: /workspace/github_cpp_makefile_star2_O3/tomfunkhouser[P]gaps/pkgs/R2Shapes/R2Draw.cpp
// Function: gaps::R2Line::Draw() const
void R2Line::
Draw(void) const
{
    // Draw line
    R2BeginLine();
    R2LoadPoint(Point());
    R2LoadPoint(Point() + Vector());
    R2EndLine();
}

// Assembly:
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x20, %rsp
movq %rdi, %rbx
movl $0x3, %edi
callq 0xe110
leaq 0x10(%rbx), %r14
movsd 0x20(%rbx), %xmm0
xorps 0x36054(%rip), %xmm0    # 0xa2020
movq %rsp, %r15
movq %r15, %rdi
movq %r14, %rsi
callq 0x6870c
leaq 0x47c29f(%rip), %r12    # 0x4e8280
leaq 0x10(%rsp), %r13
movq %r13, %rdi
movq %r12, %rsi
movq %r15, %rdx
callq 0x682cf
movq %r13, %rdi
callq 0xe590
movsd 0x20(%rbx), %xmm0
xorps 0x36018(%rip), %xmm0    # 0xa2020
movq %rsp, %r15
movq %r15, %rdi
movq %r14, %rsi
callq 0x6870c
leaq 0x10(%rsp), %r14
movq %r14, %rdi
movq %r12, %rsi
movq %r15, %rdx
callq 0x682cf
movq %rsp, %r15
movq %r15, %rdi
movq %r14, %rsi
movq %rbx, %rdx
callq 0x682cf
movq %r15, %rdi
callq 0xe590
callq 0xe5d0
addq $0x20, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
retq
nop
// File: /workspace/github_cpp_makefile_star2_O3/tomfunkhouser[P]gaps/pkgs/R2Shapes/R2Draw.cpp
// Function: gaps::R2Ray::Draw() const
void R2Ray::
Draw(void) const
{
    // Draw ray
    R2BeginLine();
    R2LoadPoint(Start());
    R2LoadPoint((Start() + Vector()));
    R2EndLine();
}

// Assembly:
pushq %r15
pushq %r14
pushq %rbx
subq $0x10, %rsp
movq %rdi, %rbx
movl $0x3, %edi
callq 0xe110
leaq 0x28(%rbx), %r14
movq %r14, %rdi
callq 0xe590
movq %rsp, %r15
movq %r15, %rdi
movq %r14, %rsi
movq %rbx, %rdx
callq 0x682cf
movq %r15, %rdi
callq 0xe590
callq 0xe5d0
addq $0x10, %rsp
popq %rbx
popq %r14
popq %r15
retq
// File: /workspace/github_cpp_makefile_star2_O3/tomfunkhouser[P]gaps/pkgs/R2Shapes/R2Draw.cpp
// Function: gaps::R2Arc::Draw(gaps::RNFlags) const
void R2Arc::
Draw(const R2DrawFlags draw_flags) const
{
    // Draw arc
    if (draw_flags[R2_EDGES_DRAW_FLAG]) {
	R2BeginLine();
	R2LoadPoint(StartPoint());
	int start_index = (int) (1 + R2circle_npoints * StartAngle() / RN_TWO_PI);
	int stop_index = (int) (R2circle_npoints * StopAngle() / RN_TWO_PI);
	for (int i = start_index; i <= stop_index; i++) 
	    R2LoadPoint(Center() + R2circle_points[i % R2circle_npoints] * Radius());
	R2LoadPoint(StopPoint());
	R2EndLine();
    }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movq %rdi, (%rsp)
leaq 0x3de57(%rip), %rax     # 0xa9f40
testq %rsi, (%rax)
je 0x6c1e1
movl $0x3, %edi
callq 0xe110
movq (%rsp), %rbx
movsd 0x28(%rbx), %xmm0
leaq 0x8(%rsp), %r14
movq %r14, %rdi
movq %rbx, %rsi
callq 0x6eb4c
movq %r14, %rdi
callq 0xe590
leaq 0x3de04(%rip), %rax     # 0xa9f28
movl (%rax), %r13d
cvtsi2sd %r13d, %xmm1
movsd 0x28(%rbx), %xmm0
mulsd %xmm1, %xmm0
leaq 0x3deac(%rip), %rax     # 0xa9fe8
movsd (%rax), %xmm2
divsd %xmm2, %xmm0
addsd 0x35eec(%rip), %xmm0    # 0xa2038
cvttsd2si %xmm0, %ebp
movsd 0x30(%rbx), %xmm0
mulsd %xmm0, %xmm1
divsd %xmm2, %xmm1
cvttsd2si %xmm1, %ebx
cmpl %ebx, %ebp
jg 0x6c1c3
movq (%rsp), %rax
leaq 0x10(%rax), %r14
incl %ebx
leaq 0x18(%rsp), %r15
leaq 0x8(%rsp), %r12
movl %ebp, %eax
cltd
idivl %r13d
movslq %edx, %rsi
shlq $0x4, %rsi
addq 0x78e3b(%rip), %rsi     # 0xe4fc8
movq (%rsp), %rax
movsd 0x20(%rax), %xmm0
movq %r15, %rdi
callq 0x6834d
movq %r12, %rdi
movq %r14, %rsi
movq %r15, %rdx
callq 0x682bb
movq %r12, %rdi
callq 0xe590
incl %ebp
cmpl %ebp, %ebx
jne 0x6c179
movq (%rsp), %rax
movsd 0x30(%rax), %xmm0
leaq 0x8(%rsp), %r14
movq %r14, %rdi
movq (%rsp), %rsi
callq 0x6eb4c
movq %r14, %rdi
callq 0xe590
callq 0xe5d0
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
// File: /workspace/github_cpp_makefile_star2_O3/tomfunkhouser[P]gaps/pkgs/R2Shapes/R2Draw.cpp
// Function: gaps::R2Polyline::Draw(gaps::RNFlags) const
void R2Polyline::
Draw(const R2DrawFlags draw_flags) const
{
    // Draw polyline
    R2BeginLine();
    for (int i = 0; i < npoints; i++) R2LoadPoint(points[i]);
    R2EndLine();
}

// Assembly:
pushq %r15
pushq %r14
pushq %rbx
movq %rdi, %rbx
movl $0x3, %edi
callq 0xe110
cmpl $0x0, 0x10(%rbx)
jle 0x6c22a
xorl %r14d, %r14d
xorl %r15d, %r15d
movq 0x8(%rbx), %rdi
addq %r14, %rdi
callq 0xe590
incq %r15
movslq 0x10(%rbx), %rax
addq $0x10, %r14
cmpq %rax, %r15
jl 0x6c20e
popq %rbx
popq %r14
popq %r15
jmp 0xe5d0
// File: /workspace/github_cpp_makefile_star2_O3/tomfunkhouser[P]gaps/pkgs/R2Shapes/R2Draw.cpp
// Function: gaps::R2Box::Draw(gaps::RNFlags) const
void R2Box::
Draw(const R2DrawFlags draw_flags) const
{
    // Draw surface
    if (draw_flags[R2_SURFACES_DRAW_FLAG]) {
        R2BeginPolygon();
        R2LoadPoint(Corner(RN_LO, RN_LO));
        R2LoadPoint(Corner(RN_HI, RN_LO));
        R2LoadPoint(Corner(RN_HI, RN_HI));
        R2LoadPoint(Corner(RN_LO, RN_HI));
	R2EndPolygon();
    }

    // Draw edges
    if (draw_flags[R2_EDGES_DRAW_FLAG]) {
	R2BeginLoop();
        R2LoadPoint(Corner(RN_LO, RN_LO));
        R2LoadPoint(Corner(RN_HI, RN_LO));
        R2LoadPoint(Corner(RN_HI, RN_HI));
        R2LoadPoint(Corner(RN_LO, RN_HI));
	R2EndLoop();
    }    
}

// Assembly:
pushq %r15
pushq %r14
pushq %rbx
subq $0x10, %rsp
movq %rsi, %r14
movq %rdi, %rbx
leaq 0x3dcfe(%rip), %rax     # 0xa9f48
testq %rsi, (%rax)
je 0x6c2d6
movl $0x9, %edi
callq 0xe110
movq %rsp, %r15
movq %r15, %rdi
movq %rbx, %rsi
xorl %edx, %edx
xorl %ecx, %ecx
callq 0x6559a
movq %r15, %rdi
callq 0xe590
movq %rsp, %r15
movq %r15, %rdi
movq %rbx, %rsi
movl $0x1, %edx
xorl %ecx, %ecx
callq 0x6559a
movq %r15, %rdi
callq 0xe590
movq %rsp, %r15
movq %r15, %rdi
movq %rbx, %rsi
movl $0x1, %edx
movl $0x1, %ecx
callq 0x6559a
movq %r15, %rdi
callq 0xe590
movq %rsp, %r15
movq %r15, %rdi
movq %rbx, %rsi
xorl %edx, %edx
movl $0x1, %ecx
callq 0x6559a
movq %r15, %rdi
callq 0xe590
callq 0xe5d0
leaq 0x3dc63(%rip), %rax     # 0xa9f40
testq %r14, (%rax)
je 0x6c369
movl $0x2, %edi
callq 0xe110
movq %rsp, %r14
movq %r14, %rdi
movq %rbx, %rsi
xorl %edx, %edx
xorl %ecx, %ecx
callq 0x6559a
movq %r14, %rdi
callq 0xe590
movq %rsp, %r14
movq %r14, %rdi
movq %rbx, %rsi
movl $0x1, %edx
xorl %ecx, %ecx
callq 0x6559a
movq %r14, %rdi
callq 0xe590
movq %rsp, %r14
movq %r14, %rdi
movq %rbx, %rsi
movl $0x1, %edx
movl $0x1, %ecx
callq 0x6559a
movq %r14, %rdi
callq 0xe590
movq %rsp, %r14
movq %r14, %rdi
movq %rbx, %rsi
xorl %edx, %edx
movl $0x1, %ecx
callq 0x6559a
movq %r14, %rdi
callq 0xe590
callq 0xe5d0
addq $0x10, %rsp
popq %rbx
popq %r14
popq %r15
retq
nop
// File: /workspace/github_cpp_makefile_star2_O3/tomfunkhouser[P]gaps/pkgs/R2Shapes/R2Draw.cpp
// Function: gaps::R2Circle::Draw(gaps::RNFlags) const
void R2Circle::
Draw(const R2DrawFlags draw_flags) const
{
    // Draw surface
    if (draw_flags[R2_SURFACES_DRAW_FLAG]) {
	R2BeginPolygon();
	for (int i = 0; i < R2circle_npoints; i++) 
	    R2LoadPoint(center + R2circle_points[i] * radius);
	R2EndPolygon();
    }

    // Draw edges
    if (draw_flags[R2_EDGES_DRAW_FLAG]) {
	R2BeginLoop();
	for (int i = 0; i < R2circle_npoints; i++) 
	    R2LoadPoint(center + R2circle_points[i] * radius);
	R2EndLoop();
    }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movq %rdi, %rbx
leaq 0x3dbbc(%rip), %rax     # 0xa9f48
testq %rsi, (%rax)
je 0x6c3fb
movq %rsi, (%rsp)
movl $0x9, %edi
callq 0xe110
leaq 0x3db82(%rip), %rax     # 0xa9f28
movslq (%rax), %r14
testq %r14, %r14
jle 0x6c3f2
leaq 0x8(%rbx), %r15
leaq 0x47c137(%rip), %r12    # 0x4e84f0
leaq 0x8(%rsp), %r13
leaq 0x18(%rsp), %rbp
movsd 0x18(%rbx), %xmm0
movq %r13, %rdi
movq %r12, %rsi
callq 0x6834d
movq %rbp, %rdi
movq %r15, %rsi
movq %r13, %rdx
callq 0x682bb
movq %rbp, %rdi
callq 0xe590
addq $0x10, %r12
decq %r14
jne 0x6c3c3
callq 0xe5d0
movq (%rsp), %rsi
leaq 0x3db3e(%rip), %rax     # 0xa9f40
testq %rsi, (%rax)
je 0x6c469
movl $0x2, %edi
callq 0xe110
leaq 0x3db10(%rip), %rax     # 0xa9f28
movslq (%rax), %rbp
testq %rbp, %rbp
jle 0x6c464
leaq 0x8(%rbx), %r14
leaq 0x47c0c5(%rip), %r15    # 0x4e84f0
leaq 0x8(%rsp), %r12
leaq 0x18(%rsp), %r13
movsd 0x18(%rbx), %xmm0
movq %r12, %rdi
movq %r15, %rsi
callq 0x6834d
movq %r13, %rdi
movq %r14, %rsi
movq %r12, %rdx
callq 0x682bb
movq %r13, %rdi
callq 0xe590
addq $0x10, %r15
decq %rbp
jne 0x6c435
callq 0xe5d0
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
// File: /workspace/github_cpp_makefile_star2_O3/tomfunkhouser[P]gaps/pkgs/R2Shapes/R2Draw.cpp
// Function: gaps::R2Polygon::Draw(gaps::RNFlags) const
void R2Polygon::
Draw(const R2DrawFlags draw_flags) const
{
    // Draw surface
    if (draw_flags[R2_SURFACES_DRAW_FLAG]) {
	R2BeginPolygon();
	for (int i = 0; i < npoints; i++) R2LoadPoint(points[i]);
	R2EndPolygon();
    }

    // Draw edges
    if (draw_flags[R2_EDGES_DRAW_FLAG]) {
	R2BeginLoop();
	for (int i = 0; i < npoints; i++) R2LoadPoint(points[i]);
	R2EndLoop();
    }
}

// Assembly:
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
pushq %rax
movq %rsi, %r14
movq %rdi, %rbx
leaq 0x3dabb(%rip), %rax     # 0xa9f48
testq %rsi, (%rax)
je 0x6c4c9
movl $0x9, %edi
callq 0xe110
cmpl $0x0, 0x10(%rbx)
jle 0x6c4c4
xorl %r15d, %r15d
xorl %r12d, %r12d
movq 0x8(%rbx), %rdi
addq %r15, %rdi
callq 0xe590
incq %r12
movslq 0x10(%rbx), %rax
addq $0x10, %r15
cmpq %rax, %r12
jl 0x6c4a8
callq 0xe5d0
leaq 0x3da70(%rip), %rax     # 0xa9f40
testq %r14, (%rax)
je 0x6c517
movl $0x2, %edi
callq 0xe110
cmpl $0x0, 0x10(%rbx)
jle 0x6c507
xorl %r14d, %r14d
xorl %r15d, %r15d
movq 0x8(%rbx), %rdi
addq %r14, %rdi
callq 0xe590
incq %r15
movslq 0x10(%rbx), %rax
addq $0x10, %r14
cmpq %rax, %r15
jl 0x6c4eb
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
jmp 0xe5d0
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
retq
nop
// File: /workspace/github_cpp_makefile_star2_O3/tomfunkhouser[P]gaps/pkgs/R2Shapes/R2Dist.cpp
// Function: gaps::R2Distance(gaps::R2Point const&, gaps::R2Ray const&)
RNLength R2Distance(const R2Point& point, const R2Ray& ray)
{
    // Check if start point is closest
    R2Vector v = point - ray.Start();
    RNScalar dir = v.Dot(ray.Vector());
    if (RNIsNegative(dir)) return v.Length();

    // Return distance from point to ray line
    return R2Distance(point, ray.Line());
}

// Assembly:
pushq %r15
pushq %r14
pushq %rbx
subq $0x10, %rsp
movq %rsi, %rbx
movq %rdi, %r14
leaq 0x28(%rsi), %rdx
movq %rsp, %r15
movq %r15, %rdi
movq %r14, %rsi
callq 0x682e3
movq %r15, %rdi
movq %rbx, %rsi
callq 0x68540
leaq 0x795e9(%rip), %rax     # 0xe5b98
movsd (%rax), %xmm1
xorpd 0x35a65(%rip), %xmm1    # 0xa2020
ucomisd %xmm0, %xmm1
ja 0x6c5f1
movsd (%r14), %xmm1
movsd 0x8(%r14), %xmm0
mulsd 0x18(%rbx), %xmm0
mulsd 0x10(%rbx), %xmm1
addsd %xmm0, %xmm1
addsd 0x20(%rbx), %xmm1
movapd 0x35a39(%rip), %xmm0    # 0xa2020
xorpd %xmm1, %xmm0
maxsd %xmm1, %xmm0
jmp 0x6c5f9
movq %rsp, %rdi
callq 0x68476
addq $0x10, %rsp
popq %rbx
popq %r14
popq %r15
retq
// File: /workspace/github_cpp_makefile_star2_O3/tomfunkhouser[P]gaps/pkgs/R2Shapes/R2Dist.cpp
// Function: gaps::R2Distance(gaps::R2Point const&, gaps::R2Span const&)
RNLength R2Distance(const R2Point& point, const R2Span& span)
{
    // Check span
    if (RNIsZero(span.Length())) return R2Distance(point, span.Start());

    // Check if start point is closest
    R2Vector v1 = point - span.Start();
    RNScalar dir1 = v1.Dot(span.Vector());
    if (RNIsNegative(dir1)) return v1.Length();

    // Check if end point is closest
    R2Vector v2 = point - span.End();
    RNScalar dir2 = v2.Dot(span.Vector());
    if (RNIsPositive(dir2)) return v2.Length();

    // Return distance from point to span line
    return R2Distance(point, span.Line());
}

// Assembly:
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
subq $0x28, %rsp
movq %rsi, %rbx
movq %rdi, %r14
movsd 0x48(%rsi), %xmm0
leaq 0x79578(%rip), %r12     # 0xe5b98
movsd (%r12), %xmm1
movapd 0x359f2(%rip), %xmm2    # 0xa2020
xorpd %xmm1, %xmm2
ucomisd %xmm2, %xmm0
jb 0x6c65d
ucomisd %xmm0, %xmm1
jb 0x6c65d
addq $0x28, %rbx
leaq 0x8(%rsp), %r15
movq %r15, %rdi
movq %r14, %rsi
movq %rbx, %rdx
callq 0x682e3
movq %r15, %rdi
jmp 0x6c6f3
leaq 0x28(%rbx), %rdx
leaq 0x8(%rsp), %r15
movq %r15, %rdi
movq %r14, %rsi
callq 0x682e3
movq %r15, %rdi
movq %rbx, %rsi
callq 0x68540
movsd (%r12), %xmm1
xorpd 0x35996(%rip), %xmm1    # 0xa2020
ucomisd %xmm0, %xmm1
ja 0x6c6e7
leaq 0x38(%rbx), %rdx
leaq 0x18(%rsp), %r15
movq %r15, %rdi
movq %r14, %rsi
callq 0x682e3
movq %r15, %rdi
movq %rbx, %rsi
callq 0x68540
ucomisd (%r12), %xmm0
ja 0x6c6ee
movsd (%r14), %xmm1
movsd 0x8(%r14), %xmm0
mulsd 0x18(%rbx), %xmm0
mulsd 0x10(%rbx), %xmm1
addsd %xmm0, %xmm1
addsd 0x20(%rbx), %xmm1
movapd 0x35943(%rip), %xmm0    # 0xa2020
xorpd %xmm1, %xmm0
maxsd %xmm1, %xmm0
jmp 0x6c6f8
leaq 0x8(%rsp), %rdi
jmp 0x6c6f3
leaq 0x18(%rsp), %rdi
callq 0x68476
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
retq
// File: /workspace/github_cpp_makefile_star2_O3/tomfunkhouser[P]gaps/pkgs/R2Shapes/R2Dist.cpp
// Function: gaps::R2Distance(gaps::R2Point const&, gaps::R2Polyline const&)
RNLength R2Distance(const R2Point& point, const R2Polyline& polyline)
{
    // Compute distance to each segment
    // This could be a lot faster
    RNLength closest_distance = FLT_MAX;
    for (int i = 1; i < polyline.NPoints(); i++) {
        const R2Point& p0 = polyline.Point(i-1);
        const R2Point& p1 = polyline.Point(i);
        R2Span span(p0, p1);
        RNLength d = R2Distance(span, point);
        if (d < closest_distance) closest_distance = d;
    }

    // Return distance
    return closest_distance;
}

// Assembly:
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x60, %rsp
cmpl $0x2, 0x10(%rsi)
jl 0x6c87f
movq %rsi, %rbx
movq %rdi, %r14
movsd 0x35816(%rip), %xmm1    # 0xa2040
movl $0x1, %r12d
movl $0x10, %r13d
leaq 0x10(%rsp), %r15
movsd %xmm1, 0x8(%rsp)
movq 0x8(%rbx), %rdx
leaq (%rdx,%r13), %rsi
addq $-0x10, %rsi
addq %r13, %rdx
movq %r15, %rdi
callq 0x67056
movq %r14, %rdi
movq %r15, %rsi
callq 0x6c603
minsd 0x8(%rsp), %xmm0
incq %r12
movslq 0x10(%rbx), %rax
addq $0x10, %r13
movapd %xmm0, %xmm1
cmpq %rax, %r12
jl 0x6c83b
jmp 0x6c887
movsd 0x357b9(%rip), %xmm0    # 0xa2040
addq $0x60, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
retq
// File: /workspace/github_cpp_makefile_star2_O3/tomfunkhouser[P]gaps/pkgs/R2Shapes/R2Dist.cpp
// Function: gaps::R2Distance(gaps::R2Point const&, gaps::R2Polygon const&)
RNLength R2Distance(const R2Point& point, const R2Polygon& polygon)
{
    // Check if polygon contains point
    if (R2Contains(polygon, point)) return 0;
  
    // Compute distance to each segment
    // This could be a lot faster
    RNLength closest_distance = FLT_MAX;
    for (int i = 0; i < polygon.NPoints(); i++) {
        const R2Point& p0 = polygon.Point(i);
        const R2Point& p1 = polygon.Point((i+1)%polygon.NPoints());
        R2Span span(p0, p1);
        RNLength d = R2Distance(span, point);
        if (d < closest_distance) closest_distance = d;
    }

    // Return distance
    return closest_distance;
}

// Assembly:
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x60, %rsp
movq %rsi, %rbx
movq %rdi, %r14
movq %rsi, %rdi
movq %r14, %rsi
callq 0x57c44
xorpd %xmm0, %xmm0
testl %eax, %eax
jne 0x6c927
movl 0x10(%rbx), %ecx
testl %ecx, %ecx
jle 0x6c91f
movsd 0x35776(%rip), %xmm1    # 0xa2040
xorl %r13d, %r13d
leaq 0x10(%rsp), %r15
xorl %r12d, %r12d
movsd %xmm1, 0x8(%rsp)
movq 0x8(%rbx), %rdi
leaq (%rdi,%r13), %rsi
incq %r12
movl %r12d, %eax
cltd
idivl %ecx
shlq $0x4, %rdx
addq %rdi, %rdx
movq %r15, %rdi
callq 0x67056
movq %r14, %rdi
movq %r15, %rsi
callq 0x6c603
minsd 0x8(%rsp), %xmm0
movslq 0x10(%rbx), %rcx
addq $0x10, %r13
movapd %xmm0, %xmm1
cmpq %rcx, %r12
jl 0x6c8d5
jmp 0x6c927
movsd 0x35719(%rip), %xmm0    # 0xa2040
addq $0x60, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
retq
// File: /workspace/github_cpp_makefile_star2_O3/tomfunkhouser[P]gaps/pkgs/R2Shapes/R2Dist.cpp
// Function: gaps::R2Distance(gaps::R2Line const&, gaps::R2Span const&)
RNLength R2Distance(const R2Line& line, const R2Span& span)
{
    // Return distance from span to line
    RNScalar d = R2SignedDistance(line, span);
    if (RNIsPositive(d)) return d;
    else if (RNIsNegative(d)) return -d;
    else return 0.0;
}

// Assembly:
pushq %rax
callq 0x6cbac
leaq 0x79020(%rip), %rax     # 0xe5b98
movsd (%rax), %xmm2
ucomisd %xmm2, %xmm0
ja 0x6cba2
xorpd 0x35496(%rip), %xmm2    # 0xa2020
xorpd %xmm1, %xmm1
ucomisd %xmm0, %xmm2
jbe 0x6cba6
movapd 0x35484(%rip), %xmm1    # 0xa2020
xorpd %xmm0, %xmm1
jmp 0x6cba6
movapd %xmm0, %xmm1
movapd %xmm1, %xmm0
popq %rax
retq
// File: /workspace/github_cpp_makefile_star2_O3/tomfunkhouser[P]gaps/pkgs/R2Shapes/R2Dist.cpp
// Function: gaps::R2SignedDistance(gaps::R2Line const&, gaps::R2Line const&)
RNLength R2SignedDistance(const R2Line& line1, const R2Line& line2)
{
    // Return signed distance from line to line
    RNScalar dot = line1.Vector().Dot(line2.Vector());
    if (RNIsEqual(dot, 1.0)) return (line1.C() - line2.C());
    else if (RNIsEqual(dot, -1.0)) return (line1.C() + line2.C());
    else return 0.0;
}

// Assembly:
pushq %r14
pushq %rbx
pushq %rax
movq %rsi, %rbx
movq %rdi, %r14
callq 0x68540
leaq 0x78edf(%rip), %rax     # 0xe5b98
movsd (%rax), %xmm2
movsd 0x35383(%rip), %xmm3    # 0xa2048
addsd %xmm0, %xmm3
movapd 0x3534f(%rip), %xmm1    # 0xa2020
xorpd %xmm2, %xmm1
ucomisd %xmm1, %xmm3
jb 0x6ccee
ucomisd %xmm3, %xmm2
jb 0x6ccee
movsd 0x20(%r14), %xmm1
subsd 0x20(%rbx), %xmm1
jmp 0x6cd11
addsd 0x35342(%rip), %xmm0    # 0xa2038
ucomisd %xmm1, %xmm0
xorpd %xmm1, %xmm1
jb 0x6cd11
ucomisd %xmm0, %xmm2
jb 0x6cd11
movsd 0x20(%r14), %xmm1
addsd 0x20(%rbx), %xmm1
movapd %xmm1, %xmm0
addq $0x8, %rsp
popq %rbx
popq %r14
retq
// File: /workspace/github_cpp_makefile_star2_O3/tomfunkhouser[P]gaps/pkgs/R2Shapes/R2Dist.cpp
// Function: gaps::R2SignedDistance(gaps::R2Line const&, gaps::R2Box const&)
RNLength R2SignedDistance(const R2Line& line, const R2Box& box)
{
    // Return signed distance from line to box
    RNQuadrant quadrant = line.Normal().Quadrant();
    RNScalar d1 = R2SignedDistance(line, box.Corner(~quadrant & 0x3));
    if (RNIsPositiveOrZero(d1)) return d1;
    RNScalar d2 = R2SignedDistance(line, box.Corner(quadrant));
    if (RNIsNegative(d2)) return d2;
    else return 0.0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
subq $0x10, %rsp
movq %rsi, %r14
movq %rdi, %rbx
addq $0x10, %rdi
callq 0x68516
movl %eax, %ebp
movl %eax, %edx
notl %edx
andl $0x3, %edx
movq %rsp, %r15
movq %r15, %rdi
movq %r14, %rsi
callq 0x65530
movsd 0x8(%r15), %xmm1
mulsd 0x18(%rbx), %xmm1
movsd (%r15), %xmm0
mulsd 0x10(%rbx), %xmm0
addsd %xmm1, %xmm0
addsd 0x20(%rbx), %xmm0
leaq 0x78dfc(%rip), %r12     # 0xe5b98
movsd (%r12), %xmm1
xorpd 0x35276(%rip), %xmm1    # 0xa2020
ucomisd %xmm1, %xmm0
jae 0x6cdf9
movq %rsp, %r15
movq %r15, %rdi
movq %r14, %rsi
movl %ebp, %edx
callq 0x65530
movsd (%r15), %xmm1
movsd 0x8(%r15), %xmm0
mulsd 0x18(%rbx), %xmm0
mulsd 0x10(%rbx), %xmm1
addsd %xmm0, %xmm1
addsd 0x20(%rbx), %xmm1
movsd (%r12), %xmm2
xorpd 0x35234(%rip), %xmm2    # 0xa2020
movapd %xmm1, %xmm0
cmpnltsd %xmm2, %xmm0
andnpd %xmm1, %xmm0
addq $0x10, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq
// File: /workspace/github_cpp_makefile_star2_O3/tomfunkhouser[P]gaps/pkgs/R2Shapes/R2Dist.cpp
// Function: gaps::R2Distance(gaps::R2Span const&, gaps::R2Halfspace const&)
RNLength R2Distance(const R2Span& span, const R2Halfspace& halfspace)
{
    // Return distance from span to halfspace
    RNScalar d = R2SignedDistance(halfspace.Line(), span);
    if (RNIsNegative(d)) return -d;
    else return 0.0;
}

// Assembly:
pushq %rax
movq %rdi, %rax
movq %rsi, %rdi
movq %rax, %rsi
callq 0x6cbac
leaq 0x78c93(%rip), %rax     # 0xe5b98
movsd (%rax), %xmm1
movapd 0x3510f(%rip), %xmm2    # 0xa2020
xorpd %xmm2, %xmm1
xorpd %xmm0, %xmm2
cmpnltsd %xmm1, %xmm0
andnpd %xmm2, %xmm0
popq %rax
retq
// File: /workspace/github_cpp_makefile_star2_O3/tomfunkhouser[P]gaps/pkgs/R2Shapes/R2Relate.cpp
// Function: gaps::R2InteriorAngle(gaps::R2Vector const&, gaps::R2Vector const&)
RNAngle 
R2InteriorAngle(const R2Vector& vector1, const R2Vector& vector2)
{
    // Return angle between vectors
    RNScalar d1 = vector1.Length();
    if (RNIsZero(d1)) return 0.0;
    RNScalar d2 = vector2.Length();
    if (RNIsZero(d2)) return 0.0;
    RNScalar cosine = vector1.Dot(vector2) / (d1 * d2);
    assert(RNIsGreaterOrEqual(cosine, -1.0) && RNIsLessOrEqual(cosine, 1.0));
    if (cosine >= 1.0) return 0.0;
    else if (cosine <= -1.0) return RN_PI;
    else return acos(cosine); 
}

// Assembly:
pushq %r15
pushq %r14
pushq %rbx
subq $0x10, %rsp
movq %rsi, %rbx
movq %rdi, %r14
callq 0x68476
leaq 0x78ac5(%rip), %r15     # 0xe5b98
movsd (%r15), %xmm2
movapd 0x34f40(%rip), %xmm1    # 0xa2020
xorpd %xmm2, %xmm1
ucomisd %xmm1, %xmm0
xorpd %xmm1, %xmm1
jb 0x6d0f8
ucomisd %xmm0, %xmm2
jae 0x6d17d
movsd %xmm0, 0x8(%rsp)
movq %rbx, %rdi
callq 0x68476
movsd (%r15), %xmm2
movapd 0x34f0d(%rip), %xmm1    # 0xa2020
xorpd %xmm2, %xmm1
ucomisd %xmm1, %xmm0
jb 0x6d129
ucomisd %xmm0, %xmm2
jb 0x6d129
xorpd %xmm1, %xmm1
jmp 0x6d17d
movq %r14, %rdi
movq %rbx, %rsi
movsd %xmm0, (%rsp)
callq 0x68540
movsd 0x8(%rsp), %xmm1
mulsd (%rsp), %xmm1
divsd %xmm1, %xmm0
ucomisd 0x34ee8(%rip), %xmm0    # 0xa2038
xorpd %xmm1, %xmm1
jae 0x6d17d
movsd 0x34eea(%rip), %xmm1    # 0xa2048
ucomisd %xmm0, %xmm1
jae 0x6d172
addq $0x10, %rsp
popq %rbx
popq %r14
popq %r15
jmp 0xe3f0
leaq 0x3ce4f(%rip), %rax     # 0xa9fc8
movsd (%rax), %xmm1
movapd %xmm1, %xmm0
addq $0x10, %rsp
popq %rbx
popq %r14
popq %r15
retq
// File: /workspace/github_cpp_makefile_star2_O3/tomfunkhouser[P]gaps/pkgs/R2Shapes/R2Relate.cpp
// Function: gaps::R2IntersectionArea(gaps::R2Box const&, gaps::R2Box const&)
RNArea 
R2IntersectionArea(const R2Box& box1, const R2Box& box2)
{
  R2Box intersection(box1);
  intersection.Intersect(box2);
  if (intersection.IsEmpty()) return 0;
  return intersection.Area();
}

// Assembly:
pushq %r14
pushq %rbx
subq $0x38, %rsp
movq %rsi, %rbx
movq %rdi, %rsi
leaq 0x10(%rsp), %r14
movq %r14, %rdi
callq 0x65278
movq %r14, %rdi
movq %rbx, %rsi
callq 0x65a66
movsd 0x18(%rsp), %xmm0
ucomisd 0x28(%rsp), %xmm0
xorpd %xmm0, %xmm0
ja 0x6d1e9
movsd 0x20(%rsp), %xmm1
ucomisd 0x30(%rsp), %xmm1
ja 0x6d1e9
leaq 0x10(%rsp), %rdi
callq 0x657a2
movsd %xmm0, 0x8(%rsp)
leaq 0x10(%rsp), %rdi
callq 0x65c14
movsd 0x8(%rsp), %xmm0
addq $0x38, %rsp
popq %rbx
popq %r14
retq
movq %rax, %rbx
leaq 0x10(%rsp), %rdi
callq 0x65c14
movq %rbx, %rdi
callq 0xe7e0
// File: /workspace/github_cpp_makefile_star2_O3/tomfunkhouser[P]gaps/pkgs/R2Shapes/R2Relate.cpp
// Function: gaps::R2Abuts(gaps::R2Box const&, gaps::R2Box const&)
RNBoolean 
R2Abuts(const R2Box& box1, const R2Box& box2) 
{
    // Return whether box1 abuts box2
    if (!R2Intersects(box1, box2)) return FALSE;
    if (RNIsEqual(box1.XMin(), box2.XMax())) return TRUE;
    if (RNIsEqual(box1.XMax(), box2.XMin())) return TRUE;
    if (RNIsEqual(box1.YMin(), box2.YMax())) return TRUE;
    if (RNIsEqual(box1.YMax(), box2.YMin())) return TRUE;
    return FALSE;
}

// Assembly:
pushq %r15
pushq %r14
pushq %rbx
movq %rsi, %rbx
movq %rdi, %r14
xorl %r15d, %r15d
xorl %edx, %edx
callq 0x58c82
testl %eax, %eax
je 0x6d4b9
movsd 0x8(%r14), %xmm2
leaq 0x78756(%rip), %rax     # 0xe5b98
movsd (%rax), %xmm0
subsd 0x18(%rbx), %xmm2
movapd 0x34bcd(%rip), %xmm1    # 0xa2020
xorpd %xmm0, %xmm1
ucomisd %xmm1, %xmm2
movl $0x1, %r15d
jb 0x6d469
ucomisd %xmm2, %xmm0
jae 0x6d4b9
movsd 0x18(%r14), %xmm2
subsd 0x8(%rbx), %xmm2
ucomisd %xmm1, %xmm2
jb 0x6d480
ucomisd %xmm2, %xmm0
jae 0x6d4b9
movsd 0x10(%r14), %xmm2
subsd 0x20(%rbx), %xmm2
ucomisd %xmm1, %xmm2
jb 0x6d497
ucomisd %xmm2, %xmm0
jae 0x6d4b9
movsd 0x20(%r14), %xmm2
subsd 0x10(%rbx), %xmm2
cmplepd %xmm2, %xmm1
cmplepd %xmm0, %xmm2
andpd %xmm1, %xmm2
movd %xmm2, %r15d
andl $0x1, %r15d
movl %r15d, %eax
popq %rbx
popq %r14
popq %r15
retq
// File: /workspace/github_cpp_makefile_star2_O3/tomfunkhouser[P]gaps/pkgs/R2Shapes/R2Relate.cpp
// Function: gaps::R2Splits(gaps::R2Line const&, gaps::R2Span const&)
int 
R2Splits(const R2Line& line, const R2Span& span)
{
    // This is just a simple version 

    // Classify span
    // Result values: 0 = on, 1 = below, 2 = above, 3 = crossing
    RNScalar d1 = R2SignedDistance(line, span.Start());
    RNScalar d2 = R2SignedDistance(line, span.End());
    if (RNIsNegative(d1)) {
        if (RNIsPositive(d2)) return 3;
	else return 1;
    }
    else if (RNIsPositive(d1)) {
        if (RNIsNegative(d2)) return 3;
	else return 2;
    }
    else {
        if (RNIsNegative(d2)) return 1;
        else if (RNIsPositive(d2)) return 2;
	else return 0;
    }
}

// Assembly:
pushq %r14
pushq %rbx
pushq %rax
movq %rsi, %rbx
movq %rdi, %r14
addq $0x28, %rsi
callq 0x6c745
movsd %xmm0, (%rsp)
addq $0x38, %rbx
movq %r14, %rdi
movq %rbx, %rsi
callq 0x6c745
movsd (%rsp), %xmm3
leaq 0x786a3(%rip), %rax     # 0xe5b98
movsd (%rax), %xmm1
movapd 0x34b1f(%rip), %xmm2    # 0xa2020
xorpd %xmm1, %xmm2
ucomisd %xmm3, %xmm2
ja 0x6d529
ucomisd %xmm1, %xmm3
ja 0x6d53b
movl $0x1, %eax
ucomisd %xmm0, %xmm2
ja 0x6d547
xorl %eax, %eax
ucomisd %xmm1, %xmm0
seta %al
addl %eax, %eax
jmp 0x6d547
xorl %eax, %eax
ucomisd %xmm1, %xmm0
seta %al
leal 0x1(,%rax,2), %eax
jmp 0x6d547
xorl %eax, %eax
ucomisd %xmm0, %xmm2
setbe %al
xorl $0x3, %eax
addq $0x8, %rsp
popq %rbx
popq %r14
retq
// File: /workspace/github_cpp_makefile_star2_O3/tomfunkhouser[P]gaps/pkgs/R2Shapes/R2Align.cpp
// Function: gaps::R2Centroid(gaps::RNArray<gaps::R2Point*> const&, double const*)
R2Point 
R2Centroid(const RNArray<R2Point *>& points, const RNScalar *weights)
{
  // Compute center of mass
  R2Point centroid(0.0, 0.0);
  RNScalar total_weight = 0;
  for (int i = 0; i < points.NEntries(); i++) {
    RNScalar weight = (weights) ? weights[i] : 1;
    R2Point *point = points[i];
    centroid += *point * weight;
    total_weight += weight;
  }

  // Compute average
  if (total_weight > 0) centroid /= total_weight;

  // Return center of mass
  return centroid;
}

// Assembly:
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x20, %rsp
movq %rdx, %r14
movq %rsi, %r15
movq %rdi, %rbx
xorpd %xmm0, %xmm0
xorpd %xmm1, %xmm1
callq 0x680a6
xorpd %xmm0, %xmm0
cmpl $0x0, 0xc(%r15)
jle 0x6d973
xorl %r13d, %r13d
leaq 0x10(%rsp), %r12
movsd %xmm0, 0x8(%rsp)
movsd 0x34718(%rip), %xmm0    # 0xa2038
testq %r14, %r14
je 0x6d92b
movsd (%r14,%r13,8), %xmm0
movq (%r15), %rax
movq (%rax,%r13,8), %rsi
movq %r12, %rdi
movsd %xmm0, (%rsp)
callq 0x6834d
movq %rbx, %rdi
movq %r12, %rsi
callq 0x681f4
movsd 0x8(%rsp), %xmm0
addsd (%rsp), %xmm0
incq %r13
movslq 0xc(%r15), %rax
cmpq %rax, %r13
jl 0x6d912
xorpd %xmm1, %xmm1
ucomisd %xmm1, %xmm0
jbe 0x6d973
movq %rbx, %rdi
callq 0x6828c
movq %rbx, %rax
addq $0x20, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
retq
// File: /workspace/github_cpp_makefile_star2_O3/tomfunkhouser[P]gaps/pkgs/R2Shapes/R2Align.cpp
// Function: gaps::R2AverageDistance(gaps::R2Point const&, gaps::RNArray<gaps::R2Point*> const&, double const*)
RNLength
R2AverageDistance(const R2Point& center, const RNArray<R2Point *>& points, const RNScalar *weights)
{
  // Compute sum of distances between a position on the surface and a center point
  RNScalar distance = 0.0;
  RNScalar total_weight = 0;
  for (int i = 0; i < points.NEntries(); i++) {
    RNScalar weight = (weights) ? weights[i] : 1;
    R2Point *point = points[i];
    distance += weight * R2Distance(*point, center);
    total_weight += weight;
  }

  // Compute average distance
  if (total_weight > 0) distance /= total_weight;

  // Return average distance
  return distance;
}

// Assembly:
cmpl $0x0, 0xc(%rsi)
xorpd %xmm3, %xmm3
xorpd %xmm2, %xmm2
jle 0x6dcf5
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
subq $0x38, %rsp
movq %rdx, %rbx
movq %rsi, %r14
movq %rdi, %r15
xorpd %xmm2, %xmm2
xorl %r12d, %r12d
xorpd %xmm3, %xmm3
movapd %xmm3, 0x10(%rsp)
movapd %xmm2, 0x20(%rsp)
movsd 0x34398(%rip), %xmm0    # 0xa2038
testq %rbx, %rbx
je 0x6dcab
movsd (%rbx,%r12,8), %xmm0
movsd %xmm0, 0x8(%rsp)
movq (%r14), %rax
movq (%rax,%r12,8), %rdi
movq %r15, %rsi
callq 0x6c52b
movsd 0x8(%rsp), %xmm1
mulsd %xmm1, %xmm0
movapd 0x20(%rsp), %xmm2
addsd %xmm0, %xmm2
movapd 0x10(%rsp), %xmm3
addsd %xmm1, %xmm3
incq %r12
movslq 0xc(%r14), %rax
cmpq %rax, %r12
jl 0x6dc8c
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
movapd %xmm2, %xmm1
divsd %xmm3, %xmm1
xorpd %xmm0, %xmm0
cmpltsd %xmm3, %xmm0
andpd %xmm0, %xmm1
andnpd %xmm2, %xmm0
orpd %xmm1, %xmm0
retq