// File: /workspace/github_c_makefile_star2_O2/MersenneTwister-Lab[P]MTGP/mtgp32-ref.c
// Function: mtgp32_init_by_array
int mtgp32_init_by_array(mtgp32_ref_t *mtgp32,
			 const mtgp32_params_ref_t *para,
			 const 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_ref_t *st;

    st = (mtgp32_status_ref_t *)malloc(sizeof(mtgp32_status_ref_t)
				     + sizeof(uint32_t) * size);
    if (st == NULL) {
	return -1;
    }
    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[2] ^ (para->tbl[3] << 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, 0xc(%rsp)
movq %rdx, 0x30(%rsp)
movq %rsi, %rbp
movq %rdi, %r13
movl (%rsi), %r15d
pushq $0x20
popq %rcx
movl %r15d, %eax
cltd
idivl %ecx
movl %eax, %ebx
movslq %eax, %r12
leaq 0xc(,%r12,4), %rdi
callq 0x10d0
testq %rax, %rax
je 0x1317
movq %rax, %r14
movq %r13, 0x20(%rsp)
leal 0x1(%r12), %r13d
leaq 0x4(,%r12,4), %rcx
movq %rax, 0x28(%rsp)
cmpl $0x4dbf, %r15d          # imm = 0x4DBF
movq %r12, 0x10(%rsp)
movq %rbp, %rdi
jle 0x131f
pushq $0xb
jmp 0x132a
pushq $-0x1
popq %rax
jmp 0x1559
cmpl $0x85f, %r15d           # imm = 0x85F
jle 0x132d
pushq $0x7
popq %rbp
jmp 0x1340
xorl %eax, %eax
cmpl $0x4c0, %r15d           # imm = 0x4C0
setge %al
leal 0x3(,%rax,2), %ebp
movl %r13d, %eax
subl %ebp, %eax
pushq $0x2
popq %rsi
cltd
idivl %esi
movl %eax, %r15d
movq %rdi, 0x18(%rsp)
movl 0x1c(%rdi), %r12d
shll $0x10, %r12d
xorl 0x18(%rdi), %r12d
movl %r12d, %eax
shrl $0x10, %eax
addl %r12d, %eax
movl %eax, %esi
shrl $0x8, %esi
addl %eax, %esi
addq $0x8, %r14
movq %r14, %rdi
movq %rcx, %rdx
callq 0x1090
pushq $0x13
popq %rcx
movq 0x20(%rsp), %rax
movq %rax, %rdi
movq 0x18(%rsp), %rsi
rep  movsl (%rsi), %es:(%rdi)
movq 0x28(%rsp), %rdi
movq %rdi, 0x50(%rax)
movl %r13d, (%rdi)
movq 0x10(%rsp), %rdx
movl %edx, 0x4(%rdi)
movl %r12d, 0x8(%rdi)
movslq %r15d, %rax
movl 0x8(%rdi,%rax,4), %ecx
xorl 0x8(%rdi,%rdx,4), %r12d
xorl %ecx, %r12d
movl %r12d, %edx
shrl $0x1b, %edx
xorl %r12d, %edx
imull $0x19660d, %edx, %esi   # imm = 0x19660D
addl %esi, %ecx
movl %ecx, 0x8(%rdi,%rax,4)
movl 0xc(%rsp), %r12d
addl %r12d, %esi
addl %ebp, %eax
cltd
idivl %r13d
movslq %edx, %rax
addl %esi, 0x8(%rdi,%rax,4)
movl %esi, 0x8(%rdi)
xorl %edi, %edi
testl %r12d, %r12d
movl $0x0, %esi
cmovgl %r12d, %esi
pushq $0x1
popq %rdx
cmpq %rdi, %rsi
je 0x1469
movslq %edx, %r8
movl (%r14,%r8,4), %r9d
leal (%r8,%r15), %ecx
movl %ecx, %eax
cltd
idivl %r13d
movslq %edx, %r10
movl (%r14,%r10,4), %r11d
leal (%r8,%rbx), %eax
cltd
idivl %r13d
movslq %edx, %rax
xorl (%r14,%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, (%r14,%r10,4)
movq 0x30(%rsp), %rdx
movl (%rdx,%rdi,4), %r9d
addl %r8d, %r9d
addl %eax, %r9d
addl %ebp, %ecx
movl %ecx, %eax
cltd
idivl %r13d
movslq %edx, %rax
addl %r9d, (%r14,%rax,4)
movl %r9d, (%r14,%r8,4)
leal 0x1(%r8), %eax
cltd
idivl %r13d
incq %rdi
jmp 0x13f5
cmpl %r12d, %ebx
cmovgl %ebx, %r12d
movq 0x10(%rsp), %r11
cmpl %r12d, %esi
jge 0x14db
movslq %edx, %rdi
movl (%r14,%rdi,4), %r8d
leal (%rdi,%r15), %ecx
movl %ecx, %eax
cltd
idivl %r13d
movslq %edx, %r9
movl (%r14,%r9,4), %r10d
leal (%rdi,%rbx), %eax
cltd
idivl %r13d
movslq %edx, %rax
xorl (%r14,%rax,4), %r8d
xorl %r10d, %r8d
movl %r8d, %eax
shrl $0x1b, %eax
xorl %r8d, %eax
imull $0x19660d, %eax, %r8d   # imm = 0x19660D
addl %r8d, %r10d
movl %r10d, (%r14,%r9,4)
addl %edi, %r8d
addl %ebp, %ecx
movl %ecx, %eax
cltd
idivl %r13d
movslq %edx, %rax
addl %r8d, (%r14,%rax,4)
movl %r8d, (%r14,%rdi,4)
leal 0x1(%rdi), %eax
cltd
idivl %r13d
incl %esi
jmp 0x1475
xorl %esi, %esi
testl %r13d, %r13d
cmovgl %r13d, %esi
subl $0x1, %esi
jb 0x1548
movslq %edx, %rdi
leal (%rdi,%r15), %ecx
movl %ecx, %eax
cltd
idivl %r13d
movslq %edx, %r8
movl (%r14,%r8,4), %r9d
movl (%r14,%rdi,4), %r10d
addl %r9d, %r10d
leal (%rdi,%rbx), %eax
cltd
idivl %r13d
movslq %edx, %rax
addl (%r14,%rax,4), %r10d
movl %r10d, %eax
shrl $0x1b, %eax
xorl %r10d, %eax
imull $0x5d588b65, %eax, %r10d # imm = 0x5D588B65
xorl %r10d, %r9d
movl %r9d, (%r14,%r8,4)
subl %edi, %r10d
addl %ebp, %ecx
movl %ecx, %eax
cltd
idivl %r13d
movslq %edx, %rax
xorl %r10d, (%r14,%rax,4)
movl %r10d, (%r14,%rdi,4)
leal 0x1(%rdi), %eax
cltd
idivl %r13d
jmp 0x14e4
xorl %eax, %eax
cmpl $0x0, (%r14,%r11,4)
jne 0x1559
movl $0x4d544750, (%r14,%r11,4) # imm = 0x4D544750
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq