// File: ralgond[P]SortedListIntersection/algo_block_merge.cpp
// Function: block_merge_intersection(unsigned int const*, unsigned int, unsigned int const*, unsigned int, unsigned int*)
uint32_t block_merge_intersection(const uint32_t* a, uint32_t a_len, const uint32_t* b, uint32_t b_len, uint32_t* c) {
	uint32_t c_pos = 0;
	uint32_t a_pos = 0;
	uint32_t b_pos = 0;

	while (a_pos+1<a_len && b_pos+1<b_len) {
		int a_data_0 = a[a_pos]; int a_data_1 = a[a_pos+1];
		int b_data_0 = b[b_pos]; int b_data_1 = b[b_pos+1];
		if (a_data_0 == b_data_0) {
			c[c_pos++] = a_data_0;
		}
	        else if (a_data_0 == b_data_1) {	
			c[c_pos++] = a_data_0;
			goto advanceB;
		} 
		else if (a_data_1 == b_data_0) {
			c[c_pos++] = a_data_1;
			goto advanceA;
		}
		if (a_data_1 == b_data_1) {
			c[c_pos++] = a_data_1;
			goto advanceAB;
		}
		else if (a_data_1 > b_data_1) goto advanceB;
		else goto advanceA;
advanceA:
		a_pos += 2;
		if (a_pos >= a_len){break;} else {continue;}
advanceB:
		b_pos += 2;
		if (b_pos >= b_len){break;} else {continue;}
advanceAB:
		a_pos += 2; b_pos += 2;
		if (a_pos >= a_len || b_pos >= b_len){break;}
	}
	
	while (a_pos < a_len && b_pos < b_len) {
		int a_data = a[a_pos];
		int b_data = b[b_pos];
		if (a_data == b_data) {
			c[c_pos++] = a_data;
			a_pos++;
			b_pos++;
		} else if (a_data > b_data) {
			b_pos++;
		} else {
			a_pos++;
		}
	}
	return c_pos;
}

