// File: /workspace/github_c_makefile_star2_O2/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
pushq $0x1
popq %rsi
movl $0x400, %edi            # imm = 0x400
callq 0x10f0
movq %rax, %rbx
leaq 0x9624(%rip), %r12      # 0x135b0
leaq 0x4b19(%rip), %r13      # 0xeaac
leaq 0x4d2c(%rip), %rbp      # 0xecc6
movq (%r12), %r12
testq %r12, %r12
je 0xa168
cmpl $0x0, 0x1c(%r12)
jne 0xa12b
movq 0x50(%r12), %rdx
movq %rbx, %rdi
movq %rbp, %r14
leaq 0x4b26(%rip), %rsi      # 0xeaeb
xorl %eax, %eax
callq 0x11a0
movl 0x30(%r12), %eax
decl %eax
cmpl $0x4, %eax
ja 0xa12b
movslq (%r13,%rax,4), %rax
addq %r13, %rax
jmpq *%rax
movq 0x38(%r12), %rdi
leaq 0x4b0c(%rip), %rsi      # 0xeafe
callq 0x1100
movq %r14, %rbp
testl %eax, %eax
jne 0xa12b
movq 0x28(%r12), %rsi
leaq 0x35bf(%rip), %rdi      # 0xd5cd
leaq 0x4ce8(%rip), %rdx      # 0xecfd
jmp 0xa0f3
movq 0x28(%r12), %rdi
movl 0x48(%r12), %esi
callq 0x9d14
jmp 0xa0f8
movq 0x38(%r12), %r15
movq %r15, %rdi
leaq 0x4ad3(%rip), %rsi      # 0xeb10
callq 0x1100
movl %eax, %ecx
leaq 0x4acf(%rip), %rax      # 0xeb1a
testl %ecx, %ecx
je 0xa100
movq %r15, %rdi
leaq 0x4ac8(%rip), %rsi      # 0xeb25
callq 0x1100
movl %eax, %ecx
leaq 0x4ac2(%rip), %rax      # 0xeb2d
testl %ecx, %ecx
je 0xa100
movq %r15, %rdi
leaq 0x4ab9(%rip), %rsi      # 0xeb36
callq 0x1100
movq %r14, %rbp
movl %eax, %ecx
leaq 0x4ab2(%rip), %rax      # 0xeb40
testl %ecx, %ecx
jne 0xa12b
jmp 0xa100
movq 0x38(%r12), %r15
movq %r15, %rdi
movq %rbp, %rsi
callq 0x1100
testl %eax, %eax
je 0xa134
movq %r15, %rdi
leaq 0x4c18(%rip), %rbp      # 0xecd2
movq %rbp, %rsi
callq 0x1100
testl %eax, %eax
je 0xa14a
movq %r15, %rdi
leaq 0x4cde(%rip), %rsi      # 0xedb2
callq 0x1100
testl %eax, %eax
movq %r14, %rbp
jne 0xa12b
movq 0x40(%r12), %rsi
leaq 0x4a1f(%rip), %rdi      # 0xeb0b
leaq 0x4cbf(%rip), %rdx      # 0xedb2
callq 0x9e04
movq %r14, %rbp
testq %rax, %rax
je 0xa12b
movl $0x1, 0x20(%r12)
movq %rbx, %rdi
leaq 0x49e5(%rip), %rsi      # 0xeaf8
movq %rbx, %rdx
movq %rax, %rcx
xorl %eax, %eax
callq 0x11a0
movq %rbx, %rdi
callq 0x9ac7
movq %r14, %rbp
addq $0x8, %r12
jmp 0x9f9a
movq 0x40(%r12), %rsi
leaq 0x49cb(%rip), %rdi      # 0xeb0b
movq %rbp, %rdx
callq 0x9e04
jmp 0xa0fb
movq 0x40(%r12), %rsi
leaq 0x49b5(%rip), %rdi      # 0xeb0b
movq %rbp, %rdx
callq 0x9e04
testq %rax, %rax
movq %r14, %rbp
jne 0xa100
jmp 0xa12b
movw $0xa, (%rbx)
movq %rbx, %rdi
callq 0x9ac7
cmpl $0x0, 0x9440(%rip)      # 0x135bc
je 0xa28f
movups 0x3b4f(%rip), %xmm0     # 0xdcd8
movups %xmm0, (%rbx)
movw $0xa, %bp
movw %bp, 0x10(%rbx)
movq %rbx, %rdi
callq 0x9ac7
leaq 0x49a8(%rip), %r14      # 0xeb4b
leaq 0x4b53(%rip), %rdx      # 0xecfd
movq %r14, %rdi
xorl %esi, %esi
callq 0x9e04
leaq 0x4993(%rip), %rsi      # 0xeb4e
movq %rbx, %rdi
movq %rax, %rdx
xorl %eax, %eax
callq 0x11a0
movq %rbx, %rdi
callq 0x9ac7
leaq 0x4b38(%rip), %rdx      # 0xed0f
movq %r14, %rdi
xorl %esi, %esi
callq 0x9e04
leaq 0x497c(%rip), %rsi      # 0xeb64
movq %rbx, %rdi
movq %rax, %rdx
xorl %eax, %eax
callq 0x11a0
movq %rbx, %rdi
callq 0x9ac7
leaq 0x4b02(%rip), %rdx      # 0xed06
movq %r14, %rdi
xorl %esi, %esi
callq 0x9e04
leaq 0x4966(%rip), %rsi      # 0xeb7b
movq %rbx, %rdi
movq %rax, %rdx
xorl %eax, %eax
callq 0x11a0
movq %rbx, %rdi
callq 0x9ac7
leaq 0x4960(%rip), %rdx      # 0xeb91
movq %r14, %rdi
xorl %esi, %esi
callq 0x9e04
leaq 0x4952(%rip), %rsi      # 0xeb94
movq %rbx, %rdi
movq %rax, %rdx
xorl %eax, %eax
callq 0x11a0
movq %rbx, %rdi
callq 0x9ac7
leaq 0x4abb(%rip), %rdx      # 0xed19
movq %r14, %rdi
xorl %esi, %esi
callq 0x9e04
leaq 0x493a(%rip), %rsi      # 0xeba9
movq %rbx, %rdi
movq %rax, %rdx
xorl %eax, %eax
callq 0x11a0
movq %rbx, %rdi
callq 0x9ac7
movw %bp, (%rbx)
movq %rbx, %rdi
callq 0x9ac7
leaq 0x3337(%rip), %rdi      # 0xd5cd
leaq 0x3f99(%rip), %rsi      # 0xe236
leaq 0x4a59(%rip), %rdx      # 0xecfd
callq 0x9e04
testq %rax, %rax
je 0xa2e9
movq %rax, %r14
movups 0x4908(%rip), %xmm0     # 0xebc0
movups %xmm0, (%rbx)
movq %rbx, %rdi
callq 0x9ac7
leaq 0x4906(%rip), %rsi      # 0xebd0
movq %rbx, %rdi
movq %r14, %rdx
xorl %eax, %eax
callq 0x11a0
movq %rbx, %rdi
callq 0x9ac7
movl $0x1, 0x92cf(%rip)      # 0x135b8
leaq 0x92c0(%rip), %r13      # 0x135b0
leaq 0x47f4(%rip), %r14      # 0xeaeb
leaq 0x3f38(%rip), %r15      # 0xe236
leaq 0x48ea(%rip), %r12      # 0xebef
movq (%r13), %r13
testq %r13, %r13
je 0xa367
cmpl $0x0, 0x1c(%r13)
jne 0xa361
movq 0x50(%r13), %rdx
movq %rbx, %rdi
movq %r14, %rsi
xorl %eax, %eax
callq 0x11a0
cmpl $0x5, 0x30(%r13)
jne 0xa361
movq 0x40(%r13), %rdi
movq %r15, %rsi
callq 0x1100
testl %eax, %eax
jne 0xa361
movl $0x1, 0x20(%r13)
movq 0x38(%r13), %rcx
movq %rbx, %rdi
movq %r12, %rsi
movq %rbx, %rdx
xorl %eax, %eax
callq 0x11a0
movq %rbx, %rdi
callq 0x9ac7
addq $0x8, %r13
jmp 0xa305
leaq 0x4896(%rip), %r14      # 0xec04
leaq 0x3ec1(%rip), %r15      # 0xe236
leaq 0x477c(%rip), %r12      # 0xeaf8
xorl %ebp, %ebp
cmpl $0x5, %ebp
je 0xa3c0
movq %rbx, %rdi
movq %r14, %rsi
movl %ebp, %edx
xorl %eax, %eax
callq 0x11a0
movq %r15, %rdi
movl %ebp, %esi
callq 0x9d14
testq %rax, %rax
je 0xa3bc
movq %rbx, %rdi
movq %r12, %rsi
movq %rbx, %rdx
movq %rax, %rcx
xorl %eax, %eax
callq 0x11a0
movq %rbx, %rdi
callq 0x9ac7
incl %ebp
jmp 0xa37e
xorl %eax, %eax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq