// File: /workspace/github_cpp_makefile_star2_O1/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 $0x148, %rsp            # imm = 0x148
movq %rsi, %r12
movl %edi, %r15d
movq 0x117b243(%rip), %rax   # 0x126af10
movq (%rax), %rdi
xorl %esi, %esi
movl $0x2, %edx
xorl %ecx, %ecx
callq 0xe6610
movq 0x117b23b(%rip), %rax   # 0x126af20
movq (%rax), %rdi
xorl %esi, %esi
movl $0x2, %edx
xorl %ecx, %ecx
callq 0xe6610
movq (%r12), %rdi
xorl %esi, %esi
callq 0x11b290
movq (%r12), %rdi
callq 0x11b2a0
leaq -0x30(%rbp), %r8
movq $0x0, (%r8)
leaq -0x38(%rbp), %rdi
xorl %esi, %esi
xorl %edx, %edx
xorl %ecx, %ecx
callq 0xf06d0
movq -0x30(%rbp), %rdi
testq %rdi, %rdi
je 0xefd33
movq (%rdi), %rax
callq *0x8(%rax)
movq $0x0, -0x30(%rbp)
movq -0x38(%rbp), %rdi
callq 0x11b100
movl $0x3, %edi
callq 0x11b120
leaq -0xd8(%rbp), %rdi
callq 0x12b280
callq 0x126ba0
leaq -0xd8(%rbp), %rdi
movq %rax, 0x58(%rdi)
callq 0x12b780
movq %rax, %rbx
movq %rax, %rdi
callq 0xf5020
leaq -0x50(%rbp), %rdi
movq %rbx, %rsi
callq 0xf74e0
movq %rbx, %rdi
xorl %esi, %esi
callq 0xfa160
movq $0x0, (%rsp)
movq %rbx, %rdi
xorl %esi, %esi
movq %rax, %rdx
xorl %ecx, %ecx
xorl %r8d, %r8d
xorl %r9d, %r9d
callq 0x11bf80
movq %rax, %r14
movq %rax, %rdi
callq 0xf79b0
movq %rbx, %rdi
callq 0x11f320
movq %rax, %r13
movq %rbx, %rdi
movq %rax, %rsi
callq 0xf0361
movq %rbx, %rdi
movq %r13, %rsi
callq 0xf0081
movq %rbx, %rdi
movq %r13, %rsi
movq %r12, %rdx
movl %r15d, %ecx
callq 0xf0440
movq %r14, %rdi
callq 0x11cf50
movq %rax, %r15
leaq 0xdf4208(%rip), %rsi    # 0xee4004
movq %rbx, %rdi
xorl %edx, %edx
movl $0x2, %ecx
callq 0x11e6b0
movq %r15, %rdi
movq %r14, %rsi
movq %rax, %rdx
movq %r13, %rcx
callq 0x10de60
leaq 0xe551a4(%rip), %rsi    # 0xf44fc7
movq %rbx, %rdi
xorl %edx, %edx
movl $0x6, %ecx
callq 0x11e6b0
movq %r15, %rdi
movq %r14, %rsi
movq %rax, %rdx
movq %r15, %rcx
callq 0x10de60
testb $0x1, %al
je 0xeff4a
leaq 0xdf41b5(%rip), %rdi    # 0xee4007
xorl %esi, %esi
xorl %edx, %edx
xorl %eax, %eax
callq 0xe6600
movl %eax, %r13d
leaq -0x168(%rbp), %r15
movl %eax, %edi
movq %r15, %rsi
callq 0xe6d10
movq 0x30(%r15), %r12
leaq 0x1(%r12), %rdi
callq 0xe6d50
movq %rax, %r15
movl %r13d, %edi
movq %rax, %rsi
movq %r12, %rdx
callq 0xe6ae0
movq %rbx, %rdi
movq %r15, %rsi
xorl %edx, %edx
movl %r12d, %ecx
callq 0x11e7e0
movq %rax, %r12
testq %rax, %rax
je 0xeff54
movq %r14, %rdi
movq %r12, %rsi
xorl %edx, %edx
callq 0x102960
movq %rax, %r12
testq %rax, %rax
je 0xeff5e
movq %r15, %rdi
callq 0xe61f0
movq %r12, %rdi
movq %r14, %rsi
callq 0xfd0a0
testq %rax, %rax
je 0xeff68
movq %r14, %rdi
callq 0xf7c20
leaq -0x50(%rbp), %rdi
callq 0xfdad0
movq %rbx, %rdi
callq 0xf5270
movq %rbx, %rdi
callq 0xf5280
callq 0x11b1e0
callq 0x11b110
movq -0x80(%rbp), %rdi
testq %rdi, %rdi
je 0xeff1b
movq (%rdi), %rax
callq *0x8(%rax)
leaq -0xd8(%rbp), %rdi
callq 0x12b2c0
movq -0x38(%rbp), %rdi
testq %rdi, %rdi
je 0xeff36
movq (%rdi), %rax
callq *0x8(%rax)
xorl %eax, %eax
addq $0x148, %rsp            # imm = 0x148
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
callq 0xf7390
jmp 0xefe4b
callq 0xf7400
jmp 0xefeac
callq 0xf7400
jmp 0xefec5
callq 0xf7400
jmp 0xefee1
jmp 0xf000d
jmp 0xf000d
jmp 0xeffc4
jmp 0xeffc4
jmp 0xeff84
jmp 0xeff84
movq %rax, %r15
jmp 0xeffcf
movq %rax, %r15
jmp 0xeffd8
jmp 0xeffbf
jmp 0xeffbf
jmp 0xeffb6
movq %rax, %r15
movq -0x30(%rbp), %rdi
testq %rdi, %rdi
je 0xeffa6
movq (%rdi), %rax
callq *0x8(%rax)
movq $0x0, -0x30(%rbp)
jmp 0xf0003
jmp 0xeffc4
jmp 0xeffc4
jmp 0xeffc4
movq %rax, %r15
jmp 0xeffec
jmp 0xeffc4
jmp 0xeffc4
movq %rax, %r15
jmp 0xeffe0
movq %rax, %r15
movq %r14, %rdi
callq 0xf7c20
leaq -0x50(%rbp), %rdi
callq 0xfdad0
movq %rbx, %rdi
callq 0xf5270
leaq -0xd8(%rbp), %rdi
callq 0x12b2c0
movq -0x38(%rbp), %rdi
testq %rdi, %rdi
je 0xefffb
movq (%rdi), %rax
callq *0x8(%rax)
movq $0x0, -0x38(%rbp)
movq %r15, %rdi
callq 0xe6940
jmp 0xf000d
movq %rax, %rdi
callq 0xf0015