// File: /workspace/github_cpp_makefile_star2_O1/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, %r14
movq %rdi, 0x40(%rsp)
addsd %xmm0, %xmm1
movq %rsi, %rdi
movsd %xmm0, 0x28(%rsp)
movsd %xmm1, 0x18(%rsp)
callq 0x7a98
movsd %xmm0, 0x38(%rsp)
movsd 0x8(%rsp), %xmm1
addsd %xmm0, %xmm1
movsd %xmm1, 0x8(%rsp)
ucomisd (%r14), %xmm1
jbe 0x787a
movsd 0x8(%rsp), %xmm0
movsd %xmm0, (%r14)
leaq 0x8(%r14), %r12
movq %r12, %r13
movq (%r13), %r13
cmpq %r12, %r13
je 0x789f
leaq 0x10(%r13), %rdi
callq 0x208dc
movsd 0x28(%rsp), %xmm1
ucomisd %xmm0, %xmm1
ja 0x7881
cmpq %r12, %r13
sete %bl
je 0x78e4
leaq 0x10(%r13), %rdi
callq 0x208dc
movsd 0x18(%rsp), %xmm1
ucomisd %xmm0, %xmm1
movq %r13, %r15
jbe 0x78e7
movq %r13, %r15
movq (%r15), %r15
cmpq %r12, %r15
sete %bl
je 0x78e7
leaq 0x10(%r15), %rdi
callq 0x208dc
movsd 0x18(%rsp), %xmm1
ucomisd %xmm0, %xmm1
ja 0x78c2
jmp 0x78e7
movq %r13, %r15
cmpq %r12, %r15
je 0x7906
leaq 0x10(%r15), %rdi
callq 0x208dc
cmpneqsd 0x18(%rsp), %xmm0
movq %xmm0, %rbp
andl $0x1, %ebp
jmp 0x7909
movb $0x1, %bpl
movq 0x8(%r15), %rdi
addq $0x10, %rdi
callq 0x208e2
movsd %xmm0, 0x30(%rsp)
cmpq (%r12), %r13
je 0x7941
movq 0x8(%r13), %rdi
addq $0x10, %rdi
callq 0x208e2
ucomisd 0x8(%rsp), %xmm0
jne 0x7941
jp 0x7941
movb $0x1, %al
movl %eax, 0x14(%rsp)
jmp 0x7949
movl $0x0, 0x14(%rsp)
movb $0x1, %al
movl %eax, 0x24(%rsp)
testb %bl, %bl
jne 0x796e
leaq 0x10(%r15), %rdi
callq 0x208e2
ucomisd 0x8(%rsp), %xmm0
jne 0x796e
jp 0x796e
movl $0x0, 0x24(%rsp)
testb %bl, %bl
jne 0x7989
leaq 0x10(%r15), %rdi
callq 0x208e2
ucomisd 0x30(%rsp), %xmm0
jne 0x7989
jp 0x7989
movb $0x1, %bl
jmp 0x798b
xorl %ebx, %ebx
movq %r12, %rdi
movq %r13, %rsi
movq %r15, %rdx
callq 0x7b80
cmpb $0x0, 0x14(%rsp)
jne 0x79dd
leaq 0x48(%rsp), %r12
movq %r12, %rdi
movsd 0x28(%rsp), %xmm0
movsd 0x8(%rsp), %xmm1
callq 0x2090c
movl $0x20, %edi
callq 0x6380
movupd (%r12), %xmm0
movupd %xmm0, 0x10(%rax)
movq %rax, %rdi
movq %r15, %rsi
callq 0x6060
incq 0x18(%r14)
orb 0x24(%rsp), %bpl
je 0x7a33
leaq 0x48(%rsp), %r12
movq %r12, %rdi
movsd 0x18(%rsp), %xmm0
movsd 0x30(%rsp), %xmm1
callq 0x2090c
movl $0x20, %edi
callq 0x6380
movupd (%r12), %xmm0
movupd %xmm0, 0x10(%rax)
movq %rax, %rdi
movq %r15, %rsi
callq 0x6060
movq 0x18(%r14), %rax
leaq 0x1(%rax), %rcx
movq %rcx, 0x18(%r14)
testb %bl, %bl
je 0x7a4c
movq %rax, 0x18(%r14)
jmp 0x7a37
decq 0x18(%r14)
movq %r15, %rdi
callq 0x65b0
movl $0x20, %esi
movq %r15, %rdi
callq 0x6390
leaq 0x48(%rsp), %r14
movq %r14, %rdi
movsd 0x28(%rsp), %xmm0
movsd 0x38(%rsp), %xmm1
callq 0x2090c
movq 0x40(%rsp), %rbx
leaq 0x10(%rbx), %rdi
movsd 0x18(%rsp), %xmm0
movsd 0x8(%rsp), %xmm1
callq 0x2090c
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