// File: /workspace/github_c_makefile_star2_O0/dropletzhu[P]msuite/tcpclient.c
// Function: main
int main(int argc, char *argv[])
{
    int sockfd;
    struct sockaddr_in their_addr;
	struct in_addr server_ip;
	int port;
	char ch;
	int retcode;
	int long_lived = 0;

    if (argc < 2) {
        usage();
        return -1;
    }

    while ((ch = getopt (argc, argv, "s:p:l")) != -1) {
        switch (ch) {
		case 's':
			retcode = inet_aton(optarg, &server_ip);
			if (retcode == 0) {
				printf("wrong address format\n");
				return -1;
			}
        case 'p':
            port = atoi(optarg);
            break;
        case 'l':
            long_lived = 1;
            break;
        default:
            usage();
            return -1;
        }
    }

    if((sockfd = socket(AF_INET, SOCK_STREAM, 0)) == -1) {
        perror("socket()");
        exit(-1);
    }

    their_addr.sin_family = AF_INET;
    their_addr.sin_port = htons(port);
    their_addr.sin_addr.s_addr = server_ip.s_addr;
    memset(&(their_addr.sin_zero), '\0', 8);

    if(connect(sockfd, (struct sockaddr *)&their_addr, sizeof(struct sockaddr)) == -1) {
        perror("connect()");
        exit(-1);
    }

	if (long_lived) {
		long_lived_connection(sockfd);
	} else {
		short_lived_connection(sockfd);
	}
 
    close(sockfd);
    return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x40, %rsp
movl $0x0, -0x4(%rbp)
movl %edi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movl $0x0, -0x38(%rbp)
cmpl $0x2, -0x8(%rbp)
jge 0x1364
callq 0x12f0
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x14c6
jmp 0x1366
movl -0x8(%rbp), %edi
movq -0x10(%rbp), %rsi
leaq 0xd59(%rip), %rdx       # 0x20cd
callq 0x10b0
movb %al, -0x2d(%rbp)
movsbl %al, %eax
cmpl $-0x1, %eax
je 0x1415
movsbl -0x2d(%rbp), %eax
movl %eax, -0x3c(%rbp)
subl $0x6c, %eax
je 0x13f6
jmp 0x1396
movl -0x3c(%rbp), %eax
subl $0x70, %eax
je 0x13e2
jmp 0x13a0
movl -0x3c(%rbp), %eax
subl $0x73, %eax
jne 0x13ff
jmp 0x13aa
movq 0x2c2f(%rip), %rax      # 0x3fe0
movq (%rax), %rdi
leaq -0x28(%rbp), %rsi
callq 0x1090
movl %eax, -0x34(%rbp)
cmpl $0x0, -0x34(%rbp)
jne 0x13e0
leaq 0xd06(%rip), %rdi       # 0x20d3
movb $0x0, %al
callq 0x1060
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x14c6
jmp 0x13e2
movq 0x2bf7(%rip), %rax      # 0x3fe0
movq (%rax), %rdi
callq 0x10c0
movl %eax, -0x2c(%rbp)
jmp 0x1410
movl $0x1, -0x38(%rbp)
jmp 0x1410
callq 0x12f0
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x14c6
jmp 0x1366
movl $0x2, %edi
movl $0x1, %esi
xorl %edx, %edx
callq 0x10f0
movl %eax, -0x14(%rbp)
cmpl $-0x1, %eax
jne 0x1444
leaq 0xcb4(%rip), %rdi       # 0x20e9
callq 0x10a0
movl $0xffffffff, %edi       # imm = 0xFFFFFFFF
callq 0x10d0
movw $0x2, -0x24(%rbp)
movl -0x2c(%rbp), %eax
movzwl %ax, %edi
callq 0x1040
movw %ax, -0x22(%rbp)
movl -0x28(%rbp), %eax
movl %eax, -0x20(%rbp)
leaq -0x24(%rbp), %rdi
addq $0x8, %rdi
xorl %esi, %esi
movl $0x8, %edx
callq 0x1070
movl -0x14(%rbp), %edi
leaq -0x24(%rbp), %rsi
movl $0x10, %edx
callq 0x10e0
cmpl $-0x1, %eax
jne 0x149f
leaq 0xc62(%rip), %rdi       # 0x20f2
callq 0x10a0
movl $0xffffffff, %edi       # imm = 0xFFFFFFFF
callq 0x10d0
cmpl $0x0, -0x38(%rbp)
je 0x14af
movl -0x14(%rbp), %edi
callq 0x1290
jmp 0x14b7
movl -0x14(%rbp), %edi
callq 0x1200
movl -0x14(%rbp), %edi
callq 0x1080
movl $0x0, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x40, %rsp
popq %rbp
retq