// File: /workspace/github_cpp_makefile_star2_O3/gty980218[P]ee450/client.cpp
// Function: main
int main(int argc,char* argv[]) {
	int sock;
	if((sock = socket(PF_INET, SOCK_STREAM, IPPROTO_TCP)) < 0){
        fprintf(stderr,"Create TCP socket failed!\n");
        exit(1);
    }

	struct sockaddr_in servaddr;
	memset(&servaddr, 0, sizeof(servaddr));
	servaddr.sin_family = AF_INET;
	servaddr.sin_port = htons(34188); 
	servaddr.sin_addr.s_addr = inet_addr("127.0.0.1");
	
	if(connect(sock, (struct sockaddr*)&servaddr, sizeof(servaddr)) < 0){
        fprintf(stderr,"Connetc failed!");
        exit(1);
    }
	
	cout<<"The client is up and running"<<endl;

	char sendbuf[1024] = {0};
	char recvbuf[1024] = {0};
	string str=argv[1];
	strcpy(sendbuf,str.c_str());
	write(sock, sendbuf, strlen(sendbuf));
	cout<<"The client has sent query to Scheduler using TCP: client location "<<str<<endl;

	read(sock, recvbuf, sizeof(recvbuf));
	string response=recvbuf;
	if(response.compare("NF")==0){
		cout<<"Location "<<str<<" not found"<<endl;
	}else if(response.compare("N")==0){
		cout<<"Score = None, No assignment"<<endl;
	}else if(response.compare("OL")==0){
		cout<<"All hospitals are unavailable due to overload"<<endl;
	}else{
		cout<<"The client has received results from the Scheduler: assigned to Hospital "<<recvbuf<<endl;
	}
	close(sock);
	
	return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
subq $0x850, %rsp            # imm = 0x850
movq %rsi, %r14
movl $0x2, %edi
movl $0x1, %esi
movl $0x6, %edx
callq 0x1040
testl %eax, %eax
js 0x162c
movl %eax, %ebx
leaq -0x70(%rbp), %r15
movq $0x0, 0x8(%r15)
movl $0x8c850002, (%r15)     # imm = 0x8C850002
leaq 0xca6(%rip), %rdi       # 0x201f
callq 0x1100
movl %eax, 0x4(%r15)
movl %ebx, %edi
movq %r15, %rsi
movl $0x10, %edx
callq 0x10c0
testl %eax, %eax
js 0x1631
movq 0x2c30(%rip), %r15      # 0x3fd0
leaq 0xc92(%rip), %rsi       # 0x2039
movl $0x1c, %edx
movq %r15, %rdi
callq 0x1120
movq (%r15), %rax
movq -0x18(%rax), %rdi
addq %r15, %rdi
movl $0xa, %esi
callq 0x10f0
movsbl %al, %esi
movq %r15, %rdi
callq 0x1030
movq %rax, %rdi
callq 0x1090
leaq -0x870(%rbp), %r15
movl $0x400, %edx            # imm = 0x400
movq %r15, %rdi
xorl %esi, %esi
callq 0x1080
leaq -0x470(%rbp), %rdi
movl $0x400, %edx            # imm = 0x400
xorl %esi, %esi
callq 0x1080
movq 0x8(%r14), %rsi
leaq -0x60(%rbp), %r14
leaq -0x40(%rbp), %rdx
movq %r14, %rdi
callq 0x1676
movq (%r14), %rsi
movq %r15, %rdi
callq 0x10e0
movq %r15, %rdi
callq 0x1070
movl %ebx, %edi
movq %r15, %rsi
movq %rax, %rdx
callq 0x1060
movq 0x2b91(%rip), %rdi      # 0x3fd0
leaq 0xc10(%rip), %rsi       # 0x2056
movl $0x42, %edx
callq 0x1120
movq -0x60(%rbp), %rsi
movq -0x58(%rbp), %rdx
movq 0x2b71(%rip), %rdi      # 0x3fd0
callq 0x1120
movq %rax, %r14
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %r14, %rdi
movl $0xa, %esi
callq 0x10f0
movsbl %al, %esi
movq %r14, %rdi
callq 0x1030
movq %rax, %rdi
callq 0x1090
leaq -0x470(%rbp), %rsi
movl $0x400, %edx            # imm = 0x400
movl %ebx, %edi
callq 0x1140
leaq -0x30(%rbp), %r12
movq %r12, -0x10(%r12)
leaq -0x470(%rbp), %r14
movq %r14, %rdi
callq 0x1070
leaq (%rax,%rbp), %rdx
addq $-0x470, %rdx           # imm = 0xFB90
leaq -0x40(%rbp), %rdi
movq %r14, %rsi
callq 0x16b4
leaq 0xbc2(%rip), %rsi       # 0x2099
leaq -0x40(%rbp), %rdi
callq 0x1050
testl %eax, %eax
je 0x1539
leaq 0xbc6(%rip), %rsi       # 0x20b1
leaq -0x40(%rbp), %rdi
callq 0x1050
testl %eax, %eax
je 0x1592
leaq 0xbcc(%rip), %rsi       # 0x20cf
leaq -0x40(%rbp), %rdi
callq 0x1050
testl %eax, %eax
je 0x15a0
movq 0x2ab5(%rip), %rdi      # 0x3fd0
leaq 0xbde(%rip), %rsi       # 0x2100
movl $0x49, %edx
callq 0x1120
movq %r14, %rdi
callq 0x1070
movq %rax, %rdx
jmp 0x15ac
movq 0x2a90(%rip), %rdi      # 0x3fd0
leaq 0xb55(%rip), %rsi       # 0x209c
movl $0x9, %edx
callq 0x1120
movq -0x60(%rbp), %rsi
movq -0x58(%rbp), %rdx
movq 0x2a70(%rip), %rdi      # 0x3fd0
callq 0x1120
movq %rax, %r15
leaq 0xb37(%rip), %rsi       # 0x20a6
movl $0xa, %edx
movq %rax, %rdi
callq 0x1120
movq (%r15), %rax
movq -0x18(%rax), %rdi
addq %r15, %rdi
movl $0xa, %esi
callq 0x10f0
jmp 0x15d2
movl $0x1b, %edx
leaq 0xb15(%rip), %r14       # 0x20b3
jmp 0x15ac
movl $0x2d, %edx
leaq 0xb26(%rip), %r14       # 0x20d2
movq 0x2a1d(%rip), %r15      # 0x3fd0
movq %r15, %rdi
movq %r14, %rsi
callq 0x1120
movq (%r15), %rax
movq -0x18(%rax), %rdi
addq %r15, %rdi
movl $0xa, %esi
callq 0x10f0
movsbl %al, %esi
movq %r15, %rdi
callq 0x1030
movq %rax, %rdi
callq 0x1090
movl %ebx, %edi
callq 0x1190
movq -0x40(%rbp), %rdi
cmpq %r12, %rdi
je 0x1601
movq -0x30(%rbp), %rsi
incq %rsi
callq 0x1110
leaq -0x50(%rbp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x161a
movq -0x50(%rbp), %rsi
incq %rsi
callq 0x1110
xorl %eax, %eax
addq $0x850, %rsp            # imm = 0x850
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq
callq 0x11d8
callq 0x11b0
jmp 0x1652
movq %rax, %rbx
movq -0x40(%rbp), %rdi
cmpq %r12, %rdi
je 0x1655
movq -0x30(%rbp), %rsi
incq %rsi
callq 0x1110
jmp 0x1655
movq %rax, %rbx
leaq -0x50(%rbp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x166e
movq -0x50(%rbp), %rsi
incq %rsi
callq 0x1110
movq %rbx, %rdi
callq 0x1160