// File: /workspace/github_cpp_makefile_star2_O3/rachit31[P]CubeSatADCS/sendUdp.cpp
// Function: SendUdp::initialize(char const*, char const*, unsigned short)
const char* SendUdp::initialize(const char* localIp, const char* remoteIp, const uint16_t sendPort)
{
  std::stringstream error;

  // Create a datagram socket (TLPI pg 1153)
  m_socketFd = socket(AF_INET, SOCK_DGRAM, 0);
  if (m_socketFd == -1)
  {
    error << "socket(): " << std::strerror(errno);
    return error.str().c_str();
  }

  // IPv4 soccket address structure (TLPI pg 1202)
  struct in_addr in_addr;

  // Convert Presentation IP to Network (TLPI pg 1206)
  int retVal = inet_pton(AF_INET, localIp, &in_addr);
  if (retVal == -1)
  {
    error << "inet_pton(): " << std::strerror(errno);
    return error.str().c_str();
  }
  else if (retVal == 0)
  {
    error << "inet_pton(): " << localIp << " is not a valid network address";
    return error.str().c_str();;
  }

  // Setup sockaddr_in structure (TLPI pg 1202)
  memset(&m_sockaddr_in, 0, sizeof(struct sockaddr_in));
  m_sockaddr_in.sin_family = AF_INET;
  m_sockaddr_in.sin_addr = in_addr;
  m_sockaddr_in.sin_port = htons(sendPort);

  // Bind Socket to Address described by sockaddr_in (TLPI pg 1153)
  if (bind(m_socketFd, (struct sockaddr *) &m_sockaddr_in, sizeof(struct sockaddr_in)) == -1)
  {
    error << "bind(): " << std::strerror(errno);
    return error.str().c_str();
  }

  // Convert Presentation IP to Network (TLPI pg 1206)
  retVal = inet_pton(AF_INET, remoteIp, &in_addr);
  if (retVal == -1)
  {
    error << "inet_pton(): " << std::strerror(errno);
    return error.str().c_str();
  }
  else if (retVal == 0)
  {
    error << "inet_pton(): " << remoteIp << " is not a valid network address";
    return error.str().c_str();;
  }

  // Setup sockaddr_in structure (TLPI pg 1202)
  memset(&m_sockaddr_in, 0, sizeof(struct sockaddr_in));
  m_sockaddr_in.sin_family = AF_INET;
  m_sockaddr_in.sin_addr = in_addr;
  m_sockaddr_in.sin_port = htons(sendPort);

  m_len = sizeof(struct sockaddr_in);

  return error.str().c_str();
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
subq $0x1b0, %rsp            # imm = 0x1B0
movl %ecx, %r14d
movq %rdx, %rbx
movq %rsi, %r12
movq %rdi, %r15
leaq -0x1d0(%rbp), %rdi
callq 0x2180
movl $0x2, %edi
movl $0x2, %esi
xorl %edx, %edx
callq 0x20a0
movl %eax, (%r15)
cmpl $-0x1, %eax
je 0x3e49
leaq -0x24(%rbp), %rdx
movl $0x2, %edi
movq %r12, %rsi
callq 0x23e0
testl %eax, %eax
je 0x3e97
cmpl $-0x1, %eax
jne 0x3ed6
leaq -0x1c0(%rbp), %rbx
leaq 0x4442(%rip), %rsi      # 0x824b
movl $0xd, %edx
movq %rbx, %rdi
callq 0x2280
callq 0x2050
movl (%rax), %edi
callq 0x20d0
testq %rax, %rax
je 0x4003
movq %rax, %r14
movq %rax, %rdi
callq 0x2100
movq %rbx, %rdi
movq %r14, %rsi
movq %rax, %rdx
callq 0x2280
jmp 0x4023
leaq -0x1c0(%rbp), %rbx
leaq 0x43e9(%rip), %rsi      # 0x8240
movl $0xa, %edx
movq %rbx, %rdi
callq 0x2280
callq 0x2050
movl (%rax), %edi
callq 0x20d0
testq %rax, %rax
je 0x3f80
movq %rax, %r14
movq %rax, %rdi
callq 0x2100
movq %rbx, %rdi
movq %r14, %rsi
movq %rax, %rdx
callq 0x2280
jmp 0x3fa0
leaq -0x1c0(%rbp), %rbx
leaq 0x43a6(%rip), %rsi      # 0x824b
movl $0xd, %edx
movq %rbx, %rdi
callq 0x2280
testq %r12, %r12
je 0x4038
movq %r12, %rdi
callq 0x2100
movq %rbx, %rdi
movq %r12, %rsi
movq %rax, %rdx
callq 0x2280
jmp 0x4056
leaq 0x4(%r15), %rsi
movq $0x0, 0xc(%r15)
movw $0x2, 0x4(%r15)
movl -0x24(%rbp), %eax
movl %eax, 0x8(%r15)
rolw $0x8, %r14w
movw %r14w, 0x6(%r15)
movl (%r15), %edi
movl $0x10, %edx
callq 0x2070
cmpl $-0x1, %eax
je 0x3fb5
leaq -0x24(%rbp), %rdx
movl $0x2, %edi
movq %rbx, %rsi
callq 0x23e0
testl %eax, %eax
je 0x407f
cmpl $-0x1, %eax
jne 0x40be
leaq -0x1c0(%rbp), %rbx
leaq 0x430b(%rip), %rsi      # 0x824b
movl $0xd, %edx
movq %rbx, %rdi
callq 0x2280
callq 0x2050
movl (%rax), %edi
callq 0x20d0
testq %rax, %rax
je 0x4128
movq %rax, %r14
movq %rax, %rdi
callq 0x2100
movq %rbx, %rdi
movq %r14, %rsi
movq %rax, %rdx
callq 0x2280
jmp 0x4148
movq -0x1c0(%rbp), %rax
movq -0x18(%rax), %rax
addq %rax, %rbx
movl -0x1a0(%rbp,%rax), %esi
orl $0x1, %esi
movq %rbx, %rdi
callq 0x2360
leaq -0x1b8(%rbp), %rsi
leaq -0x48(%rbp), %rdi
callq 0x2320
jmp 0x419c
leaq -0x1c0(%rbp), %rbx
leaq 0x42b6(%rip), %rsi      # 0x8279
movl $0x8, %edx
movq %rbx, %rdi
callq 0x2280
callq 0x2050
movl (%rax), %edi
callq 0x20d0
testq %rax, %rax
je 0x40f6
movq %rax, %r14
movq %rax, %rdi
callq 0x2100
movq %rbx, %rdi
movq %r14, %rsi
movq %rax, %rdx
callq 0x2280
jmp 0x4116
movq -0x1c0(%rbp), %rax
movq -0x18(%rax), %rax
addq %rax, %rbx
movl -0x1a0(%rbp,%rax), %esi
orl $0x1, %esi
movq %rbx, %rdi
callq 0x2360
leaq -0x1b8(%rbp), %rsi
leaq -0x48(%rbp), %rdi
callq 0x2320
jmp 0x419c
movq -0x1c0(%rbp), %rax
movq -0x18(%rax), %rax
leaq (%rbx,%rax), %rdi
movl -0x1a0(%rbp,%rax), %esi
orl $0x1, %esi
callq 0x2360
leaq 0x41fc(%rip), %rsi      # 0x8259
movl $0x1f, %edx
movq %rbx, %rdi
callq 0x2280
leaq -0x1b8(%rbp), %rsi
leaq -0x48(%rbp), %rdi
callq 0x2320
jmp 0x419c
leaq -0x1c0(%rbp), %r14
leaq 0x41be(%rip), %rsi      # 0x824b
movl $0xd, %edx
movq %r14, %rdi
callq 0x2280
testq %rbx, %rbx
je 0x415a
movq %rbx, %rdi
callq 0x2100
movq %r14, %rdi
movq %rbx, %rsi
movq %rax, %rdx
callq 0x2280
jmp 0x4178
movq $0x0, 0xc(%r15)
movw $0x2, 0x4(%r15)
movl -0x24(%rbp), %eax
movl %eax, 0x8(%r15)
movw %r14w, 0x6(%r15)
movl $0x10, 0x14(%r15)
leaq -0x1b8(%rbp), %rsi
leaq -0x48(%rbp), %rdi
callq 0x2320
jmp 0x419c
movq -0x1c0(%rbp), %rax
movq -0x18(%rax), %rax
addq %rax, %rbx
movl -0x1a0(%rbp,%rax), %esi
orl $0x1, %esi
movq %rbx, %rdi
callq 0x2360
leaq -0x1b8(%rbp), %rsi
leaq -0x48(%rbp), %rdi
callq 0x2320
jmp 0x419c
movq -0x1c0(%rbp), %rax
movq -0x18(%rax), %rax
addq %rax, %rbx
movl -0x1a0(%rbp,%rax), %esi
orl $0x1, %esi
movq %rbx, %rdi
callq 0x2360
leaq -0x1b8(%rbp), %rsi
leaq -0x48(%rbp), %rdi
callq 0x2320
jmp 0x419c
movq -0x1c0(%rbp), %rax
movq -0x18(%rax), %rax
leaq (%r14,%rax), %rdi
movl -0x1a0(%rbp,%rax), %esi
orl $0x1, %esi
callq 0x2360
leaq 0x40da(%rip), %rsi      # 0x8259
movl $0x1f, %edx
movq %r14, %rdi
callq 0x2280
leaq -0x1b8(%rbp), %rsi
leaq -0x48(%rbp), %rdi
callq 0x2320
leaq -0x38(%rbp), %rax
movq -0x10(%rax), %rbx
cmpq %rax, %rbx
je 0x41b8
movq -0x38(%rbp), %rsi
incq %rsi
movq %rbx, %rdi
callq 0x2260
movq 0x6df9(%rip), %rsi      # 0xafb8
leaq -0x1d0(%rbp), %rdi
callq 0x21c0
leaq -0x150(%rbp), %rdi
callq 0x20c0
movq %rbx, %rax
addq $0x1b0, %rsp            # imm = 0x1B0
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq
jmp 0x41fa
jmp 0x41fa
jmp 0x41fa
jmp 0x41fa
jmp 0x41fa
jmp 0x41fa
jmp 0x41fa
jmp 0x41fa
movq %rax, %rbx
movq 0x6db4(%rip), %rsi      # 0xafb8
leaq -0x1d0(%rbp), %rdi
callq 0x21c0
leaq -0x150(%rbp), %rdi
callq 0x20c0
movq %rbx, %rdi
callq 0x23a0