// File: /workspace/github_c_makefile_star2_O0/coyove[P]chann/./lib/unqlite/unqlite.c
// Function: jx9Builtin_substr
static int jx9Builtin_substr(jx9_context *pCtx, int nArg, jx9_value **apArg)
{
	const char *zSource, *zOfft;
	int nOfft, nLen, nSrcLen;	
	if( nArg < 2 ){
		/* return FALSE */
		jx9_result_bool(pCtx, 0);
		return JX9_OK;
	}
	/* Extract the target string */
	zSource = jx9_value_to_string(apArg[0], &nSrcLen);
	if( nSrcLen < 1 ){
		/* Empty string, return FALSE */
		jx9_result_bool(pCtx, 0);
		return JX9_OK;
	}
	nLen = nSrcLen; /* cc warning */
	/* Extract the offset */
	nOfft = jx9_value_to_int(apArg[1]);
	if( nOfft < 0 ){
		zOfft = &zSource[nSrcLen+nOfft]; 
		if( zOfft < zSource ){
			/* Invalid offset */
			jx9_result_bool(pCtx, 0);
			return JX9_OK;
		}
		nLen = (int)(&zSource[nSrcLen]-zOfft);
		nOfft = (int)(zOfft-zSource);
	}else if( nOfft >= nSrcLen ){
		/* Invalid offset */
		jx9_result_bool(pCtx, 0);
		return JX9_OK;
	}else{
		zOfft = &zSource[nOfft];
		nLen = nSrcLen - nOfft;
	}
	if( nArg > 2 ){
		/* Extract the length */
		nLen = jx9_value_to_int(apArg[2]);
		if( nLen == 0 ){
			/* Invalid length, return an empty string */
			jx9_result_string(pCtx, "", 0);
			return JX9_OK;
		}else if( nLen < 0 ){
			nLen = nSrcLen + nLen - nOfft;
			if( nLen < 1 ){
				/* Invalid  length */
				nLen = nSrcLen - nOfft;
			}
		}
		if( nLen + nOfft > nSrcLen ){
			/* Invalid length */
			nLen = nSrcLen - nOfft;
		}
	}
	/* Return the substring */
	jx9_result_string(pCtx, zOfft, nLen);
	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 $0x2, -0x14(%rbp)
jge 0x91b00
movq -0x10(%rbp), %rdi
xorl %esi, %esi
callq 0x57070
movl $0x0, -0x4(%rbp)
jmp 0x91c69
movq -0x20(%rbp), %rax
movq (%rax), %rdi
leaq -0x3c(%rbp), %rsi
callq 0x56e20
movq %rax, -0x28(%rbp)
cmpl $0x1, -0x3c(%rbp)
jge 0x91b31
movq -0x10(%rbp), %rdi
xorl %esi, %esi
callq 0x57070
movl $0x0, -0x4(%rbp)
jmp 0x91c69
movl -0x3c(%rbp), %eax
movl %eax, -0x38(%rbp)
movq -0x20(%rbp), %rax
movq 0x8(%rax), %rdi
callq 0x56c90
movl %eax, -0x34(%rbp)
cmpl $0x0, -0x34(%rbp)
jge 0x91ba7
movq -0x28(%rbp), %rax
movl -0x3c(%rbp), %ecx
addl -0x34(%rbp), %ecx
movslq %ecx, %rcx
addq %rcx, %rax
movq %rax, -0x30(%rbp)
movq -0x30(%rbp), %rax
cmpq -0x28(%rbp), %rax
jae 0x91b82
movq -0x10(%rbp), %rdi
xorl %esi, %esi
callq 0x57070
movl $0x0, -0x4(%rbp)
jmp 0x91c69
movq -0x28(%rbp), %rax
movslq -0x3c(%rbp), %rcx
addq %rcx, %rax
movq -0x30(%rbp), %rcx
subq %rcx, %rax
movl %eax, -0x38(%rbp)
movq -0x30(%rbp), %rax
movq -0x28(%rbp), %rcx
subq %rcx, %rax
movl %eax, -0x34(%rbp)
jmp 0x91be0
movl -0x34(%rbp), %eax
cmpl -0x3c(%rbp), %eax
jl 0x91bc6
movq -0x10(%rbp), %rdi
xorl %esi, %esi
callq 0x57070
movl $0x0, -0x4(%rbp)
jmp 0x91c69
movq -0x28(%rbp), %rax
movslq -0x34(%rbp), %rcx
addq %rcx, %rax
movq %rax, -0x30(%rbp)
movl -0x3c(%rbp), %eax
subl -0x34(%rbp), %eax
movl %eax, -0x38(%rbp)
jmp 0x91be0
cmpl $0x2, -0x14(%rbp)
jle 0x91c52
movq -0x20(%rbp), %rax
movq 0x10(%rax), %rdi
callq 0x56c90
movl %eax, -0x38(%rbp)
cmpl $0x0, -0x38(%rbp)
jne 0x91c17
movq -0x10(%rbp), %rdi
leaq 0x33f44(%rip), %rsi     # 0xc5b4b
xorl %edx, %edx
callq 0x57180
movl $0x0, -0x4(%rbp)
jmp 0x91c69
cmpl $0x0, -0x38(%rbp)
jge 0x91c3a
movl -0x3c(%rbp), %eax
addl -0x38(%rbp), %eax
subl -0x34(%rbp), %eax
movl %eax, -0x38(%rbp)
cmpl $0x1, -0x38(%rbp)
jge 0x91c38
movl -0x3c(%rbp), %eax
subl -0x34(%rbp), %eax
movl %eax, -0x38(%rbp)
jmp 0x91c3a
jmp 0x91c3c
movl -0x38(%rbp), %eax
addl -0x34(%rbp), %eax
cmpl -0x3c(%rbp), %eax
jle 0x91c50
movl -0x3c(%rbp), %eax
subl -0x34(%rbp), %eax
movl %eax, -0x38(%rbp)
jmp 0x91c52
movq -0x10(%rbp), %rdi
movq -0x30(%rbp), %rsi
movl -0x38(%rbp), %edx
callq 0x57180
movl $0x0, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x40, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)