// File: /workspace/github_c_makefile_star2_O0/coyove[P]chann/./lib/unqlite/unqlite.c
// Function: jx9Builtin_str_pad
static int jx9Builtin_str_pad(jx9_context *pCtx, int nArg, jx9_value **apArg)
{
	int iLen, iPadlen, iType, i, iDiv, iStrpad, iRealPad, jPad;
	const char *zIn, *zPad;
	if( nArg < 2 ){
		/* Missing arguments, return the empty string */
		jx9_result_string(pCtx, "", 0);
		return JX9_OK;
	}
	/* Extract the target string */
	zIn = jx9_value_to_string(apArg[0], &iLen);
	/* Padding length */
	iRealPad = iPadlen = jx9_value_to_int(apArg[1]);
	if( iPadlen > 0 ){
		iPadlen -= iLen;
	}
	if( iPadlen < 1  ){
		/* Return the string verbatim */
		jx9_result_string(pCtx, zIn, iLen);
		return JX9_OK;
	}
	zPad = " "; /* Whitespace padding */
	iStrpad = (int)sizeof(char);
	iType = 1 ; /* STR_PAD_RIGHT */
	if( nArg > 2 ){
		/* Padding string */
		zPad = jx9_value_to_string(apArg[2], &iStrpad);
		if( iStrpad < 1 ){
			/* Empty string */
			zPad = " "; /* Whitespace padding */
			iStrpad = (int)sizeof(char);
		}
		if( nArg > 3 ){
			/* Padd type */
			iType = jx9_value_to_int(apArg[3]);
			if( iType != 0 /* STR_PAD_LEFT */ && iType != 2 /* STR_PAD_BOTH */ ){
				iType = 1 ; /* STR_PAD_RIGHT */
			}
		}
	}
	iDiv = 1;
	if( iType == 2 ){
		iDiv = 2; /* STR_PAD_BOTH */
	}
	/* Perform the requested operation */
	if( iType == 0 /* STR_PAD_LEFT */ || iType == 2 /* STR_PAD_BOTH */ ){
		jPad = iStrpad;
		for( i = 0 ; i < iPadlen/iDiv ; i += jPad ){
			/* Padding */
			if( (int)jx9_context_result_buf_length(pCtx) + iLen + jPad >= iRealPad ){
				break;
			}
			jx9_result_string(pCtx, zPad, jPad);
		}
		if( iType == 0 /* STR_PAD_LEFT */ ){
			while( (int)jx9_context_result_buf_length(pCtx) + iLen < iRealPad ){
				jPad = iRealPad - (iLen + (int)jx9_context_result_buf_length(pCtx) );
				if( jPad > iStrpad ){
					jPad = iStrpad;
				}
				if( jPad < 1){
					break;
				}
				jx9_result_string(pCtx, zPad, jPad);
			}
		}
	}
	if( iLen > 0 ){
		/* Append the input string */
		jx9_result_string(pCtx, zIn, iLen);
	}
	if( iType == 1 /* STR_PAD_RIGHT */ || iType == 2 /* STR_PAD_BOTH */ ){
		for( i = 0 ; i < iPadlen/iDiv ; i += iStrpad ){
			/* Padding */
			if( (int)jx9_context_result_buf_length(pCtx) + iStrpad >= iRealPad ){
				break;
			}
			jx9_result_string(pCtx, zPad, iStrpad);
		}
		while( (int)jx9_context_result_buf_length(pCtx) < iRealPad ){
			jPad = iRealPad - (int)jx9_context_result_buf_length(pCtx);
			if( jPad > iStrpad ){
				jPad = iStrpad;
			}
			if( jPad < 1){
				break;
			}
			jx9_result_string(pCtx, zPad, jPad);
		}
	}
	return JX9_OK;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x70, %rsp
movq %rdi, -0x10(%rbp)
movl %esi, -0x14(%rbp)
movq %rdx, -0x20(%rbp)
cmpl $0x2, -0x14(%rbp)
jge 0x961e7
movq -0x10(%rbp), %rdi
leaq 0x2f977(%rip), %rsi     # 0xc5b4b
xorl %edx, %edx
callq 0x57180
movl $0x0, -0x4(%rbp)
jmp 0x96466
movq -0x20(%rbp), %rax
movq (%rax), %rdi
leaq -0x24(%rbp), %rsi
callq 0x56e20
movq %rax, -0x48(%rbp)
movq -0x20(%rbp), %rax
movq 0x8(%rax), %rdi
callq 0x56c90
movl %eax, -0x28(%rbp)
movl %eax, -0x3c(%rbp)
cmpl $0x0, -0x28(%rbp)
jle 0x9621f
movl -0x24(%rbp), %ecx
movl -0x28(%rbp), %eax
subl %ecx, %eax
movl %eax, -0x28(%rbp)
cmpl $0x1, -0x28(%rbp)
jge 0x96241
movq -0x10(%rbp), %rdi
movq -0x48(%rbp), %rsi
movl -0x24(%rbp), %edx
callq 0x57180
movl $0x0, -0x4(%rbp)
jmp 0x96466
leaq 0x2fdb2(%rip), %rax     # 0xc5ffa
movq %rax, -0x50(%rbp)
movl $0x1, -0x38(%rbp)
movl $0x1, -0x2c(%rbp)
cmpl $0x2, -0x14(%rbp)
jle 0x962ba
movq -0x20(%rbp), %rax
movq 0x10(%rax), %rdi
leaq -0x38(%rbp), %rsi
callq 0x56e20
movq %rax, -0x50(%rbp)
cmpl $0x1, -0x38(%rbp)
jge 0x9628d
leaq 0x2fd78(%rip), %rax     # 0xc5ffa
movq %rax, -0x50(%rbp)
movl $0x1, -0x38(%rbp)
cmpl $0x3, -0x14(%rbp)
jle 0x962b8
movq -0x20(%rbp), %rax
movq 0x18(%rax), %rdi
callq 0x56c90
movl %eax, -0x2c(%rbp)
cmpl $0x0, -0x2c(%rbp)
je 0x962b6
cmpl $0x2, -0x2c(%rbp)
je 0x962b6
movl $0x1, -0x2c(%rbp)
jmp 0x962b8
jmp 0x962ba
movl $0x1, -0x34(%rbp)
cmpl $0x2, -0x2c(%rbp)
jne 0x962ce
movl $0x2, -0x34(%rbp)
cmpl $0x0, -0x2c(%rbp)
je 0x962de
cmpl $0x2, -0x2c(%rbp)
jne 0x9639b
movl -0x38(%rbp), %eax
movl %eax, -0x40(%rbp)
movl $0x0, -0x30(%rbp)
movl -0x30(%rbp), %eax
movl %eax, -0x54(%rbp)
movl -0x28(%rbp), %eax
cltd
idivl -0x34(%rbp)
movl %eax, %ecx
movl -0x54(%rbp), %eax
cmpl %ecx, %eax
jge 0x96332
movq -0x10(%rbp), %rdi
callq 0x58490
addl -0x24(%rbp), %eax
addl -0x40(%rbp), %eax
cmpl -0x3c(%rbp), %eax
jl 0x96317
jmp 0x96332
movq -0x10(%rbp), %rdi
movq -0x50(%rbp), %rsi
movl -0x40(%rbp), %edx
callq 0x57180
movl -0x40(%rbp), %eax
addl -0x30(%rbp), %eax
movl %eax, -0x30(%rbp)
jmp 0x962eb
cmpl $0x0, -0x2c(%rbp)
jne 0x96399
jmp 0x9633a
movq -0x10(%rbp), %rdi
callq 0x58490
addl -0x24(%rbp), %eax
cmpl -0x3c(%rbp), %eax
jge 0x96397
movl -0x3c(%rbp), %eax
movl %eax, -0x58(%rbp)
movl -0x24(%rbp), %eax
movl %eax, -0x5c(%rbp)
movq -0x10(%rbp), %rdi
callq 0x58490
movl -0x5c(%rbp), %ecx
movl %eax, %edx
movl -0x58(%rbp), %eax
addl %edx, %ecx
subl %ecx, %eax
movl %eax, -0x40(%rbp)
movl -0x40(%rbp), %eax
cmpl -0x38(%rbp), %eax
jle 0x9637d
movl -0x38(%rbp), %eax
movl %eax, -0x40(%rbp)
cmpl $0x1, -0x40(%rbp)
jge 0x96385
jmp 0x96397
movq -0x10(%rbp), %rdi
movq -0x50(%rbp), %rsi
movl -0x40(%rbp), %edx
callq 0x57180
jmp 0x9633a
jmp 0x96399
jmp 0x9639b
cmpl $0x0, -0x24(%rbp)
jle 0x963b1
movq -0x10(%rbp), %rdi
movq -0x48(%rbp), %rsi
movl -0x24(%rbp), %edx
callq 0x57180
cmpl $0x1, -0x2c(%rbp)
je 0x963c1
cmpl $0x2, -0x2c(%rbp)
jne 0x9645f
movl $0x0, -0x30(%rbp)
movl -0x30(%rbp), %eax
movl %eax, -0x60(%rbp)
movl -0x28(%rbp), %eax
cltd
idivl -0x34(%rbp)
movl %eax, %ecx
movl -0x60(%rbp), %eax
cmpl %ecx, %eax
jge 0x9640c
movq -0x10(%rbp), %rdi
callq 0x58490
addl -0x38(%rbp), %eax
cmpl -0x3c(%rbp), %eax
jl 0x963f1
jmp 0x9640c
movq -0x10(%rbp), %rdi
movq -0x50(%rbp), %rsi
movl -0x38(%rbp), %edx
callq 0x57180
movl -0x38(%rbp), %eax
addl -0x30(%rbp), %eax
movl %eax, -0x30(%rbp)
jmp 0x963c8
jmp 0x9640e
movq -0x10(%rbp), %rdi
callq 0x58490
cmpl -0x3c(%rbp), %eax
jge 0x9645d
movl -0x3c(%rbp), %eax
movl %eax, -0x64(%rbp)
movq -0x10(%rbp), %rdi
callq 0x58490
movl %eax, %ecx
movl -0x64(%rbp), %eax
subl %ecx, %eax
movl %eax, -0x40(%rbp)
movl -0x40(%rbp), %eax
cmpl -0x38(%rbp), %eax
jle 0x96443
movl -0x38(%rbp), %eax
movl %eax, -0x40(%rbp)
cmpl $0x1, -0x40(%rbp)
jge 0x9644b
jmp 0x9645d
movq -0x10(%rbp), %rdi
movq -0x50(%rbp), %rsi
movl -0x40(%rbp), %edx
callq 0x57180
jmp 0x9640e
jmp 0x9645f
movl $0x0, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x70, %rsp
popq %rbp
retq
nop