// File: /workspace/github_c_makefile_star2_O2/ArtifexSoftware[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 0xf950
movq %rbx, %rdi
testl %eax, %eax
je 0x116d1
movl %ebp, %esi
callq 0xd49c
cmpl $0x4, (%rax)
jne 0x115f4
movq %rax, %r15
cmpq $0x0, 0x30(%rax)
je 0x115f4
movl 0x144(%rbx), %r12d
movq %rbx, %rdi
callq 0xe756
testl %r14d, %r14d
jle 0x115ae
leal 0x1(%r14), %esi
movq %rbx, %rdi
callq 0x101d4
addl 0x140(%rbx), %ebp
movl %ebp, 0x144(%rbx)
movq 0x20(%r15), %rsi
leaq 0x17236(%rip), %rdx     # 0x287fb
movq %rbx, %rdi
xorl %ecx, %ecx
callq 0x1147c
movl 0x38(%r15), %edx
movq 0x30(%r15), %rcx
movq %rbx, %rdi
movl %r14d, %esi
callq 0x114be
decl 0x2190(%rbx)
movl %r12d, 0x144(%rbx)
jmp 0x116b5
leaq 0x16ba9(%rip), %rdx     # 0x281a4
movq %rbx, %rdi
movl %ebp, %esi
callq 0x3eff
pushq $-0x1
popq %rsi
movq %rbx, %rdi
callq 0xd489
testl %eax, %eax
je 0x11624
pushq $-0x1
popq %rsi
movq %rbx, %rdi
callq 0xd49c
movq %rax, %r15
jmp 0x1162b
movq 0x90(%rbx), %r15
pushq $0x1
popq %rsi
movq %rbx, %rdi
callq 0x3f3d
movq %rbx, %rdi
xorl %esi, %esi
movq %r15, %rdx
callq 0x5d6b
movq %rax, %r15
movq %rbx, %rdi
movq %rax, %rsi
callq 0x4274
testl %r14d, %r14d
jle 0x11662
leal 0x1(%r14), %esi
movq %rbx, %rdi
callq 0x101d4
movq %rbx, %rdi
movq %r15, %rsi
callq 0x4274
leal 0x3(%r14), %esi
movq %rbx, %rdi
callq 0x101d4
movq %rbx, %rdi
movl %r14d, %esi
callq 0x110b0
pushq $-0x1
popq %rsi
movq %rbx, %rdi
callq 0xd489
testl %eax, %eax
je 0x116be
movq 0x148(%rbx), %rax
movslq 0x140(%rbx), %rcx
shlq $0x4, %rcx
movups -0x10(%rax,%rcx), %xmm0
movups %xmm0, -0x20(%rax,%rcx)
decl 0x140(%rbx)
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq
pushq $0x1
popq %rsi
movq %rbx, %rdi
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
jmp 0x3f3d
movl %ebp, %esi
callq 0xfa0c
leaq 0x17109(%rip), %rsi     # 0x287e8
movq %rbx, %rdi
movq %rax, %rdx
xorl %eax, %eax
callq 0x99a6