// File: /workspace/github_c_makefile_star2_O2/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
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movq %rdi, %rbx
cmpl $0x1, %esi
jg 0x4b6a2
leaq 0x1bfb7(%rip), %rsi     # 0x67652
movq %rbx, %rdi
xorl %edx, %edx
jmp 0x4b704
movq %rdx, %r13
movl %esi, %r12d
movq (%rdx), %rdi
leaq -0x30(%rbp), %rsi
callq 0x297ed
movq %rax, %r15
movq 0x8(%r13), %rdi
callq 0x29772
movl %eax, %r14d
xorl %eax, %eax
testl %r14d, %r14d
leaq -0x30(%rbp), %rcx
movl (%rcx), %edx
cmovgl %edx, %eax
movl %r14d, %ecx
subl %eax, %ecx
movl %ecx, -0x3c(%rbp)
jle 0x4b6fe
movq %r15, -0x38(%rbp)
movl $0x1, -0x2c(%rbp)
pushq $0x1
popq %rcx
cmpl $0x2, %r12d
jne 0x4b71a
leaq 0x1c40b(%rip), %r15     # 0x67b01
xorl %eax, %eax
movq -0x38(%rbp), %rsi
jmp 0x4b764
movq %rbx, %rdi
movq %r15, %rsi
callq 0x29903
xorl %eax, %eax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x10(%r13), %rdi
leaq -0x2c(%rbp), %rsi
callq 0x297ed
movq %rax, %r15
leaq -0x2c(%rbp), %rax
cmpl $0x0, (%rax)
jg 0x4b741
movl $0x1, -0x2c(%rbp)
leaq 0x1c3c0(%rip), %r15     # 0x67b01
cmpl $0x4, %r12d
jb 0x4b75b
movq 0x18(%r13), %rdi
callq 0x29772
testl $0xfffffffd, %eax       # imm = 0xFFFFFFFD
je 0x4b7e5
xorl %eax, %eax
movq -0x38(%rbp), %rsi
pushq $0x1
popq %rcx
movl -0x30(%rbp), %edx
movzbl %al, %r12d
decl %ecx
cmpl $0x2, %ecx
setb %r13b
testl %edx, %edx
jle 0x4b780
movq %rbx, %rdi
callq 0x29903
testb %r13b, %r13b
je 0x4b709
movl %r12d, %ecx
movl -0x3c(%rbp), %r13d
shrl %cl, %r13d
xorl %r12d, %r12d
cmpl %r13d, %r12d
jge 0x4b7d4
movq 0x8(%rbx), %rax
movl -0x2c(%rbp), %edx
movl 0x28(%rax), %eax
addl %edx, %eax
cmpl %r14d, %eax
jge 0x4b7d4
movq %rbx, %rdi
movq %r15, %rsi
callq 0x29903
addl -0x2c(%rbp), %r12d
jmp 0x4b792
movl -0x2c(%rbp), %edx
cmpl %edx, %eax
cmovll %eax, %edx
testl %edx, %edx
jle 0x4b709
movq %rbx, %rdi
movq %r15, %rsi
callq 0x29903
movq 0x8(%rbx), %rcx
movl %r14d, %eax
subl 0x28(%rcx), %eax
jg 0x4b7b9
jmp 0x4b709
movl %eax, %ecx
cmpl $0x2, %eax
sete %al
testl $0xfffffffd, %ecx       # imm = 0xFFFFFFFD
jne 0x4b6f8
movl %eax, -0x40(%rbp)
movl %ecx, -0x44(%rbp)
cmpl $0x2, %ecx
sete %cl
movl -0x2c(%rbp), %r13d
movl -0x3c(%rbp), %eax
shrl %cl, %eax
movl %eax, -0x48(%rbp)
xorl %r12d, %r12d
cmpl -0x48(%rbp), %r12d
jge 0x4b83f
movq 0x8(%rbx), %rax
movl 0x28(%rax), %eax
addl %r13d, %eax
addl -0x30(%rbp), %eax
cmpl %r14d, %eax
jge 0x4b83f
movq %rbx, %rdi
movq %r15, %rsi
movl %r13d, %edx
callq 0x29903
addl %r13d, %r12d
jmp 0x4b814
movl -0x44(%rbp), %ecx
testl %ecx, %ecx
je 0x4b869
movq -0x38(%rbp), %rsi
movl -0x40(%rbp), %eax
jmp 0x4b764
movl -0x2c(%rbp), %edx
cmpl %edx, %eax
cmovll %eax, %edx
testl %edx, %edx
jle 0x4b88b
movq %rbx, %rdi
movq %r15, %rsi
callq 0x29903
movq 0x8(%rbx), %rax
movl -0x30(%rbp), %edx
movl 0x28(%rax), %ecx
addl %edx, %ecx
movl %r14d, %eax
subl %ecx, %eax
jg 0x4b852
xorl %r12d, %r12d
xorl %r13d, %r13d
movq -0x38(%rbp), %rsi
jmp 0x4b774
xorl %eax, %eax
xorl %ecx, %ecx
jmp 0x4b6f8