// File: /workspace/github_cpp_makefile_star2_O3/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 0x11b260
movq (%r12), %rdi
callq 0x11b270
leaq -0x30(%rbp), %r8
movq $0x0, (%r8)
leaq -0x38(%rbp), %rdi
xorl %esi, %esi
xorl %edx, %edx
xorl %ecx, %ecx
callq 0xf06a0
movq -0x30(%rbp), %rdi
testq %rdi, %rdi
je 0xefd33
movq (%rdi), %rax
callq *0x8(%rax)
movq $0x0, -0x30(%rbp)
movq -0x38(%rbp), %rdi
callq 0x11b0d0
movl $0x3, %edi
callq 0x11b0f0
leaq -0xd8(%rbp), %rdi
callq 0x12b250
callq 0x126b70
leaq -0xd8(%rbp), %rdi
movq %rax, 0x58(%rdi)
callq 0x12b750
movq %rax, %rbx
movq %rax, %rdi
callq 0xf4ff0
leaq -0x50(%rbp), %rdi
movq %rbx, %rsi
callq 0xf74b0
movq %rbx, %rdi
xorl %esi, %esi
callq 0xfa130
movq $0x0, (%rsp)
movq %rbx, %rdi
xorl %esi, %esi
movq %rax, %rdx
xorl %ecx, %ecx
xorl %r8d, %r8d
xorl %r9d, %r9d
callq 0x11bf50
movq %rax, %r14
movq %rax, %rdi
callq 0xf7980
movq %rbx, %rdi
callq 0x11f2f0
movq %rax, %r13
movq %rbx, %rdi
movq %rax, %rsi
callq 0xf032a
movq %rbx, %rdi
movq %r13, %rsi
callq 0xf005f
movq %rbx, %rdi
movq %r13, %rsi
movq %r12, %rdx
movl %r15d, %ecx
callq 0xf0408
movq %r14, %rdi
callq 0x11cf20
movq %rax, %r15
leaq 0xdf4208(%rip), %rsi    # 0xee4004
movq %rbx, %rdi
xorl %edx, %edx
movl $0x2, %ecx
callq 0x11e680
movq %r15, %rdi
movq %r14, %rsi
movq %rax, %rdx
movq %r13, %rcx
callq 0x10de30
leaq 0xe551a4(%rip), %rsi    # 0xf44fc7
movq %rbx, %rdi
xorl %edx, %edx
movl $0x6, %ecx
callq 0x11e680
movq %r15, %rdi
movq %r14, %rsi
movq %rax, %rdx
movq %r15, %rcx
callq 0x10de30
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 0x11e7b0
movq %rax, %r12
testq %rax, %rax
je 0xeff54
movq %r14, %rdi
movq %r12, %rsi
xorl %edx, %edx
callq 0x102930
movq %rax, %r12
testq %rax, %rax
je 0xeff5e
movq %r15, %rdi
callq 0xe61f0
movq %r12, %rdi
movq %r14, %rsi
callq 0xfd070
testq %rax, %rax
je 0xeff68
movq %r14, %rdi
callq 0xf7bf0
leaq -0x50(%rbp), %rdi
callq 0xfdaa0
movq %rbx, %rdi
callq 0xf5240
movq %rbx, %rdi
callq 0xf5250
callq 0x11b1b0
callq 0x11b0e0
movq -0x80(%rbp), %rdi
testq %rdi, %rdi
je 0xeff1b
movq (%rdi), %rax
callq *0x8(%rax)
leaq -0xd8(%rbp), %rdi
callq 0x12b290
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 0xf7360
jmp 0xefe4b
callq 0xf73d0
jmp 0xefeac
callq 0xf73d0
jmp 0xefec5
callq 0xf73d0
jmp 0xefee1
jmp 0xeffec
jmp 0xeffec
jmp 0xeffab
jmp 0xeffab
jmp 0xeff7e
jmp 0xeff7e
movq %rax, %r15
jmp 0xeffb6
movq %rax, %r15
jmp 0xeffbf
jmp 0xeffa6
jmp 0xeffa6
jmp 0xeff9d
movq %rax, %r15
movq -0x30(%rbp), %rdi
jmp 0xeffd7
jmp 0xeffab
jmp 0xeffab
jmp 0xeffab
movq %rax, %r15
jmp 0xeffd3
jmp 0xeffab
jmp 0xeffab
movq %rax, %r15
jmp 0xeffc7
movq %rax, %r15
movq %r14, %rdi
callq 0xf7bf0
leaq -0x50(%rbp), %rdi
callq 0xfdaa0
movq %rbx, %rdi
callq 0xf5240
leaq -0xd8(%rbp), %rdi
callq 0x12b290
movq -0x38(%rbp), %rdi
testq %rdi, %rdi
je 0xeffe2
movq (%rdi), %rax
callq *0x8(%rax)
movq %r15, %rdi
callq 0xe6940
jmp 0xeffec
movq %rax, %rdi
callq 0xefff4