// File: /workspace/github_c_makefile_star2_O3/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
cmpl $0x1, %esi
jg 0x57493
movq 0x8(%rdi), %rdi
leaq 0x201e3(%rip), %rsi     # 0x77672
xorl %edx, %edx
jmp 0x57503
movq %rdx, %r12
movl %esi, %r13d
movq %rdi, -0x40(%rbp)
movq (%rdx), %rdi
leaq -0x30(%rbp), %r14
movq %r14, %rsi
callq 0x30577
movq %rax, %rbx
movq 0x8(%r12), %r15
movq %r15, %rdi
callq 0x3f362
movl (%r15), %r15d
xorl %eax, %eax
testl %r15d, %r15d
movl (%r14), %edx
cmovgl %edx, %eax
movl %r15d, %ecx
subl %eax, %ecx
movl %ecx, -0x4c(%rbp)
jle 0x574f8
movq %rbx, -0x38(%rbp)
movl $0x1, -0x2c(%rbp)
movl $0x1, %r14d
cmpl $0x2, %r13d
jne 0x57519
leaq 0x2062f(%rip), %rax     # 0x77b21
movq %rax, -0x48(%rbp)
jmp 0x57567
movq -0x40(%rbp), %rax
movq 0x8(%rax), %rdi
movq %rbx, %rsi
callq 0x302f6
xorl %eax, %eax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x10(%r12), %rdi
leaq -0x2c(%rbp), %rbx
movq %rbx, %rsi
callq 0x30577
movq %rax, -0x48(%rbp)
cmpl $0x0, (%rbx)
jg 0x57545
movl $0x1, -0x2c(%rbp)
leaq 0x205e0(%rip), %rax     # 0x77b21
movq %rax, -0x48(%rbp)
cmpl $0x4, %r13d
jb 0x57567
movq 0x18(%r12), %r12
movq %r12, %rdi
callq 0x3f362
movl (%r12), %eax
testl $0xfffffffd, %eax       # imm = 0xFFFFFFFD
je 0x57604
xorl %r13d, %r13d
movq -0x38(%rbp), %rsi
movl -0x30(%rbp), %edx
movzbl %r13b, %r12d
decl %r14d
cmpl $0x2, %r14d
setb %r14b
movq -0x48(%rbp), %r13
movq -0x40(%rbp), %rbx
testl %edx, %edx
jle 0x57595
movq 0x8(%rbx), %rdi
callq 0x302f6
testb %r14b, %r14b
je 0x57508
movl %r12d, %ecx
movl -0x4c(%rbp), %r12d
shrl %cl, %r12d
testl %r12d, %r12d
jle 0x575f3
xorl %r14d, %r14d
movl -0x2c(%rbp), %edx
movq 0x8(%rbx), %rdi
movl 0x28(%rdi), %eax
addl %edx, %eax
cmpl %r15d, %eax
jge 0x575f3
movq %r13, %rsi
callq 0x302f6
movl -0x2c(%rbp), %edx
addl %edx, %r14d
cmpl %r12d, %r14d
jl 0x575b3
jmp 0x575f3
movl %r15d, %edx
subl %eax, %edx
movl -0x2c(%rbp), %eax
cmpl %eax, %edx
cmovgel %eax, %edx
testl %edx, %edx
jle 0x57508
movq %r13, %rsi
callq 0x302f6
movq 0x8(%rbx), %rdi
movl 0x28(%rdi), %eax
cmpl %r15d, %eax
jl 0x575d6
jmp 0x57508
cmpl $0x2, %eax
sete %r13b
testl $0xfffffffd, %eax       # imm = 0xFFFFFFFD
jne 0x576ba
movl %eax, -0x50(%rbp)
cmpl $0x2, %eax
sete %cl
movl -0x4c(%rbp), %eax
shrl %cl, %eax
testl %eax, %eax
je 0x5765b
movl %eax, %ebx
movl -0x2c(%rbp), %r12d
xorl %r14d, %r14d
movq -0x40(%rbp), %rax
movq 0x8(%rax), %rdi
movl 0x28(%rdi), %eax
addl %r12d, %eax
addl -0x30(%rbp), %eax
cmpl %r15d, %eax
jge 0x5765b
movq -0x48(%rbp), %rsi
movl %r12d, %edx
callq 0x302f6
addl %r12d, %r14d
cmpl %ebx, %r14d
jl 0x57631
movl -0x50(%rbp), %r14d
testl %r14d, %r14d
jne 0x5756a
movq -0x40(%rbp), %rax
movq 0x8(%rax), %rdi
movl -0x30(%rbp), %edx
movl 0x28(%rdi), %eax
addl %edx, %eax
xorl %r12d, %r12d
cmpl %r15d, %eax
jge 0x576c2
movq -0x48(%rbp), %r13
xorl %r12d, %r12d
movl %r15d, %edx
subl %eax, %edx
movl -0x2c(%rbp), %eax
cmpl %eax, %edx
cmovgel %eax, %edx
testl %edx, %edx
jle 0x576d2
movq %r13, %rsi
callq 0x302f6
movq -0x40(%rbp), %rax
movq 0x8(%rax), %rdi
movl -0x30(%rbp), %edx
movl 0x28(%rdi), %eax
addl %edx, %eax
cmpl %r15d, %eax
jl 0x57687
xorl %r14d, %r14d
jmp 0x576c9
movl %eax, %r14d
jmp 0x5756a
xorl %r14d, %r14d
movq -0x48(%rbp), %r13
movq -0x38(%rbp), %rsi
jmp 0x57584
xorl %r13d, %r13d
xorl %r14d, %r14d
jmp 0x5756a