// File: /workspace/github_cpp_makefile_star2_O2/DoubleString[P]RtConverter/src/Rtklib/stream.cpp
// Function: bamboo::gentcp(bamboo::tcp_t*, int, char*)
static int gentcp(tcp_t *tcp, int type, char *msg)
	{
		struct hostent *hp;
#ifdef SVR_REUSEADDR
		int opt = 1;
#endif

		tracet(3, "gentcp: type=%d\n", type);

		/* generate socket */
		if ((tcp->sock = socket(AF_INET, SOCK_STREAM, 0)) == (socket_t)-1) {
			sprintf(msg, "socket error (%d)", errsock());
			tracet(1, "gentcp: socket error err=%d\n", errsock());
			tcp->state = -1;
			return 0;
		}
		if (!setsock(tcp->sock, msg)) {
			tcp->state = -1;
			return 0;
		}
		memset(&tcp->addr, 0, sizeof(tcp->addr));
		tcp->addr.sin_family = AF_INET;
		tcp->addr.sin_port = htons(tcp->port);

		if (type == 0) { /* server socket */

#ifdef SVR_REUSEADDR
		/* multiple-use of server socket */
			setsockopt(tcp->sock, SOL_SOCKET, SO_REUSEADDR, (const char *)&opt,
				sizeof(opt));
#endif
			if (::bind(tcp->sock, (struct sockaddr *)&tcp->addr, sizeof(tcp->addr)) == -1) {
				sprintf(msg, "bind error (%d) : %d", errsock(), tcp->port);
				tracet(1, "gentcp: bind error port=%d err=%d\n", tcp->port, errsock());
				closesocket(tcp->sock);
				tcp->state = -1;
				return 0;
			}
			listen(tcp->sock, 5);
		}
		else { /* client socket */
			if (!(hp = gethostbyname(tcp->saddr))) {
				sprintf(msg, "address error (%s)", tcp->saddr);
				tracet(1, "gentcp: gethostbyname error addr=%s err=%d\n", tcp->saddr, errsock());
				closesocket(tcp->sock);
				tcp->state = 0;
				tcp->tcon = ticonnect;
				tcp->tdis = tickget();
				return 0;
			}
			memcpy(&tcp->addr.sin_addr, hp->h_addr, hp->h_length);
		}
		tcp->state = 1;
		tcp->tact = tickget();
		tracet(5, "gentcp: exit sock=%d\n", tcp->sock);
		return 1;
	}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
movq %rdx, %r15
movl %esi, %r12d
movq %rdi, %rbx
leaq 0x18efc(%rip), %rsi     # 0x6c119
pushq $0x3
popq %rdi
movl %r12d, %edx
xorl %eax, %eax
callq 0x4acf2
pushq $0x2
popq %rdi
pushq $0x1
popq %r14
movl %r14d, %esi
xorl %edx, %edx
callq 0x81b0
movl %eax, 0x118(%rbx)
cmpl $-0x1, %eax
je 0x532b5
movl %eax, %edi
movq %r15, %rsi
callq 0x5340c
testl %eax, %eax
je 0x532e5
andl $0x0, 0x114(%rbx)
andq $0x0, 0x10c(%rbx)
movw $0x2, 0x108(%rbx)
movzwl 0x104(%rbx), %eax
rolw $0x8, %ax
movw %ax, 0x10a(%rbx)
testl %r12d, %r12d
je 0x532f0
leaq 0x4(%rbx), %r12
movq %r12, %rdi
callq 0x86f0
testq %rax, %rax
je 0x53349
leaq 0x10c(%rbx), %rdi
movq 0x18(%rax), %rcx
movq (%rcx), %rsi
movslq 0x14(%rax), %rdx
callq 0x84f0
jmp 0x5331c
callq 0x533ff
leaq 0x18e69(%rip), %rsi     # 0x6c12a
movq %r15, %rdi
movl %eax, %edx
xorl %eax, %eax
callq 0x8110
callq 0x533ff
leaq 0x18e63(%rip), %rsi     # 0x6c13c
pushq $0x1
popq %rdi
movl %eax, %edx
xorl %eax, %eax
callq 0x4acf2
orl $-0x1, (%rbx)
xorl %r14d, %r14d
jmp 0x533f3
leaq 0x108(%rbx), %rsi
movl 0x118(%rbx), %edi
pushq $0x10
popq %rdx
callq 0x80f0
cmpl $-0x1, %eax
je 0x533a2
movl 0x118(%rbx), %edi
pushq $0x5
popq %rsi
callq 0x86d0
movl $0x1, (%rbx)
callq 0x47c01
movl %eax, 0x120(%rbx)
movl 0x118(%rbx), %edx
leaq 0x18e96(%rip), %rsi     # 0x6c1d0
pushq $0x5
popq %rdi
xorl %eax, %eax
callq 0x4acf2
jmp 0x533f3
leaq 0x18e41(%rip), %rsi     # 0x6c191
xorl %r14d, %r14d
movq %r15, %rdi
movq %r12, %rdx
xorl %eax, %eax
callq 0x8110
callq 0x533ff
leaq 0x18e38(%rip), %rsi     # 0x6c1a4
pushq $0x1
popq %rdi
movq %r12, %rdx
movl %eax, %ecx
xorl %eax, %eax
callq 0x4acf2
movl 0x118(%rbx), %edi
callq 0x8c70
andl $0x0, (%rbx)
movl 0x34b21(%rip), %eax     # 0x87eb0
movl %eax, 0x11c(%rbx)
callq 0x47c01
movl %eax, 0x124(%rbx)
jmp 0x533f3
callq 0x533ff
movl 0x104(%rbx), %ecx
leaq 0x18da5(%rip), %rsi     # 0x6c159
xorl %r14d, %r14d
movq %r15, %rdi
movl %eax, %edx
xorl %eax, %eax
callq 0x8110
movl 0x104(%rbx), %r15d
callq 0x533ff
leaq 0x18d98(%rip), %rsi     # 0x6c16e
pushq $0x1
popq %rdi
movl %r15d, %edx
movl %eax, %ecx
xorl %eax, %eax
callq 0x4acf2
movl 0x118(%rbx), %edi
callq 0x8c70
orl $-0x1, (%rbx)
movl %r14d, %eax
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq