// File: /workspace/github_cpp_makefile_star2_O3/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 0x337fb(%rip), %eax     # 0x8fea4
movl %eax, -0x2c(%rbp)
movl $0x1, -0x30(%rbp)
leaq 0x19cbc(%rip), %rsi     # 0x76376
movl $0x3, %edi
movl %r13d, %edx
xorl %eax, %eax
callq 0x5342c
movl $0x120, %edi            # imm = 0x120
callq 0x8840
testq %rax, %rax
je 0x5c920
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 0x5c876
leaq -0x2c(%rbp), %rcx
movl %eax, %edi
movl $0x1, %esi
movl $0x8, %edx
movl $0x4, %r8d
callq 0x8b40
cmpl $-0x1, %eax
je 0x5c75d
movl 0x11c(%rbx), %edi
leaq -0x2c(%rbp), %rcx
movl $0x1, %esi
movl $0x7, %edx
movl $0x4, %r8d
callq 0x8b40
cmpl $-0x1, %eax
jne 0x5c79e
movl 0x11c(%rbx), %r13d
callq 0x8070
movl (%rax), %ecx
movl -0x2c(%rbp), %r8d
leaq 0x19c11(%rip), %rsi     # 0x76387
movl $0x2, %edi
movl %r13d, %edx
xorl %eax, %eax
callq 0x5342c
movabsq $0x7a697366756220, %rax # imm = 0x7A697366756220
movq %rax, 0xe(%r14)
movups 0x19a93(%rip), %xmm0    # 0x7622d
movups %xmm0, (%r14)
movl $0x0, 0x118(%rbx)
movq $0x0, 0x110(%rbx)
movl %r12d, %eax
rolw $0x8, %ax
movw $0x2, 0x10c(%rbx)
movw %ax, 0x10e(%rbx)
cmpl $0x0, 0x4(%rbx)
je 0x5c895
leaq 0x19c1a(%rip), %rsi     # 0x763f5
movq %r15, %rdi
callq 0x8880
testl %eax, %eax
jne 0x5c846
movl 0x11c(%rbx), %edi
leaq -0x30(%rbp), %rcx
movl $0x1, %esi
movl $0x6, %edx
movl $0x4, %r8d
callq 0x8b40
cmpl $-0x1, %eax
jne 0x5c846
movl 0x11c(%rbx), %r12d
callq 0x8070
movl (%rax), %ecx
leaq 0x19be5(%rip), %rsi     # 0x76405
movl $0x2, %edi
movl %r12d, %edx
xorl %eax, %eax
callq 0x5342c
movups 0x19c01(%rip), %xmm0    # 0x76437
movups %xmm0, 0x9(%r14)
movups 0x19bec(%rip), %xmm0    # 0x7642e
movups %xmm0, (%r14)
movq %r15, %rdi
callq 0x8710
testq %rax, %rax
je 0x5c8f9
movq %rbx, %rdi
addq $0x110, %rdi            # imm = 0x110
movq 0x18(%rax), %rcx
movq (%rcx), %rsi
movslq 0x14(%rax), %rdx
callq 0x84f0
jmp 0x5c922
callq 0x8070
movl (%rax), %edx
leaq 0x19866(%rip), %rsi     # 0x760ea
xorl %ebx, %ebx
movq %r14, %rdi
xorl %eax, %eax
callq 0x8120
jmp 0x5c922
movq %rbx, %rsi
addq $0x10c, %rsi            # imm = 0x10C
movl 0x11c(%rbx), %edi
movl $0x10, %edx
callq 0x8100
cmpl $-0x1, %eax
jne 0x5c922
movl 0x11c(%rbx), %r15d
callq 0x8070
movq %rax, %r13
movl (%rax), %r8d
leaq 0x19ae9(%rip), %rsi     # 0x763b6
movl $0x2, %edi
movl %r15d, %edx
movl %r12d, %ecx
xorl %eax, %eax
callq 0x5342c
movl (%r13), %edx
leaq 0x19af7(%rip), %rsi     # 0x763e1
movq %r14, %rdi
movl %r12d, %ecx
xorl %eax, %eax
callq 0x8120
jmp 0x5c90d
leaq 0x19851(%rip), %rsi     # 0x76151
movq %r14, %rdi
movq %r15, %rdx
xorl %eax, %eax
callq 0x8120
movl 0x11c(%rbx), %edi
callq 0x8c40
movq %rbx, %rdi
callq 0x87a0
xorl %ebx, %ebx
movq %rbx, %rax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq