// File: /workspace/github_c_makefile_star2_O2/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
pushq $0x1
popq %rsi
movl $0x400, %edi            # imm = 0x400
callq 0x10f0
movq %rax, %r14
movq %r15, %rdi
movq %rbx, %rsi
callq 0xc4ad
leaq 0xb2ac(%rip), %rsi      # 0xd1a0
movq %rbx, %rdi
callq 0x1100
testl %eax, %eax
je 0x1f13
leaq 0xb29d(%rip), %rsi      # 0xd1a4
movq %rbx, %rdi
callq 0x1100
testl %eax, %eax
jne 0x1f1e
movq %r15, %rdi
movq %rbx, %rsi
callq 0xc4ad
leaq 0xb27b(%rip), %rsi      # 0xd1a0
movq %rbx, %rdi
callq 0x1100
testl %eax, %eax
je 0x1f44
leaq 0xb26c(%rip), %rsi      # 0xd1a4
movq %rbx, %rdi
callq 0x1100
testl %eax, %eax
jne 0x1f4f
movq %r15, %rdi
movq %rbx, %rsi
callq 0xc4ad
movzbl (%rbx), %eax
cmpl $0x7b, %eax
je 0x20c3
cmpl $0x5b, %eax
je 0x2018
cmpl $0x3c, %eax
jne 0x20cd
cmpb $0x0, 0x1(%rbx)
jne 0x20cd
movq %r14, %rdi
movq %rbx, %rsi
callq 0x1190
pushq $0x1
popq %rbp
movq %r15, %rdi
movq %rbx, %rsi
callq 0xc4ad
movzbl (%rbx), %r12d
testl %r12d, %r12d
je 0x2253
cmpb $0x0, (%r14)
je 0x1fb2
movq %r14, %rdi
callq 0x1090
movw $0x20, (%r14,%rax)
movq %r14, %rdi
movq %rbx, %rsi
callq 0x1190
cmpl $0x3e, %r12d
je 0x1fd4
cmpl $0x3c, %r12d
jne 0x1fd0
cmpb $0x1, 0x1(%rbx)
adcl $0x0, %ebp
xorl %eax, %eax
jmp 0x1fdb
cmpb $0x0, 0x1(%rbx)
sete %al
addl $-0x3e, %r12d
jne 0x1ff1
movzbl 0x1(%rbx), %r12d
addl $-0x2a, %r12d
jne 0x1ff1
movzbl 0x2(%rbx), %r12d
movzbl %al, %eax
subl %eax, %ebp
cmpl $0x1, %r12d
sbbl $0x0, %ebp
testb %al, %al
je 0x200a
testl %ebp, %ebp
jne 0x1f85
jmp 0x2253
orl %ebp, %r12d
jne 0x1f85
jmp 0x2253
cmpb $0x0, 0x1(%rbx)
jne 0x20cd
movq %r14, %rdi
movq %rbx, %rsi
callq 0x1190
pushq $0x1
popq %rbp
movq %r15, %rdi
movq %rbx, %rsi
callq 0xc4ad
movzbl (%rbx), %r12d
testl %r12d, %r12d
je 0x2253
cmpb $0x0, (%r14)
je 0x205d
movq %r14, %rdi
callq 0x1090
movw $0x20, (%r14,%rax)
movq %r14, %rdi
movq %rbx, %rsi
callq 0x1190
cmpl $0x5d, %r12d
je 0x207f
cmpl $0x5b, %r12d
jne 0x207b
cmpb $0x1, 0x1(%rbx)
adcl $0x0, %ebp
xorl %eax, %eax
jmp 0x2086
cmpb $0x0, 0x1(%rbx)
sete %al
addl $-0x5d, %r12d
jne 0x209c
movzbl 0x1(%rbx), %r12d
addl $-0x2a, %r12d
jne 0x209c
movzbl 0x2(%rbx), %r12d
movzbl %al, %eax
subl %eax, %ebp
cmpl $0x1, %r12d
sbbl $0x0, %ebp
testb %al, %al
je 0x20b5
testl %ebp, %ebp
jne 0x2030
jmp 0x2253
orl %ebp, %r12d
jne 0x2030
jmp 0x2253
cmpb $0x0, 0x1(%rbx)
je 0x21bc
leaq 0xb0d6(%rip), %rsi      # 0xd1aa
movq %rbx, %rdi
callq 0x1100
movl %eax, %ebp
movq %r14, %rdi
movq %rbx, %rsi
callq 0x1190
testl %ebp, %ebp
jne 0x2253
cmpb $0x0, (%r14)
je 0x2106
movq %r14, %rdi
callq 0x1090
movw $0x20, (%r14,%rax)
movq %r15, %rdi
movq %rbx, %rsi
callq 0xc4ad
leaq 0xb0a0(%rip), %rsi      # 0xd1b8
movq %rbx, %rdi
callq 0x1100
testl %eax, %eax
jne 0x213a
movq %r14, %rdi
movq %rbx, %rsi
callq 0x1190
movq %r15, %rdi
movq %rbx, %rsi
callq 0xc4ad
movzbl (%rbx), %eax
cmpl $0x28, %eax
je 0x222d
cmpl $0x5b, %eax
jne 0x2233
cmpb $0x0, 0x1(%rbx)
jne 0x2233
movq %r14, %rdi
movq %rbx, %rsi
callq 0x1190
movq %r15, %rdi
movq %rbx, %rsi
callq 0xc4ad
movb (%rbx), %bpl
testb %bpl, %bpl
je 0x2253
cmpb $0x0, (%r14)
je 0x2190
movq %r14, %rdi
callq 0x1090
movw $0x20, (%r14,%rax)
movq %r14, %rdi
movq %rbx, %rsi
callq 0x1190
cmpb $0x5d, %bpl
jne 0x2164
cmpb $0x0, 0x1(%rbx)
je 0x2253
cmpb $0x2a, 0x1(%rbx)
jne 0x2164
cmpb $0x0, 0x2(%rbx)
jne 0x2164
jmp 0x2253
movq %r14, %rdi
movq %rbx, %rsi
callq 0x1190
pushq $0x1
popq %rbp
pushq $-0x2
popq %r12
movq %r15, %rdi
movq %rbx, %rsi
callq 0xc4ad
movzbl (%rbx), %r13d
testl %r13d, %r13d
je 0x2253
cmpb $0x0, (%r14)
je 0x21f7
movq %r14, %rdi
callq 0x1090
movw $0x20, (%r14,%rax)
movq %r14, %rdi
movq %rbx, %rsi
callq 0x1190
cmpl $0x7b, %r13d
jne 0x2214
cmpb $0x1, 0x1(%rbx)
adcl $0x0, %ebp
movl %r12d, %r13d
jmp 0x221f
addl $-0x7d, %r13d
jne 0x221f
movzbl 0x1(%rbx), %r13d
cmpl $0x1, %r13d
sbbl $0x0, %ebp
orl %ebp, %r13d
jne 0x21ce
jmp 0x2253
cmpb $0x0, 0x1(%rbx)
je 0x2277
cmpb $0x0, (%r14)
je 0x2248
movq %r14, %rdi
callq 0x1090
movw $0x20, (%r14,%rax)
movq %r14, %rdi
movq %rbx, %rsi
callq 0x1190
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 0x1190
movq %r15, %rdi
movq %rbx, %rsi
callq 0xc4ad
movb (%rbx), %bpl
testb %bpl, %bpl
je 0x2253
cmpb $0x0, (%r14)
je 0x22aa
movq %r14, %rdi
callq 0x1090
movw $0x20, (%r14,%rax)
movq %r14, %rdi
movq %rbx, %rsi
callq 0x1190
cmpb $0x29, %bpl
jne 0x2282
cmpb $0x0, 0x1(%rbx)
je 0x2253
cmpb $0x2a, 0x1(%rbx)
jne 0x2282
cmpb $0x0, 0x2(%rbx)
jne 0x2282
jmp 0x2253