// File: /workspace/github_cpp_makefile_star2_O2/xukmin[P]rase/svg-printer.cc
// Function: SvgPrinter::PrintNetwork(SensorNetwork const&, bool, bool)
void SvgPrinter::PrintNetwork(const SensorNetwork& network,
                              bool print_channels,
                              bool print_routings) {
  const static int RADIUS = 8;
  const static int STROKE_WIDTH = 1;
  const static int FONT_HEIGHT = 20;
  PositionConverter c(scale_, Position(RADIUS + STROKE_WIDTH,
                                       RADIUS + STROKE_WIDTH));

  int w = int((region_.max_x - region_.min_x) * scale_ +
              (RADIUS + STROKE_WIDTH) * 2);
  int h = int((region_.max_y - region_.min_y) * scale_ +
              (RADIUS + STROKE_WIDTH) * 2);
  fprintf(file_,
          "<svg width='%d' height='%d'"
          " xmlns='http://www.w3.org/2000/svg'"
          " xmlns:xlink='http://www.w3.org/1999/xlink'>\n"
          "<rect x='0' y='0' width='%d' height='%d'"
          " style='fill:white;stroke:black;stroke-width:1;' />\n",
          w, h + FONT_HEIGHT * 2, w, h);

  for (int i = 0; i < network.num_sensors(); i++) {
    const Position& p = network.GetPosition(i);
    if (print_channels) {
      const std::set<int>& neighbors = network.GetNeighbors(i);
      for (std::set<int>::const_iterator neighbor = neighbors.begin();
           neighbor != neighbors.end();
           ++neighbor) {
        if (i < *neighbor) {
          const Position& q = network.GetPosition(*neighbor);
          fprintf(file_,
                  "<path d='M %f %f L %f %f' stroke='gray' stroke-width='1'"
                   " stroke-dasharray='1,1' />\n",
                   c.ConvertX(p.x), c.ConvertY(p.y),
                   c.ConvertX(q.x), c.ConvertY(q.y));
        }
      }
    }
    if (print_routings) {
      int parent = network.GetParent(i);
      if (parent != -1) {
        const Position& q = network.GetPosition(parent);
        fprintf(file_,
                "<line x1='%f' y1='%f' x2='%f' y2='%f' "
                " style='stroke:royalblue;stroke-width:2' />\n",
                c.ConvertX(p.x), c.ConvertY(p.y),
                c.ConvertX(q.x), c.ConvertY(q.y));
      }
    }
  }

  if (network.num_sensors() > 0) {
    fprintf(file_,
            "<circle cx='%f' cy='%f' r='%d' stroke='yellow' stroke-width='%d'"
            " fill='red' />\n",
            c.ConvertX(network.GetPosition(0).x),
            c.ConvertY(network.GetPosition(0).y),
            RADIUS, STROKE_WIDTH);
  }
  for (int i = 1; i < network.num_sensors(); i++) {
    const Position& p = network.GetPosition(i);
    fprintf(file_,
            "<circle cx='%f' cy='%f' r='%d' stroke='green' stroke-width='%d'"
            " fill='yellow' />\n",
            c.ConvertX(p.x), c.ConvertY(p.y), RADIUS, STROKE_WIDTH);
  }

  fprintf(file_,
          "<text x='%d' y='%d' fill='royalblue' text-anchor='middle' "
          "alignment-baseline='middle' font-size='%dpx'>%s</text>\n",
          w / 2, h + FONT_HEIGHT, FONT_HEIGHT, title_.c_str());
  fprintf(file_, "</svg>\n");
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movl %ecx, 0x14(%rsp)
movl %edx, 0x10(%rsp)
movq %rsi, %r14
movsd 0x60(%rdi), %xmm3
movsd 0x50(%rdi), %xmm0
movsd 0x58(%rdi), %xmm1
subsd 0x40(%rdi), %xmm0
mulsd %xmm3, %xmm0
movsd 0x1545(%rip), %xmm2     # 0x8ca8
addsd %xmm2, %xmm0
cvttsd2si %xmm0, %edx
subsd 0x48(%rdi), %xmm1
movsd %xmm3, (%rsp)
mulsd %xmm3, %xmm1
addsd %xmm2, %xmm1
cvttsd2si %xmm1, %r9d
movq %rdi, %rbp
movq 0x68(%rdi), %rdi
leal 0x28(%r9), %ecx
leaq 0x153f(%rip), %rsi      # 0x8cd3
xorl %r12d, %r12d
movl %edx, 0xc(%rsp)
movl %edx, %r8d
movq %r9, 0x20(%rsp)
xorl %eax, %eax
callq 0x3210
movq (%r14), %rcx
movq 0x8(%r14), %rax
subq %rcx, %rax
cqto
pushq $0x48
popq %rsi
idivq %rsi
movslq %eax, %rdx
cmpq %rdx, %r12
jge 0x78e5
imulq $0x48, %r12, %rax
movq %rax, 0x18(%rsp)
leaq (%rcx,%rax), %r13
cmpb $0x0, 0x10(%rsp)
je 0x7869
movq 0x18(%rsp), %rax
leaq (%rcx,%rax), %rbx
addq $0x18, %rbx
movq 0x10(%rbx), %r15
cmpq %rbx, %r15
je 0x7869
movslq 0x20(%r15), %rax
cmpq %rax, %r12
jge 0x785c
movq (%r14), %rcx
imulq $0x48, %rax, %rax
movq 0x68(%rbp), %rdi
movsd (%r13), %xmm0
movsd (%rsp), %xmm4
mulsd %xmm4, %xmm0
movsd 0x148f(%rip), %xmm5     # 0x8cb0
addsd %xmm5, %xmm0
movsd 0x8(%r13), %xmm1
mulsd %xmm4, %xmm1
addsd %xmm5, %xmm1
movsd (%rcx,%rax), %xmm2
mulsd %xmm4, %xmm2
addsd %xmm5, %xmm2
movsd 0x8(%rcx,%rax), %xmm3
mulsd %xmm4, %xmm3
addsd %xmm5, %xmm3
leaq 0x1546(%rip), %rsi      # 0x8d9b
movb $0x4, %al
callq 0x3210
movq %r15, %rdi
callq 0x31a0
movq %rax, %r15
jmp 0x77f1
cmpb $0x0, 0x14(%rsp)
je 0x78dd
movq (%r14), %rax
movq 0x18(%rsp), %rcx
movslq 0x44(%rax,%rcx), %rcx
cmpq $-0x1, %rcx
je 0x78dd
imulq $0x48, %rcx, %rcx
movq 0x68(%rbp), %rdi
movsd (%r13), %xmm0
movsd (%rsp), %xmm4
mulsd %xmm4, %xmm0
movsd 0x140e(%rip), %xmm5     # 0x8cb0
addsd %xmm5, %xmm0
movsd 0x8(%r13), %xmm1
mulsd %xmm4, %xmm1
addsd %xmm5, %xmm1
movsd (%rax,%rcx), %xmm2
mulsd %xmm4, %xmm2
addsd %xmm5, %xmm2
movsd 0x8(%rax,%rcx), %xmm3
mulsd %xmm4, %xmm3
addsd %xmm5, %xmm3
leaq 0x1519(%rip), %rsi      # 0x8def
movb $0x4, %al
callq 0x3210
incq %r12
jmp 0x77aa
testl %eax, %eax
jle 0x7927
movq 0x68(%rbp), %rdi
movsd (%rcx), %xmm0
movsd (%rsp), %xmm2
mulsd %xmm2, %xmm0
movsd 0x13ae(%rip), %xmm3     # 0x8cb0
addsd %xmm3, %xmm0
movsd 0x8(%rcx), %xmm1
mulsd %xmm2, %xmm1
addsd %xmm3, %xmm1
leaq 0x1528(%rip), %rsi      # 0x8e42
pushq $0x8
popq %rdx
pushq $0x1
popq %rcx
movb $0x2, %al
callq 0x3210
pushq $0x1
popq %rbx
pushq $0x50
popq %r13
pushq $0x8
popq %r15
pushq $0x1
popq %r12
movq (%r14), %rcx
movq 0x8(%r14), %rax
subq %rcx, %rax
cqto
pushq $0x48
popq %rsi
idivq %rsi
cltq
cmpq %rax, %rbx
jge 0x799a
movq 0x68(%rbp), %rdi
movsd -0x8(%rcx,%r13), %xmm0
movsd (%rsp), %xmm2
mulsd %xmm2, %xmm0
movsd 0x1345(%rip), %xmm3     # 0x8cb0
addsd %xmm3, %xmm0
movsd (%rcx,%r13), %xmm1
mulsd %xmm2, %xmm1
addsd %xmm3, %xmm1
leaq 0x150e(%rip), %rsi      # 0x8e92
movl %r15d, %edx
movl %r12d, %ecx
movb $0x2, %al
callq 0x3210
incq %rbx
addq $0x48, %r13
jmp 0x7936
movq 0x20(%rbp), %r9
movq 0x68(%rbp), %rdi
pushq $0x2
popq %rcx
movl 0xc(%rsp), %eax
cltd
idivl %ecx
movq 0x20(%rsp), %rcx
addl $0x14, %ecx
leaq 0x1529(%rip), %rsi      # 0x8ee4
pushq $0x14
popq %r8
movl %eax, %edx
xorl %eax, %eax
callq 0x3210
movq 0x68(%rbp), %rcx
leaq 0x1583(%rip), %rdi      # 0x8f56
pushq $0x7
popq %rsi
pushq $0x1
popq %rdx
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x32c0