// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x50, %rsp
movq $0x0, -0x28(%rbp)
movq $0x0, -0x18(%rbp)
cmpq $0x8, -0x18(%rbp)
jae 0x173f
movq -0x18(%rbp), %rcx
leaq 0x5b42(%rip), %rax      # 0x7100
shlq $0x4, %rcx
addq %rcx, %rax
movq (%rax), %rsi
leaq 0x2aa9(%rip), %rdi      # 0x4078
movb $0x0, %al
callq 0x10d0
leaq -0x8(%rbp), %rdi
callq 0x1a70
movq -0x18(%rbp), %rcx
leaq 0x5b16(%rip), %rax      # 0x7100
shlq $0x4, %rcx
addq %rcx, %rax
movq (%rax), %rax
movq %rax, -0x50(%rbp)
movq -0x18(%rbp), %rcx
leaq 0x5afd(%rip), %rax      # 0x7100
shlq $0x4, %rcx
addq %rcx, %rax
movq (%rax), %rdi
callq 0x10c0
movq -0x50(%rbp), %rsi
movq %rax, %rdx
leaq -0x8(%rbp), %rdi
callq 0x1c10
leaq -0xc(%rbp), %rdi
leaq -0x8(%rbp), %rsi
callq 0x1d80
leaq -0xc(%rbp), %rax
movq -0x18(%rbp), %rdx
leaq 0x5ac2(%rip), %rcx      # 0x7100
shlq $0x4, %rdx
addq %rdx, %rcx
addq $0x8, %rcx
movl (%rcx), %ecx
movl (%rax), %eax
subl %ecx, %eax
setne %al
movzbl %al, %eax
cmpl $0x0, %eax
je 0x171e
leaq 0x2a2f(%rip), %rdi      # 0x4094
movb $0x0, %al
callq 0x10d0
leaq 0x2a2b(%rip), %rdi      # 0x409e
movb $0x0, %al
callq 0x10d0
movq $0x0, -0x20(%rbp)
cmpq $0x4, -0x20(%rbp)
jae 0x16ae
movq -0x20(%rbp), %rax
movzbl -0xc(%rbp,%rax), %esi
leaq 0x2a17(%rip), %rdi      # 0x40b0
movb $0x0, %al
callq 0x10d0
movq -0x20(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x20(%rbp)
jmp 0x1682
leaq 0x2a00(%rip), %rdi      # 0x40b5
movb $0x0, %al
callq 0x10d0
movq $0x0, -0x20(%rbp)
cmpq $0x4, -0x20(%rbp)
jae 0x1702
movq -0x18(%rbp), %rcx
leaq 0x5a2a(%rip), %rax      # 0x7100
shlq $0x4, %rcx
addq %rcx, %rax
movq -0x20(%rbp), %rcx
movzbl 0x8(%rax,%rcx), %esi
leaq 0x29c3(%rip), %rdi      # 0x40b0
movb $0x0, %al
callq 0x10d0
movq -0x20(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x20(%rbp)
jmp 0x16c4
leaq 0x2993(%rip), %rdi      # 0x409c
movb $0x0, %al
callq 0x10d0
movq -0x28(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x28(%rbp)
jmp 0x172c
leaq 0x29a3(%rip), %rdi      # 0x40c8
movb $0x0, %al
callq 0x10d0
jmp 0x172e
movq -0x18(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x18(%rbp)
jmp 0x15a8
leaq 0x298c(%rip), %rdi      # 0x40d2
movb $0x0, %al
callq 0x10d0
movl $0x10000, %edi          # imm = 0x10000
callq 0x1150
movq %rax, -0x30(%rbp)
cmpq $0x0, %rax
jne 0x1766
jmp 0x1889
movq -0x30(%rbp), %rdi
movl $0x55, %esi
movl $0x10000, %edx          # imm = 0x10000
callq 0x10f0
leaq -0x8(%rbp), %rdi
callq 0x1a70
movq -0x30(%rbp), %rsi
leaq -0x8(%rbp), %rdi
movl $0x10000, %edx          # imm = 0x10000
callq 0x1c10
leaq -0xc(%rbp), %rdi
leaq -0x8(%rbp), %rsi
callq 0x1d80
xorl %edi, %edi
callq 0x1080
leaq -0x8(%rbp), %rdi
callq 0x1a70
movq $0x0, -0x38(%rbp)
cmpq $0xff00, -0x38(%rbp)    # imm = 0xFF00
jae 0x17f5
callq 0x1140
andq $0xff, %rax
movq %rax, -0x40(%rbp)
movq -0x30(%rbp), %rsi
addq -0x38(%rbp), %rsi
movq -0x40(%rbp), %rdx
leaq -0x8(%rbp), %rdi
callq 0x1c10
movq -0x40(%rbp), %rax
addq -0x38(%rbp), %rax
movq %rax, -0x38(%rbp)
jmp 0x17b9
movl $0x10000, %eax          # imm = 0x10000
subq -0x38(%rbp), %rax
movq %rax, -0x40(%rbp)
movq -0x30(%rbp), %rsi
addq -0x38(%rbp), %rsi
movq -0x40(%rbp), %rdx
leaq -0x8(%rbp), %rdi
callq 0x1c10
leaq -0x44(%rbp), %rdi
leaq -0x8(%rbp), %rsi
callq 0x1d80
leaq -0xc(%rbp), %rax
leaq -0x44(%rbp), %rcx
movl (%rcx), %ecx
movl (%rax), %eax
subl %ecx, %eax
setne %al
movzbl %al, %eax
cmpl $0x0, %eax
je 0x1859
leaq 0x2850(%rip), %rdi      # 0x4094
movb $0x0, %al
callq 0x10d0
movq -0x28(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x28(%rbp)
jmp 0x1867
leaq 0x2868(%rip), %rdi      # 0x40c8
movb $0x0, %al
callq 0x10d0
movq -0x30(%rbp), %rdi
callq 0x1030
cmpq $0x0, -0x28(%rbp)
je 0x1880
movl $0x1, -0x4(%rbp)
jmp 0x1890
movl $0x0, -0x4(%rbp)
jmp 0x1890
movl $0x1, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x50, %rsp
popq %rbp
retq
nopl (%rax)