// File: /workspace/github_cpp_makefile_star2_O2/harry830622[P]floorplanner/src/contour.cpp
// Function: Contour::Update(double, double, double)
pair<Point, Point> Contour::Update(double macro_x, double macro_width,
                                   double macro_height) {
  const double lower_left_x = macro_x;
  const double lower_left_y = FindMaxYBetween(macro_x, macro_x + macro_width);
  const double upper_right_x = lower_left_x + macro_width;
  const double upper_right_y = lower_left_y + macro_height;
  if (upper_right_y > max_y_) {
    max_y_ = upper_right_y;
  }

  list<Point>::iterator it = coordinates_.begin();
  while (it != coordinates_.end() && it->x() < lower_left_x) {
    ++it;
  }
  list<Point>::iterator it_begin = it;
  while (it != coordinates_.end() && it->x() < upper_right_x) {
    ++it;
  }
  list<Point>::iterator it_end = it;

  const bool is_touched =
      (it_end == coordinates_.end() || it_end->x() != upper_right_x) ? false
                                                                     : true;
  const double last_y = prev(it_end)->y();

  bool is_previous_y_equal = false;
  if (it_begin != coordinates_.begin() &&
      prev(it_begin)->y() == upper_right_y) {
    is_previous_y_equal = true;
  }

  bool is_next_y_equal = false;
  if (it_end != coordinates_.end() && it_end->y() == upper_right_y) {
    is_next_y_equal = true;
  }

  bool is_last_y_next_y_equal = false;
  if (it_end != coordinates_.end() && it_end->y() == last_y) {
    is_last_y_next_y_equal = true;
  }

  if (is_previous_y_equal) {
    coordinates_.erase(it_begin, it_end);
  } else {
    coordinates_.erase(it_begin, it_end);
    coordinates_.insert(it_end, Point(lower_left_x, upper_right_y));
  }
  if (is_touched && is_next_y_equal) {
    coordinates_.erase(it_end);
  } else {
    coordinates_.insert(it_end, Point(upper_right_x, last_y));
    if (is_last_y_next_y_equal) {
      coordinates_.erase(it_end);
    }
  }

  /* double previous_y = -1; */
  /* for (it = coordinates_.begin(); it != coordinates_.end(); ++it) { */
  /*   if (it->y() == previous_y) { */
  /*     it = coordinates_.erase(it); */
  /*     --it; */
  /*   } else { */
  /*     previous_y = it->y(); */
  /*   } */
  /* } */

  return make_pair(Point(lower_left_x, lower_left_y),
                   Point(upper_right_x, upper_right_y));
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x48, %rsp
movsd %xmm2, (%rsp)
movq %rsi, %r14
movq %rdi, 0x30(%rsp)
addsd %xmm0, %xmm1
movq %rsi, %rdi
movsd %xmm0, 0x18(%rsp)
movsd %xmm1, 0x10(%rsp)
callq 0x84e0
movsd %xmm0, 0x28(%rsp)
movsd (%rsp), %xmm1
addsd %xmm0, %xmm1
movsd %xmm1, (%rsp)
ucomisd (%r14), %xmm1
jbe 0x8328
movsd (%rsp), %xmm0
movsd %xmm0, (%r14)
addq $0x8, %r14
movq %r14, %r12
movq (%r12), %r12
cmpq %r14, %r12
je 0x834e
leaq 0x10(%r12), %rdi
callq 0x1aa7e
movsd 0x18(%rsp), %xmm1
ucomisd %xmm0, %xmm1
ja 0x832f
movq %r12, %r15
cmpq %r14, %r15
je 0x8373
leaq 0x10(%r15), %r13
movq %r13, %rdi
callq 0x1aa7e
movsd 0x10(%rsp), %xmm1
ucomisd %xmm0, %xmm1
jbe 0x8378
movq (%r15), %r15
jmp 0x8351
movb $0x1, %bpl
jmp 0x838f
movq %r13, %rdi
callq 0x1aa7e
cmpneqsd 0x10(%rsp), %xmm0
movq %xmm0, %rbp
andl $0x1, %ebp
pushq $0x1
popq %rsi
movq %r15, %rdi
callq 0x85a3
leaq 0x10(%rax), %rdi
callq 0x1aa84
movsd %xmm0, 0x20(%rsp)
cmpq (%r14), %r12
je 0x83d3
pushq $0x1
popq %rsi
movq %r12, %rdi
callq 0x85a3
leaq 0x10(%rax), %rdi
callq 0x1aa84
ucomisd (%rsp), %xmm0
jne 0x83d3
jp 0x83d3
movb $0x1, %al
movl %eax, 0xc(%rsp)
jmp 0x83db
movl $0x0, 0xc(%rsp)
cmpq %r14, %r15
je 0x8411
leaq 0x10(%r15), %r13
movq %r13, %rdi
callq 0x1aa84
cmpeqsd (%rsp), %xmm0
movq %xmm0, %rbx
andl $0x1, %ebx
movq %r13, %rdi
callq 0x1aa84
ucomisd 0x20(%rsp), %xmm0
jne 0x8413
jp 0x8413
movb $0x1, %r13b
jmp 0x8416
xorl %ebx, %ebx
xorl %r13d, %r13d
movq %r14, %rdi
movq %r12, %rsi
movq %r15, %rdx
callq 0x85c4
cmpb $0x0, 0xc(%rsp)
jne 0x8451
leaq 0x38(%rsp), %r12
movq %r12, %rdi
movsd 0x18(%rsp), %xmm0
movsd (%rsp), %xmm1
callq 0x1aaa8
movq %r14, %rdi
movq %r15, %rsi
movq %r12, %rdx
callq 0x8734
xorb $0x1, %bl
orb %bl, %bpl
cmpb $0x1, %bpl
jne 0x8489
leaq 0x38(%rsp), %r12
movq %r12, %rdi
movsd 0x10(%rsp), %xmm0
movsd 0x20(%rsp), %xmm1
callq 0x1aaa8
movq %r14, %rdi
movq %r15, %rsi
movq %r12, %rdx
callq 0x8734
testb %r13b, %r13b
je 0x8494
movq %r14, %rdi
movq %r15, %rsi
callq 0x85ec
leaq 0x38(%rsp), %r14
movq %r14, %rdi
movsd 0x18(%rsp), %xmm0
movsd 0x28(%rsp), %xmm1
callq 0x1aaa8
movq 0x30(%rsp), %rbx
leaq 0x10(%rbx), %rdi
movsd 0x10(%rsp), %xmm0
movsd (%rsp), %xmm1
callq 0x1aaa8
movups (%r14), %xmm0
movups %xmm0, (%rbx)
movq %rbx, %rax
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nop