// File: /workspace/github_c_makefile_star2_O2/maandree[P]libkeccak/spec/libkeccak_degeneralise_spec.c
// Function: libkeccak_degeneralise_spec
int
libkeccak_degeneralise_spec(struct libkeccak_generalised_spec *restrict spec, struct libkeccak_spec *restrict output_spec)
{
	long int state_size, word_size, capacity, bitrate, output;
	int have_state_size = spec->state_size != LIBKECCAK_GENERALISED_SPEC_AUTOMATIC;
	int have_word_size  = spec->word_size  != LIBKECCAK_GENERALISED_SPEC_AUTOMATIC;
	int have_capacity   = spec->capacity   != LIBKECCAK_GENERALISED_SPEC_AUTOMATIC;
	int have_bitrate    = spec->bitrate    != LIBKECCAK_GENERALISED_SPEC_AUTOMATIC;
	int have_output     = spec->output     != LIBKECCAK_GENERALISED_SPEC_AUTOMATIC;


	if (have_state_size) {
		state_size = spec->state_size;
		if (state_size <= 0)
			return LIBKECCAK_GENERALISED_SPEC_ERROR_STATE_NONPOSITIVE;
		if (state_size > 1600)
			return LIBKECCAK_GENERALISED_SPEC_ERROR_STATE_TOO_LARGE;
		if (state_size % 25)
			return LIBKECCAK_GENERALISED_SPEC_ERROR_STATE_MOD_25;
	}

	if (have_word_size) {
		word_size = spec->word_size;
		if (word_size <= 0)
			return LIBKECCAK_GENERALISED_SPEC_ERROR_WORD_NONPOSITIVE;
		if (word_size > 64)
			return LIBKECCAK_GENERALISED_SPEC_ERROR_WORD_TOO_LARGE;		
		if (have_state_size && state_size != word_size * 25)
			return LIBKECCAK_GENERALISED_SPEC_ERROR_STATE_WORD_INCOHERENCY;
		else if (!have_state_size) {
			have_state_size = 1;
			state_size = word_size * 25;
		}
	}

	if (have_capacity) {
		capacity = spec->capacity;
		if (capacity <= 0)
			return LIBKECCAK_GENERALISED_SPEC_ERROR_CAPACITY_NONPOSITIVE;
		if (capacity & 7)
			return LIBKECCAK_GENERALISED_SPEC_ERROR_CAPACITY_MOD_8;
	}

	if (have_bitrate) {
		bitrate = spec->bitrate;
		if (bitrate <= 0)
			return LIBKECCAK_GENERALISED_SPEC_ERROR_BITRATE_NONPOSITIVE;
		if (bitrate & 7)
			return LIBKECCAK_GENERALISED_SPEC_ERROR_BITRATE_MOD_8;
	}

	if (have_output) {
		output = spec->output;
		if (output <= 0)
			return LIBKECCAK_GENERALISED_SPEC_ERROR_OUTPUT_NONPOSITIVE;
	}


	if (have_bitrate + have_capacity == 2) {
		if (!have_state_size) {
			state_size = bitrate + capacity;
			output = deft(output, capacity * 2L <= 8 ? 8 : capacity * 2L);
		} else if (state_size != bitrate + capacity) {
			return LIBKECCAK_GENERALISED_SPEC_ERROR_STATE_BITRATE_CAPACITY_INCONSISTENCY;
		}
	} else if (have_bitrate + have_capacity == 1) {
		state_size = deft(state_size, 1600L);
		capacity = deft(capacity, state_size - bitrate);
		bitrate = deft(bitrate, state_size - capacity);
		output = deft(output, capacity * 2L <= 8 ? 8 : capacity * 2L);
	} else {
		state_size = deft(state_size, 1600L);
		capacity = state_size * 9 / 25;
		bitrate = state_size - capacity;
		output = deft(output, bitrate / 2L <= 8 ? 8 : bitrate / 2L);
	}


	spec->capacity   = output_spec->capacity = capacity;
	spec->bitrate    = output_spec->bitrate  = bitrate;
	spec->output     = output_spec->output   = output;
	spec->state_size = state_size;
	spec->word_size  = state_size / 25;

	return 0;
}

