// File: /workspace/github_c_makefile_star2_O3/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, 0x4(%rsp)
movq %rdx, %r12
movq %rsi, %rbp
movl (%rsi), %r15d
leal 0x1f(%r15), %r13d
testl %r15d, %r15d
cmovnsl %r15d, %r13d
movq %rdi, 0x8(%rsp)
sarl $0x5, %r13d
movslq %r13d, %r14
leaq 0xc(,%r14,4), %rdi
callq 0x10d0
testq %rax, %rax
je 0x14c1
movq %rax, %rbx
movq %rbp, %rcx
movq %r12, 0x18(%rsp)
leal 0x1(%r14), %ebp
movq %r14, 0x10(%rsp)
leaq 0x4(,%r14,4), %rdx
movq %rax, 0x28(%rsp)
movl $0xb, %r12d
cmpl $0x4dbf, %r15d          # imm = 0x4DBF
jg 0x1365
movl $0x7, %r12d
cmpl $0x85f, %r15d           # imm = 0x85F
jg 0x1365
xorl %eax, %eax
cmpl $0x4c0, %r15d           # imm = 0x4C0
setge %al
leal 0x3(,%rax,2), %r12d
movq %r15, 0x30(%rsp)
movl %ebp, %eax
subl %r12d, %eax
movl %eax, %r15d
shrl $0x1f, %r15d
addl %eax, %r15d
movq %rcx, 0x20(%rsp)
movl 0x1c(%rcx), %r14d
shll $0x10, %r14d
xorl 0x18(%rcx), %r14d
sarl %r15d
movl %r14d, %eax
shrl $0x10, %eax
addl %r14d, %eax
movl %eax, %esi
shrl $0x8, %esi
addl %eax, %esi
addq $0x8, %rbx
movq %rbx, %rdi
callq 0x1090
movl $0x13, %ecx
movq 0x8(%rsp), %rax
movq %rax, %rdi
movq 0x20(%rsp), %rsi
rep  movsl (%rsi), %es:(%rdi)
movq 0x28(%rsp), %r9
movq %r9, 0x50(%rax)
movl %ebp, (%r9)
movq 0x10(%rsp), %rdx
movl %edx, 0x4(%r9)
movl %r14d, 0x8(%r9)
movl 0x4(%rsp), %r8d
cmpl %r8d, %edx
movl %r8d, %esi
cmovgl %edx, %esi
movslq %r15d, %rax
movl 0x8(%r9,%rax,4), %ecx
xorl 0x8(%r9,%rdx,4), %r14d
xorl %ecx, %r14d
movl %r14d, %edx
shrl $0x1b, %edx
xorl %r14d, %edx
imull $0x19660d, %edx, %edi   # imm = 0x19660D
addl %edi, %ecx
movl %ecx, 0x8(%r9,%rax,4)
addl %r8d, %edi
addl %r12d, %eax
cltd
idivl %ebp
movslq %edx, %rax
addl %edi, 0x8(%r9,%rax,4)
movl %edi, 0x8(%r9)
testl %r8d, %r8d
jle 0x14cb
movl %r8d, %eax
movq %rax, 0x8(%rsp)
movl $0x1, %edx
xorl %r8d, %r8d
movq %r15, %rdi
movq %r13, %r15
movl %r12d, %r13d
movq 0x18(%rsp), %r12
movslq %edx, %r9
movl (%rbx,%r9,4), %r10d
leal (%r9,%rdi), %ecx
movl %ecx, %eax
cltd
idivl %ebp
movslq %edx, %r11
movl (%rbx,%r11,4), %r14d
leal (%r9,%r15), %eax
cltd
idivl %ebp
movslq %edx, %rax
xorl (%rbx,%rax,4), %r10d
xorl %r14d, %r10d
movl %r10d, %eax
shrl $0x1b, %eax
xorl %r10d, %eax
imull $0x19660d, %eax, %eax   # imm = 0x19660D
addl %eax, %r14d
movl %r14d, (%rbx,%r11,4)
movl (%r12,%r8,4), %r10d
addl %r9d, %r10d
addl %eax, %r10d
addl %r13d, %ecx
movl %ecx, %eax
cltd
idivl %ebp
movslq %edx, %rax
addl %r10d, (%rbx,%rax,4)
movl %r10d, (%rbx,%r9,4)
leal 0x1(%r9), %eax
cltd
idivl %ebp
incq %r8
cmpq %r8, 0x8(%rsp)
jne 0x1446
movl 0x4(%rsp), %eax
movl %r13d, %r12d
movq %r15, %r13
movq %rdi, %r15
jmp 0x14d2
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
jmp 0x15b3
movl $0x1, %edx
xorl %eax, %eax
subl %eax, %esi
movq 0x10(%rsp), %r11
jle 0x153a
movslq %edx, %rdi
movl (%rbx,%rdi,4), %r8d
leal (%rdi,%r15), %ecx
movl %ecx, %eax
cltd
idivl %ebp
movslq %edx, %r9
movl (%rbx,%r9,4), %r10d
leal (%rdi,%r13), %eax
cltd
idivl %ebp
movslq %edx, %rax
xorl (%rbx,%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, (%rbx,%r9,4)
addl %edi, %r8d
addl %r12d, %ecx
movl %ecx, %eax
cltd
idivl %ebp
movslq %edx, %rax
addl %r8d, (%rbx,%rax,4)
movl %r8d, (%rbx,%rdi,4)
leal 0x1(%rdi), %eax
cltd
idivl %ebp
decl %esi
jne 0x14db
cmpl $-0x1f, 0x30(%rsp)
jl 0x15a2
movl %ebp, %esi
movslq %edx, %rdi
leal (%rdi,%r15), %ecx
movl %ecx, %eax
cltd
idivl %ebp
movslq %edx, %r8
movl (%rbx,%r8,4), %r9d
movl (%rbx,%rdi,4), %r10d
addl %r9d, %r10d
leal (%rdi,%r13), %eax
cltd
idivl %ebp
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
addl %r12d, %ecx
movl %ecx, %eax
cltd
idivl %ebp
movslq %edx, %rax
xorl %r10d, (%rbx,%rax,4)
movl %r10d, (%rbx,%rdi,4)
leal 0x1(%rdi), %eax
cltd
idivl %ebp
decl %esi
jne 0x1543
xorl %eax, %eax
cmpl $0x0, (%rbx,%r11,4)
jne 0x15b3
movl $0x4d544750, (%rbx,%r11,4) # imm = 0x4D544750
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq