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

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

	one = 1;
	setsockopt(sd, IPPROTO_TCP, TCP_NODELAY, (char *)&one, sizeof(one));

	return sd;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x90, %rsp
movq %rdi, -0x10(%rbp)
movl %esi, -0x14(%rbp)
movl %edx, -0x18(%rbp)
movl $0x2, %edi
movl $0x1, %esi
movl $0x6, %edx
callq 0x460080
movl %eax, -0x1c(%rbp)
cmpl $0x0, -0x1c(%rbp)
jge 0x403646
jmp 0x4035d4
movq $0x4e87a8, %rax         # imm = 0x4E87A8
movq (%rax), %rdi
leaq 0xb1db4(%rip), %rsi     # 0x4b5399
movb $0x0, %al
callq 0x40df10
movq $0x4e87a8, %rax         # imm = 0x4E87A8
movq (%rax), %rdi
leaq 0xb1ace(%rip), %rsi     # 0x4b50cb
leaq 0xb1f46(%rip), %rdx     # 0x4b554a
leaq 0xb1ce9(%rip), %rcx     # 0x4b52f4
movl $0x134, %r8d            # imm = 0x134
movb $0x0, %al
callq 0x40df10
leaq 0xb1ade(%rip), %rdi     # 0x4b50fd
callq 0x40e2c0
movq $0x4e87a8, %rax         # imm = 0x4E87A8
movq (%rax), %rdi
leaq 0xb24d5(%rip), %rsi     # 0x4b5b0a
movb $0x0, %al
callq 0x40df10
movl $0x1, %edi
callq 0x40ce70
movl $0x1, -0x20(%rbp)
movl -0x1c(%rbp), %edi
movl $0x1, %esi
movl $0x2, %edx
leaq -0x20(%rbp), %rcx
movl $0x4, %r8d
callq 0x460040
movl %eax, -0x24(%rbp)
cmpl $0x0, -0x24(%rbp)
jge 0x4036e6
jmp 0x403674
movq $0x4e87a8, %rax         # imm = 0x4E87A8
movq (%rax), %rdi
leaq 0xb1d3d(%rip), %rsi     # 0x4b53c2
movb $0x0, %al
callq 0x40df10
movq $0x4e87a8, %rax         # imm = 0x4E87A8
movq (%rax), %rdi
leaq 0xb1a2e(%rip), %rsi     # 0x4b50cb
leaq 0xb1ea6(%rip), %rdx     # 0x4b554a
leaq 0xb1c49(%rip), %rcx     # 0x4b52f4
movl $0x13b, %r8d            # imm = 0x13B
movb $0x0, %al
callq 0x40df10
leaq 0xb1a3e(%rip), %rdi     # 0x4b50fd
callq 0x40e2c0
movq $0x4e87a8, %rax         # imm = 0x4E87A8
movq (%rax), %rdi
leaq 0xb2435(%rip), %rsi     # 0x4b5b0a
movb $0x0, %al
callq 0x40df10
movl $0x1, %edi
callq 0x40ce70
cmpl $0x0, -0x18(%rbp)
je 0x40378b
movl -0x1c(%rbp), %edi
movl $0x1, %esi
movl $0x2e, %edx
leaq -0x18(%rbp), %rcx
movl $0x4, %r8d
callq 0x460040
movl %eax, -0x24(%rbp)
cmpl $0x0, -0x24(%rbp)
jge 0x403789
jmp 0x403717
movq $0x4e87a8, %rax         # imm = 0x4E87A8
movq (%rax), %rdi
leaq 0xb1d36(%rip), %rsi     # 0x4b545e
movb $0x0, %al
callq 0x40df10
movq $0x4e87a8, %rax         # imm = 0x4E87A8
movq (%rax), %rdi
leaq 0xb198b(%rip), %rsi     # 0x4b50cb
leaq 0xb1e03(%rip), %rdx     # 0x4b554a
leaq 0xb1ba6(%rip), %rcx     # 0x4b52f4
movl $0x142, %r8d            # imm = 0x142
movb $0x0, %al
callq 0x40df10
leaq 0xb199b(%rip), %rdi     # 0x4b50fd
callq 0x40e2c0
movq $0x4e87a8, %rax         # imm = 0x4E87A8
movq (%rax), %rdi
leaq 0xb2392(%rip), %rsi     # 0x4b5b0a
movb $0x0, %al
callq 0x40df10
movl $0x1, %edi
callq 0x40ce70
jmp 0x40378b
cmpl $0x1, -0x14(%rbp)
jle 0x403869
cmpl $0x10000, -0x14(%rbp)   # imm = 0x10000
jge 0x403869
leaq -0x68(%rbp), %rdi
xorl %esi, %esi
movl $0x40, %edx
callq 0x4010a8
leaq -0x90(%rbp), %rdi
movl -0x14(%rbp), %ecx
movl $0x20, %esi
leaq 0xb1d5a(%rip), %rdx     # 0x4b5522
movb $0x0, %al
callq 0x40e0a0
leaq -0x90(%rbp), %rsi
leaq -0x68(%rbp), %rdi
callq 0x402510
movl -0x1c(%rbp), %edi
movq -0x38(%rbp), %rsi
movl -0x30(%rbp), %edx
callq 0x45fdb0
cmpl $0x0, %eax
jge 0x403867
jmp 0x4037f5
movq $0x4e87a8, %rax         # imm = 0x4E87A8
movq (%rax), %rdi
leaq 0xb1c3e(%rip), %rsi     # 0x4b5444
movb $0x0, %al
callq 0x40df10
movq $0x4e87a8, %rax         # imm = 0x4E87A8
movq (%rax), %rdi
leaq 0xb18ad(%rip), %rsi     # 0x4b50cb
leaq 0xb1d25(%rip), %rdx     # 0x4b554a
leaq 0xb1ac8(%rip), %rcx     # 0x4b52f4
movl $0x14d, %r8d            # imm = 0x14D
movb $0x0, %al
callq 0x40df10
leaq 0xb18bd(%rip), %rdi     # 0x4b50fd
callq 0x40e2c0
movq $0x4e87a8, %rax         # imm = 0x4E87A8
movq (%rax), %rdi
leaq 0xb22b4(%rip), %rsi     # 0x4b5b0a
movb $0x0, %al
callq 0x40df10
movl $0x1, %edi
callq 0x40ce70
jmp 0x403869
movl -0x1c(%rbp), %edi
movq -0x10(%rbp), %rax
movq 0x30(%rax), %rsi
movq -0x10(%rbp), %rax
movl 0x38(%rax), %edx
callq 0x45fde0
movl %eax, %ecx
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
cmpl %ecx, %eax
jne 0x403916
callq 0x406610
movq %rax, %rcx
movl $0x73, %eax
cmpl (%rcx), %eax
je 0x403914
jmp 0x4038a2
movq $0x4e87a8, %rax         # imm = 0x4E87A8
movq (%rax), %rdi
leaq 0xb1c7a(%rip), %rsi     # 0x4b552d
movb $0x0, %al
callq 0x40df10
movq $0x4e87a8, %rax         # imm = 0x4E87A8
movq (%rax), %rdi
leaq 0xb1800(%rip), %rsi     # 0x4b50cb
leaq 0xb1c78(%rip), %rdx     # 0x4b554a
leaq 0xb1a1b(%rip), %rcx     # 0x4b52f4
movl $0x154, %r8d            # imm = 0x154
movb $0x0, %al
callq 0x40df10
leaq 0xb1810(%rip), %rdi     # 0x4b50fd
callq 0x40e2c0
movq $0x4e87a8, %rax         # imm = 0x4E87A8
movq (%rax), %rdi
leaq 0xb2207(%rip), %rsi     # 0x4b5b0a
movb $0x0, %al
callq 0x40df10
movl $0x1, %edi
callq 0x40ce70
jmp 0x403916
movl $0x1, -0x20(%rbp)
movl -0x1c(%rbp), %edi
movl $0x6, %esi
movl $0x1, %edx
leaq -0x20(%rbp), %rcx
movl $0x4, %r8d
callq 0x460040
movl -0x1c(%rbp), %eax
movl %eax, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x90, %rsp
popq %rbp
retq
nopl (%rax,%rax)