// File: /workspace/github_c_makefile_star2_O3/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, 0x4(%rsp)
movq %rdx, %r12
movq %rsi, %rbp
movl (%rsi), %r15d
leal 0x3f(%r15), %r13d
testl %r15d, %r15d
cmovnsl %r15d, %r13d
movq %rdi, 0x8(%rsp)
sarl $0x6, %r13d
movslq %r13d, %r14
leaq 0x10(,%r14,8), %rdi
callq 0x10d0
testq %rax, %rax
je 0x1506
movq %rax, %rbx
movq %rbp, %rcx
movq %r12, 0x18(%rsp)
leal 0x1(%r14), %ebp
movq %r14, 0x10(%rsp)
leaq 0x8(,%r14,8), %rdx
movq %rax, 0x28(%rsp)
movl $0xb, %r12d
cmpl $0x9b7f, %r15d          # imm = 0x9B7F
jg 0x1380
movl $0x7, %r12d
cmpl $0x10bf, %r15d          # imm = 0x10BF
jg 0x1380
xorl %eax, %eax
cmpl $0x980, %r15d           # imm = 0x980
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
sarl %r15d
movq %rcx, 0x20(%rsp)
movq 0x28(%rcx), %r14
shlq $0x10, %r14
xorq 0x20(%rcx), %r14
movq %r14, %rax
shrq $0x20, %rax
movq %r14, %rcx
shrq $0x30, %rcx
addq %rax, %rcx
movq %rcx, %rsi
shrq $0x8, %rsi
addl %ecx, %esi
addq $0x8, %rbx
movq %rbx, %rdi
callq 0x1090
movl $0xe, %ecx
movq 0x8(%rsp), %rax
movq %rax, %rdi
movq 0x20(%rsp), %rsi
rep  movsq (%rsi), %es:(%rdi)
movq 0x28(%rsp), %r9
movq %r9, 0x70(%rax)
movl %ebp, (%r9)
movq 0x10(%rsp), %rdx
movl %edx, 0x4(%r9)
movq %r14, 0x8(%r9)
movl 0x4(%rsp), %r8d
cmpl %r8d, %edx
movl %r8d, %esi
cmovgl %edx, %esi
movslq %r15d, %rax
movq 0x8(%r9,%rax,8), %rcx
xorq 0x8(%r9,%rdx,8), %r14
xorq %rcx, %r14
movq %r14, %rdi
shrq $0x3b, %rdi
xorq %r14, %rdi
movabsq $0x1fa0259b019, %r14    # imm = 0x1FA0259B019
imulq %r14, %rdi
addq %rdi, %rcx
movq %rcx, 0x8(%r9,%rax,8)
movslq %r8d, %rcx
addq %rcx, %rdi
addl %r12d, %eax
cltd
idivl %ebp
movslq %edx, %rax
addq %rdi, 0x8(%r9,%rax,8)
movq %rdi, 0x8(%r9)
testl %ecx, %ecx
jle 0x1510
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
movq (%rbx,%r9,8), %r10
leal (%r9,%rdi), %ecx
movl %ecx, %eax
cltd
idivl %ebp
movslq %edx, %r11
movq (%rbx,%r11,8), %r14
leal (%r9,%r15), %eax
cltd
idivl %ebp
movslq %edx, %rax
xorq (%rbx,%rax,8), %r10
xorq %r14, %r10
movq %r10, %rax
shrq $0x3b, %rax
xorq %r10, %rax
movabsq $0x1fa0259b019, %rdx    # imm = 0x1FA0259B019
imulq %rdx, %rax
addq %rax, %r14
movq %r14, (%rbx,%r11,8)
movq (%r12,%r8,8), %r10
addq %r9, %r10
addq %rax, %r10
addl %r13d, %ecx
movl %ecx, %eax
cltd
idivl %ebp
movslq %edx, %rax
addq %r10, (%rbx,%rax,8)
movq %r10, (%rbx,%r9,8)
leal 0x1(%r9), %eax
cltd
idivl %ebp
incq %r8
cmpq %r8, 0x8(%rsp)
jne 0x1478
movabsq $0x1fa0259b019, %r14    # imm = 0x1FA0259B019
movl 0x4(%rsp), %eax
movl %r13d, %r12d
movq %r15, %r13
movq %rdi, %r15
jmp 0x1517
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
jmp 0x15ff
movl $0x1, %edx
xorl %eax, %eax
subl %eax, %esi
jle 0x1578
movslq %edx, %rdi
movq (%rbx,%rdi,8), %r8
leal (%rdi,%r15), %ecx
movl %ecx, %eax
cltd
idivl %ebp
movslq %edx, %r9
movq (%rbx,%r9,8), %r10
leal (%rdi,%r13), %eax
cltd
idivl %ebp
movslq %edx, %rax
xorq (%rbx,%rax,8), %r8
xorq %r10, %r8
movq %r8, %r11
shrq $0x3b, %r11
xorq %r8, %r11
imulq %r14, %r11
addq %r11, %r10
movq %r10, (%rbx,%r9,8)
addq %rdi, %r11
addl %r12d, %ecx
movl %ecx, %eax
cltd
idivl %ebp
movslq %edx, %rax
addq %r11, (%rbx,%rax,8)
movq %r11, (%rbx,%rdi,8)
leal 0x1(%rdi), %eax
cltd
idivl %ebp
decl %esi
jne 0x151b
cmpl $-0x3f, 0x30(%rsp)
jl 0x15e9
movabsq $0xd1341c13e2fab1, %rsi # imm = 0xD1341C13E2FAB1
movl %ebp, %edi
movslq %edx, %r8
leal (%r8,%r15), %ecx
movl %ecx, %eax
cltd
idivl %ebp
movslq %edx, %r9
movq (%rbx,%r9,8), %r10
movq (%rbx,%r8,8), %r11
addq %r10, %r11
leal (%r8,%r13), %eax
cltd
idivl %ebp
movslq %edx, %rax
addq (%rbx,%rax,8), %r11
movq %r11, %r14
shrq $0x3b, %r14
xorq %r11, %r14
imulq %rsi, %r14
xorq %r14, %r10
movq %r10, (%rbx,%r9,8)
subq %r8, %r14
addl %r12d, %ecx
movl %ecx, %eax
cltd
idivl %ebp
movslq %edx, %rax
xorq %r14, (%rbx,%rax,8)
movq %r14, (%rbx,%r8,8)
leal 0x1(%r8), %eax
cltd
idivl %ebp
decl %edi
jne 0x158b
xorl %eax, %eax
movq 0x10(%rsp), %rcx
cmpq $0x0, (%rbx,%rcx,8)
jne 0x15ff
movq $0x4d544750, (%rbx,%rcx,8) # imm = 0x4D544750
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq