// File: /workspace/github_c_makefile_star2_O3/genometools[P]genometools/src/annotationsketch/graphics_cairo.c
// Function: gt_graphics_cairo_save_to_file
int gt_graphics_cairo_save_to_file(const GtGraphics *gg, const char *filename,
                                GtError *err)
{
  const GtGraphicsCairo *g = (const GtGraphicsCairo*) gg;
  cairo_surface_t *bgsurf = NULL;
  cairo_t *bgc = NULL;
  cairo_status_t rval;
  GtFile *outfile;
  gt_error_check(err);
  gt_assert(g && filename);

  /* do nothing if no surface was created */
  if (g->from_context)
    return 0;
  switch (g->type)
  {
    case GT_GRAPHICS_PNG:
      /* blend rendered image with background color */
      bgsurf = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, g->width,
                                          g->height);
      bgc = cairo_create(bgsurf);
      cairo_set_source_rgba(bgc, g->bg_color.red, g->bg_color.green,
                                 g->bg_color.blue, g->bg_color.alpha);
      cairo_paint(bgc);
      cairo_set_source_surface(bgc, g->surf, 0, 0);
      cairo_paint(bgc);
      rval = cairo_surface_write_to_png(bgsurf, filename);
      gt_assert(rval == CAIRO_STATUS_SUCCESS ||
                rval == CAIRO_STATUS_WRITE_ERROR);
      if (rval == CAIRO_STATUS_WRITE_ERROR)
      {
        cairo_destroy(bgc);
        cairo_surface_destroy(bgsurf);
        gt_error_set(err, "an I/O error occurred while attempting "
                          "to write image file \"%s\"", filename);
        return -1;
      }
      cairo_destroy(bgc);
      cairo_surface_destroy(bgsurf);
      break;
    default:
      cairo_show_page(g->cr);
      cairo_surface_flush(g->surf);
      cairo_surface_finish(g->surf);
      outfile = gt_file_open(GT_FILE_MODE_UNCOMPRESSED, filename, "w+", err);
      if (outfile)
      {
        gt_file_xwrite(outfile, gt_str_get_mem(g->outbuf),
                       gt_str_length(g->outbuf));
        gt_file_delete(outfile);
      } else return -1;
      break;
  }
  return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movq %rdx, %rbx
movq %rsi, %r14
movq %rdi, %r15
testq %rdx, %rdx
je 0x50d41
movq %rbx, %rdi
callq 0x34fea
testb %al, %al
jne 0x50ea5
testq %r15, %r15
je 0x50ea0
testq %r14, %r14
je 0x50ea0
xorl %ebp, %ebp
cmpb $0x0, 0x70(%r15)
jne 0x50e8f
cmpl $0x1, 0x48(%r15)
jne 0x50e12
cvttsd2si 0x68(%r15), %esi
cvttsd2si 0x60(%r15), %edx
xorl %ebp, %ebp
xorl %edi, %edi
callq 0xb850
movq %rax, %r12
movq %rax, %rdi
callq 0xb1e0
movq %rax, %r13
movsd 0x20(%r15), %xmm0
movsd 0x28(%r15), %xmm1
movsd 0x30(%r15), %xmm2
movsd 0x38(%r15), %xmm3
movq %rax, %rdi
callq 0xb380
movq %r13, %rdi
callq 0xba80
movq 0x18(%r15), %rsi
xorps %xmm0, %xmm0
xorps %xmm1, %xmm1
movq %r13, %rdi
callq 0xbbe0
movq %r13, %rdi
callq 0xba80
movq %r12, %rdi
movq %r14, %rsi
callq 0xb140
testl %eax, %eax
je 0x50e7f
cmpl $0xb, %eax
jne 0x50eaa
movq %r13, %rdi
callq 0xb8c0
movq %r12, %rdi
callq 0xb7a0
leaq 0x9a816(%rip), %rsi     # 0xeb619
movq %rbx, %rdi
movq %r14, %rdx
xorl %eax, %eax
callq 0x34f1f
jmp 0x50e78
movq 0x10(%r15), %rdi
callq 0xb4a0
movq 0x18(%r15), %rdi
callq 0xbaf0
movq 0x18(%r15), %rdi
callq 0xb230
leaq 0x9a825(%rip), %rdx     # 0xeb659
xorl %ebp, %ebp
xorl %edi, %edi
movq %r14, %rsi
movq %rbx, %rcx
callq 0x75969
testq %rax, %rax
je 0x50e78
movq %rax, %rbx
movq 0x40(%r15), %rdi
callq 0x3bb77
movq %rax, %r14
movq 0x40(%r15), %rdi
callq 0x3bb86
movq %rbx, %rdi
movq %r14, %rsi
movq %rax, %rdx
callq 0x76024
movq %rbx, %rdi
callq 0x760c0
jmp 0x50e8f
movl $0xffffffff, %ebp       # imm = 0xFFFFFFFF
jmp 0x50e8f
movq %r13, %rdi
callq 0xb8c0
movq %r12, %rdi
callq 0xb7a0
movl %ebp, %eax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
callq 0x16ee7
callq 0x16eae
callq 0x16f20