// File: ralgond[P]SortedListIntersection/algo_STTNI.cpp
// Function: intersect(unsigned int*, unsigned int, unsigned int*, unsigned int, unsigned int*, unsigned short)
uint32_t intersect(uint32_t * a, uint32_t a_len, uint32_t * b, uint32_t b_len, uint32_t* c, uint16_t high16) {
	uint32_t* c_begin = c;
	uint32_t ai = 0;
	uint32_t bi = 0;
	uint32_t a_st = (a_len/8) * 8;
	uint32_t b_st = (b_len/8) * 8;
	uint16_t a16[8];
	uint16_t b16[8];
	uint16_t c16[8];
	while (ai < a_st && bi < b_st) {
		a16[0] = _low16(a[ai+0]);
		a16[1] = _low16(a[ai+1]);
		a16[2] = _low16(a[ai+2]);
		a16[3] = _low16(a[ai+3]);
		a16[4] = _low16(a[ai+4]);
		a16[5] = _low16(a[ai+5]);
		a16[6] = _low16(a[ai+6]);
		a16[7] = _low16(a[ai+7]);

		b16[0] = _low16(b[bi+0]);
		b16[1] = _low16(b[bi+1]);
		b16[2] = _low16(b[bi+2]);
		b16[3] = _low16(b[bi+3]);
		b16[4] = _low16(b[bi+4]);
		b16[5] = _low16(b[bi+5]);
		b16[6] = _low16(b[bi+6]);
		b16[7] = _low16(b[bi+7]);

		uint32_t count = intersect_vector16(a16, b16, c16);

		for (uint32_t i = 0; i < count; i++) {
			uint32_t res = high16;
			res <<= 16;
			res |= c16[i];
			*c = res;
			c++;
		}

		uint16_t a_max = a16[7];
		uint16_t b_max = b16[7];
		ai += (a_max <= b_max) * 8;
		bi += (a_max >= b_max) * 8;
	}


	while (ai < a_len && bi < b_len) {
		if (a[ai] < b[bi]) {
			ai++;
		} else if (a[ai] > b[bi]) {
			bi++;
		} else {
			*c = a[ai];
			c++; ai++; bi++;
		}
	}
	return c - c_begin;
}

