// File: /workspace/github_c_makefile_star2_O3/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
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
subq $0x430, %rsp            # imm = 0x430
movq %rsi, %rbx
cmpl $0x4, %edi
jne 0x1423
movq 0x8(%rbx), %r12
movq 0x10(%rbx), %rdi
callq 0x10d0
movl %eax, %r14d
movq 0x18(%rbx), %rdi
callq 0x10d0
movl %eax, %ebp
movl $0x2, %edi
movl $0x2, %esi
xorl %edx, %edx
callq 0x10f0
movl %eax, %ebx
testl %eax, %eax
js 0x13f6
movq %r12, %rdi
callq 0x1070
testq %rax, %rax
je 0x142b
movq %rax, %r15
leaq 0x20(%rsp), %r12
movl $0x0, 0xc(%r12)
movq $0x0, 0x4(%r12)
movw $0x2, (%r12)
movzwl %r14w, %esi
rolw $0x8, %r14w
movw %r14w, 0x2(%r12)
leaq 0xd65(%rip), %rdi       # 0x205a
xorl %eax, %eax
callq 0x1040
movl %ebx, %edi
movq %r12, %rsi
movl $0x10, %edx
callq 0x10a0
testl %eax, %eax
jne 0x1433
leaq 0x14(%rsp), %r14
movl $0x0, 0x8(%r14)
movq $0x0, (%r14)
movw $0x2, -0x4(%r14)
movq 0x18(%r15), %rax
movq (%rax), %rsi
movslq 0x14(%r15), %rdx
movq %r14, %rdi
callq 0x10b0
rolw $0x8, %bp
movw %bp, -0x2(%r14)
leaq 0x3b(%rsp), %r14
movl $0x3f5, %edx            # imm = 0x3F5
movq %r14, %rdi
xorl %esi, %esi
callq 0x1050
movabsq $0x6e65696c63706455, %rax # imm = 0x6E65696C63706455
movq %rax, -0xb(%r14)
movl $0xa746e, -0x4(%r14)    # imm = 0xA746E
movl $0x10, 0xc(%rsp)
leaq 0x30(%rsp), %r14
movq %r14, %rdi
callq 0x1030
leaq 0x10(%rsp), %r8
movl %ebx, %edi
movq %r14, %rsi
movq %rax, %rdx
xorl %ecx, %ecx
movl $0x10, %r9d
callq 0x1060
testl %eax, %eax
js 0x1407
leaq 0x30(%rsp), %r14
movq %r14, %rdi
callq 0x1030
leaq 0x10(%rsp), %r8
leaq 0xc(%rsp), %r9
movl %ebx, %edi
movq %r14, %rsi
movq %rax, %rdx
xorl %ecx, %ecx
callq 0x1090
testl %eax, %eax
js 0x1415
leaq 0xcca(%rip), %rdi       # 0x20a2
leaq 0x30(%rsp), %rsi
xorl %eax, %eax
callq 0x1040
xorl %eax, %eax
addq $0x430, %rsp            # imm = 0x430
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq
leaq 0xc2d(%rip), %rdi       # 0x202a
callq 0x10c0
jmp 0x12ad
leaq 0xc72(%rip), %rdi       # 0x2080
callq 0x10c0
jmp 0x13a7
leaq 0xc74(%rip), %rdi       # 0x2090
callq 0x10c0
jmp 0x13d1
movq %rbx, %rdi
callq 0x1110
movq %r12, %rdi
callq 0x114a
callq 0x1136