// File: /workspace/github_c_makefile_star2_O2/unixlab[P]cloudflare-udp-ping/net.c
// Function: net_bind_udp
int net_bind_udp(struct net_addr *shost, int reuseport, 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 (reuseport) {
		one = 1;
		r = setsockopt(sd, SOL_SOCKET, SO_REUSEPORT, (char *)&one,
			       sizeof(one));
		if (r < 0) {
			PFATAL("setsockopt(SO_REUSEPORT)");
		}
	}

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

	if (bind(sd, shost->sockaddr, shost->sockaddr_len) < 0) {
		PFATAL("bind()");
	}

	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)");
		}
	}

	return sd;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
subq $0x10, %rsp
movl %edx, %r14d
movl %esi, %r12d
movq %rdi, %r15
movl %edx, -0x28(%rbp)
pushq $0x2
popq %rdi
pushq $0x11
popq %rdx
movl %edi, %esi
callq 0x45f7c0
testl %eax, %eax
js 0x402348
movl %eax, %ebx
leaq -0x24(%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 0x402387
testl %r12d, %r12d
je 0x4022de
leaq -0x24(%rbp), %rcx
movl $0x1, (%rcx)
pushq $0x1
popq %rsi
pushq $0xf
popq %rdx
pushq $0x4
popq %r8
movl %ebx, %edi
callq 0x45f780
testl %eax, %eax
js 0x402441
leaq -0x24(%rbp), %rcx
movl $0x1, (%rcx)
pushq $0x8
popq %rdx
pushq $0x4
popq %r8
movl %ebx, %edi
xorl %esi, %esi
callq 0x45f780
testl %eax, %eax
js 0x4023c6
movq 0x30(%r15), %rsi
movl 0x38(%r15), %edx
movl %ebx, %edi
callq 0x45f530
testl %eax, %eax
js 0x402405
testl %r14d, %r14d
je 0x402339
pushq $0x1
popq %rsi
pushq $0x2e
popq %rdx
leaq -0x28(%rbp), %rcx
pushq $0x4
popq %r8
movl %ebx, %edi
callq 0x45f780
testl %eax, %eax
js 0x40247d
movl %ebx, %eax
addq $0x10, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq
movq $0x4e77a8, %rbx         # imm = 0x4E77A8
movq (%rbx), %rcx
leaq 0xb1fb2(%rip), %rdi     # 0x4b430b
pushq $0x1b
popq %rsi
pushq $0x1
popq %rdx
callq 0x4142f0
movq (%rbx), %rdi
leaq 0xb1d0d(%rip), %rsi     # 0x4b407b
leaq 0xb1fb2(%rip), %rdx     # 0x4b4327
leaq 0xb1eea(%rip), %rcx     # 0x4b4266
movl $0x8e, %r8d
jmp 0x4024b7
movq $0x4e77a8, %rbx         # imm = 0x4E77A8
movq (%rbx), %rcx
leaq 0xb1f9c(%rip), %rdi     # 0x4b4334
pushq $0x2b
popq %rsi
pushq $0x1
popq %rdx
callq 0x4142f0
movq (%rbx), %rdi
leaq 0xb1cce(%rip), %rsi     # 0x4b407b
leaq 0xb1f73(%rip), %rdx     # 0x4b4327
leaq 0xb1eab(%rip), %rcx     # 0x4b4266
movl $0x95, %r8d
jmp 0x4024b7
movq $0x4e77a8, %rbx         # imm = 0x4E77A8
movq (%rbx), %rcx
leaq 0xb1fb5(%rip), %rdi     # 0x4b438c
pushq $0x29
popq %rsi
pushq $0x1
popq %rdx
callq 0x4142f0
movq (%rbx), %rdi
leaq 0xb1c8f(%rip), %rsi     # 0x4b407b
leaq 0xb1f34(%rip), %rdx     # 0x4b4327
leaq 0xb1e6c(%rip), %rcx     # 0x4b4266
movl $0xa4, %r8d
jmp 0x4024b7
movq $0x4e77a8, %rbx         # imm = 0x4E77A8
movq (%rbx), %rcx
leaq 0xb1fa0(%rip), %rdi     # 0x4b43b6
pushq $0x19
popq %rsi
pushq $0x1
popq %rdx
callq 0x4142f0
movq (%rbx), %rdi
leaq 0xb1c50(%rip), %rsi     # 0x4b407b
leaq 0xb1ef5(%rip), %rdx     # 0x4b4327
leaq 0xb1e2d(%rip), %rcx     # 0x4b4266
movl $0xa8, %r8d
jmp 0x4024b7
movq $0x4e77a8, %rbx         # imm = 0x4E77A8
movq (%rbx), %rcx
leaq 0xb1f0e(%rip), %rdi     # 0x4b4360
pushq $0x2b
popq %rsi
pushq $0x1
popq %rdx
callq 0x4142f0
movq (%rbx), %rdi
leaq 0xb1c14(%rip), %rsi     # 0x4b407b
leaq 0xb1eb9(%rip), %rdx     # 0x4b4327
leaq 0xb1df1(%rip), %rcx     # 0x4b4266
movl $0x9d, %r8d
jmp 0x4024b7
movq $0x4e77a8, %rbx         # imm = 0x4E77A8
movq (%rbx), %rcx
leaq 0xb1f42(%rip), %rdi     # 0x4b43d0
pushq $0x2b
popq %rsi
pushq $0x1
popq %rdx
callq 0x4142f0
movq (%rbx), %rdi
leaq 0xb1bd8(%rip), %rsi     # 0x4b407b
leaq 0xb1e7d(%rip), %rdx     # 0x4b4327
leaq 0xb1db5(%rip), %rcx     # 0x4b4266
movl $0xaf, %r8d
xorl %eax, %eax
callq 0x40d290
leaq 0xb1be8(%rip), %rdi     # 0x4b40ad
callq 0x40d640
movq (%rbx), %rsi
pushq $0xa
popq %rdi
callq 0x416660
pushq $0x1
popq %rdi
callq 0x40c1f0