// File: /workspace/github_c_makefile_star2_O2/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 0x30463
movq %rbx, %rdi
callq 0xc103
testb %al, %al
jne 0x305ee
testq %r15, %r15
je 0x305c0
testq %r14, %r14
je 0x305c0
xorl %ebp, %ebp
cmpb $0x0, 0x70(%r15)
jne 0x305af
cmpl $0x1, 0x48(%r15)
jne 0x30534
cvttsd2si 0x68(%r15), %esi
cvttsd2si 0x60(%r15), %edx
xorl %ebp, %ebp
xorl %edi, %edi
callq 0xb840
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 0xba70
movq 0x18(%r15), %rsi
xorps %xmm0, %xmm0
xorps %xmm1, %xmm1
movq %r13, %rdi
callq 0xbbd0
movq %r13, %rdi
callq 0xba70
movq %r12, %rdi
movq %r14, %rsi
callq 0xb140
testl %eax, %eax
je 0x3059f
cmpl $0xb, %eax
jne 0x30626
movq %r13, %rdi
callq 0xb8b0
movq %r12, %rdi
callq 0xb7a0
leaq 0xa40e4(%rip), %rsi     # 0xd4609
movq %rbx, %rdi
movq %r14, %rdx
xorl %eax, %eax
callq 0xc007
jmp 0x3059a
movq 0x10(%r15), %rdi
callq 0xb4a0
movq 0x18(%r15), %rdi
callq 0xbae0
movq 0x18(%r15), %rdi
callq 0xb230
leaq 0xa40f3(%rip), %rdx     # 0xd4649
xorl %ebp, %ebp
xorl %edi, %edi
movq %r14, %rsi
movq %rbx, %rcx
callq 0x53d4e
testq %rax, %rax
je 0x3059a
movq %rax, %rbx
movq 0x40(%r15), %rdi
callq 0x1441f
movq %rax, %r14
movq 0x40(%r15), %rdi
callq 0x14461
movq %rbx, %rdi
movq %r14, %rsi
movq %rax, %rdx
callq 0x5478b
movq %rbx, %rdi
callq 0x548ae
jmp 0x305af
pushq $-0x1
popq %rbp
jmp 0x305af
movq %r13, %rdi
callq 0xb8b0
movq %r12, %rdi
callq 0xb7a0
movl %ebp, %eax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0xfd9f1(%rip), %rax     # 0x12dfb8
movq (%rax), %rdi
leaq 0x99a95(%rip), %rsi     # 0xca066
leaq 0xa3fe2(%rip), %rdx     # 0xd45ba
leaq 0xa3fbc(%rip), %rcx     # 0xd459b
leaq 0xa3b86(%rip), %r8      # 0xd416c
movl $0x28e, %r9d            # imm = 0x28E
jmp 0x3061a
movq 0xfd9c3(%rip), %rax     # 0x12dfb8
movq (%rax), %rdi
leaq 0x99a67(%rip), %rsi     # 0xca066
leaq 0x9a053(%rip), %rdx     # 0xca659
leaq 0xa3f8e(%rip), %rcx     # 0xd459b
leaq 0xa3b58(%rip), %r8      # 0xd416c
movl $0x28d, %r9d            # imm = 0x28D
xorl %eax, %eax
callq 0xb8c0
callq 0xb300
movq 0xfd98b(%rip), %rax     # 0x12dfb8
movq (%rax), %rdi
leaq 0x99a2f(%rip), %rsi     # 0xca066
leaq 0xa3f8a(%rip), %rdx     # 0xd45c8
leaq 0xa3f56(%rip), %rcx     # 0xd459b
leaq 0xa3b20(%rip), %r8      # 0xd416c
movl $0x2a1, %r9d            # imm = 0x2A1
jmp 0x3061a