// File: /workspace/github_c_makefile_star2_O2/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 $0x28, %rsp
movq %rdx, 0x20(%rsp)
movq %rsi, %r15
movq %rdi, %r14
movl $0x400, %edi            # imm = 0x400
callq 0x1130
movq %rax, %rbx
pushq $0x1
popq %rsi
movl $0x400, %edi            # imm = 0x400
callq 0x10f0
movq %rax, 0x10(%rsp)
movq %r14, %rdi
callq 0x1372
movq %rax, 0x8(%rsp)
movq %rax, %rdi
movq %rbx, %rsi
callq 0xc4ad
xorl %r13d, %r13d
testq %r15, %r15
movq %r15, 0x18(%rsp)
je 0x628a
movq %r15, %rdi
callq 0x1372
testq %rax, %rax
je 0x628a
movq %rax, %r14
movq %rax, %rdi
movq %rbx, %rsi
callq 0x1ec1
movq %r14, %rdi
movq %rbx, %rsi
callq 0xc4ad
movq %rbx, %rdi
callq 0x1180
movl %eax, %r15d
movq %r14, (%rsp)
movq %r14, %rdi
movq %rbx, %rsi
callq 0xc4ad
jmp 0x6295
movq $0x0, (%rsp)
xorl %r15d, %r15d
movq 0x8(%rsp), %rdi
xorl %ebp, %ebp
xorl %r12d, %r12d
movq %rbx, %rsi
callq 0x1ec1
movzbl (%rbx), %r14d
testl %r14d, %r14d
je 0x6383
movq %rbx, %rdi
leaq 0x76b2(%rip), %rsi      # 0xd970
callq 0x1100
testl %eax, %eax
je 0x6383
movq %rbx, %rdi
cmpl $0x7b, %r14d
je 0x62ea
cmpl $0x5b, %r14d
jne 0x6338
movq (%rsp), %rsi
movq 0x10(%rsp), %rdx
callq 0x63e2
jmp 0x62f8
movq (%rsp), %rsi
movq 0x10(%rsp), %rdx
callq 0x61eb
movl %eax, %r14d
addl %r14d, %ebp
xorl %eax, %eax
testl %r15d, %r15d
setg %al
movl $0x0, %ecx
cmovgl %r14d, %ecx
subl %eax, %r15d
addl %ecx, %r12d
movq 0x8(%rsp), %r13
movq %r13, %rdi
movq %rbx, %rsi
callq 0xc4ad
movq %r13, %rdi
cmpb $0x0, (%r13)
movl %r14d, %r13d
jne 0x629f
jmp 0x6383
leaq 0x759a(%rip), %rsi      # 0xd8d9
callq 0x1100
pushq $0x1
popq %r14
testl %eax, %eax
je 0x62fb
movq %rbx, %rdi
leaq 0x6cb3(%rip), %rsi      # 0xd009
callq 0x1100
pushq $0x2
popq %r14
testl %eax, %eax
je 0x62fb
movq %rbx, %rdi
leaq 0x7ec4(%rip), %rsi      # 0xe231
callq 0x1100
testl %eax, %eax
pushq $0x4
popq %rax
cmovel %eax, %r13d
movl %r13d, %r14d
jmp 0x62fb
cmpq $0x0, 0x18(%rsp)
sete %al
movq 0x20(%rsp), %rdi
testq %rdi, %rdi
sete %cl
orb %al, %cl
jne 0x63c9
movq 0x10(%rsp), %rdx
cmpb $0x0, (%rdx)
je 0x63b8
leaq 0x7530(%rip), %rsi      # 0xd8dc
movl %r12d, %ecx
xorl %eax, %eax
callq 0x11a0
jmp 0x63c9
leaq 0x7522(%rip), %rsi      # 0xd8e1
movl %r12d, %edx
xorl %eax, %eax
callq 0x11a0
movq %rbx, %rdi
callq 0x1030
movl %ebp, %eax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq