// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x40, %rsp
movq %rdi, -0x8(%rbp)
movl %esi, -0xc(%rbp)
movq -0x8(%rbp), %rdi
xorl %esi, %esi
subl -0xc(%rbp), %esi
subl $0x1, %esi
callq 0x15290
cmpl $0x0, %eax
jne 0x186d3
movq -0x8(%rbp), %rax
movq %rax, -0x38(%rbp)
movq -0x8(%rbp), %rdi
xorl %esi, %esi
subl -0xc(%rbp), %esi
subl $0x1, %esi
callq 0x15480
movq -0x38(%rbp), %rdi
movq %rax, %rdx
leaq 0x237c7(%rip), %rsi     # 0x3be93
movb $0x0, %al
callq 0xbfe0
movq -0x8(%rbp), %rdi
xorl %esi, %esi
subl -0xc(%rbp), %esi
subl $0x1, %esi
callq 0x11760
movq %rax, -0x18(%rbp)
movq -0x18(%rbp), %rax
cmpl $0x4, (%rax)
jne 0x187a3
movq -0x18(%rbp), %rax
cmpq $0x0, 0x30(%rax)
je 0x187a3
movq -0x8(%rbp), %rax
movl 0x144(%rax), %eax
movl %eax, -0x2c(%rbp)
movq -0x8(%rbp), %rdi
callq 0x136f0
cmpl $0x0, -0xc(%rbp)
jle 0x1872f
movq -0x8(%rbp), %rdi
movl -0xc(%rbp), %esi
addl $0x1, %esi
callq 0x166e0
movq -0x8(%rbp), %rax
movl 0x140(%rax), %ecx
subl -0xc(%rbp), %ecx
subl $0x1, %ecx
movq -0x8(%rbp), %rax
movl %ecx, 0x144(%rax)
movq -0x8(%rbp), %rdi
movq -0x18(%rbp), %rax
movq 0x20(%rax), %rsi
leaq 0x2374a(%rip), %rdx     # 0x3bea6
xorl %ecx, %ecx
callq 0x180b0
movq -0x8(%rbp), %rdi
movl -0xc(%rbp), %esi
movq -0x18(%rbp), %rax
movl 0x38(%rax), %edx
movq -0x18(%rbp), %rax
movq 0x30(%rax), %rcx
callq 0x185a0
movq -0x8(%rbp), %rax
movl 0x2190(%rax), %ecx
addl $-0x1, %ecx
movl %ecx, 0x2190(%rax)
movl -0x2c(%rbp), %ecx
movq -0x8(%rbp), %rax
movl %ecx, 0x144(%rax)
jmp 0x18888
movq -0x8(%rbp), %rdi
xorl %esi, %esi
subl -0xc(%rbp), %esi
subl $0x1, %esi
leaq 0x23082(%rip), %rdx     # 0x3b838
callq 0x4380
movq -0x8(%rbp), %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
callq 0x11730
cmpl $0x0, %eax
je 0x187e2
movq -0x8(%rbp), %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
callq 0x11760
movq %rax, -0x20(%rbp)
jmp 0x187f1
movq -0x8(%rbp), %rax
movq 0x90(%rax), %rax
movq %rax, -0x20(%rbp)
movq -0x8(%rbp), %rdi
movl $0x1, %esi
callq 0x4400
movq -0x8(%rbp), %rdi
movq -0x20(%rbp), %rdx
xorl %esi, %esi
callq 0x6bc0
movq %rax, -0x28(%rbp)
movq -0x8(%rbp), %rdi
movq -0x28(%rbp), %rsi
callq 0x4870
cmpl $0x0, -0xc(%rbp)
jle 0x18834
movq -0x8(%rbp), %rdi
movl -0xc(%rbp), %esi
addl $0x1, %esi
callq 0x166e0
movq -0x8(%rbp), %rdi
movq -0x28(%rbp), %rsi
callq 0x4870
movq -0x8(%rbp), %rdi
movl -0xc(%rbp), %esi
addl $0x3, %esi
callq 0x166e0
movq -0x8(%rbp), %rdi
movl -0xc(%rbp), %esi
callq 0x17ea0
movq -0x8(%rbp), %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
callq 0x11730
cmpl $0x0, %eax
jne 0x1887f
movq -0x8(%rbp), %rdi
movl $0x1, %esi
callq 0x4400
jmp 0x18888
movq -0x8(%rbp), %rdi
callq 0x16600
addq $0x40, %rsp
popq %rbp
retq
nop