// File: /workspace/github_cpp_makefile_star2_O2/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 %rbx
subq $0x18, %rsp
movl %edx, %r14d
movl %esi, %r15d
movl %edi, %ebp
pushq $0x2
popq %rdi
pushq $0x11
popq %rdx
movl %edi, %esi
callq 0x2080
cmpl $-0x1, %eax
je 0x68fc
movl %eax, %ebx
andq $0x0, 0x10(%rsp)
movw $0x2, 0x8(%rsp)
andl $0x0, 0xc(%rsp)
movl %ebp, %eax
rolw $0x8, %ax
movw %ax, 0xa(%rsp)
testl %r15d, %r15d
je 0x68b5
cmpl $0x100007f, %r15d       # imm = 0x100007F
je 0x68b5
bswapl %r15d
movl %r15d, 0xc(%rsp)
testb %r14b, %r14b
je 0x68b5
movq 0x475b(%rip), %rdi      # 0xafb8
leaq 0x1b5c(%rip), %rsi      # 0x83c0
callq 0x21d0
movq (%rax), %rcx
movq -0x18(%rcx), %rcx
movl 0x18(%rax,%rcx), %edx
andl $-0x4b, %edx
orl $0x8, %edx
movl %edx, 0x18(%rax,%rcx)
leaq 0xb49(%rip), %rsi       # 0x73ce
movq %rax, %rdi
callq 0x21d0
movl %r15d, %esi
movq %rax, %rdi
callq 0x2130
movq (%rax), %rcx
movq -0x18(%rcx), %rcx
movl 0x18(%rax,%rcx), %edx
andl $-0x4b, %edx
orl $0x2, %edx
movl %edx, 0x18(%rax,%rcx)
movq %rax, %rdi
callq 0x20c0
leaq 0x8(%rsp), %rsi
pushq $0x10
popq %rdx
movl %ebx, %edi
callq 0x2050
testl %eax, %eax
je 0x6930
callq 0x67e9
cmpl $0x63, %eax
je 0x6998
movl %eax, %ebx
movq 0x4711(%rip), %rdi      # 0xaff0
cmpl $0x62, %eax
je 0x6975
testl %ebx, %ebx
jne 0x69ad
leaq 0x1adf(%rip), %rsi      # 0x83d6
jmp 0x69f1
callq 0x67e9
movl %eax, %ebx
movq 0x46e6(%rip), %rdi      # 0xaff0
leaq 0x1a90(%rip), %rsi      # 0x83a1
callq 0x21d0
movq %rax, %rdi
movl %ebx, %esi
callq 0x22a0
movq %rax, %rdi
callq 0x20c0
pushq $-0x1
popq %rbx
jmp 0x6a01
testb %r14b, %r14b
je 0x6a01
movq 0x4678(%rip), %rdi      # 0xafb8
leaq 0x1b08(%rip), %rsi      # 0x844f
callq 0x21d0
movzwl %bp, %esi
movq %rax, %rdi
callq 0x2290
leaq 0x1afe(%rip), %rsi      # 0x845c
movq %rax, %rdi
callq 0x21d0
movq %rax, %rdi
movl %ebx, %esi
callq 0x22a0
jmp 0x69f9
leaq 0x1a70(%rip), %rsi      # 0x83ec
callq 0x21d0
movzwl %bp, %esi
movq %rax, %rdi
callq 0x2290
leaq 0x1a5f(%rip), %rsi      # 0x83f2
movq %rax, %rdi
jmp 0x69f1
testb %r14b, %r14b
je 0x6928
movq 0x464c(%rip), %rdi      # 0xaff0
leaq 0x1a64(%rip), %rsi      # 0x840f
jmp 0x69f1
leaq 0x1a7b(%rip), %rsi      # 0x842f
callq 0x21d0
leaq 0x1b6c(%rip), %rsi      # 0x852c
movq %rax, %rdi
callq 0x21d0
movq %rax, %rdi
movl %ebx, %esi
callq 0x22a0
leaq 0xaac(%rip), %rsi       # 0x7485
movq %rax, %rdi
callq 0x21d0
movq %rax, %r14
movl %ebx, %edi
callq 0x2090
movq %r14, %rdi
movq %rax, %rsi
callq 0x21d0
pushq $-0x1
popq %rbx
movq %rax, %rdi
callq 0x20c0
movl %ebx, %eax
addq $0x18, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
retq