// File: grogers0[P]dots_and_boxes/InputOutput.cpp
// Function: read_edge(_IO_FILE*)
Edge read_edge(FILE *fp)
{
    int fd = fileno(fp);

    pollfd pev;
    pev.fd = fd;
    pev.events = POLLIN;
    pev.revents = 0;

    int pollret = poll(&pev, 1, 1000);
    if (pollret == 0) {
        throw std::runtime_error("took too long to move");
    } else if (pollret == -1) {
        printf("error poll'ing fd\n");
        exit(1);
    }

    fcntl(fd, F_SETFL, O_NONBLOCK);
    char buf[80] = {};
    ssize_t nbytes = read(fd, buf, sizeof(buf) - 1);
    fcntl(fd, F_SETFL, 0);

    if (nbytes == 0)
        throw std::runtime_error("exited early");

    char tmp;
    Edge move;
    int x, y;
    sscanf(buf, "(edge %c %d %d)\n", &tmp, &x, &y);

    move.x = x;
    move.y = y;

    if (tmp == 'h')
        move.dir = HORIZ;
    else
        move.dir = VERT;

    return move;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xb0, %rsp
movq %rdi, -0x10(%rbp)
movq -0x10(%rbp), %rdi
callq 0x2250
movl %eax, -0x14(%rbp)
movl -0x14(%rbp), %eax
movl %eax, -0x1c(%rbp)
movw $0x1, -0x18(%rbp)
movw $0x0, -0x16(%rbp)
leaq -0x1c(%rbp), %rdi
movl $0x1, %esi
movl $0x3e8, %edx            # imm = 0x3E8
callq 0x2380
movl %eax, -0x20(%rbp)
cmpl $0x0, -0x20(%rbp)
jne 0x4605
movl $0x10, %edi
callq 0x2100
movq %rax, %rdi
movq %rdi, %rax
movq %rax, -0xa0(%rbp)
leaq 0x5bd2(%rip), %rsi      # 0xa199
callq 0x20c0
jmp 0x45ce
movq -0xa0(%rbp), %rdi
movq 0xaa1c(%rip), %rsi      # 0xeff8
movq 0xa9ed(%rip), %rdx      # 0xefd0
callq 0x23f0
movq -0xa0(%rbp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x28(%rbp)
movl %eax, -0x2c(%rbp)
callq 0x2190
jmp 0x4782
cmpl $-0x1, -0x20(%rbp)
jne 0x4623
leaq 0x5b9d(%rip), %rdi      # 0xa1af
movb $0x0, %al
callq 0x2040
movl $0x1, %edi
callq 0x22e0
jmp 0x4625
movl -0x14(%rbp), %edi
movl $0x4, %esi
movl $0x800, %edx            # imm = 0x800
movb $0x0, %al
callq 0x2130
leaq -0x80(%rbp), %rdi
xorl %esi, %esi
movl $0x50, %edx
callq 0x2120
movl -0x14(%rbp), %edi
leaq -0x80(%rbp), %rsi
movl $0x4f, %edx
callq 0x2350
movq %rax, -0x88(%rbp)
movl -0x14(%rbp), %edi
movl $0x4, %esi
xorl %edx, %edx
movb $0x0, %al
callq 0x2130
cmpq $0x0, -0x88(%rbp)
jne 0x46d8
movl $0x10, %edi
callq 0x2100
movq %rax, %rdi
movq %rdi, %rax
movq %rax, -0xa8(%rbp)
leaq 0x5b28(%rip), %rsi      # 0xa1c2
callq 0x20c0
jmp 0x46a1
movq -0xa8(%rbp), %rdi
movq 0xa949(%rip), %rsi      # 0xeff8
movq 0xa91a(%rip), %rdx      # 0xefd0
callq 0x23f0
movq -0xa8(%rbp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x28(%rbp)
movl %eax, -0x2c(%rbp)
callq 0x2190
jmp 0x4782
leaq -0x4(%rbp), %rdi
callq 0x5060
leaq -0x80(%rbp), %rdi
leaq 0x5a9c(%rip), %rsi      # 0xa188
leaq -0x89(%rbp), %rdx
leaq -0x90(%rbp), %rcx
leaq -0x94(%rbp), %r8
movb $0x0, %al
callq 0x2210
movl -0x90(%rbp), %eax
movw %ax, %cx
movw -0x4(%rbp), %ax
andw $0x7f, %cx
shlw %cx
andw $0xff01, %ax            # imm = 0xFF01
orw %cx, %ax
movw %ax, -0x4(%rbp)
movl -0x94(%rbp), %eax
movw %ax, %cx
movw -0x4(%rbp), %ax
andw $0xff, %cx
shlw $0x8, %cx
andw $0xff, %ax
orw %cx, %ax
movw %ax, -0x4(%rbp)
movsbl -0x89(%rbp), %eax
cmpl $0x68, %eax
jne 0x4766
movw -0x4(%rbp), %ax
andw $-0x2, %ax
orw $0x0, %ax
movw %ax, -0x4(%rbp)
jmp 0x4776
movw -0x4(%rbp), %ax
andw $-0x2, %ax
orw $0x1, %ax
movw %ax, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0xb0, %rsp
popq %rbp
retq
movq -0x28(%rbp), %rdi
callq 0x2400
nopl (%rax,%rax)