// File: /workspace/github_c_makefile_star2_O3/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
movl $0x400, %edi            # imm = 0x400
movl $0x1, %esi
callq 0x10f0
movq %rax, %r14
movq %r12, %rdi
callq 0x137c
movq %rax, %r12
testq %rbx, %rbx
je 0x674f
cmpb $0x0, (%rbx)
je 0x674f
movq %rbx, %rdi
callq 0x137c
testq %rax, %rax
je 0x674f
movq %rax, %rbx
movq %rax, %rdi
movq %r15, %rsi
callq 0x1fbb
movq %rbx, %rdi
movq %r15, %rsi
callq 0xcaa7
movq %r15, %rdi
callq 0x7b63
movq %rax, %rbp
movq %rax, %rdi
callq 0x137c
movq %rax, %r13
movq %rbp, %rdi
callq 0x1030
movq %rbx, %rdi
movq %r15, %rsi
callq 0xcaa7
jmp 0x6754
xorl %ebx, %ebx
xorl %r13d, %r13d
movq %r12, %rdi
movq %r15, %rsi
callq 0xcaa7
movq %r12, %rdi
movq %r15, %rsi
callq 0xcaa7
movq %r15, %rdi
callq 0x1180
movl %eax, %ebp
movq %r12, %rdi
movq %r15, %rsi
callq 0xcaa7
movq %r12, %rdi
movq %r15, %rsi
callq 0x1fbb
movzbl (%r15), %eax
cmpl $0x7b, %eax
je 0x67a8
cmpl $0x5b, %eax
jne 0x67f3
movq %r15, %rdi
movq %rbx, %rsi
movq %r14, %rdx
callq 0x66b5
jmp 0x67b6
movq %r15, %rdi
movq %rbx, %rsi
movq %r14, %rdx
callq 0x64b0
movl %eax, %ebx
movq %r12, %rdi
movq %r15, %rsi
callq 0xcaa7
testq %r13, %r13
je 0x684f
movq (%rsp), %rdi
testq %rdi, %rdi
je 0x6847
cmpb $0x0, (%r14)
je 0x6834
leaq 0x8124(%rip), %rsi      # 0xe906
movq %r14, %rdx
movl %ebx, %ecx
movq %r13, %r8
xorl %eax, %eax
callq 0x11a0
jmp 0x6847
leaq 0x80ff(%rip), %rsi      # 0xe8f9
movq %r15, %rdi
callq 0x1100
testl %eax, %eax
je 0x6863
leaq 0x77fc(%rip), %rsi      # 0xe009
movq %r15, %rdi
callq 0x1100
testl %eax, %eax
je 0x686d
leaq 0x8a31(%rip), %rsi      # 0xf251
movq %r15, %rdi
callq 0x1100
xorl %ebx, %ebx
testl %eax, %eax
sete %bl
shll $0x2, %ebx
jmp 0x67b8
leaq 0x80d0(%rip), %rsi      # 0xe90b
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
movl $0x1, %ebx
jmp 0x67b8
movl $0x2, %ebx
jmp 0x67b8