// File: /workspace/github_cpp_makefile_star2_O2/theanarkh[P]js_runtime_loader/No.cc
// Function: main
int main(int argc, char* argv[]) {
  setvbuf(stdout, nullptr, _IONBF, 0);
  setvbuf(stderr, nullptr, _IONBF, 0);
  v8::V8::InitializeICUDefaultLocation(argv[0]);
  v8::V8::InitializeExternalStartupData(argv[0]);
  std::unique_ptr<Platform> platform = platform::NewDefaultPlatform();
  v8::V8::InitializePlatform(platform.get());
  v8::V8::Initialize();
  Isolate::CreateParams create_params;
  create_params.array_buffer_allocator = ArrayBuffer::Allocator::NewDefaultAllocator();
  Isolate* isolate = Isolate::New(create_params);
  {
    Isolate::Scope isolate_scope(isolate);
    HandleScope handle_scope(isolate);
    Local<ObjectTemplate> global = ObjectTemplate::New(isolate);
    Local<Context> context = Context::New(isolate, nullptr, global);
    Context::Scope context_scope(context);
    Local<Object> No = Object::New(isolate);
    No::Loader::Init(isolate, No);
    No::Console::Init(isolate, No);
    No::Process::Init(isolate, No, argv, argc);
    Local<Object> globalInstance = context->Global();
    globalInstance->Set(context, String::NewFromUtf8Literal(isolate, "No", 
    NewStringType::kNormal), No);
    // 设置全局属性global指向全局对象
    globalInstance->Set(context, String::NewFromUtf8Literal(isolate, 
      "global", 
      NewStringType::kNormal), globalInstance).Check();
    {
      // 打开文件
      int fd = open("No.js", 0, O_RDONLY);
      struct stat info;
      // 取得文件信息
      fstat(fd, &info);
      // 分配内存保存文件内容
      char *ptr = (char *)malloc(info.st_size + 1);
      // ptr[info.st_size] = '\0';
      read(fd, (void *)ptr, info.st_size);
      // 要执行的js代码
      Local<String> source = String::NewFromUtf8(isolate, ptr,
                          NewStringType::kNormal,
                          info.st_size).ToLocalChecked();

      // 编译
      Local<Script> script = Script::Compile(context, source).ToLocalChecked();
      // 解析完应该没用了，释放内存
      free(ptr);
      // 执行
      Local<Value> result = script->Run(context).ToLocalChecked();
    }
  }

  // Dispose the isolate and tear down V8.
  isolate->Dispose();
  v8::V8::Dispose();
  v8::V8::ShutdownPlatform();
  delete create_params.array_buffer_allocator;
  return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x158, %rsp            # imm = 0x158
movq %rsi, %r12
movl %edi, %r15d
movq 0x117b243(%rip), %rax   # 0x126af10
movq (%rax), %rdi
pushq $0x2
popq %rbx
xorl %esi, %esi
movl %ebx, %edx
xorl %ecx, %ecx
callq 0xe6610
movq 0x117b23b(%rip), %rax   # 0x126af20
movq (%rax), %rdi
xorl %esi, %esi
movl %ebx, %edx
xorl %ecx, %ecx
callq 0xe6610
movq (%r12), %rdi
xorl %esi, %esi
callq 0x11b280
movq (%r12), %rdi
callq 0x11b290
leaq -0x30(%rbp), %r8
andq $0x0, (%r8)
leaq -0x38(%rbp), %rdi
xorl %esi, %esi
xorl %edx, %edx
xorl %ecx, %ecx
callq 0xf06c0
movq -0x30(%rbp), %rdi
testq %rdi, %rdi
je 0xefd2d
movq (%rdi), %rax
callq *0x8(%rax)
andq $0x0, -0x30(%rbp)
movq -0x38(%rbp), %rdi
callq 0x11b0f0
pushq $0x3
popq %rdi
callq 0x11b110
leaq -0xe0(%rbp), %rdi
callq 0x12b270
callq 0x126b90
leaq -0xe0(%rbp), %rdi
movq %rax, 0x58(%rdi)
callq 0x12b770
movq %rax, %rbx
movq %rax, -0x40(%rbp)
movq %rax, %rdi
callq 0xf5010
leaq -0x58(%rbp), %rdi
movq %rbx, %rsi
callq 0xf74d0
movq %rbx, %rdi
xorl %esi, %esi
callq 0xfa150
andq $0x0, (%rsp)
movq %rbx, %rdi
xorl %esi, %esi
movq %rax, %rdx
xorl %ecx, %ecx
xorl %r8d, %r8d
xorl %r9d, %r9d
callq 0x11bf70
movq %rax, %r14
movq %rax, %rdi
callq 0xf79a0
movq %rbx, %rdi
callq 0x11f310
movq %rax, %r13
movq %rbx, %rdi
movq %rax, %rsi
callq 0xf0321
movq %rbx, %rdi
movq %r13, %rsi
callq 0xf0083
movq %rbx, %rdi
movq %r13, %rsi
movq %r12, %rdx
movl %r15d, %ecx
callq 0xf0430
movq %r14, %rdi
callq 0x11cf40
movq %rax, %r15
leaq 0xdf4212(%rip), %rsi    # 0xee4004
movq %rbx, %rdi
xorl %edx, %edx
callq 0xeffe2
movq %r15, %rdi
movq %r14, %rsi
movq %rax, %rdx
movq %r13, %rcx
callq 0x10de50
leaq 0xe551b3(%rip), %rsi    # 0xf44fc7
movq %rbx, %rdi
xorl %edx, %edx
callq 0xefff2
movq %r15, %rdi
movq %r14, %rsi
movq %rax, %rdx
movq %r15, %rcx
callq 0x10de50
testb $0x1, %al
je 0xeff3a
leaq 0xdf41c9(%rip), %rdi    # 0xee4007
xorl %esi, %esi
xorl %edx, %edx
xorl %eax, %eax
callq 0xe6600
movl %eax, %r13d
leaq -0x170(%rbp), %r15
movl %eax, %edi
movq %r15, %rsi
callq 0xe6d20
movq 0x30(%r15), %r12
leaq 0x1(%r12), %rdi
callq 0xe6d60
movq %rax, %r15
movl %r13d, %edi
movq %rax, %rsi
movq %r12, %rdx
callq 0xe6af0
movq %rbx, %rdi
movq %r15, %rsi
xorl %edx, %edx
movl %r12d, %ecx
callq 0x11e7d0
movq %rax, %r12
testq %rax, %rax
je 0xeff44
movq %r14, %rdi
movq %r12, %rsi
xorl %edx, %edx
callq 0x102950
movq %rax, %r12
testq %rax, %rax
je 0xeff4e
movq %r15, %rdi
callq 0xe61f0
movq %r12, %rdi
movq %r14, %rsi
callq 0xfd090
testq %rax, %rax
je 0xeff58
movq %r14, %rdi
callq 0xf7c10
leaq -0x58(%rbp), %rdi
callq 0xfdac0
leaq -0x40(%rbp), %rdi
callq 0xf0002
movq %rbx, %rdi
callq 0xf5270
callq 0x11b1d0
callq 0x11b100
movq -0x88(%rbp), %rdi
testq %rdi, %rdi
je 0xeff0b
movq (%rdi), %rax
callq *0x8(%rax)
leaq -0xe0(%rbp), %rdi
callq 0x12b2b0
movq -0x38(%rbp), %rdi
testq %rdi, %rdi
je 0xeff26
movq (%rdi), %rax
callq *0x8(%rax)
xorl %eax, %eax
addq $0x158, %rsp            # imm = 0x158
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
callq 0xf7380
jmp 0xefe37
callq 0xf73f0
jmp 0xefe98
callq 0xf73f0
jmp 0xefeb1
callq 0xf73f0
jmp 0xefecd
jmp 0xeffd9
jmp 0xeff99
jmp 0xeff99
jmp 0xeff6c
jmp 0xeff6c
movq %rax, %rbx
jmp 0xeffa4
movq %rax, %rbx
jmp 0xeffad
jmp 0xeff94
jmp 0xeff94
jmp 0xeff8b
movq %rax, %rbx
movq -0x30(%rbp), %rdi
jmp 0xeffc6
jmp 0xeff99
jmp 0xeff99
jmp 0xeff99
movq %rax, %rbx
jmp 0xeffc2
jmp 0xeff99
jmp 0xeff99
movq %rax, %rbx
jmp 0xeffb6
movq %rax, %rbx
movq %r14, %rdi
callq 0xf7c10
leaq -0x58(%rbp), %rdi
callq 0xfdac0
leaq -0x40(%rbp), %rdi
callq 0xf0002
leaq -0xe0(%rbp), %rdi
callq 0x12b2b0
movq -0x38(%rbp), %rdi
testq %rdi, %rdi
je 0xeffd1
movq (%rdi), %rax
callq *0x8(%rax)
movq %rbx, %rdi
callq 0xe6940
movq %rax, %rdi
callq 0xf0018
nop