#define NULL ((void *)0)
typedef unsigned long size_t; // Customize by platform.
typedef long intptr_t;
typedef unsigned long uintptr_t;
typedef long scalar_t__; // Either arithmetic or pointer type.
/* By default, we understand bool (as a convenience). */
typedef int bool;
#define false 0
#define true 1

/* Forward declarations */

/* Type definitions */
struct grammar {
  int dummy;
};
struct code_node {
  int dummy;
};
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, ...);
int /*<<< orphan*/ gen_free(int /*<<< orphan*/ *, struct grammar *);
int /*<<< orphan*/ gen_goto(int /*<<< orphan*/ *, struct grammar *);
int /*<<< orphan*/ gen_known(int /*<<< orphan*/ *, struct grammar *);
int /*<<< orphan*/ gen_non_term(int /*<<< orphan*/ *, struct grammar *);
int /*<<< orphan*/ gen_reduce(int /*<<< orphan*/ *, struct grammar *, char *,
                              struct code_node *);
int /*<<< orphan*/ gen_states(int /*<<< orphan*/ *, struct grammar *);
void gen_parser(FILE *f, struct grammar *g, char *file, char *name,
                struct code_node *pre_reduce) {
  gen_known(f, g);
  gen_non_term(f, g);
  gen_goto(f, g);
  gen_states(f, g);
  gen_reduce(f, g, file, pre_reduce);
  gen_free(f, g);
  fprintf(f, "#line 0 \"gen_parser\"\n");
  fprintf(f,
          "void *parse_%s(struct code_node *code, struct token_config *config, "
          "FILE *trace)\n",
          name);
  fprintf(f, "{\n");
  fprintf(f, "\tstruct token_state *tokens;\n");
  fprintf(f, "\tconfig->words_marks = known;\n");
  fprintf(f, "\tconfig->known_count = sizeof(known)/sizeof(known[0]);\n");
  fprintf(f, "\tconfig->ignored |= (1 << TK_line_comment) | (1 << "
             "TK_block_comment);\n");
  fprintf(f, "\ttokens = token_open(code, config);\n");
  fprintf(f, "\tvoid *rv = parser_run(tokens, states, do_reduce, do_free, "
             "trace, non_term, config);\n");
  fprintf(f, "\ttoken_close(tokens);\n");
  fprintf(f, "\treturn rv;\n");
  fprintf(f, "}\n\n");
}


