// File: /workspace/github_cpp_makefile_star2_O1/wrighteagle2d[P]wrighteaglebase/Debug/../src/PositionInfo.cpp
// Function: PositionInfo::UpdateOffsideLine()
void PositionInfo::UpdateOffsideLine() {
  const BallState &ball_state = mpWorldState->GetBall();
  const PlayerState *pPlayer = 0;

  double first = 0.0;
  double second = 0.0;
  Unum f_unum = 0;
  Unum s_unum = 0;

  // teammate offside line
  for (int i = 1; i <= TEAMSIZE; ++i) {
    pPlayer = &(mpWorldState->GetOpponent(i));
    if (pPlayer->IsAlive() == false) {
      continue;
    }

    if (pPlayer->GetPos().X() > second) {
      if (pPlayer->GetPos().X() > first) {
        second = first;
        s_unum = f_unum;
        first = pPlayer->GetPos().X();
        f_unum = i;
      } else {
        second = pPlayer->GetPos().X();
        s_unum = i;
      }
    }
  }

  if (ball_state.GetPosConf() > PlayerParam::instance().minValidConf() &&
      ball_state.GetPos().X() > second) {
    mTeammateOffsideLineOpp = 0;
    mTeammateOffsideLine = ball_state.GetPos().X();
    mTeammateOffsideLineConf = ball_state.GetPosConf();
    mTeammateOffsideLineSpeed = ball_state.GetVel().X();
  } else {
    mTeammateOffsideLine = second;
    if (s_unum == 0) {
      mTeammateOffsideLineOpp = 0;
      mTeammateOffsideLineConf = 0.0;
      mTeammateOffsideLineSpeed = 0.0;
    } else {
      mTeammateOffsideLineOpp = s_unum;
      mTeammateOffsideLineConf = mpWorldState->GetOpponent(s_unum).GetPosConf();
      mTeammateOffsideLineSpeed =
          mpWorldState->GetOpponent(s_unum).GetVel().X();
    }
  }

  // opponent offside line
  first = 0.0;
  second = 0.0;
  f_unum = 0;
  s_unum = 0;
  for (int i = 1; i <= TEAMSIZE; ++i) {
    pPlayer = &(mpWorldState->GetTeammate(i));
    if (pPlayer->IsAlive() == false) {
      continue;
    }

    if (pPlayer->GetPos().X() < second) {
      if (pPlayer->GetPos().X() < first) {
        second = first;
        s_unum = f_unum;
        first = pPlayer->GetPos().X();
        f_unum = i;
      } else {
        second = pPlayer->GetPos().X();
        s_unum = i;
      }
    }
  }
  if (ball_state.GetPosConf() > PlayerParam::instance().minValidConf() &&
      ball_state.GetPos().X() < second) {
    mOpponentOffsideLineTm = 0;
    mOpponentOffsideLine = ball_state.GetPos().X();
    mOpponentOffsideLineConf = ball_state.GetPosConf();
    mOpponentOffsideLineSpeed = ball_state.GetVel().X();
  } else {
    mOpponentOffsideLine = second;
    if (s_unum == 0) {
      mOpponentOffsideLineTm = 0;
      mOpponentOffsideLineConf = 0.0;
      mOpponentOffsideLineSpeed = 0.0;
    } else {
      mOpponentOffsideLineTm = s_unum;
      mOpponentOffsideLineConf = mpWorldState->GetTeammate(s_unum).GetPosConf();
      mOpponentOffsideLineSpeed =
          mpWorldState->GetTeammate(s_unum).GetVel().X();
    }
  }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %rbx
subq $0x18, %rsp
movq %rdi, %rbx
movq 0x10(%rdi), %r14
xorpd %xmm3, %xmm3
xorl %eax, %eax
movl $0x1, %ecx
xorl %edx, %edx
xorpd %xmm0, %xmm0
xorl %r15d, %r15d
cmpb $0x1, 0x11e2(%r14,%rax)
jne 0x4817b
movsd 0x10d8(%r14,%rax), %xmm1
ucomisd %xmm3, %xmm1
jbe 0x4817b
ucomisd %xmm0, %xmm1
movl %ecx, %r15d
cmoval %edx, %r15d
movapd %xmm1, %xmm2
maxsd %xmm0, %xmm2
movapd %xmm0, %xmm3
minsd %xmm1, %xmm3
cmoval %ecx, %edx
movapd %xmm2, %xmm0
addq $0x178, %rax            # imm = 0x178
incl %ecx
cmpq $0x1028, %rax           # imm = 0x1028
jne 0x4813e
movsd 0x50(%r14), %xmm0
movsd %xmm0, -0x20(%rbp)
movsd %xmm3, -0x28(%rbp)
callq 0x450ba
movsd -0x28(%rbp), %xmm1
movsd -0x20(%rbp), %xmm0
ucomisd 0x31e8(%rax), %xmm0
jbe 0x481e8
movsd 0x38(%r14), %xmm0
ucomisd %xmm1, %xmm0
jbe 0x481e8
movl $0x0, 0x1798(%rbx)
movsd %xmm0, 0x17a0(%rbx)
movsd 0x50(%r14), %xmm0
movsd %xmm0, 0x17a8(%rbx)
movsd 0x60(%r14), %xmm0
jmp 0x48227
movsd %xmm1, 0x17a0(%rbx)
testl %r15d, %r15d
je 0x48231
movl %r15d, 0x1798(%rbx)
movq 0x10(%rbx), %rax
decl %r15d
movslq %r15d, %rcx
imulq $0x178, %rcx, %rcx      # imm = 0x178
movsd 0x10f0(%rax,%rcx), %xmm0
movsd %xmm0, 0x17a8(%rbx)
movsd 0x1100(%rax,%rcx), %xmm0
movsd %xmm0, 0x17b0(%rbx)
jmp 0x48247
movl $0x0, 0x1798(%rbx)
xorpd %xmm0, %xmm0
movupd %xmm0, 0x17a8(%rbx)
movq 0x10(%rbx), %rax
xorpd %xmm3, %xmm3
xorl %ecx, %ecx
movl $0x1ba, %edx            # imm = 0x1BA
movl $0x1, %esi
xorpd %xmm0, %xmm0
xorl %r15d, %r15d
cmpb $0x1, (%rax,%rdx)
jne 0x48299
movsd -0x10a(%rax,%rdx), %xmm1
ucomisd %xmm1, %xmm3
jbe 0x48299
ucomisd %xmm1, %xmm0
movl %esi, %r15d
cmoval %ecx, %r15d
movapd %xmm1, %xmm2
minsd %xmm0, %xmm2
movapd %xmm0, %xmm3
maxsd %xmm1, %xmm3
cmoval %esi, %ecx
movapd %xmm2, %xmm0
addq $0x178, %rdx            # imm = 0x178
incl %esi
cmpq $0x11e2, %rdx           # imm = 0x11E2
jne 0x48262
movsd 0x50(%r14), %xmm0
movsd %xmm0, -0x20(%rbp)
movsd %xmm3, -0x28(%rbp)
callq 0x450ba
movsd -0x28(%rbp), %xmm1
movsd -0x20(%rbp), %xmm0
ucomisd 0x31e8(%rax), %xmm0
jbe 0x48308
movsd 0x38(%r14), %xmm0
ucomisd %xmm0, %xmm1
jbe 0x48308
movl $0x0, 0x17b8(%rbx)
movsd %xmm0, 0x17c0(%rbx)
movsd 0x50(%r14), %xmm0
movsd %xmm0, 0x17c8(%rbx)
movsd 0x60(%r14), %xmm0
jmp 0x48347
movsd %xmm1, 0x17c0(%rbx)
testl %r15d, %r15d
je 0x48351
movl %r15d, 0x17b8(%rbx)
movq 0x10(%rbx), %rax
decl %r15d
movslq %r15d, %rcx
imulq $0x178, %rcx, %rcx      # imm = 0x178
movsd 0xc8(%rax,%rcx), %xmm0
movsd %xmm0, 0x17c8(%rbx)
movsd 0xd8(%rax,%rcx), %xmm0
movsd %xmm0, 0x17d0(%rbx)
jmp 0x48367
movl $0x0, 0x17b8(%rbx)
xorpd %xmm0, %xmm0
movupd %xmm0, 0x17c8(%rbx)
addq $0x18, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
retq