// File: xukmin[P]rase/build-routings.cc
// Function: main
int main(int argc, char** argv) {
  std::srand(std::time(NULL));

  int num_sensors = 100;
  double communication_range = 20.0;
  double scale = 6.0;

  if (argc > 1) {
    num_sensors = std::atoi(argv[1]);
  }
  if (argc > 2) {
    communication_range = std::atof(argv[2]);
  }

  Region region;
  region.min_x = 0.0;
  region.min_y = 0.0;
  region.max_x = 100.0;
  region.max_y = 100.0;

  std::vector<RoutingBuilder*> builders;
  builders.push_back(new EarliestFirstRoutingBuilder());
  builders.push_back(new SecondEarliestFirstRoutingBuilder());
  builders.push_back(new LatestFirstRoutingBuilder());
  builders.push_back(new NearestFirstRoutingBuilder());
  builders.push_back(new SecondNearestFirstRoutingBuilder());
  builders.push_back(new FarthestFirstRoutingBuilder());
  builders.push_back(new RandomizedRoutingBuilder());
  builders.push_back(new WeightedRandomizedRoutingBuilder());

  RandomizedSensorPlacer placer(num_sensors, region);
  std::vector<Position> positions;
  GeneratePositionsThatCanBeConnected(communication_range, &placer, &positions);

  SensorNetwork network;
  network.DeploySensors(positions, communication_range);

  for (int i = 0; i < builders.size(); i++) {
    builders[i]->BuildRouting(&network);

    const std::string filename = "routings-" + IntToString(num_sensors) + "-" +
                                 builders[i]->name() + ".svg";
    SvgPrinter printer(filename, builders[i]->title(), region, scale);
    printer.PrintNetwork(network);
  }

  for (int i = 0; i < builders.size(); i++) {
    delete builders[i];
  }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x320, %rsp            # imm = 0x320
movl $0x0, -0x4(%rbp)
movl %edi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
xorl %eax, %eax
movl %eax, %edi
callq 0x31c0
movl %eax, %edi
callq 0x31d0
movl $0x64, -0x14(%rbp)
movsd 0x10ab8(%rip), %xmm0    # 0x14010
movsd %xmm0, -0x20(%rbp)
movsd 0x10aa3(%rip), %xmm0    # 0x14008
movsd %xmm0, -0x28(%rbp)
cmpl $0x1, -0x8(%rbp)
jle 0x3580
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rdi
callq 0x3300
movl %eax, -0x14(%rbp)
cmpl $0x2, -0x8(%rbp)
jle 0x3598
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rdi
callq 0x32b0
movsd %xmm0, -0x20(%rbp)
movq $0x0, -0x48(%rbp)
movq $0x0, -0x40(%rbp)
movabsq $0x4059000000000000, %rax # imm = 0x4059000000000000
movq %rax, -0x38(%rbp)
movq %rax, -0x30(%rbp)
leaq -0x60(%rbp), %rdi
callq 0x3cb0
movl $0x50, %edi
callq 0x31f0
movq %rax, -0x2b8(%rbp)
jmp 0x35d6
movq -0x2b8(%rbp), %rdi
callq 0xf7f0
jmp 0x35e4
movq -0x2b8(%rbp), %rax
movq %rax, -0x68(%rbp)
leaq -0x60(%rbp), %rdi
leaq -0x68(%rbp), %rsi
callq 0x3cd0
jmp 0x35fe
movl $0x50, %edi
callq 0x31f0
movq %rax, -0x2c0(%rbp)
jmp 0x3611
movq -0x2c0(%rbp), %rdi
callq 0xf9c0
jmp 0x361f
movq -0x2c0(%rbp), %rax
movq %rax, -0x80(%rbp)
leaq -0x60(%rbp), %rdi
leaq -0x80(%rbp), %rsi
callq 0x3cd0
jmp 0x3639
movl $0x50, %edi
callq 0x31f0
movq %rax, -0x2c8(%rbp)
jmp 0x364c
movq -0x2c8(%rbp), %rdi
callq 0xfb60
jmp 0x365a
movq -0x2c8(%rbp), %rax
movq %rax, -0x88(%rbp)
leaq -0x60(%rbp), %rdi
leaq -0x88(%rbp), %rsi
callq 0x3cd0
jmp 0x367a
movl $0x50, %edi
callq 0x31f0
movq %rax, -0x2d0(%rbp)
jmp 0x368d
movq -0x2d0(%rbp), %rdi
callq 0xff80
jmp 0x369b
movq -0x2d0(%rbp), %rax
movq %rax, -0x90(%rbp)
leaq -0x60(%rbp), %rdi
leaq -0x90(%rbp), %rsi
callq 0x3cd0
jmp 0x36bb
movl $0x50, %edi
callq 0x31f0
movq %rax, -0x2d8(%rbp)
jmp 0x36ce
movq -0x2d8(%rbp), %rdi
callq 0x10290
jmp 0x36dc
movq -0x2d8(%rbp), %rax
movq %rax, -0x98(%rbp)
leaq -0x60(%rbp), %rdi
leaq -0x98(%rbp), %rsi
callq 0x3cd0
jmp 0x36fc
movl $0x50, %edi
callq 0x31f0
movq %rax, -0x2e0(%rbp)
jmp 0x370f
movq -0x2e0(%rbp), %rdi
callq 0x104d0
jmp 0x371d
movq -0x2e0(%rbp), %rax
movq %rax, -0xa0(%rbp)
leaq -0x60(%rbp), %rdi
leaq -0xa0(%rbp), %rsi
callq 0x3cd0
jmp 0x373d
movl $0x50, %edi
callq 0x31f0
movq %rax, -0x2e8(%rbp)
jmp 0x3750
movq -0x2e8(%rbp), %rdi
callq 0xfd30
jmp 0x375e
movq -0x2e8(%rbp), %rax
movq %rax, -0xa8(%rbp)
leaq -0x60(%rbp), %rdi
leaq -0xa8(%rbp), %rsi
callq 0x3cd0
jmp 0x377e
movl $0x50, %edi
callq 0x31f0
movq %rax, -0x2f0(%rbp)
jmp 0x3791
movq -0x2f0(%rbp), %rdi
callq 0x108b0
jmp 0x379f
movq -0x2f0(%rbp), %rax
movq %rax, -0xb0(%rbp)
leaq -0x60(%rbp), %rdi
leaq -0xb0(%rbp), %rsi
callq 0x3cd0
jmp 0x37bf
movl -0x14(%rbp), %esi
leaq -0xe0(%rbp), %rdi
leaq -0x48(%rbp), %rdx
callq 0x3d00
jmp 0x37d4
leaq -0xf8(%rbp), %rdi
movq %rdi, -0x2f8(%rbp)
callq 0x3d90
movq -0x2f8(%rbp), %rsi
movsd -0x20(%rbp), %xmm0
leaq -0xe0(%rbp), %rdi
callq 0x60a0
jmp 0x3801
leaq -0x190(%rbp), %rdi
callq 0x3db0
jmp 0x380f
movsd -0x20(%rbp), %xmm0
leaq -0x190(%rbp), %rdi
leaq -0xf8(%rbp), %rsi
callq 0x76a0
jmp 0x3829
movl $0x0, -0x194(%rbp)
movslq -0x194(%rbp), %rax
movq %rax, -0x300(%rbp)
leaq -0x60(%rbp), %rdi
callq 0x3e10
movq %rax, %rcx
movq -0x300(%rbp), %rax
cmpq %rcx, %rax
jae 0x3bc3
movslq -0x194(%rbp), %rsi
leaq -0x60(%rbp), %rdi
callq 0x3e30
movq (%rax), %rdi
leaq -0x190(%rbp), %rsi
callq 0xf620
jmp 0x387e
movl -0x14(%rbp), %esi
leaq -0x238(%rbp), %rdi
callq 0x133f0
jmp 0x388f
leaq 0x10782(%rip), %rsi     # 0x14018
leaq -0x218(%rbp), %rdi
leaq -0x238(%rbp), %rdx
callq 0x3ef0
jmp 0x38ab
leaq 0x1076e(%rip), %rdx     # 0x14020
leaq -0x1f8(%rbp), %rdi
leaq -0x218(%rbp), %rsi
callq 0x3e50
jmp 0x38c7
movslq -0x194(%rbp), %rsi
leaq -0x60(%rbp), %rdi
callq 0x3e30
movq (%rax), %rdi
callq 0x3f40
movq %rax, -0x308(%rbp)
jmp 0x38e8
movq -0x308(%rbp), %rdx
leaq -0x1d8(%rbp), %rdi
leaq -0x1f8(%rbp), %rsi
callq 0x3ea0
jmp 0x3904
leaq 0x10717(%rip), %rdx     # 0x14022
leaq -0x1b8(%rbp), %rdi
leaq -0x1d8(%rbp), %rsi
callq 0x3e50
jmp 0x3920
leaq -0x1d8(%rbp), %rdi
callq 0x3120
leaq -0x1f8(%rbp), %rdi
callq 0x3120
leaq -0x218(%rbp), %rdi
callq 0x3120
leaq -0x238(%rbp), %rdi
callq 0x3120
movslq -0x194(%rbp), %rsi
leaq -0x60(%rbp), %rdi
callq 0x3e30
movq (%rax), %rdi
callq 0x3f60
movq %rax, -0x310(%rbp)
jmp 0x3971
movq -0x310(%rbp), %rdx
movsd -0x28(%rbp), %xmm0
leaq -0x2a8(%rbp), %rdi
leaq -0x1b8(%rbp), %rsi
leaq -0x48(%rbp), %rcx
callq 0x12bf0
jmp 0x3996
leaq -0x2a8(%rbp), %rdi
leaq -0x190(%rbp), %rsi
movl $0x1, %ecx
movl %ecx, %edx
callq 0x12d50
jmp 0x39b2
leaq -0x2a8(%rbp), %rdi
callq 0x12d00
leaq -0x1b8(%rbp), %rdi
callq 0x3120
movl -0x194(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x194(%rbp)
jmp 0x3833
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x70(%rbp)
movl %eax, -0x74(%rbp)
jmp 0x3c90
movq -0x2b8(%rbp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x70(%rbp)
movl %eax, -0x74(%rbp)
movl $0x50, %esi
callq 0x3200
jmp 0x3c90
movq -0x2c0(%rbp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x70(%rbp)
movl %eax, -0x74(%rbp)
movl $0x50, %esi
callq 0x3200
jmp 0x3c90
movq -0x2c8(%rbp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x70(%rbp)
movl %eax, -0x74(%rbp)
movl $0x50, %esi
callq 0x3200
jmp 0x3c90
movq -0x2d0(%rbp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x70(%rbp)
movl %eax, -0x74(%rbp)
movl $0x50, %esi
callq 0x3200
jmp 0x3c90
movq -0x2d8(%rbp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x70(%rbp)
movl %eax, -0x74(%rbp)
movl $0x50, %esi
callq 0x3200
jmp 0x3c90
movq -0x2e0(%rbp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x70(%rbp)
movl %eax, -0x74(%rbp)
movl $0x50, %esi
callq 0x3200
jmp 0x3c90
movq -0x2e8(%rbp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x70(%rbp)
movl %eax, -0x74(%rbp)
movl $0x50, %esi
callq 0x3200
jmp 0x3c90
movq -0x2f0(%rbp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x70(%rbp)
movl %eax, -0x74(%rbp)
movl $0x50, %esi
callq 0x3200
jmp 0x3c90
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x70(%rbp)
movl %eax, -0x74(%rbp)
jmp 0x3c78
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x70(%rbp)
movl %eax, -0x74(%rbp)
jmp 0x3c6c
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x70(%rbp)
movl %eax, -0x74(%rbp)
jmp 0x3b7b
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x70(%rbp)
movl %eax, -0x74(%rbp)
jmp 0x3b6f
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x70(%rbp)
movl %eax, -0x74(%rbp)
jmp 0x3b63
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x70(%rbp)
movl %eax, -0x74(%rbp)
leaq -0x1d8(%rbp), %rdi
callq 0x3120
leaq -0x1f8(%rbp), %rdi
callq 0x3120
leaq -0x218(%rbp), %rdi
callq 0x3120
leaq -0x238(%rbp), %rdi
callq 0x3120
jmp 0x3c6c
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x70(%rbp)
movl %eax, -0x74(%rbp)
jmp 0x3bb2
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x70(%rbp)
movl %eax, -0x74(%rbp)
leaq -0x2a8(%rbp), %rdi
callq 0x12d00
leaq -0x1b8(%rbp), %rdi
callq 0x3120
jmp 0x3c6c
movl $0x0, -0x2ac(%rbp)
movslq -0x2ac(%rbp), %rax
movq %rax, -0x318(%rbp)
leaq -0x60(%rbp), %rdi
callq 0x3e10
movq %rax, %rcx
movq -0x318(%rbp), %rax
cmpq %rcx, %rax
jae 0x3c33
movslq -0x2ac(%rbp), %rsi
leaq -0x60(%rbp), %rdi
callq 0x3e30
movq (%rax), %rax
movq %rax, -0x320(%rbp)
cmpq $0x0, %rax
je 0x3c20
movq -0x320(%rbp), %rdi
movq (%rdi), %rax
callq *0x8(%rax)
jmp 0x3c22
movl -0x2ac(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x2ac(%rbp)
jmp 0x3bcd
leaq -0x190(%rbp), %rdi
callq 0x3f80
leaq -0xf8(%rbp), %rdi
callq 0x3fd0
leaq -0xe0(%rbp), %rdi
callq 0x4030
leaq -0x60(%rbp), %rdi
callq 0x4050
movl -0x4(%rbp), %eax
addq $0x320, %rsp            # imm = 0x320
popq %rbp
retq
leaq -0x190(%rbp), %rdi
callq 0x3f80
leaq -0xf8(%rbp), %rdi
callq 0x3fd0
leaq -0xe0(%rbp), %rdi
callq 0x4030
leaq -0x60(%rbp), %rdi
callq 0x4050
movq -0x70(%rbp), %rdi
callq 0x3340
nopw %cs:(%rax,%rax)
nopl (%rax)