// File: 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
movq %rsp, %rbp
subq $0x130, %rsp            # imm = 0x130
movb %cl, %al
movb %dl, %cl
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
andb $0x1, %cl
movb %cl, -0x11(%rbp)
andb $0x1, %al
movb %al, -0x12(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0xa0(%rbp)
movsd 0x60(%rax), %xmm0
movsd %xmm0, -0xa8(%rbp)
leaq -0x40(%rbp), %rdi
movsd 0x1f02(%rip), %xmm1     # 0x14c98
movaps %xmm1, %xmm0
callq 0x6180
movsd -0xa8(%rbp), %xmm0
leaq -0x30(%rbp), %rdi
leaq -0x40(%rbp), %rsi
callq 0x132d0
movq -0xa0(%rbp), %rax
movsd 0x50(%rax), %xmm0
subsd 0x40(%rax), %xmm0
movsd 0x60(%rax), %xmm1
mulsd %xmm1, %xmm0
movsd 0x1ebb(%rip), %xmm1     # 0x14c90
addsd %xmm1, %xmm0
cvttsd2si %xmm0, %ecx
movl %ecx, -0x44(%rbp)
movsd 0x58(%rax), %xmm0
subsd 0x48(%rax), %xmm0
movsd 0x60(%rax), %xmm1
mulsd %xmm1, %xmm0
movsd 0x1e95(%rip), %xmm1     # 0x14c90
addsd %xmm1, %xmm0
cvttsd2si %xmm0, %ecx
movl %ecx, -0x48(%rbp)
movq 0x68(%rax), %rdi
movl -0x44(%rbp), %edx
movl -0x48(%rbp), %ecx
addl $0x28, %ecx
movl -0x44(%rbp), %r8d
movl -0x48(%rbp), %r9d
leaq 0x1e99(%rip), %rsi      # 0x14cbb
movb $0x0, %al
callq 0x32d0
movl $0x0, -0x4c(%rbp)
movl -0x4c(%rbp), %eax
movl %eax, -0xac(%rbp)
movq -0x10(%rbp), %rdi
callq 0x87a0
movl %eax, %ecx
movl -0xac(%rbp), %eax
cmpl %ecx, %eax
jge 0x1309b
movq -0x10(%rbp), %rdi
movl -0x4c(%rbp), %esi
callq 0x13310
movq %rax, -0x58(%rbp)
testb $0x1, -0x11(%rbp)
je 0x12faa
movq -0x10(%rbp), %rdi
movl -0x4c(%rbp), %esi
callq 0x8900
movq %rax, -0x60(%rbp)
movq -0x60(%rbp), %rdi
callq 0x8480
movq %rax, -0x68(%rbp)
movq -0x60(%rbp), %rdi
callq 0x84b0
movq %rax, -0x70(%rbp)
leaq -0x68(%rbp), %rdi
leaq -0x70(%rbp), %rsi
callq 0x8930
testb $0x1, %al
jne 0x12eac
jmp 0x12fa8
movl -0x4c(%rbp), %eax
movl %eax, -0xb0(%rbp)
leaq -0x68(%rbp), %rdi
callq 0x89c0
movq %rax, %rcx
movl -0xb0(%rbp), %eax
cmpl (%rcx), %eax
jge 0x12f98
movq -0x10(%rbp), %rax
movq %rax, -0xd8(%rbp)
leaq -0x68(%rbp), %rdi
callq 0x89c0
movq -0xd8(%rbp), %rdi
movl (%rax), %esi
callq 0x13310
movq %rax, %rcx
movq -0xa0(%rbp), %rax
movq %rcx, -0x78(%rbp)
movq 0x68(%rax), %rax
movq %rax, -0xd0(%rbp)
movq -0x58(%rbp), %rax
movsd (%rax), %xmm0
leaq -0x30(%rbp), %rdi
callq 0x13340
movsd %xmm0, -0xb8(%rbp)
movq -0x58(%rbp), %rax
movsd 0x8(%rax), %xmm0
leaq -0x30(%rbp), %rdi
callq 0x13370
movsd %xmm0, -0xc8(%rbp)
movq -0x78(%rbp), %rax
movsd (%rax), %xmm0
leaq -0x30(%rbp), %rdi
callq 0x13340
movsd %xmm0, -0xc0(%rbp)
movq -0x78(%rbp), %rax
movsd 0x8(%rax), %xmm0
leaq -0x30(%rbp), %rdi
callq 0x13370
movq -0xd0(%rbp), %rdi
movsd -0xc8(%rbp), %xmm1
movsd -0xc0(%rbp), %xmm2
movaps %xmm0, %xmm3
movsd -0xb8(%rbp), %xmm0
leaq 0x1df2(%rip), %rsi      # 0x14d83
movb $0x4, %al
callq 0x32d0
jmp 0x12f9a
leaq -0x68(%rbp), %rdi
callq 0x8a90
jmp 0x12e89
jmp 0x12faa
testb $0x1, -0x12(%rbp)
je 0x1308b
movq -0x10(%rbp), %rdi
movl -0x4c(%rbp), %esi
callq 0x8b00
movl %eax, -0x7c(%rbp)
cmpl $-0x1, -0x7c(%rbp)
je 0x13089
movq -0x10(%rbp), %rdi
movl -0x7c(%rbp), %esi
callq 0x13310
movq %rax, %rcx
movq -0xa0(%rbp), %rax
movq %rcx, -0x88(%rbp)
movq 0x68(%rax), %rax
movq %rax, -0xf8(%rbp)
movq -0x58(%rbp), %rax
movsd (%rax), %xmm0
leaq -0x30(%rbp), %rdi
callq 0x13340
movsd %xmm0, -0xe0(%rbp)
movq -0x58(%rbp), %rax
movsd 0x8(%rax), %xmm0
leaq -0x30(%rbp), %rdi
callq 0x13370
movsd %xmm0, -0xf0(%rbp)
movq -0x88(%rbp), %rax
movsd (%rax), %xmm0
leaq -0x30(%rbp), %rdi
callq 0x13340
movsd %xmm0, -0xe8(%rbp)
movq -0x88(%rbp), %rax
movsd 0x8(%rax), %xmm0
leaq -0x30(%rbp), %rdi
callq 0x13370
movq -0xf8(%rbp), %rdi
movsd -0xf0(%rbp), %xmm1
movsd -0xe8(%rbp), %xmm2
movaps %xmm0, %xmm3
movsd -0xe0(%rbp), %xmm0
leaq 0x1d55(%rip), %rsi      # 0x14dd7
movb $0x4, %al
callq 0x32d0
jmp 0x1308b
jmp 0x1308d
movl -0x4c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x4c(%rbp)
jmp 0x12e30
movq -0x10(%rbp), %rdi
callq 0x87a0
cmpl $0x0, %eax
jle 0x1311e
movq -0xa0(%rbp), %rax
movq 0x68(%rax), %rax
movq %rax, -0x108(%rbp)
movq -0x10(%rbp), %rdi
xorl %esi, %esi
callq 0x13310
movsd (%rax), %xmm0
leaq -0x30(%rbp), %rdi
callq 0x13340
movsd %xmm0, -0x100(%rbp)
movq -0x10(%rbp), %rdi
xorl %esi, %esi
callq 0x13310
movsd 0x8(%rax), %xmm0
leaq -0x30(%rbp), %rdi
callq 0x13370
movq -0x108(%rbp), %rdi
movaps %xmm0, %xmm1
movsd -0x100(%rbp), %xmm0
leaq 0x1d1d(%rip), %rsi      # 0x14e2a
movl $0x8, %edx
movl $0x1, %ecx
movb $0x2, %al
callq 0x32d0
movl $0x1, -0x8c(%rbp)
movl -0x8c(%rbp), %eax
movl %eax, -0x10c(%rbp)
movq -0x10(%rbp), %rdi
callq 0x87a0
movl %eax, %ecx
movl -0x10c(%rbp), %eax
cmpl %ecx, %eax
jge 0x131e7
movq -0x10(%rbp), %rdi
movl -0x8c(%rbp), %esi
callq 0x13310
movq %rax, %rcx
movq -0xa0(%rbp), %rax
movq %rcx, -0x98(%rbp)
movq 0x68(%rax), %rax
movq %rax, -0x120(%rbp)
movq -0x98(%rbp), %rax
movsd (%rax), %xmm0
leaq -0x30(%rbp), %rdi
callq 0x13340
movsd %xmm0, -0x118(%rbp)
movq -0x98(%rbp), %rax
movsd 0x8(%rax), %xmm0
leaq -0x30(%rbp), %rdi
callq 0x13370
movq -0x120(%rbp), %rdi
movaps %xmm0, %xmm1
movsd -0x118(%rbp), %xmm0
leaq 0x1cb8(%rip), %rsi      # 0x14e7a
movl $0x8, %edx
movl $0x1, %ecx
movb $0x2, %al
callq 0x32d0
movl -0x8c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x8c(%rbp)
jmp 0x13128
movq -0xa0(%rbp), %rdi
movq 0x68(%rdi), %rax
movq %rax, -0x130(%rbp)
movl -0x44(%rbp), %eax
movl $0x2, %ecx
cltd
idivl %ecx
movl %eax, -0x128(%rbp)
movl -0x48(%rbp), %eax
addl $0x14, %eax
movl %eax, -0x124(%rbp)
addq $0x20, %rdi
callq 0x30b0
movq -0x130(%rbp), %rdi
movl -0x128(%rbp), %edx
movl -0x124(%rbp), %ecx
movq %rax, %r9
leaq 0x1c90(%rip), %rsi      # 0x14ecc
movl $0x14, %r8d
movb $0x0, %al
callq 0x32d0
movq -0xa0(%rbp), %rax
movq 0x68(%rax), %rdi
leaq 0x1ce3(%rip), %rsi      # 0x14f3e
movb $0x0, %al
callq 0x32d0
addq $0x130, %rsp            # imm = 0x130
popq %rbp
retq
nopl (%rax,%rax)