// File: /workspace/github_c_makefile_star2_O0/tylerneylon[P]APIsWithLua/ch4/eatyguy8.c
// Function: main
int main() {

  start();

  // Create a Lua state and load the module.
  lua_State *L = luaL_newstate();
  luaL_openlibs(L);

  // Set up API functions written in C.
  lua_register(L, "timestamp", timestamp);
  luaopen_Pair(L);
  lua_setglobal(L, "Pair");

  // Set up API functions written in Lua.
  luaL_dofile(L, "util.lua");
  luaL_dofile(L, "Character.lua");
  lua_setglobal(L, "Character");

  // Load eatyguy8 and run the init() function.
  luaL_dofile(L, "eatyguy8.lua");
  lua_setglobal(L, "eatyguy");
  lua_settop(L, 0);

  lua_getglobal(L, "eatyguy");
  lua_getfield(L, -1, "init");  // -1 means stack top.
  lua_call(L, 0, 0);            // 0, 0 = #args, #retvals

  lua_getglobal(L, "eatyguy");
  while (1) {
    int is_end_of_seq;
    int key = getkey(&is_end_of_seq);
    if (key == ESC_KEY || key == 'q' || key == 'Q') done();

    // Call eatyguy.loop(state).
    lua_getfield(L, -1, "loop");
    push_state_table(L, key, is_end_of_seq);
    lua_call(L, 1, 0);

    sleephires(0.016);  // Sleep for 16ms.
  }

  return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x20, %rsp
movl $0x0, -0x4(%rbp)
callq 0x5760
callq 0x217b0
movq %rax, -0x10(%rbp)
movq -0x10(%rbp), %rdi
callq 0x21b70
movq -0x10(%rbp), %rdi
leaq -0x61(%rip), %rsi       # 0x58b0
xorl %edx, %edx
callq 0x6ea0
movq -0x10(%rbp), %rdi
leaq 0x2e768(%rip), %rsi     # 0x3408b
callq 0x77e0
movq -0x10(%rbp), %rdi
callq 0x33680
movq -0x10(%rbp), %rdi
leaq 0x2e759(%rip), %rsi     # 0x34095
callq 0x77e0
movq -0x10(%rbp), %rdi
leaq 0x2e74e(%rip), %rsi     # 0x3409a
xorl %eax, %eax
movl %eax, %edx
callq 0x20c80
movl %eax, %ecx
movb $0x1, %al
cmpl $0x0, %ecx
movb %al, -0x19(%rbp)
jne 0x5984
movq -0x10(%rbp), %rdi
xorl %ecx, %ecx
movl $0xffffffff, %edx       # imm = 0xFFFFFFFF
xorl %eax, %eax
movl %eax, %r9d
movl %ecx, %esi
movq %r9, %r8
callq 0x8210
cmpl $0x0, %eax
setne %al
movb %al, -0x19(%rbp)
movb -0x19(%rbp), %al
movq -0x10(%rbp), %rdi
leaq 0x2e711(%rip), %rsi     # 0x340a3
xorl %eax, %eax
movl %eax, %edx
callq 0x20c80
movl %eax, %ecx
movb $0x1, %al
cmpl $0x0, %ecx
movb %al, -0x1a(%rbp)
jne 0x59ca
movq -0x10(%rbp), %rdi
xorl %ecx, %ecx
movl $0xffffffff, %edx       # imm = 0xFFFFFFFF
xorl %eax, %eax
movl %eax, %r9d
movl %ecx, %esi
movq %r9, %r8
callq 0x8210
cmpl $0x0, %eax
setne %al
movb %al, -0x1a(%rbp)
movb -0x1a(%rbp), %al
movq -0x10(%rbp), %rdi
leaq 0x2e6d9(%rip), %rsi     # 0x340b1
callq 0x77e0
movq -0x10(%rbp), %rdi
leaq 0x2e6d3(%rip), %rsi     # 0x340bb
xorl %eax, %eax
movl %eax, %edx
callq 0x20c80
movl %eax, %ecx
movb $0x1, %al
cmpl $0x0, %ecx
movb %al, -0x1b(%rbp)
jne 0x5a20
movq -0x10(%rbp), %rdi
xorl %ecx, %ecx
movl $0xffffffff, %edx       # imm = 0xFFFFFFFF
xorl %eax, %eax
movl %eax, %r9d
movl %ecx, %esi
movq %r9, %r8
callq 0x8210
cmpl $0x0, %eax
setne %al
movb %al, -0x1b(%rbp)
movb -0x1b(%rbp), %al
movq -0x10(%rbp), %rdi
leaq 0x2e69a(%rip), %rsi     # 0x340c8
callq 0x77e0
movq -0x10(%rbp), %rdi
xorl %esi, %esi
callq 0x5dc0
movq -0x10(%rbp), %rdi
leaq 0x2e67f(%rip), %rsi     # 0x340c8
callq 0x70b0
movq -0x10(%rbp), %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
leaq 0x2e672(%rip), %rdx     # 0x340d0
callq 0x72f0
movq -0x10(%rbp), %rdi
xorl %edx, %edx
xorl %eax, %eax
movl %eax, %r8d
movl %edx, %esi
movq %r8, %rcx
callq 0x8140
movq -0x10(%rbp), %rdi
leaq 0x2e645(%rip), %rsi     # 0x340c8
callq 0x70b0
leaq -0x14(%rbp), %rdi
callq 0x5650
movl %eax, -0x18(%rbp)
cmpl $0x1b, -0x18(%rbp)
je 0x5aa6
cmpl $0x71, -0x18(%rbp)
je 0x5aa6
cmpl $0x51, -0x18(%rbp)
jne 0x5aab
callq 0x57a0
movq -0x10(%rbp), %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
leaq 0x2f405(%rip), %rdx     # 0x34ec0
callq 0x72f0
movq -0x10(%rbp), %rdi
movl -0x18(%rbp), %esi
movl -0x14(%rbp), %edx
callq 0x5830
movq -0x10(%rbp), %rdi
movl $0x1, %esi
xorl %edx, %edx
xorl %eax, %eax
movl %eax, %r8d
movq %r8, %rcx
callq 0x8140
movsd 0x2e529(%rip), %xmm0    # 0x34018
callq 0x56f0
jmp 0x5a88
nopw %cs:(%rax,%rax)