// File: /workspace/github_c_makefile_star2_O3/keithnoguchi[P]pearls-in-action/0x9/find_first_flat_test.c
// Function: test_find_first_flat_1023
int test_find_first_flat_1023(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		= "double entries in the front",
			.dup_pos	= DUPLICATE_FRONT,
			.dup_count	= 2,
			.v		= 0,
			.want		= 0,
		},
		{
			.name		= "triple entries in the front",
			.dup_pos	= DUPLICATE_FRONT,
			.dup_count	= 3,
			.v		= 0,
			.want		= 0,
		},
		{
			.name		= "quad entries in the front",
			.dup_pos	= DUPLICATE_FRONT,
			.dup_count	= 4,
			.v		= 0,
			.want		= 0,
		},
		{
			.name		= "five entries in the front",
			.dup_pos	= DUPLICATE_FRONT,
			.dup_count	= 5,
			.v		= 0,
			.want		= 0,
		},
		{
			.name		= "single entry in the back",
			.dup_pos	= DUPLICATE_BACK,
			.dup_count	= 1,
			.v		= 1023,
			.want		= 1023,
		},
		{
			.name		= "double entries in the back",
			.dup_pos	= DUPLICATE_BACK,
			.dup_count	= 2,
			.v		= 1023,
			.want		= 1022,
		},
		{
			.name		= "triple entries in the back",
			.dup_pos	= DUPLICATE_BACK,
			.dup_count	= 3,
			.v		= 1023,
			.want		= 1021,
		},
		{
			.name		= "quad entries in the back",
			.dup_pos	= DUPLICATE_BACK,
			.dup_count	= 4,
			.v		= 1023,
			.want		= 1020,
		},
		{
			.name		= "five entries in the back",
			.dup_pos	= DUPLICATE_BACK,
			.dup_count	= 5,
			.v		= 1023,
			.want		= 1019,
		},
		{
			.name		= "single entry in the middle",
			.dup_pos	= DUPLICATE_MIDDLE,
			.dup_count	= 1,
			.v		= 511,
			.want		= 511,
		},
		{
			.name		= "double entries in the middle",
			.dup_pos	= DUPLICATE_MIDDLE,
			.dup_count	= 2,
			.v		= 511,
			.want		= 511,
		},
		{
			.name		= "triple entries in the middle",
			.dup_pos	= DUPLICATE_MIDDLE,
			.dup_count	= 3,
			.v		= 511,
			.want		= 510,
		},
		{
			.name		= "quad entries in the middle",
			.dup_pos	= DUPLICATE_MIDDLE,
			.dup_count	= 4,
			.v		= 511,
			.want		= 510,
		},
		{
			.name		= "five entries in the middle",
			.dup_pos	= DUPLICATE_MIDDLE,
			.dup_count	= 5,
			.v		= 511,
			.want		= 509,
		},
		{ /* sentry */ },
	};
	const struct test *t;
	int fail = 0;

	for (t = tests; t->name; t++) {
		int x[1024];
		int nr = sizeof(x)/sizeof(int);
		int got;

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

		generate_array(x, nr, t->dup_pos, t->dup_count);
		got = find_first_flat(t->v, x, nr);
		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 $0x1008, %rsp           # imm = 0x1008
movq %rdi, %rbx
leaq 0x1fc1(%rip), %r14      # 0x3c70
leaq 0x3ea(%rip), %rcx       # 0x20a0
leaq 0x737(%rip), %r15       # 0x23f4
movq %rsp, %r12
xorl %r13d, %r13d
movl (%rbx), %esi
incl %esi
movl %esi, (%rbx)
leaq 0x4ba(%rip), %rdi       # 0x218a
movq %r15, %rdx
xorl %eax, %eax
callq 0x1040
movl 0x8(%r14), %ecx
movl 0xc(%r14), %edx
xorl %eax, %eax
movdqa 0x504(%rip), %xmm0      # 0x21f0
movdqa 0x50c(%rip), %xmm1      # 0x2200
movdqa %xmm0, (%rsp,%rax,4)
addq $0x4, %rax
paddd %xmm1, %xmm0
cmpq $0x400, %rax            # imm = 0x400
jne 0x1cf4
cmpl $0x2, %ecx
je 0x1d45
cmpl $0x1, %ecx
movdqa 0x347(%rip), %xmm6      # 0x2060
pcmpeqd %xmm7, %xmm7
movdqa 0x36a(%rip), %xmm8      # 0x2090
je 0x1d33
testl %ecx, %ecx
jne 0x1d68
xorl %esi, %esi
movl (%rsp), %eax
jmp 0x1d68
movl 0x7fc(%rsp), %eax
movl $0x400, %esi            # imm = 0x400
subl %edx, %esi
shrl %esi
jmp 0x1d68
movl 0xffc(%rsp), %eax
movl $0x400, %esi            # imm = 0x400
subl %edx, %esi
movdqa 0x305(%rip), %xmm6      # 0x2060
pcmpeqd %xmm7, %xmm7
movdqa 0x328(%rip), %xmm8      # 0x2090
testl %edx, %edx
jle 0x1e50
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 0x2af(%rip), %xmm1      # 0x2050
movdqa 0x2d7(%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 0x1ddf
movl %eax, -0xc(%rdx,%rsi)
pxor %xmm7, %xmm3
pextrw $0x4, %xmm3, %edi
testb $0x1, %dil
je 0x1df2
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 0x1e2b
movl %eax, -0x4(%rdx,%rsi)
pextrw $0x4, %xmm3, %edi
testb $0x1, %dil
je 0x1e39
movl %eax, (%rdx,%rsi)
paddq %xmm8, %xmm1
paddq %xmm8, %xmm2
addq $0x10, %rsi
cmpq %rsi, %rcx
jne 0x1da9
movl 0x10(%r14), %edi
movl 0x14(%r14), %ebp
movq %r12, %rsi
movl $0x400, %edx            # imm = 0x400
callq 0x1bd4
cmpl %ebp, %eax
jne 0x1e77
leaq 0x358(%rip), %rdi       # 0x21c8
callq 0x1030
jmp 0x1e8c
leaq 0x331(%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 0x1cc3
movl %r13d, %eax
addq $0x1008, %rsp           # imm = 0x1008
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq