// File: /workspace/github_c_makefile_star2_O1/aquaxis[P]synverll/src/parser_ir_memory.c
// Function: _get_array_size
int __get_array_size(char *type, char *ptr, char *rslt_ptr)
{
	char *buf;
	char *token;
	int size = 0;
	int total = 0;
	int num = 0;
	char *buf_ptr = NULL;
	char *ptr_cnt = NULL;
	char *temp = NULL;
	char *str = NULL;

	token = malloc(STR_MAX);
	temp = calloc(STR_MAX,1);

	buf = charalloc(type);

	if(ptr != NULL){
		if(strlen(ptr) > 0){
			buf_ptr = charalloc(ptr);
		}
	}

	/*
	 * ポインタの位置の検出
	 */
	if(buf_ptr != NULL){
		// Type
		get_irtype_llvm(buf_ptr, token);
		// Name
		get_token_llvm(buf_ptr, token);
		str = regalloc(token);
		ptr_cnt = charalloc(str);
		free(str);
		// ,
		get_token_llvm(buf_ptr, token);
	}

	// [ num x type ]
	// [
	get_token_llvm(buf, token);
	// num
	get_token_llvm(buf, token);
	num = atoi(token);
	// x
	get_token_llvm(buf, token);
	// type
	get_irtype_llvm(buf, token);

	if(token[0] == '['){
		size = __get_array_size(token, buf_ptr, temp);
	}else if(token[0] == '{'){
		size = __get_struct_size(token, buf_ptr, temp);
	}else if(!strcmp(token, "i8")){
		size = 1;
	}else if(!strcmp(token, "i16")){
		size = 2;
	}else if(!strcmp(token, "i32")){
		size = 4;
	}
	total += size * num;

	// ]
	get_token_llvm(buf, token);

	if(ptr_cnt != NULL){
		if(rslt_ptr != NULL){
			if(strlen(temp) > 0){
				sprintf(rslt_ptr, "%s + (%d * %s)", temp, size, ptr_cnt);
			}else{
				sprintf(rslt_ptr, "(%d * %s)", size, ptr_cnt);
			}
		}
		free(ptr_cnt);
	}

	return total;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movq %rdx, (%rsp)
movq %rsi, %rbx
movq %rdi, %r12
movl $0x400, %edi            # imm = 0x400
callq 0x1140
movq %rax, %r15
movl $0x400, %edi            # imm = 0x400
movl $0x1, %esi
callq 0x1100
movq %rax, %r14
movq %r12, %rdi
callq 0x1395
movq %rax, %r12
testq %rbx, %rbx
je 0x682b
cmpb $0x0, (%rbx)
je 0x682b
movq %rbx, %rdi
callq 0x1395
movq %rax, %rbx
jmp 0x682d
xorl %ebx, %ebx
testq %rbx, %rbx
je 0x6873
movq %rbx, %rdi
movq %r15, %rsi
callq 0x201a
movq %rbx, %rdi
movq %r15, %rsi
callq 0xcc26
movq %r15, %rdi
callq 0x7c87
movq %rax, %rbp
movq %rax, %rdi
callq 0x1395
movq %rax, %r13
movq %rbp, %rdi
callq 0x1030
movq %rbx, %rdi
movq %r15, %rsi
callq 0xcc26
jmp 0x6876
xorl %r13d, %r13d
movq %r12, %rdi
movq %r15, %rsi
callq 0xcc26
movq %r12, %rdi
movq %r15, %rsi
callq 0xcc26
movq %r15, %rdi
callq 0x1190
movl %eax, %ebp
movq %r12, %rdi
movq %r15, %rsi
callq 0xcc26
movq %r12, %rdi
movq %r15, %rsi
callq 0x201a
movzbl (%r15), %eax
cmpl $0x7b, %eax
je 0x68ca
cmpl $0x5b, %eax
jne 0x6915
movq %r15, %rdi
movq %rbx, %rsi
movq %r14, %rdx
callq 0x67d5
jmp 0x68d8
movq %r15, %rdi
movq %rbx, %rsi
movq %r14, %rdx
callq 0x65b8
movl %eax, %ebx
movq %r12, %rdi
movq %r15, %rsi
callq 0xcc26
testq %r13, %r13
je 0x6971
movq (%rsp), %rdi
testq %rdi, %rdi
je 0x6969
cmpb $0x0, (%r14)
je 0x6956
leaq 0x800f(%rip), %rsi      # 0xe913
movq %r14, %rdx
movl %ebx, %ecx
movq %r13, %r8
xorl %eax, %eax
callq 0x11b0
jmp 0x6969
leaq 0x76f0(%rip), %rsi      # 0xe00c
movq %r15, %rdi
callq 0x1110
testl %eax, %eax
je 0x6985
leaq 0x76e0(%rip), %rsi      # 0xe00f
movq %r15, %rdi
callq 0x1110
testl %eax, %eax
je 0x698f
leaq 0x891b(%rip), %rsi      # 0xf25d
movq %r15, %rdi
callq 0x1110
xorl %ebx, %ebx
testl %eax, %eax
sete %bl
shll $0x2, %ebx
jmp 0x68da
leaq 0x7fbb(%rip), %rsi      # 0xe918
movl %ebx, %edx
movq %r13, %rcx
xorl %eax, %eax
callq 0x11b0
movq %r13, %rdi
callq 0x1030
imull %ebp, %ebx
movl %ebx, %eax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movl $0x1, %ebx
jmp 0x68da
movl $0x2, %ebx
jmp 0x68da