// Assembly:
pushq %rbp
pushq %rbx
movq 0x18(%rdi), %rcx
movq 0x20(%rdi), %rbx
movq (%rdi), %r9
movq 0x8(%rdi), %r10
movq 0x10(%rdi), %r8
cmpq $-0x10000, %rcx         # imm = 0xFFFF0000
setne %r11b
je 0x7d1a
testq %rcx, %rcx
jle 0x7cf6
cmpq $0x640, %rcx            # imm = 0x640
jbe 0x7d00
movl $0x2, %eax
jmp 0x7f12
movl $0x1, %eax
jmp 0x7f12
movw $0x19, %bp
movl %ecx, %eax
xorl %edx, %edx
divw %bp
testw %dx, %dx
je 0x7d1a
movl $0x3, %eax
jmp 0x7f12
cmpq $-0x10000, %rbx         # imm = 0xFFFF0000
jne 0x7d45
cmpq $-0x10000, %r10         # imm = 0xFFFF0000
je 0x7d5a
testq %r10, %r10
jle 0x7dff
testb $0x7, %r10b
je 0x7d5a
movl $0x8, %eax
jmp 0x7f12
testq %rbx, %rbx
jle 0x7d9a
cmpq $0x40, %rbx
jbe 0x7da4
movl $0x5, %eax
jmp 0x7f12
cmpq $-0x10000, %r9          # imm = 0xFFFF0000
je 0x7d7c
testq %r9, %r9
jle 0x7e1c
testb $0x7, %r9b
je 0x7d7c
movl $0xa, %eax
jmp 0x7f12
cmpq $-0x10000, %r8          # imm = 0xFFFF0000
setne %al
testq %r8, %r8
setle %dl
testb %dl, %al
je 0x7dc8
movl $0xb, %eax
jmp 0x7f12
movl $0x4, %eax
jmp 0x7f12
cmpq $-0x10000, %rcx         # imm = 0xFFFF0000
setne %dl
imulq $0x19, %rbx, %rax
cmpq %rax, %rcx
setne %r11b
testb %r11b, %dl
je 0x7e09
movl $0x6, %eax
jmp 0x7f12
movq $-0x10000, %rax         # imm = 0xFFFF0000
cmpq %rax, %r9
sete %dl
cmpq %rax, %r10
sete %bl
orb %dl, %bl
jne 0x7e26
leaq (%r9,%r10), %rax
testb %r11b, %r11b
je 0x7e83
cmpq %rax, %rcx
je 0x7ee0
movl $0xc, %eax
jmp 0x7f12
movl $0x7, %eax
jmp 0x7f12
cmpq $-0x10000, %rcx         # imm = 0xFFFF0000
cmoveq %rax, %rcx
movb $0x1, %r11b
jmp 0x7d23
movl $0x9, %eax
jmp 0x7f12
cmpq %rax, %r9
setne %dl
cmpq %rax, %r10
setne %al
testb %r11b, %r11b
movl $0x640, %r11d           # imm = 0x640
cmoveq %r11, %rcx
cmpb %dl, %al
je 0x7ea9
movq %rcx, %rax
subq %r9, %rax
movq $-0x10000, %rdx         # imm = 0xFFFF0000
cmpq %rdx, %r10
cmoveq %rax, %r10
movq %rcx, %rax
subq %r10, %rax
cmpq %rdx, %r9
cmoveq %rax, %r9
leaq (%r10,%r10), %rax
cmpq $0x5, %r10
movabsq $0x8, %r11
cmovgeq %rax, %r11
cmpq %rdx, %r8
cmoveq %r11, %r8
jmp 0x7ee0
leaq (%r10,%r10), %rcx
cmpq $0x5, %r10
movabsq $0x8, %rdx
cmovgeq %rcx, %rdx
cmpq $-0x10000, %r8          # imm = 0xFFFF0000
cmoveq %rdx, %r8
movq %rax, %rcx
jmp 0x7ee0
leal (%rcx,%rcx,8), %eax
movl $0x19, %r9d
cltd
idivl %r9d
movslq %eax, %r10
movq %rcx, %r9
subq %r10, %r9
cmpq $-0x10000, %r8          # imm = 0xFFFF0000
jne 0x7ee0
movq %r9, %rax
shrq %rax
cmpq $0x12, %r9
movabsq $0x8, %r8
cmovgeq %rax, %r8
movq %r10, 0x8(%rsi)
movq %r10, 0x8(%rdi)
movq %r9, (%rsi)
movq %r9, (%rdi)
movq %r8, 0x10(%rsi)
movq %r8, 0x10(%rdi)
movq %rcx, 0x18(%rdi)
movabsq $0x19, %rsi
movq %rcx, %rax
cqto
idivq %rsi
movq %rax, 0x20(%rdi)
xorl %eax, %eax
popq %rbx
popq %rbp
retq
nopl (%rax)