// File: /workspace/github_cpp_makefile_star2_O1/DoubleString[P]RtConverter/src/Rtklib/stream.cpp
// Function: bamboo::genudp(int, int, char const*, char*)
static udp_t *genudp(int type, int port, const char *saddr, char *msg)
	{
		udp_t *udp;
		struct hostent *hp;
		int bs = buffsize, opt = 1;

		tracet(3, "genudp: type=%d\n", type);

		if (!(udp = (udp_t *)malloc(sizeof(udp_t)))) return NULL;
		udp->state = 2;
		udp->type = type;
		udp->port = port;
		strcpy(udp->saddr, saddr);

		if ((udp->sock = socket(AF_INET, SOCK_DGRAM, 0)) == (socket_t)-1) {
			sprintf(msg, "socket error (%d)", errsock());
			return NULL;
		}
		if (setsockopt(udp->sock, SOL_SOCKET, SO_RCVBUF, (const char *)&bs, sizeof(bs)) == -1 ||
			setsockopt(udp->sock, SOL_SOCKET, SO_SNDBUF, (const char *)&bs, sizeof(bs)) == -1) {
			tracet(2, "genudp: setsockopt error sock=%d err=%d bs=%d\n", udp->sock, errsock(), bs);
			sprintf(msg, "sockopt error: bufsiz");
		}
		memset(&udp->addr, 0, sizeof(udp->addr));
		udp->addr.sin_family = AF_INET;
		udp->addr.sin_port = htons(port);

		if (!udp->type) { /* udp server */
			udp->addr.sin_addr.s_addr = htonl(INADDR_ANY);
#ifdef SVR_REUSEADDR
			setsockopt(udp->sock, SOL_SOCKET, SO_REUSEADDR, (const char *)&opt, sizeof(opt));
#endif
			if (::bind(udp->sock, (struct sockaddr *)&udp->addr, sizeof(udp->addr)) == -1) {
				tracet(2, "genudp: bind error sock=%d port=%d err=%d\n", udp->sock, port, errsock());
				sprintf(msg, "bind error (%d): %d", errsock(), port);
				closesocket(udp->sock);
				free(udp);
				return NULL;
			}
		}
		else { /* udp client */
			if (!strcmp(saddr, "255.255.255.255") &&
				setsockopt(udp->sock, SOL_SOCKET, SO_BROADCAST, (const char *)&opt,
					sizeof(opt)) == -1) {
				tracet(2, "genudp: setsockopt error sock=%d err=%d\n", udp->sock, errsock());
				sprintf(msg, "sockopt error: broadcast");
			}
			if (!(hp = gethostbyname(saddr))) {
				sprintf(msg, "address error (%s)", saddr);
				closesocket(udp->sock);
				free(udp);
				return NULL;
			}
			memcpy(&udp->addr.sin_addr, hp->h_addr, hp->h_length);
		}
		return udp;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movq %rcx, %r14
movq %rdx, %r15
movl %esi, %r12d
movl %edi, %r13d
movl 0x32ccb(%rip), %eax     # 0x8fea4
movl %eax, -0x2c(%rbp)
movl $0x1, -0x30(%rbp)
leaq 0x19207(%rip), %rsi     # 0x763f1
movl $0x3, %edi
movl %r13d, %edx
xorl %eax, %eax
callq 0x53ec4
movl $0x120, %edi            # imm = 0x120
callq 0x8850
testq %rax, %rax
je 0x5d44f
movq %rax, %rbx
movl $0x2, (%rax)
movl %r13d, 0x4(%rax)
movl %r12d, 0x8(%rax)
leaq 0xc(%rax), %rdi
movq %r15, %rsi
callq 0x85c0
movl $0x2, %edi
movl $0x2, %esi
xorl %edx, %edx
callq 0x8190
movl %eax, 0x11c(%rbx)
cmpl $-0x1, %eax
je 0x5d39b
leaq -0x2c(%rbp), %rcx
movl %eax, %edi
movl $0x1, %esi
movl $0x8, %edx
movl $0x4, %r8d
callq 0x8b50
cmpl $-0x1, %eax
je 0x5d28d
movl 0x11c(%rbx), %edi
leaq -0x2c(%rbp), %rcx
movl $0x1, %esi
movl $0x7, %edx
movl $0x4, %r8d
callq 0x8b50
cmpl $-0x1, %eax
jne 0x5d2ce
movl 0x11c(%rbx), %r13d
callq 0x8070
movl (%rax), %ecx
movl -0x2c(%rbp), %r8d
leaq 0x1915c(%rip), %rsi     # 0x76402
movl $0x2, %edi
movl %r13d, %edx
xorl %eax, %eax
callq 0x53ec4
movabsq $0x7a697366756220, %rax # imm = 0x7A697366756220
movq %rax, 0xe(%r14)
movups 0x18fde(%rip), %xmm0    # 0x762a8
movups %xmm0, (%r14)
xorps %xmm0, %xmm0
movups %xmm0, 0x10c(%rbx)
movl %r12d, %eax
rolw $0x8, %ax
movw $0x2, 0x10c(%rbx)
movw %ax, 0x10e(%rbx)
cmpl $0x0, 0x4(%rbx)
je 0x5d3ba
leaq 0x19170(%rip), %rsi     # 0x76470
movq %r15, %rdi
callq 0x8890
testl %eax, %eax
jne 0x5d36b
movl 0x11c(%rbx), %edi
leaq -0x30(%rbp), %rcx
movl $0x1, %esi
movl $0x6, %edx
movl $0x4, %r8d
callq 0x8b50
cmpl $-0x1, %eax
jne 0x5d36b
movl 0x11c(%rbx), %r12d
callq 0x8070
movl (%rax), %ecx
leaq 0x1913b(%rip), %rsi     # 0x76480
movl $0x2, %edi
movl %r12d, %edx
xorl %eax, %eax
callq 0x53ec4
movups 0x19157(%rip), %xmm0    # 0x764b2
movups %xmm0, 0x9(%r14)
movups 0x19142(%rip), %xmm0    # 0x764a9
movups %xmm0, (%r14)
movq %r15, %rdi
callq 0x8720
testq %rax, %rax
je 0x5d428
movq %rbx, %rdi
addq $0x110, %rdi            # imm = 0x110
movq 0x18(%rax), %rcx
movq (%rcx), %rsi
movslq 0x14(%rax), %rdx
callq 0x84f0
jmp 0x5d451
callq 0x8070
movl (%rax), %edx
leaq 0x18dbc(%rip), %rsi     # 0x76165
xorl %ebx, %ebx
movq %r14, %rdi
xorl %eax, %eax
callq 0x8120
jmp 0x5d451
movq %rbx, %rsi
addq $0x10c, %rsi            # imm = 0x10C
movl $0x0, 0x110(%rbx)
movl 0x11c(%rbx), %edi
movl $0x10, %edx
callq 0x8100
cmpl $-0x1, %eax
jne 0x5d451
movl 0x11c(%rbx), %r15d
callq 0x8070
movq %rax, %r13
movl (%rax), %r8d
leaq 0x19035(%rip), %rsi     # 0x76431
movl $0x2, %edi
movl %r15d, %edx
movl %r12d, %ecx
xorl %eax, %eax
callq 0x53ec4
movl (%r13), %edx
leaq 0x19043(%rip), %rsi     # 0x7645c
movq %r14, %rdi
movl %r12d, %ecx
xorl %eax, %eax
callq 0x8120
jmp 0x5d43c
leaq 0x18d9d(%rip), %rsi     # 0x761cc
movq %r14, %rdi
movq %r15, %rdx
xorl %eax, %eax
callq 0x8120
movl 0x11c(%rbx), %edi
callq 0x8c50
movq %rbx, %rdi
callq 0x87b0
xorl %ebx, %ebx
movq %rbx, %rax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq