// File: /workspace/github_c_makefile_star2_O0/sharpyfox[P]citrusleaf-client/src/cl_info.c
// Function: citrusleaf_info_host_limit
int
citrusleaf_info_host_limit(struct sockaddr_in *sa_in, char *names, char **values, int timeout_ms, bool send_asis, uint64_t max_response_length)
{
	int rv = -1;
    int io_rv;
	*values = 0;
	
	// Deal with the incoming 'names' parameter
	// Translate interior ';'  in the passed-in names to \n
	uint32_t	slen = 0;
	if (names) {
		if (send_asis) {
			slen = strlen(names);
		} else {
			char *_t = names;
			while (*_t) { 
				slen++; 
				if ((*_t == ';') || (*_t == ':') || (*_t == ',')) *_t = '\n'; 
				_t++; 
			}
		}
	}
	
	// Sometimes people forget/cant add the trailing '\n'. Be nice and add it for them.
	// using a stack allocated variable so we dn't have to clean up, Pain in the ass syntactically
	// but a nice little thing
	if (names) {
		if (names[slen-1] == '\n') {
			slen = 0;
		} else { 
			slen++; if (slen > 1024) { return(-1); } 
		}
	}
	char names_with_term[slen+1];
	if (slen) { 
		strcpy(names_with_term, names);
		names_with_term[slen-1] = '\n';
		names_with_term[slen] = 0;
		names = names_with_term;
	}
		
	// Actually doing a non-blocking connect
	int fd = cf_socket_create_and_connect_nb(sa_in);
	if (fd == -1) {
		return -1;
	}

	cl_proto 	*req;
	uint8_t		buf[1024];
	uint		buf_sz;


	// Un-initialized buf can lead to junk lastshiptimes values. 
	// Initialize buf to 0.
	
	bzero(buf, 1024);
	
	if (names) {
		uint sz = strlen(names);
		buf_sz = sz + sizeof(cl_proto);
		if (buf_sz < 1024)
			req = (cl_proto *) buf;
		else
			req = (cl_proto *) malloc(buf_sz);
		if (req == NULL)	goto Done;

		req->sz = sz;
		memcpy(req->data,names,sz);
	}
	else {
		req = (cl_proto *) buf;
		req->sz = 0;
		buf_sz = sizeof(cl_proto);
		names = "";
	}
		
	req->version = CL_PROTO_VERSION;
	req->type = CL_PROTO_TYPE_INFO;
	cl_proto_swap(req);
	
    if (timeout_ms)
        io_rv = cf_socket_write_timeout(fd, (uint8_t *) req, buf_sz, 0, timeout_ms);
    else
        io_rv = cf_socket_write_forever(fd, (uint8_t *) req, buf_sz);
    
	if ((uint8_t *)req != buf)	free(req);
	if (io_rv != 0) {
#ifdef DEBUG        
		cf_debug("info returned error, rv %d errno %d bufsz %d", io_rv, errno, buf_sz);
#endif        
		goto Done;
	}
	
	cl_proto	*rsp = (cl_proto *)buf;
    if (timeout_ms) 
        io_rv = cf_socket_read_timeout(fd, buf, 8, 0, timeout_ms);
    else
        io_rv = cf_socket_read_forever(fd, buf, 8);
    
    if (0 != io_rv) {
#ifdef DEBUG        
		cf_debug("info socket read failed: rv %d errno %d", io_rv, errno);
#endif        
		goto Done;
	}
	cl_proto_swap(rsp);
	
	if (rsp->sz) {
		uint8_t *v_buf = malloc(rsp->sz + 1);
		if (!v_buf) goto Done;
        
        if (timeout_ms)
            io_rv = cf_socket_read_timeout(fd, v_buf, rsp->sz, 0, timeout_ms);
        else
            io_rv = cf_socket_read_forever(fd, v_buf, rsp->sz);
        
        if (io_rv != 0) {
            free(v_buf);
            goto Done;
		}
			
		v_buf[rsp->sz] = 0;
		*values = (char *) v_buf;
		
	}                                                                                               
	else {
		*values = 0;
	}
	rv = 0;

Done:	
	shutdown(fd, SHUT_RDWR);
	close(fd);
	return(rv);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x490, %rsp            # imm = 0x490
movb %r8b, %al
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq %rdx, -0x20(%rbp)
movl %ecx, -0x24(%rbp)
andb $0x1, %al
movb %al, -0x25(%rbp)
movq %r9, -0x30(%rbp)
movl $0xffffffff, -0x34(%rbp) # imm = 0xFFFFFFFF
movq -0x20(%rbp), %rax
movq $0x0, (%rax)
movl $0x0, -0x3c(%rbp)
cmpq $0x0, -0x18(%rbp)
je 0x17931
testb $0x1, -0x25(%rbp)
je 0x178da
movq -0x18(%rbp), %rdi
callq 0x2100
movl %eax, -0x3c(%rbp)
jmp 0x1792f
movq -0x18(%rbp), %rax
movq %rax, -0x48(%rbp)
movq -0x48(%rbp), %rax
cmpb $0x0, (%rax)
je 0x1792d
movl -0x3c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x3c(%rbp)
movq -0x48(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x3b, %eax
je 0x17918
movq -0x48(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x3a, %eax
je 0x17918
movq -0x48(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x2c, %eax
jne 0x1791f
movq -0x48(%rbp), %rax
movb $0xa, (%rax)
movq -0x48(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x48(%rbp)
jmp 0x178e2
jmp 0x1792f
jmp 0x17931
cmpq $0x0, -0x18(%rbp)
je 0x17978
movq -0x18(%rbp), %rax
movl -0x3c(%rbp), %ecx
subl $0x1, %ecx
movl %ecx, %ecx
movsbl (%rax,%rcx), %eax
cmpl $0xa, %eax
jne 0x17956
movl $0x0, -0x3c(%rbp)
jmp 0x17976
movl -0x3c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x3c(%rbp)
cmpl $0x400, -0x3c(%rbp)     # imm = 0x400
jbe 0x17974
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x17ce4
jmp 0x17976
jmp 0x17978
movl -0x3c(%rbp), %eax
incl %eax
movq %rsp, %rcx
movq %rcx, -0x50(%rbp)
movq %rax, %rdx
addq $0xf, %rdx
andq $-0x10, %rdx
movq %rsp, %rcx
subq %rdx, %rcx
movq %rcx, -0x490(%rbp)
movq %rcx, %rsp
movq %rax, -0x58(%rbp)
cmpl $0x0, -0x3c(%rbp)
je 0x179d7
movq -0x490(%rbp), %rdi
movq -0x18(%rbp), %rsi
callq 0x2270
movq -0x490(%rbp), %rax
movl -0x3c(%rbp), %ecx
subl $0x1, %ecx
movl %ecx, %ecx
movb $0xa, (%rax,%rcx)
movl -0x3c(%rbp), %ecx
movb $0x0, (%rax,%rcx)
movq %rax, -0x18(%rbp)
movq -0x10(%rbp), %rdi
callq 0x16950
movl %eax, -0x5c(%rbp)
cmpl $-0x1, -0x5c(%rbp)
jne 0x179fc
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
movl $0x1, -0x60(%rbp)
jmp 0x17cdd
leaq -0x470(%rbp), %rdi
xorl %esi, %esi
movl $0x400, %edx            # imm = 0x400
callq 0x2170
cmpq $0x0, -0x18(%rbp)
je 0x17a9f
movq -0x18(%rbp), %rdi
callq 0x2100
movl %eax, -0x478(%rbp)
movl -0x478(%rbp), %eax
addq $0x8, %rax
movl %eax, -0x474(%rbp)
cmpl $0x400, -0x474(%rbp)    # imm = 0x400
jae 0x17a52
leaq -0x470(%rbp), %rax
movq %rax, -0x68(%rbp)
jmp 0x17a63
movl -0x474(%rbp), %eax
movl %eax, %edi
callq 0x2310
movq %rax, -0x68(%rbp)
cmpq $0x0, -0x68(%rbp)
jne 0x17a6f
jmp 0x17cbb
movl -0x478(%rbp), %eax
movl %eax, %ecx
movq -0x68(%rbp), %rax
movl %ecx, 0x2(%rax)
movw $0x0, 0x6(%rax)
movq -0x68(%rbp), %rdi
addq $0x8, %rdi
movq -0x18(%rbp), %rsi
movl -0x478(%rbp), %eax
movl %eax, %edx
callq 0x21e0
jmp 0x17ad0
leaq -0x470(%rbp), %rax
movq %rax, -0x68(%rbp)
movq -0x68(%rbp), %rax
movw $0x0, 0x6(%rax)
movl $0x0, 0x2(%rax)
movl $0x8, -0x474(%rbp)
leaq 0xfb6(%rip), %rax       # 0x18a82
movq %rax, -0x18(%rbp)
movq -0x68(%rbp), %rax
movb $0x2, (%rax)
movq -0x68(%rbp), %rax
movb $0x1, 0x1(%rax)
movq -0x68(%rbp), %rdi
callq 0x13a70
cmpl $0x0, -0x24(%rbp)
je 0x17b0f
movl -0x5c(%rbp), %edi
movq -0x68(%rbp), %rsi
movl -0x474(%rbp), %eax
movl %eax, %edx
movl -0x24(%rbp), %r8d
xorl %eax, %eax
movl %eax, %ecx
callq 0x15c90
movl %eax, -0x38(%rbp)
jmp 0x17b26
movl -0x5c(%rbp), %edi
movq -0x68(%rbp), %rsi
movl -0x474(%rbp), %eax
movl %eax, %edx
callq 0x166a0
movl %eax, -0x38(%rbp)
movq -0x68(%rbp), %rax
leaq -0x470(%rbp), %rcx
cmpq %rcx, %rax
je 0x17b3f
movq -0x68(%rbp), %rdi
callq 0x22e0
cmpl $0x0, -0x38(%rbp)
je 0x17b4a
jmp 0x17cbb
leaq -0x470(%rbp), %rax
movq %rax, -0x480(%rbp)
cmpl $0x0, -0x24(%rbp)
je 0x17b7f
movl -0x5c(%rbp), %edi
leaq -0x470(%rbp), %rsi
movl -0x24(%rbp), %r8d
movl $0x8, %edx
xorl %eax, %eax
movl %eax, %ecx
callq 0x15350
movl %eax, -0x38(%rbp)
jmp 0x17b96
movl -0x5c(%rbp), %edi
leaq -0x470(%rbp), %rsi
movl $0x8, %edx
callq 0x16590
movl %eax, -0x38(%rbp)
xorl %eax, %eax
cmpl -0x38(%rbp), %eax
je 0x17ba2
jmp 0x17cbb
movq -0x480(%rbp), %rdi
callq 0x13a70
movq -0x480(%rbp), %rcx
movl 0x2(%rcx), %eax
movzwl 0x6(%rcx), %ecx
shlq $0x20, %rcx
orq %rcx, %rax
cmpq $0x0, %rax
je 0x17ca9
movq -0x480(%rbp), %rax
movl 0x2(%rax), %ecx
movl %ecx, %edi
movzwl 0x6(%rax), %eax
shlq $0x20, %rax
orq %rax, %rdi
addq $0x1, %rdi
callq 0x2310
movq %rax, -0x488(%rbp)
cmpq $0x0, -0x488(%rbp)
jne 0x17c03
jmp 0x17cbb
cmpl $0x0, -0x24(%rbp)
je 0x17c3c
movl -0x5c(%rbp), %edi
movq -0x488(%rbp), %rsi
movq -0x480(%rbp), %rax
movl 0x2(%rax), %ecx
movl %ecx, %edx
movzwl 0x6(%rax), %eax
shlq $0x20, %rax
orq %rax, %rdx
movl -0x24(%rbp), %r8d
xorl %eax, %eax
movl %eax, %ecx
callq 0x15350
movl %eax, -0x38(%rbp)
jmp 0x17c65
movl -0x5c(%rbp), %edi
movq -0x488(%rbp), %rsi
movq -0x480(%rbp), %rax
movl 0x2(%rax), %ecx
movl %ecx, %edx
movzwl 0x6(%rax), %eax
shlq $0x20, %rax
orq %rax, %rdx
callq 0x16590
movl %eax, -0x38(%rbp)
cmpl $0x0, -0x38(%rbp)
je 0x17c79
movq -0x488(%rbp), %rdi
callq 0x22e0
jmp 0x17cbb
movq -0x488(%rbp), %rax
movq -0x480(%rbp), %rdx
movl 0x2(%rdx), %ecx
movzwl 0x6(%rdx), %edx
shlq $0x20, %rdx
orq %rdx, %rcx
movb $0x0, (%rax,%rcx)
movq -0x488(%rbp), %rcx
movq -0x20(%rbp), %rax
movq %rcx, (%rax)
jmp 0x17cb4
movq -0x20(%rbp), %rax
movq $0x0, (%rax)
movl $0x0, -0x34(%rbp)
movl -0x5c(%rbp), %edi
movl $0x2, %esi
callq 0x2340
movl -0x5c(%rbp), %edi
callq 0x2570
movl -0x34(%rbp), %eax
movl %eax, -0x4(%rbp)
movl $0x1, -0x60(%rbp)
movq -0x50(%rbp), %rax
movq %rax, %rsp
movl -0x4(%rbp), %eax
movq %rbp, %rsp
popq %rbp
retq
nopl (%rax)