// File: /workspace/github_c_makefile_star2_O2/unixlab[P]cloudflare-udp-ping/net.c
// Function: net_bind_tcp
int net_bind_tcp(struct net_addr *shost, int reuseport)
{
	int sd = socket(PF_INET, SOCK_STREAM, IPPROTO_TCP);
	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)");
		}
	}

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

	r = listen(sd, 128);
	if (r < 0) {
		PFATAL("listen()");
	}

	return sd;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %rbx
pushq %rax
movl %esi, %r15d
movq %rdi, %r14
pushq $0x2
popq %rdi
pushq $0x1
popq %rsi
pushq $0x6
popq %rdx
callq 0x45f7c0
testl %eax, %eax
js 0x402588
movl %eax, %ebx
leaq -0x1c(%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 0x4025c7
testl %r15d, %r15d
je 0x402550
leaq -0x1c(%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 0x40267e
movq 0x30(%r14), %rsi
movl 0x38(%r14), %edx
movl %ebx, %edi
callq 0x45f530
testl %eax, %eax
js 0x402606
movl %ebx, %edi
movl $0x80, %esi
callq 0x45f600
testl %eax, %eax
js 0x402642
movl %ebx, %eax
addq $0x8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
retq
movq $0x4e77a8, %rbx         # imm = 0x4E77A8
movq (%rbx), %rcx
leaq 0xb1d72(%rip), %rdi     # 0x4b430b
pushq $0x1b
popq %rsi
pushq $0x1
popq %rdx
callq 0x4142f0
movq (%rbx), %rdi
leaq 0xb1acd(%rip), %rsi     # 0x4b407b
leaq 0xb1e47(%rip), %rdx     # 0x4b43fc
leaq 0xb1caa(%rip), %rcx     # 0x4b4266
movl $0xba, %r8d
jmp 0x4026b8
movq $0x4e77a8, %rbx         # imm = 0x4E77A8
movq (%rbx), %rcx
leaq 0xb1d5c(%rip), %rdi     # 0x4b4334
pushq $0x2b
popq %rsi
pushq $0x1
popq %rdx
callq 0x4142f0
movq (%rbx), %rdi
leaq 0xb1a8e(%rip), %rsi     # 0x4b407b
leaq 0xb1e08(%rip), %rdx     # 0x4b43fc
leaq 0xb1c6b(%rip), %rcx     # 0x4b4266
movl $0xc1, %r8d
jmp 0x4026b8
movq $0x4e77a8, %rbx         # imm = 0x4E77A8
movq (%rbx), %rcx
leaq 0xb1d9f(%rip), %rdi     # 0x4b43b6
pushq $0x19
popq %rsi
pushq $0x1
popq %rdx
callq 0x4142f0
movq (%rbx), %rdi
leaq 0xb1a4f(%rip), %rsi     # 0x4b407b
leaq 0xb1dc9(%rip), %rdx     # 0x4b43fc
leaq 0xb1c2c(%rip), %rcx     # 0x4b4266
movl $0xcf, %r8d
jmp 0x4026b8
movq $0x4e77a8, %rbx         # imm = 0x4E77A8
movq (%rbx), %rcx
leaq 0xb1db6(%rip), %rdi     # 0x4b4409
pushq $0x1b
popq %rsi
pushq $0x1
popq %rdx
callq 0x4142f0
movq (%rbx), %rdi
leaq 0xb1a13(%rip), %rsi     # 0x4b407b
leaq 0xb1d8d(%rip), %rdx     # 0x4b43fc
leaq 0xb1bf0(%rip), %rcx     # 0x4b4266
movl $0xd4, %r8d
jmp 0x4026b8
movq $0x4e77a8, %rbx         # imm = 0x4E77A8
movq (%rbx), %rcx
leaq 0xb1cd1(%rip), %rdi     # 0x4b4360
pushq $0x2b
popq %rsi
pushq $0x1
popq %rdx
callq 0x4142f0
movq (%rbx), %rdi
leaq 0xb19d7(%rip), %rsi     # 0x4b407b
leaq 0xb1d51(%rip), %rdx     # 0x4b43fc
leaq 0xb1bb4(%rip), %rcx     # 0x4b4266
movl $0xc9, %r8d
xorl %eax, %eax
callq 0x40d290
leaq 0xb19e7(%rip), %rdi     # 0x4b40ad
callq 0x40d640
movq (%rbx), %rsi
pushq $0xa
popq %rdi
callq 0x416660
pushq $0x1
popq %rdi
callq 0x40c1f0