// File: /workspace/github_cpp_makefile_star2_O2/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:
pushq %r15
pushq %r14
pushq %rbx
movl %edx, %r14d
movq %rsi, %r15
movq %rdi, %rbx
movl $0x9c8, %edx            # imm = 0x9C8
movl $0x8b, %esi
callq 0x3170
movl $0xdd4afe5d, %eax       # imm = 0xDD4AFE5D
movl %eax, 0x4c8(%rbx)
leal 0x51bf72d2(%r14), %ecx
addl %r14d, %eax
movl %eax, 0x4f4(%rbx)
movl %ecx, (%rbx)
xorl %esi, %esi
testl %r14d, %r14d
movl $0x0, %ecx
cmovgl %r14d, %ecx
pushq $0x1
popq %rdx
movl $0x270, %edi            # imm = 0x270
cmpq %rsi, %rcx
je 0xdc4b
movslq %edx, %r8
movl (%rbx,%r8,4), %r9d
leal 0x132(%r8), %eax
cltd
idivl %edi
movslq %edx, %r10
movl (%rbx,%r10,4), %r11d
leal 0x26f(%r8), %eax
cltd
idivl %edi
movslq %edx, %rax
xorl (%rbx,%rax,4), %r9d
xorl %r11d, %r9d
movl %r9d, %eax
shrl $0x1b, %eax
xorl %r9d, %eax
imull $0x19660d, %eax, %eax   # imm = 0x19660D
addl %eax, %r11d
movl %r11d, (%rbx,%r10,4)
movl (%r15,%rsi,4), %r9d
addl %r8d, %r9d
addl %eax, %r9d
leal 0x13d(%r8), %eax
cltd
idivl %edi
movslq %edx, %rax
addl %r9d, (%rbx,%rax,4)
movl %r9d, (%rbx,%r8,4)
leal 0x1(%r8), %eax
cltd
idivl %edi
incq %rsi
jmp 0xdbd9
cmpl $0x270, %r14d           # imm = 0x270
movl $0x26f, %esi            # imm = 0x26F
cmovgel %r14d, %esi
movl $0x270, %edi            # imm = 0x270
cmpl %esi, %ecx
jae 0xdcca
movslq %edx, %r8
movl (%rbx,%r8,4), %r9d
leal 0x132(%r8), %eax
cltd
idivl %edi
movslq %edx, %r10
movl (%rbx,%r10,4), %r11d
leal 0x26f(%r8), %eax
cltd
idivl %edi
movslq %edx, %rax
xorl (%rbx,%rax,4), %r9d
xorl %r11d, %r9d
movl %r9d, %eax
shrl $0x1b, %eax
xorl %r9d, %eax
imull $0x19660d, %eax, %r9d   # imm = 0x19660D
addl %r9d, %r11d
movl %r11d, (%rbx,%r10,4)
addl %r8d, %r9d
leal 0x13d(%r8), %eax
cltd
idivl %edi
movslq %edx, %rax
addl %r9d, (%rbx,%rax,4)
movl %r9d, (%rbx,%r8,4)
leal 0x1(%r8), %eax
cltd
idivl %edi
incl %ecx
jmp 0xdc60
movl $0x270, %ecx            # imm = 0x270
movl $0x270, %esi            # imm = 0x270
subl $0x1, %esi
jb 0xdd39
movslq %edx, %rdi
leal 0x132(%rdi), %eax
cltd
idivl %ecx
movslq %edx, %r8
movl (%rbx,%r8,4), %r9d
movl (%rbx,%rdi,4), %r10d
addl %r9d, %r10d
leal 0x26f(%rdi), %eax
cltd
idivl %ecx
movslq %edx, %rax
addl (%rbx,%rax,4), %r10d
movl %r10d, %eax
shrl $0x1b, %eax
xorl %r10d, %eax
imull $0x5d588b65, %eax, %r10d # imm = 0x5D588B65
xorl %r10d, %r9d
movl %r9d, (%rbx,%r8,4)
subl %edi, %r10d
leal 0x13d(%rdi), %eax
cltd
idivl %ecx
movslq %edx, %rax
xorl %r10d, (%rbx,%rax,4)
movl %r10d, (%rbx,%rdi,4)
leal 0x1(%rdi), %eax
cltd
idivl %ecx
jmp 0xdcd4
movl $0x270, 0x9c0(%rbx)     # imm = 0x270
movq %rbx, %rdi
popq %rbx
popq %r14
popq %r15
jmp 0xdb51