// File: /workspace/github_c_makefile_star2_O0/keithnoguchi[P]pearls-in-action/0xd/set1_test.c
// Function: test_set1_insert
static int test_set1_insert(int *test_nr)
{
	const struct test {
		const char	*name;
		int		nr;
		int		max;
		int		insert[128];
		int		want[128];
	} tests[] = {
		{
			.name	= "insert([0, 1))",
			.nr	= 1,
			.max	= 1,
			.insert	= {0, 1},
			.want	= {0},
		},
		{
			.name	= "duplicate insert([0, 1))",
			.nr	= 1,
			.max	= 1,
			.insert	= {0, 0, 0, 1},
			.want	= {0},
		},
		{
			.name	= "insert([0, 2))",
			.nr	= 2,
			.max	= 2,
			.insert	= {0, 1, 2},
			.want	= {0, 1},
		},
		{
			.name	= "reserve insert([0, 2))",
			.nr	= 2,
			.max	= 2,
			.insert	= {1, 0, 2},
			.want	= {0, 1},
		},
		{
			.name	= "duplicate insert([0, 2))",
			.nr	= 2,
			.max	= 2,
			.insert	= {0, 1, 1, 2},
			.want	= {0, 1},
		},
		{
			.name	= "insert([0, 3))",
			.nr	= 3,
			.max	= 3,
			.insert	= {0, 1, 2, 3},
			.want	= {0, 1, 2},
		},
		{
			.name	= "reverse insert([0, 3))",
			.nr	= 3,
			.max	= 3,
			.insert	= {2, 1, 0, 3},
			.want	= {0, 1, 2},
		},
		{
			.name	= "duplicate insert([0, 3))",
			.nr	= 3,
			.max	= 3,
			.insert	= {0, 1, 1, 2, 2, 3},
			.want	= {0, 1, 2},
		},
		{
			.name	= "insert([0, 10))",
			.nr	= 10,
			.max	= 10,
			.insert	= {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10},
			.want	= {0, 1, 2, 3, 4, 5, 6, 7, 8, 9},
		},
		{
			.name	= "revert insert([0, 10))",
			.nr	= 10,
			.max	= 10,
			.insert	= {9, 8, 7, 6, 5, 4, 3, 2, 1, 0, 10},
			.want	= {0, 1, 2, 3, 4, 5, 6, 7, 8, 9},
		},
		{
			.name	= "duplicate insert([0, 10))",
			.nr	= 10,
			.max	= 10,
			.insert	= {
				0, 1, 2, 3, 4, 5, 6, 7, 8, 9,
				0, 1, 2, 3, 4, 5, 6, 7, 8, 9,
				10,
			},
			.want	= {0, 1, 2, 3, 4, 5, 6, 7, 8, 9},
		},
		{
			.name	= "duplicate revert insert([0, 10))",
			.nr	= 10,
			.max	= 10,
			.insert	= {
				9, 8, 7, 6, 5, 4, 3, 2, 1, 0,
				9, 8, 7, 6, 5, 4, 3, 2, 1, 0,
				10,
			},
			.want	= {0, 1, 2, 3, 4, 5, 6, 7, 8, 9},
		},
		{ /* sentinel */ },
	};
	const struct test *t;
	int fail = 0;

	for (t = tests; t->name; t++) {
		struct set *s;
		double diff;
		clock_t c;
		int *got = NULL;
		int i;

		printf("%3d) %-21s: %-35s", ++(*test_nr), __FUNCTION__,
		       t->name);

		s = alloc_set1(t->nr, t->max);
		if (!s) {
			printf("FAIL: alloc_set1(m=%d,n=%d): %s\n",
			       t->nr, t->max, strerror(errno));
			goto fail;
		}
		c = clock();
		for (i = 0; t->insert[i] != t->max; i++)
			set_insert(s, t->insert[i]);
		c = clock()-c;
		diff = (double)c/CLOCKS_PER_SEC;
		if (set_size(s) != t->nr) {
			printf("FAIL: %ld=set_size()!=%d\n: %9.6fsec",
			       set_size(s), t->nr, diff);
			goto fail;
		}
		got = malloc(sizeof(int)*(t->nr+1)); /* +1 for sentinel */
		set_report(s, got);
		for (i = 0; got[i] != t->max; i++)
			if (got[i] != t->want[i]) {
				printf("FAIL: got[%d](%d)!=want[%d](%d): %9.6fsec\n",
				       i, got[i], i, t->want[i], diff);
				goto fail;
			}
		free(got);
		set_free(s);
		printf("PASS: %9.6fsec\n", diff);
		continue;
fail:
		if (got)
			free(got);
		if (s)
			set_free(s);
		fail++;
	}
	return fail;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x3520, %rsp           # imm = 0x3520
movq %rdi, -0x8(%rbp)
leaq -0x34e0(%rbp), %rdi
leaq 0x2203(%rip), %rsi      # 0x3920
movl $0x34d0, %edx           # imm = 0x34D0
callq 0x1080
movl $0x0, -0x34ec(%rbp)
leaq -0x34e0(%rbp), %rax
movq %rax, -0x34e8(%rbp)
movq -0x34e8(%rbp), %rax
cmpq $0x0, (%rax)
je 0x1a4b
movq $0x0, -0x3510(%rbp)
movq -0x8(%rbp), %rax
movl (%rax), %esi
addl $0x1, %esi
movl %esi, (%rax)
movq -0x34e8(%rbp), %rax
movq (%rax), %rcx
leaq 0x97b(%rip), %rdi       # 0x20f2
leaq 0xaa8(%rip), %rdx       # 0x2226
movb $0x0, %al
callq 0x1060
movq -0x34e8(%rbp), %rax
movl 0x8(%rax), %edi
movq -0x34e8(%rbp), %rax
movl 0xc(%rax), %esi
callq 0x1220
movq %rax, -0x34f8(%rbp)
cmpq $0x0, -0x34f8(%rbp)
jne 0x17fd
movq -0x34e8(%rbp), %rax
movl 0x8(%rax), %eax
movl %eax, -0x351c(%rbp)
movq -0x34e8(%rbp), %rax
movl 0xc(%rax), %eax
movl %eax, -0x3518(%rbp)
callq 0x1040
movl (%rax), %edi
callq 0x10a0
movl -0x351c(%rbp), %esi
movl -0x3518(%rbp), %edx
movq %rax, %rcx
leaq 0xa46(%rip), %rdi       # 0x2237
movb $0x0, %al
callq 0x1060
jmp 0x19f7
callq 0x1050
movq %rax, -0x3508(%rbp)
movl $0x0, -0x3514(%rbp)
movq -0x34e8(%rbp), %rax
movslq -0x3514(%rbp), %rcx
movl 0x10(%rax,%rcx,4), %eax
movq -0x34e8(%rbp), %rcx
cmpl 0xc(%rcx), %eax
je 0x1860
movq -0x34f8(%rbp), %rdi
movq -0x34e8(%rbp), %rax
movslq -0x3514(%rbp), %rcx
movl 0x10(%rax,%rcx,4), %esi
callq 0x1aa0
movl -0x3514(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x3514(%rbp)
jmp 0x1813
callq 0x1050
subq -0x3508(%rbp), %rax
movq %rax, -0x3508(%rbp)
cvtsi2sdq -0x3508(%rbp), %xmm0
movsd 0x7e4(%rip), %xmm1      # 0x2068
divsd %xmm1, %xmm0
movsd %xmm0, -0x3500(%rbp)
movq -0x34f8(%rbp), %rdi
callq 0x1a60
movq -0x34e8(%rbp), %rcx
movslq 0x8(%rcx), %rcx
cmpq %rcx, %rax
je 0x18e0
movq -0x34f8(%rbp), %rdi
callq 0x1a60
movq %rax, %rsi
movq -0x34e8(%rbp), %rax
movl 0x8(%rax), %edx
movsd -0x3500(%rbp), %xmm0
leaq 0x984(%rip), %rdi       # 0x2258
movb $0x1, %al
callq 0x1060
jmp 0x19f7
movq -0x34e8(%rbp), %rax
movl 0x8(%rax), %eax
addl $0x1, %eax
movslq %eax, %rdi
shlq $0x2, %rdi
callq 0x1090
movq %rax, -0x3510(%rbp)
movq -0x34f8(%rbp), %rdi
movq -0x3510(%rbp), %rsi
callq 0x1ad0
movl $0x0, -0x3514(%rbp)
movq -0x3510(%rbp), %rax
movslq -0x3514(%rbp), %rcx
movl (%rax,%rcx,4), %eax
movq -0x34e8(%rbp), %rcx
cmpl 0xc(%rcx), %eax
je 0x19c7
movq -0x3510(%rbp), %rax
movslq -0x3514(%rbp), %rcx
movl (%rax,%rcx,4), %eax
movq -0x34e8(%rbp), %rcx
movslq -0x3514(%rbp), %rdx
cmpl 0x210(%rcx,%rdx,4), %eax
je 0x19b1
movl -0x3514(%rbp), %esi
movq -0x3510(%rbp), %rax
movslq -0x3514(%rbp), %rcx
movl (%rax,%rcx,4), %edx
movl -0x3514(%rbp), %ecx
movq -0x34e8(%rbp), %rax
movslq -0x3514(%rbp), %rdi
movl 0x210(%rax,%rdi,4), %r8d
movsd -0x3500(%rbp), %xmm0
leaq 0x8d4(%rip), %rdi       # 0x227c
movb $0x1, %al
callq 0x1060
jmp 0x19f7
jmp 0x19b3
movl -0x3514(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x3514(%rbp)
jmp 0x191d
movq -0x3510(%rbp), %rdi
callq 0x1030
movq -0x34f8(%rbp), %rdi
callq 0x1a80
movsd -0x3500(%rbp), %xmm0
leaq 0x774(%rip), %rdi       # 0x2162
movb $0x1, %al
callq 0x1060
jmp 0x1a32
cmpq $0x0, -0x3510(%rbp)
je 0x1a0d
movq -0x3510(%rbp), %rdi
callq 0x1030
cmpq $0x0, -0x34f8(%rbp)
je 0x1a23
movq -0x34f8(%rbp), %rdi
callq 0x1a80
movl -0x34ec(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x34ec(%rbp)
movq -0x34e8(%rbp), %rax
addq $0x410, %rax            # imm = 0x410
movq %rax, -0x34e8(%rbp)
jmp 0x173f
movl -0x34ec(%rbp), %eax
addq $0x3520, %rsp           # imm = 0x3520
popq %rbp
retq
nopw (%rax,%rax)