// File: menhits[P]phplus/src/PhplusStdLib.cpp
// Function: populateIntArrayAndFuncs()
void populateIntArrayAndFuncs()
{
	TupleTypeMaker maker;
	maker.add("_size", Int);
	maker.add("_data", Int->getPtr());
	IntArray=maker.get(false);
	
	addType(IntArray, "IntArray");
	
	//func("IntArray", IntArray, Void, Int,
	//	retrn Tuple(right, (double)((int*)malloc(Int->getSize()*right)));
	//);
	
	addAction("IntArray", Void, Int, IntArray, LAMBDA_HEADER
		{
			char* out=(char*)malloc(IntArray->getSize());
			int sizeIn=*(int*)rightIn;
			int* intPtrData=(int *)malloc(Int->getSize()*sizeIn);
			setValInTuple<int>(out, IntArray, "_size", sizeIn);
			setValInTuple<int *>(out, IntArray, "_data", intPtrData);
			return out;
		},
		ADD_CPP_HEADER
		{
			addToProgMakeIntArray(prog);
			prog->name("$makeIntArray");
			prog->pushExpr();
				right->addToProg(prog);
			prog->popExpr();
		}
	);
	
	addAction("len", IntArray, Void, Int,
		LAMBDA_HEADER
		{
			int* out=(int*)malloc(sizeof(int));
			*out=getValFromTuple<int>(leftIn, IntArray, "_size");
			return out;
		},
		ADD_CPP_HEADER
		{
			getElemFromTupleAction(IntArray, "_size")->addToProg(left, voidAction, prog);
		}
	);
	
	addAction("get", IntArray, Int, Int, LAMBDA_HEADER
		{
			int pos=*(int*)rightIn;
			int size=getValFromTuple<int>(leftIn, IntArray, "_size");
			if (pos<0 || pos>=size)
				throw PhplusError("tried to acces position "+to_string(pos)+" of array "+to_string(size)+" long", RUNTIME_ERROR);
			int* arrayPtr=getValFromTuple<int*>(leftIn, IntArray, "_data");
			int val=*(arrayPtr+pos);
			int* out=(int*)malloc(sizeof(int));
			*out=val;
			return out;
		},
		ADD_CPP_HEADER
		{
			getElemFromTupleAction(IntArray, "_data")->addToProg(left, voidAction, prog);
			prog->code("[");
			prog->pushExpr();
				right->addToProg(prog);
			prog->popExpr();
			prog->code("]");
		}
	);
	
	addAction("set", IntArray, PNCN_Tuple(Int, Int), Void,
		LAMBDA_HEADER
		{
			Type rightType=PNCN_Tuple(Int, Int);
			int pos=getValFromTuple<int>(rightIn, rightType, "a");
			int size=getValFromTuple<int>(leftIn, IntArray, "_size");
			if (pos<0 || pos>=size)
				throw PhplusError("tried to set value at position "+to_string(pos)+" of array "+to_string(size)+" long", RUNTIME_ERROR);
			int val=getValFromTuple<int>(rightIn, rightType, "b");
			int* arrayPtr=getValFromTuple<int*>(leftIn, IntArray, "_data");
			*(arrayPtr+pos)=val;
			return nullptr;
		},
		ADD_CPP_HEADER
		{
			getElemFromTupleAction(IntArray, "_data")->addToProg(left, voidAction, prog);
			prog->code("[");
			prog->pushExpr();
				getElemFromTupleAction(right->getReturnType(), "a")->addToProg(right, voidAction, prog);
			prog->popExpr();
			prog->code("]");
			prog->code(" = ");
			getElemFromTupleAction(right->getReturnType(), "b")->addToProg(right, voidAction, prog);
		}
	);
}

