// File: /workspace/github_c_makefile_star2_O1/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 0x575e(%rip), %rbx      # 0x7128
leaq 0x269e(%rip), %r12      # 0x406f
movq $0x0, 0x8(%rsp)
xorl %r15d, %r15d
movq %r15, %r13
shlq $0x4, %r13
leaq 0x5735(%rip), %rax      # 0x7120
movq (%r13,%rax), %rsi
leaq 0x264a(%rip), %rdi      # 0x4041
xorl %eax, %eax
callq 0x10f0
leaq 0x4(%rsp), %r14
movq %r14, %rdi
callq 0x1c9c
leaq 0x570e(%rip), %rax      # 0x7120
movq (%r13,%rax), %rbp
movq %rbp, %rdi
callq 0x10e0
movq %r14, %rdi
movq %rbp, %rsi
movq %rax, %rdx
callq 0x1f4c
movq %rsp, %rdi
movq %r14, %rsi
callq 0x2034
movl (%rsp), %eax
leaq 0x56de(%rip), %rcx      # 0x7120
cmpl 0x8(%r13,%rcx), %eax
je 0x1ab8
leaq 0x26f3(%rip), %rdi      # 0x4143
callq 0x10b0
leaq 0x2601(%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 0x1a66
leaq 0x25ef(%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 0x1a8f
movl $0xa, %edi
callq 0x1040
incq 0x8(%rsp)
jmp 0x1ac4
leaq 0x267b(%rip), %rdi      # 0x413a
callq 0x10b0
incq %r15
addq $0x10, %rbx
cmpq $0x8, %r15
jne 0x19dd
leaq 0x25ab(%rip), %rdi      # 0x4087
xorl %eax, %eax
callq 0x10f0
movl $0x10000, %edi          # imm = 0x10000
callq 0x1180
testq %rax, %rax
je 0x1bb5
movq %rax, %rbx
movl $0x10000, %edx          # imm = 0x10000
movq %rax, %rdi
movl $0x55, %esi
callq 0x1120
leaq 0x4(%rsp), %r14
movq %r14, %rdi
callq 0x1c9c
movl $0x10000, %edx          # imm = 0x10000
movq %r14, %rdi
movq %rbx, %rsi
callq 0x1f4c
movq %rsp, %rdi
movq %r14, %rsi
callq 0x2034
xorl %r15d, %r15d
xorl %edi, %edi
callq 0x1090
movq %r14, %rdi
callq 0x1c9c
movq %r15, %r12
callq 0x1170
movzbl %al, %r15d
leaq (%rbx,%r12), %rsi
movq %r14, %rdi
movq %r15, %rdx
callq 0x1f4c
addq %r12, %r15
cmpq $0xff00, %r15           # imm = 0xFF00
jb 0x1b45
movl $0x10000, %edx          # imm = 0x10000
subq %r15, %rdx
movq %rbx, %rsi
addq %r15, %rsi
leaq 0x4(%rsp), %r14
movq %r14, %rdi
callq 0x1f4c
leaq 0x14(%rsp), %r15
movq %r15, %rdi
movq %r14, %rsi
callq 0x2034
movl (%rsp), %eax
cmpl (%r15), %eax
je 0x1bbc
leaq 0x259d(%rip), %rdi      # 0x4143
callq 0x10b0
movq 0x8(%rsp), %r14
incq %r14
jmp 0x1bcd
movl $0x1, %eax
jmp 0x1bdd
leaq 0x2577(%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