// File: /workspace/github_cpp_makefile_star2_O3/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, 0x1c(%rsp)
movl %edx, 0x18(%rsp)
movq %rsi, %rbp
movq %rdi, %r13
movsd 0x60(%rdi), %xmm3
movsd 0x50(%rdi), %xmm0
movsd 0x58(%rdi), %xmm1
subsd 0x40(%rdi), %xmm0
mulsd %xmm3, %xmm0
movsd 0x1dcc(%rip), %xmm2     # 0x9ce8
addsd %xmm2, %xmm0
cvttsd2si %xmm0, %edx
subsd 0x48(%rdi), %xmm1
movsd %xmm3, (%rsp)
mulsd %xmm3, %xmm1
addsd %xmm2, %xmm1
cvttsd2si %xmm1, %r9d
movq 0x68(%rdi), %rdi
leal 0x28(%r9), %ecx
leaq 0x1dc9(%rip), %rsi      # 0x9d13
movl %edx, 0x14(%rsp)
movl %edx, %r8d
movq %r9, 0x20(%rsp)
xorl %eax, %eax
callq 0x31f0
movq (%rbp), %rax
movq 0x8(%rbp), %rcx
movq %rcx, %rdx
subq %rax, %rdx
shrq $0x3, %rdx
imull $0x38e38e39, %edx, %edx # imm = 0x38E38E39
testl %edx, %edx
jle 0x812c
movq %r13, 0x8(%rsp)
xorl %r12d, %r12d
movsd (%rsp), %xmm4
leaq (%r12,%r12,8), %r14
leaq (%rax,%r14,8), %r13
cmpb $0x0, 0x18(%rsp)
je 0x8037
leaq (%rax,%r14,8), %rbx
addq $0x18, %rbx
movq 0x10(%rbx), %r15
cmpq %rbx, %r15
je 0x8037
movslq 0x20(%r15), %rax
cmpq %rax, %r12
jge 0x801e
movq (%rbp), %rcx
leaq (%rax,%rax,8), %rax
movq 0x8(%rsp), %rdx
movq 0x68(%rdx), %rdi
movsd (%r13), %xmm0
movsd (%rsp), %xmm4
mulsd %xmm4, %xmm0
movsd 0x1d0d(%rip), %xmm5     # 0x9cf0
addsd %xmm5, %xmm0
movsd 0x8(%r13), %xmm1
mulsd %xmm4, %xmm1
addsd %xmm5, %xmm1
movsd (%rcx,%rax,8), %xmm2
mulsd %xmm4, %xmm2
addsd %xmm5, %xmm2
movsd 0x8(%rcx,%rax,8), %xmm3
mulsd %xmm4, %xmm3
addsd %xmm5, %xmm3
leaq 0x1dc4(%rip), %rsi      # 0x9ddb
movb $0x4, %al
callq 0x31f0
movq %r15, %rdi
callq 0x31a0
movq %rax, %r15
cmpq %rbx, %rax
jne 0x7fb2
movq (%rbp), %rax
movsd (%rsp), %xmm4
cmpb $0x0, 0x1c(%rsp)
je 0x80ac
movslq 0x44(%rax,%r14,8), %rcx
cmpq $-0x1, %rcx
je 0x80ac
leaq (%rcx,%rcx,8), %rcx
movq 0x8(%rsp), %rdx
movq 0x68(%rdx), %rdi
movsd (%r13), %xmm0
mulsd %xmm4, %xmm0
movsd 0x1c88(%rip), %xmm5     # 0x9cf0
addsd %xmm5, %xmm0
movsd 0x8(%r13), %xmm1
mulsd %xmm4, %xmm1
addsd %xmm5, %xmm1
movsd (%rax,%rcx,8), %xmm2
mulsd %xmm4, %xmm2
addsd %xmm5, %xmm2
movsd 0x8(%rax,%rcx,8), %xmm3
mulsd %xmm4, %xmm3
addsd %xmm5, %xmm3
leaq 0x1d93(%rip), %rsi      # 0x9e2f
movb $0x4, %al
callq 0x31f0
movsd (%rsp), %xmm4
movq (%rbp), %rax
incq %r12
movq 0x8(%rbp), %rcx
movq %rcx, %rdx
subq %rax, %rdx
sarq $0x3, %rdx
movabsq $-0x71c71c71c71c71c7, %rsi # imm = 0x8E38E38E38E38E39
imulq %rsi, %rdx
movslq %edx, %rsi
cmpq %rsi, %r12
jl 0x7f8a
testl %edx, %edx
jle 0x8127
movq 0x8(%rsp), %r13
movq 0x68(%r13), %rdi
movsd (%rax), %xmm0
mulsd %xmm4, %xmm0
movsd 0x1bfc(%rip), %xmm2     # 0x9cf0
addsd %xmm2, %xmm0
movsd 0x8(%rax), %xmm1
mulsd %xmm4, %xmm1
addsd %xmm2, %xmm1
leaq 0x1d76(%rip), %rsi      # 0x9e82
movl $0x8, %edx
movl $0x1, %ecx
movb $0x2, %al
callq 0x31f0
movq (%rbp), %rax
movq 0x8(%rbp), %rcx
jmp 0x812c
movq 0x8(%rsp), %r13
subq %rax, %rcx
shrq $0x3, %rcx
imull $0x38e38e39, %ecx, %ecx # imm = 0x38E38E39
cmpl $0x2, %ecx
movsd (%rsp), %xmm2
jl 0x81bb
movl $0x1, %ebx
movl $0x50, %r12d
leaq 0x1d7d(%rip), %r15      # 0x9ed2
movq 0x68(%r13), %rdi
movsd -0x8(%rax,%r12), %xmm0
mulsd %xmm2, %xmm0
movsd 0x1b84(%rip), %xmm3     # 0x9cf0
addsd %xmm3, %xmm0
movsd (%rax,%r12), %xmm1
mulsd %xmm2, %xmm1
addsd %xmm3, %xmm1
movq %r15, %rsi
movl $0x8, %edx
movl $0x1, %ecx
movb $0x2, %al
callq 0x31f0
movsd (%rsp), %xmm2
incq %rbx
movq (%rbp), %rax
movq 0x8(%rbp), %rcx
subq %rax, %rcx
shrq $0x3, %rcx
imull $0x38e38e39, %ecx, %ecx # imm = 0x38E38E39
movslq %ecx, %rcx
addq $0x48, %r12
cmpq %rcx, %rbx
jl 0x8155
movq 0x20(%r13), %r9
movq 0x68(%r13), %rdi
movl 0x14(%rsp), %eax
movl %eax, %edx
shrl $0x1f, %edx
addl %eax, %edx
sarl %edx
movq 0x20(%rsp), %rcx
addl $0x14, %ecx
leaq 0x1d45(%rip), %rsi      # 0x9f24
movl $0x14, %r8d
xorl %eax, %eax
callq 0x31f0
movq 0x68(%r13), %rcx
leaq 0x1d9f(%rip), %rdi      # 0x9f96
movl $0x7, %esi
movl $0x1, %edx
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x32a0