// File: /workspace/github_c_makefile_star2_O1/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 0x519c8
movq %rbx, %rdi
callq 0x3566a
testb %al, %al
jne 0x51b2c
testq %r15, %r15
je 0x51b27
testq %r14, %r14
je 0x51b27
xorl %ebp, %ebp
cmpb $0x0, 0x70(%r15)
jne 0x51b16
cmpl $0x1, 0x48(%r15)
jne 0x51a99
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 0x51b06
cmpl $0xb, %eax
jne 0x51b31
movq %r13, %rdi
callq 0xb8c0
movq %r12, %rdi
callq 0xb7a0
leaq 0x99bdf(%rip), %rsi     # 0xeb669
movq %rbx, %rdi
movq %r14, %rdx
xorl %eax, %eax
callq 0x3559f
jmp 0x51aff
movq 0x10(%r15), %rdi
callq 0xb4a0
movq 0x18(%r15), %rdi
callq 0xbaf0
movq 0x18(%r15), %rdi
callq 0xb230
leaq 0x99bee(%rip), %rdx     # 0xeb6a9
xorl %ebp, %ebp
xorl %edi, %edi
movq %r14, %rsi
movq %rbx, %rcx
callq 0x75422
testq %rax, %rax
je 0x51aff
movq %rax, %rbx
movq 0x40(%r15), %rdi
callq 0x3c425
movq %rax, %r14
movq 0x40(%r15), %rdi
callq 0x3c434
movq %rbx, %rdi
movq %r14, %rsi
movq %rax, %rdx
callq 0x75ae0
movq %rbx, %rdi
callq 0x75b7c
jmp 0x51b16
movl $0xffffffff, %ebp       # imm = 0xFFFFFFFF
jmp 0x51b16
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 0x17039
callq 0x17000
callq 0x17072