// File: /workspace/github_c_makefile_star2_O3/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, %r14
movq %rsi, %r12
movq %rdi, %r15
movl (%rsi), %ebx
leal 0x1f(%rbx), %r13d
testl %ebx, %ebx
cmovnsl %ebx, %r13d
callq 0x122d
movl %eax, %ecx
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
testl %ecx, %ecx
jne 0x162b
movq %r14, 0x20(%rsp)
movl %ebp, 0x4(%rsp)
sarl $0x5, %r13d
leal 0x1(%r13), %ebp
movq %r15, 0x8(%rsp)
movq 0xf0(%r15), %r15
movl $0xb, %edx
cmpl $0x4dbf, %ebx           # imm = 0x4DBF
jg 0x13c6
movl $0x7, %edx
cmpl $0x85f, %ebx            # imm = 0x85F
jg 0x13c6
xorl %eax, %eax
cmpl $0x4c0, %ebx            # imm = 0x4C0
setge %al
leal 0x3(,%rax,2), %edx
movl %edx, 0x1c(%rsp)
movq %rbx, 0x30(%rsp)
movl %ebp, %eax
subl %edx, %eax
movl %eax, %r14d
shrl $0x1f, %r14d
addl %eax, %r14d
sarl %r14d
movq %r12, %rax
movq %r12, 0x10(%rsp)
movl 0x30(%r12), %r12d
shll $0x10, %r12d
xorl 0x20(%rax), %r12d
movl %r12d, %eax
shrl $0x10, %eax
addl %r12d, %eax
movl %eax, %esi
shrl $0x8, %esi
addl %eax, %esi
leaq 0x10(%r15), %rbx
movslq %ebp, %rax
movq %rax, 0x28(%rsp)
leaq (,%rax,4), %rdx
movq %rbx, %rdi
callq 0x1090
movl $0xec, %edx
movq 0x8(%rsp), %rdi
movq 0x10(%rsp), %rsi
callq 0x10d0
movq 0x8(%rsp), %rax
movq %r15, 0xf0(%rax)
movq 0x28(%rsp), %r9
movl %r9d, 0x4(%r15)
movl %r13d, (%r15)
movl %r12d, 0x10(%r15)
movl 0x4(%rsp), %esi
cmpl %esi, %r13d
movl %esi, %edi
cmovgl %r13d, %edi
movslq %r14d, %rax
movl 0x10(%r15,%rax,4), %ecx
movslq %r13d, %r11
xorl 0x10(%r15,%r11,4), %r12d
xorl %ecx, %r12d
movl %r12d, %edx
shrl $0x1b, %edx
xorl %r12d, %edx
movl 0x1c(%rsp), %r12d
imull $0x19660d, %edx, %r8d   # imm = 0x19660D
addl %r8d, %ecx
movl %ecx, 0x10(%r15,%rax,4)
addl %esi, %r8d
addl %r12d, %eax
cltd
idivl %r9d
movslq %edx, %rax
addl %r8d, 0x10(%r15,%rax,4)
movl %r8d, 0x10(%r15)
testl %esi, %esi
jle 0x154b
movq %r11, 0x10(%rsp)
movl %esi, %eax
movq %rax, 0x8(%rsp)
movl $0x1, %edx
xorl %r9d, %r9d
movq %r14, %r8
movq %r13, %r14
movl %r12d, %r13d
movq 0x20(%rsp), %r15
movslq %edx, %r10
movl (%rbx,%r10,4), %r11d
leal (%r10,%r8), %ecx
movl %ecx, %eax
cltd
idivl %ebp
movslq %edx, %r12
movl (%rbx,%r12,4), %esi
leal (%r10,%r14), %eax
cltd
idivl %ebp
movslq %edx, %rax
xorl (%rbx,%rax,4), %r11d
xorl %esi, %r11d
movl %r11d, %eax
shrl $0x1b, %eax
xorl %r11d, %eax
imull $0x19660d, %eax, %eax   # imm = 0x19660D
addl %eax, %esi
movl %esi, (%rbx,%r12,4)
movl (%r15,%r9,4), %esi
addl %r10d, %esi
addl %eax, %esi
addl %r13d, %ecx
movl %ecx, %eax
cltd
idivl %ebp
movslq %edx, %rax
addl %esi, (%rbx,%rax,4)
movl %esi, (%rbx,%r10,4)
leal 0x1(%r10), %eax
cltd
idivl %ebp
incq %r9
cmpq %r9, 0x8(%rsp)
jne 0x14ce
movq 0x10(%rsp), %r11
movl 0x4(%rsp), %eax
movl %r13d, %r12d
movq %r14, %r13
movq %r8, %r14
jmp 0x1552
movl $0x1, %edx
xorl %eax, %eax
subl %eax, %edi
jle 0x15b1
movslq %edx, %r8
movl (%rbx,%r8,4), %esi
leal (%r8,%r14), %ecx
movl %ecx, %eax
cltd
idivl %ebp
movslq %edx, %r9
movl (%rbx,%r9,4), %r10d
leal (%r8,%r13), %eax
cltd
idivl %ebp
movslq %edx, %rax
xorl (%rbx,%rax,4), %esi
xorl %r10d, %esi
movl %esi, %eax
shrl $0x1b, %eax
xorl %esi, %eax
imull $0x19660d, %eax, %esi   # imm = 0x19660D
addl %esi, %r10d
movl %r10d, (%rbx,%r9,4)
addl %r8d, %esi
addl %r12d, %ecx
movl %ecx, %eax
cltd
idivl %ebp
movslq %edx, %rax
addl %esi, (%rbx,%rax,4)
movl %esi, (%rbx,%r8,4)
leal 0x1(%r8), %eax
cltd
idivl %ebp
decl %edi
jne 0x1556
cmpl $-0x1f, 0x30(%rsp)
jl 0x161a
movl %ebp, %edi
movslq %edx, %r8
leal (%r8,%r14), %ecx
movl %ecx, %eax
cltd
idivl %ebp
movslq %edx, %rsi
movl (%rbx,%rsi,4), %r9d
movl (%rbx,%r8,4), %r10d
addl %r9d, %r10d
leal (%r8,%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,%rsi,4)
subl %r8d, %r10d
addl %r12d, %ecx
movl %ecx, %eax
cltd
idivl %ebp
movslq %edx, %rax
xorl %r10d, (%rbx,%rax,4)
movl %r10d, (%rbx,%r8,4)
leal 0x1(%r8), %eax
cltd
idivl %ebp
decl %edi
jne 0x15ba
xorl %eax, %eax
cmpl $0x0, (%rbx,%r11,4)
jne 0x162b
movl $0x4d544750, (%rbx,%r11,4) # imm = 0x4D544750
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq