// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x30, %rsp
movq $0x0, -0x10(%rbp)
movq $0x0, -0x18(%rbp)
movl $0x400, %edi            # imm = 0x400
movl $0x1, %esi
callq 0x10c0
movq %rax, -0x18(%rbp)
movq 0xa18e(%rip), %rax      # 0x18590
movq %rax, -0x8(%rbp)
cmpq $0x0, -0x8(%rbp)
je 0xe784
movq -0x8(%rbp), %rax
cmpl $0x0, 0x1c(%rax)
jne 0xe773
movq -0x18(%rbp), %rdi
movq -0x8(%rbp), %rax
movq 0x50(%rax), %rdx
leaq 0x66c5(%rip), %rsi      # 0x14af7
xorl %eax, %eax
callq 0x1160
movq -0x8(%rbp), %rax
movl 0x30(%rax), %eax
decl %eax
movl %eax, %ecx
movq %rcx, -0x28(%rbp)
subl $0x4, %eax
ja 0xe76f
movq -0x28(%rbp), %rax
leaq 0x665c(%rip), %rcx      # 0x14ab8
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movq -0x8(%rbp), %rax
movq 0x28(%rax), %rdi
movq -0x8(%rbp), %rax
movl 0x48(%rax), %esi
callq 0xdf60
movq %rax, -0x10(%rbp)
cmpq $0x0, -0x10(%rbp)
je 0xe4b2
movq -0x8(%rbp), %rax
movl $0x1, 0x20(%rax)
movq -0x18(%rbp), %rdi
movq -0x18(%rbp), %rdx
movq -0x10(%rbp), %rcx
leaq 0x6662(%rip), %rsi      # 0x14b04
movb $0x0, %al
callq 0x1160
movq -0x18(%rbp), %rdi
callq 0xdc20
jmp 0xe771
movq -0x8(%rbp), %rax
movq 0x38(%rax), %rdi
leaq 0x6644(%rip), %rsi      # 0x14b0a
callq 0x10d0
cmpl $0x0, %eax
jne 0xe526
movq -0x8(%rbp), %rax
movq 0x28(%rax), %rsi
leaq 0x4d3e(%rip), %rdi      # 0x1321d
leaq 0x682d(%rip), %rdx      # 0x14d13
callq 0xe0e0
movq %rax, -0x10(%rbp)
cmpq $0x0, -0x10(%rbp)
je 0xe524
movq -0x8(%rbp), %rax
movl $0x1, 0x20(%rax)
movq -0x18(%rbp), %rdi
movq -0x18(%rbp), %rdx
movq -0x10(%rbp), %rcx
leaq 0x65f0(%rip), %rsi      # 0x14b04
movb $0x0, %al
callq 0x1160
movq -0x18(%rbp), %rdi
callq 0xdc20
jmp 0xe526
jmp 0xe771
movq -0x8(%rbp), %rax
movq 0x38(%rax), %rdi
leaq 0x67a2(%rip), %rsi      # 0x14cdc
callq 0x10d0
cmpl $0x0, %eax
jne 0xe59d
movq -0x8(%rbp), %rax
movq 0x40(%rax), %rsi
leaq 0x65c4(%rip), %rdi      # 0x14b17
leaq 0x6782(%rip), %rdx      # 0x14cdc
callq 0xe0e0
movq %rax, -0x10(%rbp)
cmpq $0x0, -0x10(%rbp)
je 0xe598
movq -0x8(%rbp), %rax
movl $0x1, 0x20(%rax)
movq -0x18(%rbp), %rdi
movq -0x18(%rbp), %rdx
movq -0x10(%rbp), %rcx
leaq 0x657c(%rip), %rsi      # 0x14b04
movb $0x0, %al
callq 0x1160
movq -0x18(%rbp), %rdi
callq 0xdc20
jmp 0xe67f
movq -0x8(%rbp), %rax
movq 0x38(%rax), %rdi
leaq 0x673c(%rip), %rsi      # 0x14ce8
callq 0x10d0
cmpl $0x0, %eax
jne 0xe60c
movq -0x8(%rbp), %rax
movq 0x40(%rax), %rsi
leaq 0x6552(%rip), %rdi      # 0x14b17
leaq 0x671c(%rip), %rdx      # 0x14ce8
callq 0xe0e0
movq %rax, -0x10(%rbp)
cmpq $0x0, -0x10(%rbp)
je 0xe60a
movq -0x8(%rbp), %rax
movl $0x1, 0x20(%rax)
movq -0x18(%rbp), %rdi
movq -0x18(%rbp), %rdx
movq -0x10(%rbp), %rcx
leaq 0x650a(%rip), %rsi      # 0x14b04
movb $0x0, %al
callq 0x1160
movq -0x18(%rbp), %rdi
callq 0xdc20
jmp 0xe67d
movq -0x8(%rbp), %rax
movq 0x38(%rax), %rdi
leaq 0x67b5(%rip), %rsi      # 0x14dd0
callq 0x10d0
cmpl $0x0, %eax
jne 0xe67b
movq -0x8(%rbp), %rax
movq 0x40(%rax), %rsi
leaq 0x64e3(%rip), %rdi      # 0x14b17
leaq 0x6795(%rip), %rdx      # 0x14dd0
callq 0xe0e0
movq %rax, -0x10(%rbp)
cmpq $0x0, -0x10(%rbp)
je 0xe679
movq -0x8(%rbp), %rax
movl $0x1, 0x20(%rax)
movq -0x18(%rbp), %rdi
movq -0x18(%rbp), %rdx
movq -0x10(%rbp), %rcx
leaq 0x649b(%rip), %rsi      # 0x14b04
movb $0x0, %al
callq 0x1160
movq -0x18(%rbp), %rdi
callq 0xdc20
jmp 0xe67b
jmp 0xe67d
jmp 0xe67f
jmp 0xe771
movq -0x8(%rbp), %rax
movq 0x38(%rax), %rdi
leaq 0x6489(%rip), %rsi      # 0x14b1c
callq 0x10d0
cmpl $0x0, %eax
jne 0xe6d3
movq -0x8(%rbp), %rax
movl $0x1, 0x20(%rax)
movq -0x18(%rbp), %rdi
movq -0x18(%rbp), %rdx
leaq 0x644d(%rip), %rsi      # 0x14b04
leaq 0x6468(%rip), %rcx      # 0x14b26
movb $0x0, %al
callq 0x1160
movq -0x18(%rbp), %rdi
callq 0xdc20
jmp 0xe76d
movq -0x8(%rbp), %rax
movq 0x38(%rax), %rdi
leaq 0x644f(%rip), %rsi      # 0x14b31
callq 0x10d0
cmpl $0x0, %eax
jne 0xe71f
movq -0x8(%rbp), %rax
movl $0x1, 0x20(%rax)
movq -0x18(%rbp), %rdi
movq -0x18(%rbp), %rdx
leaq 0x63fe(%rip), %rsi      # 0x14b04
leaq 0x642c(%rip), %rcx      # 0x14b39
movb $0x0, %al
callq 0x1160
movq -0x18(%rbp), %rdi
callq 0xdc20
jmp 0xe76b
movq -0x8(%rbp), %rax
movq 0x38(%rax), %rdi
leaq 0x6414(%rip), %rsi      # 0x14b42
callq 0x10d0
cmpl $0x0, %eax
jne 0xe769
movq -0x8(%rbp), %rax
movl $0x1, 0x20(%rax)
movq -0x18(%rbp), %rdi
movq -0x18(%rbp), %rdx
leaq 0x63b2(%rip), %rsi      # 0x14b04
leaq 0x63f3(%rip), %rcx      # 0x14b4c
movb $0x0, %al
callq 0x1160
movq -0x18(%rbp), %rdi
callq 0xdc20
jmp 0xe76b
jmp 0xe76d
jmp 0xe771
jmp 0xe771
jmp 0xe773
movq -0x8(%rbp), %rax
movq 0x8(%rax), %rax
movq %rax, -0x8(%rbp)
jmp 0xe406
movq -0x18(%rbp), %rdi
leaq 0x6831(%rip), %rsi      # 0x14fc0
movb $0x0, %al
callq 0x1160
movq -0x18(%rbp), %rdi
callq 0xdc20
cmpl $0x0, 0x9df6(%rip)      # 0x1859c
je 0xe904
movq -0x18(%rbp), %rdi
leaq 0x5545(%rip), %rsi      # 0x13cfc
movb $0x0, %al
callq 0x1160
movq -0x18(%rbp), %rdi
callq 0xdc20
leaq 0x6389(%rip), %rdi      # 0x14b57
xorl %eax, %eax
movl %eax, %esi
leaq 0x653a(%rip), %rdx      # 0x14d13
callq 0xe0e0
movq %rax, -0x10(%rbp)
movq -0x18(%rbp), %rdi
movq -0x10(%rbp), %rdx
leaq 0x6369(%rip), %rsi      # 0x14b5a
movb $0x0, %al
callq 0x1160
movq -0x18(%rbp), %rdi
callq 0xdc20
leaq 0x634f(%rip), %rdi      # 0x14b57
xorl %eax, %eax
movl %eax, %esi
leaq 0x6512(%rip), %rdx      # 0x14d25
callq 0xe0e0
movq %rax, -0x10(%rbp)
movq -0x18(%rbp), %rdi
movq -0x10(%rbp), %rdx
leaq 0x6345(%rip), %rsi      # 0x14b70
movb $0x0, %al
callq 0x1160
movq -0x18(%rbp), %rdi
callq 0xdc20
leaq 0x6315(%rip), %rdi      # 0x14b57
xorl %eax, %eax
movl %eax, %esi
leaq 0x64cf(%rip), %rdx      # 0x14d1c
callq 0xe0e0
movq %rax, -0x10(%rbp)
movq -0x18(%rbp), %rdi
movq -0x10(%rbp), %rdx
leaq 0x6322(%rip), %rsi      # 0x14b87
movb $0x0, %al
callq 0x1160
movq -0x18(%rbp), %rdi
callq 0xdc20
leaq 0x62db(%rip), %rdi      # 0x14b57
xorl %eax, %eax
movl %eax, %esi
leaq 0x64c1(%rip), %rdx      # 0x14d48
callq 0xe0e0
movq %rax, -0x10(%rbp)
movq -0x18(%rbp), %rdi
movq -0x10(%rbp), %rdx
leaq 0x62fe(%rip), %rsi      # 0x14b9d
movb $0x0, %al
callq 0x1160
movq -0x18(%rbp), %rdi
callq 0xdc20
leaq 0x62a1(%rip), %rdi      # 0x14b57
xorl %eax, %eax
movl %eax, %esi
leaq 0x646e(%rip), %rdx      # 0x14d2f
callq 0xe0e0
movq %rax, -0x10(%rbp)
movq -0x18(%rbp), %rdi
movq -0x10(%rbp), %rdx
leaq 0x62d9(%rip), %rsi      # 0x14bb2
movb $0x0, %al
callq 0x1160
movq -0x18(%rbp), %rdi
callq 0xdc20
movq -0x18(%rbp), %rdi
leaq 0x66cc(%rip), %rsi      # 0x14fc0
movb $0x0, %al
callq 0x1160
movq -0x18(%rbp), %rdi
callq 0xdc20
leaq 0x4912(%rip), %rdi      # 0x1321d
leaq 0x598c(%rip), %rsi      # 0x1429e
leaq 0x63fa(%rip), %rdx      # 0x14d13
callq 0xe0e0
movq %rax, -0x10(%rbp)
cmpq $0x0, -0x10(%rbp)
je 0xe96d
movq -0x18(%rbp), %rdi
leaq 0x6295(%rip), %rsi      # 0x14bc9
movb $0x0, %al
callq 0x1160
movq -0x18(%rbp), %rdi
callq 0xdc20
movq -0x18(%rbp), %rdi
movq -0x10(%rbp), %rdx
leaq 0x6286(%rip), %rsi      # 0x14bd9
movb $0x0, %al
callq 0x1160
movq -0x18(%rbp), %rdi
callq 0xdc20
movl $0x1, 0x9c2b(%rip)      # 0x18598
movq 0x9c1c(%rip), %rax      # 0x18590
movq %rax, -0x8(%rbp)
cmpq $0x0, -0x8(%rbp)
je 0xea0f
movq -0x8(%rbp), %rax
cmpl $0x0, 0x1c(%rax)
jne 0xe9fe
movq -0x18(%rbp), %rdi
movq -0x8(%rbp), %rax
movq 0x50(%rax), %rdx
leaq 0x6157(%rip), %rsi      # 0x14af7
movb $0x0, %al
callq 0x1160
movq -0x8(%rbp), %rax
cmpl $0x5, 0x30(%rax)
jne 0xe9fc
movq -0x8(%rbp), %rax
movq 0x40(%rax), %rdi
leaq 0x58de(%rip), %rsi      # 0x1429e
callq 0x10d0
cmpl $0x0, %eax
jne 0xe9fc
movq -0x8(%rbp), %rax
movl $0x1, 0x20(%rax)
movq -0x18(%rbp), %rdi
movq -0x18(%rbp), %rdx
movq -0x8(%rbp), %rax
movq 0x38(%rax), %rcx
leaq 0x620c(%rip), %rsi      # 0x14bf8
movb $0x0, %al
callq 0x1160
movq -0x18(%rbp), %rdi
callq 0xdc20
jmp 0xe9fe
movq -0x8(%rbp), %rax
movq 0x8(%rax), %rax
movq %rax, -0x8(%rbp)
jmp 0xe978
movl $0x0, -0x1c(%rbp)
cmpl $0x5, -0x1c(%rbp)
jge 0xea7b
movq -0x18(%rbp), %rdi
movl -0x1c(%rbp), %edx
leaq 0x61e3(%rip), %rsi      # 0x14c0d
movb $0x0, %al
callq 0x1160
movl -0x1c(%rbp), %esi
leaq 0x5863(%rip), %rdi      # 0x1429e
callq 0xdf60
movq %rax, -0x10(%rbp)
cmpq $0x0, -0x10(%rbp)
je 0xea6e
movq -0x18(%rbp), %rdi
movq -0x18(%rbp), %rdx
movq -0x10(%rbp), %rcx
leaq 0x60a6(%rip), %rsi      # 0x14b04
movb $0x0, %al
callq 0x1160
movq -0x18(%rbp), %rdi
callq 0xdc20
jmp 0xea70
movl -0x1c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x1c(%rbp)
jmp 0xea16
xorl %eax, %eax
addq $0x30, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)