// File: /workspace/github_c_makefile_star2_O1/aquaxis[P]synverll/src/parser_ir_top.c
// Function: create_top_assign
int create_top_assign()
{
	TOP_SIGNAL_TREE *now_top_signal_tree;
	char *verilog = NULL;
	char *wire = NULL;
	int i;

	wire = calloc(STR_MAX, 1);

	now_top_signal_tree = top_signal_tree_top;
    while(now_top_signal_tree != NULL){
		if(now_top_signal_tree->inout == SIG_IN){
//			sprintf(wire, "assign %s = ", now_top_signal_tree->label);
			sprintf(wire, "assign %s = ", now_top_signal_tree->verilog_signal);

			switch(now_top_signal_tree->flag){
				case FLAG_ARGS:
					verilog = search_top_signal_call_args(now_top_signal_tree->module_name, now_top_signal_tree->args_num);
					if(verilog != NULL){
						now_top_signal_tree->used = 1;
						sprintf(wire, "%s%s\n", wire, verilog);
						register_top_module_assign(wire);
					}
					break;
				case FLAG_CTRL:
					if(!strcmp(now_top_signal_tree->name, "__func_start")){
						verilog = search_top_signal_func("call", now_top_signal_tree->module_name, "req");
						if(verilog != NULL){
							now_top_signal_tree->used = 1;
							sprintf(wire, "%s%s\n", wire, verilog);
							register_top_module_assign(wire);
						}
					}
					break;
				case FLAG_CALL:
					if(!strcmp(now_top_signal_tree->name, "done")){
						verilog = search_top_signal_func("func", now_top_signal_tree->call_name, "done");
						if(verilog != NULL){
							now_top_signal_tree->used = 1;
							sprintf(wire, "%s%s\n", wire, verilog);
							register_top_module_assign(wire);
						}
					}else if(!strcmp(now_top_signal_tree->name, "ready")){
						verilog = search_top_signal_func("func", now_top_signal_tree->call_name, "ready");
						if(verilog != NULL){
							now_top_signal_tree->used = 1;
							sprintf(wire, "%s%s\n", wire, verilog);
							register_top_module_assign(wire);
						}
					}else if(!strcmp(now_top_signal_tree->name, "result")){
						verilog = search_top_signal_func("func", now_top_signal_tree->call_name, "result");
						if(verilog != NULL){
							now_top_signal_tree->used = 1;
							sprintf(wire, "%s%s\n", wire, verilog);
							register_top_module_assign(wire);
						}
					}
					break;
				case FLAG_GMEM:
					if(!strcmp(now_top_signal_tree->name, "__gm_done")){
						now_top_signal_tree->used = 1;
						sprintf(wire, "%s%s\n", wire, "__gm_done;");
						register_top_module_assign(wire);
					}else if(!strcmp(now_top_signal_tree->name, "__gm_di")){
						now_top_signal_tree->used = 1;
						sprintf(wire, "%s%s\n", wire, "__gm_di;");
						register_top_module_assign(wire);
					}else if(!strcmp(now_top_signal_tree->name, "__gm_base")){
						now_top_signal_tree->used = 1;
						sprintf(wire, "%s%s\n", wire, "__gm_base;");
						register_top_module_assign(wire);
					}
					break;
				default:
					break;
			}
		}
        now_top_signal_tree = now_top_signal_tree->next_ptr;
	}

	sprintf(wire, "\n");
	register_top_module_assign(wire);

if(use_gm_if){
	sprintf(wire, "// Global Memory\n");
	register_top_module_assign(wire);

	// Global Memory
	verilog = search_top_signal_func("gm", NULL, "req");
	sprintf(wire, "assign __gm_req = %s\n", verilog);
	register_top_module_assign(wire);

	verilog = search_top_signal_func("gm", NULL, "adrs");
	sprintf(wire, "assign __gm_adrs = %s\n", verilog);
	register_top_module_assign(wire);

	verilog = search_top_signal_func("gm", NULL, "rnw");
	sprintf(wire, "assign __gm_rnw = %s\n", verilog);
	register_top_module_assign(wire);

	verilog = search_top_signal_func("gm", NULL, "do");
	sprintf(wire, "assign __gm_do = %s\n", verilog);
	register_top_module_assign(wire);

	verilog = search_top_signal_func("gm", NULL, "leng");
	sprintf(wire, "assign __gm_leng = %s\n", verilog);
	register_top_module_assign(wire);

	sprintf(wire, "\n");
	register_top_module_assign(wire);
}
	// LLVM memcpy
	verilog = search_top_signal_func("call", "llvm_memcpy", "req");
	if(verilog != NULL){
		sprintf(wire, "// LLVM memcpy\n");
		register_top_module_assign(wire);

		sprintf(wire, "assign __llvm_memcpy_req = %s\n", verilog);
		register_top_module_assign(wire);

		use_llvm_memcpy = 1;
	}

	now_top_signal_tree = top_signal_tree_top;
    while(now_top_signal_tree != NULL){
		if(now_top_signal_tree->inout == SIG_IN){
			sprintf(wire, "assign %s = ", now_top_signal_tree->verilog_signal);

			if(now_top_signal_tree->flag == FLAG_CALL && !strcmp(now_top_signal_tree->call_name, "llvm_memcpy")){
				now_top_signal_tree->used = 1;
				sprintf(wire, "%s__llvm_memcpy_%s;\n", wire, now_top_signal_tree->name);
				register_top_module_assign(wire);
			}
		}
        now_top_signal_tree = now_top_signal_tree->next_ptr;
	}

	for(i = 0; i < 5; i++){
		sprintf(wire, "assign __llvm_memcpy_args_%d = ", i);
		verilog = search_top_signal_call_args("llvm_memcpy", i);
		if(verilog != NULL){
//			now_top_signal_tree->used = 1;
			sprintf(wire, "%s%s\n", wire, verilog);
			register_top_module_assign(wire);
		}
	}

	return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movl $0x400, %edi            # imm = 0x400
movl $0x1, %esi
callq 0x1100
movq %rax, %rbx
movq 0xa0c0(%rip), %r12      # 0x145c0
testq %r12, %r12
je 0xa6df
leaq 0x55c8(%rip), %r13      # 0xfad8
leaq 0x57db(%rip), %rbp      # 0xfcf2
cmpl $0x0, 0x1c(%r12)
jne 0xa69b
movq 0x50(%r12), %rdx
movq %rbx, %rdi
movq %rbp, %r14
leaq 0x55e2(%rip), %rsi      # 0xfb17
xorl %eax, %eax
callq 0x11b0
movl 0x30(%r12), %eax
decl %eax
cmpl $0x4, %eax
ja 0xa69b
movslq (%r13,%rax,4), %rax
addq %r13, %rax
jmpq *%rax
movq 0x38(%r12), %rdi
leaq 0x55c8(%rip), %rsi      # 0xfb2a
callq 0x1110
movq %r14, %rbp
testl %eax, %eax
jne 0xa69b
movq 0x28(%r12), %rsi
leaq 0x405d(%rip), %rdi      # 0xe5db
leaq 0x57a4(%rip), %rdx      # 0xfd29
jmp 0xa663
movq 0x28(%r12), %rdi
movl 0x48(%r12), %esi
callq 0xa283
jmp 0xa668
movq 0x38(%r12), %r15
movq %r15, %rdi
leaq 0x558f(%rip), %rsi      # 0xfb3c
callq 0x1110
movl %eax, %ecx
leaq 0x558b(%rip), %rax      # 0xfb46
testl %ecx, %ecx
je 0xa670
movq %r15, %rdi
leaq 0x5584(%rip), %rsi      # 0xfb51
callq 0x1110
movl %eax, %ecx
leaq 0x557e(%rip), %rax      # 0xfb59
testl %ecx, %ecx
je 0xa670
movq %r15, %rdi
leaq 0x5575(%rip), %rsi      # 0xfb62
callq 0x1110
movq %r14, %rbp
movl %eax, %ecx
leaq 0x556e(%rip), %rax      # 0xfb6c
testl %ecx, %ecx
jne 0xa69b
jmp 0xa670
movq 0x38(%r12), %r15
movq %r15, %rdi
movq %rbp, %rsi
callq 0x1110
testl %eax, %eax
je 0xa6ab
movq %r15, %rdi
leaq 0x56d4(%rip), %rbp      # 0xfcfe
movq %rbp, %rsi
callq 0x1110
testl %eax, %eax
je 0xa6c1
movq %r15, %rdi
leaq 0x579a(%rip), %rsi      # 0xfdde
callq 0x1110
testl %eax, %eax
movq %r14, %rbp
jne 0xa69b
movq 0x40(%r12), %rsi
leaq 0x54db(%rip), %rdi      # 0xfb37
leaq 0x577b(%rip), %rdx      # 0xfdde
callq 0xa375
movq %r14, %rbp
testq %rax, %rax
je 0xa69b
movl $0x1, 0x20(%r12)
movq %rbx, %rdi
leaq 0x54a1(%rip), %rsi      # 0xfb24
movq %rbx, %rdx
movq %rax, %rcx
xorl %eax, %eax
callq 0x11b0
movq %rbx, %rdi
callq 0xa02c
movq %r14, %rbp
movq 0x8(%r12), %r12
testq %r12, %r12
jne 0xa517
jmp 0xa6df
movq 0x40(%r12), %rsi
leaq 0x5480(%rip), %rdi      # 0xfb37
movq %rbp, %rdx
callq 0xa375
jmp 0xa66b
movq 0x40(%r12), %rsi
leaq 0x546a(%rip), %rdi      # 0xfb37
movq %rbp, %rdx
callq 0xa375
testq %rax, %rax
movq %r14, %rbp
jne 0xa670
jmp 0xa69b
movw $0xa, (%rbx)
movq %rbx, %rdi
callq 0xa02c
cmpl $0x0, 0x9ed9(%rip)      # 0x145cc
je 0xa806
movups 0x4604(%rip), %xmm0     # 0xed04
movups %xmm0, (%rbx)
movw $0xa, %bp
movw %bp, 0x10(%rbx)
movq %rbx, %rdi
callq 0xa02c
leaq 0x545d(%rip), %r14      # 0xfb77
leaq 0x5608(%rip), %rdx      # 0xfd29
movq %r14, %rdi
xorl %esi, %esi
callq 0xa375
leaq 0x5448(%rip), %rsi      # 0xfb7a
movq %rbx, %rdi
movq %rax, %rdx
xorl %eax, %eax
callq 0x11b0
movq %rbx, %rdi
callq 0xa02c
leaq 0x55ed(%rip), %rdx      # 0xfd3b
movq %r14, %rdi
xorl %esi, %esi
callq 0xa375
leaq 0x5431(%rip), %rsi      # 0xfb90
movq %rbx, %rdi
movq %rax, %rdx
xorl %eax, %eax
callq 0x11b0
movq %rbx, %rdi
callq 0xa02c
leaq 0x55b7(%rip), %rdx      # 0xfd32
movq %r14, %rdi
xorl %esi, %esi
callq 0xa375
leaq 0x541b(%rip), %rsi      # 0xfba7
movq %rbx, %rdi
movq %rax, %rdx
xorl %eax, %eax
callq 0x11b0
movq %rbx, %rdi
callq 0xa02c
leaq 0x5415(%rip), %rdx      # 0xfbbd
movq %r14, %rdi
xorl %esi, %esi
callq 0xa375
leaq 0x5407(%rip), %rsi      # 0xfbc0
movq %rbx, %rdi
movq %rax, %rdx
xorl %eax, %eax
callq 0x11b0
movq %rbx, %rdi
callq 0xa02c
leaq 0x5570(%rip), %rdx      # 0xfd45
movq %r14, %rdi
xorl %esi, %esi
callq 0xa375
leaq 0x53ef(%rip), %rsi      # 0xfbd5
movq %rbx, %rdi
movq %rax, %rdx
xorl %eax, %eax
callq 0x11b0
movq %rbx, %rdi
callq 0xa02c
movw %bp, (%rbx)
movq %rbx, %rdi
callq 0xa02c
leaq 0x3dce(%rip), %rdi      # 0xe5db
leaq 0x4a4e(%rip), %rsi      # 0xf262
leaq 0x550e(%rip), %rdx      # 0xfd29
callq 0xa375
testq %rax, %rax
je 0xa860
movq %rax, %r14
movups 0x53bd(%rip), %xmm0     # 0xfbec
movups %xmm0, (%rbx)
movq %rbx, %rdi
callq 0xa02c
leaq 0x53bb(%rip), %rsi      # 0xfbfc
movq %rbx, %rdi
movq %r14, %rdx
xorl %eax, %eax
callq 0x11b0
movq %rbx, %rdi
callq 0xa02c
movl $0x1, 0x9d68(%rip)      # 0x145c8
movq 0x9d59(%rip), %r13      # 0x145c0
testq %r13, %r13
je 0xa8dd
leaq 0x52a4(%rip), %r14      # 0xfb17
leaq 0x49e8(%rip), %r15      # 0xf262
leaq 0x539a(%rip), %r12      # 0xfc1b
cmpl $0x0, 0x1c(%r13)
jne 0xa8d4
movq 0x50(%r13), %rdx
movq %rbx, %rdi
movq %r14, %rsi
xorl %eax, %eax
callq 0x11b0
cmpl $0x5, 0x30(%r13)
jne 0xa8d4
movq 0x40(%r13), %rdi
movq %r15, %rsi
callq 0x1110
testl %eax, %eax
jne 0xa8d4
movl $0x1, 0x20(%r13)
movq 0x38(%r13), %rcx
movq %rbx, %rdi
movq %r12, %rsi
movq %rbx, %rdx
xorl %eax, %eax
callq 0x11b0
movq %rbx, %rdi
callq 0xa02c
movq 0x8(%r13), %r13
testq %r13, %r13
jne 0xa881
leaq 0x534c(%rip), %r14      # 0xfc30
leaq 0x4977(%rip), %r15      # 0xf262
leaq 0x5232(%rip), %r12      # 0xfb24
xorl %ebp, %ebp
movq %rbx, %rdi
movq %r14, %rsi
movl %ebp, %edx
xorl %eax, %eax
callq 0x11b0
movq %r15, %rdi
movl %ebp, %esi
callq 0xa283
testq %rax, %rax
je 0xa92d
movq %rbx, %rdi
movq %r12, %rsi
movq %rbx, %rdx
movq %rax, %rcx
xorl %eax, %eax
callq 0x11b0
movq %rbx, %rdi
callq 0xa02c
incl %ebp
cmpl $0x5, %ebp
jne 0xa8f4
xorl %eax, %eax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq