// File: 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
movq %rsp, %rbp
subq $0x1d0, %rsp            # imm = 0x1D0
movq %rdi, -0x198(%rbp)
movq %rdi, -0x190(%rbp)
movq %rsi, -0x8(%rbp)
movsd %xmm0, -0x10(%rbp)
movsd %xmm1, -0x18(%rbp)
movsd %xmm2, -0x20(%rbp)
movq -0x8(%rbp), %rdi
movq %rdi, -0x188(%rbp)
movsd -0x10(%rbp), %xmm0
movsd %xmm0, -0x28(%rbp)
movsd -0x10(%rbp), %xmm0
movsd -0x10(%rbp), %xmm1
addsd -0x18(%rbp), %xmm1
callq 0xc0c0
movq -0x188(%rbp), %rax
movsd %xmm0, -0x30(%rbp)
movsd -0x28(%rbp), %xmm0
addsd -0x18(%rbp), %xmm0
movsd %xmm0, -0x38(%rbp)
movsd -0x30(%rbp), %xmm0
addsd -0x20(%rbp), %xmm0
movsd %xmm0, -0x40(%rbp)
movsd -0x40(%rbp), %xmm0
ucomisd (%rax), %xmm0
jbe 0xbb3a
movq -0x188(%rbp), %rax
movsd -0x40(%rbp), %xmm0
movsd %xmm0, (%rax)
movq -0x188(%rbp), %rdi
addq $0x8, %rdi
callq 0xc400
movq %rax, -0x48(%rbp)
movq -0x188(%rbp), %rdi
addq $0x8, %rdi
callq 0xc460
movq %rax, -0x50(%rbp)
leaq -0x48(%rbp), %rdi
leaq -0x50(%rbp), %rsi
callq 0xc430
movb %al, %cl
xorl %eax, %eax
testb $0x1, %cl
movb %al, -0x199(%rbp)
jne 0xbb80
jmp 0xbba6
leaq -0x48(%rbp), %rdi
callq 0xc490
movq %rax, %rdi
callq 0x48a20
movaps %xmm0, %xmm1
movsd -0x28(%rbp), %xmm0
ucomisd %xmm1, %xmm0
seta %al
movb %al, -0x199(%rbp)
movb -0x199(%rbp), %al
testb $0x1, %al
jne 0xbbb2
jmp 0xbbbd
leaq -0x48(%rbp), %rdi
callq 0xc4b0
jmp 0xbb4e
movq -0x48(%rbp), %rax
movq %rax, -0x58(%rbp)
movq -0x188(%rbp), %rdi
addq $0x8, %rdi
callq 0xc460
movq %rax, -0x60(%rbp)
leaq -0x48(%rbp), %rdi
leaq -0x60(%rbp), %rsi
callq 0xc430
movb %al, %cl
xorl %eax, %eax
testb $0x1, %cl
movb %al, -0x19a(%rbp)
jne 0xbbf7
jmp 0xbc1d
leaq -0x48(%rbp), %rdi
callq 0xc490
movq %rax, %rdi
callq 0x48a20
movaps %xmm0, %xmm1
movsd -0x38(%rbp), %xmm0
ucomisd %xmm1, %xmm0
seta %al
movb %al, -0x19a(%rbp)
movb -0x19a(%rbp), %al
testb $0x1, %al
jne 0xbc29
jmp 0xbc34
leaq -0x48(%rbp), %rdi
callq 0xc4b0
jmp 0xbbc5
movq -0x188(%rbp), %rdi
movq -0x48(%rbp), %rax
movq %rax, -0x68(%rbp)
addq $0x8, %rdi
callq 0xc460
movq %rax, -0x78(%rbp)
leaq -0x68(%rbp), %rdi
leaq -0x78(%rbp), %rsi
callq 0xc4d0
movb %al, %cl
movb $0x1, %al
testb $0x1, %cl
movb %al, -0x19b(%rbp)
jne 0xbc90
leaq -0x68(%rbp), %rdi
callq 0xc490
movq %rax, %rdi
callq 0x48a20
ucomisd -0x38(%rbp), %xmm0
setne %al
setp %cl
orb %cl, %al
movb %al, -0x19b(%rbp)
movb -0x19b(%rbp), %al
andb $0x1, %al
decb %al
andb $0x1, %al
movb %al, -0x69(%rbp)
movq -0x68(%rbp), %rax
movq %rax, -0x90(%rbp)
movq -0x90(%rbp), %rdi
movl $0x1, %esi
callq 0xc500
movq %rax, -0x88(%rbp)
leaq -0x88(%rbp), %rdi
callq 0xc490
movq %rax, %rdi
callq 0x48a40
movq -0x188(%rbp), %rdi
movsd %xmm0, -0x80(%rbp)
movb $0x0, -0x91(%rbp)
addq $0x8, %rdi
callq 0xc400
movq %rax, -0xa0(%rbp)
leaq -0x58(%rbp), %rdi
leaq -0xa0(%rbp), %rsi
callq 0xc430
movb %al, %cl
xorl %eax, %eax
testb $0x1, %cl
movb %al, -0x19c(%rbp)
jne 0xbd1a
jmp 0xbd64
movq -0x58(%rbp), %rax
movq %rax, -0xb0(%rbp)
movq -0xb0(%rbp), %rdi
movl $0x1, %esi
callq 0xc500
movq %rax, -0xa8(%rbp)
leaq -0xa8(%rbp), %rdi
callq 0xc490
movq %rax, %rdi
callq 0x48a40
ucomisd -0x40(%rbp), %xmm0
sete %al
setnp %cl
andb %cl, %al
movb %al, -0x19c(%rbp)
movb -0x19c(%rbp), %al
testb $0x1, %al
jne 0xbd70
jmp 0xbd77
movb $0x1, -0x91(%rbp)
movq -0x188(%rbp), %rdi
movb $0x0, -0xb1(%rbp)
addq $0x8, %rdi
callq 0xc460
movq %rax, -0xc0(%rbp)
leaq -0x68(%rbp), %rdi
leaq -0xc0(%rbp), %rsi
callq 0xc430
movb %al, %cl
xorl %eax, %eax
testb $0x1, %cl
movb %al, -0x19d(%rbp)
jne 0xbdb6
jmp 0xbdda
leaq -0x68(%rbp), %rdi
callq 0xc490
movq %rax, %rdi
callq 0x48a40
ucomisd -0x40(%rbp), %xmm0
sete %al
setnp %cl
andb %cl, %al
movb %al, -0x19d(%rbp)
movb -0x19d(%rbp), %al
testb $0x1, %al
jne 0xbde6
jmp 0xbded
movb $0x1, -0xb1(%rbp)
movq -0x188(%rbp), %rdi
movb $0x0, -0xc1(%rbp)
addq $0x8, %rdi
callq 0xc460
movq %rax, -0xd0(%rbp)
leaq -0x68(%rbp), %rdi
leaq -0xd0(%rbp), %rsi
callq 0xc430
movb %al, %cl
xorl %eax, %eax
testb $0x1, %cl
movb %al, -0x19e(%rbp)
jne 0xbe2c
jmp 0xbe50
leaq -0x68(%rbp), %rdi
callq 0xc490
movq %rax, %rdi
callq 0x48a40
ucomisd -0x80(%rbp), %xmm0
sete %al
setnp %cl
andb %cl, %al
movb %al, -0x19e(%rbp)
movb -0x19e(%rbp), %al
testb $0x1, %al
jne 0xbe5c
jmp 0xbe63
movb $0x1, -0xc1(%rbp)
testb $0x1, -0x91(%rbp)
je 0xbec4
movq -0x188(%rbp), %rax
addq $0x8, %rax
movq %rax, -0x1a8(%rbp)
leaq -0xd8(%rbp), %rdi
leaq -0x58(%rbp), %rsi
callq 0xc5c0
leaq -0xe0(%rbp), %rdi
leaq -0x68(%rbp), %rsi
callq 0xc5c0
movq -0x1a8(%rbp), %rdi
movq -0xd8(%rbp), %rsi
movq -0xe0(%rbp), %rdx
callq 0xc540
movq %rax, -0xe8(%rbp)
jmp 0xbf73
movq -0x188(%rbp), %rax
addq $0x8, %rax
movq %rax, -0x1b8(%rbp)
leaq -0xf0(%rbp), %rdi
leaq -0x58(%rbp), %rsi
callq 0xc5c0
leaq -0xf8(%rbp), %rdi
leaq -0x68(%rbp), %rsi
callq 0xc5c0
movq -0x1b8(%rbp), %rdi
movq -0xf0(%rbp), %rsi
movq -0xf8(%rbp), %rdx
callq 0xc540
movq %rax, %rcx
movq -0x188(%rbp), %rax
movq %rcx, -0x100(%rbp)
addq $0x8, %rax
movq %rax, -0x1b0(%rbp)
leaq -0x108(%rbp), %rdi
leaq -0x68(%rbp), %rsi
callq 0xc5c0
movsd -0x28(%rbp), %xmm0
movsd -0x40(%rbp), %xmm1
leaq -0x118(%rbp), %rdi
callq 0x48b00
movq -0x1b0(%rbp), %rdi
movq -0x108(%rbp), %rsi
leaq -0x118(%rbp), %rdx
callq 0xc5e0
movq %rax, -0x120(%rbp)
testb $0x1, -0x69(%rbp)
je 0xbfc3
testb $0x1, -0xb1(%rbp)
je 0xbfc3
movq -0x188(%rbp), %rax
addq $0x8, %rax
movq %rax, -0x1c0(%rbp)
leaq -0x128(%rbp), %rdi
leaq -0x68(%rbp), %rsi
callq 0xc5c0
movq -0x1c0(%rbp), %rdi
movq -0x128(%rbp), %rsi
callq 0xc620
movq %rax, -0x130(%rbp)
jmp 0xc063
movq -0x188(%rbp), %rax
addq $0x8, %rax
movq %rax, -0x1c8(%rbp)
leaq -0x138(%rbp), %rdi
leaq -0x68(%rbp), %rsi
callq 0xc5c0
movsd -0x38(%rbp), %xmm0
movsd -0x80(%rbp), %xmm1
leaq -0x148(%rbp), %rdi
callq 0x48b00
movq -0x1c8(%rbp), %rdi
movq -0x138(%rbp), %rsi
leaq -0x148(%rbp), %rdx
callq 0xc5e0
movq %rax, -0x150(%rbp)
testb $0x1, -0xc1(%rbp)
je 0xc061
movq -0x188(%rbp), %rax
addq $0x8, %rax
movq %rax, -0x1d0(%rbp)
leaq -0x158(%rbp), %rdi
leaq -0x68(%rbp), %rsi
callq 0xc5c0
movq -0x1d0(%rbp), %rdi
movq -0x158(%rbp), %rsi
callq 0xc620
movq %rax, -0x160(%rbp)
jmp 0xc063
movsd -0x28(%rbp), %xmm0
movsd -0x30(%rbp), %xmm1
leaq -0x170(%rbp), %rdi
callq 0x48b00
movsd -0x38(%rbp), %xmm0
movsd -0x40(%rbp), %xmm1
leaq -0x180(%rbp), %rdi
callq 0x48b00
movq -0x198(%rbp), %rdi
leaq -0x170(%rbp), %rsi
leaq -0x180(%rbp), %rdx
callq 0xc670
movq -0x190(%rbp), %rax
addq $0x1d0, %rsp            # imm = 0x1D0
popq %rbp
retq
nopl (%rax)