// File: /workspace/github_c_makefile_star2_O0/mjosaarinen[P]brutus/crypto_aead/pi32cipher256v2/ref2/pi-cipher.c
// Function: pi32_init
int PI_INIT(
        PI_CTX *ctx,
        const void *key,
        size_t key_length_b,
        const void *pmn,
        size_t pmn_length_b)
{
	int i;
	uint8_t setup_buf[PI_IS_BITS / 8];
	if ((key_length_b % 8 != 0) || (pmn_length_b % 8 != 0)) {
		return -1;
	}
    if (key_length_b / 8 + pmn_length_b / 8 + 1 >= PI_IS_BITS / 8) {
        return -1;
    }
    memset(ctx->tag, 0, sizeof(ctx->tag));
    memset(setup_buf, 0, sizeof(setup_buf));
    memcpy(setup_buf, key, key_length_b / 8);
    memcpy(&setup_buf[key_length_b / 8], pmn, pmn_length_b / 8);
    setup_buf[key_length_b / 8 + pmn_length_b / 8] = 1;
    for (i = 0; i < 16; ++i) {
        ctx->cis[i / 4][i % 4] = load_word_little(&setup_buf[i * PI_WORD_SIZE / 8]);
    }
    pi((word_t*)ctx->cis);
    ctx->ctr = 0;
    for (i = 0; i * PI_WORD_SIZE < 64; ++i) {
		ctx->ctr |= (uint64_t)ctx->cis[1][i] << (i * PI_WORD_SIZE);
	}
    return 0;
}

// Assembly:
subq $0x98, %rsp
movq %rdi, 0x88(%rsp)
movq %rsi, 0x80(%rsp)
movq %rdx, 0x78(%rsp)
movq %rcx, 0x70(%rsp)
movq %r8, 0x68(%rsp)
movq 0x78(%rsp), %rax
andq $0x7, %rax
cmpq $0x0, %rax
jne 0x1404
movq 0x68(%rsp), %rax
andq $0x7, %rax
cmpq $0x0, %rax
je 0x1414
movl $0xffffffff, 0x94(%rsp) # imm = 0xFFFFFFFF
jmp 0x15cb
movq 0x78(%rsp), %rax
shrq $0x3, %rax
movq 0x68(%rsp), %rcx
shrq $0x3, %rcx
addq %rcx, %rax
addq $0x1, %rax
cmpq $0x40, %rax
jb 0x1443
movl $0xffffffff, 0x94(%rsp) # imm = 0xFFFFFFFF
jmp 0x15cb
movq 0x88(%rsp), %rdi
addq $0x40, %rdi
xorl %esi, %esi
movl $0x20, %edx
callq 0x1030
leaq 0x20(%rsp), %rdi
xorl %esi, %esi
movl $0x40, %edx
callq 0x1030
leaq 0x20(%rsp), %rdi
movq 0x80(%rsp), %rsi
movq 0x78(%rsp), %rdx
shrq $0x3, %rdx
callq 0x1120
movq 0x78(%rsp), %rax
shrq $0x3, %rax
leaq 0x20(%rsp), %rdi
addq %rax, %rdi
movq 0x70(%rsp), %rsi
movq 0x68(%rsp), %rdx
shrq $0x3, %rdx
callq 0x1120
movq 0x78(%rsp), %rax
shrq $0x3, %rax
movq 0x68(%rsp), %rcx
shrq $0x3, %rcx
addq %rcx, %rax
movb $0x1, 0x20(%rsp,%rax)
movl $0x0, 0x64(%rsp)
cmpl $0x10, 0x64(%rsp)
jge 0x1552
movl 0x64(%rsp), %eax
shll $0x5, %eax
movl $0x8, %ecx
cltd
idivl %ecx
cltq
leaq 0x20(%rsp), %rdi
addq %rax, %rdi
callq 0x15e0
movl %eax, 0x1c(%rsp)
movq 0x88(%rsp), %rax
movq %rax, 0x8(%rsp)
movl 0x64(%rsp), %eax
movl $0x4, %ecx
cltd
idivl %ecx
movl %eax, %ecx
movq 0x8(%rsp), %rax
movslq %ecx, %rcx
shlq $0x4, %rcx
addq %rcx, %rax
movq %rax, 0x10(%rsp)
movl 0x64(%rsp), %eax
movl $0x4, %ecx
cltd
idivl %ecx
movq 0x10(%rsp), %rax
movl %edx, %ecx
movl 0x1c(%rsp), %edx
movslq %ecx, %rcx
movl %edx, (%rax,%rcx,4)
movl 0x64(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x64(%rsp)
jmp 0x14cd
movq 0x88(%rsp), %rdi
callq 0x1630
movq 0x88(%rsp), %rax
movq $0x0, 0x60(%rax)
movl $0x0, 0x64(%rsp)
movl 0x64(%rsp), %eax
shll $0x5, %eax
cmpl $0x40, %eax
jge 0x15c0
movq 0x88(%rsp), %rax
movslq 0x64(%rsp), %rcx
movl 0x10(%rax,%rcx,4), %eax
movl 0x64(%rsp), %ecx
shll $0x5, %ecx
movl %ecx, %ecx
shlq %cl, %rax
movq %rax, %rcx
movq 0x88(%rsp), %rax
orq 0x60(%rax), %rcx
movq %rcx, 0x60(%rax)
movl 0x64(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x64(%rsp)
jmp 0x1577
movl $0x0, 0x94(%rsp)
movl 0x94(%rsp), %eax
addq $0x98, %rsp
retq
nopw (%rax,%rax)