// Assembly:
movq %rdi, -0x8(%rsp)
movl %esi, -0xc(%rsp)
movq %rdx, -0x18(%rsp)
movl %ecx, -0x1c(%rsp)
movq %r8, -0x28(%rsp)
movl $0x0, -0x2c(%rsp)
movl $0x0, -0x30(%rsp)
movl $0x0, -0x34(%rsp)
movl -0x30(%rsp), %ecx
addl $0x1, %ecx
xorl %eax, %eax
cmpl -0xc(%rsp), %ecx
movb %al, -0x4d(%rsp)
jae 0x5034
movl -0x34(%rsp), %eax
addl $0x1, %eax
cmpl -0x1c(%rsp), %eax
setb %al
movb %al, -0x4d(%rsp)
movb -0x4d(%rsp), %al
testb $0x1, %al
jne 0x5041
jmp 0x51a2
movq -0x8(%rsp), %rax
movl -0x30(%rsp), %ecx
movl (%rax,%rcx,4), %eax
movl %eax, -0x38(%rsp)
movq -0x8(%rsp), %rax
movl -0x30(%rsp), %ecx
addl $0x1, %ecx
movl %ecx, %ecx
movl (%rax,%rcx,4), %eax
movl %eax, -0x3c(%rsp)
movq -0x18(%rsp), %rax
movl -0x34(%rsp), %ecx
movl (%rax,%rcx,4), %eax
movl %eax, -0x40(%rsp)
movq -0x18(%rsp), %rax
movl -0x34(%rsp), %ecx
addl $0x1, %ecx
movl %ecx, %ecx
movl (%rax,%rcx,4), %eax
movl %eax, -0x44(%rsp)
movl -0x38(%rsp), %eax
cmpl -0x40(%rsp), %eax
jne 0x50b2
movl -0x38(%rsp), %edx
movq -0x28(%rsp), %rax
movl -0x2c(%rsp), %ecx
movl %ecx, %esi
addl $0x1, %esi
movl %esi, -0x2c(%rsp)
movl %ecx, %ecx
movl %edx, (%rax,%rcx,4)
jmp 0x5104
movl -0x38(%rsp), %eax
cmpl -0x44(%rsp), %eax
jne 0x50d9
movl -0x38(%rsp), %edx
movq -0x28(%rsp), %rax
movl -0x2c(%rsp), %ecx
movl %ecx, %esi
addl $0x1, %esi
movl %esi, -0x2c(%rsp)
movl %ecx, %ecx
movl %edx, (%rax,%rcx,4)
jmp 0x5155
movl -0x3c(%rsp), %eax
cmpl -0x40(%rsp), %eax
jne 0x5100
movl -0x3c(%rsp), %edx
movq -0x28(%rsp), %rax
movl -0x2c(%rsp), %ecx
movl %ecx, %esi
addl $0x1, %esi
movl %esi, -0x2c(%rsp)
movl %ecx, %ecx
movl %edx, (%rax,%rcx,4)
jmp 0x5139
jmp 0x5102
jmp 0x5104
movl -0x3c(%rsp), %eax
cmpl -0x44(%rsp), %eax
jne 0x512b
movl -0x3c(%rsp), %edx
movq -0x28(%rsp), %rax
movl -0x2c(%rsp), %ecx
movl %ecx, %esi
addl $0x1, %esi
movl %esi, -0x2c(%rsp)
movl %ecx, %ecx
movl %edx, (%rax,%rcx,4)
jmp 0x5171
movl -0x3c(%rsp), %eax
cmpl -0x44(%rsp), %eax
jle 0x5137
jmp 0x5155
jmp 0x5139
movl -0x30(%rsp), %eax
addl $0x2, %eax
movl %eax, -0x30(%rsp)
movl -0x30(%rsp), %eax
cmpl -0xc(%rsp), %eax
jb 0x5150
jmp 0x51a2
jmp 0x500f
movl -0x34(%rsp), %eax
addl $0x2, %eax
movl %eax, -0x34(%rsp)
movl -0x34(%rsp), %eax
cmpl -0x1c(%rsp), %eax
jb 0x516c
jmp 0x51a2
jmp 0x500f
movl -0x30(%rsp), %eax
addl $0x2, %eax
movl %eax, -0x30(%rsp)
movl -0x34(%rsp), %eax
addl $0x2, %eax
movl %eax, -0x34(%rsp)
movl -0x30(%rsp), %eax
cmpl -0xc(%rsp), %eax
jae 0x519b
movl -0x34(%rsp), %eax
cmpl -0x1c(%rsp), %eax
jb 0x519d
jmp 0x51a2
jmp 0x500f
jmp 0x51a4
movl -0x30(%rsp), %ecx
xorl %eax, %eax
cmpl -0xc(%rsp), %ecx
movb %al, -0x4e(%rsp)
jae 0x51c3
movl -0x34(%rsp), %eax
cmpl -0x1c(%rsp), %eax
setb %al
movb %al, -0x4e(%rsp)
movb -0x4e(%rsp), %al
testb $0x1, %al
jne 0x51d0
jmp 0x5256
movq -0x8(%rsp), %rax
movl -0x30(%rsp), %ecx
movl (%rax,%rcx,4), %eax
movl %eax, -0x48(%rsp)
movq -0x18(%rsp), %rax
movl -0x34(%rsp), %ecx
movl (%rax,%rcx,4), %eax
movl %eax, -0x4c(%rsp)
movl -0x48(%rsp), %eax
cmpl -0x4c(%rsp), %eax
jne 0x522d
movl -0x48(%rsp), %edx
movq -0x28(%rsp), %rax
movl -0x2c(%rsp), %ecx
movl %ecx, %esi
addl $0x1, %esi
movl %esi, -0x2c(%rsp)
movl %ecx, %ecx
movl %edx, (%rax,%rcx,4)
movl -0x30(%rsp), %eax
addl $0x1, %eax
movl %eax, -0x30(%rsp)
movl -0x34(%rsp), %eax
addl $0x1, %eax
movl %eax, -0x34(%rsp)
jmp 0x5251
movl -0x48(%rsp), %eax
cmpl -0x4c(%rsp), %eax
jle 0x5244
movl -0x34(%rsp), %eax
addl $0x1, %eax
movl %eax, -0x34(%rsp)
jmp 0x524f
movl -0x30(%rsp), %eax
addl $0x1, %eax
movl %eax, -0x30(%rsp)
jmp 0x5251
jmp 0x51a4
movl -0x2c(%rsp), %eax
retq
nopl (%rax,%rax)