// File: /workspace/github_cpp_makefile_star2_O3/wrighteagle2d[P]wrighteaglebase/Debug/../src/CommunicateSystem.cpp
// Function: CommunicateSystem::SendBallStatus(BallState const&, int)
bool CommunicateSystem::SendBallStatus(const BallState &ball_state, int cd) {
  if (mCommuType != FREE_FORM) {
    return false;
  }

  SetCommunicateType(FREE_FORM);

  if (mBallSended == true) {
    return false;
  }

  int pos_cd = ball_state.GetPosDelay();
  int vel_cd = ball_state.GetVelDelay();
  Vector pos = ball_state.GetPos();
  Vector vel = ball_state.GetVel();
  FreeFormType send_type = FREE_FORM_MAX;

  if (pos_cd <= cd) {
    if (mFreeFormCodecBitCount[BALL_ONLY_POS] + mBitsUsed <= MAX_BITS_USED) {
      if (vel_cd <= cd) {
        if (vel.Mod2() > FLOAT_EPS) { // BALL_WITH_SPEED
          if (mFreeFormCodecBitCount[BALL_WITH_SPEED] + mBitsUsed <=
              MAX_BITS_USED) {
            send_type = BALL_WITH_SPEED;
          } else { // BALL_ONLY_POS
            send_type = BALL_ONLY_POS;
          }
        } else { // BALL_WITH_ZERO_SPEED
          if (mFreeFormCodecBitCount[BALL_WITH_ZERO_SPEED] + mBitsUsed <=
              MAX_BITS_USED) {
            send_type = BALL_WITH_ZERO_SPEED;
          } else { // BALL_ONLY_POS
            send_type = BALL_ONLY_POS;
          }
        }
      } else { // BALL_ONLY_POS
        send_type = BALL_ONLY_POS;
      }
    }
  }
  if (send_type != FREE_FORM_MAX) {
    switch (send_type) {
    case BALL_WITH_SPEED:
      AddDataToCommuBits(pos.X(), POS_X);
      AddDataToCommuBits(pos.Y(), POS_Y);
      AddDataToCommuBits(vel.Mod(), BALL_SPEED);
      AddDataToCommuBits(vel.Dir(), DIR);
      AddFreeFormFlagToCommuBits(BALL_WITH_SPEED);
      mBallSended = true;
      Logger::instance().GetTextLogger("freeform")
          << mpAgent->GetWorldState().CurrentTime() << " send ball: " << pos
          << " " << vel << endl;
      return true;
    case BALL_WITH_ZERO_SPEED:
      AddDataToCommuBits(pos.X(), POS_X);
      AddDataToCommuBits(pos.Y(), POS_Y);
      AddFreeFormFlagToCommuBits(BALL_WITH_ZERO_SPEED);
      mBallSended = true;
      Logger::instance().GetTextLogger("freeform")
          << mpAgent->GetWorldState().CurrentTime() << " send ball: " << pos
          << " " << Vector(0, 0) << endl;
      return true;
    case BALL_ONLY_POS:
      AddDataToCommuBits(pos.X(), POS_X);
      AddDataToCommuBits(pos.Y(), POS_Y);
      AddFreeFormFlagToCommuBits(BALL_ONLY_POS);
      Logger::instance().GetTextLogger("freeform")
          << mpAgent->GetWorldState().CurrentTime() << " send ball: " << pos
          << endl;
      mBallSended = true;
      return true;
    default:
      PRINT_ERROR("send ball status");
      break;
    }
  }
  return false;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %rbx
subq $0x68, %rsp
cmpl $0x0, 0x3c(%rdi)
jne 0x1db05
movq %rdi, %rbx
leaq 0x80(%rdi), %rax
movq %rax, 0xc0(%rdi)
leaq 0x98(%rdi), %rax
movq %rax, 0xc8(%rdi)
cmpb $0x0, 0x24(%rdi)
jne 0x1db05
movl 0x18(%rsi), %eax
movl 0x40(%rsi), %edi
movups 0x8(%rsi), %xmm0
movaps %xmm0, -0x30(%rbp)
movupd 0x30(%rsi), %xmm0
movapd %xmm0, -0x40(%rbp)
cmpl %edx, %eax
jg 0x1db05
movl 0x20(%rbx), %eax
movl 0xd8(%rbx), %esi
addl %eax, %esi
movl 0x66a0f(%rip), %ecx     # 0x84510
cmpl %ecx, %esi
jle 0x1db14
xorl %ebx, %ebx
movl %ebx, %eax
addq $0x68, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
retq
cmpl %edx, %edi
jle 0x1dbe5
movsd -0x30(%rbp), %xmm0
movq %rbx, %rdi
xorl %esi, %esi
callq 0x1d7ac
movsd -0x28(%rbp), %xmm0
movq %rbx, %rdi
movl $0x1, %esi
callq 0x1d7ac
movq %rbx, %rdi
movl $0x2, %esi
callq 0x1d8aa
callq 0x34c60
leaq 0x4c6e5(%rip), %rsi     # 0x6a23b
movq %rax, %rdi
callq 0x34e74
movq %rax, %r14
movq 0x10(%rbx), %rax
movq 0x18(%rax), %r15
callq 0x43dce
cmpb $0x1, 0x5c45(%rax)
jne 0x1db8d
addq $0x10, %r15
movq %r14, %rdi
addq $0x210, %rdi            # imm = 0x210
movq %r15, %rsi
callq 0xe974
leaq 0x4c6b0(%rip), %rsi     # 0x6a244
movq %r14, %rdi
callq 0x1ee52
movq %rax, %r14
callq 0x43dce
cmpb $0x1, 0x5c45(%rax)
jne 0x1dbbd
leaq 0x210(%r14), %rdi
leaq -0x30(%rbp), %rsi
callq 0x1efff
callq 0x43dce
cmpb $0x1, 0x5c45(%rax)
jne 0x1dbda
addq $0x210, %r14            # imm = 0x210
movq %r14, %rdi
callq 0x9240
movb $0x1, 0x24(%rbx)
movb $0x1, %bl
jmp 0x1db07
movsd -0x40(%rbp), %xmm1
movsd -0x38(%rbp), %xmm2
movapd %xmm2, %xmm0
mulsd %xmm2, %xmm0
movapd %xmm1, %xmm3
mulsd %xmm1, %xmm3
addsd %xmm0, %xmm3
ucomisd 0x4b435(%rip), %xmm3    # 0x69040
jbe 0x1dd9c
addl 0xd0(%rbx), %eax
cmpl %ecx, %eax
jg 0x1db1c
movsd -0x30(%rbp), %xmm0
movq %rbx, %rdi
xorl %esi, %esi
movapd %xmm1, -0x70(%rbp)
movapd %xmm2, -0x60(%rbp)
movapd %xmm3, -0x50(%rbp)
callq 0x1d7ac
movsd -0x28(%rbp), %xmm0
movq %rbx, %rdi
movl $0x1, %esi
callq 0x1d7ac
xorps %xmm0, %xmm0
sqrtsd -0x50(%rbp), %xmm0
movq %rbx, %rdi
movl $0x2, %esi
callq 0x1d7ac
movapd -0x60(%rbp), %xmm4
movapd -0x70(%rbp), %xmm1
movapd 0x4b39a(%rip), %xmm3    # 0x69010
movapd %xmm1, %xmm0
andpd %xmm3, %xmm0
movsd 0x4b3ba(%rip), %xmm2    # 0x69040
ucomisd %xmm0, %xmm2
jbe 0x1dc9a
andpd %xmm4, %xmm3
xorpd %xmm0, %xmm0
ucomisd %xmm3, %xmm2
ja 0x1dcb3
movapd %xmm4, %xmm0
callq 0x90d0
mulsd 0x4b39d(%rip), %xmm0    # 0x69048
divsd 0x4b39d(%rip), %xmm0    # 0x69050
movq %rbx, %rdi
movl $0x4, %esi
callq 0x1d7ac
movq %rbx, %rdi
xorl %esi, %esi
callq 0x1d8aa
movb $0x1, 0x24(%rbx)
callq 0x34c60
leaq 0x4c561(%rip), %rsi     # 0x6a23b
movq %rax, %rdi
callq 0x34e74
movq %rax, %r14
movq 0x10(%rbx), %rax
movq 0x18(%rax), %rbx
callq 0x43dce
cmpb $0x1, 0x5c45(%rax)
jne 0x1dd11
addq $0x10, %rbx
movq %r14, %rdi
addq $0x210, %rdi            # imm = 0x210
movq %rbx, %rsi
callq 0xe974
leaq 0x4c52c(%rip), %rsi     # 0x6a244
movq %r14, %rdi
callq 0x1ee52
movq %rax, %rbx
callq 0x43dce
cmpb $0x1, 0x5c45(%rax)
jne 0x1dd44
movq %rbx, %rdi
addq $0x210, %rdi            # imm = 0x210
leaq -0x30(%rbp), %rsi
callq 0x1efff
leaq 0x4ee79(%rip), %rsi     # 0x6cbc4
movq %rbx, %rdi
callq 0x13482
movq %rax, %r14
callq 0x43dce
cmpb $0x1, 0x5c45(%rax)
jne 0x1dd74
leaq 0x210(%r14), %rdi
leaq -0x40(%rbp), %rsi
callq 0x1efff
callq 0x43dce
movb $0x1, %bl
cmpb $0x1, 0x5c45(%rax)
jne 0x1db07
addq $0x210, %r14            # imm = 0x210
movq %r14, %rdi
callq 0x9240
jmp 0x1db07
addl 0xd4(%rbx), %eax
cmpl %ecx, %eax
jg 0x1db1c
movsd -0x30(%rbp), %xmm0
movq %rbx, %rdi
xorl %esi, %esi
callq 0x1d7ac
movsd -0x28(%rbp), %xmm0
movq %rbx, %rdi
movl $0x1, %esi
callq 0x1d7ac
movq %rbx, %rdi
movl $0x1, %esi
callq 0x1d8aa
movb $0x1, 0x24(%rbx)
callq 0x34c60
leaq 0x4c453(%rip), %rsi     # 0x6a23b
movq %rax, %rdi
callq 0x34e74
movq %rax, %r14
movq 0x10(%rbx), %rax
movq 0x18(%rax), %rbx
callq 0x43dce
cmpb $0x1, 0x5c45(%rax)
jne 0x1de1f
addq $0x10, %rbx
movq %r14, %rdi
addq $0x210, %rdi            # imm = 0x210
movq %rbx, %rsi
callq 0xe974
leaq 0x4c41e(%rip), %rsi     # 0x6a244
movq %r14, %rdi
callq 0x1ee52
movq %rax, %rbx
callq 0x43dce
cmpb $0x1, 0x5c45(%rax)
jne 0x1de52
movq %rbx, %rdi
addq $0x210, %rdi            # imm = 0x210
leaq -0x30(%rbp), %rsi
callq 0x1efff
leaq 0x4ed6b(%rip), %rsi     # 0x6cbc4
movq %rbx, %rdi
callq 0x13482
movq %rax, %rbx
xorpd %xmm0, %xmm0
movapd %xmm0, -0x80(%rbp)
callq 0x43dce
cmpb $0x1, 0x5c45(%rax)
jne 0x1de8b
leaq 0x210(%rbx), %rdi
leaq -0x80(%rbp), %rsi
callq 0x1efff
callq 0x43dce
cmpb $0x1, 0x5c45(%rax)
jne 0x1dbde
addq $0x210, %rbx            # imm = 0x210
movq %rbx, %rdi
callq 0x9240
jmp 0x1dbde
nop