// File: /workspace/github_cpp_makefile_star2_O1/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, %rbp
movq %rdi, %r13
movsd 0x60(%rdi), %xmm3
movsd 0x50(%rdi), %xmm0
movsd 0x58(%rdi), %xmm1
subsd 0x40(%rdi), %xmm0
mulsd %xmm3, %xmm0
movsd 0x1e1c(%rip), %xmm2     # 0x9c98
addsd %xmm2, %xmm0
cvttsd2si %xmm0, %edx
subsd 0x48(%rdi), %xmm1
movsd %xmm3, (%rsp)
mulsd %xmm3, %xmm1
addsd %xmm2, %xmm1
cvttsd2si %xmm1, %r14d
movq 0x68(%rdi), %rdi
leal 0x28(%r14), %ecx
leaq 0x1e19(%rip), %rsi      # 0x9cc3
xorl %ebx, %ebx
movl %edx, 0xc(%rsp)
movl %edx, %r8d
movl %r14d, %r9d
xorl %eax, %eax
callq 0x3200
movq (%rbp), %rax
movq 0x8(%rbp), %rcx
subq %rax, %rcx
shrq $0x3, %rcx
imull $0x38e38e39, %ecx, %ecx # imm = 0x38E38E39
testl %ecx, %ecx
jle 0x8038
movq %r14, 0x20(%rsp)
movq %r13, %r14
xorl %r12d, %r12d
leaq (%r12,%r12,8), %rcx
movq %rcx, 0x18(%rsp)
leaq (%rax,%rcx,8), %r13
cmpb $0x0, 0x10(%rsp)
je 0x7f8a
movq 0x18(%rsp), %rcx
leaq (%rax,%rcx,8), %rbx
addq $0x18, %rbx
movq 0x10(%rbx), %r15
cmpq %rbx, %r15
je 0x7f8a
movslq 0x20(%r15), %rax
cmpq %rax, %r12
jge 0x7f7a
movq (%rbp), %rcx
leaq (%rax,%rax,8), %rax
movq 0x68(%r14), %rdi
movsd (%r13), %xmm0
movsd (%rsp), %xmm4
mulsd %xmm4, %xmm0
movsd 0x1d61(%rip), %xmm5     # 0x9ca0
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 0x1e18(%rip), %rsi      # 0x9d8b
movb $0x4, %al
callq 0x3200
movq %r15, %rdi
callq 0x31b0
movq %rax, %r15
cmpq %rbx, %rax
jne 0x7f13
cmpb $0x0, 0x14(%rsp)
je 0x7fff
movq (%rbp), %rax
movq 0x18(%rsp), %rcx
movslq 0x44(%rax,%rcx,8), %rcx
cmpq $-0x1, %rcx
je 0x7fff
leaq (%rcx,%rcx,8), %rcx
movq 0x68(%r14), %rdi
movsd (%r13), %xmm0
movsd (%rsp), %xmm4
mulsd %xmm4, %xmm0
movsd 0x1cdc(%rip), %xmm5     # 0x9ca0
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 0x1de7(%rip), %rsi      # 0x9ddf
movb $0x4, %al
callq 0x3200
incq %r12
movq (%rbp), %rax
movq 0x8(%rbp), %rcx
subq %rax, %rcx
sarq $0x3, %rcx
movabsq $-0x71c71c71c71c71c7, %rdx # imm = 0x8E38E38E38E38E39
imulq %rdx, %rcx
movslq %ecx, %rdx
cmpq %rdx, %r12
jl 0x7ee5
testl %ecx, %ecx
setg %bl
movq %r14, %r13
movq 0x20(%rsp), %r14
testb %bl, %bl
je 0x807e
movq 0x68(%r13), %rdi
movsd (%rax), %xmm0
movsd (%rsp), %xmm3
mulsd %xmm3, %xmm0
movsd 0x1c4b(%rip), %xmm2     # 0x9ca0
addsd %xmm2, %xmm0
movsd 0x8(%rax), %xmm1
mulsd %xmm3, %xmm1
addsd %xmm2, %xmm1
leaq 0x1dc5(%rip), %rsi      # 0x9e32
movl $0x8, %edx
movl $0x1, %ecx
movb $0x2, %al
callq 0x3200
movq (%rbp), %rax
movq 0x8(%rbp), %rcx
subq %rax, %rcx
shrq $0x3, %rcx
imull $0x38e38e39, %ecx, %ecx # imm = 0x38E38E39
cmpl $0x2, %ecx
movsd (%rsp), %xmm2
jl 0x8115
movl $0x1, %ebx
movl $0x50, %r12d
leaq 0x1dd3(%rip), %r15      # 0x9e82
movq 0x68(%r13), %rdi
movsd -0x8(%rax,%r12), %xmm0
mulsd %xmm2, %xmm0
movsd 0x1bda(%rip), %xmm3     # 0x9ca0
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 0x3200
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 0x80af
movq 0x20(%r13), %r9
movq 0x68(%r13), %rdi
movl 0xc(%rsp), %eax
movl %eax, %edx
shrl $0x1f, %edx
addl %eax, %edx
sarl %edx
addl $0x14, %r14d
leaq 0x1d9f(%rip), %rsi      # 0x9ed4
movl %r14d, %ecx
movl $0x14, %r8d
xorl %eax, %eax
callq 0x3200
movq 0x68(%r13), %rcx
leaq 0x1df6(%rip), %rdi      # 0x9f46
movl $0x7, %esi
movl $0x1, %edx
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x32b0
nop