// File: /workspace/github_c_makefile_star2_O0/dropletzhu[P]msuite/udpclient.c
// Function: main
int main(int argc, char **argv) {
    int sockfd, sport, dport, n, retcode;
    socklen_t serverlen;
    struct sockaddr_in serveraddr;
    struct sockaddr_in cliaddr;
    struct hostent *server;
    char *hostname;
    char buf[BUFSIZE];

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

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

    /* gethostbyname: get the server's DNS entry */
    server = gethostbyname(hostname);
    if (server == NULL) {
        fprintf(stderr,"ERROR, no such host as %s\n", hostname);
        exit(0);
    }

    bzero((char *) &cliaddr, sizeof(cliaddr));
    cliaddr.sin_family = AF_INET;
    cliaddr.sin_port = htons(sport);
    printf("source port %d\n",ntohs(cliaddr.sin_port));
    retcode = bind(sockfd,(struct sockaddr*)&cliaddr, sizeof(cliaddr));
    if (retcode != 0 ) {
        perror("ERROR bind");
        exit(0);
    }

    /* build the server's Internet address */
    bzero((char *) &serveraddr, sizeof(serveraddr));
    serveraddr.sin_family = AF_INET;
    bcopy((char *)server->h_addr, 
	  (char *)&serveraddr.sin_addr.s_addr, server->h_length);
    serveraddr.sin_port = htons(dport);

    /* get a message from the user */
    bzero(buf, BUFSIZE);
    snprintf(buf, BUFSIZE, "Udpclient\n");

    /* send the message to the server */
    serverlen = sizeof(serveraddr);
    n = sendto(sockfd, buf, strlen(buf), 0, (struct sockaddr*)&serveraddr, serverlen);
    if (n < 0) 
      perror("ERROR in sendto");
    
    /* print the server's reply */
    n = recvfrom(sockfd, buf, strlen(buf), 0, (struct sockaddr*)&serveraddr, &serverlen);
    if (n < 0) 
      perror("ERROR in recvfrom");
    printf("Echo from server: %s", buf);
    return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x480, %rsp            # imm = 0x480
movl $0x0, -0x4(%rbp)
movl %edi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
cmpl $0x4, -0x8(%rbp)
je 0x1275
movq 0x2da2(%rip), %rax      # 0x3ff8
movq (%rax), %rdi
movq -0x10(%rbp), %rax
movq (%rax), %rdx
leaq 0xd9d(%rip), %rsi       # 0x2004
movb $0x0, %al
callq 0x10a0
xorl %edi, %edi
callq 0x1110
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rax
movq %rax, -0x58(%rbp)
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rdi
callq 0x1100
movl %eax, -0x18(%rbp)
movq -0x10(%rbp), %rax
movq 0x18(%rax), %rdi
callq 0x1100
movl %eax, -0x1c(%rbp)
movl $0x2, %esi
xorl %edx, %edx
movl %esi, %edi
callq 0x1120
movl %eax, -0x14(%rbp)
cmpl $0x0, -0x14(%rbp)
jge 0x12c4
leaq 0xd6b(%rip), %rdi       # 0x202a
callq 0x10f0
movq -0x58(%rbp), %rdi
callq 0x1090
movq %rax, -0x50(%rbp)
cmpq $0x0, -0x50(%rbp)
jne 0x12fb
movq 0x2d19(%rip), %rax      # 0x3ff8
movq (%rax), %rdi
movq -0x58(%rbp), %rdx
leaq 0xd52(%rip), %rsi       # 0x203f
movb $0x0, %al
callq 0x10a0
xorl %edi, %edi
callq 0x1110
leaq -0x48(%rbp), %rdi
xorl %esi, %esi
movl $0x10, %edx
callq 0x1070
movw $0x2, -0x48(%rbp)
movl -0x18(%rbp), %eax
movzwl %ax, %edi
callq 0x1040
movw %ax, -0x46(%rbp)
movzwl -0x46(%rbp), %edi
callq 0x10c0
movzwl %ax, %esi
leaq 0xd27(%rip), %rdi       # 0x205a
movb $0x0, %al
callq 0x1050
movl -0x14(%rbp), %edi
leaq -0x48(%rbp), %rsi
movl $0x10, %edx
callq 0x10d0
movl %eax, -0x24(%rbp)
cmpl $0x0, -0x24(%rbp)
je 0x1367
leaq 0xd0f(%rip), %rdi       # 0x206a
callq 0x10f0
xorl %edi, %edi
callq 0x1110
leaq -0x38(%rbp), %rdi
xorl %esi, %esi
movl $0x10, %edx
callq 0x1070
movw $0x2, -0x38(%rbp)
movq -0x50(%rbp), %rax
movq 0x18(%rax), %rax
movq (%rax), %rsi
leaq -0x38(%rbp), %rdi
addq $0x4, %rdi
movq -0x50(%rbp), %rax
movslq 0x14(%rax), %rdx
callq 0x10e0
movl -0x1c(%rbp), %eax
movzwl %ax, %edi
callq 0x1040
movw %ax, -0x36(%rbp)
leaq -0x460(%rbp), %rdi
xorl %esi, %esi
movl $0x400, %edx            # imm = 0x400
callq 0x1070
leaq -0x460(%rbp), %rdi
movl $0x400, %esi            # imm = 0x400
leaq 0xca3(%rip), %rdx       # 0x2075
movb $0x0, %al
callq 0x1060
movl $0x10, -0x28(%rbp)
movl -0x14(%rbp), %eax
movl %eax, -0x46c(%rbp)
leaq -0x460(%rbp), %rax
movq %rax, -0x468(%rbp)
leaq -0x460(%rbp), %rdi
callq 0x1030
movl -0x46c(%rbp), %edi
movq -0x468(%rbp), %rsi
movq %rax, %rdx
movl -0x28(%rbp), %r9d
xorl %ecx, %ecx
leaq -0x38(%rbp), %r8
callq 0x1080
movl %eax, -0x20(%rbp)
cmpl $0x0, -0x20(%rbp)
jge 0x1437
leaq 0xc4e(%rip), %rdi       # 0x2080
callq 0x10f0
movl -0x14(%rbp), %eax
movl %eax, -0x47c(%rbp)
leaq -0x460(%rbp), %rax
movq %rax, -0x478(%rbp)
leaq -0x460(%rbp), %rdi
callq 0x1030
movl -0x47c(%rbp), %edi
movq -0x478(%rbp), %rsi
movq %rax, %rdx
xorl %ecx, %ecx
leaq -0x38(%rbp), %r8
leaq -0x28(%rbp), %r9
callq 0x10b0
movl %eax, -0x20(%rbp)
cmpl $0x0, -0x20(%rbp)
jge 0x148e
leaq 0xc07(%rip), %rdi       # 0x2090
callq 0x10f0
leaq -0x460(%rbp), %rsi
leaq 0xc06(%rip), %rdi       # 0x20a2
movb $0x0, %al
callq 0x1050
xorl %eax, %eax
addq $0x480, %rsp            # imm = 0x480
popq %rbp
retq