// File: /workspace/github_c_makefile_star2_O2/unixlab[P]cloudflare-udp-ping/net.c
// Function: net_connect_udp
int net_connect_udp(struct net_addr *shost, int src_port, int busy_poll)
{
	int sd = socket(PF_INET, SOCK_DGRAM, IPPROTO_UDP);
	if (sd < 0) {
		PFATAL("socket()");
	}

	int one = 1;
	int r = setsockopt(sd, SOL_SOCKET, SO_REUSEADDR, (char *)&one,
			   sizeof(one));
	if (r < 0) {
		PFATAL("setsockopt(SO_REUSEADDR)");
	}

	if (busy_poll) {
		r = setsockopt(sd, SOL_SOCKET, SO_BUSY_POLL, (char *)&busy_poll,
			       sizeof(busy_poll));
		if (r < 0) {
			PFATAL("setsockopt(SO_BUSY_POLL)");
		}
	}

	one = 1;
	r = setsockopt(sd, SOL_SOCKET, SO_TIMESTAMPNS, (char *)&one,
		       sizeof(one));
	if (r < 0) {
		PFATAL("setsockopt(SO_TIMESTAMPNS)");
	}

	if (src_port > 1 && src_port < 65536) {
		struct net_addr src;
		memset(&src, 0, sizeof(struct net_addr));
		char buf[32];
		snprintf(buf, sizeof(buf), "0.0.0.0:%d", src_port);
		parse_addr(&src, buf);
		if (bind(sd, src.sockaddr, src.sockaddr_len) < 0) {
			PFATAL("bind()");
		}
	}

	if (-1 == connect(sd, shost->sockaddr, shost->sockaddr_len)) {
		/* is non-blocking, so we don't get error at that point yet */
		if (EINPROGRESS != errno) {
			PFATAL("connect()");
			return -1;
		}
	}

	return sd;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x68, %rsp
movl %edx, %r12d
movl %esi, %r15d
movq %rdi, %r14
movl %edx, -0x30(%rbp)
pushq $0x2
popq %rdi
pushq $0x11
popq %rdx
movl %edi, %esi
callq 0x45f7c0
testl %eax, %eax
js 0x40296a
movl %eax, %ebx
leaq -0x2c(%rbp), %rcx
movl $0x1, (%rcx)
pushq $0x1
popq %rsi
pushq $0x2
popq %rdx
pushq $0x4
popq %r8
movl %eax, %edi
callq 0x45f780
testl %eax, %eax
js 0x4029a9
testl %r12d, %r12d
je 0x4028a9
pushq $0x1
popq %rsi
pushq $0x2e
popq %rdx
leaq -0x30(%rbp), %rcx
pushq $0x4
popq %r8
movl %ebx, %edi
callq 0x45f780
testl %eax, %eax
js 0x402a27
leaq -0x2c(%rbp), %rcx
movl $0x1, (%rcx)
pushq $0x1
popq %rsi
pushq $0x23
popq %rdx
pushq $0x4
popq %r8
movl %ebx, %edi
callq 0x45f780
testl %eax, %eax
js 0x4029e8
leal -0x2(%r15), %eax
cmpl $0xfffd, %eax           # imm = 0xFFFD
ja 0x402937
xorps %xmm0, %xmm0
leaq -0x90(%rbp), %r12
movaps %xmm0, 0x30(%r12)
movaps %xmm0, 0x20(%r12)
movaps %xmm0, 0x10(%r12)
movaps %xmm0, (%r12)
leaq 0xb1b95(%rip), %rdx     # 0x4b4494
leaq -0x50(%rbp), %r13
pushq $0x20
popq %rsi
movq %r13, %rdi
movl %r15d, %ecx
xorl %eax, %eax
callq 0x40d420
movq %r12, %rdi
movq %r13, %rsi
callq 0x401fc3
movq 0x30(%r12), %rsi
movl 0x38(%r12), %edx
movl %ebx, %edi
callq 0x45f530
testl %eax, %eax
js 0x402a63
movq 0x30(%r14), %rsi
movl 0x38(%r14), %edx
movl %ebx, %edi
callq 0x45f560
cmpl $-0x1, %eax
jne 0x402959
callq 0x405990
cmpl $0x73, (%rax)
jne 0x402a9f
movl %ebx, %eax
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq $0x4e77a8, %rbx         # imm = 0x4E77A8
movq (%rbx), %rcx
leaq 0xb1990(%rip), %rdi     # 0x4b430b
pushq $0x1b
popq %rsi
pushq $0x1
popq %rdx
callq 0x4142f0
movq (%rbx), %rdi
leaq 0xb16eb(%rip), %rsi     # 0x4b407b
leaq 0xb1abf(%rip), %rdx     # 0x4b4456
leaq 0xb18c8(%rip), %rcx     # 0x4b4266
movl $0x101, %r8d            # imm = 0x101
jmp 0x402ad9
movq $0x4e77a8, %rbx         # imm = 0x4E77A8
movq (%rbx), %rcx
leaq 0xb197a(%rip), %rdi     # 0x4b4334
pushq $0x2b
popq %rsi
pushq $0x1
popq %rdx
callq 0x4142f0
movq (%rbx), %rdi
leaq 0xb16ac(%rip), %rsi     # 0x4b407b
leaq 0xb1a80(%rip), %rdx     # 0x4b4456
leaq 0xb1889(%rip), %rcx     # 0x4b4266
movl $0x108, %r8d            # imm = 0x108
jmp 0x402ad9
movq $0x4e77a8, %rbx         # imm = 0x4E77A8
movq (%rbx), %rcx
leaq 0xb1a6d(%rip), %rdi     # 0x4b4466
pushq $0x2d
popq %rsi
pushq $0x1
popq %rdx
callq 0x4142f0
movq (%rbx), %rdi
leaq 0xb166d(%rip), %rsi     # 0x4b407b
leaq 0xb1a41(%rip), %rdx     # 0x4b4456
leaq 0xb184a(%rip), %rcx     # 0x4b4266
movl $0x117, %r8d            # imm = 0x117
jmp 0x402ad9
movq $0x4e77a8, %rbx         # imm = 0x4E77A8
movq (%rbx), %rcx
leaq 0xb1998(%rip), %rdi     # 0x4b43d0
pushq $0x2b
popq %rsi
pushq $0x1
popq %rdx
callq 0x4142f0
movq (%rbx), %rdi
leaq 0xb162e(%rip), %rsi     # 0x4b407b
leaq 0xb1a02(%rip), %rdx     # 0x4b4456
leaq 0xb180b(%rip), %rcx     # 0x4b4266
movl $0x10f, %r8d            # imm = 0x10F
jmp 0x402ad9
movq $0x4e77a8, %rbx         # imm = 0x4E77A8
movq (%rbx), %rcx
leaq 0xb1942(%rip), %rdi     # 0x4b43b6
pushq $0x19
popq %rsi
pushq $0x1
popq %rdx
callq 0x4142f0
movq (%rbx), %rdi
leaq 0xb15f2(%rip), %rsi     # 0x4b407b
leaq 0xb19c6(%rip), %rdx     # 0x4b4456
leaq 0xb17cf(%rip), %rcx     # 0x4b4266
movl $0x121, %r8d            # imm = 0x121
jmp 0x402ad9
movq $0x4e77a8, %rbx         # imm = 0x4E77A8
movq (%rbx), %rcx
leaq 0xb19ef(%rip), %rdi     # 0x4b449f
pushq $0x1c
popq %rsi
pushq $0x1
popq %rdx
callq 0x4142f0
movq (%rbx), %rdi
leaq 0xb15b6(%rip), %rsi     # 0x4b407b
leaq 0xb198a(%rip), %rdx     # 0x4b4456
leaq 0xb1793(%rip), %rcx     # 0x4b4266
movl $0x128, %r8d            # imm = 0x128
xorl %eax, %eax
callq 0x40d290
leaq 0xb15c6(%rip), %rdi     # 0x4b40ad
callq 0x40d640
movq (%rbx), %rsi
pushq $0xa
popq %rdi
callq 0x416660
pushq $0x1
popq %rdi
callq 0x40c1f0