// File: /workspace/github_cpp_makefile_star2_O1/Distrotech[P]stund/udp.cxx
// Function: openPort(unsigned short, unsigned int, bool)
Socket
openPort( unsigned short port, unsigned int interfaceIp, bool verbose )
{
   Socket fd;
    
   fd = socket(PF_INET, SOCK_DGRAM, IPPROTO_UDP);
   if ( fd == INVALID_SOCKET )
   {
      int err = getErrno();
      cerr << "Could not create a UDP socket:" << err << endl;
      return INVALID_SOCKET;
   }
    
   struct sockaddr_in addr;
   memset((char*) &(addr),0, sizeof((addr)));
   addr.sin_family = AF_INET;
   addr.sin_addr.s_addr = htonl(INADDR_ANY);
   addr.sin_port = htons(port);
    
   if ( (interfaceIp != 0) && 
        ( interfaceIp != 0x100007f ) )
   {
      addr.sin_addr.s_addr = htonl(interfaceIp);
      if (verbose )
      {
         clog << "Binding to interface " 
              << hex << "0x" << htonl(interfaceIp) << dec << endl;
      }
   }
	
   if ( bind( fd,(struct sockaddr*)&addr, sizeof(addr)) != 0 )
   {
      int e = getErrno();
        
      switch (e)
      {
         case 0:
         {
            cerr << "Could not bind socket" << endl;
            return INVALID_SOCKET;
         }
         case EADDRINUSE:
         {
            cerr << "Port " << port << " for receiving UDP is in use" << endl;
            return INVALID_SOCKET;
         }
         break;
         case EADDRNOTAVAIL:
         {
            if ( verbose ) 
            {
               cerr << "Cannot assign requested address" << endl;
            }
            return INVALID_SOCKET;
         }
         break;
         default:
         {
            cerr << "Could not bind UDP receive port"
                 << "Error=" << e << " " << strerror(e) << endl;
            return INVALID_SOCKET;
         }
         break;
      }
   }
   if ( verbose )
   {
      clog << "Opened port " << port << " with fd " << fd << endl;
   }
   
   assert( fd != INVALID_SOCKET  );
	
   return fd;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
subq $0x10, %rsp
movl %edx, %r14d
movl %esi, %r15d
movl %edi, %ebp
movl $0x2, %edi
movl $0x2, %esi
movl $0x11, %edx
callq 0x2090
cmpl $-0x1, %eax
je 0x7d6a
movl %eax, %ebx
xorps %xmm0, %xmm0
movaps %xmm0, (%rsp)
movw $0x2, (%rsp)
movl $0x0, 0x4(%rsp)
movl %ebp, %eax
rolw $0x8, %ax
movw %ax, 0x2(%rsp)
testl %r15d, %r15d
je 0x7d1a
cmpl $0x100007f, %r15d       # imm = 0x100007F
je 0x7d1a
bswapl %r15d
movl %r15d, 0x4(%rsp)
testb %r14b, %r14b
je 0x7d1a
movq 0x5327(%rip), %r12      # 0xcfb8
leaq 0x2728(%rip), %rsi      # 0xa3c0
movl $0x15, %edx
movq %r12, %rdi
callq 0x21f0
movq (%r12), %rax
movq -0x18(%rax), %rax
movl 0x18(%r12,%rax), %ecx
andl $-0x4b, %ecx
orl $0x8, %ecx
movl %ecx, 0x18(%r12,%rax)
leaq 0x1713(%rip), %rsi      # 0x93d7
movl $0x2, %edx
movq %r12, %rdi
callq 0x21f0
movl %r15d, %esi
movq %r12, %rdi
callq 0x2130
movq %rax, %r15
movq (%rax), %rax
movq -0x18(%rax), %rcx
movl 0x18(%r15,%rcx), %edx
andl $-0x4b, %edx
orl $0x2, %edx
movl %edx, 0x18(%r15,%rcx)
movq -0x18(%rax), %rdi
addq %r15, %rdi
movl $0xa, %esi
callq 0x21b0
movsbl %al, %esi
movq %r15, %rdi
callq 0x2030
movq %rax, %rdi
callq 0x2140
movq %rsp, %rsi
movl %ebx, %edi
movl $0x10, %edx
callq 0x2060
testl %eax, %eax
je 0x7dca
callq 0x2040
movl (%rax), %ebx
cmpl $0x63, %ebx
je 0x7e5f
cmpl $0x62, %ebx
je 0x7e22
movq 0x529f(%rip), %r14      # 0xcff0
testl %ebx, %ebx
jne 0x7e85
leaq 0x2676(%rip), %rsi      # 0xa3d6
movl $0x15, %edx
jmp 0x7e80
callq 0x2040
movl (%rax), %ebx
movq 0x5278(%rip), %r14      # 0xcff0
leaq 0x2622(%rip), %rsi      # 0xa3a1
movl $0x1e, %edx
movq %r14, %rdi
callq 0x21f0
movq %r14, %rdi
movl %ebx, %esi
callq 0x22a0
movq %rax, %rbx
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x21b0
movsbl %al, %esi
movq %rbx, %rdi
callq 0x2030
movq %rax, %rdi
callq 0x2140
movl $0xffffffff, %ebx       # imm = 0xFFFFFFFF
jmp 0x7f1f
testb %r14b, %r14b
je 0x7f1f
movq 0x51de(%rip), %r14      # 0xcfb8
leaq 0x266e(%rip), %rsi      # 0xa44f
movl $0xc, %edx
movq %r14, %rdi
callq 0x21f0
movzwl %bp, %esi
movq %r14, %rdi
callq 0x2130
movq %rax, %r14
leaq 0x2659(%rip), %rsi      # 0xa45c
movl $0x9, %edx
movq %rax, %rdi
callq 0x21f0
movq %r14, %rdi
movl %ebx, %esi
callq 0x22a0
movq %rax, %r14
jmp 0x7ef8
movq 0x51c7(%rip), %rbx      # 0xcff0
leaq 0x25bc(%rip), %rsi      # 0xa3ec
movl $0x5, %edx
movq %rbx, %rdi
callq 0x21f0
movzwl %bp, %esi
movq %rbx, %rdi
callq 0x2130
movq %rax, %r14
leaq 0x25a0(%rip), %rsi      # 0xa3f2
movl $0x1c, %edx
movq %rax, %rdi
jmp 0x7eee
movl $0xffffffff, %ebx       # imm = 0xFFFFFFFF
testb %r14b, %r14b
je 0x7f1f
movq 0x517c(%rip), %r14      # 0xcff0
leaq 0x2594(%rip), %rsi      # 0xa40f
movl $0x1f, %edx
movq %r14, %rdi
jmp 0x7eee
leaq 0x25a3(%rip), %rsi      # 0xa42f
movl $0x1f, %edx
movq %r14, %rdi
callq 0x21f0
leaq 0x268c(%rip), %rsi      # 0xa52c
movl $0x6, %edx
movq %r14, %rdi
callq 0x21f0
movq %r14, %rdi
movl %ebx, %esi
callq 0x22a0
movq %rax, %r14
leaq 0x15cc(%rip), %rsi      # 0x948d
movl $0x1, %edx
movq %rax, %rdi
callq 0x21f0
movl %ebx, %edi
callq 0x20a0
testq %rax, %rax
je 0x7f2e
movq %rax, %rbx
movq %rax, %rdi
callq 0x20c0
movq %r14, %rdi
movq %rbx, %rsi
movq %rax, %rdx
callq 0x21f0
movl $0xffffffff, %ebx       # imm = 0xFFFFFFFF
movq (%r14), %rax
movq -0x18(%rax), %rdi
addq %r14, %rdi
movl $0xa, %esi
callq 0x21b0
movsbl %al, %esi
movq %r14, %rdi
callq 0x2030
movq %rax, %rdi
callq 0x2140
movl %ebx, %eax
addq $0x10, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq
movq (%r14), %rax
movq -0x18(%rax), %rax
movq %r14, %rdi
addq %rax, %rdi
movl 0x20(%r14,%rax), %esi
orl $0x1, %esi
callq 0x2290
jmp 0x7ef3