x86 assembly (clang, -O0):
<gen_parser>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    %r8,-0x28(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1050 <gen_known@plt>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1060 <gen_non_term@plt>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1070 <gen_goto@plt>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1080 <gen_states@plt>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
mov    -0x28(%rbp),%rcx
call   1090 <gen_reduce@plt>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1040 <gen_free@plt>
mov    -0x8(%rbp),%rdi
lea    0xe13(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
mov    -0x8(%rbp),%rdi
mov    -0x20(%rbp),%rdx
lea    0xe13(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
mov    -0x8(%rbp),%rdi
lea    0xe53(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
mov    -0x8(%rbp),%rdi
lea    0xe44(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
mov    -0x8(%rbp),%rdi
lea    0xe50(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
mov    -0x8(%rbp),%rdi
lea    0xe5d(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
mov    -0x8(%rbp),%rdi
lea    0xe83(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
mov    -0x8(%rbp),%rdi
lea    0xeb8(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
mov    -0x8(%rbp),%rdi
lea    0xecb(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
mov    -0x8(%rbp),%rdi
lea    0xf0f(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
mov    -0x8(%rbp),%rdi
lea    0xf14(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
mov    -0x8(%rbp),%rdi
lea    0xf0f(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<gen_parser>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
mov    %r8,%r12
mov    %rcx,%r14
mov    %rdx,%r13
mov    %rsi,%rbx
mov    %rdi,%r15
call   1050 <gen_known@plt>
mov    %r15,%rdi
mov    %rbx,%rsi
call   1060 <gen_non_term@plt>
mov    %r15,%rdi
mov    %rbx,%rsi
call   1070 <gen_goto@plt>
mov    %r15,%rdi
mov    %rbx,%rsi
call   1080 <gen_states@plt>
mov    %r15,%rdi
mov    %rbx,%rsi
mov    %r13,%rdx
mov    %r12,%rcx
call   10a0 <gen_reduce@plt>
mov    %r15,%rdi
mov    %rbx,%rsi
call   1040 <gen_free@plt>
lea    0xe1f(%rip),%rdi
mov    $0x15,%esi
mov    $0x1,%edx
mov    %r15,%rcx
call   1090 <fwrite@plt>
lea    0xe1c(%rip),%rsi
mov    %r15,%rdi
mov    %r14,%rdx
xor    %eax,%eax
call   1030 <fprintf@plt>
lea    0xe5a(%rip),%rdi
mov    $0x2,%esi
mov    $0x1,%edx
mov    %r15,%rcx
call   1090 <fwrite@plt>
lea    0xe44(%rip),%rdi
mov    $0x1d,%esi
mov    $0x1,%edx
mov    %r15,%rcx
call   1090 <fwrite@plt>
lea    0xe49(%rip),%rdi
mov    $0x1e,%esi
mov    $0x1,%edx
mov    %r15,%rcx
call   1090 <fwrite@plt>
lea    0xe4f(%rip),%rdi
mov    $0x37,%esi
mov    $0x1,%edx
mov    %r15,%rcx
call   1090 <fwrite@plt>
lea    0xe6e(%rip),%rdi
mov    $0x46,%esi
mov    $0x1,%edx
mov    %r15,%rcx
call   1090 <fwrite@plt>
lea    0xe9c(%rip),%rdi
mov    $0x24,%esi
mov    $0x1,%edx
mov    %r15,%rcx
call   1090 <fwrite@plt>
lea    0xea8(%rip),%rdi
mov    $0x55,%esi
mov    $0x1,%edx
mov    %r15,%rcx
call   1090 <fwrite@plt>
lea    0xee5(%rip),%rdi
mov    $0x16,%esi
mov    $0x1,%edx
mov    %r15,%rcx
call   1090 <fwrite@plt>
lea    0xee3(%rip),%rdi
mov    $0xc,%esi
mov    $0x1,%edx
mov    %r15,%rcx
call   1090 <fwrite@plt>
lea    0xed7(%rip),%rdi
mov    $0x3,%esi
mov    $0x1,%edx
mov    %r15,%rcx
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
jmp    1090 <fwrite@plt>

LLVM IR (-O0):
%struct.grammar = type { i32 }
%struct.code_node = type { i32 }
@.str = [22 x i8] c"#line 0 \22gen_parser\22\0A\00"
@.str.1 = [82 x i8] c"void *parse_%s(struct code_node *code, struct token_config *config, FILE *trace)\0A\00"
@.str.2 = [3 x i8] c"{\0A\00"
@.str.3 = [30 x i8] c"\09struct token_state *tokens;\0A\00"
@.str.4 = [31 x i8] c"\09config->words_marks = known;\0A\00"
@.str.5 = [56 x i8] c"\09config->known_count = sizeof(known)/sizeof(known[0]);\0A\00"
@.str.6 = [71 x i8] c"\09config->ignored |= (1 << TK_line_comment) | (1 << TK_block_comment);\0A\00"
@.str.7 = [37 x i8] c"\09tokens = token_open(code, config);\0A\00"
@.str.8 = [86 x i8] c"\09void *rv = parser_run(tokens, states, do_reduce, do_free, trace, non_term, config);\0A\00"
@.str.9 = [23 x i8] c"\09token_close(tokens);\0A\00"
@.str.10 = [13 x i8] c"\09return rv;\0A\00"
@.str.11 = [4 x i8] c"}\0A\0A\00"
define void @gen_parser(i32* %0, %struct.grammar* %1, i8* %2, i8* %3, %struct.code_node* %4) {
%6 = alloca i32*
%7 = alloca %struct.grammar*
%8 = alloca i8*
%9 = alloca i8*
%10 = alloca %struct.code_node*
store i32* %0, i32** %6
store %struct.grammar* %1, %struct.grammar** %7
store i8* %2, i8** %8
store i8* %3, i8** %9
store %struct.code_node* %4, %struct.code_node** %10
%11 = load i32*, i32** %6
%12 = load %struct.grammar*, %struct.grammar** %7
%13 = call i32 @gen_known(i32* %11, %struct.grammar* %12)
%14 = load i32*, i32** %6
%15 = load %struct.grammar*, %struct.grammar** %7
%16 = call i32 @gen_non_term(i32* %14, %struct.grammar* %15)
%17 = load i32*, i32** %6
%18 = load %struct.grammar*, %struct.grammar** %7
%19 = call i32 @gen_goto(i32* %17, %struct.grammar* %18)
%20 = load i32*, i32** %6
%21 = load %struct.grammar*, %struct.grammar** %7
%22 = call i32 @gen_states(i32* %20, %struct.grammar* %21)
%23 = load i32*, i32** %6
%24 = load %struct.grammar*, %struct.grammar** %7
%25 = load i8*, i8** %8
%26 = load %struct.code_node*, %struct.code_node** %10
%27 = call i32 @gen_reduce(i32* %23, %struct.grammar* %24, i8* %25, %struct.code_node* %26)
%28 = load i32*, i32** %6
%29 = load %struct.grammar*, %struct.grammar** %7
%30 = call i32 @gen_free(i32* %28, %struct.grammar* %29)
%31 = load i32*, i32** %6
%32 = call i32 (i32*, i8*, ...) @fprintf(i32* %31, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0))
%33 = load i32*, i32** %6
%34 = load i8*, i8** %9
%35 = call i32 (i32*, i8*, ...) @fprintf(i32* %33, i8* getelementptr inbounds ([82 x i8], [82 x i8]* @.str.1, i64 0, i64 0), i8* %34)
%36 = load i32*, i32** %6
%37 = call i32 (i32*, i8*, ...) @fprintf(i32* %36, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
%38 = load i32*, i32** %6
%39 = call i32 (i32*, i8*, ...) @fprintf(i32* %38, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.3, i64 0, i64 0))
%40 = load i32*, i32** %6
%41 = call i32 (i32*, i8*, ...) @fprintf(i32* %40, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.4, i64 0, i64 0))
%42 = load i32*, i32** %6
%43 = call i32 (i32*, i8*, ...) @fprintf(i32* %42, i8* getelementptr inbounds ([56 x i8], [56 x i8]* @.str.5, i64 0, i64 0))
%44 = load i32*, i32** %6
%45 = call i32 (i32*, i8*, ...) @fprintf(i32* %44, i8* getelementptr inbounds ([71 x i8], [71 x i8]* @.str.6, i64 0, i64 0))
%46 = load i32*, i32** %6
%47 = call i32 (i32*, i8*, ...) @fprintf(i32* %46, i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.7, i64 0, i64 0))
%48 = load i32*, i32** %6
%49 = call i32 (i32*, i8*, ...) @fprintf(i32* %48, i8* getelementptr inbounds ([86 x i8], [86 x i8]* @.str.8, i64 0, i64 0))
%50 = load i32*, i32** %6
%51 = call i32 (i32*, i8*, ...) @fprintf(i32* %50, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.9, i64 0, i64 0))
%52 = load i32*, i32** %6
%53 = call i32 (i32*, i8*, ...) @fprintf(i32* %52, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.10, i64 0, i64 0))
%54 = load i32*, i32** %6
%55 = call i32 (i32*, i8*, ...) @fprintf(i32* %54, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.11, i64 0, i64 0))
ret void
}

LLVM IR (-O2):
%struct.grammar = type { i32 }
%struct.code_node = type { i32 }
@.str = [22 x i8] c"#line 0 \22gen_parser\22\0A\00"
@.str.1 = [82 x i8] c"void *parse_%s(struct code_node *code, struct token_config *config, FILE *trace)\0A\00"
@.str.2 = [3 x i8] c"{\0A\00"
@.str.3 = [30 x i8] c"\09struct token_state *tokens;\0A\00"
@.str.4 = [31 x i8] c"\09config->words_marks = known;\0A\00"
@.str.5 = [56 x i8] c"\09config->known_count = sizeof(known)/sizeof(known[0]);\0A\00"
@.str.6 = [71 x i8] c"\09config->ignored |= (1 << TK_line_comment) | (1 << TK_block_comment);\0A\00"
@.str.7 = [37 x i8] c"\09tokens = token_open(code, config);\0A\00"
@.str.8 = [86 x i8] c"\09void *rv = parser_run(tokens, states, do_reduce, do_free, trace, non_term, config);\0A\00"
@.str.9 = [23 x i8] c"\09token_close(tokens);\0A\00"
@.str.10 = [13 x i8] c"\09return rv;\0A\00"
@.str.11 = [4 x i8] c"}\0A\0A\00"
define void @gen_parser(i32* %0, %struct.grammar* %1, i8* %2, i8* %3, %struct.code_node* %4) {
%6 = tail call i32 @gen_known(i32* %0, %struct.grammar* %1)
%7 = tail call i32 @gen_non_term(i32* %0, %struct.grammar* %1)
%8 = tail call i32 @gen_goto(i32* %0, %struct.grammar* %1)
%9 = tail call i32 @gen_states(i32* %0, %struct.grammar* %1)
%10 = tail call i32 @gen_reduce(i32* %0, %struct.grammar* %1, i8* %2, %struct.code_node* %4)
%11 = tail call i32 @gen_free(i32* %0, %struct.grammar* %1)
%12 = tail call i64 @fwrite(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0), i64 21, i64 1, i32* %0)
%13 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %0, i8* getelementptr inbounds ([82 x i8], [82 x i8]* @.str.1, i64 0, i64 0), i8* %3)
%14 = tail call i64 @fwrite(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i64 2, i64 1, i32* %0)
%15 = tail call i64 @fwrite(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.3, i64 0, i64 0), i64 29, i64 1, i32* %0)
%16 = tail call i64 @fwrite(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.4, i64 0, i64 0), i64 30, i64 1, i32* %0)
%17 = tail call i64 @fwrite(i8* getelementptr inbounds ([56 x i8], [56 x i8]* @.str.5, i64 0, i64 0), i64 55, i64 1, i32* %0)
%18 = tail call i64 @fwrite(i8* getelementptr inbounds ([71 x i8], [71 x i8]* @.str.6, i64 0, i64 0), i64 70, i64 1, i32* %0)
%19 = tail call i64 @fwrite(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.7, i64 0, i64 0), i64 36, i64 1, i32* %0)
%20 = tail call i64 @fwrite(i8* getelementptr inbounds ([86 x i8], [86 x i8]* @.str.8, i64 0, i64 0), i64 85, i64 1, i32* %0)
%21 = tail call i64 @fwrite(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.9, i64 0, i64 0), i64 22, i64 1, i32* %0)
%22 = tail call i64 @fwrite(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.10, i64 0, i64 0), i64 12, i64 1, i32* %0)
%23 = tail call i64 @fwrite(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.11, i64 0, i64 0), i64 3, i64 1, i32* %0)
ret void
}