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

    st = (mtgp64_status_ref_t *)malloc(sizeof(mtgp64_status_ref_t)
				     + sizeof(uint64_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 >> 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, 0xc(%rsp)
movq %rdx, 0x30(%rsp)
movq %rsi, %rbp
movq %rdi, %r13
movl (%rsi), %r15d
pushq $0x40
popq %rcx
movl %r15d, %eax
cltd
idivl %ecx
movl %eax, %ebx
movslq %eax, %r12
leaq 0x10(,%r12,8), %rdi
callq 0x10d0
testq %rax, %rax
je 0x1335
movq %rax, %r14
movq %r13, 0x20(%rsp)
leal 0x1(%r12), %r13d
leaq 0x8(,%r12,8), %rcx
movq %rax, 0x28(%rsp)
cmpl $0x9b7f, %r15d          # imm = 0x9B7F
movq %r12, 0x10(%rsp)
movq %rbp, %rdi
jle 0x133d
pushq $0xb
jmp 0x1348
pushq $-0x1
popq %rax
jmp 0x15ad
cmpl $0x10bf, %r15d          # imm = 0x10BF
jle 0x134b
pushq $0x7
popq %rbp
jmp 0x135e
xorl %eax, %eax
cmpl $0x980, %r15d           # imm = 0x980
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)
movq 0x28(%rdi), %r12
shlq $0x10, %r12
xorq 0x20(%rdi), %r12
movq %r12, %rax
shrq $0x20, %rax
movq %r12, %rdx
shrq $0x30, %rdx
addq %rax, %rdx
movq %rdx, %rsi
shrq $0x8, %rsi
addl %edx, %esi
addq $0x8, %r14
movq %r14, %rdi
movq %rcx, %rdx
callq 0x1090
pushq $0xe
popq %rcx
movq 0x20(%rsp), %rax
movq %rax, %rdi
movq 0x18(%rsp), %rsi
rep  movsq (%rsi), %es:(%rdi)
movq 0x28(%rsp), %rdi
movq %rdi, 0x70(%rax)
movl %r13d, (%rdi)
movq 0x10(%rsp), %rdx
movl %edx, 0x4(%rdi)
movq %r12, 0x8(%rdi)
movslq %r15d, %rax
movq 0x8(%rdi,%rax,8), %rcx
xorq 0x8(%rdi,%rdx,8), %r12
xorq %rcx, %r12
movq %r12, %rsi
shrq $0x3b, %rsi
xorq %r12, %rsi
movabsq $0x1fa0259b019, %rdx    # imm = 0x1FA0259B019
imulq %rdx, %rsi
addq %rsi, %rcx
movq %rcx, 0x8(%rdi,%rax,8)
movl 0xc(%rsp), %r12d
movslq %r12d, %rcx
addq %rcx, %rsi
addl %ebp, %eax
cltd
idivl %r13d
movslq %edx, %rax
addq %rsi, 0x8(%rdi,%rax,8)
movq %rsi, 0x8(%rdi)
xorl %edi, %edi
testl %ecx, %ecx
movl $0x0, %esi
cmovgl %r12d, %esi
pushq $0x1
popq %rdx
cmpq %rdi, %rsi
je 0x14ab
movslq %edx, %r8
movq (%r14,%r8,8), %r9
leal (%r8,%r15), %ecx
movl %ecx, %eax
cltd
idivl %r13d
movslq %edx, %r10
movq (%r14,%r10,8), %r11
leal (%r8,%rbx), %eax
cltd
idivl %r13d
movslq %edx, %rax
xorq (%r14,%rax,8), %r9
xorq %r11, %r9
movq %r9, %rax
shrq $0x3b, %rax
xorq %r9, %rax
movabsq $0x1fa0259b019, %rdx    # imm = 0x1FA0259B019
imulq %rdx, %rax
addq %rax, %r11
movq %r11, (%r14,%r10,8)
movq 0x30(%rsp), %rdx
movq (%rdx,%rdi,8), %r9
addq %r8, %r9
addq %rax, %r9
addl %ebp, %ecx
movl %ecx, %eax
cltd
idivl %r13d
movslq %edx, %rax
addq %r9, (%r14,%rax,8)
movq %r9, (%r14,%r8,8)
leal 0x1(%r8), %eax
cltd
idivl %r13d
incq %rdi
jmp 0x142e
cmpl %r12d, %ebx
cmovgl %ebx, %r12d
cmpl %r12d, %esi
jge 0x1520
movslq %edx, %rdi
movq (%r14,%rdi,8), %r8
leal (%rdi,%r15), %ecx
movl %ecx, %eax
cltd
idivl %r13d
movslq %edx, %r9
movq (%r14,%r9,8), %r10
leal (%rdi,%rbx), %eax
cltd
idivl %r13d
movslq %edx, %rax
xorq (%r14,%rax,8), %r8
xorq %r10, %r8
movq %r8, %r11
shrq $0x3b, %r11
xorq %r8, %r11
movabsq $0x1fa0259b019, %rax    # imm = 0x1FA0259B019
imulq %rax, %r11
addq %r11, %r10
movq %r10, (%r14,%r9,8)
addq %rdi, %r11
addl %ebp, %ecx
movl %ecx, %eax
cltd
idivl %r13d
movslq %edx, %rax
addq %r11, (%r14,%rax,8)
movq %r11, (%r14,%rdi,8)
leal 0x1(%rdi), %eax
cltd
idivl %r13d
incl %esi
jmp 0x14b2
xorl %esi, %esi
testl %r13d, %r13d
cmovgl %r13d, %esi
movabsq $0xd1341c13e2fab1, %rdi # imm = 0xD1341C13E2FAB1
subl $0x1, %esi
jb 0x1597
movslq %edx, %r8
leal (%r8,%r15), %ecx
movl %ecx, %eax
cltd
idivl %r13d
movslq %edx, %r9
movq (%r14,%r9,8), %r10
movq (%r14,%r8,8), %r11
addq %r10, %r11
leal (%r8,%rbx), %eax
cltd
idivl %r13d
movslq %edx, %rax
addq (%r14,%rax,8), %r11
movq %r11, %r12
shrq $0x3b, %r12
xorq %r11, %r12
imulq %rdi, %r12
xorq %r12, %r10
movq %r10, (%r14,%r9,8)
subq %r8, %r12
addl %ebp, %ecx
movl %ecx, %eax
cltd
idivl %r13d
movslq %edx, %rax
xorq %r12, (%r14,%rax,8)
movq %r12, (%r14,%r8,8)
leal 0x1(%r8), %eax
cltd
idivl %r13d
jmp 0x1533
xorl %eax, %eax
movq 0x10(%rsp), %rcx
cmpq $0x0, (%r14,%rcx,8)
jne 0x15ad
movq $0x4d544750, (%r14,%rcx,8) # imm = 0x4D544750
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq