// File: /workspace/github_cpp_makefile_star2_O3/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 0x19e0a(%rip), %rsi     # 0x760d9
xorl %r14d, %r14d
movl $0x3, %edi
movl %r12d, %edx
xorl %eax, %eax
callq 0x5342c
movl $0x2, %edi
movl $0x1, %esi
xorl %edx, %edx
callq 0x8190
movl %eax, 0x118(%rbx)
cmpl $-0x1, %eax
je 0x5c372
movl %eax, %edi
movq %r15, %rsi
callq 0x5c4d8
testl %eax, %eax
je 0x5c3af
movl $0x0, 0x114(%rbx)
movq $0x0, 0x10c(%rbx)
movw $0x2, 0x108(%rbx)
movzwl 0x104(%rbx), %eax
rolw $0x8, %ax
movw %ax, 0x10a(%rbx)
testl %r12d, %r12d
je 0x5c3bd
leaq 0x4(%rbx), %r12
movq %r12, %rdi
callq 0x8710
testq %rax, %rax
je 0x5c41f
leaq 0x10c(%rbx), %rdi
movq 0x18(%rax), %rcx
movq (%rcx), %rsi
movslq 0x14(%rax), %rdx
callq 0x84f0
jmp 0x5c3ed
callq 0x8070
movq %rax, %r12
movl (%rax), %edx
leaq 0x19d67(%rip), %rsi     # 0x760ea
movq %r15, %rdi
xorl %eax, %eax
callq 0x8120
movl (%r12), %edx
leaq 0x19d64(%rip), %rsi     # 0x760fc
movl $0x1, %edi
xorl %eax, %eax
callq 0x5342c
movl $0xffffffff, (%rbx)     # imm = 0xFFFFFFFF
jmp 0x5c47b
movl $0xffffffff, (%rbx)     # imm = 0xFFFFFFFF
xorl %r14d, %r14d
jmp 0x5c47b
leaq 0x108(%rbx), %rsi
movl 0x118(%rbx), %edi
movl $0x10, %edx
callq 0x8100
cmpl $-0x1, %eax
je 0x5c487
movl 0x118(%rbx), %edi
movl $0x5, %esi
callq 0x86e0
movl $0x1, (%rbx)
callq 0x4fece
movl %eax, 0x120(%rbx)
movl 0x118(%rbx), %edx
leaq 0x19d85(%rip), %rsi     # 0x76190
movl $0x5, %edi
xorl %eax, %eax
callq 0x5342c
movl $0x1, %r14d
jmp 0x5c47b
leaq 0x19d2b(%rip), %rsi     # 0x76151
xorl %r14d, %r14d
movq %r15, %rdi
movq %r12, %rdx
xorl %eax, %eax
callq 0x8120
callq 0x8070
movl (%rax), %ecx
leaq 0x19d20(%rip), %rsi     # 0x76164
movl $0x1, %edi
movq %r12, %rdx
xorl %eax, %eax
callq 0x5342c
movl 0x118(%rbx), %edi
callq 0x8c40
movl $0x0, (%rbx)
movl 0x33a36(%rip), %eax     # 0x8fea0
movl %eax, 0x11c(%rbx)
callq 0x4fece
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 0x19c7b(%rip), %rsi     # 0x76119
xorl %r14d, %r14d
movq %r15, %rdi
xorl %eax, %eax
callq 0x8120
movl 0x104(%rbx), %edx
movl (%r12), %ecx
leaq 0x19c72(%rip), %rsi     # 0x7612e
movl $0x1, %edi
xorl %eax, %eax
callq 0x5342c
movl 0x118(%rbx), %edi
callq 0x8c40
jmp 0x5c3a4