// Assembly:
subq $0x498, %rsp            # imm = 0x498
leaq 0x490(%rsp), %rdi
callq 0x9f900
leaq 0x46f(%rsp), %rdi
movq %rdi, 0x128(%rsp)
callq 0xb690
movq 0x128(%rsp), %rdx
leaq 0x723e9(%rip), %rsi     # 0xd5371
leaq 0x470(%rsp), %rdi
callq 0xb4c0
jmp 0x62f97
leaq 0xb554a(%rip), %rsi     # 0x1184e8
leaq 0x448(%rsp), %rdi
movq %rdi, 0x120(%rsp)
callq 0x1a920
movq 0x120(%rsp), %rdx
leaq 0x490(%rsp), %rdi
leaq 0x470(%rsp), %rsi
callq 0x9f990
jmp 0x62fd2
leaq 0x448(%rsp), %rdi
callq 0x1a950
leaq 0x470(%rsp), %rdi
callq 0xb6e8
leaq 0x46f(%rsp), %rdi
callq 0xb3f0
leaq 0x427(%rsp), %rdi
movq %rdi, 0x118(%rsp)
callq 0xb690
movq 0x118(%rsp), %rdx
leaq 0x726ef(%rip), %rsi     # 0xd570c
leaq 0x428(%rsp), %rdi
callq 0xb4c0
jmp 0x6302c
leaq 0xb54b5(%rip), %rdi     # 0x1184e8
callq 0x1a660
movq %rax, %rsi
leaq 0x410(%rsp), %rdi
callq 0x9ed40
jmp 0x6304a
leaq 0x490(%rsp), %rdi
leaq 0x428(%rsp), %rsi
leaq 0x410(%rsp), %rdx
callq 0x9f990
jmp 0x63069
leaq 0x410(%rsp), %rdi
callq 0x1a950
leaq 0x428(%rsp), %rdi
callq 0xb6e8
leaq 0x427(%rsp), %rdi
callq 0xb3f0
leaq 0x400(%rsp), %rdi
leaq 0x490(%rsp), %rsi
xorl %edx, %edx
callq 0xa0070
jmp 0x630a9
leaq 0xb5398(%rip), %rdi     # 0x118448
movq %rdi, 0x108(%rsp)
leaq 0x400(%rsp), %rsi
movq %rsi, 0x100(%rsp)
callq 0x1bae0
movq 0x100(%rsp), %rdi
callq 0x1a950
movq 0x108(%rsp), %rsi
leaq 0x3f0(%rsp), %rdi
callq 0x1a920
leaq 0x3cf(%rsp), %rdi
movq %rdi, 0x110(%rsp)
callq 0xb690
movq 0x110(%rsp), %rdx
leaq 0x7221d(%rip), %rsi     # 0xd5330
leaq 0x3d0(%rsp), %rdi
callq 0xb4c0
jmp 0x63122
leaq 0x3f0(%rsp), %rdi
leaq 0x3d0(%rsp), %rsi
callq 0x4e8b0
jmp 0x63139
leaq 0x3d0(%rsp), %rdi
callq 0xb6e8
leaq 0x3cf(%rsp), %rdi
callq 0xb3f0
leaq 0x3f0(%rsp), %rdi
callq 0x1a950
leaq 0xb5341(%rip), %rsi     # 0x1184a8
leaq 0x3b8(%rsp), %rdi
movq %rdi, 0xd8(%rsp)
callq 0x1a920
leaq 0xb5365(%rip), %rsi     # 0x1184e8
leaq 0x3a8(%rsp), %rdi
movq %rdi, 0xe0(%rsp)
callq 0x1a920
leaq 0xb52a9(%rip), %rsi     # 0x118448
leaq 0x398(%rsp), %rdi
movq %rdi, 0xe8(%rsp)
callq 0x1a920
leaq 0x378(%rsp), %rdi
movq %rdi, 0xf0(%rsp)
leaq 0x377(%rsp), %rsi
callq 0x63ad0
leaq 0x350(%rsp), %rdi
movq %rdi, 0xf8(%rsp)
leaq 0x34f(%rsp), %rsi
callq 0x63b60
movq 0xd8(%rsp), %rsi
movq 0xe0(%rsp), %rdx
movq 0xe8(%rsp), %rcx
movq 0xf0(%rsp), %r8
movq 0xf8(%rsp), %r9
leaq 0x72113(%rip), %rdi     # 0xd5330
callq 0x96b70
jmp 0x63224
leaq 0x350(%rsp), %rdi
callq 0x95bf0
leaq 0x378(%rsp), %rdi
callq 0x95c00
leaq 0x398(%rsp), %rdi
callq 0x1a950
leaq 0x3a8(%rsp), %rdi
callq 0x1a950
leaq 0x3b8(%rsp), %rdi
callq 0x1a950
leaq 0xb51dc(%rip), %rsi     # 0x118448
leaq 0x338(%rsp), %rdi
movq %rdi, 0xb0(%rsp)
callq 0x1a920
leaq 0xb5220(%rip), %rsi     # 0x1184a8
leaq 0x328(%rsp), %rdi
movq %rdi, 0xb8(%rsp)
callq 0x1a920
leaq 0xb5244(%rip), %rsi     # 0x1184e8
leaq 0x318(%rsp), %rdi
movq %rdi, 0xc0(%rsp)
callq 0x1a920
leaq 0x2f8(%rsp), %rdi
movq %rdi, 0xc8(%rsp)
leaq 0x2f7(%rsp), %rsi
callq 0x63bf0
leaq 0x2d0(%rsp), %rdi
movq %rdi, 0xd0(%rsp)
leaq 0x2cf(%rsp), %rsi
callq 0x63c80
movq 0xb0(%rsp), %rsi
movq 0xb8(%rsp), %rdx
movq 0xc0(%rsp), %rcx
movq 0xc8(%rsp), %r8
movq 0xd0(%rsp), %r9
leaq 0x7227b(%rip), %rdi     # 0xd559d
callq 0x96b70
jmp 0x63329
leaq 0x2d0(%rsp), %rdi
callq 0x95bf0
leaq 0x2f8(%rsp), %rdi
callq 0x95c00
leaq 0x318(%rsp), %rdi
callq 0x1a950
leaq 0x328(%rsp), %rdi
callq 0x1a950
leaq 0x338(%rsp), %rdi
callq 0x1a950
leaq 0xb50d7(%rip), %rsi     # 0x118448
leaq 0x2b8(%rsp), %rdi
movq %rdi, 0x88(%rsp)
callq 0x1a920
leaq 0xb515b(%rip), %rsi     # 0x1184e8
movq %rsi, 0x80(%rsp)
leaq 0x2a8(%rsp), %rdi
movq %rdi, 0x90(%rsp)
callq 0x1a920
movq 0x80(%rsp), %rsi
leaq 0x298(%rsp), %rdi
movq %rdi, 0x98(%rsp)
callq 0x1a920
leaq 0x278(%rsp), %rdi
movq %rdi, 0xa0(%rsp)
leaq 0x277(%rsp), %rsi
callq 0x63d10
leaq 0x250(%rsp), %rdi
movq %rdi, 0xa8(%rsp)
leaq 0x24f(%rsp), %rsi
callq 0x63da0
movq 0x88(%rsp), %rsi
movq 0x90(%rsp), %rdx
movq 0x98(%rsp), %rcx
movq 0xa0(%rsp), %r8
movq 0xa8(%rsp), %r9
leaq 0x72188(%rip), %rdi     # 0xd55b8
callq 0x96b70
jmp 0x63437
leaq 0x250(%rsp), %rdi
callq 0x95bf0
leaq 0x278(%rsp), %rdi
callq 0x95c00
leaq 0x298(%rsp), %rdi
callq 0x1a950
leaq 0x2a8(%rsp), %rdi
callq 0x1a950
leaq 0x2b8(%rsp), %rdi
callq 0x1a950
leaq 0xb4fc9(%rip), %rsi     # 0x118448
leaq 0x238(%rsp), %rdi
callq 0x1a920
movb $0x1, 0x195(%rsp)
leaq 0x1a0(%rsp), %rax
movq %rax, 0x70(%rsp)
movq %rax, 0x198(%rsp)
leaq 0x197(%rsp), %rdi
movq %rdi, 0x78(%rsp)
callq 0xb690
movq 0x70(%rsp), %rdi
movq 0x78(%rsp), %rdx
leaq 0x72244(%rip), %rsi     # 0xd5710
callq 0xb4c0
jmp 0x634d3
leaq 0x1c0(%rsp), %rdi
leaq 0xb5006(%rip), %rsi     # 0x1184e8
callq 0x1a920
leaq 0x1d0(%rsp), %rax
movq %rax, 0x60(%rsp)
movq %rax, 0x198(%rsp)
leaq 0x196(%rsp), %rdi
movq %rdi, 0x68(%rsp)
callq 0xb690
movq 0x60(%rsp), %rdi
movq 0x68(%rsp), %rdx
leaq 0x71788(%rip), %rsi     # 0xd4ca7
callq 0xb4c0
jmp 0x63526
movq 0x60(%rsp), %rdi
addq $0x20, %rdi
leaq 0xb4fb2(%rip), %rsi     # 0x1184e8
callq 0x1a920
movb $0x0, 0x195(%rsp)
leaq 0x1a0(%rsp), %rax
movq %rax, 0x200(%rsp)
movq $0x2, 0x208(%rsp)
leaq 0x194(%rsp), %rdi
movq %rdi, 0x58(%rsp)
callq 0x967d0
movq 0x58(%rsp), %rcx
movq 0x200(%rsp), %rsi
movq 0x208(%rsp), %rdx
leaq 0x210(%rsp), %rdi
callq 0x967e0
jmp 0x63595
leaq 0x228(%rsp), %rdi
leaq 0x210(%rsp), %rsi
movl $0x1, %edx
callq 0x9f7c0
jmp 0x635b1
leaq 0xb4ef0(%rip), %rsi     # 0x1184a8
leaq 0x180(%rsp), %rdi
movq %rdi, 0x40(%rsp)
callq 0x1a920
leaq 0x160(%rsp), %rdi
movq %rdi, 0x48(%rsp)
leaq 0x15f(%rsp), %rsi
callq 0x63e30
leaq 0x138(%rsp), %rdi
movq %rdi, 0x50(%rsp)
leaq 0x137(%rsp), %rsi
callq 0x63ec0
movq 0x40(%rsp), %rcx
movq 0x48(%rsp), %r8
movq 0x50(%rsp), %r9
leaq 0x6dfa4(%rip), %rdi     # 0xd15b8
leaq 0x238(%rsp), %rsi
leaq 0x228(%rsp), %rdx
callq 0x96b70
jmp 0x6362b
leaq 0x138(%rsp), %rdi
callq 0x95bf0
leaq 0x160(%rsp), %rdi
callq 0x95c00
leaq 0x180(%rsp), %rdi
callq 0x1a950
leaq 0x228(%rsp), %rdi
callq 0x1a950
leaq 0x210(%rsp), %rdi
callq 0x1e810
leaq 0x194(%rsp), %rdi
callq 0x1ea60
leaq 0x1a0(%rsp), %rax
movq %rax, 0x30(%rsp)
addq $0x60, %rax
movq %rax, 0x38(%rsp)
movq 0x38(%rsp), %rdi
addq $-0x30, %rdi
movq %rdi, 0x28(%rsp)
callq 0x1e980
movq 0x30(%rsp), %rcx
movq 0x28(%rsp), %rax
cmpq %rcx, %rax
movq %rax, 0x38(%rsp)
jne 0x6368f
leaq 0x196(%rsp), %rdi
callq 0xb3f0
leaq 0x197(%rsp), %rdi
callq 0xb3f0
leaq 0x238(%rsp), %rdi
callq 0x1a950
leaq 0x490(%rsp), %rdi
callq 0x1c080
addq $0x498, %rsp            # imm = 0x498
retq
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x460(%rsp)
movl %eax, 0x45c(%rsp)
jmp 0x63736
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x460(%rsp)
movl %eax, 0x45c(%rsp)
leaq 0x448(%rsp), %rdi
callq 0x1a950
leaq 0x470(%rsp), %rdi
callq 0xb6e8
leaq 0x46f(%rsp), %rdi
callq 0xb3f0
jmp 0x63aa7
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x460(%rsp)
movl %eax, 0x45c(%rsp)
jmp 0x637a2
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x460(%rsp)
movl %eax, 0x45c(%rsp)
jmp 0x63795
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x460(%rsp)
movl %eax, 0x45c(%rsp)
leaq 0x410(%rsp), %rdi
callq 0x1a950
leaq 0x428(%rsp), %rdi
callq 0xb6e8
leaq 0x427(%rsp), %rdi
callq 0xb3f0
jmp 0x63aa7
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x460(%rsp)
movl %eax, 0x45c(%rsp)
jmp 0x63aa7
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x460(%rsp)
movl %eax, 0x45c(%rsp)
jmp 0x63804
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x460(%rsp)
movl %eax, 0x45c(%rsp)
leaq 0x3d0(%rsp), %rdi
callq 0xb6e8
leaq 0x3cf(%rsp), %rdi
callq 0xb3f0
leaq 0x3f0(%rsp), %rdi
callq 0x1a950
jmp 0x63aa7
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x460(%rsp)
movl %eax, 0x45c(%rsp)
leaq 0x350(%rsp), %rdi
callq 0x95bf0
leaq 0x378(%rsp), %rdi
callq 0x95c00
leaq 0x398(%rsp), %rdi
callq 0x1a950
leaq 0x3a8(%rsp), %rdi
callq 0x1a950
leaq 0x3b8(%rsp), %rdi
callq 0x1a950
jmp 0x63aa7
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x460(%rsp)
movl %eax, 0x45c(%rsp)
leaq 0x2d0(%rsp), %rdi
callq 0x95bf0
leaq 0x2f8(%rsp), %rdi
callq 0x95c00
leaq 0x318(%rsp), %rdi
callq 0x1a950
leaq 0x328(%rsp), %rdi
callq 0x1a950
leaq 0x338(%rsp), %rdi
callq 0x1a950
jmp 0x63aa7
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x460(%rsp)
movl %eax, 0x45c(%rsp)
leaq 0x250(%rsp), %rdi
callq 0x95bf0
leaq 0x278(%rsp), %rdi
callq 0x95c00
leaq 0x298(%rsp), %rdi
callq 0x1a950
leaq 0x2a8(%rsp), %rdi
callq 0x1a950
leaq 0x2b8(%rsp), %rdi
callq 0x1a950
jmp 0x63aa7
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x460(%rsp)
movl %eax, 0x45c(%rsp)
jmp 0x63a3d
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x460(%rsp)
movl %eax, 0x45c(%rsp)
jmp 0x63a30
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x460(%rsp)
movl %eax, 0x45c(%rsp)
jmp 0x639e4
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x460(%rsp)
movl %eax, 0x45c(%rsp)
jmp 0x639d7
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x460(%rsp)
movl %eax, 0x45c(%rsp)
leaq 0x138(%rsp), %rdi
callq 0x95bf0
leaq 0x160(%rsp), %rdi
callq 0x95c00
leaq 0x180(%rsp), %rdi
callq 0x1a950
leaq 0x228(%rsp), %rdi
callq 0x1a950
leaq 0x210(%rsp), %rdi
callq 0x1e810
leaq 0x194(%rsp), %rdi
callq 0x1ea60
leaq 0x1a0(%rsp), %rax
movq %rax, 0x18(%rsp)
addq $0x60, %rax
movq %rax, 0x20(%rsp)
movq 0x20(%rsp), %rdi
addq $-0x30, %rdi
movq %rdi, 0x10(%rsp)
callq 0x1e980
movq 0x18(%rsp), %rcx
movq 0x10(%rsp), %rax
cmpq %rcx, %rax
movq %rax, 0x20(%rsp)
jne 0x63a07
jmp 0x63a30
leaq 0x196(%rsp), %rdi
callq 0xb3f0
leaq 0x197(%rsp), %rdi
callq 0xb3f0
testb $0x1, 0x195(%rsp)
jne 0x63a56
jmp 0x63a9a
movq 0x198(%rsp), %rax
leaq 0x1a0(%rsp), %rcx
cmpq %rax, %rcx
movq %rax, 0x8(%rsp)
je 0x63a98
movq 0x8(%rsp), %rdi
addq $-0x30, %rdi
movq %rdi, (%rsp)
callq 0x1e980
movq (%rsp), %rax
leaq 0x1a0(%rsp), %rcx
cmpq %rcx, %rax
movq %rax, 0x8(%rsp)
jne 0x63a70
jmp 0x63a9a
leaq 0x238(%rsp), %rdi
callq 0x1a950
leaq 0x490(%rsp), %rdi
callq 0x1c080
movq 0x460(%rsp), %rdi
callq 0xb680
nopw %cs:(%rax,%rax)