// File: /workspace/github_c_makefile_star2_O3/aparrish[P]rwet-examples-c/markov_gen.c
// Function: markov_gen_generate_new
int markov_gen_generate_new(markov_gen_t* mg, char** line) {

	char* current_key;
	char** possible_next;
	UT_array* output, * next_slice;
	ngram_t* current_ngram;
	int i, output_len, joined_len;

	/* grab a random ngram that occurred at the beginning of a line */
	current_ngram = *((ngram_t**)utarray_choice(mg->beginnings));

	/* make a key by joining the array with a space */
	joined_len = join_new(&current_key, current_ngram->ngram, " ");

	/* new array for output */
	utarray_new(output, &ut_str_icd);

	/* copy from first ngram to output */
	utarray_concat(output, current_ngram->ngram);

	for (i = 0; i < mg->max; i++) {

		/* try to find an ngram with this key */
		HASH_FIND_STR(mg->ngrams, current_key, current_ngram);
		free(current_key); /* previously malloc'ed by join_new */

		/* if we found an ngram */
		if (current_ngram != NULL) {
			/* get a random next word */
			possible_next = (char**)utarray_choice(current_ngram->possible_nexts);
			/* add the word to our output */
			utarray_push_back(output, possible_next);
			/* make a new key from the last n elements of output array */
			output_len = utarray_len(output);
			next_slice = slice_new(output, output_len - (mg->n), output_len);
			joined_len = join_new(&current_key, next_slice, " ");
			utarray_free(next_slice);
		}
		else {
			break;
		}
	}

	/* join output into supplied char* */
	joined_len = join_new(line, output, " ");

	utarray_free(output);
	return joined_len;

}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movq %rsi, %rbp
movq %rdi, %r15
callq 0x1150
movq 0x10(%r15), %rax
movq 0x8(%rax), %rbx
movq 0x28(%rax), %r14
callq 0x1150
movq 0x10(%r15), %rcx
xorl %r13d, %r13d
xorl %edx, %edx
divl (%rcx)
imulq %rbx, %rdx
movq (%r14,%rdx), %r14
movq 0x8(%r14), %rsi
leaq 0xd9c(%rip), %rdx       # 0x30b0
movq %rsp, %rdi
callq 0x164f
movl $0x1, %edi
movl $0x30, %esi
callq 0x1080
movq %rax, %rbx
movups 0x2aa3(%rip), %xmm0     # 0x4dd8
movups %xmm0, 0x18(%rax)
movups 0x2a88(%rip), %xmm0     # 0x4dc8
movups %xmm0, 0x8(%rax)
movq 0x8(%r14), %r12
movl (%r12), %eax
testl %eax, %eax
je 0x23ba
movl $0x8, %ecx
testl %r13d, %r13d
leal (%r13,%r13), %edx
movl %edx, %r13d
cmovel %ecx, %r13d
cmpl %r13d, %eax
ja 0x2355
movl %r13d, 0x4(%rbx)
movl %r13d, %edi
shlq $0x3, %rdi
callq 0x10b0
movq %rax, 0x28(%rbx)
testq %rax, %rax
je 0x27f7
xorl %r13d, %r13d
movl (%rbx), %edi
addq %r13, %rdi
imulq 0x8(%rbx), %rdi
addq 0x28(%rbx), %rdi
movq 0x8(%r12), %rsi
imulq %r13, %rsi
addq 0x28(%r12), %rsi
callq *0x18(%rbx)
incq %r13
movq 0x8(%r14), %r12
movl (%r12), %eax
cmpq %rax, %r13
jb 0x2389
addl %eax, (%rbx)
cmpl $0x0, 0x4(%r15)
jle 0x2793
xorl %r14d, %r14d
movq %rbp, 0x8(%rsp)
movq %r14, 0x10(%rsp)
movq 0x8(%r15), %r14
testq %r14, %r14
je 0x2785
movq (%rsp), %rbp
movq %rbp, %rdi
callq 0x1060
movq %rax, %r12
cmpl $0xc, %r12d
jb 0x2518
movl $0xfeedbeef, %ecx       # imm = 0xFEEDBEEF
movl $0x9e3779b9, %edx       # imm = 0x9E3779B9
movq %rbp, %rax
movl %r12d, %edi
movl $0x9e3779b9, %esi       # imm = 0x9E3779B9
movsbl (%rax), %r8d
addl %esi, %r8d
movsbl 0x1(%rax), %r9d
shll $0x8, %r9d
addl %r8d, %r9d
movsbl 0x2(%rax), %r8d
shll $0x10, %r8d
movzbl 0x3(%rax), %esi
shll $0x18, %esi
addl %r8d, %esi
addl %r9d, %esi
movsbl 0x4(%rax), %r8d
addl %edx, %r8d
movsbl 0x5(%rax), %r9d
shll $0x8, %r9d
addl %r8d, %r9d
movsbl 0x6(%rax), %r8d
shll $0x10, %r8d
movzbl 0x7(%rax), %edx
shll $0x18, %edx
addl %r8d, %edx
addl %r9d, %edx
movsbl 0x8(%rax), %r8d
addl %ecx, %r8d
movsbl 0x9(%rax), %r9d
shll $0x8, %r9d
addl %r8d, %r9d
movsbl 0xa(%rax), %r8d
shll $0x10, %r8d
movzbl 0xb(%rax), %ecx
shll $0x18, %ecx
addl %r8d, %ecx
addl %r9d, %ecx
subl %edx, %esi
subl %ecx, %esi
movl %ecx, %r8d
shrl $0xd, %r8d
xorl %esi, %r8d
subl %ecx, %edx
subl %r8d, %edx
movl %r8d, %esi
shll $0x8, %esi
xorl %edx, %esi
subl %r8d, %ecx
subl %esi, %ecx
movl %esi, %edx
shrl $0xd, %edx
xorl %ecx, %edx
subl %esi, %r8d
subl %edx, %r8d
movl %edx, %ecx
shrl $0xc, %ecx
xorl %r8d, %ecx
subl %edx, %esi
subl %ecx, %esi
movl %ecx, %r8d
shll $0x10, %r8d
xorl %esi, %r8d
subl %ecx, %edx
subl %r8d, %edx
movl %r8d, %r9d
shrl $0x5, %r9d
xorl %edx, %r9d
subl %r8d, %ecx
subl %r9d, %ecx
movl %r9d, %esi
shrl $0x3, %esi
xorl %ecx, %esi
subl %r9d, %r8d
subl %esi, %r8d
movl %esi, %edx
shll $0xa, %edx
xorl %r8d, %edx
subl %esi, %r9d
subl %edx, %r9d
movl %edx, %ecx
shrl $0xf, %ecx
xorl %r9d, %ecx
addq $0xc, %rax
addl $-0xc, %edi
cmpl $0xb, %edi
ja 0x240d
jmp 0x252d
movl $0x9e3779b9, %esi       # imm = 0x9E3779B9
movl $0xfeedbeef, %ecx       # imm = 0xFEEDBEEF
movl $0x9e3779b9, %edx       # imm = 0x9E3779B9
movl %r12d, %edi
movq %rbp, %rax
addl %r12d, %ecx
decl %edi
cmpl $0xa, %edi
ja 0x25bd
leaq 0xb3e(%rip), %r8        # 0x3080
movslq (%r8,%rdi,4), %rdi
addq %r8, %rdi
jmpq *%rdi
movzbl 0xa(%rax), %edi
shll $0x18, %edi
addl %ecx, %edi
movl %edi, %ecx
movsbl 0x9(%rax), %edi
shll $0x10, %edi
addl %ecx, %edi
movl %edi, %ecx
movsbl 0x8(%rax), %edi
shll $0x8, %edi
addl %ecx, %edi
movl %edi, %ecx
movzbl 0x7(%rax), %edi
shll $0x18, %edi
addl %edx, %edi
movl %edi, %edx
movsbl 0x6(%rax), %edi
shll $0x10, %edi
addl %edx, %edi
movl %edi, %edx
movsbl 0x5(%rax), %edi
shll $0x8, %edi
addl %edx, %edi
movl %edi, %edx
movsbl 0x4(%rax), %edi
addl %edx, %edi
movl %edi, %edx
movzbl 0x3(%rax), %edi
shll $0x18, %edi
addl %esi, %edi
movl %edi, %esi
movsbl 0x2(%rax), %edi
shll $0x10, %edi
addl %esi, %edi
movl %edi, %esi
movsbl 0x1(%rax), %edi
shll $0x8, %edi
addl %esi, %edi
movl %edi, %esi
movsbl (%rax), %eax
addl %esi, %eax
movl %eax, %esi
subl %ecx, %esi
subl %edx, %esi
movl %ecx, %eax
shrl $0xd, %eax
xorl %esi, %eax
subl %ecx, %edx
subl %eax, %edx
movl %eax, %esi
shll $0x8, %esi
xorl %edx, %esi
subl %eax, %ecx
subl %esi, %ecx
movl %esi, %edx
shrl $0xd, %edx
xorl %ecx, %edx
subl %esi, %eax
subl %edx, %eax
movl %edx, %ecx
shrl $0xc, %ecx
xorl %eax, %ecx
subl %edx, %esi
subl %ecx, %esi
movl %ecx, %eax
shll $0x10, %eax
xorl %esi, %eax
subl %ecx, %edx
subl %eax, %edx
movl %eax, %esi
shrl $0x5, %esi
xorl %edx, %esi
subl %eax, %ecx
subl %esi, %ecx
movl %esi, %edx
shrl $0x3, %edx
xorl %ecx, %edx
subl %esi, %eax
subl %edx, %eax
movl %edx, %ecx
shll $0xa, %ecx
xorl %eax, %ecx
addl %ecx, %edx
subl %edx, %esi
shrl $0xf, %ecx
xorl %esi, %ecx
movq 0x18(%r14), %r14
movl 0x8(%r14), %eax
decl %eax
andl %ecx, %eax
movq (%r14), %rcx
shlq $0x4, %rax
movq (%rcx,%rax), %r13
testq %r13, %r13
je 0x2785
subq 0x20(%r14), %r13
movl 0x48(%r13), %eax
cmpq %rax, %r12
jne 0x265e
movq 0x40(%r13), %rdi
movq %rbp, %rsi
movq %r12, %rdx
callq 0x10c0
testl %eax, %eax
je 0x2664
movq 0x38(%r13), %r13
jmp 0x2635
movq (%rsp), %rdi
callq 0x1030
callq 0x1150
movq 0x10(%r13), %rax
movq 0x8(%rax), %r14
movq 0x28(%rax), %r12
callq 0x1150
movq 0x10(%r13), %rcx
xorl %edx, %edx
divl (%rcx)
movl %edx, %ebp
movl (%rbx), %ecx
movl 0x4(%rbx), %eax
incl %ecx
cmpl %eax, %ecx
movl $0x8, %edx
jbe 0x26c9
testl %eax, %eax
leal (%rax,%rax), %eax
cmovel %edx, %eax
cmpl %eax, %ecx
ja 0x269d
movl %eax, 0x4(%rbx)
movq 0x28(%rbx), %rdi
movl %eax, %esi
imulq 0x8(%rbx), %rsi
callq 0x10d0
movq %rax, 0x28(%rbx)
testq %rax, %rax
je 0x27f7
imulq %rbp, %r14
addq %r14, %r12
movq 0x18(%rbx), %rax
movq 0x8(%rbx), %rdx
movl (%rbx), %edi
leal 0x1(%rdi), %ecx
imulq %rdx, %rdi
addq 0x28(%rbx), %rdi
movl %ecx, (%rbx)
movq %r12, %rsi
testq %rax, %rax
je 0x26f3
callq *%rax
jmp 0x26f8
callq 0x10a0
movq 0x8(%rsp), %rbp
movl (%rbx), %edx
movl %edx, %esi
subl (%r15), %esi
movq %rbx, %rdi
callq 0x14ef
movq %rax, %r12
movq %rsp, %rdi
movq %rax, %rsi
leaq 0x994(%rip), %rdx       # 0x30b0
callq 0x164f
cmpl $0x0, 0x4(%r12)
movq 0x10(%rsp), %r14
je 0x276e
cmpq $0x0, 0x20(%r12)
je 0x275f
cmpl $0x0, (%r12)
je 0x275f
xorl %r14d, %r14d
movq 0x8(%r12), %rdi
imulq %r14, %rdi
addq 0x28(%r12), %rdi
callq *0x20(%r12)
incq %r14
movl (%r12), %eax
cmpq %rax, %r14
jb 0x2740
movq 0x28(%r12), %rdi
callq 0x1030
movq 0x10(%rsp), %r14
movq %r12, %rdi
callq 0x1030
incl %r14d
cmpl 0x4(%r15), %r14d
jl 0x23cd
jmp 0x2793
movq (%rsp), %rdi
callq 0x1030
movq 0x8(%rsp), %rbp
leaq 0x916(%rip), %rdx       # 0x30b0
movq %rbp, %rdi
movq %rbx, %rsi
callq 0x164f
movl %eax, %ebp
cmpl $0x0, 0x4(%rbx)
je 0x27de
cmpq $0x0, 0x20(%rbx)
je 0x27d5
cmpl $0x0, (%rbx)
je 0x27d5
xorl %r14d, %r14d
movq 0x8(%rbx), %rdi
imulq %r14, %rdi
addq 0x28(%rbx), %rdi
callq *0x20(%rbx)
incq %r14
movl (%rbx), %eax
cmpq %rax, %r14
jb 0x27bc
movq 0x28(%rbx), %rdi
callq 0x1030
movq %rbx, %rdi
callq 0x1030
movl %ebp, %eax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movl $0xffffffff, %edi       # imm = 0xFFFFFFFF
callq 0x1110