// File: /workspace/github_cpp_makefile_star2_O3/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 $0x58, %rsp
movsd %xmm2, 0x8(%rsp)
movq %rsi, %rbx
movq %rdi, 0x40(%rsp)
addsd %xmm0, %xmm1
movq %rsi, %rdi
movsd %xmm0, 0x20(%rsp)
movsd %xmm1, 0x18(%rsp)
callq 0x80d6
movsd %xmm0, 0x38(%rsp)
movsd 0x8(%rsp), %xmm1
addsd %xmm0, %xmm1
movsd %xmm1, 0x8(%rsp)
ucomisd (%rbx), %xmm1
jbe 0x7ecc
movsd 0x8(%rsp), %xmm0
movsd %xmm0, (%rbx)
movq %rbx, 0x30(%rsp)
leaq 0x8(%rbx), %r12
movq %r12, %r13
movq (%r13), %r13
movb $0x1, %bl
cmpq %r12, %r13
je 0x7f1e
leaq 0x10(%r13), %rdi
callq 0x20422
movsd 0x20(%rsp), %xmm1
ucomisd %xmm0, %xmm1
ja 0x7ed8
movq %r13, %r15
leaq 0x10(%r15), %rdi
callq 0x20422
movsd 0x18(%rsp), %xmm1
ucomisd %xmm0, %xmm1
seta %bpl
jbe 0x7f24
movq (%r15), %r15
cmpq %r12, %r15
jne 0x7efb
jmp 0x7f24
movq %r13, %r15
movb $0x1, %bpl
cmpq %r12, %r15
je 0x7f41
leaq 0x10(%r15), %rdi
callq 0x20422
cmpneqsd 0x18(%rsp), %xmm0
movq %xmm0, %rbx
andl $0x1, %ebx
movq 0x8(%r15), %rdi
addq $0x10, %rdi
callq 0x20428
movsd %xmm0, 0x28(%rsp)
cmpq (%r12), %r13
je 0x7f79
movq 0x8(%r13), %rdi
addq $0x10, %rdi
callq 0x20428
ucomisd 0x8(%rsp), %xmm0
jne 0x7f79
jp 0x7f79
movb $0x1, %al
movl %eax, 0x14(%rsp)
jmp 0x7f81
movl $0x0, 0x14(%rsp)
testb %bpl, %bpl
je 0x7f8b
xorl %r14d, %r14d
jmp 0x7fbe
leaq 0x10(%r15), %rbp
movq %rbp, %rdi
callq 0x20428
cmpeqsd 0x8(%rsp), %xmm0
movq %xmm0, %r14
andl $0x1, %r14d
movq %rbp, %rdi
callq 0x20428
ucomisd 0x28(%rsp), %xmm0
jne 0x7fbe
jp 0x7fbe
movb $0x1, %bpl
jmp 0x7fc0
xorl %ebp, %ebp
movq %r12, %rdi
movq %r13, %rsi
movq %r15, %rdx
callq 0x81be
cmpb $0x0, 0x14(%rsp)
movq 0x30(%rsp), %r13
jne 0x8017
leaq 0x48(%rsp), %r12
movq %r12, %rdi
movsd 0x20(%rsp), %xmm0
movsd 0x8(%rsp), %xmm1
callq 0x2044c
movl $0x20, %edi
callq 0x6380
movupd (%r12), %xmm0
movupd %xmm0, 0x10(%rax)
movq %rax, %rdi
movq %r15, %rsi
callq 0x6060
incq 0x18(%r13)
xorb $0x1, %r14b
orb %r14b, %bl
je 0x8070
leaq 0x48(%rsp), %r12
movq %r12, %rdi
movsd 0x18(%rsp), %xmm0
movsd 0x28(%rsp), %xmm1
callq 0x2044c
movl $0x20, %edi
callq 0x6380
movupd (%r12), %xmm0
movupd %xmm0, 0x10(%rax)
movq %rax, %rdi
movq %r15, %rsi
callq 0x6060
movq 0x18(%r13), %rax
leaq 0x1(%rax), %rcx
movq %rcx, 0x18(%r13)
testb %bpl, %bpl
je 0x8089
movq %rax, 0x18(%r13)
jmp 0x8074
decq 0x18(%r13)
movq %r15, %rdi
callq 0x65b0
movl $0x20, %esi
movq %r15, %rdi
callq 0x6390
leaq 0x48(%rsp), %r14
movq %r14, %rdi
movsd 0x20(%rsp), %xmm0
movsd 0x38(%rsp), %xmm1
callq 0x2044c
movq 0x40(%rsp), %rbx
leaq 0x10(%rbx), %rdi
movsd 0x18(%rsp), %xmm0
movsd 0x8(%rsp), %xmm1
callq 0x2044c
movups (%r14), %xmm0
movups %xmm0, (%rbx)
movq %rbx, %rax
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nop