// File: /workspace/github_cpp_makefile_star2_O3/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 0x7ccb
movl %eax, %ebx
movq $0x0, 0x8(%rsp)
movw $0x2, (%rsp)
movl $0x0, 0x4(%rsp)
movl %ebp, %eax
rolw $0x8, %ax
movw %ax, 0x2(%rsp)
testl %r15d, %r15d
je 0x7c7b
cmpl $0x100007f, %r15d       # imm = 0x100007F
jne 0x7d2b
movq %rsp, %rsi
movl %ebx, %edi
movl $0x10, %edx
callq 0x2060
testl %eax, %eax
je 0x7de5
callq 0x2040
movl (%rax), %ebx
cmpl $0x63, %ebx
je 0x7e96
cmpl $0x62, %ebx
je 0x7e59
movq 0x533e(%rip), %r14      # 0xcff0
testl %ebx, %ebx
jne 0x7ebc
leaq 0x2715(%rip), %rsi      # 0xa3d6
movl $0x15, %edx
jmp 0x7eb7
callq 0x2040
movl (%rax), %ebx
movq 0x5317(%rip), %r14      # 0xcff0
leaq 0x26c1(%rip), %rsi      # 0xa3a1
movl $0x1e, %edx
movq %r14, %rdi
callq 0x21f0
movq %r14, %rdi
movl %ebx, %esi
callq 0x2290
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 0x7f56
bswapl %r15d
movl %r15d, 0x4(%rsp)
testb %r14b, %r14b
je 0x7e3d
movq 0x5275(%rip), %r12      # 0xcfb8
leaq 0x2676(%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 0x1658(%rip), %rsi      # 0x93ce
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
jne 0x7c92
jmp 0x7dee
testb %r14b, %r14b
je 0x7f56
movq 0x51c3(%rip), %r14      # 0xcfb8
leaq 0x2653(%rip), %rsi      # 0xa44f
movl $0xc, %edx
movq %r14, %rdi
callq 0x21f0
movzwl %bp, %esi
movq %r14, %rdi
callq 0x2130
movq %rax, %r14
leaq 0x263e(%rip), %rsi      # 0xa45c
movl $0x9, %edx
movq %rax, %rdi
callq 0x21f0
movq %r14, %rdi
movl %ebx, %esi
callq 0x2290
movq %rax, %r14
jmp 0x7f2f
movq %rsp, %rsi
movl %ebx, %edi
movl $0x10, %edx
callq 0x2060
testl %eax, %eax
jne 0x7c92
jmp 0x7f56
movq 0x5190(%rip), %rbx      # 0xcff0
leaq 0x2585(%rip), %rsi      # 0xa3ec
movl $0x5, %edx
movq %rbx, %rdi
callq 0x21f0
movzwl %bp, %esi
movq %rbx, %rdi
callq 0x2130
movq %rax, %r14
leaq 0x2569(%rip), %rsi      # 0xa3f2
movl $0x1c, %edx
movq %rax, %rdi
jmp 0x7f25
movl $0xffffffff, %ebx       # imm = 0xFFFFFFFF
testb %r14b, %r14b
je 0x7f56
movq 0x5145(%rip), %r14      # 0xcff0
leaq 0x255d(%rip), %rsi      # 0xa40f
movl $0x1f, %edx
movq %r14, %rdi
jmp 0x7f25
leaq 0x256c(%rip), %rsi      # 0xa42f
movl $0x1f, %edx
movq %r14, %rdi
callq 0x21f0
leaq 0x2655(%rip), %rsi      # 0xa52c
movl $0x6, %edx
movq %r14, %rdi
callq 0x21f0
movq %r14, %rdi
movl %ebx, %esi
callq 0x2290
movq %rax, %r14
leaq 0x158d(%rip), %rsi      # 0x9485
movl $0x1, %edx
movq %rax, %rdi
callq 0x21f0
movl %ebx, %edi
callq 0x20a0
testq %rax, %rax
je 0x7f65
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 0x2280
jmp 0x7f2a