// File: /workspace/github_c_makefile_star2_O3/unixlab[P]cloudflare-udp-ping/udpserver.c
// Function: main
int main(int argc, const char *argv[])
{
	const char *listen_addr_str = "0.0.0.0:4321";
	int thread_num = 1;
	int reuseport = 0;
	int polling = 0;
	int busy_poll = 0;

	static struct option long_options[] = {
		{"busy-poll", required_argument, 0, 'b'},
		{"threads", required_argument, 0, 't'},
		{"polling", no_argument, 0, 'p'},
		{"reuseport", no_argument, 0, 'r'},
		{"listen", required_argument, 0, 'l'},
		{NULL, 0, 0, 0}};
	const char *optstring = optstring_from_long_options(long_options);

	optind = 1;
	while (1) {
		int option_index = 0;
		int arg = getopt_long(argc, (char **)argv, optstring,
				      long_options, &option_index);
		if (arg == -1) {
			break;
		}

		switch (arg) {
		case 'b':
			busy_poll = atoi(optarg);
			break;

		case 't':
			thread_num = atoi(optarg);
			break;

		case 'p':
			polling = 1;
			break;

		case 'r':
			reuseport = 1;
			break;

		case 'l':
			listen_addr_str = optarg;
			break;

		default:
			FATAL("Unknown option %c: %s", arg, argv[optind]);
		}
	}

	if (optind != argc) {
		FATAL("Usage: %s [--buf-size=<>] [--threads=<>] [--polling] "
		      "[--reuseport] [--listen=]",
		      argv[0]);
	}

	struct net_addr listen_addr;
	parse_addr(&listen_addr, listen_addr_str);

	int main_fd = -1;
	if (reuseport == 0) {
		fprintf(stderr,
			"[*] Starting udpreceiver on %s, "
			"polling=%i, busy_poll=%i, threads=%i, reuseport=%i\n",
			addr_to_str(&listen_addr), polling, busy_poll,
			thread_num, reuseport);

		main_fd = net_bind_udp(&listen_addr, 0, busy_poll);
	}

	struct state *array_of_states =
		calloc(thread_num, sizeof(struct state));

	int t;
	for (t = 0; t < thread_num; t++) {
		struct state *state = &array_of_states[t];
		state_init(state);
		state->polling = polling;
		if (reuseport == 0) {
			state->fd = main_fd;
		} else {
			fprintf(stderr, "[*] Starting udpreceiver on %s\n",
				addr_to_str(&listen_addr));

			int fd = net_bind_udp(&listen_addr, 1, busy_poll);
			state->fd = fd;
		}
		thread_spawn(thread_loop, state);
	}

	while (1) {
		struct timeval timeout = NSEC_TIMEVAL(MSEC_NSEC(1000UL));
		while (1) {
			int r = select(0, NULL, NULL, NULL, &timeout);
			if (r != 0) {
				continue;
			}
			if (TIMEVAL_NSEC(&timeout) == 0) {
				break;
			}
		}
	}

	return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x88, %rsp
movq %rsi, %r12
movl %edi, %r13d
leaq 0xe4f03(%rip), %rbx     # 0x4e7110
movq %rbx, %rdi
callq 0x402e41
movq %rax, %r14
movq $0x4e8160, %r15         # imm = 0x4E8160
movl $0x1, (%r15)
leaq -0xa0(%rbp), %r8
movl $0x0, (%r8)
movl %r13d, %edi
movq %r12, %rsi
movq %rax, %rdx
movq %rbx, %rcx
callq 0x45c040
cmpl $-0x1, %eax
je 0x40245a
movl $0x0, -0x34(%rbp)
movl $0x1, -0x40(%rbp)
leaq 0xb1dc9(%rip), %rcx     # 0x4b402c
movq %rcx, -0x48(%rbp)
leaq 0xb1d96(%rip), %r15     # 0x4b4004
leaq -0xa0(%rbp), %rbx
movl $0x0, -0x30(%rbp)
movl $0x0, -0x2c(%rbp)
leal -0x62(%rax), %ecx
rorl %ecx
cmpl $0x9, %ecx
ja 0x4024e9
movslq (%r15,%rcx,4), %rcx
addq %r15, %rcx
jmpq *%rcx
movq $0x4eea80, %rax         # imm = 0x4EEA80
movq (%rax), %rdi
callq 0x40b700
movl %eax, -0x2c(%rbp)
jmp 0x4022e2
movq $0x4eea80, %rax         # imm = 0x4EEA80
movq (%rax), %rdi
callq 0x40b700
movl %eax, -0x40(%rbp)
jmp 0x4022e2
movl $0x1, -0x30(%rbp)
jmp 0x4022e2
movl $0x1, -0x34(%rbp)
jmp 0x4022e2
movq $0x4eea80, %rax         # imm = 0x4EEA80
movq (%rax), %rax
movq %rax, -0x48(%rbp)
movl $0x0, -0xa0(%rbp)
movl %r13d, %edi
movq %r12, %rsi
movq %r14, %rdx
leaq 0xe4e14(%rip), %rcx     # 0x4e7110
movq %rbx, %r8
callq 0x45c040
cmpl $-0x1, %eax
jne 0x402283
movq $0x4e8160, %rax         # imm = 0x4E8160
cmpl %r13d, (%rax)
jne 0x402531
leaq -0xa0(%rbp), %rdi
movq -0x48(%rbp), %rsi
callq 0x4026eb
cmpl $0x0, -0x34(%rbp)
movl -0x40(%rbp), %r13d
je 0x402484
xorl %r12d, %r12d
movl $0xffffffff, %r14d      # imm = 0xFFFFFFFF
movslq %r13d, %r15
movl $0x1800, %esi           # imm = 0x1800
movq %r15, %rdi
callq 0x426970
testl %r15d, %r15d
jle 0x402423
movq %rax, %rbx
movl %r13d, %r13d
leaq 0x212(%rip), %r15       # 0x40257c
leaq 0x8(%rbx), %rax
movq %rax, 0x28(%rbx)
movl $0x1c, 0x30(%rbx)
leaq 0x7e0(%rbx), %rax
movq %rax, 0x38(%rbx)
movq $0x1, 0x40(%rbx)
leaq 0x7f0(%rbx), %rax
movq %rax, 0x48(%rbx)
movq $0x1000, 0x50(%rbx)     # imm = 0x1000
leaq 0x60(%rbx), %rax
movq %rax, 0x7e0(%rbx)
movq $0x780, 0x7e8(%rbx) # imm = 0x780
movl -0x30(%rbp), %eax
movl %eax, 0x4(%rbx)
movl %r14d, %eax
testb %r12b, %r12b
je 0x4023de
movl %eax, (%rbx)
movq %r15, %rdi
movq %rbx, %rsi
callq 0x402aad
addq $0x1800, %rbx           # imm = 0x1800
decq %r13
jne 0x40236a
jmp 0x402423
movq $0x4e77c8, %rax         # imm = 0x4E77C8
movq (%rax), %rax
movq %rax, -0x40(%rbp)
leaq -0xa0(%rbp), %rdi
callq 0x402848
movq -0x40(%rbp), %rdi
leaq 0xb1d69(%rip), %rsi     # 0x4b416c
movq %rax, %rdx
xorl %eax, %eax
callq 0x40d320
leaq -0xa0(%rbp), %rdi
movl $0x1, %esi
movl -0x2c(%rbp), %edx
callq 0x4028d5
jmp 0x4023c3
movups 0xb1dd6(%rip), %xmm0    # 0x4b4200
movaps %xmm0, -0x60(%rbp)
leaq -0x60(%rbp), %r8
xorl %edi, %edi
xorl %esi, %esi
xorl %edx, %edx
xorl %ecx, %ecx
callq 0x45d280
testl %eax, %eax
jne 0x40242e
imulq $0x3b9aca00, -0x60(%rbp), %rax # imm = 0x3B9ACA00
imulq $-0x3e8, -0x58(%rbp), %rcx # imm = 0xFC18
cmpq %rcx, %rax
jne 0x40242e
jmp 0x402423
cmpl %r13d, (%r15)
jne 0x402531
leaq 0xb1bc2(%rip), %rsi     # 0x4b402c
leaq -0xa0(%rbp), %rdi
callq 0x4026eb
movl $0x1, %r13d
xorl %r12d, %r12d
xorl %r15d, %r15d
jmp 0x40248c
movl -0x30(%rbp), %r15d
movl -0x2c(%rbp), %r12d
movq $0x4e77c8, %rax         # imm = 0x4E77C8
movq (%rax), %rbx
leaq -0xa0(%rbp), %r14
movq %r14, %rdi
callq 0x402848
movl $0x0, (%rsp)
leaq 0xb1c65(%rip), %rsi     # 0x4b4118
movq %rbx, %rdi
movq %rax, %rdx
movl %r15d, -0x30(%rbp)
movl %r15d, %ecx
movl %r12d, %r8d
movl %r13d, %r9d
xorl %eax, %eax
callq 0x40d320
movq %r14, %rdi
xorl %esi, %esi
movl %r12d, -0x2c(%rbp)
movl %r12d, %edx
callq 0x4028d5
movl %eax, %r14d
movb $0x1, %r12b
jmp 0x402344
movq $0x4e77c8, %rbx         # imm = 0x4E77C8
movq (%rbx), %rdi
movq $0x4e8160, %rcx         # imm = 0x4E8160
movslq (%rcx), %rcx
movq (%r12,%rcx,8), %rcx
leaq 0xb1b5c(%rip), %rsi     # 0x4b4064
movl %eax, %edx
xorl %eax, %eax
callq 0x40d320
movq (%rbx), %rdi
leaq 0xb1b73(%rip), %rsi     # 0x4b408e
leaq 0xc910b(%rip), %rdx     # 0x4cb62d
leaq 0xb1b80(%rip), %rcx     # 0x4b40a9
movl $0x80, %r8d
jmp 0x40256b
movq $0x4e77c8, %rbx         # imm = 0x4E77C8
movq (%rbx), %rdi
movq (%r12), %rdx
leaq 0xb1b6f(%rip), %rsi     # 0x4b40b5
xorl %eax, %eax
callq 0x40d320
movq (%rbx), %rdi
leaq 0xb1b37(%rip), %rsi     # 0x4b408e
leaq 0xc90cf(%rip), %rdx     # 0x4cb62d
leaq 0xb1b44(%rip), %rcx     # 0x4b40a9
movl $0x87, %r8d
xorl %eax, %eax
callq 0x40d320
movl $0x1, %edi
callq 0x40c280