// File: /workspace/github_c_makefile_star2_O2/MersenneTwister-Lab[P]MTGP/mtgp64-fast.c
// Function: mtgp64_init_by_array
int mtgp64_init_by_array(mtgp64_fast_t *mtgp64,
			 const mtgp64_params_fast_t *para,
			 uint64_t *array, int length) {
    int i, j, count;
    uint64_t r;
    int lag;
    int mid;
    int size = para->mexp / 64 + 1;
    uint64_t hidden_seed;
    uint64_t tmp;
    mtgp64_status_fast_t *st;
    int rc;

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

    st = mtgp64->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 >> 32;
    tmp += tmp >> 16;
    tmp += tmp >> 8;
    memset(st->array, tmp & 0xff, sizeof(uint64_t) * size);
    mtgp64->params = *para;
    mtgp64->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 $0x40
popq %rcx
movl %r14d, %eax
cltd
idivl %ecx
movl %eax, %ebx
callq 0x122d
testl %eax, %eax
je 0x1373
pushq $-0x1
popq %rax
jmp 0x1631
movq %r13, %rsi
movl %ebp, 0x14(%rsp)
leal 0x1(%rbx), %r13d
movq 0x1b0(%r12), %rdi
cmpl $0x9b7f, %r14d          # imm = 0x9B7F
movq %r15, 0x30(%rsp)
movq %r12, 0x8(%rsp)
jle 0x139d
pushq $0xb
jmp 0x13a8
cmpl $0x10bf, %r14d          # imm = 0x10BF
jle 0x13ab
pushq $0x7
popq %rbp
jmp 0x13be
xorl %eax, %eax
cmpl $0x980, %r14d           # imm = 0x980
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)
movq 0x50(%rsi), %r12
shlq $0x10, %r12
xorq 0x30(%rsi), %r12
movq %r12, %rax
shrq $0x20, %rax
movq %r12, %rcx
shrq $0x30, %rcx
addq %rax, %rcx
movq %rcx, %rsi
shrq $0x8, %rsi
addl %ecx, %esi
leaq 0x10(%rdi), %r15
movslq %r13d, %rax
movq %rax, 0x20(%rsp)
leaq (,%rax,8), %rdx
movq %rdi, 0x18(%rsp)
movq %r15, %rdi
callq 0x1090
movl $0x1b0, %edx            # imm = 0x1B0
movq 0x8(%rsp), %rdi
movq 0x28(%rsp), %rsi
callq 0x10d0
movq 0x18(%rsp), %rsi
movq 0x8(%rsp), %rax
movq %rsi, 0x1b0(%rax)
movq 0x20(%rsp), %r9
movl %r9d, 0x4(%rsi)
movl %ebx, (%rsi)
movq %r12, 0x10(%rsi)
movslq %r14d, %rax
movq 0x10(%rsi,%rax,8), %rcx
movslq %ebx, %rdx
movq %rdx, 0x8(%rsp)
xorq 0x10(%rsi,%rdx,8), %r12
movq %rsi, %r8
xorq %rcx, %r12
movq %r12, %rdi
shrq $0x3b, %rdi
xorq %r12, %rdi
movabsq $0x1fa0259b019, %rdx    # imm = 0x1FA0259B019
imulq %rdx, %rdi
addq %rdi, %rcx
movq %rcx, 0x10(%rsi,%rax,8)
movl 0x14(%rsp), %esi
movslq %esi, %rcx
addq %rcx, %rdi
addl %ebp, %eax
cltd
idivl %r9d
movslq %edx, %rax
addq %rdi, 0x10(%r8,%rax,8)
movq %rdi, 0x10(%r8)
xorl %r8d, %r8d
testl %ecx, %ecx
movl $0x0, %edi
cmovgl %esi, %edi
pushq $0x1
popq %rdx
cmpq %r8, %rdi
je 0x1530
movslq %edx, %r9
movq (%r15,%r9,8), %r10
leal (%r9,%r14), %ecx
movl %ecx, %eax
cltd
idivl %r13d
movslq %edx, %r11
movq (%r15,%r11,8), %r12
leal (%r9,%rbx), %eax
cltd
idivl %r13d
movslq %edx, %rax
xorq (%r15,%rax,8), %r10
xorq %r12, %r10
movq %r10, %rax
shrq $0x3b, %rax
xorq %r10, %rax
movabsq $0x1fa0259b019, %rdx    # imm = 0x1FA0259B019
imulq %rdx, %rax
addq %rax, %r12
movq %r12, (%r15,%r11,8)
movq 0x30(%rsp), %rdx
movq (%rdx,%r8,8), %r10
addq %r9, %r10
addq %rax, %r10
addl %ebp, %ecx
movl %ecx, %eax
cltd
idivl %r13d
movslq %edx, %rax
addq %r10, (%r15,%rax,8)
movq %r10, (%r15,%r9,8)
leal 0x1(%r9), %eax
cltd
idivl %r13d
incq %r8
jmp 0x14b3
cmpl %esi, %ebx
cmovgl %ebx, %esi
cmpl %esi, %edi
jge 0x15a4
movslq %edx, %r8
movq (%r15,%r8,8), %r9
leal (%r8,%r14), %ecx
movl %ecx, %eax
cltd
idivl %r13d
movslq %edx, %r10
movq (%r15,%r10,8), %r11
leal (%r8,%rbx), %eax
cltd
idivl %r13d
movslq %edx, %rax
xorq (%r15,%rax,8), %r9
xorq %r11, %r9
movq %r9, %r12
shrq $0x3b, %r12
xorq %r9, %r12
movabsq $0x1fa0259b019, %rax    # imm = 0x1FA0259B019
imulq %rax, %r12
addq %r12, %r11
movq %r11, (%r15,%r10,8)
addq %r8, %r12
addl %ebp, %ecx
movl %ecx, %eax
cltd
idivl %r13d
movslq %edx, %rax
addq %r12, (%r15,%rax,8)
movq %r12, (%r15,%r8,8)
leal 0x1(%r8), %eax
cltd
idivl %r13d
incl %edi
jmp 0x1535
xorl %edi, %edi
testl %r13d, %r13d
cmovgl %r13d, %edi
movabsq $0xd1341c13e2fab1, %r8  # imm = 0xD1341C13E2FAB1
subl $0x1, %edi
jb 0x161b
movslq %edx, %r9
leal (%r9,%r14), %ecx
movl %ecx, %eax
cltd
idivl %r13d
movslq %edx, %r10
movq (%r15,%r10,8), %r11
movq (%r15,%r9,8), %rsi
addq %r11, %rsi
leal (%r9,%rbx), %eax
cltd
idivl %r13d
movslq %edx, %rax
addq (%r15,%rax,8), %rsi
movq %rsi, %r12
shrq $0x3b, %r12
xorq %rsi, %r12
imulq %r8, %r12
xorq %r12, %r11
movq %r11, (%r15,%r10,8)
subq %r9, %r12
addl %ebp, %ecx
movl %ecx, %eax
cltd
idivl %r13d
movslq %edx, %rax
xorq %r12, (%r15,%rax,8)
movq %r12, (%r15,%r9,8)
leal 0x1(%r9), %eax
cltd
idivl %r13d
jmp 0x15b7
xorl %eax, %eax
movq 0x8(%rsp), %rcx
cmpq $0x0, (%r15,%rcx,8)
jne 0x1631
movq $0x4d544750, (%r15,%rcx,8) # imm = 0x4D544750
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq