// File: /workspace/github_c_makefile_star2_O2/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 $0x28, %rsp
movq %rsi, 0x20(%rsp)
movq %rdi, %r15
callq 0x1160
movq 0x10(%r15), %rax
movq 0x8(%rax), %rbx
movq 0x28(%rax), %r14
callq 0x1160
movq %r15, 0x8(%rsp)
movq 0x10(%r15), %rcx
xorl %r13d, %r13d
xorl %edx, %edx
divl (%rcx)
imulq %rbx, %rdx
movq (%r14,%rdx), %r14
movq 0x8(%r14), %rsi
leaq 0xd99(%rip), %rdx       # 0x30b0
leaq 0x18(%rsp), %rdi
callq 0x162c
pushq $0x1
popq %rdi
pushq $0x30
popq %rsi
callq 0x1090
movq %rax, %rbx
movups 0x2aa2(%rip), %xmm0     # 0x4dd8
movups %xmm0, 0x18(%rax)
movups 0x2a87(%rip), %xmm0     # 0x4dc8
movups %xmm0, 0x8(%rax)
movq 0x8(%r14), %r15
movl (%r15), %ebp
testl %ebp, %ebp
je 0x23b9
pushq $0x8
popq %rcx
cmpl %r13d, %ebp
jbe 0x236b
testl %r13d, %r13d
leal (%r13,%r13), %eax
cmovel %ecx, %eax
movl %eax, 0x4(%rbx)
movl %eax, %r13d
jmp 0x2353
movl %r13d, %edi
shlq $0x3, %rdi
callq 0x10c0
movq %rax, 0x28(%rbx)
testq %rax, %rax
je 0x282e
xorl %r13d, %r13d
movl %ebp, %eax
cmpq %rax, %r13
jae 0x23b7
movl (%rbx), %edi
addq %r13, %rdi
imulq 0x8(%rbx), %rdi
addq 0x28(%rbx), %rdi
movq 0x8(%r15), %rsi
imulq %r13, %rsi
addq 0x28(%r15), %rsi
callq *0x18(%rbx)
incq %r13
movq 0x8(%r14), %r15
movl (%r15), %ebp
jmp 0x2387
addl %ebp, (%rbx)
xorl %r12d, %r12d
movq 0x8(%rsp), %rax
cmpl 0x4(%rax), %r12d
jge 0x27cb
movq 0x8(%rsp), %rax
movq 0x8(%rax), %rax
movq 0x18(%rsp), %rbp
testq %rax, %rax
je 0x26ad
movq %rax, (%rsp)
movq %r12, 0x10(%rsp)
movq %rbp, %rdi
callq 0x1060
movq %rax, %r14
leaq 0xb(%rbp), %rax
movl $0x9e3779b9, %esi       # imm = 0x9E3779B9
movl $0xfeedbeef, %ecx       # imm = 0xFEEDBEEF
movl $0x9e3779b9, %edx       # imm = 0x9E3779B9
movl %r14d, %edi
cmpl $0xc, %edi
jb 0x2520
movsbl -0xb(%rax), %r9d
movsbl -0xa(%rax), %r8d
shll $0x8, %r8d
movsbl -0x9(%rax), %r11d
shll $0x10, %r11d
movzbl -0x8(%rax), %r10d
shll $0x18, %r10d
addl %r11d, %r10d
movsbl -0x7(%rax), %r11d
movsbl -0x6(%rax), %r13d
shll $0x8, %r13d
movsbl -0x5(%rax), %r15d
shll $0x10, %r15d
movzbl -0x4(%rax), %r12d
shll $0x18, %r12d
addl %r15d, %r12d
addl %r11d, %edx
addl %r13d, %edx
addl %r12d, %edx
movsbl -0x3(%rax), %r11d
movsbl -0x2(%rax), %r15d
shll $0x8, %r15d
movsbl -0x1(%rax), %r12d
shll $0x10, %r12d
movzbl (%rax), %r13d
shll $0x18, %r13d
addl %r12d, %r13d
addl %r11d, %ecx
addl %r15d, %ecx
addl %r13d, %ecx
addl %r9d, %esi
addl %r8d, %esi
addl %r10d, %esi
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
addl $-0xc, %edi
addq $0xc, %rax
jmp 0x240c
addl %r14d, %ecx
decl %edi
cmpl $0xa, %edi
ja 0x27bd
leaq 0xb4b(%rip), %r8        # 0x3080
movslq (%r8,%rdi,4), %rdi
addq %r8, %rdi
movq 0x10(%rsp), %r12
jmpq *%rdi
movq (%rsp), %r8
jmp 0x25e5
movq (%rsp), %r8
jmp 0x25bc
movq (%rsp), %r8
jmp 0x25cf
movq (%rsp), %r8
jmp 0x25c4
movq (%rsp), %r8
jmp 0x259b
movq (%rsp), %r8
jmp 0x25da
movq (%rsp), %r8
jmp 0x25b1
movq (%rsp), %r8
jmp 0x25a6
movzbl -0x1(%rax), %edi
shll $0x18, %edi
addl %ecx, %edi
movl %edi, %ecx
movsbl -0x2(%rax), %edi
shll $0x10, %edi
addl %ecx, %edi
movl %edi, %ecx
movq (%rsp), %r8
movsbl -0x3(%rax), %edi
shll $0x8, %edi
addl %ecx, %edi
movl %edi, %ecx
movzbl -0x4(%rax), %edi
shll $0x18, %edi
addl %edx, %edi
movl %edi, %edx
movsbl -0x5(%rax), %edi
shll $0x10, %edi
addl %edx, %edi
movl %edi, %edx
movsbl -0x6(%rax), %edi
shll $0x8, %edi
addl %edx, %edi
movl %edi, %edx
movsbl -0x7(%rax), %edi
addl %edx, %edi
movl %edi, %edx
movzbl -0x8(%rax), %edi
shll $0x18, %edi
addl %esi, %edi
movl %edi, %esi
movsbl -0x9(%rax), %edi
shll $0x10, %edi
addl %esi, %edi
movl %edi, %esi
movsbl -0xa(%rax), %edi
shll $0x8, %edi
addl %esi, %edi
movl %edi, %esi
movsbl -0xb(%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(%r8), %r13
movl 0x8(%r13), %eax
decl %eax
andl %ecx, %eax
movq (%r13), %rcx
shlq $0x4, %rax
movq (%rcx,%rax), %r15
testq %r15, %r15
je 0x2671
subq 0x20(%r13), %r15
jmp 0x2674
xorl %r15d, %r15d
testq %r15, %r15
je 0x26ad
movl 0x48(%r15), %eax
cmpq %rax, %r14
jne 0x2695
movq 0x40(%r15), %rdi
movq %rbp, %rsi
movq %r14, %rdx
callq 0x10d0
testl %eax, %eax
je 0x26b0
movq 0x38(%r15), %rax
movl $0x0, %r15d
testq %rax, %rax
je 0x2674
subq 0x20(%r13), %rax
movq %rax, %r15
jmp 0x2674
xorl %r15d, %r15d
movq %rbp, %rdi
callq 0x1030
testq %r15, %r15
je 0x27cb
callq 0x1160
movq 0x10(%r15), %rax
movq 0x8(%rax), %r13
movq 0x28(%rax), %r14
callq 0x1160
movq 0x10(%r15), %rcx
xorl %edx, %edx
divl (%rcx)
movl %edx, %ebp
movl (%rbx), %eax
movl 0x4(%rbx), %ecx
incl %eax
cmpl %ecx, %eax
jbe 0x271d
pushq $0x8
popq %rdx
cmpl %ecx, %eax
jbe 0x2700
testl %ecx, %ecx
leal (%rcx,%rcx), %ecx
cmovel %edx, %ecx
movl %ecx, 0x4(%rbx)
jmp 0x26ef
movq 0x28(%rbx), %rdi
movl %ecx, %esi
imulq 0x8(%rbx), %rsi
callq 0x10e0
movq %rax, 0x28(%rbx)
testq %rax, %rax
je 0x282e
imulq %rbp, %r13
addq %r13, %r14
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 %r14, %rsi
testq %rax, %rax
je 0x2747
callq *%rax
jmp 0x274c
callq 0x10b0
movl (%rbx), %edx
movl %edx, %esi
movq 0x8(%rsp), %rax
subl (%rax), %esi
movq %rbx, %rdi
callq 0x14c7
movq %rax, %r14
leaq 0x18(%rsp), %rdi
movq %rax, %rsi
leaq 0x93f(%rip), %rdx       # 0x30b0
callq 0x162c
cmpl $0x0, 0x4(%r14)
je 0x27ad
cmpq $0x0, 0x20(%r14)
je 0x27a4
xorl %r15d, %r15d
movl (%r14), %eax
cmpq %rax, %r15
jae 0x27a4
movq 0x8(%r14), %rdi
imulq %r15, %rdi
addq 0x28(%r14), %rdi
callq *0x20(%r14)
incq %r15
jmp 0x2787
movq 0x28(%r14), %rdi
callq 0x1030
movq %r14, %rdi
callq 0x1030
incl %r12d
jmp 0x23bc
movq 0x10(%rsp), %r12
movq (%rsp), %r8
jmp 0x25ed
leaq 0x8de(%rip), %rdx       # 0x30b0
movq 0x20(%rsp), %rdi
movq %rbx, %rsi
callq 0x162c
movl %eax, %ebp
cmpl $0x0, 0x4(%rbx)
je 0x2815
cmpq $0x0, 0x20(%rbx)
je 0x280c
xorl %r14d, %r14d
movl (%rbx), %eax
cmpq %rax, %r14
jae 0x280c
movq 0x8(%rbx), %rdi
imulq %r14, %rdi
addq 0x28(%rbx), %rdi
callq *0x20(%rbx)
incq %r14
jmp 0x27f1
movq 0x28(%rbx), %rdi
callq 0x1030
movq %rbx, %rdi
callq 0x1030
movl %ebp, %eax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
pushq $-0x1
popq %rdi
callq 0x1120