// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x460, %rsp            # imm = 0x460
movl $0x0, -0x4(%rbp)
movl %edi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
cmpl $0x2, -0x8(%rbp)
je 0x1288
movq 0x2d92(%rip), %rax      # 0x3ff8
movq (%rax), %rdi
movq -0x10(%rbp), %rax
movq (%rax), %rdx
leaq 0xd8d(%rip), %rsi       # 0x2004
movb $0x0, %al
callq 0x10b0
movl $0x1, %edi
callq 0x1100
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rdi
callq 0x10f0
movl %eax, -0x18(%rbp)
movl $0x2, %esi
xorl %edx, %edx
movl %esi, %edi
callq 0x1110
movl %eax, -0x14(%rbp)
cmpl $0x0, -0x14(%rbp)
jge 0x12bb
leaq 0xd60(%rip), %rdi       # 0x2016
callq 0x1220
movl $0x1, -0x44c(%rbp)
movl -0x14(%rbp), %edi
movl $0x1, %esi
movl $0x2, %edx
leaq -0x44c(%rbp), %rcx
movl $0x4, %r8d
callq 0x1030
leaq -0x2c(%rbp), %rdi
xorl %esi, %esi
movl $0x10, %edx
callq 0x1090
movw $0x2, -0x2c(%rbp)
xorl %edi, %edi
callq 0x1080
movl %eax, -0x28(%rbp)
movl -0x18(%rbp), %eax
movzwl %ax, %edi
callq 0x1060
movw %ax, -0x2a(%rbp)
movl -0x14(%rbp), %edi
leaq -0x2c(%rbp), %rsi
movl $0x10, %edx
callq 0x10d0
cmpl $0x0, %eax
jge 0x1335
leaq 0xcfb(%rip), %rdi       # 0x202b
callq 0x1220
movl $0x10, -0x1c(%rbp)
leaq -0x440(%rbp), %rdi
xorl %esi, %esi
movl $0x400, %edx            # imm = 0x400
callq 0x1090
movl -0x14(%rbp), %edi
leaq -0x440(%rbp), %rsi
movl $0x400, %edx            # imm = 0x400
xorl %ecx, %ecx
leaq -0x3c(%rbp), %r8
leaq -0x1c(%rbp), %r9
callq 0x10c0
movl %eax, -0x450(%rbp)
cmpl $0x0, -0x450(%rbp)
jge 0x1388
leaq 0xcb9(%rip), %rdi       # 0x203c
callq 0x1220
movl -0x38(%rbp), %edi
callq 0x1040
movq %rax, -0x448(%rbp)
cmpq $0x0, -0x448(%rbp)
jne 0x13ad
leaq 0xca6(%rip), %rdi       # 0x204e
callq 0x1220
movq -0x448(%rbp), %rsi
leaq 0xca7(%rip), %rdi       # 0x2062
movb $0x0, %al
callq 0x1070
movl -0x14(%rbp), %eax
movl %eax, -0x45c(%rbp)
leaq -0x440(%rbp), %rax
movq %rax, -0x458(%rbp)
leaq -0x440(%rbp), %rdi
callq 0x1050
movl -0x45c(%rbp), %edi
movq -0x458(%rbp), %rsi
movq %rax, %rdx
movl -0x1c(%rbp), %r9d
xorl %ecx, %ecx
leaq -0x3c(%rbp), %r8
callq 0x10a0
movl %eax, -0x450(%rbp)
cmpl $0x0, -0x450(%rbp)
jge 0x141f
leaq 0xc6a(%rip), %rdi       # 0x2084
callq 0x1220
jmp 0x133c