// File: /workspace/github_cpp_makefile_star2_O2/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 0x348ff(%rip), %eax     # 0x87eb4
movl %eax, -0x2c(%rbp)
movl $0x1, -0x30(%rbp)
leaq 0x18df0(%rip), %rsi     # 0x6c3b6
pushq $0x3
popq %rdi
movl %r13d, %edx
xorl %eax, %eax
callq 0x4acf2
movl $0x120, %edi            # imm = 0x120
callq 0x8830
testq %rax, %rax
je 0x53805
movq %rax, %rbx
movl $0x2, (%rax)
movl %r13d, 0x4(%rax)
movl %r12d, 0x8(%rax)
leaq 0xc(%rax), %rdi
movq %r15, %rsi
callq 0x85c0
pushq $0x2
popq %rdi
movl %edi, %esi
xorl %edx, %edx
callq 0x81b0
movl %eax, 0x11c(%rbx)
cmpl $-0x1, %eax
je 0x5375f
pushq $0x1
popq %rsi
pushq $0x8
popq %rdx
leaq -0x2c(%rbp), %rcx
pushq $0x4
popq %r8
movl %eax, %edi
callq 0x8b40
cmpl $-0x1, %eax
je 0x53656
movl 0x11c(%rbx), %edi
pushq $0x1
popq %rsi
pushq $0x7
popq %rdx
leaq -0x2c(%rbp), %rcx
pushq $0x4
popq %r8
callq 0x8b40
cmpl $-0x1, %eax
jne 0x53695
movl 0x11c(%rbx), %r13d
callq 0x533ff
movl -0x2c(%rbp), %r8d
leaq 0x18d5a(%rip), %rsi     # 0x6c3c7
pushq $0x2
popq %rdi
movl %r13d, %edx
movl %eax, %ecx
xorl %eax, %eax
callq 0x4acf2
movabsq $0x7a697366756220, %rax # imm = 0x7A697366756220
movq %rax, 0xe(%r14)
movups 0x18bdc(%rip), %xmm0    # 0x6c26d
movups %xmm0, (%r14)
andl $0x0, 0x118(%rbx)
andq $0x0, 0x110(%rbx)
movl %r12d, %eax
rolw $0x8, %ax
movw $0x2, 0x10c(%rbx)
movw %ax, 0x10e(%rbx)
cmpl $0x0, 0x4(%rbx)
je 0x5377e
leaq 0x18d69(%rip), %rsi     # 0x6c435
movq %r15, %rdi
callq 0x8890
testl %eax, %eax
jne 0x5372f
movl 0x11c(%rbx), %edi
pushq $0x1
popq %rsi
pushq $0x6
popq %rdx
leaq -0x30(%rbp), %rcx
pushq $0x4
popq %r8
callq 0x8b40
cmpl $-0x1, %eax
jne 0x5372f
movl 0x11c(%rbx), %r12d
callq 0x533ff
leaq 0x18d3c(%rip), %rsi     # 0x6c445
pushq $0x2
popq %rdi
movl %r12d, %edx
movl %eax, %ecx
xorl %eax, %eax
callq 0x4acf2
movups 0x18d58(%rip), %xmm0    # 0x6c477
movups %xmm0, 0x9(%r14)
movups 0x18d43(%rip), %xmm0    # 0x6c46e
movups %xmm0, (%r14)
movq %r15, %rdi
callq 0x86f0
testq %rax, %rax
je 0x537de
movq %rbx, %rdi
addq $0x110, %rdi            # imm = 0x110
movq 0x18(%rax), %rcx
movq (%rcx), %rsi
movslq 0x14(%rax), %rdx
callq 0x84f0
jmp 0x53807
callq 0x533ff
leaq 0x189bf(%rip), %rsi     # 0x6c12a
xorl %ebx, %ebx
movq %r14, %rdi
movl %eax, %edx
xorl %eax, %eax
callq 0x8110
jmp 0x53807
movq %rbx, %rsi
addq $0x10c, %rsi            # imm = 0x10C
movl 0x11c(%rbx), %edi
pushq $0x10
popq %rdx
callq 0x80f0
cmpl $-0x1, %eax
jne 0x53807
movl 0x11c(%rbx), %r15d
callq 0x533ff
leaq 0x18c48(%rip), %rsi     # 0x6c3f6
pushq $0x2
popq %rdi
movl %r15d, %edx
movl %r12d, %ecx
movl %eax, %r8d
xorl %eax, %eax
callq 0x4acf2
callq 0x533ff
leaq 0x18c54(%rip), %rsi     # 0x6c421
movq %r14, %rdi
movl %eax, %edx
movl %r12d, %ecx
xorl %eax, %eax
callq 0x8110
jmp 0x537f2
leaq 0x189ac(%rip), %rsi     # 0x6c191
movq %r14, %rdi
movq %r15, %rdx
xorl %eax, %eax
callq 0x8110
movl 0x11c(%rbx), %edi
callq 0x8c70
movq %rbx, %rdi
callq 0x8780
xorl %ebx, %ebx
movq %rbx, %rax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq