// File: /workspace/github_c_makefile_star2_O1/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 0x58cbd
movq 0x8(%rbx), %rdi
leaq 0x209ae(%rip), %rsi     # 0x79667
xorl %edx, %edx
jmp 0x58d20
movq %rdx, %r12
movl %esi, %r13d
movq (%rdx), %rdi
leaq -0x30(%rbp), %rsi
callq 0x30b04
movq %rax, %r14
movq 0x8(%r12), %r15
movq %r15, %rdi
callq 0x3fd5f
movl (%r15), %r15d
xorl %eax, %eax
testl %r15d, %r15d
leaq -0x30(%rbp), %rcx
movl (%rcx), %edx
cmovgl %edx, %eax
movl %r15d, %ecx
subl %eax, %ecx
movl %ecx, -0x34(%rbp)
jle 0x58d19
movq %r14, -0x48(%rbp)
movl $0x1, -0x2c(%rbp)
movl $0x1, %ecx
cmpl $0x2, %r13d
jne 0x58d36
leaq 0x20dff(%rip), %r12     # 0x79b16
jmp 0x58d94
movq 0x8(%rbx), %rdi
movq %r14, %rsi
callq 0x3087c
xorl %eax, %eax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rbx, -0x40(%rbp)
movq 0x10(%r12), %rdi
leaq -0x2c(%rbp), %r14
movq %r14, %rsi
callq 0x30b04
cmpl $0x0, (%r14)
jle 0x58d56
movq %rax, %rbx
jmp 0x58d64
movl $0x1, -0x2c(%rbp)
leaq 0x20db2(%rip), %rbx     # 0x79b16
cmpl $0x4, %r13d
movl $0x1, %ecx
jl 0x58d8d
movq 0x18(%r12), %r12
movq %r12, %rdi
callq 0x3fd5f
movl (%r12), %eax
testl $0xfffffffd, %eax       # imm = 0xFFFFFFFD
movl $0x1, %ecx
cmovel %eax, %ecx
movq %rbx, %r12
movq -0x40(%rbp), %rbx
movl -0x34(%rbp), %r13d
movq -0x48(%rbp), %r14
movq %rcx, -0x50(%rbp)
testl $0xfffffffd, %ecx       # imm = 0xFFFFFFFD
jne 0x58e24
movq %r12, -0x40(%rbp)
cmpl $0x2, -0x50(%rbp)
sete %cl
shrl %cl, %r13d
testl %r13d, %r13d
jle 0x58de8
movl -0x2c(%rbp), %r12d
xorl %r14d, %r14d
movq 0x8(%rbx), %rdi
movl 0x28(%rdi), %eax
addl %r12d, %eax
addl -0x30(%rbp), %eax
cmpl %r15d, %eax
jge 0x58de8
movq -0x40(%rbp), %rsi
movl %r12d, %edx
callq 0x3087c
addl %r12d, %r14d
cmpl %r13d, %r14d
jl 0x58dc2
cmpl $0x0, -0x50(%rbp)
movq -0x40(%rbp), %r12
movl -0x34(%rbp), %r13d
movq -0x48(%rbp), %r14
jne 0x58e24
jmp 0x58e15
movl %r15d, %edx
subl %eax, %edx
movl -0x2c(%rbp), %eax
cmpl %eax, %edx
cmovgel %eax, %edx
testl %edx, %edx
jle 0x58e24
movq %r12, %rsi
callq 0x3087c
movq 0x8(%rbx), %rdi
movl -0x30(%rbp), %eax
addl 0x28(%rdi), %eax
cmpl %r15d, %eax
jl 0x58dfc
movl -0x30(%rbp), %edx
testl %edx, %edx
jle 0x58e37
movq 0x8(%rbx), %rdi
movq %r14, %rsi
callq 0x3087c
movq -0x50(%rbp), %rcx
leal -0x1(%rcx), %eax
cmpl $0x1, %eax
ja 0x58d25
cmpl $0x2, %ecx
sete %cl
shrl %cl, %r13d
testl %r13d, %r13d
jle 0x58e99
xorl %r14d, %r14d
movq 0x8(%rbx), %rdi
movl -0x2c(%rbp), %edx
movl 0x28(%rdi), %eax
addl %edx, %eax
cmpl %r15d, %eax
jge 0x58e99
movq %r12, %rsi
callq 0x3087c
addl -0x2c(%rbp), %r14d
cmpl %r13d, %r14d
jl 0x58e58
jmp 0x58e99
movl %r15d, %edx
subl %eax, %edx
movl -0x2c(%rbp), %eax
cmpl %eax, %edx
cmovgel %eax, %edx
testl %edx, %edx
jle 0x58d25
movq %r12, %rsi
callq 0x3087c
movq 0x8(%rbx), %rdi
movl 0x28(%rdi), %eax
cmpl %r15d, %eax
jl 0x58e7c
jmp 0x58d25