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

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

	buf = charalloc(type);

	// {
	get_token_llvm(buf, token);

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

	/*
	 * ポインタの位置の検出
	 */
	if(buf_ptr != NULL){
		// Type
		get_irtype_llvm(buf_ptr, token);
		// Name
		get_token_llvm(buf_ptr, token);
		ptr_cnt = atoi(token);	// 数字しかありえないはず
		// ,
		get_token_llvm(buf_ptr, token);
	}

	do{
		get_irtype_llvm(buf, token);
		if((strlen(token) == 0) || (!strcmp(token, ")"))) break;

		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;

		if(ptr_cnt > 0){
			size_count += size;
			ptr_cnt--;
		}

		// ","か"}"
		get_token_llvm(buf, token);
	}while(strlen(buf) > 0);

	if(ptr != NULL){
		if(rslt_ptr != NULL){
			if(strlen(temp) > 0){
				sprintf(rslt_ptr, "%s + (%d)", temp, size_count);
			}else{
				sprintf(rslt_ptr, "(%d)", size_count);
			}
		}
	}

	free(token);

	return total;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x38, %rsp
movq %rdx, 0x30(%rsp)
movq %rsi, %r15
movq %rdi, %r14
movl $0x400, %edi            # imm = 0x400
callq 0x1140
movq %rax, %rbx
movl $0x400, %edi            # imm = 0x400
movl $0x1, %esi
callq 0x1100
movq %rax, 0x18(%rsp)
movq %r14, %rdi
callq 0x1395
movq %rax, %r13
movq %rax, %rdi
movq %rbx, 0x8(%rsp)
movq %rbx, %rsi
callq 0xcc26
xorl %r12d, %r12d
testq %r15, %r15
je 0x6622
movq %r15, %rdi
callq 0x1395
movq %rax, %r14
jmp 0x6625
xorl %r14d, %r14d
movq %r15, 0x28(%rsp)
testq %r14, %r14
je 0x6660
movq %r14, %rdi
movq 0x8(%rsp), %rbx
movq %rbx, %rsi
callq 0x201a
movq %r14, %rdi
movq %rbx, %rsi
callq 0xcc26
movq %rbx, %rdi
callq 0x1190
movl %eax, %r12d
movq %r14, %rdi
movq %rbx, %rsi
callq 0xcc26
movq %r14, 0x20(%rsp)
movl $0x0, 0x14(%rsp)
xorl %ebp, %ebp
xorl %r15d, %r15d
movq 0x8(%rsp), %r14
movq %r13, %rbx
movq %r13, %rdi
movq %r14, %rsi
callq 0x201a
movzbl (%r14), %r13d
testl %r13d, %r13d
je 0x6774
movq %r14, %rdi
leaq 0x8301(%rip), %rsi      # 0xe99d
callq 0x1110
testl %eax, %eax
je 0x6774
cmpl $0x7b, %r13d
je 0x66ce
cmpl $0x5b, %r13d
movq 0x8(%rsp), %r14
movq %r14, %rdi
jne 0x671e
movq 0x20(%rsp), %rsi
movq 0x18(%rsp), %rdx
callq 0x67d5
jmp 0x66e5
movq 0x8(%rsp), %r14
movq %r14, %rdi
movq 0x20(%rsp), %rsi
movq 0x18(%rsp), %rdx
callq 0x65b8
movl %eax, %edx
movq %rbx, %r13
addl %edx, %ebp
xorl %eax, %eax
testl %r12d, %r12d
setg %al
movl $0x0, %ecx
movl %edx, 0x14(%rsp)
cmovgl %edx, %ecx
subl %eax, %r12d
addl %ecx, %r15d
movq %r13, %rdi
movq %r14, %rsi
callq 0xcc26
cmpb $0x0, (%r13)
jne 0x6677
jmp 0x6774
leaq 0x78e7(%rip), %rsi      # 0xe00c
callq 0x1110
testl %eax, %eax
movq %rbx, %r13
je 0x6763
movq %r14, %rdi
leaq 0x78d4(%rip), %rsi      # 0xe00f
callq 0x1110
testl %eax, %eax
je 0x676a
movq %r14, %rdi
leaq 0x8b0f(%rip), %rsi      # 0xf25d
callq 0x1110
testl %eax, %eax
movl $0x4, %eax
movl 0x14(%rsp), %edx
cmovel %eax, %edx
jmp 0x66ea
movl $0x1, %edx
jmp 0x66ea
movl $0x2, %edx
jmp 0x66ea
cmpq $0x0, 0x28(%rsp)
sete %al
movq 0x30(%rsp), %rdi
testq %rdi, %rdi
sete %cl
orb %al, %cl
jne 0x67ba
movq 0x18(%rsp), %rdx
cmpb $0x0, (%rdx)
je 0x67a9
leaq 0x816c(%rip), %rsi      # 0xe909
movl %r15d, %ecx
xorl %eax, %eax
callq 0x11b0
jmp 0x67ba
leaq 0x815e(%rip), %rsi      # 0xe90e
movl %r15d, %edx
xorl %eax, %eax
callq 0x11b0
movq 0x8(%rsp), %rdi
callq 0x1030
movl %ebp, %eax
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq