// File: /workspace/github_c_makefile_star2_O1/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 0x124e
movq 0x8(%rsi), %rdi
callq 0x10d0
movl %eax, %ebp
movl $0x2, %edi
movl $0x2, %esi
xorl %edx, %edx
callq 0x10f0
testl %eax, %eax
jns 0x126e
leaq 0xdcd(%rip), %rdi       # 0x2016
jmp 0x136b
movq 0x2da3(%rip), %rax      # 0x3ff8
movq (%rax), %rdi
movq (%rsi), %rdx
leaq 0xda2(%rip), %rsi       # 0x2004
xorl %eax, %eax
callq 0x1090
jmp 0x1370
movl %eax, %ebx
leaq 0xc(%rsp), %rcx
movl $0x1, (%rcx)
movl %eax, %edi
movl $0x1, %esi
movl $0x2, %edx
movl $0x4, %r8d
callq 0x1030
xorps %xmm0, %xmm0
leaq 0x20(%rsp), %rsi
movaps %xmm0, (%rsi)
movw $0x2, (%rsi)
movl $0x0, 0x4(%rsi)
rolw $0x8, %bp
movw %bp, 0x2(%rsi)
movl %ebx, %edi
movl $0x10, %edx
callq 0x10b0
testl %eax, %eax
jns 0x12cd
leaq 0xd63(%rip), %rdi       # 0x202b
jmp 0x136b
leaq 0x8(%rsp), %r14
movl $0x10, (%r14)
leaq 0x30(%rsp), %r15
leaq 0x10(%rsp), %r12
leaq 0xd78(%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 0x135b
movl 0x14(%rsp), %edi
callq 0x1040
testq %rax, %rax
je 0x1364
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 0x12ea
leaq 0xd2b(%rip), %rdi       # 0x2084
jmp 0x136b
leaq 0xcda(%rip), %rdi       # 0x203c
jmp 0x136b
leaq 0xce3(%rip), %rdi       # 0x204e
callq 0x10c0
movl $0x1, %edi
callq 0x10e0