// File: /workspace/github_c_makefile_star2_O3/Tarsnap[P]libcperciva/tests/crc32/main.c
// Function: selftest
static int
selftest(void)
{
	CRC32C_CTX ctx;
	uint8_t cbuf[4];
	size_t i, j;
	size_t failures = 0;
	char * largebuf;
	size_t bytes_processed;
	size_t new_chunk;
	uint8_t alt_buf[4];

	/* Run regular test cases. */
	for (i = 0; i < sizeof(tests) / sizeof(tests[0]); i++) {
		printf("Computing CRC32C of \"%s\"...", tests[i].s);
		CRC32C_Init(&ctx);
		CRC32C_Update(&ctx, (const uint8_t *)tests[i].s,
		    strlen(tests[i].s));
		CRC32C_Final(cbuf, &ctx);
		if (memcmp(cbuf, tests[i].cbuf, 4)) {
			printf(" FAILED!\n");
			printf("Computed CRC32C: ");
			for (j = 0; j < 4; j++)
				printf("%02x", cbuf[j]);
			printf("\nCorrect CRC32C:  ");
			for (j = 0; j < 4; j++)
				printf("%02x", tests[i].cbuf[j]);
			printf("\n");
			failures++;
		} else {
			printf(" PASSED!\n");
		}
	}

	/* Test with a large buffer and unaligned access. */
	printf("Computing CRC32C of a large buffer two different ways...");

	/* Prepare a large buffer with repeating 01010101_2 = 85. */
	if ((largebuf = malloc(LARGE_BUFSIZE)) == NULL)
		goto err0;
	memset(largebuf, 85, LARGE_BUFSIZE);

	/* Compute checksum with one call. */
	CRC32C_Init(&ctx);
	CRC32C_Update(&ctx, (const uint8_t *)largebuf, LARGE_BUFSIZE);
	CRC32C_Final(cbuf, &ctx);

	/* Ensure we have a repeatable pattern of random values. */
	srandom(0);

	/* Compute checksum with multiple calls. */
	CRC32C_Init(&ctx);
	bytes_processed = 0;
	while (bytes_processed < LARGE_BUFSIZE - MAX_CHUNK) {
		/* Get an insecure random number; not used for cryptography. */
		new_chunk = ((unsigned long int)random()) % MAX_CHUNK;

		/* Process that amount of data. */
		CRC32C_Update(&ctx, (const uint8_t *)&largebuf[bytes_processed],
		    new_chunk);
		bytes_processed += new_chunk;
	}
	new_chunk = LARGE_BUFSIZE - bytes_processed;
	CRC32C_Update(&ctx, (const uint8_t *)&largebuf[bytes_processed],
	    new_chunk);
	CRC32C_Final(alt_buf, &ctx);

	/* Compare checksums. */
	if (memcmp(cbuf, alt_buf, 4)) {
		printf(" FAILED!\n");
		failures++;
	} else
		printf(" PASSED!\n");

	/* Clean up. */
	free(largebuf);

	/* Report overall success to exit code. */
	if (failures)
		return (1);
	else
		return (0);

err0:
	/* Failure! */
	return (1);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
leaq 0x571e(%rip), %rbx      # 0x7128
leaq 0x265e(%rip), %r12      # 0x406f
movq $0x0, 0x8(%rsp)
xorl %r15d, %r15d
movq %r15, %r13
shlq $0x4, %r13
leaq 0x56f5(%rip), %rax      # 0x7120
movq (%r13,%rax), %rsi
leaq 0x260a(%rip), %rdi      # 0x4041
xorl %eax, %eax
callq 0x10f0
leaq 0x4(%rsp), %r14
movq %r14, %rdi
callq 0x1cdc
leaq 0x56ce(%rip), %rax      # 0x7120
movq (%r13,%rax), %rbp
movq %rbp, %rdi
callq 0x10e0
movq %r14, %rdi
movq %rbp, %rsi
movq %rax, %rdx
callq 0x1f8c
movq %rsp, %rdi
movq %r14, %rsi
callq 0x2074
movl (%rsp), %eax
leaq 0x569e(%rip), %rcx      # 0x7120
cmpl 0x8(%r13,%rcx), %eax
je 0x1af8
leaq 0x26b3(%rip), %rdi      # 0x4143
callq 0x10b0
leaq 0x25c1(%rip), %rdi      # 0x405d
xorl %eax, %eax
callq 0x10f0
xorl %r13d, %r13d
movzbl (%rsp,%r13), %esi
movq %r12, %rdi
xorl %eax, %eax
callq 0x10f0
incq %r13
cmpq $0x4, %r13
jne 0x1aa6
leaq 0x25af(%rip), %rdi      # 0x4074
xorl %eax, %eax
callq 0x10f0
xorl %r13d, %r13d
movzbl (%rbx,%r13), %esi
movq %r12, %rdi
xorl %eax, %eax
callq 0x10f0
incq %r13
cmpq $0x4, %r13
jne 0x1acf
movl $0xa, %edi
callq 0x1040
incq 0x8(%rsp)
jmp 0x1b04
leaq 0x263b(%rip), %rdi      # 0x413a
callq 0x10b0
incq %r15
addq $0x10, %rbx
cmpq $0x8, %r15
jne 0x1a1d
leaq 0x256b(%rip), %rdi      # 0x4087
xorl %eax, %eax
callq 0x10f0
movl $0x10000, %edi          # imm = 0x10000
callq 0x1180
testq %rax, %rax
je 0x1bf5
movq %rax, %rbx
movl $0x10000, %edx          # imm = 0x10000
movq %rax, %rdi
movl $0x55, %esi
callq 0x1120
leaq 0x4(%rsp), %r14
movq %r14, %rdi
callq 0x1cdc
movl $0x10000, %edx          # imm = 0x10000
movq %r14, %rdi
movq %rbx, %rsi
callq 0x1f8c
movq %rsp, %rdi
movq %r14, %rsi
callq 0x2074
xorl %r15d, %r15d
xorl %edi, %edi
callq 0x1090
movq %r14, %rdi
callq 0x1cdc
movq %r15, %r12
callq 0x1170
movzbl %al, %r15d
leaq (%rbx,%r12), %rsi
movq %r14, %rdi
movq %r15, %rdx
callq 0x1f8c
addq %r12, %r15
cmpq $0xff00, %r15           # imm = 0xFF00
jb 0x1b85
movl $0x10000, %edx          # imm = 0x10000
subq %r15, %rdx
movq %rbx, %rsi
addq %r15, %rsi
leaq 0x4(%rsp), %r14
movq %r14, %rdi
callq 0x1f8c
leaq 0x14(%rsp), %r15
movq %r15, %rdi
movq %r14, %rsi
callq 0x2074
movl (%rsp), %eax
cmpl (%r15), %eax
je 0x1bfc
leaq 0x255d(%rip), %rdi      # 0x4143
callq 0x10b0
movq 0x8(%rsp), %r14
incq %r14
jmp 0x1c0d
movl $0x1, %eax
jmp 0x1c1d
leaq 0x2537(%rip), %rdi      # 0x413a
callq 0x10b0
movq 0x8(%rsp), %r14
movq %rbx, %rdi
callq 0x1030
xorl %eax, %eax
testq %r14, %r14
setne %al
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq