// File: /workspace/github_c_makefile_star2_O2/deplinenoise[P]tundra/src/Main.cpp
// Function: main
int main(int argc, char* argv[])
{
  using namespace t2;

  InitCommon();

  Driver driver;
  DriverOptions options;

  // Set default options
  DriverOptionsInit(&options);

  // Scan options from command line, update argc/argv
  if (!InitOptions(&options, &argc, &argv))
  {
    ShowHelp();
    return 1;
  }

  DriverInitializeTundraFilePaths(&options);
#if defined(TUNDRA_WIN32)
  if (!options.m_RunUnprotected && nullptr == getenv("_TUNDRA2_PARENT_PROCESS_HANDLE"))
  {
    // Re-launch Tundra2 as a child in a new process group. The child will be passed a handle to our process so it can
    // watch for us dying, but not be affected by sudden termination itself.
    // This ridiculous tapdance is there to prevent hard termination by things like visual studio and the mingw shell.
    // Because Tundra needs to save build state when shutting down, we need this.

    HANDLE myproc = GetCurrentProcess();
    HANDLE self_copy = NULL;
    if (!DuplicateHandle(myproc, myproc, myproc, &self_copy, 0, TRUE, DUPLICATE_SAME_ACCESS))
    {
      CroakErrno("DuplicateHandle() failed");
    }

    // Expose handle in the environment for the child process.
    {
      char handle_value[128];
      _snprintf(handle_value, sizeof handle_value, "_TUNDRA2_PARENT_PROCESS_HANDLE=%016I64x", uint64_t(self_copy));
      _putenv(handle_value);
    }

    STARTUPINFOA startup_info;
    PROCESS_INFORMATION proc_info;
    ZeroMemory(&startup_info, sizeof startup_info);
    ZeroMemory(&proc_info, sizeof proc_info);
    startup_info.cb = sizeof startup_info;

    HANDLE job_handle = CreateJobObject(NULL,  NULL);

    // Set job object limits so children can break out.
    JOBOBJECT_EXTENDED_LIMIT_INFORMATION limits;
    ZeroMemory(&limits, sizeof(limits));
    limits.BasicLimitInformation.LimitFlags = JOB_OBJECT_LIMIT_BREAKAWAY_OK | JOB_OBJECT_LIMIT_SILENT_BREAKAWAY_OK;

    if (!SetInformationJobObject(job_handle, JobObjectExtendedLimitInformation, &limits, sizeof limits) )
      CroakErrno("couldn't set job info");

    if (!CreateProcessA(NULL, GetCommandLineA(), NULL, NULL, TRUE, CREATE_BREAKAWAY_FROM_JOB|CREATE_NEW_PROCESS_GROUP|CREATE_SUSPENDED, NULL, NULL, &startup_info, &proc_info))
      CroakErrno("CreateProcess() failed");

    AssignProcessToJobObject(job_handle, proc_info.hProcess);
    ResumeThread(proc_info.hThread);

    WaitForSingleObject(proc_info.hProcess, INFINITE);

    DWORD exit_code = 1;
    GetExitCodeProcess(proc_info.hProcess, &exit_code);

    CloseHandle(proc_info.hThread);
    CloseHandle(proc_info.hProcess);
    ExitProcess(exit_code);
  }
  else if (const char* handle_str = getenv("_TUNDRA2_PARENT_PROCESS_HANDLE"))
  {
    HANDLE h = (HANDLE) _strtoi64(handle_str, NULL, 16);
    SignalHandlerInitWithParentProcess(h);
  }
  else
  {
    SignalHandlerInit();
  }
#else
  SignalHandlerInit();
#endif

  uint64_t start_time = TimerGet();

  ExecInit(options.m_ThreadCount);

  if (options.m_WorkingDir)
  {
    if (!SetCwd(options.m_WorkingDir))
      Croak("couldn't change directory to %s", options.m_WorkingDir);
  }

  if (options.m_ShowHelp)
  {
    ShowHelp();
    return 0;
  }

  // Initialize logging
  int log_flags = kWarning | kError;

  if (options.m_DebugMessages)
    log_flags |= kInfo | kDebug;

  if (options.m_SpammyVerbose)
    log_flags |= kSpam | kInfo | kDebug;

  SetLogFlags(log_flags);

  if (options.m_IdeGen)
  {
    // FIXME: How to detect build file for other type of generators?
    GenerateIdeIntegrationFiles("tundra.lua", argc, (const char**) argv);
    return 0;
  }

  if (options.m_QuickstartGen)
  {
    GenerateTemplateFiles(argc, (const char**) argv);
    return 0;
  }

  // Protect against running two or more instances simultaneously in the same directory.
  // This can happen if Visual Studio is trying to launch more than one copy of tundra.
#if defined(TUNDRA_WIN32)
  {
    char mutex_name[MAX_PATH];
    char cwd[MAX_PATH];
    char cwd_nerfed[MAX_PATH];
    GetCwd(cwd, sizeof cwd);
    const char *i = cwd;
    char *o = cwd_nerfed;
    char ch;
    do
    {
      ch = *i++;
      switch (ch)
      {
      case '\\':
      case ':':
        ch = '^';
        break;
      }
      *o++ = ch;
    } while(ch);

    _snprintf(mutex_name, sizeof mutex_name, "Global\\Tundra--%s-%s", cwd_nerfed, options.m_DAGFileName);
    mutex_name[sizeof(mutex_name)-1] = '\0';
    bool warning_printed = false;
    HANDLE mutex = CreateMutexA(nullptr, false, mutex_name);

    while (WAIT_TIMEOUT == WaitForSingleObject(mutex, 100))
    {
      if (!warning_printed)
      {
        Log(kWarning, "More than one copy of Tundra running in %s -- PID %u waiting", cwd, GetCurrentProcessId());
        warning_printed = true;
      }
      Sleep(100);
    }

    Log(kDebug, "PID %u successfully locked %s", GetCurrentProcessId(), cwd);
  }
#endif

  // Initialize driver
  if (!DriverInit(&driver, &options))
    return 1;

  // Initialize profiler if needed
  if (driver.m_Options.m_ProfileOutput)
    ProfilerInit(driver.m_Options.m_ProfileOutput, driver.m_Options.m_ThreadCount);


  BuildResult::Enum build_result = BuildResult::kSetupError;

  if (!DriverInitData(&driver))
    goto leave;

  if (driver.m_Options.m_GenDagOnly)
  {
    Log(kDebug, "Only generating DAG - quitting");
    build_result = BuildResult::kOk;
    goto leave;
  }

  if (driver.m_Options.m_ShowTargets)
  {
    DriverShowTargets(&driver);
    Log(kDebug, "Only showing targets - quitting");
    build_result = BuildResult::kOk;
    goto leave;
  }

  DriverRemoveStaleOutputs(&driver);

  // Prepare list of nodes to build/clean/rebuild
  if (!DriverPrepareNodes(&driver, (const char**) argv, argc))
  {
    Log(kError, "couldn't set up list of targets to build");
    goto leave;
  }

  if (driver.m_Options.m_Clean || driver.m_Options.m_Rebuild)
  {
    DriverCleanOutputs(&driver);

    if (!driver.m_Options.m_Rebuild)
    {
      build_result = BuildResult::kOk;
      goto leave;
    }
  }

  build_result = DriverBuild(&driver);

  if (!DriverSaveBuildState(&driver))
    Log(kError, "Couldn't save build state");

  if (!DriverSaveScanCache(&driver))
    Log(kWarning, "Couldn't save header scanning cache");

  if (!DriverSaveDigestCache(&driver))
    Log(kWarning, "Couldn't save SHA1 digest cache");

leave:
  DriverDestroy(&driver);

  // Dump/close profiler
  if (driver.m_Options.m_ProfileOutput)
    ProfilerDestroy();

  // Dump stats
  if (options.m_DisplayStats)
  {
    printf("output cleanup:    %10.2f ms\n", TimerToSeconds(g_Stats.m_StaleCheckTimeCycles) * 1000.0);
    printf("json parse time:   %10.2f ms\n", TimerToSeconds(g_Stats.m_JsonParseTimeCycles) * 1000.0);
    printf("scan cache:\n");
    printf("  hits (new):      %10u\n", g_Stats.m_NewScanCacheHits);
    printf("  hits (frozen):   %10u\n", g_Stats.m_OldScanCacheHits);
    printf("  misses:          %10u\n", g_Stats.m_ScanCacheMisses);
    printf("  inserts:         %10u\n", g_Stats.m_ScanCacheInserts);
    printf("  save time:       %10.2f ms\n", TimerToSeconds(g_Stats.m_ScanCacheSaveTime) * 1000.0);
    printf("  entries dropped: %10u\n", g_Stats.m_ScanCacheEntriesDropped);
    printf("file signing:\n");
    printf("  cache hits:      %10u\n", g_Stats.m_DigestCacheHits);
    printf("  cache get time:  %10.2f ms\n", TimerToSeconds(g_Stats.m_DigestCacheGetTimeCycles) * 1000.0);
    printf("  cache save time: %10.2f ms\n", TimerToSeconds(g_Stats.m_DigestCacheSaveTimeCycles) * 1000.0);
    printf("  digests:         %10u\n", g_Stats.m_FileDigestCount);
    printf("  digest time:     %10.2f ms\n", TimerToSeconds(g_Stats.m_FileDigestTimeCycles) * 1000.0);
    printf("stat cache:\n");
    printf("  hits:            %10u\n", g_Stats.m_StatCacheHits);
    printf("  misses:          %10u\n", g_Stats.m_StatCacheMisses);
    printf("  dirty:           %10u\n", g_Stats.m_StatCacheDirty);
    printf("building:\n");
    printf("  old records:     %10u\n", g_Stats.m_StateSaveOld);
    printf("  new records:     %10u\n", g_Stats.m_StateSaveNew);
    printf("  dropped records: %10u\n", g_Stats.m_StateSaveDropped);
    printf("  state save time: %10.2f ms\n", TimerToSeconds(g_Stats.m_StateSaveTimeCycles) * 1000.0);
    printf("  exec() count:    %10u\n", g_Stats.m_ExecCount);
    printf("  exec() time:     %10.2f s\n", TimerToSeconds(g_Stats.m_ExecTimeCycles));
    printf("low-level syscalls:\n");
    printf("  mmap() calls:    %10u\n", g_Stats.m_MmapCalls);
    printf("  mmap() time:     %10.2f ms\n", TimerToSeconds(g_Stats.m_MmapTimeCycles) * 1000.0);
    printf("  munmap() calls:  %10u\n", g_Stats.m_MunmapCalls);
    printf("  munmap() time:   %10.2f ms\n", TimerToSeconds(g_Stats.m_MunmapTimeCycles) * 1000.0);
    printf("  stat() calls:    %10u\n", g_Stats.m_StatCount);
    printf("  stat() time:     %10.2f ms\n", TimerToSeconds(g_Stats.m_StatTimeCycles) * 1000.0);
  }

  if (!options.m_Quiet)
  {
    double total_time = TimerDiffSeconds(start_time, TimerGet());
    if (total_time < 60.0)
    {
      printf("*** %s (%.2f seconds)\n", BuildResult::Names[build_result], total_time);
    }
    else
    {
      int t = (int)total_time;
      int h = t / 3600; t -= h * 3600;
      int m = t / 60; t -= m * 60;
      int s = t;
      printf("*** %s (%.2f seconds - %d:%02d:%02d)\n", BuildResult::Names[build_result], total_time, h, m, s);
    }
  }

  return build_result == BuildResult::kOk ? 0 : 1;

  // Match up nodes to nodes in the build state
  //   Walk DAG node array in parallel with build state node array
  //   If a node is not present in the DAG but is in the old build state:
  //     Loop over its outputs and delete them
  // For all DAG nodes:
  //   Loop over their aux output references and flag them as in use
  //
  // Loop over aux outputs in union of (build state | dag)
  //   Delete file if it is not flagged as in use
  //
  // Clean up empty output directories:
  //   If any file was deleted due to cleanup:
  //     Walk all directories known to be created and rmdir() them
  //      (If any valid files are left in there we'll get an error and move on)
  //
  // Find out what nodes we want to build this time (match command line args against DAG info)
  //
  //   Construct config set:
  //     If config list on cmdline is empty, use default config
  //     Otherwise, look up each config and add to set
  //
  //   For each alias on the command line:
  //      Add the set of nodes referenced by the alias to the build queue
  //        Filtered by config set
  //
  //   If set of nodes to build is empty:
  //     Add all default sets (filter by config set) to the build queue
  //
  // Set up node state for each node to build
  //
  // Set up nodes for pass barriers
  //
  // Build
  //
  // Generate build state data
  //
  // Save header scanning state
  // Report stats
  // Exit
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x4a8, %rsp            # imm = 0x4A8
movq %rsi, 0x18(%rsp)
movl %edi, 0xc(%rsp)
callq 0x56cc
leaq 0x20(%rsp), %rdi
callq 0x892e
pushq $0x1
popq %rax
movl %eax, %r14d
movl 0xc(%rsp), %ebx
movslq %r14d, %r12
subl %r14d, %ebx
jle 0x3954
movq 0x18(%rsp), %rax
movq (%rax,%r12,8), %r13
cmpb $0x2d, (%r13)
jne 0x3954
cmpb $0x2d, 0x1(%r13)
movq %r14, 0x50(%rsp)
jne 0x37f1
movq %r13, %rdi
pushq $0x3d
popq %rsi
callq 0x3130
movq %rax, %rbx
testq %rax, %rax
je 0x3874
movq %rbx, %r15
subq %r13, %r15
addq $-0x2, %r15
jmp 0x3880
leal 0x1(%r14), %eax
cmpl 0xc(%rsp), %eax
jge 0x3808
cltq
movq 0x18(%rsp), %rcx
movq (%rcx,%rax,8), %r15
jmp 0x380b
xorl %r15d, %r15d
leaq 0xfc45(%rip), %rsi      # 0x13457
cmpb $0x0, 0x2(%r13)
jne 0x3933
xorl %r14d, %r14d
leaq 0x19269(%rip), %r12     # 0x1ca90
movq $0x0, 0x10(%rsp)
xorl %ebp, %ebp
testb $0x1, %bpl
jne 0x3910
cmpq $0x13, %r14
ja 0x3910
movb 0x1(%r13), %al
cmpb (%r12), %al
jne 0x386b
leaq 0x20(%rsp), %rdi
movq %r12, %rsi
movq %r15, %rdx
pushq $0x1
popq %rcx
callq 0x4028
movq %rax, 0x10(%rsp)
movb $0x1, %bpl
incq %r14
addq $0x28, %r12
jmp 0x3832
leaq 0x2(%r13), %rdi
callq 0x3150
movq %rax, %r15
leaq 0x1(%rbx), %rax
testq %rbx, %rbx
cmoveq %rbx, %rax
movq %rax, 0x58(%rsp)
leaq 0x2(%r13), %rax
movq %rax, 0x60(%rsp)
movq $0x0, 0x10(%rsp)
leaq 0x191e7(%rip), %r12     # 0x1ca90
xorl %ebp, %ebp
xorl %r14d, %r14d
testb $0x1, %bpl
jne 0x3910
cmpq $0x13, %r14
ja 0x3910
movq %r13, %rbx
movq 0x8(%r12), %r13
movq %r13, %rdi
callq 0x3150
cmpq %r15, %rax
jne 0x3904
movq 0x60(%rsp), %rdi
movq %r13, %rsi
movq %r15, %rdx
callq 0x3360
testl %eax, %eax
movq %rbx, %r13
jne 0x3907
leaq 0x20(%rsp), %rdi
movq %r12, %rsi
movq 0x58(%rsp), %rdx
xorl %ecx, %ecx
callq 0x4028
movq %rax, 0x10(%rsp)
movb $0x1, %bpl
jmp 0x3907
movq %rbx, %r13
incq %r14
addq $0x28, %r12
jmp 0x38ae
movq 0x10(%rsp), %r14
testl %r14d, %r14d
movq 0x50(%rsp), %rax
je 0x3947
addl %eax, %r14d
testb $0x1, %bpl
jne 0x379b
leaq 0xfb34(%rip), %rsi      # 0x13467
movq 0x1969e(%rip), %rax     # 0x1cfd8
movq (%rax), %rdi
movq %r13, %rdx
xorl %eax, %eax
callq 0x3480
callq 0x3ef7
pushq $0x1
popq %rax
jmp 0x39ef
leaq 0x20(%rsp), %r15
movq %r15, %rdi
callq 0x8914
callq 0xffd2
callq 0x5b35
movq %rax, %r14
movl 0x10(%r15), %edi
callq 0x10960
movq 0x18(%r15), %rdi
testq %rdi, %rdi
je 0x398d
callq 0x5ab2
testb %al, %al
je 0x3ee4
cmpb $0x1, 0x20(%rsp)
jne 0x399b
callq 0x3ef7
jmp 0x39ed
cmpb $0x0, 0x24(%rsp)
pushq $0xf
popq %rax
pushq $0x3
popq %rbp
cmovel %ebp, %eax
cmpb $0x0, 0x26(%rsp)
movq 0x18(%rsp), %rcx
leaq (%rcx,%r12,8), %r15
pushq $0x1f
popq %rdi
cmovel %eax, %edi
callq 0x597a
cmpb $0x1, 0x2a(%rsp)
jne 0x39dc
leaq 0xf6a0(%rip), %rdi      # 0x13070
movl %ebx, %esi
movq %r15, %rdx
callq 0x6401
jmp 0x39ed
cmpb $0x1, 0x2f(%rsp)
jne 0x3a01
movl %ebx, %edi
movq %r15, %rsi
callq 0x6576
xorl %eax, %eax
addq $0x4a8, %rsp            # imm = 0x4A8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x68(%rsp), %rdi
leaq 0x20(%rsp), %rsi
callq 0x95f2
testb %al, %al
je 0x394c
movq 0x148(%rsp), %rdi
testq %rdi, %rdi
je 0x3a31
movl 0x130(%rsp), %esi
callq 0xdedc
leaq 0x68(%rsp), %rdi
callq 0x8b8b
testb %al, %al
je 0x3a7d
cmpb $0x1, 0x128(%rsp)
jne 0x3a52
leaq 0xf62b(%rip), %rsi      # 0x1307b
jmp 0x3a71
cmpb $0x1, 0x123(%rsp)
jne 0x3e19
leaq 0x68(%rsp), %rdi
callq 0x8957
leaq 0xf629(%rip), %rsi      # 0x1309a
xorl %ebp, %ebp
pushq $0x8
popq %rdi
xorl %eax, %eax
callq 0x5981
leaq 0x68(%rsp), %rbx
movq %rbx, %rdi
callq 0x9713
cmpq $0x0, 0xe0(%rbx)
je 0x3a99
callq 0xe1f6
cmpb $0x1, 0x27(%rsp)
jne 0x3d7f
leaq 0x19af5(%rip), %r15     # 0x1d5a0
movq 0x80(%r15), %rdi
callq 0x5b6a
mulsd 0xf581(%rip), %xmm0     # 0x13040
leaq 0xf67b(%rip), %rdi      # 0x13141
movb $0x1, %al
callq 0x3060
movq 0x98(%r15), %rdi
callq 0x5b6a
mulsd 0xf55f(%rip), %xmm0     # 0x13040
leaq 0xf677(%rip), %rdi      # 0x1315f
movb $0x1, %al
callq 0x3060
leaq 0xfd39(%rip), %rdi      # 0x1382f
callq 0x3540
movl (%r15), %esi
leaq 0xf678(%rip), %rdi      # 0x1317d
xorl %eax, %eax
callq 0x3060
movl 0x4(%r15), %esi
leaq 0xf67f(%rip), %rdi      # 0x13196
xorl %eax, %eax
callq 0x3060
movl 0x8(%r15), %esi
leaq 0xf686(%rip), %rbx      # 0x131af
movq %rbx, %rdi
xorl %eax, %eax
callq 0x3060
movl 0xc(%r15), %esi
leaq 0xf68a(%rip), %rdi      # 0x131c8
xorl %eax, %eax
callq 0x3060
movq 0x10(%r15), %rdi
callq 0x5b6a
mulsd 0xf4ea(%rip), %xmm0     # 0x13040
leaq 0xf684(%rip), %rdi      # 0x131e1
movb $0x1, %al
callq 0x3060
movl 0x18(%r15), %esi
leaq 0xf690(%rip), %rdi      # 0x131ff
xorl %eax, %eax
callq 0x3060
leaq 0xfcbe(%rip), %rdi      # 0x1383b
callq 0x3540
movl 0xb0(%r15), %esi
leaq 0xf688(%rip), %rdi      # 0x13218
xorl %eax, %eax
callq 0x3060
movq 0xa8(%r15), %rdi
callq 0x5b6a
mulsd 0xf495(%rip), %xmm0     # 0x13040
leaq 0xf67f(%rip), %rdi      # 0x13231
movb $0x1, %al
callq 0x3060
movq 0xa0(%r15), %rdi
callq 0x5b6a
mulsd 0xf473(%rip), %xmm0     # 0x13040
leaq 0xf67b(%rip), %rdi      # 0x1324f
movb $0x1, %al
callq 0x3060
movl 0xb4(%r15), %esi
leaq 0xf684(%rip), %rdi      # 0x1326d
xorl %eax, %eax
callq 0x3060
movq 0xb8(%r15), %rdi
callq 0x5b6a
mulsd 0xf43c(%rip), %xmm0     # 0x13040
leaq 0xf67b(%rip), %rdi      # 0x13286
movb $0x1, %al
callq 0x3060
leaq 0xfc30(%rip), %rdi      # 0x13849
callq 0x3540
movl 0x70(%r15), %esi
leaq 0xf67b(%rip), %rdi      # 0x132a4
xorl %eax, %eax
callq 0x3060
movl 0x74(%r15), %esi
movq %rbx, %rdi
xorl %eax, %eax
callq 0x3060
movl 0x78(%r15), %esi
leaq 0xf674(%rip), %rdi      # 0x132bd
xorl %eax, %eax
callq 0x3060
leaq 0xfbfe(%rip), %rdi      # 0x13855
callq 0x3540
movl 0x20(%r15), %esi
leaq 0xf66f(%rip), %rdi      # 0x132d6
xorl %eax, %eax
callq 0x3060
movl 0x1c(%r15), %esi
leaq 0xf676(%rip), %rdi      # 0x132ef
xorl %eax, %eax
callq 0x3060
movl 0x24(%r15), %esi
leaq 0xf67d(%rip), %rdi      # 0x13308
xorl %eax, %eax
callq 0x3060
movq 0x28(%r15), %rdi
callq 0x5b6a
mulsd 0xf39d(%rip), %xmm0     # 0x13040
leaq 0xf677(%rip), %rdi      # 0x13321
movb $0x1, %al
callq 0x3060
movl 0x88(%r15), %esi
leaq 0xf680(%rip), %rdi      # 0x1333f
xorl %eax, %eax
callq 0x3060
movq 0x90(%r15), %rdi
callq 0x5b6a
leaq 0xf67f(%rip), %rdi      # 0x13358
movb $0x1, %al
callq 0x3060
leaq 0xfb78(%rip), %rdi      # 0x1385f
callq 0x3540
movl 0x30(%r15), %esi
leaq 0xf67e(%rip), %rdi      # 0x13375
xorl %eax, %eax
callq 0x3060
movq 0x38(%r15), %rdi
callq 0x5b6a
mulsd 0xf331(%rip), %xmm0     # 0x13040
leaq 0xf678(%rip), %rdi      # 0x1338e
movb $0x1, %al
callq 0x3060
movl 0x40(%r15), %esi
leaq 0xf684(%rip), %rdi      # 0x133ac
xorl %eax, %eax
callq 0x3060
movq 0x48(%r15), %rdi
callq 0x5b6a
mulsd 0xf300(%rip), %xmm0     # 0x13040
leaq 0xf67e(%rip), %rdi      # 0x133c5
movb $0x1, %al
callq 0x3060
movl 0x60(%r15), %esi
leaq 0xf68a(%rip), %rdi      # 0x133e3
xorl %eax, %eax
callq 0x3060
movq 0x68(%r15), %rdi
callq 0x5b6a
mulsd 0xf2cf(%rip), %xmm0     # 0x13040
leaq 0xf684(%rip), %rdi      # 0x133fc
movb $0x1, %al
callq 0x3060
cmpb $0x0, 0x29(%rsp)
jne 0x3e0d
callq 0x5b35
movq %r14, %rdi
movq %rax, %rsi
callq 0x5b94
movsd 0xf2a6(%rip), %xmm1     # 0x13048
ucomisd %xmm0, %xmm1
jbe 0x3dc5
movl %ebp, %eax
leaq 0x1959f(%rip), %rcx     # 0x1d350
movq (%rcx,%rax,8), %rsi
leaq 0xf65e(%rip), %rdi      # 0x1341a
movb $0x1, %al
callq 0x3060
jmp 0x3e0d
cvttsd2si %xmm0, %ecx
movl $0xe10, %esi            # imm = 0xE10
movl %ecx, %eax
cltd
idivl %esi
movl %eax, %r9d
imull $0xfffff1f0, %eax, %esi # imm = 0xFFFFF1F0
addl %ecx, %esi
pushq $0x3c
popq %rcx
movl %esi, %eax
cltd
idivl %ecx
imull $-0x3c, %eax, %r8d
addl %esi, %r8d
movl %ebp, %ecx
leaq 0x1955a(%rip), %rdx     # 0x1d350
movq (%rdx,%rcx,8), %rsi
leaq 0xf630(%rip), %rdi      # 0x13431
movl %r9d, %edx
movl %eax, %ecx
movb $0x1, %al
callq 0x3060
xorl %eax, %eax
testl %ebp, %ebp
setne %al
jmp 0x39ef
leaq 0x68(%rsp), %r12
movq %r12, %rdi
callq 0x9f8d
movq %r12, %rdi
movq %r15, %rsi
movl %ebx, %edx
callq 0x9026
testb %al, %al
je 0x3ed6
cmpb $0x0, 0x12b(%rsp)
jne 0x3e4f
cmpb $0x1, 0x12c(%rsp)
jne 0x3e6b
leaq 0x68(%rsp), %rbx
movq %rbx, %rdi
callq 0xa464
xorl %ebp, %ebp
cmpb $0x1, 0xc4(%rbx)
jne 0x3a7d
leaq 0x68(%rsp), %rbx
movq %rbx, %rdi
callq 0x97a1
movl %eax, %ebp
movq %rbx, %rdi
callq 0x9b17
testb %al, %al
jne 0x3e97
leaq 0xf256(%rip), %rsi      # 0x130e3
pushq $0x1
popq %rdi
xorl %eax, %eax
callq 0x5981
leaq 0x68(%rsp), %rdi
callq 0x9a44
testb %al, %al
jne 0x3eb6
leaq 0xf251(%rip), %rsi      # 0x130fd
pushq $0x2
popq %rdi
xorl %eax, %eax
callq 0x5981
leaq 0x68(%rsp), %rdi
callq 0x9adb
testb %al, %al
jne 0x3a7d
leaq 0xf252(%rip), %rsi      # 0x13121
pushq $0x2
jmp 0x3a75
leaq 0xf1dd(%rip), %rsi      # 0x130ba
pushq $0x1
jmp 0x3a75
movq 0x38(%rsp), %rsi
leaq 0xf160(%rip), %rdi      # 0x13050
xorl %eax, %eax
callq 0x56cd