// File: /workspace/github_c_makefile_star2_O0/coyove[P]chann/./lib/unqlite/unqlite.c
// Function: jx9Builtin_round
static int jx9Builtin_round(jx9_context *pCtx, int nArg, jx9_value **apArg)
{
	int n = 0;
	double r;
	if( nArg < 1 ){
		/* Missing argument, return 0 */
		jx9_result_int(pCtx, 0);
		return JX9_OK;
	}
	/* Extract the precision if available */
	if( nArg > 1 ){
		n = jx9_value_to_int(apArg[1]);
		if( n>30 ){
			n = 30;
		}
		if( n<0 ){
			n = 0;
		}
	}
	r = jx9_value_to_double(apArg[0]);
	/* If Y==0 and X will fit in a 64-bit int, 
     * handle the rounding directly.Otherwise 
	 * use our own cutsom printf [i.e:SyBufferFormat()].
     */
  if( n==0 && r>=0 && r<LARGEST_INT64-1 ){
    r = (double)((jx9_int64)(r+0.5));
  }else if( n==0 && r<0 && (-r)<LARGEST_INT64-1 ){
    r = -(double)((jx9_int64)((-r)+0.5));
  }else{
	  char zBuf[256];
	  sxu32 nLen;
	  nLen = SyBufferFormat(zBuf, sizeof(zBuf), "%.*f", n, r);
	  /* Convert the string to real number */
	  SyStrToReal(zBuf, nLen, (void *)&r, 0);
  }
  /* Return thr rounded value */
  jx9_result_double(pCtx, r);
  return JX9_OK;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x140, %rsp            # imm = 0x140
movq %rdi, -0x10(%rbp)
movl %esi, -0x14(%rbp)
movq %rdx, -0x20(%rbp)
movl $0x0, -0x24(%rbp)
cmpl $0x1, -0x14(%rbp)
jge 0x9139a
movq -0x10(%rbp), %rdi
xorl %esi, %esi
callq 0x56fb0
movl $0x0, -0x4(%rbp)
jmp 0x91508
cmpl $0x1, -0x14(%rbp)
jle 0x913cc
movq -0x20(%rbp), %rax
movq 0x8(%rax), %rdi
callq 0x56c90
movl %eax, -0x24(%rbp)
cmpl $0x1e, -0x24(%rbp)
jle 0x913bd
movl $0x1e, -0x24(%rbp)
cmpl $0x0, -0x24(%rbp)
jge 0x913ca
movl $0x0, -0x24(%rbp)
jmp 0x913cc
movq -0x20(%rbp), %rax
movq (%rax), %rdi
callq 0x56db0
movsd %xmm0, -0x30(%rbp)
cmpl $0x0, -0x24(%rbp)
jne 0x91421
movsd -0x30(%rbp), %xmm0
xorps %xmm1, %xmm1
ucomisd %xmm1, %xmm0
jb 0x91421
movsd 0x3071f(%rip), %xmm0    # 0xc1b18
ucomisd -0x30(%rbp), %xmm0
jbe 0x91421
movsd 0x306e0(%rip), %xmm0    # 0xc1ae8
addsd -0x30(%rbp), %xmm0
cvttsd2si %xmm0, %rax
cvtsi2sd %rax, %xmm0
movsd %xmm0, -0x30(%rbp)
jmp 0x914f3
cmpl $0x0, -0x24(%rbp)
jne 0x914af
xorps %xmm0, %xmm0
ucomisd -0x30(%rbp), %xmm0
jbe 0x914af
movsd -0x30(%rbp), %xmm0
movq %xmm0, %rax
movabsq $-0x8000000000000000, %rcx # imm = 0x8000000000000000
xorq %rcx, %rax
movq %rax, %xmm1
movsd 0x306bf(%rip), %xmm0    # 0xc1b18
ucomisd %xmm1, %xmm0
jbe 0x914af
movsd -0x30(%rbp), %xmm0
movq %xmm0, %rax
movabsq $-0x8000000000000000, %rcx # imm = 0x8000000000000000
xorq %rcx, %rax
movq %rax, %xmm0
movsd 0x30665(%rip), %xmm1    # 0xc1ae8
addsd %xmm1, %xmm0
cvttsd2si %xmm0, %rax
cvtsi2sd %rax, %xmm0
movq %xmm0, %rax
movabsq $-0x8000000000000000, %rcx # imm = 0x8000000000000000
xorq %rcx, %rax
movq %rax, %xmm0
movsd %xmm0, -0x30(%rbp)
jmp 0x914f1
leaq -0x130(%rbp), %rdi
movl -0x24(%rbp), %ecx
movsd -0x30(%rbp), %xmm0
movl $0x100, %esi            # imm = 0x100
leaq 0x33ee4(%rip), %rdx     # 0xc53ae
movb $0x1, %al
callq 0x5d800
movl %eax, -0x134(%rbp)
leaq -0x130(%rbp), %rdi
movl -0x134(%rbp), %esi
leaq -0x30(%rbp), %rdx
xorl %eax, %eax
movl %eax, %ecx
callq 0x6f220
jmp 0x914f3
movq -0x10(%rbp), %rdi
movsd -0x30(%rbp), %xmm0
callq 0x570d0
movl $0x0, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x140, %rsp            # imm = 0x140
popq %rbp
retq
nopw %cs:(%rax,%rax)