// File: arnoldrobbins[P]mcilroy-regex/sed2.cpp
// Function: selected(unsigned char*, Text*)
int
selected(uchar *pc, Text *data)
{
	int active;
	int *ipc = (int*)pc;	/* points to address words */
	int *q = instr(pc);	/* points to instruction word */
	int neg = !!(*q & NEG);
	switch(q - ipc)	{
	case 0:			/* 0 address */
		return !neg;
	case 1:			/* 1 address */
		return neg ^ (sel1(ipc[0], data)==1);
	case 2:
		quit(IBUG,1);
	case 3:			/* 2 address */
		q--;		/* points to activity indicator */
		active = !(*q & INACT);
		if((*q&AMASK) < recno) {
			switch(sel1(ipc[active], data)) {
			case 0:
				if((active&ateof()) == 0)
					break;
			case 1:
				*q = recno;
				if(active)
					*q |= INACT;
				return (neg^1) << (!active&!ateof());
			case -1:
				if(active) {
					*q = recno | INACT;
					return neg;
				}
			}
		}
		return (neg^active) << 1;
	default:
		quit(IBUG,2);
		return 0;	/* dummy */
	}
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x60, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0x28(%rbp)
movq -0x10(%rbp), %rdi
callq 0x64f0
movq %rax, -0x30(%rbp)
movq -0x30(%rbp), %rax
movl (%rax), %eax
shrl $0x18, %eax
andl $0x1, %eax
movl %eax, -0x34(%rbp)
movq -0x30(%rbp), %rax
movq -0x28(%rbp), %rcx
subq %rcx, %rax
sarq $0x2, %rax
movq %rax, -0x40(%rbp)
subq $0x3, %rax
ja 0x784d
movq -0x40(%rbp), %rax
leaq 0x9ea8(%rip), %rcx      # 0x11564
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
cmpl $0x0, -0x34(%rbp)
setne %al
xorb $-0x1, %al
andb $0x1, %al
movzbl %al, %eax
movl %eax, -0x4(%rbp)
jmp 0x7867
movl -0x34(%rbp), %eax
movl %eax, -0x44(%rbp)
movq -0x28(%rbp), %rax
movl (%rax), %edi
movq -0x18(%rbp), %rsi
callq 0x7870
movl %eax, %ecx
movl -0x44(%rbp), %eax
cmpl $0x1, %ecx
sete %cl
andb $0x1, %cl
movzbl %cl, %ecx
xorl %ecx, %eax
movl %eax, -0x4(%rbp)
jmp 0x7867
leaq 0x9e7a(%rip), %rdi      # 0x1158c
movl $0x1, %esi
movb $0x0, %al
callq 0x5820
movq -0x30(%rbp), %rax
addq $-0x4, %rax
movq %rax, -0x30(%rbp)
movq -0x30(%rbp), %rax
movl (%rax), %eax
andl $0x80000000, %eax       # imm = 0x80000000
cmpl $0x0, %eax
setne %al
xorb $-0x1, %al
andb $0x1, %al
movzbl %al, %eax
movl %eax, -0x1c(%rbp)
movq -0x30(%rbp), %rax
movl (%rax), %eax
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
leaq 0x109c1(%rip), %rcx     # 0x18118
cmpl (%rcx), %eax
jge 0x7840
movq -0x28(%rbp), %rax
movslq -0x1c(%rbp), %rcx
movl (%rax,%rcx,4), %edi
movq -0x18(%rbp), %rsi
callq 0x7870
movl %eax, %ecx
movl %ecx, -0x48(%rbp)
subl $-0x1, %eax
je 0x7819
jmp 0x7783
movl -0x48(%rbp), %eax
testl %eax, %eax
je 0x7799
jmp 0x778c
movl -0x48(%rbp), %eax
subl $0x1, %eax
je 0x77b7
jmp 0x783e
movl -0x1c(%rbp), %eax
movl %eax, -0x4c(%rbp)
callq 0x5d30
movl %eax, %ecx
movl -0x4c(%rbp), %eax
andl %ecx, %eax
cmpl $0x0, %eax
jne 0x77b5
jmp 0x783e
jmp 0x77b7
leaq 0x1095a(%rip), %rax     # 0x18118
movl (%rax), %ecx
movq -0x30(%rbp), %rax
movl %ecx, (%rax)
cmpl $0x0, -0x1c(%rbp)
je 0x77da
movq -0x30(%rbp), %rax
movl (%rax), %ecx
orl $0x80000000, %ecx       # imm = 0x80000000
movl %ecx, (%rax)
movl -0x34(%rbp), %eax
xorl $0x1, %eax
movl %eax, -0x50(%rbp)
cmpl $0x0, -0x1c(%rbp)
setne %al
xorb $-0x1, %al
andb $0x1, %al
movzbl %al, %eax
movl %eax, -0x54(%rbp)
callq 0x5d30
movl -0x54(%rbp), %ecx
movl %eax, %edx
movl -0x50(%rbp), %eax
cmpl $0x0, %edx
setne %dl
xorb $-0x1, %dl
andb $0x1, %dl
movzbl %dl, %edx
andl %edx, %ecx
shll %cl, %eax
movl %eax, -0x4(%rbp)
jmp 0x7867
cmpl $0x0, -0x1c(%rbp)
je 0x783c
leaq 0x108f2(%rip), %rax     # 0x18118
movl (%rax), %ecx
orl $0x80000000, %ecx       # imm = 0x80000000
movq -0x30(%rbp), %rax
movl %ecx, (%rax)
movl -0x34(%rbp), %eax
movl %eax, -0x4(%rbp)
jmp 0x7867
jmp 0x783e
jmp 0x7840
movl -0x34(%rbp), %eax
xorl -0x1c(%rbp), %eax
shll %eax
movl %eax, -0x4(%rbp)
jmp 0x7867
leaq 0x9d38(%rip), %rdi      # 0x1158c
movl $0x2, %esi
movb $0x0, %al
callq 0x5820
movl $0x0, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x60, %rsp
popq %rbp
retq