// File: /workspace/github_c_makefile_star2_O0/coyove[P]chann/./lib/unqlite/unqlite.c
// Function: vm_builtin_utf8_encode
static int vm_builtin_utf8_encode(jx9_context *pCtx, int nArg, jx9_value **apArg)
{
	const unsigned char *zIn, *zEnd;
	int nByte, c, e;
	if( nArg < 1 ){
		/* Missing arguments, return null */
		jx9_result_null(pCtx);
		return JX9_OK;
	}
	/* Extract the target string */
	zIn = (const unsigned char *)jx9_value_to_string(apArg[0], &nByte);
	if( nByte < 1 ){
		/* Empty string, return null */
		jx9_result_null(pCtx);
		return JX9_OK;
	}
	zEnd = &zIn[nByte];
	/* Start the encoding process */
	for(;;){
		if( zIn >= zEnd ){
			/* End of input */
			break;
		}
		c = zIn[0];
		/* Advance the stream cursor */
		zIn++;
		/* Encode */
		if( c<0x00080 ){
			e = (c&0xFF);
			jx9_result_string(pCtx, (const char *)&e, (int)sizeof(char));
		}else if( c<0x00800 ){
			e = 0xC0 + ((c>>6)&0x1F);
			jx9_result_string(pCtx, (const char *)&e, (int)sizeof(char));
			e = 0x80 + (c & 0x3F);
			jx9_result_string(pCtx, (const char *)&e, (int)sizeof(char));
		}else if( c<0x10000 ){
			e = 0xE0 + ((c>>12)&0x0F);
			jx9_result_string(pCtx, (const char *)&e, (int)sizeof(char));
			e = 0x80 + ((c>>6) & 0x3F);
			jx9_result_string(pCtx, (const char *)&e, (int)sizeof(char));
			e = 0x80 + (c & 0x3F);
			jx9_result_string(pCtx, (const char *)&e, (int)sizeof(char));
		}else{
			e = 0xF0 + ((c>>18) & 0x07);
			jx9_result_string(pCtx, (const char *)&e, (int)sizeof(char));
			e = 0x80 + ((c>>12) & 0x3F);
			jx9_result_string(pCtx, (const char *)&e, (int)sizeof(char));
			e = 0x80 + ((c>>6) & 0x3F);
			jx9_result_string(pCtx, (const char *)&e, (int)sizeof(char));
			e = 0x80 + (c & 0x3F);
			jx9_result_string(pCtx, (const char *)&e, (int)sizeof(char));
		} 
	}
	/* All done */
	return JX9_OK;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x40, %rsp
movq %rdi, -0x10(%rbp)
movl %esi, -0x14(%rbp)
movq %rdx, -0x20(%rbp)
cmpl $0x1, -0x14(%rbp)
jge 0x8b96e
movq -0x10(%rbp), %rdi
callq 0x57120
movl $0x0, -0x4(%rbp)
jmp 0x8bb5a
movq -0x20(%rbp), %rax
movq (%rax), %rdi
leaq -0x34(%rbp), %rsi
callq 0x56e20
movq %rax, -0x28(%rbp)
cmpl $0x1, -0x34(%rbp)
jge 0x8b99d
movq -0x10(%rbp), %rdi
callq 0x57120
movl $0x0, -0x4(%rbp)
jmp 0x8bb5a
movq -0x28(%rbp), %rax
movslq -0x34(%rbp), %rcx
addq %rcx, %rax
movq %rax, -0x30(%rbp)
movq -0x28(%rbp), %rax
cmpq -0x30(%rbp), %rax
jb 0x8b9bb
jmp 0x8bb53
movq -0x28(%rbp), %rax
movzbl (%rax), %eax
movl %eax, -0x38(%rbp)
movq -0x28(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x28(%rbp)
cmpl $0x80, -0x38(%rbp)
jge 0x8b9fc
movl -0x38(%rbp), %eax
andl $0xff, %eax
movl %eax, -0x3c(%rbp)
movq -0x10(%rbp), %rdi
leaq -0x3c(%rbp), %rsi
movl $0x1, %edx
callq 0x57180
jmp 0x8bb4e
cmpl $0x800, -0x38(%rbp)     # imm = 0x800
jge 0x8ba4d
movl -0x38(%rbp), %eax
sarl $0x6, %eax
andl $0x1f, %eax
addl $0xc0, %eax
movl %eax, -0x3c(%rbp)
movq -0x10(%rbp), %rdi
leaq -0x3c(%rbp), %rsi
movl $0x1, %edx
callq 0x57180
movl -0x38(%rbp), %eax
andl $0x3f, %eax
addl $0x80, %eax
movl %eax, -0x3c(%rbp)
movq -0x10(%rbp), %rdi
leaq -0x3c(%rbp), %rsi
movl $0x1, %edx
callq 0x57180
jmp 0x8bb4c
cmpl $0x10000, -0x38(%rbp)   # imm = 0x10000
jge 0x8bac1
movl -0x38(%rbp), %eax
sarl $0xc, %eax
andl $0xf, %eax
addl $0xe0, %eax
movl %eax, -0x3c(%rbp)
movq -0x10(%rbp), %rdi
leaq -0x3c(%rbp), %rsi
movl $0x1, %edx
callq 0x57180
movl -0x38(%rbp), %eax
sarl $0x6, %eax
andl $0x3f, %eax
addl $0x80, %eax
movl %eax, -0x3c(%rbp)
movq -0x10(%rbp), %rdi
leaq -0x3c(%rbp), %rsi
movl $0x1, %edx
callq 0x57180
movl -0x38(%rbp), %eax
andl $0x3f, %eax
addl $0x80, %eax
movl %eax, -0x3c(%rbp)
movq -0x10(%rbp), %rdi
leaq -0x3c(%rbp), %rsi
movl $0x1, %edx
callq 0x57180
jmp 0x8bb4a
movl -0x38(%rbp), %eax
sarl $0x12, %eax
andl $0x7, %eax
addl $0xf0, %eax
movl %eax, -0x3c(%rbp)
movq -0x10(%rbp), %rdi
leaq -0x3c(%rbp), %rsi
movl $0x1, %edx
callq 0x57180
movl -0x38(%rbp), %eax
sarl $0xc, %eax
andl $0x3f, %eax
addl $0x80, %eax
movl %eax, -0x3c(%rbp)
movq -0x10(%rbp), %rdi
leaq -0x3c(%rbp), %rsi
movl $0x1, %edx
callq 0x57180
movl -0x38(%rbp), %eax
sarl $0x6, %eax
andl $0x3f, %eax
addl $0x80, %eax
movl %eax, -0x3c(%rbp)
movq -0x10(%rbp), %rdi
leaq -0x3c(%rbp), %rsi
movl $0x1, %edx
callq 0x57180
movl -0x38(%rbp), %eax
andl $0x3f, %eax
addl $0x80, %eax
movl %eax, -0x3c(%rbp)
movq -0x10(%rbp), %rdi
leaq -0x3c(%rbp), %rsi
movl $0x1, %edx
callq 0x57180
jmp 0x8bb4c
jmp 0x8bb4e
jmp 0x8b9ac
movl $0x0, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x40, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)