// File: /workspace/github_c_makefile_star2_O1/ccxvii[P]mujs/./jsrun.c
// Function: js_construct
void js_construct(js_State *J, int n)
{
	js_Object *obj;
	js_Object *prototype;
	js_Object *newobj;

	if (!js_iscallable(J, -n-1))
		js_typeerror(J, "%s is not callable", js_typeof(J, -n-1));

	obj = js_toobject(J, -n-1);

	/* built-in constructors create their own objects, give them a 'null' this */
	if (obj->type == JS_CCFUNCTION && obj->u.c.constructor) {
		int savebot = BOT;
		js_pushnull(J);
		if (n > 0)
			js_rot(J, n + 1);
		BOT = TOP - n - 1;

		jsR_pushtrace(J, obj->u.c.name, "native", 0);
		jsR_callcfunction(J, n, obj->u.c.length, obj->u.c.constructor);
		--J->tracetop;

		BOT = savebot;
		return;
	}

	/* extract the function object's prototype property */
	js_getproperty(J, -n - 1, "prototype");
	if (js_isobject(J, -1))
		prototype = js_toobject(J, -1);
	else
		prototype = J->Object_prototype;
	js_pop(J, 1);

	/* create a new object with above prototype, and shift it into the 'this' slot */
	newobj = jsV_newobject(J, JS_COBJECT, prototype);
	js_pushobject(J, newobj);
	if (n > 0)
		js_rot(J, n + 1);

	/* and save a copy to return */
	js_pushobject(J, newobj);
	js_rot(J, n + 3);

	/* call the function */
	js_call(J, n);

	/* if result is not an object, return the original object we created */
	if (!js_isobject(J, -1)) {
		js_pop(J, 1);
	} else {
		js_rot2pop1(J);
	}
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
movl %esi, %r14d
movq %rdi, %rbx
movl %esi, %ebp
notl %ebp
movl %ebp, %esi
callq 0x14e17
movq %rbx, %rdi
testl %eax, %eax
je 0x17473
movl %ebp, %esi
callq 0x11c37
cmpl $0x4, (%rax)
jne 0x172dc
movq %rax, %r15
cmpq $0x0, 0x30(%rax)
je 0x172dc
movl 0x144(%rbx), %r12d
movq %rbx, %rdi
callq 0x13525
testl %r14d, %r14d
jle 0x17296
leal 0x1(%r14), %esi
movq %rbx, %rdi
callq 0x15abb
addl 0x140(%rbx), %ebp
movl %ebp, 0x144(%rbx)
movq 0x20(%r15), %rsi
leaq 0x1c54e(%rip), %rdx     # 0x337fb
movq %rbx, %rdi
xorl %ecx, %ecx
callq 0x17162
movl 0x38(%r15), %edx
movq 0x30(%r15), %rcx
movq %rbx, %rdi
movl %r14d, %esi
callq 0x171a4
decl 0x2190(%rbx)
movl %r12d, 0x144(%rbx)
jmp 0x1746a
leaq 0x1bec1(%rip), %rdx     # 0x331a4
movq %rbx, %rdi
movl %ebp, %esi
callq 0x4032
movl 0x140(%rbx), %ecx
leal -0x1(%rcx), %eax
testl %ecx, %ecx
jle 0x17309
movl %eax, %edx
shlq $0x4, %rdx
addq 0x148(%rbx), %rdx
jmp 0x17310
leaq 0x290e8(%rip), %rdx     # 0x403f8
cmpb $0x7, 0xf(%rdx)
jne 0x17329
testl %ecx, %ecx
jle 0x17332
movl %eax, %esi
shlq $0x4, %rsi
addq 0x148(%rbx), %rsi
jmp 0x17339
movq 0x90(%rbx), %r15
jmp 0x17344
leaq 0x290bf(%rip), %rsi     # 0x403f8
movq %rbx, %rdi
callq 0x15489
movq %rax, %r15
movl 0x140(%rbx), %ecx
movl 0x144(%rbx), %eax
leal -0x1(%rcx), %edx
movl %edx, 0x140(%rbx)
cmpl %eax, %ecx
jle 0x1748e
movq %rbx, %rdi
movl $0x68, %esi
callq 0xe119
movq %rax, %r12
xorps %xmm0, %xmm0
movups %xmm0, (%rax)
movups %xmm0, 0x10(%rax)
movups %xmm0, 0x20(%rax)
movups %xmm0, 0x30(%rax)
movups %xmm0, 0x40(%rax)
movups %xmm0, 0x50(%rax)
movq $0x0, 0x60(%rax)
movq 0x170(%rbx), %rax
movq %rax, 0x50(%r12)
movq %r12, 0x170(%rbx)
incl 0x154(%rbx)
movabsq $0x100000000, %rax      # imm = 0x100000000
movq %rax, (%r12)
leaq 0x28ff7(%rip), %rax     # 0x403b8
movq %rax, 0x8(%r12)
movq %r15, 0x18(%r12)
movq %rbx, %rdi
movq %r12, %rsi
callq 0x44e7
testl %r14d, %r14d
jle 0x173e7
leal 0x1(%r14), %esi
movq %rbx, %rdi
callq 0x15abb
movq %rbx, %rdi
movq %r12, %rsi
callq 0x44e7
leal 0x3(%r14), %esi
movq %rbx, %rdi
callq 0x15abb
movq %rbx, %rdi
movl %r14d, %esi
callq 0x16c25
movslq 0x140(%rbx), %rax
testq %rax, %rax
jle 0x1742c
movq 0x148(%rbx), %rcx
movq %rax, %rdx
shlq $0x4, %rdx
addq %rdx, %rcx
addq $-0x10, %rcx
jmp 0x17433
leaq 0x28fc5(%rip), %rcx     # 0x403f8
cmpb $0x7, 0xf(%rcx)
jne 0x17456
movq 0x148(%rbx), %rcx
shlq $0x4, %rax
movups -0x10(%rcx,%rax), %xmm0
movups %xmm0, -0x20(%rcx,%rax)
decl 0x140(%rbx)
jmp 0x1746a
movl %eax, %ecx
decl %ecx
movl %ecx, 0x140(%rbx)
movl 0x144(%rbx), %ecx
cmpl %ecx, %eax
jle 0x17496
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq
movl %ebp, %esi
callq 0x14f7f
leaq 0x1c367(%rip), %rsi     # 0x337e8
movq %rbx, %rdi
movq %rax, %rdx
xorl %eax, %eax
callq 0xcce3
movl %eax, 0x140(%rbx)
jmp 0x1749c
movl %ecx, 0x140(%rbx)
leaq 0x1c2cb(%rip), %rsi     # 0x3376e
movq %rbx, %rdi
xorl %eax, %eax
callq 0xc939