// File: /workspace/github_c_makefile_star2_O2/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 0x1130
movq %rax, %r15
pushq $0x1
popq %rsi
movl $0x400, %edi            # imm = 0x400
callq 0x10f0
movq %rax, %r14
movq %r12, %rdi
callq 0x1372
movq %rax, %r12
testq %rbx, %rbx
je 0x647a
cmpb $0x0, (%rbx)
je 0x647a
movq %rbx, %rdi
callq 0x1372
testq %rax, %rax
je 0x647a
movq %rax, %rbx
movq %rax, %rdi
movq %r15, %rsi
callq 0x1ec1
movq %rbx, %rdi
movq %r15, %rsi
callq 0xc4ad
movq %r15, %rdi
callq 0x7706
movq %rax, %rbp
movq %rax, %rdi
callq 0x1372
movq %rax, %r13
movq %rbp, %rdi
callq 0x1030
movq %rbx, %rdi
movq %r15, %rsi
callq 0xc4ad
jmp 0x647f
xorl %ebx, %ebx
xorl %r13d, %r13d
movq %r12, %rdi
movq %r15, %rsi
callq 0xc4ad
movq %r12, %rdi
movq %r15, %rsi
callq 0xc4ad
movq %r15, %rdi
callq 0x1180
movl %eax, %ebp
movq %r12, %rdi
movq %r15, %rsi
callq 0xc4ad
movq %r12, %rdi
movq %r15, %rsi
callq 0x1ec1
movzbl (%r15), %eax
cmpl $0x7b, %eax
je 0x64d3
cmpl $0x5b, %eax
jne 0x64e5
movq %r15, %rdi
movq %rbx, %rsi
movq %r14, %rdx
callq 0x63e2
jmp 0x64e1
movq %r15, %rdi
movq %rbx, %rsi
movq %r14, %rdx
callq 0x61eb
movl %eax, %ebx
jmp 0x652d
leaq 0x73ed(%rip), %rsi      # 0xd8d9
movq %r15, %rdi
callq 0x1100
testl %eax, %eax
je 0x6526
leaq 0x6b0a(%rip), %rsi      # 0xd009
movq %r15, %rdi
callq 0x1100
testl %eax, %eax
je 0x652a
leaq 0x7d1f(%rip), %rsi      # 0xe231
movq %r15, %rdi
callq 0x1100
xorl %ebx, %ebx
testl %eax, %eax
sete %bl
shll $0x2, %ebx
jmp 0x652d
pushq $0x1
jmp 0x652c
pushq $0x2
popq %rbx
movq %r12, %rdi
movq %r15, %rsi
callq 0xc4ad
testq %r13, %r13
je 0x657f
movq (%rsp), %rdi
testq %rdi, %rdi
je 0x6577
cmpb $0x0, (%r14)
je 0x6564
leaq 0x7393(%rip), %rsi      # 0xd8e6
movq %r14, %rdx
movl %ebx, %ecx
movq %r13, %r8
xorl %eax, %eax
callq 0x11a0
jmp 0x6577
leaq 0x7380(%rip), %rsi      # 0xd8eb
movl %ebx, %edx
movq %r13, %rcx
xorl %eax, %eax
callq 0x11a0
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