// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x4b0, %rsp            # imm = 0x4B0
movl $0x0, -0x4(%rbp)
movl %edi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
callq 0x7590
leaq -0x480(%rbp), %rdi
callq 0xd470
leaq -0x480(%rbp), %rdi
leaq -0x8(%rbp), %rsi
leaq -0x10(%rbp), %rdx
callq 0x3f80
testb $0x1, %al
jne 0x37a3
callq 0x42a0
movl $0x1, -0x4(%rbp)
jmp 0x3f6d
leaq -0x480(%rbp), %rdi
callq 0xd440
callq 0x1d9e0
callq 0x7d10
movq %rax, -0x488(%rbp)
movl -0x470(%rbp), %edi
callq 0x1ebc0
cmpq $0x0, -0x468(%rbp)
je 0x37fc
movq -0x468(%rbp), %rdi
callq 0x7c10
testb $0x1, %al
jne 0x37fa
movq -0x468(%rbp), %rsi
leaq 0x1f85d(%rip), %rdi     # 0x23050
movb $0x0, %al
callq 0x75a0
jmp 0x37fc
testb $0x1, -0x480(%rbp)
je 0x3816
callq 0x42a0
movl $0x0, -0x4(%rbp)
jmp 0x3f6d
movl $0x3, -0x48c(%rbp)
testb $0x1, -0x47c(%rbp)
je 0x3838
movl -0x48c(%rbp), %eax
orl $0xc, %eax
movl %eax, -0x48c(%rbp)
testb $0x1, -0x47a(%rbp)
je 0x3850
movl -0x48c(%rbp), %eax
orl $0x1c, %eax
movl %eax, -0x48c(%rbp)
movl -0x48c(%rbp), %edi
callq 0x7a40
testb $0x1, -0x476(%rbp)
je 0x3883
movl -0x8(%rbp), %esi
movq -0x10(%rbp), %rdx
leaq 0x1f7fe(%rip), %rdi     # 0x23070
callq 0x8bb0
movl $0x0, -0x4(%rbp)
jmp 0x3f6d
testb $0x1, -0x471(%rbp)
je 0x38a4
movl -0x8(%rbp), %edi
movq -0x10(%rbp), %rsi
callq 0x8d20
movl $0x0, -0x4(%rbp)
jmp 0x3f6d
leaq -0x450(%rbp), %rdi
leaq -0x480(%rbp), %rsi
callq 0xe650
testb $0x1, %al
jne 0x38c7
movl $0x1, -0x4(%rbp)
jmp 0x3f6d
cmpq $0x0, -0x370(%rbp)
je 0x38e3
movq -0x370(%rbp), %rdi
movl -0x388(%rbp), %esi
callq 0x19830
movl $0x3, -0x490(%rbp)
leaq -0x450(%rbp), %rdi
callq 0xd7e0
testb $0x1, %al
jne 0x3902
jmp 0x3a51
testb $0x1, -0x390(%rbp)
je 0x392d
movl $0x8, %edi
leaq 0x1f764(%rip), %rsi     # 0x2307b
movb $0x0, %al
callq 0x7a60
movl $0x0, -0x490(%rbp)
jmp 0x3a51
testb $0x1, -0x395(%rbp)
je 0x3964
leaq -0x450(%rbp), %rdi
callq 0xd540
movl $0x8, %edi
leaq 0x1f74c(%rip), %rsi     # 0x2309a
movb $0x0, %al
callq 0x7a60
movl $0x0, -0x490(%rbp)
jmp 0x3a51
leaq -0x450(%rbp), %rdi
callq 0xf770
movq -0x10(%rbp), %rsi
movl -0x8(%rbp), %edx
leaq -0x450(%rbp), %rdi
callq 0xdc90
testb $0x1, %al
jne 0x399f
movl $0x1, %edi
leaq 0x1f727(%rip), %rsi     # 0x230ba
movb $0x0, %al
callq 0x7a60
jmp 0x3a51
testb $0x1, -0x38d(%rbp)
jne 0x39b1
testb $0x1, -0x38c(%rbp)
je 0x39d4
leaq -0x450(%rbp), %rdi
callq 0x10030
testb $0x1, -0x38c(%rbp)
jne 0x39d2
movl $0x0, -0x490(%rbp)
jmp 0x3a51
jmp 0x39d4
leaq -0x450(%rbp), %rdi
callq 0xe8b0
movl %eax, -0x490(%rbp)
leaq -0x450(%rbp), %rdi
callq 0xeda0
testb $0x1, %al
jne 0x3a09
movl $0x1, %edi
leaq 0x1f6e1(%rip), %rsi     # 0x230e3
movb $0x0, %al
callq 0x7a60
leaq -0x450(%rbp), %rdi
callq 0xec30
testb $0x1, %al
jne 0x3a2c
movl $0x2, %edi
leaq 0x1f6d8(%rip), %rsi     # 0x230fd
movb $0x0, %al
callq 0x7a60
leaq -0x450(%rbp), %rdi
callq 0xed30
testb $0x1, %al
jne 0x3a4f
movl $0x2, %edi
leaq 0x1f6d9(%rip), %rsi     # 0x23121
movb $0x0, %al
callq 0x7a60
jmp 0x3a51
leaq -0x450(%rbp), %rdi
callq 0xe7e0
cmpq $0x0, -0x370(%rbp)
je 0x3a6c
callq 0x19c10
testb $0x1, -0x479(%rbp)
je 0x3e33
leaq 0x2bb10(%rip), %rax     # 0x2f590
movq 0x80(%rax), %rdi
callq 0x7d50
movsd 0x1f5ac(%rip), %xmm1    # 0x23040
mulsd %xmm1, %xmm0
leaq 0x1f6a2(%rip), %rdi     # 0x23141
movb $0x1, %al
callq 0x3060
leaq 0x2bae3(%rip), %rax     # 0x2f590
movq 0x98(%rax), %rdi
callq 0x7d50
movsd 0x1f57f(%rip), %xmm1    # 0x23040
mulsd %xmm1, %xmm0
leaq 0x1f693(%rip), %rdi     # 0x2315f
movb $0x1, %al
callq 0x3060
leaq 0x1f6a3(%rip), %rdi     # 0x2317d
movb $0x0, %al
callq 0x3060
leaq 0x2baa8(%rip), %rax     # 0x2f590
movl (%rax), %esi
leaq 0x1f699(%rip), %rdi     # 0x2318a
movb $0x0, %al
callq 0x3060
leaq 0x2ba91(%rip), %rax     # 0x2f590
movl 0x4(%rax), %esi
leaq 0x1f69a(%rip), %rdi     # 0x231a3
movb $0x0, %al
callq 0x3060
leaq 0x2ba79(%rip), %rax     # 0x2f590
movl 0x8(%rax), %esi
leaq 0x1f69b(%rip), %rdi     # 0x231bc
movb $0x0, %al
callq 0x3060
leaq 0x2ba61(%rip), %rax     # 0x2f590
movl 0xc(%rax), %esi
leaq 0x1f69c(%rip), %rdi     # 0x231d5
movb $0x0, %al
callq 0x3060
leaq 0x2ba49(%rip), %rax     # 0x2f590
movq 0x10(%rax), %rdi
callq 0x7d50
movsd 0x1f4e8(%rip), %xmm1    # 0x23040
mulsd %xmm1, %xmm0
leaq 0x1f68b(%rip), %rdi     # 0x231ee
movb $0x1, %al
callq 0x3060
leaq 0x2ba1f(%rip), %rax     # 0x2f590
movl 0x18(%rax), %esi
leaq 0x1f691(%rip), %rdi     # 0x2320c
movb $0x0, %al
callq 0x3060
leaq 0x1f69c(%rip), %rdi     # 0x23225
movb $0x0, %al
callq 0x3060
leaq 0x2b9f9(%rip), %rax     # 0x2f590
movl 0xb0(%rax), %esi
leaq 0x1f690(%rip), %rdi     # 0x23234
movb $0x0, %al
callq 0x3060
leaq 0x2b9de(%rip), %rax     # 0x2f590
movq 0xa8(%rax), %rdi
callq 0x7d50
movsd 0x1f47a(%rip), %xmm1    # 0x23040
mulsd %xmm1, %xmm0
leaq 0x1f67c(%rip), %rdi     # 0x2324d
movb $0x1, %al
callq 0x3060
leaq 0x2b9b1(%rip), %rax     # 0x2f590
movq 0xa0(%rax), %rdi
callq 0x7d50
movsd 0x1f44d(%rip), %xmm1    # 0x23040
mulsd %xmm1, %xmm0
leaq 0x1f66d(%rip), %rdi     # 0x2326b
movb $0x1, %al
callq 0x3060
leaq 0x2b984(%rip), %rax     # 0x2f590
movl 0xb4(%rax), %esi
leaq 0x1f670(%rip), %rdi     # 0x23289
movb $0x0, %al
callq 0x3060
leaq 0x2b969(%rip), %rax     # 0x2f590
movq 0xb8(%rax), %rdi
callq 0x7d50
movsd 0x1f405(%rip), %xmm1    # 0x23040
mulsd %xmm1, %xmm0
leaq 0x1f65c(%rip), %rdi     # 0x232a2
movb $0x1, %al
callq 0x3060
leaq 0x1f66c(%rip), %rdi     # 0x232c0
movb $0x0, %al
callq 0x3060
leaq 0x2b92e(%rip), %rax     # 0x2f590
movl 0x70(%rax), %esi
leaq 0x1f661(%rip), %rdi     # 0x232cd
movb $0x0, %al
callq 0x3060
leaq 0x2b916(%rip), %rax     # 0x2f590
movl 0x74(%rax), %esi
leaq 0x1f538(%rip), %rdi     # 0x231bc
movb $0x0, %al
callq 0x3060
leaq 0x2b8fe(%rip), %rax     # 0x2f590
movl 0x78(%rax), %esi
leaq 0x1f64a(%rip), %rdi     # 0x232e6
movb $0x0, %al
callq 0x3060
leaq 0x1f655(%rip), %rdi     # 0x232ff
movb $0x0, %al
callq 0x3060
leaq 0x2b8d8(%rip), %rax     # 0x2f590
movl 0x20(%rax), %esi
leaq 0x1f648(%rip), %rdi     # 0x2330a
movb $0x0, %al
callq 0x3060
leaq 0x2b8c0(%rip), %rax     # 0x2f590
movl 0x1c(%rax), %esi
leaq 0x1f649(%rip), %rdi     # 0x23323
movb $0x0, %al
callq 0x3060
leaq 0x2b8a8(%rip), %rax     # 0x2f590
movl 0x24(%rax), %esi
leaq 0x1f64a(%rip), %rdi     # 0x2333c
movb $0x0, %al
callq 0x3060
leaq 0x2b890(%rip), %rax     # 0x2f590
movq 0x28(%rax), %rdi
callq 0x7d50
movsd 0x1f32f(%rip), %xmm1    # 0x23040
mulsd %xmm1, %xmm0
leaq 0x1f639(%rip), %rdi     # 0x23355
movb $0x1, %al
callq 0x3060
leaq 0x2b866(%rip), %rax     # 0x2f590
movl 0x88(%rax), %esi
leaq 0x1f63c(%rip), %rdi     # 0x23373
movb $0x0, %al
callq 0x3060
leaq 0x2b84b(%rip), %rax     # 0x2f590
movq 0x90(%rax), %rdi
callq 0x7d50
leaq 0x1f634(%rip), %rdi     # 0x2338c
movb $0x1, %al
callq 0x3060
leaq 0x1f643(%rip), %rdi     # 0x233a9
movb $0x0, %al
callq 0x3060
leaq 0x2b81c(%rip), %rax     # 0x2f590
movl 0x30(%rax), %esi
leaq 0x1f640(%rip), %rdi     # 0x233be
movb $0x0, %al
callq 0x3060
leaq 0x2b804(%rip), %rax     # 0x2f590
movq 0x38(%rax), %rdi
callq 0x7d50
movsd 0x1f2a3(%rip), %xmm1    # 0x23040
mulsd %xmm1, %xmm0
leaq 0x1f62f(%rip), %rdi     # 0x233d7
movb $0x1, %al
callq 0x3060
leaq 0x2b7da(%rip), %rax     # 0x2f590
movl 0x40(%rax), %esi
leaq 0x1f635(%rip), %rdi     # 0x233f5
movb $0x0, %al
callq 0x3060
leaq 0x2b7c2(%rip), %rax     # 0x2f590
movq 0x48(%rax), %rdi
callq 0x7d50
movsd 0x1f261(%rip), %xmm1    # 0x23040
mulsd %xmm1, %xmm0
leaq 0x1f624(%rip), %rdi     # 0x2340e
movb $0x1, %al
callq 0x3060
leaq 0x2b798(%rip), %rax     # 0x2f590
movl 0x60(%rax), %esi
leaq 0x1f62a(%rip), %rdi     # 0x2342c
movb $0x0, %al
callq 0x3060
leaq 0x2b780(%rip), %rax     # 0x2f590
movq 0x68(%rax), %rdi
callq 0x7d50
movsd 0x1f21f(%rip), %xmm1    # 0x23040
mulsd %xmm1, %xmm0
leaq 0x1f619(%rip), %rdi     # 0x23445
movb $0x1, %al
callq 0x3060
testb $0x1, -0x477(%rbp)
jne 0x3f57
movq -0x488(%rbp), %rax
movq %rax, -0x4b0(%rbp)
callq 0x7d10
movq -0x4b0(%rbp), %rdi
movq %rax, %rsi
callq 0x7d90
movsd %xmm0, -0x498(%rbp)
movsd 0x1f1d6(%rip), %xmm0    # 0x23048
ucomisd -0x498(%rbp), %xmm0
jbe 0x3eaa
movl -0x490(%rbp), %eax
movl %eax, %ecx
leaq 0x2b4b5(%rip), %rax     # 0x2f340
movq (%rax,%rcx,8), %rsi
movsd -0x498(%rbp), %xmm0
leaq 0x1f5c5(%rip), %rdi     # 0x23463
movb $0x1, %al
callq 0x3060
jmp 0x3f55
cvttsd2si -0x498(%rbp), %eax
movl %eax, -0x49c(%rbp)
movl -0x49c(%rbp), %eax
movl $0xe10, %ecx            # imm = 0xE10
cltd
idivl %ecx
movl %eax, -0x4a0(%rbp)
imull $0xe10, -0x4a0(%rbp), %ecx # imm = 0xE10
movl -0x49c(%rbp), %eax
subl %ecx, %eax
movl %eax, -0x49c(%rbp)
movl -0x49c(%rbp), %eax
movl $0x3c, %ecx
cltd
idivl %ecx
movl %eax, -0x4a4(%rbp)
imull $0x3c, -0x4a4(%rbp), %ecx
movl -0x49c(%rbp), %eax
subl %ecx, %eax
movl %eax, -0x49c(%rbp)
movl -0x49c(%rbp), %eax
movl %eax, -0x4a8(%rbp)
movl -0x490(%rbp), %eax
movl %eax, %ecx
leaq 0x2b418(%rip), %rax     # 0x2f340
movq (%rax,%rcx,8), %rsi
movsd -0x498(%rbp), %xmm0
movl -0x4a0(%rbp), %edx
movl -0x4a4(%rbp), %ecx
movl -0x4a8(%rbp), %r8d
leaq 0x1f52c(%rip), %rdi     # 0x2347a
movb $0x1, %al
callq 0x3060
jmp 0x3f57
movl -0x490(%rbp), %edx
movl $0x1, %eax
xorl %ecx, %ecx
cmpl $0x0, %edx
cmovel %ecx, %eax
movl %eax, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x4b0, %rsp            # imm = 0x4B0
popq %rbp
retq
nopl (%rax)