// File: ctSkennerton[P]fxtract/util/concurs.c
// Function: record
static void
record(int skt)
{
    char	mode[] = { RECORD };

    max_fd     = skt;
    FD_ZERO(&open_fds);
    FD_SET(skt, &open_fds);

    while (1) {
	int    fd, nfds;
	fd_set    read_fds = open_fds, error_fds = open_fds;
	char    buf[MAX_CONCUR_MSG];

	if (0 > (nfds = select(max_fd+1, &read_fds, NULL, &error_fds, 0))) {
	    if (errno == EINTR)
		continue;
	    fprintf(stderr, "# concurs: select failed: %s\n", strerror(errno));
	    exit(1);
	}

	if (FD_ISSET(skt, &read_fds)) {
	    --nfds;
	    fd = sock_accept(skt);

	    if (0 >= sock_recv(fd, buf, sizeof buf)) {
		fprintf(stderr, "concurs: recv new player failed: %s\n", strerror(errno));
	    } else {
		sock_send(fd, mode, sizeof(mode));
		playerv[fd] = strdup(buf);
		printf("%s:%s\n", buf, buf);
		FD_SET(fd, &open_fds);
		if (max_fd < fd) max_fd = fd;
	    }
	}

	for (fd = skt+1; nfds > 0; ++fd) {
	    int    endit = 0, ret;

	    if (FD_ISSET(fd, &read_fds)) {
		--nfds;
		ret = sock_recv(fd, buf, sizeof(buf));
		if (ret < 0)
		    fprintf(stderr, "concurs: error reading %s\n", playerv[fd]);
		if (ret > 0)
		    printf("%s:%.*s\n", playerv[fd], ret, buf);
		else    endit = 1;
	    }

	    if (FD_ISSET(fd, &error_fds)) {
		--nfds;
		endit = 1;
		fprintf(stderr, "concurs: error from %s\n", playerv[fd]);
	    }

	    if (endit) {
		close(fd);
		FD_CLR(fd, &open_fds);
		free(playerv[fd]);
		playerv[fd] = NULL;
		while (max_fd > skt && !playerv[max_fd])
		    --max_fd;
	    }
	}
    }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x570, %rsp            # imm = 0x570
movl %edi, -0x4(%rbp)
movb 0x5a6c(%rip), %al       # 0x9130
movb %al, -0x5(%rbp)
movl -0x4(%rbp), %eax
movl %eax, 0x91a0(%rip)      # 0xc870
leaq 0x91a1(%rip), %rax      # 0xc878
movq %rax, -0x18(%rbp)
movl $0x0, -0xc(%rbp)
movl -0xc(%rbp), %eax
cmpq $0x10, %rax
jae 0x3705
movq -0x18(%rbp), %rax
movl -0xc(%rbp), %ecx
movq $0x0, (%rax,%rcx,8)
movl -0xc(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xc(%rbp)
jmp 0x36e2
jmp 0x3707
movl -0x4(%rbp), %eax
movl $0x40, %ecx
cltd
idivl %ecx
movl %edx, %eax
movl %eax, %ecx
movl $0x1, %eax
shlq %cl, %rax
movq %rax, -0x530(%rbp)
movl -0x4(%rbp), %eax
movl $0x40, %ecx
cltd
idivl %ecx
movq -0x530(%rbp), %rdx
movslq %eax, %rcx
leaq 0x9137(%rip), %rax      # 0xc878
orq (%rax,%rcx,8), %rdx
leaq 0x912c(%rip), %rax      # 0xc878
movq %rdx, (%rax,%rcx,8)
leaq -0xa0(%rbp), %rdi
leaq 0x911a(%rip), %rsi      # 0xc878
movl $0x80, %edx
callq 0x3200
leaq -0x120(%rbp), %rdi
leaq 0x9102(%rip), %rsi      # 0xc878
movl $0x80, %edx
callq 0x3200
movl 0x90ea(%rip), %edi      # 0xc870
addl $0x1, %edi
leaq -0xa0(%rbp), %rsi
xorl %eax, %eax
movl %eax, %r8d
leaq -0x120(%rbp), %rcx
movq %r8, %rdx
callq 0x3280
movl %eax, %ecx
movl %ecx, -0x20(%rbp)
xorl %eax, %eax
cmpl %ecx, %eax
jle 0x37fa
callq 0x3040
cmpl $0x4, (%rax)
jne 0x37bb
jmp 0x3750
movq 0x8816(%rip), %rax      # 0xbfd8
movq (%rax), %rax
movq %rax, -0x538(%rbp)
callq 0x3040
movl (%rax), %edi
callq 0x30f0
movq -0x538(%rbp), %rdi
movq %rax, %rdx
leaq 0x582f(%rip), %rsi      # 0x9018
movb $0x0, %al
callq 0x3390
movl $0x1, %edi
callq 0x3330
movl -0x4(%rbp), %eax
movl $0x40, %ecx
cltd
idivl %ecx
cltq
movq -0xa0(%rbp,%rax,8), %rax
movq %rax, -0x540(%rbp)
movl -0x4(%rbp), %eax
movl $0x40, %ecx
cltd
idivl %ecx
movq -0x540(%rbp), %rax
movl %edx, %ecx
movl $0x1, %edx
shlq %cl, %rdx
movq %rdx, %rcx
andq %rcx, %rax
cmpq $0x0, %rax
je 0x3958
movl -0x20(%rbp), %eax
addl $-0x1, %eax
movl %eax, -0x20(%rbp)
movl -0x4(%rbp), %edi
callq 0x78c0
movl %eax, -0x1c(%rbp)
movl -0x1c(%rbp), %edi
leaq -0x520(%rbp), %rsi
movl $0x400, %edx            # imm = 0x400
callq 0x8520
movl %eax, %ecx
xorl %eax, %eax
cmpl %ecx, %eax
jl 0x38ac
movq 0x875f(%rip), %rax      # 0xbfd8
movq (%rax), %rax
movq %rax, -0x548(%rbp)
callq 0x3040
movl (%rax), %edi
callq 0x30f0
movq -0x548(%rbp), %rdi
movq %rax, %rdx
leaq 0x5796(%rip), %rsi      # 0x9036
movb $0x0, %al
callq 0x3390
jmp 0x3956
movl -0x1c(%rbp), %edi
leaq -0x5(%rbp), %rsi
movl $0x1, %edx
callq 0x8580
leaq -0x520(%rbp), %rdi
callq 0x3460
movq %rax, %rdx
movslq -0x1c(%rbp), %rcx
leaq 0x9029(%rip), %rax      # 0xc900
movq %rdx, (%rax,%rcx,8)
leaq -0x520(%rbp), %rsi
leaq -0x520(%rbp), %rdx
leaq 0x5828(%rip), %rdi      # 0x9118
movb $0x0, %al
callq 0x3050
movl -0x1c(%rbp), %eax
movl $0x40, %ecx
cltd
idivl %ecx
movl %edx, %eax
movl %eax, %ecx
movl $0x1, %eax
shlq %cl, %rax
movq %rax, -0x550(%rbp)
movl -0x1c(%rbp), %eax
movl $0x40, %ecx
cltd
idivl %ecx
movq -0x550(%rbp), %rdx
movslq %eax, %rcx
leaq 0x8f47(%rip), %rax      # 0xc878
orq (%rax,%rcx,8), %rdx
leaq 0x8f3c(%rip), %rax      # 0xc878
movq %rdx, (%rax,%rcx,8)
movl 0x8f2a(%rip), %eax      # 0xc870
cmpl -0x1c(%rbp), %eax
jge 0x3954
movl -0x1c(%rbp), %eax
movl %eax, 0x8f1c(%rip)      # 0xc870
jmp 0x3956
jmp 0x3958
movl -0x4(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x1c(%rbp)
cmpl $0x0, -0x20(%rbp)
jle 0x3bb8
movl $0x0, -0x524(%rbp)
movl -0x1c(%rbp), %eax
movl $0x40, %ecx
cltd
idivl %ecx
cltq
movq -0xa0(%rbp,%rax,8), %rax
movq %rax, -0x558(%rbp)
movl -0x1c(%rbp), %eax
movl $0x40, %ecx
cltd
idivl %ecx
movq -0x558(%rbp), %rax
movl %edx, %ecx
movl $0x1, %edx
shlq %cl, %rdx
movq %rdx, %rcx
andq %rcx, %rax
cmpq $0x0, %rax
je 0x3a51
movl -0x20(%rbp), %eax
addl $-0x1, %eax
movl %eax, -0x20(%rbp)
movl -0x1c(%rbp), %edi
leaq -0x520(%rbp), %rsi
movl $0x400, %edx            # imm = 0x400
callq 0x8520
movl %eax, -0x528(%rbp)
cmpl $0x0, -0x528(%rbp)
jge 0x3a10
movq 0x85e8(%rip), %rax      # 0xbfd8
movq (%rax), %rdi
movslq -0x1c(%rbp), %rcx
leaq 0x8f02(%rip), %rax      # 0xc900
movq (%rax,%rcx,8), %rdx
leaq 0x5652(%rip), %rsi      # 0x905b
movb $0x0, %al
callq 0x3390
cmpl $0x0, -0x528(%rbp)
jle 0x3a45
movslq -0x1c(%rbp), %rcx
leaq 0x8edc(%rip), %rax      # 0xc900
movq (%rax,%rcx,8), %rsi
movl -0x528(%rbp), %edx
leaq -0x520(%rbp), %rcx
leaq 0x563a(%rip), %rdi      # 0x9076
movb $0x0, %al
callq 0x3050
jmp 0x3a4f
movl $0x1, -0x524(%rbp)
jmp 0x3a51
movl -0x1c(%rbp), %eax
movl $0x40, %ecx
cltd
idivl %ecx
cltq
movq -0x120(%rbp,%rax,8), %rax
movq %rax, -0x560(%rbp)
movl -0x1c(%rbp), %eax
movl $0x40, %ecx
cltd
idivl %ecx
movq -0x560(%rbp), %rax
movl %edx, %ecx
movl $0x1, %edx
shlq %cl, %rdx
movq %rdx, %rcx
andq %rcx, %rax
cmpq $0x0, %rax
je 0x3acf
movl -0x20(%rbp), %eax
addl $-0x1, %eax
movl %eax, -0x20(%rbp)
movl $0x1, -0x524(%rbp)
movq 0x8529(%rip), %rax      # 0xbfd8
movq (%rax), %rdi
movslq -0x1c(%rbp), %rcx
leaq 0x8e43(%rip), %rax      # 0xc900
movq (%rax,%rcx,8), %rdx
leaq 0x55b7(%rip), %rsi      # 0x907f
movb $0x0, %al
callq 0x3390
cmpl $0x0, -0x524(%rbp)
je 0x3ba8
movl -0x1c(%rbp), %edi
callq 0x34b0
movl -0x1c(%rbp), %eax
movl $0x40, %ecx
cltd
idivl %ecx
movl %edx, %eax
movl %eax, %ecx
movl $0x1, %eax
shlq %cl, %rax
xorq $-0x1, %rax
movq %rax, -0x568(%rbp)
movl -0x1c(%rbp), %eax
movl $0x40, %ecx
cltd
idivl %ecx
movq -0x568(%rbp), %rdx
movslq %eax, %rcx
leaq 0x8d56(%rip), %rax      # 0xc878
andq (%rax,%rcx,8), %rdx
leaq 0x8d4b(%rip), %rax      # 0xc878
movq %rdx, (%rax,%rcx,8)
movslq -0x1c(%rbp), %rcx
leaq 0x8dc4(%rip), %rax      # 0xc900
movq (%rax,%rcx,8), %rdi
callq 0x3320
movslq -0x1c(%rbp), %rcx
leaq 0x8db0(%rip), %rax      # 0xc900
movq $0x0, (%rax,%rcx,8)
movl 0x8d12(%rip), %ecx      # 0xc870
xorl %eax, %eax
cmpl -0x4(%rbp), %ecx
movb %al, -0x569(%rbp)
jle 0x3b89
movslq 0x8cfe(%rip), %rcx      # 0xc870
leaq 0x8d87(%rip), %rax      # 0xc900
cmpq $0x0, (%rax,%rcx,8)
setne %al
xorb $-0x1, %al
movb %al, -0x569(%rbp)
movb -0x569(%rbp), %al
testb $0x1, %al
jne 0x3b95
jmp 0x3ba6
movl 0x8cd5(%rip), %eax      # 0xc870
addl $-0x1, %eax
movl %eax, 0x8ccc(%rip)      # 0xc870
jmp 0x3b58
jmp 0x3ba8
jmp 0x3baa
movl -0x1c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x1c(%rbp)
jmp 0x3961
jmp 0x3750
nopl (%rax)