// File: /workspace/github_c_makefile_star2_O3/keithnoguchi[P]pearls-in-action/0x9/find_first1000_test.c
// Function: test_find_first1000
int test_find_first1000(int *i)
{
	const struct test {
		const char	*name;
		enum dup_pos	dup_pos;
		int		dup_count;
		int		v;
		int		want;
	} tests[] = {
		{
			.name		= "single entry in the front",
			.dup_pos	= DUPLICATE_FRONT,
			.dup_count	= 1,
			.v		= 0,
			.want		= 0,
		},
		{
			.name		= "two entries in the front",
			.dup_pos	= DUPLICATE_FRONT,
			.dup_count	= 2,
			.v		= 0,
			.want		= 0,
		},
		{
			.name		= "three entries in the front",
			.dup_pos	= DUPLICATE_FRONT,
			.dup_count	= 3,
			.v		= 0,
			.want		= 0,
		},
		{
			.name	= "single entry in the back",
			.dup_pos	= DUPLICATE_BACK,
			.dup_count	= 1,
			.v		= 999,
			.want		= 999,
		},
		{
			.name		= "two entries in the back",
			.dup_pos	= DUPLICATE_BACK,
			.dup_count	= 2,
			.v		= 999,
			.want		= 998,
		},
		{
			.name		= "three entries in the back",
			.dup_pos	= DUPLICATE_BACK,
			.dup_count	= 3,
			.v		= 999,
			.want		= 997,
		},
		{
			.name		= "single entry in the middle",
			.dup_pos	= DUPLICATE_MIDDLE,
			.dup_count	= 1,
			.v		= 499,
			.want		= 499,
		},
		{
			.name		= "two entries in the middle",
			.dup_pos	= DUPLICATE_MIDDLE,
			.dup_count	= 2,
			.v		= 499,
			.want		= 499,
		},
		{
			.name		= "three entries in the middle",
			.dup_pos	= DUPLICATE_MIDDLE,
			.dup_count	= 3,
			.v		= 499,
			.want		= 498,
		},
		{ /* sentinel */ },
	};
	const struct test *t;
	int fail = 0;

	for (t = tests; t->name; t++) {
		int x[1000];
		int got;

		printf("%3d) %-25s: %-45s", ++(*i), "test_find_first1000",
		       t->name);

		generate_array1000(x, t->dup_pos, t->dup_count);
		got = find_first1000(t->v, x);
		if (got != t->want) {
			printf("FAIL: got(%d)!=want(%d)\n", got, t->want);
			fail++;
		} else
			puts("PASS");
	}
	return fail;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xfa8, %rsp            # imm = 0xFA8
movq %rdi, %rbx
leaq 0x2395(%rip), %r14      # 0x39a0
leaq 0xa8e(%rip), %rcx       # 0x20a0
leaq 0xbf7(%rip), %r15       # 0x2210
movq %rsp, %r12
xorl %r13d, %r13d
movl (%rbx), %esi
incl %esi
movl %esi, (%rbx)
leaq 0xb5e(%rip), %rdi       # 0x218a
movq %r15, %rdx
xorl %eax, %eax
callq 0x1040
movl 0x8(%r14), %ecx
movl 0xc(%r14), %edx
xorl %eax, %eax
movdqa 0xba8(%rip), %xmm0      # 0x21f0
movdqa 0xbb0(%rip), %xmm1      # 0x2200
movdqa %xmm0, (%rsp,%rax,4)
addq $0x4, %rax
paddd %xmm1, %xmm0
cmpq $0x3e8, %rax            # imm = 0x3E8
jne 0x1650
cmpl $0x2, %ecx
je 0x16a8
cmpl $0x1, %ecx
movdqa 0x9eb(%rip), %xmm6      # 0x2060
pcmpeqd %xmm7, %xmm7
movdqa 0xa0e(%rip), %xmm8      # 0x2090
je 0x168f
testl %ecx, %ecx
jne 0x16cb
xorl %esi, %esi
movl (%rsp), %eax
jmp 0x16cb
movl 0x7cc(%rsp), %eax
movl $0x3e8, %ecx            # imm = 0x3E8
subl %edx, %ecx
movl %ecx, %esi
shrl $0x1f, %esi
addl %ecx, %esi
sarl %esi
jmp 0x16cb
movl 0xf9c(%rsp), %eax
movl $0x3e8, %esi            # imm = 0x3E8
subl %edx, %esi
movdqa 0x9a2(%rip), %xmm6      # 0x2060
pcmpeqd %xmm7, %xmm7
movdqa 0x9c5(%rip), %xmm8      # 0x2090
testl %edx, %edx
jle 0x17b3
movslq %esi, %rsi
leal 0x3(%rdx), %ecx
decq %rdx
movq %rdx, %xmm0
pshufd $0x44, %xmm0, %xmm0     # xmm0 = xmm0[0,1,0,1]
leaq 0xc(%rsp), %rdx
leaq (%rdx,%rsi,4), %rdx
shrl $0x2, %ecx
shlq $0x4, %rcx
pxor %xmm6, %xmm0
xorl %esi, %esi
movdqa 0x94c(%rip), %xmm1      # 0x2050
movdqa 0x974(%rip), %xmm2      # 0x2080
movdqa %xmm1, %xmm3
pxor %xmm6, %xmm3
movdqa %xmm3, %xmm4
pcmpgtd %xmm0, %xmm4
pcmpeqd %xmm0, %xmm3
pshufd $0xf5, %xmm3, %xmm5     # xmm5 = xmm3[1,1,3,3]
pand %xmm4, %xmm5
pshufd $0xf5, %xmm4, %xmm3     # xmm3 = xmm4[1,1,3,3]
por %xmm5, %xmm3
movd %xmm3, %edi
notl %edi
testb $0x1, %dil
je 0x1742
movl %eax, -0xc(%rdx,%rsi)
pxor %xmm7, %xmm3
pextrw $0x4, %xmm3, %edi
testb $0x1, %dil
je 0x1755
movl %eax, -0x8(%rdx,%rsi)
movdqa %xmm2, %xmm3
pxor %xmm6, %xmm3
movdqa %xmm3, %xmm4
pcmpgtd %xmm0, %xmm4
pcmpeqd %xmm0, %xmm3
pshufd $0xf5, %xmm3, %xmm5     # xmm5 = xmm3[1,1,3,3]
pand %xmm4, %xmm5
pshufd $0xf5, %xmm4, %xmm3     # xmm3 = xmm4[1,1,3,3]
por %xmm5, %xmm3
pxor %xmm7, %xmm3
pextrw $0x0, %xmm3, %edi
testb $0x1, %dil
je 0x178e
movl %eax, -0x4(%rdx,%rsi)
pextrw $0x4, %xmm3, %edi
testb $0x1, %dil
je 0x179c
movl %eax, (%rdx,%rsi)
paddq %xmm8, %xmm1
paddq %xmm8, %xmm2
addq $0x10, %rsi
cmpq %rsi, %rcx
jne 0x170c
movl 0x10(%r14), %edi
movl 0x14(%r14), %ebp
movq %r12, %rsi
callq 0x1598
cmpl %ebp, %eax
jne 0x17d5
leaq 0x9fa(%rip), %rdi       # 0x21c8
callq 0x1030
jmp 0x17ea
leaq 0x9d3(%rip), %rdi       # 0x21af
movl %eax, %esi
movl %ebp, %edx
xorl %eax, %eax
callq 0x1040
incl %r13d
movq 0x18(%r14), %rcx
addq $0x18, %r14
testq %rcx, %rcx
jne 0x161f
movl %r13d, %eax
addq $0xfa8, %rsp            # imm = 0xFA8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq