// File: /workspace/github_c_makefile_star2_O0/aquaxis[P]synverll/src/parser.c
// Function: create_header_source
int create_header_source()
{
//    PARSER_TREE *now_parser_tree;
//    PARSER_TREE *parser_tree_process;
//    unsigned int now_level;
    char *token;
    char *line;
    int m = 0;
    FILE *fp;
    int size, start;
//    char *filename;
	char *const_extern = "extern \0";
	char *const_define = "#define \0";
	char *const_space = " \0";
	int i;
	char *const_extern_c = "__extern.c\0";
	char *const_extern_h = "__extern.h\0";

	char *const_grmem_func = "void __gr_mem(){\n";

    printf(" -> Create Header Source\n");

	token = calloc(STR_MAX, 1);

	/*
	 * グローバル変数用ソースコードの生成
	 */
	fp = fopen(const_extern_c, "wb+");
	fwrite(const_grmem_func, 1, strlen(const_grmem_func), fp);
    parser_tree_current = parser_tree_top;
    while(parser_tree_current != NULL){
        if(parser_tree_current->flag == PARSER_FLAG_LINE){
			size = strlen(parser_tree_current->line.body);
			fwrite(parser_tree_current->line.body, 1, size, fp);
			fwrite("\n\n", 1, 2, fp);
        }
        parser_tree_current = parser_tree_current->next_ptr;
    }
	fwrite("}\n", 1, 2, fp);
	fclose(fp);

	/*
	 * externヘッダファイルの生成
	 */
	fp = fopen(const_extern_h, "wb+");
    parser_tree_current = parser_tree_top;

	/*
	 * デファイン文
	 */
    while(parser_tree_current != NULL){
        if(parser_tree_current->flag == PARSER_FLAG_DEFINE){
			fwrite(const_define, 1, strlen(const_define), fp);
			size = strlen(parser_tree_current->define.name);
			fwrite(parser_tree_current->define.name, 1, size, fp);
			fwrite(const_space, 1, strlen(const_space), fp);
			size = strlen(parser_tree_current->define.value);
			fwrite(parser_tree_current->define.value, 1, size, fp);
			fwrite(const_space, 1, strlen(const_space), fp);
			fwrite("\n", 1, 1, fp);
		}
        parser_tree_current = parser_tree_current->next_ptr;
	}

	/*
	 * グローバル変数
	 */
    parser_tree_current = parser_tree_top;
    while(parser_tree_current != NULL){
        if(parser_tree_current->flag == PARSER_FLAG_LINE){
			// 予約語から
			m++;

			line = charalloc(parser_tree_current->line.body);

			// fopenのエラー処理が必要
			size = strlen(line);

			m = 0;
			// "="を見つけたら強制的に";\0"に変換する
			size = strlen(line);
			for(i = 0; i < size; i++){
				if(line[i] == '='){
					line[i] = ';';
					line[i+1] = '\0';
					break;
				}
			}

			// static宣言はextern宣言にして出力する
			// typedefはそのまま出力する
			// その他の宣言はextern化して出力する
			get_token(line, token);
			if(!strcmp(token, "static")){
				fwrite(const_extern, 1, strlen(const_extern), fp);
				start = strlen(const_space);
				size = strlen(line);
				fwrite(&line[start], 1, size-start, fp);
			}else if(!strcmp(token, "typedef")){
				fwrite(token, 1, strlen(token), fp);
				size = strlen(line);
				fwrite(line, 1, size, fp);
			}else{
				fwrite(const_extern, 1, strlen(const_extern), fp);
				fwrite(token, 1, strlen(token), fp);
				size = strlen(line);
				fwrite(line, 1, size, fp);
			}
			fwrite(const_space, 1, strlen(const_space), fp);
			fwrite("\n\n", 1, 2, fp);

			free(line);
        }
        parser_tree_current = parser_tree_current->next_ptr;
    }

	/*
	 * extern関数定義
	 */
    parser_tree_current = parser_tree_top;

    while(parser_tree_current != NULL){
        if(parser_tree_current->flag == PARSER_FLAG_PROCESS){
			// 予約語から
			m++;

			line = charalloc(parser_tree_current->line.body);
			// fopenのエラー処理が必要
			size = strlen(parser_tree_current->line.body);

			m = 0;
			// ")"を見つけたら強制的に";\0"に変換する
			size = strlen(line);
			for(i = 0; i < size; i++){
				if(line[i] == ')'){
					line[i+1] = ';';
					line[i+2] = '\0';
					break;
				}
			}

			// static宣言はextern宣言にして出力する
			// typedefはそのまま出力する
			// その他の宣言はextern化して出力する
			get_token(line, token);
			if(!strcmp(token, "static")){
				fwrite(const_extern, 1, strlen(const_extern), fp);
				start = strlen(const_space);
				size = strlen(line);
				fwrite(&line[start], 1, size-start, fp);
			}else{
				fwrite(const_extern, 1, strlen(const_extern), fp);
				fwrite(token, 1, strlen(token), fp);
				size = strlen(line);
				fwrite(line, 1, size, fp);
			}
			fwrite(const_space, 1, strlen(const_space), fp);
			fwrite("\n\n", 1, 2, fp);

			free(line);
        }
        parser_tree_current = parser_tree_current->next_ptr;
    }

	fclose(fp);

	free(token);

    return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xd0, %rsp
movl $0x0, -0x14(%rbp)
leaq 0x1188e(%rip), %rax     # 0x13047
movq %rax, -0x30(%rbp)
leaq 0x1188c(%rip), %rax     # 0x13050
movq %rax, -0x38(%rbp)
leaq 0x1188b(%rip), %rax     # 0x1305a
movq %rax, -0x40(%rbp)
leaq 0x11883(%rip), %rax     # 0x1305d
movq %rax, -0x50(%rbp)
leaq 0x11884(%rip), %rax     # 0x13069
movq %rax, -0x58(%rbp)
leaq 0x118a4(%rip), %rax     # 0x13094
movq %rax, -0x60(%rbp)
leaq 0x118ab(%rip), %rdi     # 0x130a6
movb $0x0, %al
callq 0x1090
movl $0x400, %edi            # imm = 0x400
movl $0x1, %esi
callq 0x10c0
movq %rax, -0x8(%rbp)
movq -0x50(%rbp), %rdi
leaq 0x11870(%rip), %rsi     # 0x13090
callq 0x1120
movq %rax, -0x20(%rbp)
movq -0x60(%rbp), %rax
movq %rax, -0x68(%rbp)
movq -0x60(%rbp), %rdi
callq 0x1070
movq -0x68(%rbp), %rdi
movq %rax, %rdx
movq -0x20(%rbp), %rcx
movl $0x1, %esi
callq 0x1180
movq 0x1689a(%rip), %rax     # 0x180f0
movq %rax, 0x1689b(%rip)     # 0x180f8
cmpq $0x0, 0x16893(%rip)     # 0x180f8
je 0x18d8
movq 0x1688a(%rip), %rax     # 0x180f8
cmpl $0x3d, 0x10(%rax)
jne 0x18c4
movq 0x1687d(%rip), %rax     # 0x180f8
movq 0x6c50(%rax), %rdi
callq 0x1070
movl %eax, -0x24(%rbp)
movq 0x16867(%rip), %rax     # 0x180f8
movq 0x6c50(%rax), %rdi
movslq -0x24(%rbp), %rdx
movq -0x20(%rbp), %rcx
movl $0x1, %esi
callq 0x1180
movq -0x20(%rbp), %rcx
leaq 0x1370a(%rip), %rdi     # 0x14fbf
movl $0x1, %esi
movl $0x2, %edx
callq 0x1180
movq 0x1682d(%rip), %rax     # 0x180f8
movq 0x8(%rax), %rax
movq %rax, 0x16822(%rip)     # 0x180f8
jmp 0x185d
movq -0x20(%rbp), %rcx
leaq 0x117dd(%rip), %rdi     # 0x130c0
movl $0x1, %esi
movl $0x2, %edx
callq 0x1180
movq -0x20(%rbp), %rdi
callq 0x1060
movq -0x58(%rbp), %rdi
leaq 0x1178a(%rip), %rsi     # 0x13090
callq 0x1120
movq %rax, -0x20(%rbp)
movq 0x167da(%rip), %rax     # 0x180f0
movq %rax, 0x167db(%rip)     # 0x180f8
cmpq $0x0, 0x167d3(%rip)     # 0x180f8
je 0x1a4b
movq 0x167c6(%rip), %rax     # 0x180f8
cmpl $0x3, 0x10(%rax)
jne 0x1a34
movq -0x38(%rbp), %rax
movq %rax, -0x80(%rbp)
movq -0x38(%rbp), %rdi
callq 0x1070
movq -0x80(%rbp), %rdi
movq %rax, %rdx
movq -0x20(%rbp), %rcx
movl $0x1, %esi
callq 0x1180
movq 0x1678f(%rip), %rdi     # 0x180f8
addq $0x20, %rdi
callq 0x1070
movl %eax, -0x24(%rbp)
movq 0x1677c(%rip), %rdi     # 0x180f8
addq $0x20, %rdi
movslq -0x24(%rbp), %rdx
movq -0x20(%rbp), %rcx
movl $0x1, %esi
callq 0x1180
movq -0x40(%rbp), %rax
movq %rax, -0x78(%rbp)
movq -0x40(%rbp), %rdi
callq 0x1070
movq -0x78(%rbp), %rdi
movq %rax, %rdx
movq -0x20(%rbp), %rcx
movl $0x1, %esi
callq 0x1180
movq 0x16739(%rip), %rdi     # 0x180f8
addq $0x20, %rdi
addq $0x400, %rdi            # imm = 0x400
callq 0x1070
movl %eax, -0x24(%rbp)
movq 0x1671f(%rip), %rdi     # 0x180f8
addq $0x20, %rdi
addq $0x400, %rdi            # imm = 0x400
movslq -0x24(%rbp), %rdx
movq -0x20(%rbp), %rcx
movl $0x1, %esi
callq 0x1180
movq -0x40(%rbp), %rax
movq %rax, -0x70(%rbp)
movq -0x40(%rbp), %rdi
callq 0x1070
movq -0x70(%rbp), %rdi
movq %rax, %rdx
movq -0x20(%rbp), %rcx
movl $0x1, %esi
callq 0x1180
movq -0x20(%rbp), %rcx
leaq 0x13599(%rip), %rdi     # 0x14fc0
movl $0x1, %edx
movq %rdx, %rsi
callq 0x1180
movq 0x166bd(%rip), %rax     # 0x180f8
movq 0x8(%rax), %rax
movq %rax, 0x166b2(%rip)     # 0x180f8
jmp 0x191d
movq 0x1669e(%rip), %rax     # 0x180f0
movq %rax, 0x1669f(%rip)     # 0x180f8
cmpq $0x0, 0x16697(%rip)     # 0x180f8
je 0x1cd7
movq 0x1668a(%rip), %rax     # 0x180f8
cmpl $0x3d, 0x10(%rax)
jne 0x1cc0
movl -0x14(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x14(%rbp)
movq 0x16670(%rip), %rax     # 0x180f8
movq 0x6c50(%rax), %rdi
callq 0x13b0
movq %rax, -0x10(%rbp)
movq -0x10(%rbp), %rdi
callq 0x1070
movl %eax, -0x24(%rbp)
movl $0x0, -0x14(%rbp)
movq -0x10(%rbp), %rdi
callq 0x1070
movl %eax, -0x24(%rbp)
movl $0x0, -0x44(%rbp)
movl -0x44(%rbp), %eax
cmpl -0x24(%rbp), %eax
jge 0x1b03
movq -0x10(%rbp), %rax
movslq -0x44(%rbp), %rcx
movsbl (%rax,%rcx), %eax
cmpl $0x3d, %eax
jne 0x1af6
movq -0x10(%rbp), %rax
movslq -0x44(%rbp), %rcx
movb $0x3b, (%rax,%rcx)
movq -0x10(%rbp), %rax
movl -0x44(%rbp), %ecx
addl $0x1, %ecx
movslq %ecx, %rcx
movb $0x0, (%rax,%rcx)
jmp 0x1b03
jmp 0x1af8
movl -0x44(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x44(%rbp)
jmp 0x1abe
movq -0x10(%rbp), %rdi
movq -0x8(%rbp), %rsi
callq 0x10eb0
movq -0x8(%rbp), %rdi
leaq 0x115a8(%rip), %rsi     # 0x130c3
callq 0x10d0
cmpl $0x0, %eax
jne 0x1b90
movq -0x30(%rbp), %rax
movq %rax, -0x88(%rbp)
movq -0x30(%rbp), %rdi
callq 0x1070
movq -0x88(%rbp), %rdi
movq %rax, %rdx
movq -0x20(%rbp), %rcx
movl $0x1, %esi
callq 0x1180
movq -0x40(%rbp), %rdi
callq 0x1070
movl %eax, -0x28(%rbp)
movq -0x10(%rbp), %rdi
callq 0x1070
movl %eax, -0x24(%rbp)
movq -0x10(%rbp), %rdi
movslq -0x28(%rbp), %rax
addq %rax, %rdi
movl -0x24(%rbp), %eax
subl -0x28(%rbp), %eax
movslq %eax, %rdx
movq -0x20(%rbp), %rcx
movl $0x1, %esi
callq 0x1180
jmp 0x1c71
movq -0x8(%rbp), %rdi
leaq 0x1152f(%rip), %rsi     # 0x130ca
callq 0x10d0
cmpl $0x0, %eax
jne 0x1bf5
movq -0x8(%rbp), %rax
movq %rax, -0x90(%rbp)
movq -0x8(%rbp), %rdi
callq 0x1070
movq -0x90(%rbp), %rdi
movq %rax, %rdx
movq -0x20(%rbp), %rcx
movl $0x1, %esi
callq 0x1180
movq -0x10(%rbp), %rdi
callq 0x1070
movl %eax, -0x24(%rbp)
movq -0x10(%rbp), %rdi
movslq -0x24(%rbp), %rdx
movq -0x20(%rbp), %rcx
movl $0x1, %esi
callq 0x1180
jmp 0x1c6f
movq -0x30(%rbp), %rax
movq %rax, -0xa0(%rbp)
movq -0x30(%rbp), %rdi
callq 0x1070
movq -0xa0(%rbp), %rdi
movq %rax, %rdx
movq -0x20(%rbp), %rcx
movl $0x1, %esi
callq 0x1180
movq -0x8(%rbp), %rax
movq %rax, -0x98(%rbp)
movq -0x8(%rbp), %rdi
callq 0x1070
movq -0x98(%rbp), %rdi
movq %rax, %rdx
movq -0x20(%rbp), %rcx
movl $0x1, %esi
callq 0x1180
movq -0x10(%rbp), %rdi
callq 0x1070
movl %eax, -0x24(%rbp)
movq -0x10(%rbp), %rdi
movslq -0x24(%rbp), %rdx
movq -0x20(%rbp), %rcx
movl $0x1, %esi
callq 0x1180
jmp 0x1c71
movq -0x40(%rbp), %rax
movq %rax, -0xa8(%rbp)
movq -0x40(%rbp), %rdi
callq 0x1070
movq -0xa8(%rbp), %rdi
movq %rax, %rdx
movq -0x20(%rbp), %rcx
movl $0x1, %esi
callq 0x1180
movq -0x20(%rbp), %rcx
leaq 0x13317(%rip), %rdi     # 0x14fbf
movl $0x1, %esi
movl $0x2, %edx
callq 0x1180
movq -0x10(%rbp), %rdi
callq 0x1030
movq 0x16431(%rip), %rax     # 0x180f8
movq 0x8(%rax), %rax
movq %rax, 0x16426(%rip)     # 0x180f8
jmp 0x1a59
movq 0x16412(%rip), %rax     # 0x180f0
movq %rax, 0x16413(%rip)     # 0x180f8
cmpq $0x0, 0x1640b(%rip)     # 0x180f8
je 0x1f08
movq 0x163fe(%rip), %rax     # 0x180f8
cmpl $0x19, 0x10(%rax)
jne 0x1ef1
movl -0x14(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x14(%rbp)
movq 0x163e4(%rip), %rax     # 0x180f8
movq 0x6c50(%rax), %rdi
callq 0x13b0
movq %rax, -0x10(%rbp)
movq 0x163cd(%rip), %rax     # 0x180f8
movq 0x6c50(%rax), %rdi
callq 0x1070
movl %eax, -0x24(%rbp)
movl $0x0, -0x14(%rbp)
movq -0x10(%rbp), %rdi
callq 0x1070
movl %eax, -0x24(%rbp)
movl $0x0, -0x44(%rbp)
movl -0x44(%rbp), %eax
cmpl -0x24(%rbp), %eax
jge 0x1d9e
movq -0x10(%rbp), %rax
movslq -0x44(%rbp), %rcx
movsbl (%rax,%rcx), %eax
cmpl $0x29, %eax
jne 0x1d91
movq -0x10(%rbp), %rax
movl -0x44(%rbp), %ecx
addl $0x1, %ecx
movslq %ecx, %rcx
movb $0x3b, (%rax,%rcx)
movq -0x10(%rbp), %rax
movl -0x44(%rbp), %ecx
addl $0x2, %ecx
movslq %ecx, %rcx
movb $0x0, (%rax,%rcx)
jmp 0x1d9e
jmp 0x1d93
movl -0x44(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x44(%rbp)
jmp 0x1d54
movq -0x10(%rbp), %rdi
movq -0x8(%rbp), %rsi
callq 0x10eb0
movq -0x8(%rbp), %rdi
leaq 0x1130d(%rip), %rsi     # 0x130c3
callq 0x10d0
cmpl $0x0, %eax
jne 0x1e28
movq -0x30(%rbp), %rax
movq %rax, -0xb0(%rbp)
movq -0x30(%rbp), %rdi
callq 0x1070
movq -0xb0(%rbp), %rdi
movq %rax, %rdx
movq -0x20(%rbp), %rcx
movl $0x1, %esi
callq 0x1180
movq -0x40(%rbp), %rdi
callq 0x1070
movl %eax, -0x28(%rbp)
movq -0x10(%rbp), %rdi
callq 0x1070
movl %eax, -0x24(%rbp)
movq -0x10(%rbp), %rdi
movslq -0x28(%rbp), %rax
addq %rax, %rdi
movl -0x24(%rbp), %eax
subl -0x28(%rbp), %eax
movslq %eax, %rdx
movq -0x20(%rbp), %rcx
movl $0x1, %esi
callq 0x1180
jmp 0x1ea2
movq -0x30(%rbp), %rax
movq %rax, -0xc0(%rbp)
movq -0x30(%rbp), %rdi
callq 0x1070
movq -0xc0(%rbp), %rdi
movq %rax, %rdx
movq -0x20(%rbp), %rcx
movl $0x1, %esi
callq 0x1180
movq -0x8(%rbp), %rax
movq %rax, -0xb8(%rbp)
movq -0x8(%rbp), %rdi
callq 0x1070
movq -0xb8(%rbp), %rdi
movq %rax, %rdx
movq -0x20(%rbp), %rcx
movl $0x1, %esi
callq 0x1180
movq -0x10(%rbp), %rdi
callq 0x1070
movl %eax, -0x24(%rbp)
movq -0x10(%rbp), %rdi
movslq -0x24(%rbp), %rdx
movq -0x20(%rbp), %rcx
movl $0x1, %esi
callq 0x1180
movq -0x40(%rbp), %rax
movq %rax, -0xc8(%rbp)
movq -0x40(%rbp), %rdi
callq 0x1070
movq -0xc8(%rbp), %rdi
movq %rax, %rdx
movq -0x20(%rbp), %rcx
movl $0x1, %esi
callq 0x1180
movq -0x20(%rbp), %rcx
leaq 0x130e6(%rip), %rdi     # 0x14fbf
movl $0x1, %esi
movl $0x2, %edx
callq 0x1180
movq -0x10(%rbp), %rdi
callq 0x1030
movq 0x16200(%rip), %rax     # 0x180f8
movq 0x8(%rax), %rax
movq %rax, 0x161f5(%rip)     # 0x180f8
jmp 0x1ce5
movq -0x20(%rbp), %rdi
callq 0x1060
movq -0x8(%rbp), %rdi
callq 0x1030
xorl %eax, %eax
addq $0xd0, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)