// File: /workspace/github_c_makefile_star2_O2/dropletzhu[P]msuite/udpserver.c
// Function: main
int main(int argc, char **argv) {
  int sockfd; /* socket */
  int portno; /* port to listen on */
  unsigned int clientlen; /* byte size of client's address */
  struct sockaddr_in serveraddr; /* server's addr */
  struct sockaddr_in clientaddr; /* client addr */
  char buf[BUFSIZE]; /* message buf */
  char *hostaddrp; /* dotted decimal host addr string */
  int optval; /* flag value for setsockopt */
  int n; /* message byte size */

  /* 
   * check command line arguments 
   */
  if (argc != 2) {
    fprintf(stderr, "usage: %s <port>\n", argv[0]);
    exit(1);
  }
  portno = atoi(argv[1]);

  /* 
   * socket: create the parent socket 
   */
  sockfd = socket(AF_INET, SOCK_DGRAM, 0);
  if (sockfd < 0) 
    error("ERROR opening socket");

  /* setsockopt: Handy debugging trick that lets 
   * us rerun the server immediately after we kill it; 
   * otherwise we have to wait about 20 secs. 
   * Eliminates "ERROR on binding: Address already in use" error. 
   */
  optval = 1;
  setsockopt(sockfd, SOL_SOCKET, SO_REUSEADDR, 
	     (const void *)&optval , sizeof(int));

  /*
   * build the server's Internet address
   */
  bzero((char *) &serveraddr, sizeof(serveraddr));
  serveraddr.sin_family = AF_INET;
  serveraddr.sin_addr.s_addr = htonl(INADDR_ANY);
  serveraddr.sin_port = htons((unsigned short)portno);

  /* 
   * bind: associate the parent socket with a port 
   */
  if (bind(sockfd, (struct sockaddr *) &serveraddr, 
	   sizeof(serveraddr)) < 0) 
    error("ERROR on binding");

  /* 
   * main loop: wait for a datagram, then echo it
   */
  clientlen = sizeof(clientaddr);
  while (1) {

    /*
     * recvfrom: receive a UDP datagram from a client
     */
    bzero(buf, BUFSIZE);
    n = recvfrom(sockfd, buf, BUFSIZE, 0,
		 (struct sockaddr *) &clientaddr, &clientlen);
    if (n < 0)
      error("ERROR in recvfrom");

    hostaddrp = inet_ntoa(clientaddr.sin_addr);
    if (hostaddrp == NULL)
      error("ERROR on inet_ntoa\n");
    printf("server received datagram from %s\n", hostaddrp);
    
    /* 
     * sendto: echo the input back to the client 
     */
    n = sendto(sockfd, buf, strlen(buf), 0, 
	       (struct sockaddr *) &clientaddr, clientlen);
    if (n < 0) 
      error("ERROR in sendto");
  }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x438, %rsp            # imm = 0x438
cmpl $0x2, %edi
jne 0x1247
movq 0x8(%rsi), %rdi
callq 0x10d0
movl %eax, %ebp
pushq $0x2
popq %rdi
movl %edi, %esi
xorl %edx, %edx
callq 0x10f0
testl %eax, %eax
jns 0x126a
leaq 0xdd4(%rip), %rdi       # 0x2016
callq 0x11fc
movq 0x2daa(%rip), %rax      # 0x3ff8
movq (%rax), %rdi
movq (%rsi), %rdx
leaq 0xda9(%rip), %rsi       # 0x2004
xorl %eax, %eax
callq 0x1090
pushq $0x1
popq %rdi
callq 0x10e0
movl %eax, %ebx
leaq 0xc(%rsp), %rcx
movl $0x1, (%rcx)
pushq $0x1
popq %rsi
pushq $0x2
popq %rdx
pushq $0x4
popq %r8
movl %eax, %edi
callq 0x1030
leaq 0x20(%rsp), %rsi
andq $0x0, 0x8(%rsi)
movw $0x2, (%rsi)
andl $0x0, 0x4(%rsi)
rolw $0x8, %bp
movw %bp, 0x2(%rsi)
pushq $0x10
popq %rdx
movl %ebx, %edi
callq 0x10b0
testl %eax, %eax
jns 0x12bd
leaq 0xd73(%rip), %rdi       # 0x202b
callq 0x11fc
leaq 0x8(%rsp), %r14
movl $0x10, (%r14)
leaq 0x30(%rsp), %r15
leaq 0x10(%rsp), %r12
leaq 0xd88(%rip), %r13       # 0x2062
movl $0x400, %edx            # imm = 0x400
movq %r15, %rdi
xorl %esi, %esi
callq 0x1070
movl $0x400, %edx            # imm = 0x400
movl %ebx, %edi
movq %r15, %rsi
xorl %ecx, %ecx
movq %r12, %r8
movq %r14, %r9
callq 0x10a0
testl %eax, %eax
js 0x134e
movl 0x14(%rsp), %edi
callq 0x1040
testq %rax, %rax
je 0x135a
movq %r13, %rdi
movq %rax, %rsi
xorl %eax, %eax
callq 0x1060
movq %r15, %rdi
callq 0x1050
movl 0x8(%rsp), %r9d
movl %ebx, %edi
movq %r15, %rsi
movq %rax, %rdx
xorl %ecx, %ecx
movq %r12, %r8
callq 0x1080
testl %eax, %eax
jns 0x12da
leaq 0xd3b(%rip), %rdi       # 0x2084
callq 0x11fc
leaq 0xce7(%rip), %rdi       # 0x203c
callq 0x11fc
leaq 0xced(%rip), %rdi       # 0x204e
callq 0x11fc