// File: /workspace/github_cpp_makefile_star2_O1/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 0x1934a(%rip), %rsi     # 0x76154
xorl %r14d, %r14d
movl $0x3, %edi
movl %r12d, %edx
xorl %eax, %eax
callq 0x53ec4
movl $0x2, %edi
movl $0x1, %esi
xorl %edx, %edx
callq 0x8190
movl %eax, 0x118(%rbx)
cmpl $-0x1, %eax
je 0x5cea2
movl %eax, %edi
movq %r15, %rsi
callq 0x5d008
testl %eax, %eax
je 0x5cedf
xorps %xmm0, %xmm0
movups %xmm0, 0x108(%rbx)
movw $0x2, 0x108(%rbx)
movzwl 0x104(%rbx), %eax
rolw $0x8, %ax
movw %ax, 0x10a(%rbx)
testl %r12d, %r12d
je 0x5ceed
leaq 0x4(%rbx), %r12
movq %r12, %rdi
callq 0x8720
testq %rax, %rax
je 0x5cf4f
leaq 0x10c(%rbx), %rdi
movq 0x18(%rax), %rcx
movq (%rcx), %rsi
movslq 0x14(%rax), %rdx
callq 0x84f0
jmp 0x5cf1d
callq 0x8070
movq %rax, %r12
movl (%rax), %edx
leaq 0x192b2(%rip), %rsi     # 0x76165
movq %r15, %rdi
xorl %eax, %eax
callq 0x8120
movl (%r12), %edx
leaq 0x192af(%rip), %rsi     # 0x76177
movl $0x1, %edi
xorl %eax, %eax
callq 0x53ec4
movl $0xffffffff, (%rbx)     # imm = 0xFFFFFFFF
jmp 0x5cfab
movl $0xffffffff, (%rbx)     # imm = 0xFFFFFFFF
xorl %r14d, %r14d
jmp 0x5cfab
leaq 0x108(%rbx), %rsi
movl 0x118(%rbx), %edi
movl $0x10, %edx
callq 0x8100
cmpl $-0x1, %eax
je 0x5cfb7
movl 0x118(%rbx), %edi
movl $0x5, %esi
callq 0x86f0
movl $0x1, (%rbx)
callq 0x5088f
movl %eax, 0x120(%rbx)
movl 0x118(%rbx), %edx
leaq 0x192d0(%rip), %rsi     # 0x7620b
movl $0x5, %edi
xorl %eax, %eax
callq 0x53ec4
movl $0x1, %r14d
jmp 0x5cfab
leaq 0x19276(%rip), %rsi     # 0x761cc
xorl %r14d, %r14d
movq %r15, %rdi
movq %r12, %rdx
xorl %eax, %eax
callq 0x8120
callq 0x8070
movl (%rax), %ecx
leaq 0x1926b(%rip), %rsi     # 0x761df
movl $0x1, %edi
movq %r12, %rdx
xorl %eax, %eax
callq 0x53ec4
movl 0x118(%rbx), %edi
callq 0x8c50
movl $0x0, (%rbx)
movl 0x32f06(%rip), %eax     # 0x8fea0
movl %eax, 0x11c(%rbx)
callq 0x5088f
movl %eax, 0x124(%rbx)
movl %r14d, %eax
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq
callq 0x8070
movq %rax, %r12
movl (%rax), %edx
movl 0x104(%rbx), %ecx
leaq 0x191c6(%rip), %rsi     # 0x76194
xorl %r14d, %r14d
movq %r15, %rdi
xorl %eax, %eax
callq 0x8120
movl 0x104(%rbx), %edx
movl (%r12), %ecx
leaq 0x191bd(%rip), %rsi     # 0x761a9
movl $0x1, %edi
xorl %eax, %eax
callq 0x53ec4
movl 0x118(%rbx), %edi
callq 0x8c50
jmp 0x5ced4