// Assembly:
subq $0x98, %rsp
movw %r9w, %ax
movq %rdi, 0x90(%rsp)
movl %esi, 0x8c(%rsp)
movq %rdx, 0x80(%rsp)
movl %ecx, 0x7c(%rsp)
movq %r8, 0x70(%rsp)
movw %ax, 0x6e(%rsp)
movq 0x70(%rsp), %rax
movq %rax, 0x60(%rsp)
movl $0x0, 0x5c(%rsp)
movl $0x0, 0x58(%rsp)
movl 0x8c(%rsp), %eax
shrl $0x3, %eax
shll $0x3, %eax
movl %eax, 0x54(%rsp)
movl 0x7c(%rsp), %eax
shrl $0x3, %eax
shll $0x3, %eax
movl %eax, 0x50(%rsp)
movl 0x5c(%rsp), %ecx
xorl %eax, %eax
cmpl 0x54(%rsp), %ecx
movb %al, 0xf(%rsp)
jae 0x3e08
movl 0x58(%rsp), %eax
cmpl 0x50(%rsp), %eax
setb %al
movb %al, 0xf(%rsp)
movb 0xf(%rsp), %al
testb $0x1, %al
jne 0x3e15
jmp 0x40c1
movq 0x90(%rsp), %rax
movl 0x5c(%rsp), %ecx
addl $0x0, %ecx
movl %ecx, %ecx
movl (%rax,%rcx,4), %edi
callq 0x49a0
movw %ax, 0x40(%rsp)
movq 0x90(%rsp), %rax
movl 0x5c(%rsp), %ecx
addl $0x1, %ecx
movl %ecx, %ecx
movl (%rax,%rcx,4), %edi
callq 0x49a0
movw %ax, 0x42(%rsp)
movq 0x90(%rsp), %rax
movl 0x5c(%rsp), %ecx
addl $0x2, %ecx
movl %ecx, %ecx
movl (%rax,%rcx,4), %edi
callq 0x49a0
movw %ax, 0x44(%rsp)
movq 0x90(%rsp), %rax
movl 0x5c(%rsp), %ecx
addl $0x3, %ecx
movl %ecx, %ecx
movl (%rax,%rcx,4), %edi
callq 0x49a0
movw %ax, 0x46(%rsp)
movq 0x90(%rsp), %rax
movl 0x5c(%rsp), %ecx
addl $0x4, %ecx
movl %ecx, %ecx
movl (%rax,%rcx,4), %edi
callq 0x49a0
movw %ax, 0x48(%rsp)
movq 0x90(%rsp), %rax
movl 0x5c(%rsp), %ecx
addl $0x5, %ecx
movl %ecx, %ecx
movl (%rax,%rcx,4), %edi
callq 0x49a0
movw %ax, 0x4a(%rsp)
movq 0x90(%rsp), %rax
movl 0x5c(%rsp), %ecx
addl $0x6, %ecx
movl %ecx, %ecx
movl (%rax,%rcx,4), %edi
callq 0x49a0
movw %ax, 0x4c(%rsp)
movq 0x90(%rsp), %rax
movl 0x5c(%rsp), %ecx
addl $0x7, %ecx
movl %ecx, %ecx
movl (%rax,%rcx,4), %edi
callq 0x49a0
movw %ax, 0x4e(%rsp)
movq 0x80(%rsp), %rax
movl 0x58(%rsp), %ecx
addl $0x0, %ecx
movl %ecx, %ecx
movl (%rax,%rcx,4), %edi
callq 0x49a0
movw %ax, 0x30(%rsp)
movq 0x80(%rsp), %rax
movl 0x58(%rsp), %ecx
addl $0x1, %ecx
movl %ecx, %ecx
movl (%rax,%rcx,4), %edi
callq 0x49a0
movw %ax, 0x32(%rsp)
movq 0x80(%rsp), %rax
movl 0x58(%rsp), %ecx
addl $0x2, %ecx
movl %ecx, %ecx
movl (%rax,%rcx,4), %edi
callq 0x49a0
movw %ax, 0x34(%rsp)
movq 0x80(%rsp), %rax
movl 0x58(%rsp), %ecx
addl $0x3, %ecx
movl %ecx, %ecx
movl (%rax,%rcx,4), %edi
callq 0x49a0
movw %ax, 0x36(%rsp)
movq 0x80(%rsp), %rax
movl 0x58(%rsp), %ecx
addl $0x4, %ecx
movl %ecx, %ecx
movl (%rax,%rcx,4), %edi
callq 0x49a0
movw %ax, 0x38(%rsp)
movq 0x80(%rsp), %rax
movl 0x58(%rsp), %ecx
addl $0x5, %ecx
movl %ecx, %ecx
movl (%rax,%rcx,4), %edi
callq 0x49a0
movw %ax, 0x3a(%rsp)
movq 0x80(%rsp), %rax
movl 0x58(%rsp), %ecx
addl $0x6, %ecx
movl %ecx, %ecx
movl (%rax,%rcx,4), %edi
callq 0x49a0
movw %ax, 0x3c(%rsp)
movq 0x80(%rsp), %rax
movl 0x58(%rsp), %ecx
addl $0x7, %ecx
movl %ecx, %ecx
movl (%rax,%rcx,4), %edi
callq 0x49a0
movw %ax, 0x3e(%rsp)
leaq 0x40(%rsp), %rdi
leaq 0x30(%rsp), %rsi
leaq 0x20(%rsp), %rdx
callq 0x49b0
movl %eax, 0x1c(%rsp)
movl $0x0, 0x18(%rsp)
movl 0x18(%rsp), %eax
cmpl 0x1c(%rsp), %eax
jae 0x406a
movzwl 0x6e(%rsp), %eax
movl %eax, 0x14(%rsp)
movl 0x14(%rsp), %eax
shll $0x10, %eax
movl %eax, 0x14(%rsp)
movl 0x18(%rsp), %eax
movzwl 0x20(%rsp,%rax,2), %eax
orl 0x14(%rsp), %eax
movl %eax, 0x14(%rsp)
movl 0x14(%rsp), %ecx
movq 0x70(%rsp), %rax
movl %ecx, (%rax)
movq 0x70(%rsp), %rax
addq $0x4, %rax
movq %rax, 0x70(%rsp)
movl 0x18(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x18(%rsp)
jmp 0x4015
movw 0x4e(%rsp), %ax
movw %ax, 0x12(%rsp)
movw 0x3e(%rsp), %ax
movw %ax, 0x10(%rsp)
movzwl 0x12(%rsp), %eax
movzwl 0x10(%rsp), %ecx
cmpl %ecx, %eax
setle %al
andb $0x1, %al
movzbl %al, %eax
shll $0x3, %eax
addl 0x5c(%rsp), %eax
movl %eax, 0x5c(%rsp)
movzwl 0x12(%rsp), %eax
movzwl 0x10(%rsp), %ecx
cmpl %ecx, %eax
setge %al
andb $0x1, %al
movzbl %al, %eax
shll $0x3, %eax
addl 0x58(%rsp), %eax
movl %eax, 0x58(%rsp)
jmp 0x3de9
jmp 0x40c3
movl 0x5c(%rsp), %ecx
xorl %eax, %eax
cmpl 0x8c(%rsp), %ecx
movb %al, 0xe(%rsp)
jae 0x40e5
movl 0x58(%rsp), %eax
cmpl 0x7c(%rsp), %eax
setb %al
movb %al, 0xe(%rsp)
movb 0xe(%rsp), %al
testb $0x1, %al
jne 0x40f2
jmp 0x418d
movq 0x90(%rsp), %rax
movl 0x5c(%rsp), %ecx
movl (%rax,%rcx,4), %eax
movq 0x80(%rsp), %rcx
movl 0x58(%rsp), %edx
cmpl (%rcx,%rdx,4), %eax
jae 0x411f
movl 0x5c(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x5c(%rsp)
jmp 0x4188
movq 0x90(%rsp), %rax
movl 0x5c(%rsp), %ecx
movl (%rax,%rcx,4), %eax
movq 0x80(%rsp), %rcx
movl 0x58(%rsp), %edx
cmpl (%rcx,%rdx,4), %eax
jbe 0x414c
movl 0x58(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x58(%rsp)
jmp 0x4186
movq 0x90(%rsp), %rax
movl 0x5c(%rsp), %ecx
movl (%rax,%rcx,4), %ecx
movq 0x70(%rsp), %rax
movl %ecx, (%rax)
movq 0x70(%rsp), %rax
addq $0x4, %rax
movq %rax, 0x70(%rsp)
movl 0x5c(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x5c(%rsp)
movl 0x58(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x58(%rsp)
jmp 0x4188
jmp 0x40c3
movq 0x70(%rsp), %rax
movq 0x60(%rsp), %rcx
subq %rcx, %rax
sarq $0x2, %rax
addq $0x98, %rsp
retq
nopw %cs:(%rax,%rax)