// File: /workspace/github_c_makefile_star2_O2/MersenneTwister-Lab[P]MTGP/mtgp32-fast.c
// Function: mtgp32_init_by_array
int mtgp32_init_by_array(mtgp32_fast_t *mtgp32,
			 const mtgp32_params_fast_t *para,
			 uint32_t *array, int length) {
    int i, j, count;
    uint32_t r;
    int lag;
    int mid;
    int size = para->mexp / 32 + 1;
    uint32_t hidden_seed;
    uint32_t tmp;
    mtgp32_status_fast_t *st;
    int rc;

    rc = alloc_state(mtgp32, para);
    if (rc) {
	return rc;
    }

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

    hidden_seed = para->tbl[4] ^ (para->tbl[8] << 16);
    tmp = hidden_seed;
    tmp += tmp >> 16;
    tmp += tmp >> 8;
    memset(st->array, tmp & 0xff, sizeof(uint32_t) * size);
    mtgp32->params = *para;
    mtgp32->status = st;
    st->size = size;
    st->idx = size - 1;
    st->array[0] = hidden_seed;

    if (length + 1 > size) {
	count = length + 1;
    } else {
	count = size;
    }
    r = ini_func1(st->array[0] ^ st->array[mid] ^ st->array[size - 1]);
    st->array[mid] += r;
    r += length;
    st->array[(mid + lag) % size] += r;
    st->array[0] = r;
    i = 1;
    count--;
    for (i = 1, j = 0; (j < count) && (j < length); j++) {
	r = ini_func1(st->array[i] ^ st->array[(i + mid) % size]
		      ^ st->array[(i + size - 1) % size]);
	st->array[(i + mid) % size] += r;
	r += array[j] + i;
	st->array[(i + mid + lag) % size] += r;
	st->array[i] = r;
	i = (i + 1) % size;
    }
    for (; j < count; j++) {
	r = ini_func1(st->array[i] ^ st->array[(i + mid) % size]
		      ^ st->array[(i + size - 1) % size]);
	st->array[(i + mid) % size] += r;
	r += i;
	st->array[(i + mid + lag) % size] += r;
	st->array[i] = r;
	i = (i + 1) % size;
    }
    for (j = 0; j < size; j++) {
	r = ini_func2(st->array[i] + st->array[(i + mid) % size]
		      + st->array[(i + size - 1) % size]);
	st->array[(i + mid) % size] ^= r;
	r -= i;
	st->array[(i + mid + lag) % size] ^= r;
	st->array[i] = r;
	i = (i + 1) % size;
    }
    if (st->array[size - 1] == 0) {
	st->array[size - 1] = non_zero;
    }
    return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x38, %rsp
movl %ecx, %ebp
movq %rdx, %r15
movq %rsi, %r13
movq %rdi, %r12
movl (%rsi), %r14d
pushq $0x20
popq %rcx
movl %r14d, %eax
cltd
idivl %ecx
movl %eax, %ebx
callq 0x122b
testl %eax, %eax
je 0x1355
pushq $-0x1
popq %rax
jmp 0x15e3
movq %r13, %rsi
leal 0x1(%rbx), %r13d
movq 0xf0(%r12), %rdi
cmpl $0x4dbf, %r14d          # imm = 0x4DBF
movl %ebp, 0xc(%rsp)
movq %r15, 0x30(%rsp)
movq %r12, 0x10(%rsp)
jle 0x137f
pushq $0xb
jmp 0x138a
cmpl $0x85f, %r14d           # imm = 0x85F
jle 0x138d
pushq $0x7
popq %rbp
jmp 0x13a0
xorl %eax, %eax
cmpl $0x4c0, %r14d           # imm = 0x4C0
setge %al
leal 0x3(,%rax,2), %ebp
movl %r13d, %eax
subl %ebp, %eax
pushq $0x2
popq %rcx
cltd
idivl %ecx
movl %eax, %r14d
movq %rsi, 0x28(%rsp)
movl 0x30(%rsi), %r12d
shll $0x10, %r12d
xorl 0x20(%rsi), %r12d
movl %r12d, %eax
shrl $0x10, %eax
addl %r12d, %eax
movl %eax, %esi
shrl $0x8, %esi
addl %eax, %esi
leaq 0x10(%rdi), %r15
movslq %r13d, %rax
movq %rax, 0x20(%rsp)
leaq (,%rax,4), %rdx
movq %rdi, 0x18(%rsp)
movq %r15, %rdi
callq 0x1090
movl $0xec, %edx
movq 0x10(%rsp), %rdi
movq 0x28(%rsp), %rsi
callq 0x10d0
movq 0x18(%rsp), %rdx
movq 0x10(%rsp), %rax
movq %rdx, 0xf0(%rax)
movq 0x20(%rsp), %r9
movl %r9d, 0x4(%rdx)
movl %ebx, (%rdx)
movl %r12d, 0x10(%rdx)
movslq %r14d, %rax
movl 0x10(%rdx,%rax,4), %ecx
movslq %ebx, %rsi
xorl 0x10(%rdx,%rsi,4), %r12d
movq %rdx, %r8
xorl %ecx, %r12d
movl %r12d, %edx
shrl $0x1b, %edx
xorl %r12d, %edx
imull $0x19660d, %edx, %edi   # imm = 0x19660D
addl %edi, %ecx
movl %ecx, 0x10(%r8,%rax,4)
movl 0xc(%rsp), %r12d
addl %r12d, %edi
addl %ebp, %eax
cltd
idivl %r9d
movslq %edx, %rax
addl %edi, 0x10(%r8,%rax,4)
movl %edi, 0x10(%r8)
xorl %r8d, %r8d
testl %r12d, %r12d
movl $0x0, %edi
cmovgl %r12d, %edi
pushq $0x1
popq %rdx
cmpq %r8, %rdi
je 0x14f4
movslq %edx, %r9
movl (%r15,%r9,4), %r10d
leal (%r9,%r14), %ecx
movl %ecx, %eax
cltd
idivl %r13d
movslq %edx, %r11
movl (%r15,%r11,4), %r12d
leal (%r9,%rbx), %eax
cltd
idivl %r13d
movslq %edx, %rax
xorl (%r15,%rax,4), %r10d
xorl %r12d, %r10d
movl %r10d, %eax
shrl $0x1b, %eax
xorl %r10d, %eax
imull $0x19660d, %eax, %eax   # imm = 0x19660D
addl %eax, %r12d
movl %r12d, (%r15,%r11,4)
movl 0xc(%rsp), %r12d
movq 0x30(%rsp), %rdx
movl (%rdx,%r8,4), %r10d
addl %r9d, %r10d
addl %eax, %r10d
addl %ebp, %ecx
movl %ecx, %eax
cltd
idivl %r13d
movslq %edx, %rax
addl %r10d, (%r15,%rax,4)
movl %r10d, (%r15,%r9,4)
leal 0x1(%r9), %eax
cltd
idivl %r13d
incq %r8
jmp 0x147b
cmpl %r12d, %ebx
cmovgl %ebx, %r12d
cmpl %r12d, %edi
jge 0x1563
movslq %edx, %r8
movl (%r15,%r8,4), %r9d
leal (%r8,%r14), %ecx
movl %ecx, %eax
cltd
idivl %r13d
movslq %edx, %r10
movl (%r15,%r10,4), %r11d
leal (%r8,%rbx), %eax
cltd
idivl %r13d
movslq %edx, %rax
xorl (%r15,%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, (%r15,%r10,4)
addl %r8d, %r9d
addl %ebp, %ecx
movl %ecx, %eax
cltd
idivl %r13d
movslq %edx, %rax
addl %r9d, (%r15,%rax,4)
movl %r9d, (%r15,%r8,4)
leal 0x1(%r8), %eax
cltd
idivl %r13d
incl %edi
jmp 0x14fb
xorl %edi, %edi
testl %r13d, %r13d
cmovgl %r13d, %edi
subl $0x1, %edi
jb 0x15d2
movslq %edx, %r8
leal (%r8,%r14), %ecx
movl %ecx, %eax
cltd
idivl %r13d
movslq %edx, %r9
movl (%r15,%r9,4), %r10d
movl (%r15,%r8,4), %r11d
addl %r10d, %r11d
leal (%r8,%rbx), %eax
cltd
idivl %r13d
movslq %edx, %rax
addl (%r15,%rax,4), %r11d
movl %r11d, %eax
shrl $0x1b, %eax
xorl %r11d, %eax
imull $0x5d588b65, %eax, %r11d # imm = 0x5D588B65
xorl %r11d, %r10d
movl %r10d, (%r15,%r9,4)
subl %r8d, %r11d
addl %ebp, %ecx
movl %ecx, %eax
cltd
idivl %r13d
movslq %edx, %rax
xorl %r11d, (%r15,%rax,4)
movl %r11d, (%r15,%r8,4)
leal 0x1(%r8), %eax
cltd
idivl %r13d
jmp 0x156c
xorl %eax, %eax
cmpl $0x0, (%r15,%rsi,4)
jne 0x15e3
movl $0x4d544750, (%r15,%rsi,4) # imm = 0x4D544750
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq