// File: JenTus[P]TCEM/src_TCEM/sfmt/SFMT.c
// Function: sfmt_init_by_array
void sfmt_init_by_array(sfmt_t * sfmt, uint32_t *init_key, int key_length) {
    int i, j, count;
    uint32_t r;
    int lag;
    int mid;
    int size = SFMT_N * 4;
    uint32_t *psfmt32 = &sfmt->state[0].u[0];

    if (size >= 623) {
	lag = 11;
    } else if (size >= 68) {
	lag = 7;
    } else if (size >= 39) {
	lag = 5;
    } else {
	lag = 3;
    }
    mid = (size - lag) / 2;

    memset(sfmt, 0x8b, sizeof(sfmt_t));
    if (key_length + 1 > SFMT_N32) {
	count = key_length + 1;
    } else {
	count = SFMT_N32;
    }
    r = func1(psfmt32[idxof(0)] ^ psfmt32[idxof(mid)]
	      ^ psfmt32[idxof(SFMT_N32 - 1)]);
    psfmt32[idxof(mid)] += r;
    r += key_length;
    psfmt32[idxof(mid + lag)] += r;
    psfmt32[idxof(0)] = r;

    count--;
    for (i = 1, j = 0; (j < count) && (j < key_length); j++) {
	r = func1(psfmt32[idxof(i)] ^ psfmt32[idxof((i + mid) % SFMT_N32)]
		  ^ psfmt32[idxof((i + SFMT_N32 - 1) % SFMT_N32)]);
	psfmt32[idxof((i + mid) % SFMT_N32)] += r;
	r += init_key[j] + i;
	psfmt32[idxof((i + mid + lag) % SFMT_N32)] += r;
	psfmt32[idxof(i)] = r;
	i = (i + 1) % SFMT_N32;
    }
    for (; j < count; j++) {
	r = func1(psfmt32[idxof(i)] ^ psfmt32[idxof((i + mid) % SFMT_N32)]
		  ^ psfmt32[idxof((i + SFMT_N32 - 1) % SFMT_N32)]);
	psfmt32[idxof((i + mid) % SFMT_N32)] += r;
	r += i;
	psfmt32[idxof((i + mid + lag) % SFMT_N32)] += r;
	psfmt32[idxof(i)] = r;
	i = (i + 1) % SFMT_N32;
    }
    for (j = 0; j < SFMT_N32; j++) {
	r = func2(psfmt32[idxof(i)] + psfmt32[idxof((i + mid) % SFMT_N32)]
		  + psfmt32[idxof((i + SFMT_N32 - 1) % SFMT_N32)]);
	psfmt32[idxof((i + mid) % SFMT_N32)] ^= r;
	r -= i;
	psfmt32[idxof((i + mid + lag) % SFMT_N32)] ^= r;
	psfmt32[idxof(i)] = r;
	i = (i + 1) % SFMT_N32;
    }

    sfmt->idx = SFMT_N32;
    period_certification(sfmt);
}

