// File: /workspace/github_c_makefile_star2_O3/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 %r12
pushq %rbx
movq %rsi, %rbx
movq %rdi, %r15
movl $0x400, %edi            # imm = 0x400
movl $0x1, %esi
callq 0x10f0
movq %rax, %r14
movq %r15, %rdi
movq %rbx, %rsi
callq 0xcaa7
leaq 0xc1b3(%rip), %rsi      # 0xe1a0
movq %rbx, %rdi
callq 0x1100
testl %eax, %eax
je 0x200c
leaq 0xc1a4(%rip), %rsi      # 0xe1a4
movq %rbx, %rdi
callq 0x1100
testl %eax, %eax
jne 0x2017
movq %r15, %rdi
movq %rbx, %rsi
callq 0xcaa7
leaq 0xc182(%rip), %rsi      # 0xe1a0
movq %rbx, %rdi
callq 0x1100
testl %eax, %eax
je 0x203d
leaq 0xc173(%rip), %rsi      # 0xe1a4
movq %rbx, %rdi
callq 0x1100
testl %eax, %eax
jne 0x2048
movq %r15, %rdi
movq %rbx, %rsi
callq 0xcaa7
movzbl (%rbx), %eax
cmpl $0x7b, %eax
je 0x21c8
cmpl $0x5b, %eax
je 0x2117
cmpl $0x3c, %eax
jne 0x21d2
cmpb $0x0, 0x1(%rbx)
jne 0x21d2
movq %r14, %rdi
movq %rbx, %rsi
callq 0x1190
movq %r15, %rdi
movq %rbx, %rsi
callq 0xcaa7
movb (%rbx), %r12b
testb %r12b, %r12b
je 0x2359
movl $0x1, %ebp
cmpb $0x0, (%r14)
je 0x20ac
movq %r14, %rdi
callq 0x1090
movw $0x20, (%r14,%rax)
movq %r14, %rdi
movq %rbx, %rsi
callq 0x1190
cmpb $0x3e, %r12b
je 0x20d4
movzbl %r12b, %ecx
movl $0x1, %eax
cmpl $0x3c, %ecx
jne 0x20ea
cmpb $0x1, 0x1(%rbx)
adcl $0x0, %ebp
jmp 0x20ea
movb 0x1(%rbx), %al
cmpb $0x1, %al
sbbl $0x0, %ebp
cmpb $0x2a, %al
jne 0x210a
movzbl 0x2(%rbx), %eax
cmpl $0x1, %eax
sbbl $0x0, %ebp
orl %ebp, %eax
je 0x2359
movq %r15, %rdi
movq %rbx, %rsi
callq 0xcaa7
movb (%rbx), %r12b
testb %r12b, %r12b
jne 0x2097
jmp 0x2359
testb %al, %al
jne 0x20f2
testl %ebp, %ebp
jne 0x20f2
jmp 0x2359
cmpb $0x0, 0x1(%rbx)
jne 0x21d2
movq %r14, %rdi
movq %rbx, %rsi
callq 0x1190
movq %r15, %rdi
movq %rbx, %rsi
callq 0xcaa7
movb (%rbx), %r12b
testb %r12b, %r12b
je 0x2359
movl $0x1, %ebp
cmpb $0x0, (%r14)
je 0x215d
movq %r14, %rdi
callq 0x1090
movw $0x20, (%r14,%rax)
movq %r14, %rdi
movq %rbx, %rsi
callq 0x1190
cmpb $0x5d, %r12b
je 0x2185
movzbl %r12b, %ecx
movl $0x1, %eax
cmpl $0x5b, %ecx
jne 0x219b
cmpb $0x1, 0x1(%rbx)
adcl $0x0, %ebp
jmp 0x219b
movb 0x1(%rbx), %al
cmpb $0x1, %al
sbbl $0x0, %ebp
cmpb $0x2a, %al
jne 0x21bb
movzbl 0x2(%rbx), %eax
cmpl $0x1, %eax
sbbl $0x0, %ebp
orl %ebp, %eax
je 0x2359
movq %r15, %rdi
movq %rbx, %rsi
callq 0xcaa7
movb (%rbx), %r12b
testb %r12b, %r12b
jne 0x2148
jmp 0x2359
testb %al, %al
jne 0x21a3
testl %ebp, %ebp
jne 0x21a3
jmp 0x2359
cmpb $0x0, 0x1(%rbx)
je 0x22c1
leaq 0xbfd1(%rip), %rsi      # 0xe1aa
movq %rbx, %rdi
callq 0x1100
movl %eax, %ebp
movq %r14, %rdi
movq %rbx, %rsi
callq 0x1190
testl %ebp, %ebp
jne 0x2359
cmpb $0x0, (%r14)
je 0x220b
movq %r14, %rdi
callq 0x1090
movw $0x20, (%r14,%rax)
movq %r15, %rdi
movq %rbx, %rsi
callq 0xcaa7
leaq 0xbf9b(%rip), %rsi      # 0xe1b8
movq %rbx, %rdi
callq 0x1100
testl %eax, %eax
jne 0x223f
movq %r14, %rdi
movq %rbx, %rsi
callq 0x1190
movq %r15, %rdi
movq %rbx, %rsi
callq 0xcaa7
movzbl (%rbx), %eax
cmpl $0x28, %eax
je 0x2333
cmpl $0x5b, %eax
jne 0x2339
cmpb $0x0, 0x1(%rbx)
jne 0x2339
movq %r14, %rdi
movq %rbx, %rsi
callq 0x1190
movq %r15, %rdi
movq %rbx, %rsi
callq 0xcaa7
movb (%rbx), %bpl
testb %bpl, %bpl
je 0x2359
cmpb $0x0, (%r14)
je 0x2295
movq %r14, %rdi
callq 0x1090
movw $0x20, (%r14,%rax)
movq %r14, %rdi
movq %rbx, %rsi
callq 0x1190
cmpb $0x5d, %bpl
jne 0x2269
cmpb $0x0, 0x1(%rbx)
je 0x2359
cmpb $0x2a, 0x1(%rbx)
jne 0x2269
cmpb $0x0, 0x2(%rbx)
jne 0x2269
jmp 0x2359
movq %r14, %rdi
movq %rbx, %rsi
callq 0x1190
movl $0x1, %ebp
movq %r15, %rdi
movq %rbx, %rsi
callq 0xcaa7
movzbl (%rbx), %r12d
testl %r12d, %r12d
je 0x2359
cmpb $0x0, (%r14)
je 0x22fa
movq %r14, %rdi
callq 0x1090
movw $0x20, (%r14,%rax)
movq %r14, %rdi
movq %rbx, %rsi
callq 0x1190
cmpl $0x7b, %r12d
jne 0x231a
cmpb $0x1, 0x1(%rbx)
adcl $0x0, %ebp
movl $0xfffffffe, %r12d      # imm = 0xFFFFFFFE
jmp 0x2325
addl $-0x7d, %r12d
jne 0x2325
movzbl 0x1(%rbx), %r12d
cmpl $0x1, %r12d
sbbl $0x0, %ebp
orl %ebp, %r12d
jne 0x22d1
jmp 0x2359
cmpb $0x0, 0x1(%rbx)
je 0x2377
cmpb $0x0, (%r14)
je 0x234e
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
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq
movq %r14, %rdi
movq %rbx, %rsi
callq 0x1190
movq %r15, %rdi
movq %rbx, %rsi
callq 0xcaa7
movb (%rbx), %bpl
testb %bpl, %bpl
je 0x2359
cmpb $0x0, (%r14)
je 0x23aa
movq %r14, %rdi
callq 0x1090
movw $0x20, (%r14,%rax)
movq %r14, %rdi
movq %rbx, %rsi
callq 0x1190
cmpb $0x29, %bpl
jne 0x2382
cmpb $0x0, 0x1(%rbx)
je 0x2359
cmpb $0x2a, 0x1(%rbx)
jne 0x2382
cmpb $0x0, 0x2(%rbx)
jne 0x2382
jmp 0x2359