// File: /workspace/github_c_makefile_star2_O1/aquaxis[P]synverll/src/parser_ir.c
// Function: get_irtype_llvm
int get_irtype_llvm(char *line, char *token)
{
	char *result;
	int level = 0;

	result = calloc(STR_MAX, 1);

	get_token_llvm(line, token);
	strcpy(result, "");

	/*
	 * add/mul演算のみ次の宣言が付く場合がある
	 * nsw: No Signed Wrap
	 * nuw: No UnSigned Wrap
	 */
	if(!strcmp(token, "nsw") || !strcmp(token, "nuw")){
		// nsw, nusについては必要性がわからないため保留
		get_token_llvm(line, token);
	}
	if(!strcmp(token, "nsw") || !strcmp(token, "nuw")){
		// nsw, nusについては必要性がわからないため保留
		get_token_llvm(line, token);
	}

	if(!strcmp(token, "<")){
		// 構造体型
		strcat(result, token);
		level = 1;
		do{
			get_token_llvm(line, token);
			if(!strcmp(token, "")) break;
			if(strlen(result) > 0)strcat(result, " ");
			strcat(result, token);
			if(!strcmp(token,"<")) level++;
			if(!strcmp(token,">")) level--;
			if(!strcmp(token,">*")) level--;
		}while((strcmp(token,">") && strcmp(token,">*")) || (level != 0));
		strcpy(token, result);
	}else if(!strcmp(token, "[")){
		// 構造体型
		strcat(result, token);
		level = 1;
		do{
			get_token_llvm(line, token);
			if(!strcmp(token, "")) break;
			if(strlen(result) > 0)strcat(result, " ");
			strcat(result, token);
			if(!strcmp(token,"[")) level++;
			if(!strcmp(token,"]")) level--;
			if(!strcmp(token,"]*")) level--;
		}while((strcmp(token,"]") && strcmp(token,"]*")) || (level != 0));
		strcpy(token, result);
	}else if(!strcmp(token, "{")){
		// 構造体型
		strcat(result, token);
		level = 1;
		do{
			get_token_llvm(line, token);
			if(!strcmp(token, "")) break;
			if(strlen(result) > 0)strcat(result, " ");
			strcat(result, token);
			if(!strcmp(token,"{")) level++;
			if(!strcmp(token,"}")) level--;
		}while(strcmp(token,"}") || (level != 0));
		strcpy(token, result);
	}else if(!strcmp(token, "getelementptr")){
		// ポインタ
		/*
		 * ToDo:
		 * ポインタはinboundsされていないケースもあるかも
		 */
		strcat(result, token);
		if(strlen(result) > 0)strcat(result, " ");
		// inbounds
		get_token_llvm(line, token);
		if(!strcmp(token, "inbounds")){
			strcat(result, token);
			// type
			get_token_llvm(line, token);
		}
		if(!strcmp(token, "[")){
			strcat(result, token);
			level = 1;
			do{
				get_token_llvm(line, token);
				if(!strcmp(token, "")) break;
				if(strlen(result) > 0)strcat(result, " ");
				strcat(result, token);
				if(!strcmp(token, "[")) level++;
				if(!strcmp(token, "]")) level--;
			}while(strcmp(token,"]") && strcmp(token,"]*") && (level != 0));
		}else if(!strcmp(token, "(")){
			strcat(result, token);
			level = 1;
			do{
				get_token_llvm(line, token);
				if(!strcmp(token, "")) break;
				if(strlen(result) > 0)strcat(result, " ");
				strcat(result, token);
				if(!strcmp(token, "(")) level++;
				if(!strcmp(token, ")")) level--;
			}while(strcmp(token,")") && strcmp(token,")*") && (level != 0));
		}else{
			if(strlen(result) > 0)strcat(result, " ");
			strcat(result, token);
		}
		strcpy(token, result);
	}else{
		// 単独のタイプ
		strcat(result, token);
		strcpy(token, result);
	}

	free(result);
	return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movq %rsi, %rbx
movq %rdi, %r15
movl $0x400, %edi            # imm = 0x400
movl $0x1, %esi
callq 0x1100
movq %rax, %r14
movq %r15, %rdi
movq %rbx, %rsi
callq 0xcc26
movb $0x0, (%r14)
leaq 0xc155(%rip), %rsi      # 0xe1a8
movq %rbx, %rdi
callq 0x1110
testl %eax, %eax
je 0x2072
leaq 0xc146(%rip), %rsi      # 0xe1ac
movq %rbx, %rdi
callq 0x1110
testl %eax, %eax
jne 0x207d
movq %r15, %rdi
movq %rbx, %rsi
callq 0xcc26
leaq 0xc124(%rip), %rsi      # 0xe1a8
movq %rbx, %rdi
callq 0x1110
testl %eax, %eax
je 0x20a3
leaq 0xc115(%rip), %rsi      # 0xe1ac
movq %rbx, %rdi
callq 0x1110
testl %eax, %eax
jne 0x20ae
movq %r15, %rdi
movq %rbx, %rsi
callq 0xcc26
leaq 0xbff6(%rip), %rsi      # 0xe0ab
movq %rbx, %rdi
callq 0x1110
testl %eax, %eax
je 0x21b3
leaq 0xc0e7(%rip), %rsi      # 0xe1b3
movq %rbx, %rdi
callq 0x1110
testl %eax, %eax
je 0x226e
leaq 0xbfcc(%rip), %rsi      # 0xe0af
movq %rbx, %rdi
callq 0x1110
testl %eax, %eax
je 0x2326
leaq 0xc0be(%rip), %rsi      # 0xe1b8
movq %rbx, %rdi
callq 0x1110
movl %eax, %ebp
movq %r14, %rdi
movq %rbx, %rsi
callq 0x11a0
testl %ebp, %ebp
jne 0x239a
cmpb $0x0, (%r14)
je 0x212c
movq %r14, %rdi
callq 0x1090
movw $0x20, (%r14,%rax)
movq %r15, %rdi
movq %rbx, %rsi
callq 0xcc26
leaq 0xc088(%rip), %rsi      # 0xe1c6
movq %rbx, %rdi
callq 0x1110
testl %eax, %eax
jne 0x2160
movq %r14, %rdi
movq %rbx, %rsi
callq 0x11a0
movq %r15, %rdi
movq %rbx, %rsi
callq 0xcc26
leaq 0xc04c(%rip), %rsi      # 0xe1b3
movq %rbx, %rdi
callq 0x1110
testl %eax, %eax
je 0x23be
leaq 0xbf2f(%rip), %rsi      # 0xe0ad
movq %rbx, %rdi
callq 0x1110
testl %eax, %eax
je 0x242a
cmpb $0x0, (%r14)
je 0x21a3
movq %r14, %rdi
callq 0x1090
movw $0x20, (%r14,%rax)
movq %r14, %rdi
movq %rbx, %rsi
callq 0x11a0
jmp 0x239a
movq %r14, %rdi
movq %rbx, %rsi
callq 0x11a0
movq %r15, %rdi
movq %rbx, %rsi
callq 0xcc26
cmpb $0x0, (%rbx)
je 0x239a
movl $0x1, %r13d
cmpb $0x0, (%r14)
je 0x21ed
movq %r14, %rdi
callq 0x1090
movw $0x20, (%r14,%rax)
movq %r14, %rdi
movq %rbx, %rsi
callq 0x11a0
movq %rbx, %rdi
leaq 0xbea9(%rip), %rsi      # 0xe0ab
callq 0x1110
cmpl $0x1, %eax
adcl $0x0, %r13d
movq %rbx, %rdi
leaq 0xdfc3(%rip), %rsi      # 0x101db
callq 0x1110
movl %eax, %r12d
xorl %ebp, %ebp
testl %eax, %eax
sete %bpl
movq %rbx, %rdi
leaq 0xbf7e(%rip), %rsi      # 0xe1b0
callq 0x1110
cmpl $0x1, %eax
sbbl %ebp, %r13d
testl %r12d, %r12d
je 0x224c
orl %r13d, %eax
jne 0x2255
jmp 0x239a
testl %r13d, %r13d
je 0x239a
movq %r15, %rdi
movq %rbx, %rsi
callq 0xcc26
cmpb $0x0, (%rbx)
jne 0x21d8
jmp 0x239a
movq %r14, %rdi
movq %rbx, %rsi
callq 0x11a0
movq %r15, %rdi
movq %rbx, %rsi
callq 0xcc26
cmpb $0x0, (%rbx)
je 0x239a
movl $0x1, %r13d
cmpb $0x0, (%r14)
je 0x22a8
movq %r14, %rdi
callq 0x1090
movw $0x20, (%r14,%rax)
movq %r14, %rdi
movq %rbx, %rsi
callq 0x11a0
movq %rbx, %rdi
leaq 0xbef6(%rip), %rsi      # 0xe1b3
callq 0x1110
cmpl $0x1, %eax
adcl $0x0, %r13d
movq %rbx, %rdi
leaq 0xdd7a(%rip), %rsi      # 0x1004d
callq 0x1110
movl %eax, %r12d
xorl %ebp, %ebp
testl %eax, %eax
sete %bpl
movq %rbx, %rdi
leaq 0xbec8(%rip), %rsi      # 0xe1b5
callq 0x1110
cmpl $0x1, %eax
sbbl %ebp, %r13d
testl %r12d, %r12d
je 0x2307
orl %r13d, %eax
jne 0x2310
jmp 0x239a
testl %r13d, %r13d
je 0x239a
movq %r15, %rdi
movq %rbx, %rsi
callq 0xcc26
cmpb $0x0, (%rbx)
jne 0x2293
jmp 0x239a
movq %r14, %rdi
movq %rbx, %rsi
callq 0x11a0
movl $0x1, %ebp
leaq 0xbd72(%rip), %r12      # 0xe0af
leaq 0xbd6d(%rip), %r13      # 0xe0b1
movq %r15, %rdi
movq %rbx, %rsi
callq 0xcc26
cmpb $0x0, (%rbx)
je 0x239a
cmpb $0x0, (%r14)
je 0x2369
movq %r14, %rdi
callq 0x1090
movw $0x20, (%r14,%rax)
movq %r14, %rdi
movq %rbx, %rsi
callq 0x11a0
movq %rbx, %rdi
movq %r12, %rsi
callq 0x1110
cmpl $0x1, %eax
adcl $0x0, %ebp
movq %rbx, %rdi
movq %r13, %rsi
callq 0x1110
cmpl $0x1, %eax
sbbl $0x0, %ebp
orl %ebp, %eax
jne 0x2344
movq %rbx, %rdi
movq %r14, %rsi
callq 0x1060
movq %r14, %rdi
callq 0x1030
xorl %eax, %eax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %r14, %rdi
movq %rbx, %rsi
callq 0x11a0
leaq 0xdc7d(%rip), %r12      # 0x1004d
leaq 0xbdde(%rip), %r13      # 0xe1b5
movq %r15, %rdi
movq %rbx, %rsi
callq 0xcc26
cmpb $0x0, (%rbx)
je 0x239a
cmpb $0x0, (%r14)
je 0x23fc
movq %r14, %rdi
callq 0x1090
movw $0x20, (%r14,%rax)
movq %r14, %rdi
movq %rbx, %rsi
callq 0x11a0
movq %rbx, %rdi
movq %r12, %rsi
callq 0x1110
testl %eax, %eax
je 0x239a
movq %rbx, %rdi
movq %r13, %rsi
callq 0x1110
testl %eax, %eax
jne 0x23d7
jmp 0x239a
movq %r14, %rdi
movq %rbx, %rsi
callq 0x11a0
leaq 0xc561(%rip), %r12      # 0xe99d
leaq 0xbd8c(%rip), %r13      # 0xe1cf
movq %r15, %rdi
movq %rbx, %rsi
callq 0xcc26
cmpb $0x0, (%rbx)
je 0x239a
cmpb $0x0, (%r14)
je 0x246c
movq %r14, %rdi
callq 0x1090
movw $0x20, (%r14,%rax)
movq %r14, %rdi
movq %rbx, %rsi
callq 0x11a0
movq %rbx, %rdi
movq %r12, %rsi
callq 0x1110
testl %eax, %eax
je 0x239a
movq %rbx, %rdi
movq %r13, %rsi
callq 0x1110
testl %eax, %eax
jne 0x2443
jmp 0x239a