// Assembly:
subq $0x188, %rsp            # imm = 0x188
movq %rdi, 0x180(%rsp)
movq %rsi, 0x178(%rsp)
movl %edx, 0x174(%rsp)
movl $0x270, 0x158(%rsp) # imm = 0x270
movq 0x180(%rsp), %rax
movq %rax, 0x150(%rsp)
cmpl $0x26f, 0x158(%rsp) # imm = 0x26F
jl 0x227d3
movl $0xb, 0x160(%rsp)
jmp 0x22810
cmpl $0x44, 0x158(%rsp)
jl 0x227ea
movl $0x7, 0x160(%rsp)
jmp 0x2280e
cmpl $0x27, 0x158(%rsp)
jl 0x22801
movl $0x5, 0x160(%rsp)
jmp 0x2280c
movl $0x3, 0x160(%rsp)
jmp 0x2280e
jmp 0x22810
movl 0x158(%rsp), %eax
subl 0x160(%rsp), %eax
movl $0x2, %ecx
cltd
idivl %ecx
movl %eax, 0x15c(%rsp)
movq 0x180(%rsp), %rdi
movl $0x8b, %esi
movl $0x9c8, %edx            # imm = 0x9C8
callq 0x41b0
movl 0x174(%rsp), %eax
addl $0x1, %eax
cmpl $0x270, %eax            # imm = 0x270
jle 0x22868
movl 0x174(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x168(%rsp)
jmp 0x22873
movl $0x270, 0x168(%rsp) # imm = 0x270
movq 0x150(%rsp), %rax
movq %rax, 0x100(%rsp)
xorl %edi, %edi
callq 0x22610
movl %eax, %ecx
movq 0x100(%rsp), %rax
movslq %ecx, %rcx
movl (%rax,%rcx,4), %eax
movl %eax, 0x110(%rsp)
movq 0x150(%rsp), %rax
movq %rax, 0x108(%rsp)
movl 0x15c(%rsp), %edi
callq 0x22610
movq 0x108(%rsp), %rcx
movl %eax, %edx
movl 0x110(%rsp), %eax
movslq %edx, %rdx
xorl (%rcx,%rdx,4), %eax
movl %eax, 0x114(%rsp)
movq 0x150(%rsp), %rax
movq %rax, 0x118(%rsp)
movl $0x26f, %edi            # imm = 0x26F
callq 0x22610
movl 0x114(%rsp), %edi
movl %eax, %ecx
movq 0x118(%rsp), %rax
movslq %ecx, %rcx
xorl (%rax,%rcx,4), %edi
callq 0x23080
movl %eax, 0x164(%rsp)
movl 0x164(%rsp), %eax
movl %eax, 0x124(%rsp)
movq 0x150(%rsp), %rax
movq %rax, 0x128(%rsp)
movl 0x15c(%rsp), %edi
callq 0x22610
movl 0x124(%rsp), %edx
movl %eax, %ecx
movq 0x128(%rsp), %rax
movslq %ecx, %rcx
addl (%rax,%rcx,4), %edx
movl %edx, (%rax,%rcx,4)
movl 0x174(%rsp), %eax
addl 0x164(%rsp), %eax
movl %eax, 0x164(%rsp)
movl 0x164(%rsp), %eax
movl %eax, 0x134(%rsp)
movq 0x150(%rsp), %rax
movq %rax, 0x138(%rsp)
movl 0x15c(%rsp), %edi
addl 0x160(%rsp), %edi
callq 0x22610
movl 0x134(%rsp), %edx
movl %eax, %ecx
movq 0x138(%rsp), %rax
movslq %ecx, %rcx
addl (%rax,%rcx,4), %edx
movl %edx, (%rax,%rcx,4)
movl 0x164(%rsp), %eax
movl %eax, 0x144(%rsp)
movq 0x150(%rsp), %rax
movq %rax, 0x148(%rsp)
xorl %edi, %edi
callq 0x22610
movl 0x144(%rsp), %edx
movl %eax, %ecx
movq 0x148(%rsp), %rax
movslq %ecx, %rcx
movl %edx, (%rax,%rcx,4)
movl 0x168(%rsp), %eax
addl $-0x1, %eax
movl %eax, 0x168(%rsp)
movl $0x1, 0x170(%rsp)
movl $0x0, 0x16c(%rsp)
movl 0x16c(%rsp), %ecx
xorl %eax, %eax
cmpl 0x168(%rsp), %ecx
movb %al, 0xff(%rsp)
jge 0x22a50
movl 0x16c(%rsp), %eax
cmpl 0x174(%rsp), %eax
setl %al
movb %al, 0xff(%rsp)
movb 0xff(%rsp), %al
testb $0x1, %al
jne 0x22a60
jmp 0x22c78
movq 0x150(%rsp), %rax
movq %rax, 0xa8(%rsp)
movl 0x170(%rsp), %edi
callq 0x22610
movl %eax, %ecx
movq 0xa8(%rsp), %rax
movslq %ecx, %rcx
movl (%rax,%rcx,4), %eax
movl %eax, 0xb8(%rsp)
movq 0x150(%rsp), %rax
movq %rax, 0xb0(%rsp)
movl 0x170(%rsp), %eax
addl 0x15c(%rsp), %eax
movl $0x270, %ecx            # imm = 0x270
cltd
idivl %ecx
movl %edx, %edi
callq 0x22610
movq 0xb0(%rsp), %rcx
movl %eax, %edx
movl 0xb8(%rsp), %eax
movslq %edx, %rdx
xorl (%rcx,%rdx,4), %eax
movl %eax, 0xbc(%rsp)
movq 0x150(%rsp), %rax
movq %rax, 0xc0(%rsp)
movl 0x170(%rsp), %eax
addl $0x270, %eax            # imm = 0x270
subl $0x1, %eax
movl $0x270, %ecx            # imm = 0x270
cltd
idivl %ecx
movl %edx, %edi
callq 0x22610
movl 0xbc(%rsp), %edi
movl %eax, %ecx
movq 0xc0(%rsp), %rax
movslq %ecx, %rcx
xorl (%rax,%rcx,4), %edi
callq 0x23080
movl %eax, 0x164(%rsp)
movl 0x164(%rsp), %eax
movl %eax, 0xcc(%rsp)
movq 0x150(%rsp), %rax
movq %rax, 0xd0(%rsp)
movl 0x170(%rsp), %eax
addl 0x15c(%rsp), %eax
movl $0x270, %ecx            # imm = 0x270
cltd
idivl %ecx
movl %edx, %edi
callq 0x22610
movl 0xcc(%rsp), %edx
movl %eax, %ecx
movq 0xd0(%rsp), %rax
movslq %ecx, %rcx
addl (%rax,%rcx,4), %edx
movl %edx, (%rax,%rcx,4)
movq 0x178(%rsp), %rax
movslq 0x16c(%rsp), %rcx
movl (%rax,%rcx,4), %eax
addl 0x170(%rsp), %eax
addl 0x164(%rsp), %eax
movl %eax, 0x164(%rsp)
movl 0x164(%rsp), %eax
movl %eax, 0xdc(%rsp)
movq 0x150(%rsp), %rax
movq %rax, 0xe0(%rsp)
movl 0x170(%rsp), %eax
addl 0x15c(%rsp), %eax
addl 0x160(%rsp), %eax
movl $0x270, %ecx            # imm = 0x270
cltd
idivl %ecx
movl %edx, %edi
callq 0x22610
movl 0xdc(%rsp), %edx
movl %eax, %ecx
movq 0xe0(%rsp), %rax
movslq %ecx, %rcx
addl (%rax,%rcx,4), %edx
movl %edx, (%rax,%rcx,4)
movl 0x164(%rsp), %eax
movl %eax, 0xec(%rsp)
movq 0x150(%rsp), %rax
movq %rax, 0xf0(%rsp)
movl 0x170(%rsp), %edi
callq 0x22610
movl 0xec(%rsp), %edx
movl %eax, %ecx
movq 0xf0(%rsp), %rax
movslq %ecx, %rcx
movl %edx, (%rax,%rcx,4)
movl 0x170(%rsp), %eax
addl $0x1, %eax
movl $0x270, %ecx            # imm = 0x270
cltd
idivl %ecx
movl %edx, 0x170(%rsp)
movl 0x16c(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x16c(%rsp)
jmp 0x22a1f
jmp 0x22c7a
movl 0x16c(%rsp), %eax
cmpl 0x168(%rsp), %eax
jge 0x22e6f
movq 0x150(%rsp), %rax
movq %rax, 0x58(%rsp)
movl 0x170(%rsp), %edi
callq 0x22610
movl %eax, %ecx
movq 0x58(%rsp), %rax
movslq %ecx, %rcx
movl (%rax,%rcx,4), %eax
movl %eax, 0x68(%rsp)
movq 0x150(%rsp), %rax
movq %rax, 0x60(%rsp)
movl 0x170(%rsp), %eax
addl 0x15c(%rsp), %eax
movl $0x270, %ecx            # imm = 0x270
cltd
idivl %ecx
movl %edx, %edi
callq 0x22610
movq 0x60(%rsp), %rcx
movl %eax, %edx
movl 0x68(%rsp), %eax
movslq %edx, %rdx
xorl (%rcx,%rdx,4), %eax
movl %eax, 0x6c(%rsp)
movq 0x150(%rsp), %rax
movq %rax, 0x70(%rsp)
movl 0x170(%rsp), %eax
addl $0x270, %eax            # imm = 0x270
subl $0x1, %eax
movl $0x270, %ecx            # imm = 0x270
cltd
idivl %ecx
movl %edx, %edi
callq 0x22610
movl 0x6c(%rsp), %edi
movl %eax, %ecx
movq 0x70(%rsp), %rax
movslq %ecx, %rcx
xorl (%rax,%rcx,4), %edi
callq 0x23080
movl %eax, 0x164(%rsp)
movl 0x164(%rsp), %eax
movl %eax, 0x7c(%rsp)
movq 0x150(%rsp), %rax
movq %rax, 0x80(%rsp)
movl 0x170(%rsp), %eax
addl 0x15c(%rsp), %eax
movl $0x270, %ecx            # imm = 0x270
cltd
idivl %ecx
movl %edx, %edi
callq 0x22610
movl 0x7c(%rsp), %edx
movl %eax, %ecx
movq 0x80(%rsp), %rax
movslq %ecx, %rcx
addl (%rax,%rcx,4), %edx
movl %edx, (%rax,%rcx,4)
movl 0x170(%rsp), %eax
addl 0x164(%rsp), %eax
movl %eax, 0x164(%rsp)
movl 0x164(%rsp), %eax
movl %eax, 0x8c(%rsp)
movq 0x150(%rsp), %rax
movq %rax, 0x90(%rsp)
movl 0x170(%rsp), %eax
addl 0x15c(%rsp), %eax
addl 0x160(%rsp), %eax
movl $0x270, %ecx            # imm = 0x270
cltd
idivl %ecx
movl %edx, %edi
callq 0x22610
movl 0x8c(%rsp), %edx
movl %eax, %ecx
movq 0x90(%rsp), %rax
movslq %ecx, %rcx
addl (%rax,%rcx,4), %edx
movl %edx, (%rax,%rcx,4)
movl 0x164(%rsp), %eax
movl %eax, 0x9c(%rsp)
movq 0x150(%rsp), %rax
movq %rax, 0xa0(%rsp)
movl 0x170(%rsp), %edi
callq 0x22610
movl 0x9c(%rsp), %edx
movl %eax, %ecx
movq 0xa0(%rsp), %rax
movslq %ecx, %rcx
movl %edx, (%rax,%rcx,4)
movl 0x170(%rsp), %eax
addl $0x1, %eax
movl $0x270, %ecx            # imm = 0x270
cltd
idivl %ecx
movl %edx, 0x170(%rsp)
movl 0x16c(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x16c(%rsp)
jmp 0x22c7a
movl $0x0, 0x16c(%rsp)
cmpl $0x270, 0x16c(%rsp) # imm = 0x270
jge 0x23050
movq 0x150(%rsp), %rax
movq %rax, 0x8(%rsp)
movl 0x170(%rsp), %edi
callq 0x22610
movl %eax, %ecx
movq 0x8(%rsp), %rax
movslq %ecx, %rcx
movl (%rax,%rcx,4), %eax
movl %eax, 0x18(%rsp)
movq 0x150(%rsp), %rax
movq %rax, 0x10(%rsp)
movl 0x170(%rsp), %eax
addl 0x15c(%rsp), %eax
movl $0x270, %ecx            # imm = 0x270
cltd
idivl %ecx
movl %edx, %edi
callq 0x22610
movq 0x10(%rsp), %rcx
movl %eax, %edx
movl 0x18(%rsp), %eax
movslq %edx, %rdx
addl (%rcx,%rdx,4), %eax
movl %eax, 0x1c(%rsp)
movq 0x150(%rsp), %rax
movq %rax, 0x20(%rsp)
movl 0x170(%rsp), %eax
addl $0x270, %eax            # imm = 0x270
subl $0x1, %eax
movl $0x270, %ecx            # imm = 0x270
cltd
idivl %ecx
movl %edx, %edi
callq 0x22610
movl 0x1c(%rsp), %edi
movl %eax, %ecx
movq 0x20(%rsp), %rax
movslq %ecx, %rcx
addl (%rax,%rcx,4), %edi
callq 0x230a0
movl %eax, 0x164(%rsp)
movl 0x164(%rsp), %eax
movl %eax, 0x2c(%rsp)
movq 0x150(%rsp), %rax
movq %rax, 0x30(%rsp)
movl 0x170(%rsp), %eax
addl 0x15c(%rsp), %eax
movl $0x270, %ecx            # imm = 0x270
cltd
idivl %ecx
movl %edx, %edi
callq 0x22610
movl 0x2c(%rsp), %edx
movl %eax, %ecx
movq 0x30(%rsp), %rax
movslq %ecx, %rcx
xorl (%rax,%rcx,4), %edx
movl %edx, (%rax,%rcx,4)
movl 0x170(%rsp), %ecx
movl 0x164(%rsp), %eax
subl %ecx, %eax
movl %eax, 0x164(%rsp)
movl 0x164(%rsp), %eax
movl %eax, 0x3c(%rsp)
movq 0x150(%rsp), %rax
movq %rax, 0x40(%rsp)
movl 0x170(%rsp), %eax
addl 0x15c(%rsp), %eax
addl 0x160(%rsp), %eax
movl $0x270, %ecx            # imm = 0x270
cltd
idivl %ecx
movl %edx, %edi
callq 0x22610
movl 0x3c(%rsp), %edx
movl %eax, %ecx
movq 0x40(%rsp), %rax
movslq %ecx, %rcx
xorl (%rax,%rcx,4), %edx
movl %edx, (%rax,%rcx,4)
movl 0x164(%rsp), %eax
movl %eax, 0x4c(%rsp)
movq 0x150(%rsp), %rax
movq %rax, 0x50(%rsp)
movl 0x170(%rsp), %edi
callq 0x22610
movl 0x4c(%rsp), %edx
movl %eax, %ecx
movq 0x50(%rsp), %rax
movslq %ecx, %rcx
movl %edx, (%rax,%rcx,4)
movl 0x170(%rsp), %eax
addl $0x1, %eax
movl $0x270, %ecx            # imm = 0x270
cltd
idivl %ecx
movl %edx, 0x170(%rsp)
movl 0x16c(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x16c(%rsp)
jmp 0x22e7a
movq 0x180(%rsp), %rax
movl $0x270, 0x9c0(%rax)     # imm = 0x270
movq 0x180(%rsp), %rdi
callq 0x22620
addq $0x188, %rsp            # imm = 0x188
retq
nopw (%rax,%rax)