// File: /workspace/github_cpp_makefile_star2_O2/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 %rbx
subq $0x858, %rsp            # imm = 0x858
movq %rsi, %r14
pushq $0x2
popq %rdi
pushq $0x1
popq %rsi
pushq $0x6
popq %rdx
callq 0x1030
testl %eax, %eax
js 0x14c3
movl %eax, %ebx
leaq -0x70(%rbp), %r15
andq $0x0, 0x8(%r15)
movl $0x8c850002, (%r15)     # imm = 0x8C850002
leaq 0xd11(%rip), %rdi       # 0x201f
callq 0x1110
movl %eax, 0x4(%r15)
pushq $0x10
popq %rdx
movl %ebx, %edi
movq %r15, %rsi
callq 0x10c0
testl %eax, %eax
js 0x14d8
movq 0x2c9d(%rip), %rdi      # 0x3fd0
leaq 0xcff(%rip), %rsi       # 0x2039
callq 0x1100
movq %rax, %rdi
callq 0x1080
leaq -0x870(%rbp), %r15
movl $0x400, %edx            # imm = 0x400
movq %r15, %rdi
xorl %esi, %esi
callq 0x1090
leaq -0x470(%rbp), %rdi
movl $0x400, %edx            # imm = 0x400
xorl %esi, %esi
callq 0x1090
movq 0x8(%r14), %rsi
leaq -0x60(%rbp), %r14
leaq -0x40(%rbp), %rdx
movq %r14, %rdi
callq 0x1520
movq (%r14), %rsi
movq %r15, %rdi
callq 0x10f0
movq %r15, %rdi
callq 0x1060
movl %ebx, %edi
movq %r15, %rsi
movq %rax, %rdx
callq 0x1050
movq 0x2c25(%rip), %r14      # 0x3fd0
leaq 0xca4(%rip), %rsi       # 0x2056
movq %r14, %rdi
callq 0x1100
leaq -0x60(%rbp), %rsi
movq %rax, %rdi
callq 0x10e0
movq %rax, %rdi
callq 0x1080
leaq -0x470(%rbp), %rsi
movl $0x400, %edx            # imm = 0x400
movl %ebx, %edi
callq 0x1130
leaq -0x40(%rbp), %rdi
leaq -0x470(%rbp), %r15
leaq -0x19(%rbp), %rdx
movq %r15, %rsi
callq 0x1520
leaq 0xc9a(%rip), %rsi       # 0x2099
leaq -0x40(%rbp), %rdi
callq 0x1040
testl %eax, %eax
je 0x144c
leaq 0xc9e(%rip), %rsi       # 0x20b1
leaq -0x40(%rbp), %rdi
callq 0x1040
testl %eax, %eax
je 0x1477
leaq 0xca8(%rip), %rsi       # 0x20cf
leaq -0x40(%rbp), %rdi
callq 0x1040
testl %eax, %eax
je 0x1480
movq 0x2b95(%rip), %rdi      # 0x3fd0
leaq 0xcbe(%rip), %rsi       # 0x2100
callq 0x1100
movq %rax, %r14
jmp 0x1487
movq 0x2b7d(%rip), %rdi      # 0x3fd0
leaq 0xc42(%rip), %rsi       # 0x209c
callq 0x1100
leaq -0x60(%rbp), %rsi
movq %rax, %rdi
callq 0x10e0
movq %rax, %r14
leaq 0xc31(%rip), %r15       # 0x20a6
jmp 0x1487
leaq 0xc35(%rip), %r15       # 0x20b3
jmp 0x1487
leaq 0xc4b(%rip), %r15       # 0x20d2
movq %r14, %rdi
movq %r15, %rsi
callq 0x1100
movq %rax, %rdi
callq 0x1080
movl %ebx, %edi
callq 0x1180
leaq -0x40(%rbp), %rdi
callq 0x1070
leaq -0x60(%rbp), %rdi
callq 0x1070
xorl %eax, %eax
addq $0x858, %rsp            # imm = 0x858
popq %rbx
popq %r14
popq %r15
popq %rbp
retq
movq 0x2b0e(%rip), %rax      # 0x3fd8
movq (%rax), %rcx
leaq 0xb30(%rip), %rdi       # 0x2004
pushq $0x1a
jmp 0x14eb
movq 0x2af9(%rip), %rax      # 0x3fd8
movq (%rax), %rcx
leaq 0xb40(%rip), %rdi       # 0x2029
pushq $0xf
popq %rsi
pushq $0x1
popq %rdx
callq 0x1170
pushq $0x1
popq %rdi
callq 0x1120
jmp 0x150c
movq %rax, %rbx
leaq -0x40(%rbp), %rdi
callq 0x1070
jmp 0x150f
movq %rax, %rbx
leaq -0x60(%rbp), %rdi
callq 0x1070
movq %rbx, %rdi
callq 0x1150