// File: /workspace/github_c_makefile_star2_O0/creationix[P]color-control/src/compile.c
// Function: main
int main() {

  mpc_parser_t *State  = mpc_new("statement");
  mpc_parser_t *Ident  = mpc_new("ident");
  mpc_parser_t *Number  = mpc_new("number");
  mpc_parser_t *Hex  = mpc_new("hex");
  mpc_parser_t *Dec  = mpc_new("decimal");
  mpc_parser_t *Bool  = mpc_new("boolean");
  mpc_parser_t *For  = mpc_new("for");
  mpc_parser_t *Range  = mpc_new("range");
  mpc_parser_t *By  = mpc_new("by");
  mpc_parser_t *If  = mpc_new("if");
  mpc_parser_t *Assign  = mpc_new("assign");
  mpc_parser_t *Expr  = mpc_new("expression");
  mpc_parser_t *Call  = mpc_new("call");
  mpc_parser_t *Not  = mpc_new("not");
  mpc_parser_t *Or  = mpc_new("or");
  mpc_parser_t *And  = mpc_new("and");
  mpc_parser_t *Equal  = mpc_new("equality");
  mpc_parser_t *Comp  = mpc_new("comparison");
  mpc_parser_t *Sum  = mpc_new("sum");
  mpc_parser_t *Prod  = mpc_new("product");
  mpc_parser_t *Value = mpc_new("value");
  mpc_parser_t *Block = mpc_new("block");
  mpc_parser_t *Prog = mpc_new("program");

  mpc_err_t* err = mpca_lang(MPCA_LANG_DEFAULT,
    "statement: <for> | <if> | <assign> | <expression>;"
    "for : \"for\" <ident> \"in\" <number> <range>? <by>? <block>;"
    "range: /\\.\\.\\.?/ <number>;"
    "by: \"by\" <number>;"
    "if : \"if\" <expression> <block>;"
    "assign : <ident> '=' <expression>;"
    "expression: <or>;"
    "ident: /[a-zA-Z_][a-zA-Z_0-9]*/;"
    "number: <boolean> | <hex> | <decimal>;"
    "hex: /0x[0-9a-f]+/;"
    "decimal: /[0-9]+/;"
    "boolean: \"true\" | \"false\";"
    "or : <and> ( \"||\" <and> )*;"
    "and : <equality> ( \"&&\" <equality> )*;"
    "equality : <comparison> ( (\"==\" | \"!=\") <comparison> )*;"
    "comparison : <sum> ( (\"<=\" | \">=\" | '<' | '>') <sum> )*;"
    "sum : <product> ( ('+' | '-') <product> )*;"
    "product : <not> ( ('*' | '/' | '%') <not> )*;"
    "not: '!' <value> | <value>;"
    "call:  <ident> '(' <statement>? (',' <statement>)* ')';"
    "value : <number> | <call> | <ident> | '(' <statement> ')';"
    "block: '{' <statement>* '}';"
    "program : /^/ <statement>* /$/;",
    State, Ident, Number, Hex, Dec, Bool, For, Range, By, If, Assign, Expr, Call, Not, Or, And, Equal, Comp, Sum, Prod, Value, Block, Prog, NULL);

  if (err) {
    mpc_err_print_to(err, stderr);
    return -1;
  }

  uint8_t* input = stdin_read(NULL);

  // replace comments with white space as preprocessor.
  {
    size_t i = 0;
    bool comment = false;
    uint8_t c;
    while ((c = input[i])) {
      if (comment) {
        if (c == '\n') comment = false;
        else input[i] = ' ';
      }
      else {
        if (c == '#') {
          comment = true;
          input[i] = ' ';
        }
      }
      i++;
    }
  }

  // fprintf(stderr, "\n## Source with comments stripped ##\n\n%s\n", input);

  mpc_result_t r;
  if (mpc_parse("input", (char*)input, Prog, &r)) {
    // mpc_ast_print_to(r.output, stderr);
    generate_block(r.output);
    mpc_ast_delete(r.output);
  } else {
    mpc_err_print_to(r.error, stderr);
    mpc_err_delete(r.error);
  }
  stdin_free(input);

  mpc_cleanup(21, State, Ident, Number, Hex, Dec, Bool, For, Range, By, If, Assign, Expr, Call, Not, Or, And, Equal, Comp, Sum, Prod, Value, Block, Prog);

  // Tag ends with marker bytes so we can tell apart from random serial stuff.
  output[0] = '(';
  output[1] = ']';
  output[output_len++] = '[';
  output[output_len++] = ')';
  // Write full length (including header/trailer as big-endian uint16_t)
  output[2] = output_len >> 8;
  output[3] = output_len & 0xff;

  write(1, output, output_len);

}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x238, %rsp            # imm = 0x238
movl $0x0, -0x2c(%rbp)
leaq 0x5193(%rip), %rdi      # 0x11865
callq 0x4700
movq %rax, -0x38(%rbp)
leaq 0x518d(%rip), %rdi      # 0x1186f
callq 0x4700
movq %rax, -0x40(%rbp)
leaq 0x4fee(%rip), %rdi      # 0x116e0
callq 0x4700
movq %rax, -0x48(%rbp)
leaq 0x5173(%rip), %rdi      # 0x11875
callq 0x4700
movq %rax, -0x50(%rbp)
leaq 0x4fc6(%rip), %rdi      # 0x116d8
callq 0x4700
movq %rax, -0x58(%rbp)
leaq 0x5157(%rip), %rdi      # 0x11879
callq 0x4700
movq %rax, -0x60(%rbp)
leaq 0x514f(%rip), %rdi      # 0x11881
callq 0x4700
movq %rax, -0x68(%rbp)
leaq 0x4fd4(%rip), %rdi      # 0x11716
callq 0x4700
movq %rax, -0x70(%rbp)
leaq 0x5133(%rip), %rdi      # 0x11885
callq 0x4700
movq %rax, -0x78(%rbp)
leaq 0x5126(%rip), %rdi      # 0x11888
callq 0x4700
movq %rax, -0x80(%rbp)
leaq 0x5119(%rip), %rdi      # 0x1188b
callq 0x4700
movq %rax, -0x88(%rbp)
leaq 0x510d(%rip), %rdi      # 0x11892
callq 0x4700
movq %rax, -0x90(%rbp)
leaq 0x5105(%rip), %rdi      # 0x1189d
callq 0x4700
movq %rax, -0x98(%rbp)
leaq 0x50f7(%rip), %rdi      # 0x118a2
callq 0x4700
movq %rax, -0xa0(%rbp)
leaq 0x50c4(%rip), %rdi      # 0x11882
callq 0x4700
movq %rax, -0xa8(%rbp)
leaq 0x572d(%rip), %rdi      # 0x11efe
callq 0x4700
movq %rax, -0xb0(%rbp)
leaq 0x50c2(%rip), %rdi      # 0x118a6
callq 0x4700
movq %rax, -0xb8(%rbp)
leaq 0x50b8(%rip), %rdi      # 0x118af
callq 0x4700
movq %rax, -0xc0(%rbp)
leaq 0x50b0(%rip), %rdi      # 0x118ba
callq 0x4700
movq %rax, -0xc8(%rbp)
leaq 0x50a1(%rip), %rdi      # 0x118be
callq 0x4700
movq %rax, -0xd0(%rbp)
leaq 0x5096(%rip), %rdi      # 0x118c6
callq 0x4700
movq %rax, -0xd8(%rbp)
leaq 0x5089(%rip), %rdi      # 0x118cc
callq 0x4700
movq %rax, -0xe0(%rbp)
leaq 0x507c(%rip), %rdi      # 0x118d2
callq 0x4700
movq %rax, -0xe8(%rbp)
movq -0x38(%rbp), %rdx
movq -0x40(%rbp), %rcx
movq -0x48(%rbp), %r8
movq -0x50(%rbp), %r9
movq -0x58(%rbp), %rax
movq %rax, -0x170(%rbp)
movq -0x60(%rbp), %rax
movq %rax, -0x168(%rbp)
movq -0x68(%rbp), %rax
movq %rax, -0x160(%rbp)
movq -0x70(%rbp), %rax
movq %rax, -0x158(%rbp)
movq -0x78(%rbp), %rax
movq %rax, -0x150(%rbp)
movq -0x80(%rbp), %rax
movq %rax, -0x148(%rbp)
movq -0x88(%rbp), %rax
movq %rax, -0x140(%rbp)
movq -0x90(%rbp), %rax
movq %rax, -0x138(%rbp)
movq -0x98(%rbp), %rax
movq %rax, -0x130(%rbp)
movq -0xa0(%rbp), %rax
movq %rax, -0x128(%rbp)
movq -0xa8(%rbp), %rax
movq %rax, -0x120(%rbp)
movq -0xb0(%rbp), %r13
movq -0xb8(%rbp), %r12
movq -0xc0(%rbp), %r15
movq -0xc8(%rbp), %r14
movq -0xd0(%rbp), %rbx
movq -0xd8(%rbp), %r11
movq -0xe0(%rbp), %r10
movq -0xe8(%rbp), %rax
movq %rax, -0x118(%rbp)
xorl %edi, %edi
leaq 0x4f98(%rip), %rsi      # 0x118da
xorl %eax, %eax
movq -0x170(%rbp), %rax
movq %rax, (%rsp)
movq -0x168(%rbp), %rax
movq %rax, 0x8(%rsp)
movq -0x160(%rbp), %rax
movq %rax, 0x10(%rsp)
movq -0x158(%rbp), %rax
movq %rax, 0x18(%rsp)
movq -0x150(%rbp), %rax
movq %rax, 0x20(%rsp)
movq -0x148(%rbp), %rax
movq %rax, 0x28(%rsp)
movq -0x140(%rbp), %rax
movq %rax, 0x30(%rsp)
movq -0x138(%rbp), %rax
movq %rax, 0x38(%rsp)
movq -0x130(%rbp), %rax
movq %rax, 0x40(%rsp)
movq -0x128(%rbp), %rax
movq %rax, 0x48(%rsp)
movq -0x120(%rbp), %rax
movq %rax, 0x50(%rsp)
movq -0x118(%rbp), %rax
movq %r13, 0x58(%rsp)
movq %r12, 0x60(%rsp)
movq %r15, 0x68(%rsp)
movq %r14, 0x70(%rsp)
movq %rbx, 0x78(%rsp)
movq %r11, 0x80(%rsp)
movq %r10, 0x88(%rsp)
movq %rax, 0x90(%rsp)
movq $0x0, 0x98(%rsp)
movb $0x0, %al
callq 0xb2c0
movq %rax, -0xf0(%rbp)
cmpq $0x0, -0xf0(%rbp)
je 0xca45
movq -0xf0(%rbp), %rdi
movq 0xa5c7(%rip), %rax      # 0x16ff8
movq (%rax), %rsi
callq 0x23e0
movl $0xffffffff, -0x2c(%rbp) # imm = 0xFFFFFFFF
jmp 0xcd6e
xorl %eax, %eax
movl %eax, %edi
callq 0xc480
movq %rax, -0xf8(%rbp)
movq $0x0, -0x100(%rbp)
movb $0x0, -0x101(%rbp)
movq -0xf8(%rbp), %rax
movq -0x100(%rbp), %rcx
movb (%rax,%rcx), %al
movb %al, -0x102(%rbp)
cmpb $0x0, %al
je 0xcaf2
testb $0x1, -0x101(%rbp)
je 0xcab4
movzbl -0x102(%rbp), %eax
cmpl $0xa, %eax
jne 0xcaa0
movb $0x0, -0x101(%rbp)
jmp 0xcab2
movq -0xf8(%rbp), %rax
movq -0x100(%rbp), %rcx
movb $0x20, (%rax,%rcx)
jmp 0xcadb
movzbl -0x102(%rbp), %eax
cmpl $0x23, %eax
jne 0xcad9
movb $0x1, -0x101(%rbp)
movq -0xf8(%rbp), %rax
movq -0x100(%rbp), %rcx
movb $0x20, (%rax,%rcx)
jmp 0xcadb
movq -0x100(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x100(%rbp)
jmp 0xca67
movq -0xf8(%rbp), %rsi
movq -0xe8(%rbp), %rdx
leaq 0x4a9c(%rip), %rdi      # 0x115a3
leaq -0x110(%rbp), %rcx
callq 0x3c70
cmpl $0x0, %eax
je 0xcb32
movq -0x110(%rbp), %rdi
callq 0xcd90
movq -0x110(%rbp), %rdi
callq 0x8bc0
jmp 0xcb54
movq -0x110(%rbp), %rdi
movq 0xa4b8(%rip), %rax      # 0x16ff8
movq (%rax), %rsi
callq 0x23e0
movq -0x110(%rbp), %rdi
callq 0x2330
movq -0xf8(%rbp), %rdi
callq 0xc590
movq -0x38(%rbp), %rsi
movq -0x40(%rbp), %rdx
movq -0x48(%rbp), %rcx
movq -0x50(%rbp), %r8
movq -0x58(%rbp), %r9
movq -0x60(%rbp), %rax
movq -0x68(%rbp), %rdi
movq %rdi, -0x1c0(%rbp)
movq -0x70(%rbp), %rdi
movq %rdi, -0x1b8(%rbp)
movq -0x78(%rbp), %rdi
movq %rdi, -0x1b0(%rbp)
movq -0x80(%rbp), %rdi
movq %rdi, -0x1a8(%rbp)
movq -0x88(%rbp), %rdi
movq %rdi, -0x1a0(%rbp)
movq -0x90(%rbp), %rdi
movq %rdi, -0x198(%rbp)
movq -0x98(%rbp), %rdi
movq %rdi, -0x190(%rbp)
movq -0xa0(%rbp), %rdi
movq %rdi, -0x188(%rbp)
movq -0xa8(%rbp), %rdi
movq %rdi, -0x180(%rbp)
movq -0xb0(%rbp), %r13
movq -0xb8(%rbp), %r12
movq -0xc0(%rbp), %r15
movq -0xc8(%rbp), %r14
movq -0xd0(%rbp), %rbx
movq -0xd8(%rbp), %r11
movq -0xe0(%rbp), %r10
movq -0xe8(%rbp), %rdi
movq %rdi, -0x178(%rbp)
movl $0x15, %edi
movq %rax, (%rsp)
movq -0x1c0(%rbp), %rax
movq %rax, 0x8(%rsp)
movq -0x1b8(%rbp), %rax
movq %rax, 0x10(%rsp)
movq -0x1b0(%rbp), %rax
movq %rax, 0x18(%rsp)
movq -0x1a8(%rbp), %rax
movq %rax, 0x20(%rsp)
movq -0x1a0(%rbp), %rax
movq %rax, 0x28(%rsp)
movq -0x198(%rbp), %rax
movq %rax, 0x30(%rsp)
movq -0x190(%rbp), %rax
movq %rax, 0x38(%rsp)
movq -0x188(%rbp), %rax
movq %rax, 0x40(%rsp)
movq -0x180(%rbp), %rax
movq %rax, 0x48(%rsp)
movq -0x178(%rbp), %rax
movq %r13, 0x50(%rsp)
movq %r12, 0x58(%rsp)
movq %r15, 0x60(%rsp)
movq %r14, 0x68(%rsp)
movq %rbx, 0x70(%rsp)
movq %r11, 0x78(%rsp)
movq %r10, 0x80(%rsp)
movq %rax, 0x88(%rsp)
movb $0x0, %al
callq 0x4da0
movb $0x28, 0xa5cf(%rip)     # 0x172b0
movb $0x5d, 0xa5c9(%rip)     # 0x172b1
movw 0xa4d1(%rip), %ax       # 0x171c0
movw %ax, %cx
addw $0x1, %cx
movw %cx, 0xa4c3(%rip)       # 0x171c0
movzwl %ax, %eax
movl %eax, %ecx
leaq 0xa5a7(%rip), %rax      # 0x172b0
movb $0x5b, (%rax,%rcx)
movw 0xa4ac(%rip), %ax       # 0x171c0
movw %ax, %cx
addw $0x1, %cx
movw %cx, 0xa49e(%rip)       # 0x171c0
movzwl %ax, %eax
movl %eax, %ecx
leaq 0xa582(%rip), %rax      # 0x172b0
movb $0x29, (%rax,%rcx)
movzwl 0xa487(%rip), %eax      # 0x171c0
sarl $0x8, %eax
movb %al, 0xa570(%rip)       # 0x172b2
movzwl 0xa477(%rip), %eax      # 0x171c0
andl $0xff, %eax
movb %al, 0xa55f(%rip)       # 0x172b3
movzwl 0xa465(%rip), %eax      # 0x171c0
movl %eax, %edx
movl $0x1, %edi
leaq 0xa547(%rip), %rsi      # 0x172b0
callq 0x2070
movl -0x2c(%rbp), %eax
addq $0x238, %rsp            # imm = 0x238
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nopw %cs:(%rax,%rax)