// File: /workspace/github_c_makefile_star2_O3/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, %r14
movq %rsi, %r12
movq %rdi, %r15
movl (%rsi), %ebx
leal 0x3f(%rbx), %r13d
testl %ebx, %ebx
cmovnsl %ebx, %r13d
callq 0x122f
movl %eax, %ecx
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
testl %ecx, %ecx
jne 0x1688
movq %r14, 0x18(%rsp)
movl %ebp, 0x4(%rsp)
sarl $0x6, %r13d
leal 0x1(%r13), %ebp
movq %r15, 0x8(%rsp)
movq 0x1b0(%r15), %rdx
movl $0xb, %r15d
cmpl $0x9b7f, %ebx           # imm = 0x9B7F
jg 0x13e6
movl $0x7, %r15d
cmpl $0x10bf, %ebx           # imm = 0x10BF
jg 0x13e6
xorl %eax, %eax
cmpl $0x980, %ebx            # imm = 0x980
setge %al
leal 0x3(,%rax,2), %r15d
movq %rbx, 0x30(%rsp)
movl %ebp, %eax
subl %r15d, %eax
movl %eax, %r14d
shrl $0x1f, %r14d
addl %eax, %r14d
movq %r12, %rax
movq %r12, 0x10(%rsp)
movq 0x50(%r12), %r12
shlq $0x10, %r12
xorq 0x30(%rax), %r12
sarl %r14d
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(%rdx), %rbx
movslq %ebp, %rax
movq %rax, 0x28(%rsp)
movq %rdx, 0x20(%rsp)
leaq (,%rax,8), %rdx
movq %rbx, %rdi
callq 0x1090
movl $0x1b0, %edx            # imm = 0x1B0
movq 0x8(%rsp), %rdi
movq 0x10(%rsp), %rsi
callq 0x10d0
movq 0x20(%rsp), %r8
movq 0x8(%rsp), %rax
movq %r8, 0x1b0(%rax)
movq 0x28(%rsp), %r10
movl %r10d, 0x4(%r8)
movl %r13d, (%r8)
movl 0x4(%rsp), %esi
cmpl %esi, %r13d
movl %esi, %edi
cmovgl %r13d, %edi
movq %r12, 0x10(%r8)
movslq %r14d, %rax
movq 0x10(%r8,%rax,8), %rcx
movslq %r13d, %rdx
movq %rdx, 0x10(%rsp)
xorq 0x10(%r8,%rdx,8), %r12
movq %r8, %r9
xorq %rcx, %r12
movq %r12, %r8
shrq $0x3b, %r8
xorq %r12, %r8
movabsq $0x1fa0259b019, %r12    # imm = 0x1FA0259B019
imulq %r12, %r8
addq %r8, %rcx
movq %rcx, 0x10(%r9,%rax,8)
movslq %esi, %rcx
addq %rcx, %r8
addl %r15d, %eax
cltd
idivl %r10d
movslq %edx, %rax
addq %r8, 0x10(%r9,%rax,8)
movq %r8, 0x10(%r9)
testl %ecx, %ecx
jle 0x1596
movl %esi, %eax
movq %rax, 0x8(%rsp)
movl $0x1, %edx
xorl %r9d, %r9d
movq %r14, %r8
movq %r13, %r14
movl %r15d, %r13d
movq 0x18(%rsp), %r15
movslq %edx, %r10
movq (%rbx,%r10,8), %r11
leal (%r10,%r8), %ecx
movl %ecx, %eax
cltd
idivl %ebp
movslq %edx, %r12
movq (%rbx,%r12,8), %rsi
leal (%r10,%r14), %eax
cltd
idivl %ebp
movslq %edx, %rax
xorq (%rbx,%rax,8), %r11
xorq %rsi, %r11
movq %r11, %rax
shrq $0x3b, %rax
xorq %r11, %rax
movabsq $0x1fa0259b019, %rdx    # imm = 0x1FA0259B019
imulq %rdx, %rax
addq %rax, %rsi
movq %rsi, (%rbx,%r12,8)
movq (%r15,%r9,8), %rsi
addq %r10, %rsi
addq %rax, %rsi
addl %r13d, %ecx
movl %ecx, %eax
cltd
idivl %ebp
movslq %edx, %rax
addq %rsi, (%rbx,%rax,8)
movq %rsi, (%rbx,%r10,8)
leal 0x1(%r10), %eax
cltd
idivl %ebp
incq %r9
cmpq %r9, 0x8(%rsp)
jne 0x1508
movabsq $0x1fa0259b019, %r12    # imm = 0x1FA0259B019
movl 0x4(%rsp), %eax
movl %r13d, %r15d
movq %r14, %r13
movq %r8, %r14
jmp 0x159d
movl $0x1, %edx
xorl %eax, %eax
subl %eax, %edi
jle 0x15ff
movslq %edx, %r8
movq (%rbx,%r8,8), %rsi
leal (%r8,%r14), %ecx
movl %ecx, %eax
cltd
idivl %ebp
movslq %edx, %r9
movq (%rbx,%r9,8), %r10
leal (%r8,%r13), %eax
cltd
idivl %ebp
movslq %edx, %rax
xorq (%rbx,%rax,8), %rsi
xorq %r10, %rsi
movq %rsi, %r11
shrq $0x3b, %r11
xorq %rsi, %r11
imulq %r12, %r11
addq %r11, %r10
movq %r10, (%rbx,%r9,8)
addq %r8, %r11
addl %r15d, %ecx
movl %ecx, %eax
cltd
idivl %ebp
movslq %edx, %rax
addq %r11, (%rbx,%rax,8)
movq %r11, (%rbx,%r8,8)
leal 0x1(%r8), %eax
cltd
idivl %ebp
decl %edi
jne 0x15a1
cmpl $-0x3f, 0x30(%rsp)
jl 0x1672
movabsq $0xd1341c13e2fab1, %rdi # imm = 0xD1341C13E2FAB1
movl %ebp, %r8d
movslq %edx, %r9
leal (%r9,%r14), %ecx
movl %ecx, %eax
cltd
idivl %ebp
movslq %edx, %rsi
movq (%rbx,%rsi,8), %r10
movq (%rbx,%r9,8), %r11
addq %r10, %r11
leal (%r9,%r13), %eax
cltd
idivl %ebp
movslq %edx, %rax
addq (%rbx,%rax,8), %r11
movq %r11, %r12
shrq $0x3b, %r12
xorq %r11, %r12
imulq %rdi, %r12
xorq %r12, %r10
movq %r10, (%rbx,%rsi,8)
subq %r9, %r12
addl %r15d, %ecx
movl %ecx, %eax
cltd
idivl %ebp
movslq %edx, %rax
xorq %r12, (%rbx,%rax,8)
movq %r12, (%rbx,%r9,8)
leal 0x1(%r9), %eax
cltd
idivl %ebp
decl %r8d
jne 0x1613
xorl %eax, %eax
movq 0x10(%rsp), %rcx
cmpq $0x0, (%rbx,%rcx,8)
jne 0x1688
movq $0x4d544750, (%rbx,%rcx,8) # imm = 0x4D544750
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq