// File: /workspace/github_c_makefile_star2_O0/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
subq $0x20, %rsp
movq %rdi, -0x8(%rbp)
movl %esi, -0xc(%rbp)
movl %edx, -0x10(%rbp)
movl $0x2, %esi
movl $0x11, %edx
movl %esi, %edi
callq 0x460080
movl %eax, -0x14(%rbp)
cmpl $0x0, -0x14(%rbp)
jge 0x402960
jmp 0x4028ee
movq $0x4e87a8, %rax         # imm = 0x4E87A8
movq (%rax), %rdi
leaq 0xb2a9a(%rip), %rsi     # 0x4b5399
movb $0x0, %al
callq 0x40df10
movq $0x4e87a8, %rax         # imm = 0x4E87A8
movq (%rax), %rdi
leaq 0xb27b4(%rip), %rsi     # 0x4b50cb
leaq 0xb2a97(%rip), %rdx     # 0x4b53b5
leaq 0xb29cf(%rip), %rcx     # 0x4b52f4
movl $0x8e, %r8d
movb $0x0, %al
callq 0x40df10
leaq 0xb27c4(%rip), %rdi     # 0x4b50fd
callq 0x40e2c0
movq $0x4e87a8, %rax         # imm = 0x4E87A8
movq (%rax), %rdi
leaq 0xb31bb(%rip), %rsi     # 0x4b5b0a
movb $0x0, %al
callq 0x40df10
movl $0x1, %edi
callq 0x40ce70
movl $0x1, -0x18(%rbp)
movl -0x14(%rbp), %edi
movl $0x1, %esi
movl $0x2, %edx
leaq -0x18(%rbp), %rcx
movl $0x4, %r8d
callq 0x460040
movl %eax, -0x1c(%rbp)
cmpl $0x0, -0x1c(%rbp)
jge 0x402a00
jmp 0x40298e
movq $0x4e87a8, %rax         # imm = 0x4E87A8
movq (%rax), %rdi
leaq 0xb2a23(%rip), %rsi     # 0x4b53c2
movb $0x0, %al
callq 0x40df10
movq $0x4e87a8, %rax         # imm = 0x4E87A8
movq (%rax), %rdi
leaq 0xb2714(%rip), %rsi     # 0x4b50cb
leaq 0xb29f7(%rip), %rdx     # 0x4b53b5
leaq 0xb292f(%rip), %rcx     # 0x4b52f4
movl $0x95, %r8d
movb $0x0, %al
callq 0x40df10
leaq 0xb2724(%rip), %rdi     # 0x4b50fd
callq 0x40e2c0
movq $0x4e87a8, %rax         # imm = 0x4E87A8
movq (%rax), %rdi
leaq 0xb311b(%rip), %rsi     # 0x4b5b0a
movb $0x0, %al
callq 0x40df10
movl $0x1, %edi
callq 0x40ce70
cmpl $0x0, -0xc(%rbp)
je 0x402aac
movl $0x1, -0x18(%rbp)
movl -0x14(%rbp), %edi
movl $0x1, %esi
movl $0xf, %edx
leaq -0x18(%rbp), %rcx
movl $0x4, %r8d
callq 0x460040
movl %eax, -0x1c(%rbp)
cmpl $0x0, -0x1c(%rbp)
jge 0x402aaa
jmp 0x402a38
movq $0x4e87a8, %rax         # imm = 0x4E87A8
movq (%rax), %rdi
leaq 0xb29a5(%rip), %rsi     # 0x4b53ee
movb $0x0, %al
callq 0x40df10
movq $0x4e87a8, %rax         # imm = 0x4E87A8
movq (%rax), %rdi
leaq 0xb266a(%rip), %rsi     # 0x4b50cb
leaq 0xb294d(%rip), %rdx     # 0x4b53b5
leaq 0xb2885(%rip), %rcx     # 0x4b52f4
movl $0x9d, %r8d
movb $0x0, %al
callq 0x40df10
leaq 0xb267a(%rip), %rdi     # 0x4b50fd
callq 0x40e2c0
movq $0x4e87a8, %rax         # imm = 0x4E87A8
movq (%rax), %rdi
leaq 0xb3071(%rip), %rsi     # 0x4b5b0a
movb $0x0, %al
callq 0x40df10
movl $0x1, %edi
callq 0x40ce70
jmp 0x402aac
movl $0x1, -0x18(%rbp)
movl -0x14(%rbp), %edi
xorl %esi, %esi
movl $0x8, %edx
leaq -0x18(%rbp), %rcx
movl $0x4, %r8d
callq 0x460040
movl %eax, -0x1c(%rbp)
cmpl $0x0, -0x1c(%rbp)
jge 0x402b49
jmp 0x402ad7
movq $0x4e87a8, %rax         # imm = 0x4E87A8
movq (%rax), %rdi
leaq 0xb2932(%rip), %rsi     # 0x4b541a
movb $0x0, %al
callq 0x40df10
movq $0x4e87a8, %rax         # imm = 0x4E87A8
movq (%rax), %rdi
leaq 0xb25cb(%rip), %rsi     # 0x4b50cb
leaq 0xb28ae(%rip), %rdx     # 0x4b53b5
leaq 0xb27e6(%rip), %rcx     # 0x4b52f4
movl $0xa4, %r8d
movb $0x0, %al
callq 0x40df10
leaq 0xb25db(%rip), %rdi     # 0x4b50fd
callq 0x40e2c0
movq $0x4e87a8, %rax         # imm = 0x4E87A8
movq (%rax), %rdi
leaq 0xb2fd2(%rip), %rsi     # 0x4b5b0a
movb $0x0, %al
callq 0x40df10
movl $0x1, %edi
callq 0x40ce70
movl -0x14(%rbp), %edi
movq -0x8(%rbp), %rax
movq 0x30(%rax), %rsi
movq -0x8(%rbp), %rax
movl 0x38(%rax), %edx
callq 0x45fdb0
cmpl $0x0, %eax
jge 0x402bd9
jmp 0x402b67
movq $0x4e87a8, %rax         # imm = 0x4E87A8
movq (%rax), %rdi
leaq 0xb28cc(%rip), %rsi     # 0x4b5444
movb $0x0, %al
callq 0x40df10
movq $0x4e87a8, %rax         # imm = 0x4E87A8
movq (%rax), %rdi
leaq 0xb253b(%rip), %rsi     # 0x4b50cb
leaq 0xb281e(%rip), %rdx     # 0x4b53b5
leaq 0xb2756(%rip), %rcx     # 0x4b52f4
movl $0xa8, %r8d
movb $0x0, %al
callq 0x40df10
leaq 0xb254b(%rip), %rdi     # 0x4b50fd
callq 0x40e2c0
movq $0x4e87a8, %rax         # imm = 0x4E87A8
movq (%rax), %rdi
leaq 0xb2f42(%rip), %rsi     # 0x4b5b0a
movb $0x0, %al
callq 0x40df10
movl $0x1, %edi
callq 0x40ce70
cmpl $0x0, -0x10(%rbp)
je 0x402c7e
movl -0x14(%rbp), %edi
movl $0x1, %esi
movl $0x2e, %edx
leaq -0x10(%rbp), %rcx
movl $0x4, %r8d
callq 0x460040
movl %eax, -0x1c(%rbp)
cmpl $0x0, -0x1c(%rbp)
jge 0x402c7c
jmp 0x402c0a
movq $0x4e87a8, %rax         # imm = 0x4E87A8
movq (%rax), %rdi
leaq 0xb2843(%rip), %rsi     # 0x4b545e
movb $0x0, %al
callq 0x40df10
movq $0x4e87a8, %rax         # imm = 0x4E87A8
movq (%rax), %rdi
leaq 0xb2498(%rip), %rsi     # 0x4b50cb
leaq 0xb277b(%rip), %rdx     # 0x4b53b5
leaq 0xb26b3(%rip), %rcx     # 0x4b52f4
movl $0xaf, %r8d
movb $0x0, %al
callq 0x40df10
leaq 0xb24a8(%rip), %rdi     # 0x4b50fd
callq 0x40e2c0
movq $0x4e87a8, %rax         # imm = 0x4E87A8
movq (%rax), %rdi
leaq 0xb2e9f(%rip), %rsi     # 0x4b5b0a
movb $0x0, %al
callq 0x40df10
movl $0x1, %edi
callq 0x40ce70
jmp 0x402c7e
movl -0x14(%rbp), %eax
addq $0x20, %rsp
popq %rbp
retq
nopw (%rax,%rax)