// File: /workspace/github_c_makefile_star2_O1/aquaxis[P]synverll/src/parser_ir_proc.c
// Function: create_verilog_call_args
int create_verilog_call_args(char *name, char *args, char *buf, int is_call)
{
	char *token;
	char *line;
	char *temp;
	char *type;
	int args_num = 0;
	char *str;
	int width;

	token = calloc(STR_MAX, 1);
	temp = calloc(STR_MAX, 1);
	type = calloc(STR_MAX, 1);
	line = charalloc(args);
	strcpy(buf, "");

	get_token_llvm(line, token);	// "("

	/* ToDo:
	 * Verilog HDLを作成しつつ、外部信号も生成すること
	 */
	while(strlen(line) > 0){
		// タイプ
		/*
		 * タイプが整数の場合は、Writeのみ
		 * タイプがポインタの場合はRead/Write有り
		 * タイプがメモリの場合はRead/Write有り
		 */
		get_irtype_llvm(line, token);
		if(!strcmp(token, "") || !strcmp(token,")")) break;
		strcpy(type, token);

		{
			do{
				get_token_llvm(line, token);
				if(!strcmp(token, "align")){
					get_token_llvm(line, token);
					get_token_llvm(line, token);
				}
			}while(
				!strcmp(token, "zeroext") ||
				!strcmp(token, "signext") ||
				!strcmp(token, "inreg") ||
				!strcmp(token, "byval") ||
				!strcmp(token, "sret") ||
				!strcmp(token, "align") ||
				!strcmp(token, "noalias") ||
				!strcmp(token, "nocapture") ||
				!strcmp(token, "nest") ||
				!strcmp(token, "readonly") ||
				!strcmp(token, "readnone") ||
				!strcmp(token, "returned") ||
				!strcmp(token, "dereferenceable") ||
				!strcmp(token, "dereferenceable_or_null")
			);
		}

		if(!strcmp(token, "getelementptr")){
			// ポインタの場合はアドレス値を算出するように復元
			sprintf(temp, "%s%s", token, line);
			free(line);
			line = calloc(strlen(temp)+1, 1);
			strcpy(line, temp);
			get_irtype_llvm(line, token);
		}

		create_adrs_getelementptr(token, token);
		str = regalloc(token);
		sprintf(temp, "\t\t\t__call_%s_args_%d <= %s;\n", name, args_num, str);
		free(str);
		strcat(buf, temp);

		// インターフェースの作成
		width = get_width(type);
		// call_sianal_treeへ登録
		if(!is_call) register_call_signal_tree(name, "args", args_num, width, 1);
		args_num++;

		// 次の","か")"まで読み飛ばし
		do{
			get_token_llvm(line, token);
		}while(strcmp(token, ",") && strcmp(token, ")"));
	}

	free(token);
	free(type);
	free(temp);
	free(line);

	return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x38, %rsp
movl %ecx, 0x1c(%rsp)
movq %rdx, %r15
movq %rsi, %rbx
movq %rdi, 0x20(%rsp)
movl $0x400, %edi            # imm = 0x400
movl $0x1, %esi
callq 0x1100
movq %rax, %r14
movl $0x400, %edi            # imm = 0x400
movl $0x1, %esi
callq 0x1100
movq %rax, 0x8(%rsp)
movl $0x400, %edi            # imm = 0x400
movl $0x1, %esi
callq 0x1100
movq %rax, 0x10(%rsp)
movq %rbx, %rdi
callq 0x1395
movq %rax, %rbp
movq %r15, 0x28(%rsp)
movb $0x0, (%r15)
movq %rax, %rdi
movq %r14, %rsi
callq 0xcc26
cmpb $0x0, (%rbp)
je 0x812b
leaq 0x69bb(%rip), %r12      # 0xe81a
leaq 0x6713(%rip), %r13      # 0xe579
leaq 0x72d0(%rip), %rbx      # 0xf13d
leaq 0x69ac(%rip), %r15      # 0xe820
movl $0x0, 0x4(%rsp)
movq %rbp, %rdi
movq %r14, %rsi
callq 0x201a
cmpb $0x0, (%r14)
je 0x812b
movq %r14, %rdi
leaq 0x6b02(%rip), %rsi      # 0xe99d
callq 0x1110
testl %eax, %eax
je 0x812b
movq 0x10(%rsp), %rdi
movq %r14, %rsi
callq 0x1060
movq %rbp, %rdi
movq %r14, %rsi
callq 0xcc26
movq %r14, %rdi
movq %r12, %rsi
callq 0x1110
testl %eax, %eax
jne 0x7ee5
movq %rbp, %rdi
movq %r14, %rsi
callq 0xcc26
movq %rbp, %rdi
movq %r14, %rsi
callq 0xcc26
movq %r14, %rdi
movq %r13, %rsi
callq 0x1110
testl %eax, %eax
je 0x7eb5
movq %r14, %rdi
movq %rbx, %rsi
callq 0x1110
testl %eax, %eax
je 0x7eb5
movq %r14, %rdi
movq %r15, %rsi
callq 0x1110
testl %eax, %eax
je 0x7eb5
movq %r14, %rdi
leaq 0x690a(%rip), %rsi      # 0xe826
callq 0x1110
testl %eax, %eax
je 0x7eb5
movq %r14, %rdi
leaq 0x68fd(%rip), %rsi      # 0xe82c
callq 0x1110
testl %eax, %eax
je 0x7eb5
movq %r14, %rdi
movq %r12, %rsi
callq 0x1110
testl %eax, %eax
je 0x7eb5
movq %r14, %rdi
leaq 0x71ec(%rip), %rsi      # 0xf145
callq 0x1110
testl %eax, %eax
je 0x7eb5
movq %r14, %rdi
leaq 0x68c1(%rip), %rsi      # 0xe831
callq 0x1110
testl %eax, %eax
je 0x7eb5
movq %r14, %rdi
leaq 0x68b4(%rip), %rsi      # 0xe83b
callq 0x1110
testl %eax, %eax
je 0x7eb5
movq %r14, %rdi
leaq 0x68a2(%rip), %rsi      # 0xe840
callq 0x1110
testl %eax, %eax
je 0x7eb5
movq %r14, %rdi
leaq 0x6894(%rip), %rsi      # 0xe849
callq 0x1110
testl %eax, %eax
je 0x7eb5
movq %r14, %rdi
leaq 0x6886(%rip), %rsi      # 0xe852
callq 0x1110
testl %eax, %eax
je 0x7eb5
movq %r14, %rdi
leaq 0x6878(%rip), %rsi      # 0xe85b
callq 0x1110
testl %eax, %eax
je 0x7eb5
movq %r14, %rdi
leaq 0x6871(%rip), %rsi      # 0xe86b
callq 0x1110
testl %eax, %eax
je 0x7eb5
movq %r14, %rdi
leaq 0x61a7(%rip), %rsi      # 0xe1b8
callq 0x1110
testl %eax, %eax
jne 0x806e
movq 0x8(%rsp), %rdi
leaq 0x6228(%rip), %rsi      # 0xe24e
movq %r14, %rdx
movq %rbp, %rcx
xorl %eax, %eax
callq 0x11b0
movq %rbp, %rdi
callq 0x1030
movq 0x8(%rsp), %rdi
callq 0x1090
leaq 0x1(%rax), %rdi
movl $0x1, %esi
callq 0x1100
movq %rax, %rbp
movq %rax, %rdi
movq 0x8(%rsp), %rsi
callq 0x1060
movq %rbp, %rdi
movq %r14, %rsi
callq 0x201a
movq %r14, %rdi
movq %r14, %rsi
callq 0x8160
movq %r14, %rdi
callq 0x7c87
movq %rax, 0x30(%rsp)
movq 0x8(%rsp), %rdi
leaq 0x70bb(%rip), %rsi      # 0xf14d
movq 0x20(%rsp), %rdx
movl 0x4(%rsp), %ecx
movq %rax, %r8
xorl %eax, %eax
callq 0x11b0
movq 0x30(%rsp), %rdi
callq 0x1030
movq 0x28(%rsp), %rdi
movq 0x8(%rsp), %rsi
callq 0x11a0
movq 0x10(%rsp), %rdi
callq 0x12ec
cmpl $0x0, 0x1c(%rsp)
jne 0x80ec
movq 0x20(%rsp), %rdi
leaq 0x708f(%rip), %rsi      # 0xf16a
movl 0x4(%rsp), %edx
movl %eax, %ecx
movl $0x1, %r8d
callq 0x5254
incl 0x4(%rsp)
movq %rbp, %rdi
movq %r14, %rsi
callq 0xcc26
movq %r14, %rdi
leaq 0x7997(%rip), %rsi      # 0xfa9c
callq 0x1110
testl %eax, %eax
je 0x8121
movq %r14, %rdi
leaq 0x6885(%rip), %rsi      # 0xe99d
callq 0x1110
testl %eax, %eax
jne 0x80f0
cmpb $0x0, (%rbp)
jne 0x7e7c
movq %r14, %rdi
callq 0x1030
movq 0x10(%rsp), %rdi
callq 0x1030
movq 0x8(%rsp), %rdi
callq 0x1030
movq %rbp, %rdi
callq 0x1030
xorl %eax, %eax
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq