// File: /workspace/github_c_makefile_star2_O3/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 0x14940
movq %rbx, %rdi
testl %eax, %eax
je 0x16f89
movl %ebp, %esi
callq 0x1189f
cmpl $0x4, (%rax)
jne 0x16ded
movq %rax, %r15
cmpq $0x0, 0x30(%rax)
je 0x16ded
movl 0x144(%rbx), %r12d
movq %rbx, %rdi
callq 0x130d5
testl %r14d, %r14d
jle 0x16da7
leal 0x1(%r14), %esi
movq %rbx, %rdi
callq 0x155dd
addl 0x140(%rbx), %ebp
movl %ebp, 0x144(%rbx)
movq 0x20(%r15), %rsi
leaq 0x1ca6d(%rip), %rdx     # 0x3382b
movq %rbx, %rdi
xorl %ecx, %ecx
callq 0x16c73
movl 0x38(%r15), %edx
movq 0x30(%r15), %rcx
movq %rbx, %rdi
movl %r14d, %esi
callq 0x16cb5
decl 0x2190(%rbx)
movl %r12d, 0x144(%rbx)
jmp 0x16f69
leaq 0x1c3e0(%rip), %rdx     # 0x331d4
movq %rbx, %rdi
movl %ebp, %esi
callq 0x3fd2
movl 0x140(%rbx), %eax
leal -0x1(%rax), %ecx
testl %eax, %eax
jle 0x16e24
movq 0x148(%rbx), %rsi
movl %ecx, %edx
shlq $0x4, %rdx
cmpb $0x7, 0xf(%rsi,%rdx)
jne 0x16e4a
addq %rdx, %rsi
jmp 0x16e34
cmpb $0x7, 0x295dc(%rip)     # 0x40407
jne 0x16e4a
leaq 0x295c4(%rip), %rsi     # 0x403f8
movq %rbx, %rdi
callq 0x14fb2
movq %rax, %r15
movl 0x140(%rbx), %eax
leal -0x1(%rax), %ecx
jmp 0x16e51
movq 0x90(%rbx), %r15
movl %ecx, 0x140(%rbx)
movl 0x144(%rbx), %ecx
cmpl %ecx, %eax
jle 0x16f72
movq %rbx, %rdi
movl $0x68, %esi
callq 0xde05
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)
leaq 0x29501(%rip), %rax     # 0x403b8
movq %rax, 0x8(%r12)
movq %r15, 0x18(%r12)
movl $0x1, 0x4(%r12)
movq %rbx, %rdi
movq %r12, %rsi
callq 0x4487
testl %r14d, %r14d
jle 0x16ee6
leal 0x1(%r14), %esi
movq %rbx, %rdi
callq 0x155dd
movq %rbx, %rdi
movq %r12, %rsi
callq 0x4487
leal 0x3(%r14), %esi
movq %rbx, %rdi
callq 0x155dd
movq %rbx, %rdi
movl %r14d, %esi
callq 0x16762
movslq 0x140(%rbx), %rax
testq %rax, %rax
jle 0x16f2b
movq 0x148(%rbx), %rcx
movq %rax, %rdx
shlq $0x4, %rdx
addq %rdx, %rcx
addq $-0x10, %rcx
jmp 0x16f32
leaq 0x294c6(%rip), %rcx     # 0x403f8
cmpb $0x7, 0xf(%rcx)
jne 0x16f55
movq 0x148(%rbx), %rcx
shlq $0x4, %rax
movups -0x10(%rcx,%rax), %xmm0
movups %xmm0, -0x20(%rcx,%rax)
decl 0x140(%rbx)
jmp 0x16f69
movl %eax, %ecx
decl %ecx
movl %ecx, 0x140(%rbx)
movl 0x144(%rbx), %ecx
cmpl %ecx, %eax
jle 0x16f72
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq
movl %ecx, 0x140(%rbx)
leaq 0x1c81f(%rip), %rsi     # 0x3379e
movq %rbx, %rdi
xorl %eax, %eax
callq 0xc666
movl %ebp, %esi
callq 0x14aa8
leaq 0x1c881(%rip), %rsi     # 0x33818
movq %rbx, %rdi
movq %rax, %rdx
xorl %eax, %eax
callq 0xca10