// File: /workspace/github_cpp_makefile_star2_O1/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 0x162b
movl %eax, %ebx
xorps %xmm0, %xmm0
leaq -0x70(%rbp), %r15
movaps %xmm0, (%r15)
movl $0x8c850002, (%r15)     # imm = 0x8C850002
leaq 0xca7(%rip), %rdi       # 0x201f
callq 0x1100
movl %eax, 0x4(%r15)
movl %ebx, %edi
movq %r15, %rsi
movl $0x10, %edx
callq 0x10c0
testl %eax, %eax
js 0x1630
movq 0x2c31(%rip), %r15      # 0x3fd0
leaq 0xc93(%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 0x2b92(%rip), %rdi      # 0x3fd0
leaq 0xc11(%rip), %rsi       # 0x2056
movl $0x42, %edx
callq 0x1120
movq -0x60(%rbp), %rsi
movq -0x58(%rbp), %rdx
movq 0x2b72(%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 0xbc3(%rip), %rsi       # 0x2099
leaq -0x40(%rbp), %rdi
callq 0x1050
testl %eax, %eax
je 0x1538
leaq 0xbc7(%rip), %rsi       # 0x20b1
leaq -0x40(%rbp), %rdi
callq 0x1050
testl %eax, %eax
je 0x1591
leaq 0xbcd(%rip), %rsi       # 0x20cf
leaq -0x40(%rbp), %rdi
callq 0x1050
testl %eax, %eax
je 0x159f
movq 0x2ab6(%rip), %rdi      # 0x3fd0
leaq 0xbdf(%rip), %rsi       # 0x2100
movl $0x49, %edx
callq 0x1120
movq %r14, %rdi
callq 0x1070
movq %rax, %rdx
jmp 0x15ab
movq 0x2a91(%rip), %rdi      # 0x3fd0
leaq 0xb56(%rip), %rsi       # 0x209c
movl $0x9, %edx
callq 0x1120
movq -0x60(%rbp), %rsi
movq -0x58(%rbp), %rdx
movq 0x2a71(%rip), %rdi      # 0x3fd0
callq 0x1120
movq %rax, %r15
leaq 0xb38(%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 0x15d1
movl $0x1b, %edx
leaq 0xb16(%rip), %r14       # 0x20b3
jmp 0x15ab
movl $0x2d, %edx
leaq 0xb27(%rip), %r14       # 0x20d2
movq 0x2a1e(%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 0x1600
movq -0x30(%rbp), %rsi
incq %rsi
callq 0x1110
leaq -0x50(%rbp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x1619
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 0x1651
movq %rax, %rbx
movq -0x40(%rbp), %rdi
cmpq %r12, %rdi
je 0x1654
movq -0x30(%rbp), %rsi
incq %rsi
callq 0x1110
jmp 0x1654
movq %rax, %rbx
leaq -0x50(%rbp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x166d
movq -0x50(%rbp), %rsi
incq %rsi
callq 0x1110
movq %rbx, %rdi
callq 0x1160
nop