// File: /workspace/github_c_makefile_star2_O3/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
movl $0x400, %edi            # imm = 0x400
movl $0x1, %esi
callq 0x10f0
movq %rax, 0x8(%rsp)
movq %r14, %rdi
callq 0x137c
movq %rax, %r13
movq %rax, %rdi
movq %rbx, %rsi
callq 0xcaa7
movq $0x0, 0x10(%rsp)
testq %r15, %r15
movq %r15, 0x18(%rsp)
je 0x6555
movq %r15, %rdi
callq 0x137c
testq %rax, %rax
je 0x6555
movq %rax, %r12
movq %rax, %rdi
movq %rbx, %rsi
callq 0x1fbb
movq %r12, %rdi
movq %rbx, %rsi
callq 0xcaa7
movq %rbx, %rdi
callq 0x1180
movl %eax, %r14d
movq %r12, (%rsp)
movq %r12, %rdi
movq %rbx, %rsi
callq 0xcaa7
jmp 0x6560
movq $0x0, (%rsp)
xorl %r14d, %r14d
xorl %ebp, %ebp
xorl %r15d, %r15d
movq %r13, %r12
movq %r13, %rdi
movq %rbx, %rsi
callq 0x1fbb
movzbl (%rbx), %r13d
testl %r13d, %r13d
je 0x6656
movq %rbx, %rdi
leaq 0x8406(%rip), %rsi      # 0xe990
callq 0x1100
testl %eax, %eax
je 0x6656
movq %rbx, %rdi
cmpl $0x7b, %r13d
je 0x65b6
cmpl $0x5b, %r13d
jne 0x65fc
movq (%rsp), %rsi
movq 0x8(%rsp), %rdx
callq 0x66b5
jmp 0x65c4
movq (%rsp), %rsi
movq 0x8(%rsp), %rdx
callq 0x64b0
movq %r12, %r13
addl %eax, %ebp
xorl %edx, %edx
testl %r14d, %r14d
setg %dl
movl $0x0, %ecx
movq %rax, 0x10(%rsp)
cmovgl %eax, %ecx
subl %edx, %r14d
addl %ecx, %r15d
movq %r13, %rdi
movq %rbx, %rsi
callq 0xcaa7
cmpb $0x0, (%r13)
jne 0x6565
jmp 0x6656
leaq 0x82f6(%rip), %rsi      # 0xe8f9
callq 0x1100
testl %eax, %eax
movq %r12, %r13
je 0x6642
movq %rbx, %rdi
leaq 0x79f0(%rip), %rsi      # 0xe009
callq 0x1100
testl %eax, %eax
je 0x664c
movq %rbx, %rdi
leaq 0x8c25(%rip), %rsi      # 0xf251
callq 0x1100
testl %eax, %eax
movq 0x10(%rsp), %rax
movl $0x4, %ecx
cmovel %ecx, %eax
jmp 0x65c7
movl $0x1, %eax
jmp 0x65c7
movl $0x2, %eax
jmp 0x65c7
cmpq $0x0, 0x18(%rsp)
sete %al
movq 0x20(%rsp), %rdi
testq %rdi, %rdi
sete %cl
orb %al, %cl
jne 0x669c
movq 0x8(%rsp), %rdx
cmpb $0x0, (%rdx)
je 0x668b
leaq 0x827d(%rip), %rsi      # 0xe8fc
movl %r15d, %ecx
xorl %eax, %eax
callq 0x11a0
jmp 0x669c
leaq 0x826f(%rip), %rsi      # 0xe901
movl %r15d, %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