// File: /workspace/github_c_makefile_star2_O2/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 0x13aa
movq 0x8(%rbx), %r14
movq 0x10(%rbx), %rdi
callq 0x10d0
movl %eax, %r12d
movq 0x18(%rbx), %rdi
callq 0x10d0
movl %eax, %ebp
pushq $0x2
popq %rdi
movl %edi, %esi
xorl %edx, %edx
callq 0x10f0
movl %eax, %ebx
testl %eax, %eax
js 0x137d
movq %r14, %rdi
callq 0x1070
testq %rax, %rax
je 0x13c0
movq %rax, %r15
leaq 0x20(%rsp), %r14
andl $0x0, 0xc(%r14)
andq $0x0, 0x4(%r14)
movw $0x2, (%r14)
movzwl %r12w, %esi
rolw $0x8, %r12w
movw %r12w, 0x2(%r14)
leaq 0xdd4(%rip), %rdi       # 0x205a
xorl %eax, %eax
callq 0x1040
pushq $0x10
popq %rdx
movl %ebx, %edi
movq %r14, %rsi
callq 0x10a0
testl %eax, %eax
jne 0x13dd
leaq 0x14(%rsp), %r14
andl $0x0, 0x8(%r14)
andq $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
pushq $0x10
popq %r9
movl %ebx, %edi
movq %r14, %rsi
movq %rax, %rdx
xorl %ecx, %ecx
callq 0x1060
testl %eax, %eax
js 0x138e
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 0x139c
leaq 0xd43(%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 0xca6(%rip), %rdi       # 0x202a
callq 0x10c0
jmp 0x1248
leaq 0xceb(%rip), %rdi       # 0x2080
callq 0x10c0
jmp 0x132e
leaq 0xced(%rip), %rdi       # 0x2090
callq 0x10c0
jmp 0x1358
movq 0x2c47(%rip), %rax      # 0x3ff8
movq (%rax), %rdi
movq (%rbx), %rdx
leaq 0xc46(%rip), %rsi       # 0x2004
jmp 0x13d4
movq 0x2c31(%rip), %rax      # 0x3ff8
movq (%rax), %rdi
leaq 0xc6e(%rip), %rsi       # 0x203f
movq %r14, %rdx
xorl %eax, %eax
callq 0x1080
jmp 0x13e9
leaq 0xc86(%rip), %rdi       # 0x206a
callq 0x10c0
xorl %edi, %edi
callq 0x10e0