// File: 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
subq $0x60, %rsp
movl %edi, -0xc(%rbp)
movl %esi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq %rcx, -0x20(%rbp)
movl 0x55498(%rip), %eax     # 0xf9a74
movl %eax, -0x34(%rbp)
movl $0x1, -0x38(%rbp)
movl -0xc(%rbp), %edx
movl $0x3, %edi
leaq 0x24b50(%rip), %rsi     # 0xc9145
movb $0x0, %al
callq 0x95890
movl $0x120, %edi            # imm = 0x120
callq 0x99e0
movq %rax, -0x28(%rbp)
cmpq $0x0, %rax
jne 0xa461d
movq $0x0, -0x8(%rbp)
jmp 0xa491e
movq -0x28(%rbp), %rax
movl $0x2, (%rax)
movl -0xc(%rbp), %ecx
movq -0x28(%rbp), %rax
movl %ecx, 0x4(%rax)
movl -0x10(%rbp), %ecx
movq -0x28(%rbp), %rax
movl %ecx, 0x8(%rax)
movq -0x28(%rbp), %rdi
addq $0xc, %rdi
movq -0x18(%rbp), %rsi
callq 0x96f0
movl $0x2, %esi
xorl %edx, %edx
movl %esi, %edi
callq 0x91e0
movq -0x28(%rbp), %rcx
movl %eax, 0x11c(%rcx)
cmpl $-0x1, %eax
jne 0xa4697
movq -0x20(%rbp), %rax
movq %rax, -0x40(%rbp)
callq 0xa43f0
movq -0x40(%rbp), %rdi
movl %eax, %edx
leaq 0x24836(%rip), %rsi     # 0xc8eb9
movb $0x0, %al
callq 0x9150
movq $0x0, -0x8(%rbp)
jmp 0xa491e
movq -0x28(%rbp), %rax
movl 0x11c(%rax), %edi
movl $0x1, %esi
movl $0x8, %edx
leaq -0x34(%rbp), %rcx
movl $0x4, %r8d
callq 0x9d50
cmpl $-0x1, %eax
je 0xa46e7
movq -0x28(%rbp), %rax
movl 0x11c(%rax), %edi
movl $0x1, %esi
movl $0x7, %edx
leaq -0x34(%rbp), %rcx
movl $0x4, %r8d
callq 0x9d50
cmpl $-0x1, %eax
jne 0xa4727
movq -0x28(%rbp), %rax
movl 0x11c(%rax), %eax
movl %eax, -0x44(%rbp)
callq 0xa43f0
movl -0x44(%rbp), %edx
movl %eax, %ecx
movl -0x34(%rbp), %r8d
movl $0x2, %edi
leaq 0x24a48(%rip), %rsi     # 0xc9156
movb $0x0, %al
callq 0x95890
movq -0x20(%rbp), %rdi
leaq 0x248dc(%rip), %rsi     # 0xc8ffc
movb $0x0, %al
callq 0x9150
movq -0x28(%rbp), %rdi
addq $0x10c, %rdi            # imm = 0x10C
xorl %esi, %esi
movl $0x10, %edx
callq 0x93d0
movq -0x28(%rbp), %rax
movw $0x2, 0x10c(%rax)
movl -0x10(%rbp), %eax
movzwl %ax, %edi
callq 0x90b0
movw %ax, %cx
movq -0x28(%rbp), %rax
movw %cx, 0x10e(%rax)
movq -0x28(%rbp), %rax
cmpl $0x0, 0x4(%rax)
jne 0xa482b
xorl %edi, %edi
callq 0x95b0
movl %eax, %ecx
movq -0x28(%rbp), %rax
movl %ecx, 0x110(%rax)
movq -0x28(%rbp), %rax
movl 0x11c(%rax), %edi
movq -0x28(%rbp), %rsi
addq $0x10c, %rsi            # imm = 0x10C
movl $0x10, %edx
callq 0x9120
cmpl $-0x1, %eax
jne 0xa4826
movq -0x28(%rbp), %rax
movl 0x11c(%rax), %eax
movl %eax, -0x58(%rbp)
movl -0x10(%rbp), %eax
movl %eax, -0x54(%rbp)
callq 0xa43f0
movl -0x58(%rbp), %edx
movl -0x54(%rbp), %ecx
movl %eax, %r8d
movl $0x2, %edi
leaq 0x249af(%rip), %rsi     # 0xc9185
movb $0x0, %al
callq 0x95890
movq -0x20(%rbp), %rax
movq %rax, -0x50(%rbp)
callq 0xa43f0
movq -0x50(%rbp), %rdi
movl %eax, %edx
movl -0x10(%rbp), %ecx
leaq 0x249b6(%rip), %rsi     # 0xc91b0
movb $0x0, %al
callq 0x9150
movq -0x28(%rbp), %rax
movl 0x11c(%rax), %edi
callq 0x9e90
movq -0x28(%rbp), %rdi
callq 0x9900
movq $0x0, -0x8(%rbp)
jmp 0xa491e
jmp 0xa4916
movq -0x18(%rbp), %rdi
leaq 0x2498e(%rip), %rsi     # 0xc91c4
callq 0x9a60
cmpl $0x0, %eax
jne 0xa48a4
movq -0x28(%rbp), %rax
movl 0x11c(%rax), %edi
movl $0x1, %esi
movl $0x6, %edx
leaq -0x38(%rbp), %rcx
movl $0x4, %r8d
callq 0x9d50
cmpl $-0x1, %eax
jne 0xa48a4
movq -0x28(%rbp), %rax
movl 0x11c(%rax), %eax
movl %eax, -0x5c(%rbp)
callq 0xa43f0
movl -0x5c(%rbp), %edx
movl %eax, %ecx
movl $0x2, %edi
leaq 0x24949(%rip), %rsi     # 0xc91d4
movb $0x0, %al
callq 0x95890
movq -0x20(%rbp), %rdi
leaq 0x24960(%rip), %rsi     # 0xc91fd
movb $0x0, %al
callq 0x9150
movq -0x18(%rbp), %rdi
callq 0x9880
movq %rax, -0x30(%rbp)
cmpq $0x0, %rax
jne 0xa48ef
movq -0x20(%rbp), %rdi
movq -0x18(%rbp), %rdx
leaq 0x2465a(%rip), %rsi     # 0xc8f20
movb $0x0, %al
callq 0x9150
movq -0x28(%rbp), %rax
movl 0x11c(%rax), %edi
callq 0x9e90
movq -0x28(%rbp), %rdi
callq 0x9900
movq $0x0, -0x8(%rbp)
jmp 0xa491e
movq -0x28(%rbp), %rdi
addq $0x10c, %rdi            # imm = 0x10C
addq $0x4, %rdi
movq -0x30(%rbp), %rax
movq 0x18(%rax), %rax
movq (%rax), %rsi
movq -0x30(%rbp), %rax
movslq 0x14(%rax), %rdx
callq 0x9610
movq -0x28(%rbp), %rax
movq %rax, -0x8(%rbp)
movq -0x8(%rbp), %rax
addq $0x60, %rsp
popq %rbp
retq
nopl (%rax,%rax)