// File: /workspace/github_c_makefile_star2_O0/maandree[P]libkeccak/test.c
// Function: test_state
static int
test_state(struct libkeccak_spec *restrict spec)
{
	struct libkeccak_state *restrict state;
	struct libkeccak_state *restrict state2;
	size_t marshal_size, marshalled_size, i, n;
	char *restrict marshalled_data;

	state = libkeccak_state_create(spec);
	if (!state) {
		perror("libkeccak_state_initialise");
		return -1;
	}

	n = state->mlen / 2;
	for (i = 0; i < n; i++)
		state->M[state->mptr++] = (unsigned char)i;

	state2 = libkeccak_state_duplicate(state);
	if (!state2) {
		perror("libkeccak_state_duplicate");
		return -1;
	}

	if (state->M[state->mptr - 1] != state2->M[state2->mptr - 1]) {
		printf("Inconsistency found between original state and duplicate state.\n");
		return -1;
	}

	marshal_size = libkeccak_state_marshal(state2, NULL);
	marshalled_data = malloc(marshal_size);
	if (!marshalled_data) {
		perror("malloc");
		return -1;
	}

	marshalled_size = libkeccak_state_marshal(state2, marshalled_data);
	if (marshalled_size != marshal_size) {
		printf("libkeccak_state_marshal returned an unexpected value.\n");
		return -1;
	}

	libkeccak_state_free(state);

	state = malloc(sizeof(struct libkeccak_state));
	if (!state) {
		perror("malloc");
		return -1;
	}
	marshalled_size = libkeccak_state_unmarshal(state, marshalled_data);
	if (!marshalled_size) {
		perror("libkeccak_state_unmarshal");
		return -1;
	}
	if (marshalled_size != marshal_size) {
		printf("libkeccak_state_unmarshal returned an unexpected value.\n");
		return -1;
	}

	if (libkeccak_state_unmarshal(NULL, marshalled_data) != marshal_size) {
		printf("libkeccak_state_unmarshal(NULL, .) returned an unexpected value.\n");
		return -1;
	}

	if (state->M[state->mptr - 1] != state2->M[state2->mptr - 1]) {
		printf("Inconsistency found between original state and unmarshalled state.\n");
		return -1;
	}

	free(marshalled_data);
	libkeccak_state_free(state);
	libkeccak_state_free(state2);
	return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x50, %rsp
movq %rdi, -0x10(%rbp)
movq -0x10(%rbp), %rdi
callq 0xb200
movq %rax, -0x18(%rbp)
cmpq $0x0, -0x18(%rbp)
jne 0x1608
leaq 0xbc2c(%rip), %rdi      # 0xd223
callq 0x1100
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x188c
movq -0x18(%rbp), %rax
movq 0x110(%rax), %rax
shrq %rax
movq %rax, -0x40(%rbp)
movq $0x0, -0x38(%rbp)
movq -0x38(%rbp), %rax
cmpq -0x40(%rbp), %rax
jae 0x1667
movq -0x38(%rbp), %rax
movb %al, %dl
movq -0x18(%rbp), %rax
movq 0x118(%rax), %rax
movq -0x18(%rbp), %rsi
movq 0x108(%rsi), %rcx
movq %rcx, %rdi
addq $0x1, %rdi
movq %rdi, 0x108(%rsi)
movb %dl, (%rax,%rcx)
movq -0x38(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x38(%rbp)
jmp 0x1622
movq -0x18(%rbp), %rdi
callq 0xb260
movq %rax, -0x20(%rbp)
cmpq $0x0, -0x20(%rbp)
jne 0x1693
leaq 0xbbbc(%rip), %rdi      # 0xd23e
callq 0x1100
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x188c
movq -0x18(%rbp), %rax
movq 0x118(%rax), %rax
movq -0x18(%rbp), %rcx
movq 0x108(%rcx), %rcx
subq $0x1, %rcx
movzbl (%rax,%rcx), %eax
movq -0x20(%rbp), %rcx
movq 0x118(%rcx), %rcx
movq -0x20(%rbp), %rdx
movq 0x108(%rdx), %rdx
subq $0x1, %rdx
movzbl (%rcx,%rdx), %ecx
cmpl %ecx, %eax
je 0x16ed
leaq 0xbb7e(%rip), %rdi      # 0xd258
movb $0x0, %al
callq 0x1060
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x188c
movq -0x20(%rbp), %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0xb310
movq %rax, -0x28(%rbp)
movq -0x28(%rbp), %rdi
callq 0x10c0
movq %rax, -0x48(%rbp)
cmpq $0x0, -0x48(%rbp)
jne 0x172a
leaq 0xbb80(%rip), %rdi      # 0xd299
callq 0x1100
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x188c
movq -0x20(%rbp), %rdi
movq -0x48(%rbp), %rsi
callq 0xb310
movq %rax, -0x30(%rbp)
movq -0x30(%rbp), %rax
cmpq -0x28(%rbp), %rax
je 0x175f
leaq 0xbb54(%rip), %rdi      # 0xd2a0
movb $0x0, %al
callq 0x1060
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x188c
movq -0x18(%rbp), %rdi
callq 0xb2c0
movl $0x120, %edi            # imm = 0x120
callq 0x10c0
movq %rax, -0x18(%rbp)
cmpq $0x0, -0x18(%rbp)
jne 0x1795
leaq 0xbb15(%rip), %rdi      # 0xd299
callq 0x1100
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x188c
movq -0x18(%rbp), %rdi
movq -0x48(%rbp), %rsi
callq 0xb540
movq %rax, -0x30(%rbp)
cmpq $0x0, -0x30(%rbp)
jne 0x17c5
leaq 0xbb23(%rip), %rdi      # 0xd2d7
callq 0x1100
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x188c
movq -0x30(%rbp), %rax
cmpq -0x28(%rbp), %rax
je 0x17e9
leaq 0xbb1b(%rip), %rdi      # 0xd2f1
movb $0x0, %al
callq 0x1060
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x188c
movq -0x48(%rbp), %rsi
xorl %eax, %eax
movl %eax, %edi
callq 0xb540
cmpq -0x28(%rbp), %rax
je 0x1813
leaq 0xbb27(%rip), %rdi      # 0xd32a
movb $0x0, %al
callq 0x1060
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x188c
movq -0x18(%rbp), %rax
movq 0x118(%rax), %rax
movq -0x18(%rbp), %rcx
movq 0x108(%rcx), %rcx
subq $0x1, %rcx
movzbl (%rax,%rcx), %eax
movq -0x20(%rbp), %rcx
movq 0x118(%rcx), %rcx
movq -0x20(%rbp), %rdx
movq 0x108(%rdx), %rdx
subq $0x1, %rdx
movzbl (%rcx,%rdx), %ecx
cmpl %ecx, %eax
je 0x186a
leaq 0xbb12(%rip), %rdi      # 0xd36c
movb $0x0, %al
callq 0x1060
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x188c
movq -0x48(%rbp), %rdi
callq 0x1030
movq -0x18(%rbp), %rdi
callq 0xb2c0
movq -0x20(%rbp), %rdi
callq 0xb2c0
movl $0x0, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x50, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)