// File: /workspace/github_c_makefile_star2_O1/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 $0x498, %rsp            # imm = 0x498
movq %rsi, %r15
movl %edi, %r12d
callq 0x5bdc
leaq 0x20(%rsp), %rbp
movq %rbp, %rdi
callq 0x95ca
movl $0x1, %r14d
movq %r15, 0x8(%rsp)
movl %r12d, 0x4(%rsp)
cmpl %r12d, %r14d
jge 0x3bfc
movslq %r14d, %rax
movq (%r15,%rax,8), %rdi
movl $0x3, %ebx
cmpb $0x2d, (%rdi)
jne 0x3ba2
cmpb $0x2d, 0x1(%rdi)
movq %rdi, 0x18(%rsp)
movq %r14, 0x10(%rsp)
jne 0x3a5b
movl $0x3d, %esi
movq %rdi, %r14
callq 0x3130
movq %rax, %rbx
testq %rax, %rax
je 0x3adb
movq %rbx, %r13
subq %r14, %r13
addq $-0x2, %r13
jmp 0x3ae7
leal 0x1(%r14), %eax
cmpl %r12d, %eax
jge 0x3a6c
cltq
movq (%r15,%rax,8), %rbx
jmp 0x3a6e
xorl %ebx, %ebx
movb 0x2(%rdi), %r15b
testb %r15b, %r15b
jne 0x3bac
xorl %r12d, %r12d
leaq 0x1900b(%rip), %r14     # 0x1ca90
movl $0x0, (%rsp)
xorl %r13d, %r13d
movb 0x1(%rdi), %al
cmpb (%r14), %al
jne 0x3ab5
movq %rbp, %rdi
movq %r14, %rsi
movq %rbx, %rdx
movl $0x1, %ecx
callq 0x4324
movq 0x18(%rsp), %rdi
movl %eax, (%rsp)
movb $0x1, %r12b
cmpq $0x12, %r13
ja 0x3ac8
incq %r13
addq $0x28, %r14
testb $0x1, %r12b
je 0x3a8f
movl $0x1, %ebx
testb %r15b, %r15b
jne 0x3b8e
jmp 0x3b5e
leaq 0x2(%r14), %rdi
callq 0x3150
movq %rax, %r13
leaq 0x1(%rbx), %rax
testq %rbx, %rbx
cmoveq %rbx, %rax
movq %rax, 0x50(%rsp)
leaq 0x2(%r14), %r15
xorl %ebp, %ebp
leaq 0x18f8c(%rip), %rbx     # 0x1ca90
xorl %r12d, %r12d
movl $0x0, (%rsp)
movq 0x8(%rbx), %r14
movq %r14, %rdi
callq 0x3150
cmpq %r13, %rax
jne 0x3b4b
movq %r15, %rdi
movq %r14, %rsi
movq %r13, %rdx
callq 0x3360
testl %eax, %eax
jne 0x3b4b
leaq 0x20(%rsp), %rdi
movq %rbx, %rsi
movq 0x50(%rsp), %rdx
xorl %ecx, %ecx
callq 0x4324
movl %eax, (%rsp)
movb $0x1, %r12b
cmpq $0x12, %rbp
ja 0x3b5e
incq %rbp
addq $0x28, %rbx
testb $0x1, %r12b
je 0x3b0e
movl $0x1, %ebx
movl (%rsp), %eax
testl %eax, %eax
je 0x3b8e
testb $0x1, %r12b
movq 0x10(%rsp), %r14
leaq 0x20(%rsp), %rbp
je 0x3bd8
addl %r14d, %eax
xorl %ebx, %ebx
movl %eax, %r14d
movq 0x8(%rsp), %r15
movl 0x4(%rsp), %r12d
jmp 0x3ba2
movq 0x8(%rsp), %r15
movl 0x4(%rsp), %r12d
movq 0x10(%rsp), %r14
leaq 0x20(%rsp), %rbp
testl %ebx, %ebx
je 0x3a05
jmp 0x3bf7
movq 0x19425(%rip), %rax     # 0x1cfd8
movq (%rax), %rdi
movl $0x0, (%rsp)
leaq 0x11893(%rip), %rsi     # 0x15457
movq 0x18(%rsp), %rdx
xorl %eax, %eax
callq 0x3480
xorl %r12d, %r12d
jmp 0x3ac8
movq 0x193f9(%rip), %rax     # 0x1cfd8
movq (%rax), %rdi
leaq 0x1187e(%rip), %rsi     # 0x15467
movq 0x18(%rsp), %rdx
xorl %eax, %eax
callq 0x3480
jmp 0x3b82
cmpl $0x3, %ebx
jne 0x3c0a
subl %r14d, %r12d
movslq %r14d, %rax
leaq (%r15,%rax,8), %r15
movb $0x1, %al
jmp 0x3c0c
xorl %eax, %eax
testb %al, %al
je 0x3c57
leaq 0x20(%rsp), %r14
movq %r14, %rdi
callq 0x95b0
callq 0x11b1a
callq 0x60a6
movq %rax, %rbx
movl 0x10(%r14), %edi
callq 0x12728
movq 0x18(%r14), %rdi
testq %rdi, %rdi
je 0x3c49
callq 0x6023
testb %al, %al
je 0x41da
cmpb $0x1, 0x20(%rsp)
jne 0x3c63
callq 0x41ed
jmp 0x3cb4
callq 0x41ed
movl $0x1, %eax
jmp 0x3cb6
cmpb $0x0, 0x24(%rsp)
movl $0xf, %eax
movl $0x3, %ecx
cmovnel %eax, %ecx
cmpb $0x0, 0x26(%rsp)
movl $0x1f, %edi
cmovel %ecx, %edi
callq 0x5ee9
cmpb $0x1, 0x2a(%rsp)
jne 0x3ca2
leaq 0x113db(%rip), %rdi     # 0x15070
movl %r12d, %esi
movq %r15, %rdx
callq 0x6ab0
jmp 0x3cb4
cmpb $0x1, 0x2f(%rsp)
jne 0x3cc8
movl %r12d, %edi
movq %r15, %rsi
callq 0x6c3d
xorl %eax, %eax
addq $0x498, %rsp            # imm = 0x498
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x58(%rsp), %rdi
leaq 0x20(%rsp), %rsi
callq 0xa628
movl %eax, %ecx
movl $0x1, %eax
testb %cl, %cl
je 0x3cb6
movq 0x138(%rsp), %rdi
testq %rdi, %rdi
je 0x3cfb
movl 0x120(%rsp), %esi
callq 0xf6c0
leaq 0x58(%rsp), %rdi
callq 0x9816
movl $0x3, %ebp
testb %al, %al
je 0x3d4e
cmpb $0x1, 0x118(%rsp)
jne 0x3d21
leaq 0x1135c(%rip), %rsi     # 0x1507b
jmp 0x3d40
cmpb $0x1, 0x113(%rsp)
jne 0x4103
leaq 0x58(%rsp), %rdi
callq 0x95f3
leaq 0x1135a(%rip), %rsi     # 0x1509a
xorl %ebp, %ebp
movl $0x8, %edi
xorl %eax, %eax
callq 0x5ef0
leaq 0x58(%rsp), %r14
movq %r14, %rdi
callq 0xa74c
cmpq $0x0, 0xe0(%r14)
je 0x3d6a
callq 0xfa02
cmpb $0x1, 0x27(%rsp)
jne 0x4050
leaq 0x19824(%rip), %r15     # 0x1d5a0
movq 0x80(%r15), %rdi
callq 0x60db
mulsd 0x112b0(%rip), %xmm0    # 0x15040
leaq 0x113aa(%rip), %rdi     # 0x15141
movb $0x1, %al
callq 0x3060
movq 0x98(%r15), %rdi
callq 0x60db
mulsd 0x1128e(%rip), %xmm0    # 0x15040
leaq 0x113a6(%rip), %rdi     # 0x1515f
movb $0x1, %al
callq 0x3060
leaq 0x11a68(%rip), %rdi     # 0x1582f
callq 0x3540
movl (%r15), %esi
leaq 0x113a7(%rip), %rdi     # 0x1517d
xorl %eax, %eax
callq 0x3060
movl 0x4(%r15), %esi
leaq 0x113ae(%rip), %rdi     # 0x15196
xorl %eax, %eax
callq 0x3060
movl 0x8(%r15), %esi
leaq 0x113b5(%rip), %r14     # 0x151af
movq %r14, %rdi
xorl %eax, %eax
callq 0x3060
movl 0xc(%r15), %esi
leaq 0x113b9(%rip), %rdi     # 0x151c8
xorl %eax, %eax
callq 0x3060
movq 0x10(%r15), %rdi
callq 0x60db
mulsd 0x11219(%rip), %xmm0    # 0x15040
leaq 0x113b3(%rip), %rdi     # 0x151e1
movb $0x1, %al
callq 0x3060
movl 0x18(%r15), %esi
leaq 0x113bf(%rip), %rdi     # 0x151ff
xorl %eax, %eax
callq 0x3060
leaq 0x119ed(%rip), %rdi     # 0x1583b
callq 0x3540
movl 0xb0(%r15), %esi
leaq 0x113b7(%rip), %rdi     # 0x15218
xorl %eax, %eax
callq 0x3060
movq 0xa8(%r15), %rdi
callq 0x60db
mulsd 0x111c4(%rip), %xmm0    # 0x15040
leaq 0x113ae(%rip), %rdi     # 0x15231
movb $0x1, %al
callq 0x3060
movq 0xa0(%r15), %rdi
callq 0x60db
mulsd 0x111a2(%rip), %xmm0    # 0x15040
leaq 0x113aa(%rip), %rdi     # 0x1524f
movb $0x1, %al
callq 0x3060
movl 0xb4(%r15), %esi
leaq 0x113b3(%rip), %rdi     # 0x1526d
xorl %eax, %eax
callq 0x3060
movq 0xb8(%r15), %rdi
callq 0x60db
mulsd 0x1116b(%rip), %xmm0    # 0x15040
leaq 0x113aa(%rip), %rdi     # 0x15286
movb $0x1, %al
callq 0x3060
leaq 0x1195f(%rip), %rdi     # 0x15849
callq 0x3540
movl 0x70(%r15), %esi
leaq 0x113aa(%rip), %rdi     # 0x152a4
xorl %eax, %eax
callq 0x3060
movl 0x74(%r15), %esi
movq %r14, %rdi
xorl %eax, %eax
callq 0x3060
movl 0x78(%r15), %esi
leaq 0x113a3(%rip), %rdi     # 0x152bd
xorl %eax, %eax
callq 0x3060
leaq 0x1192d(%rip), %rdi     # 0x15855
callq 0x3540
movl 0x20(%r15), %esi
leaq 0x1139e(%rip), %rdi     # 0x152d6
xorl %eax, %eax
callq 0x3060
movl 0x1c(%r15), %esi
leaq 0x113a5(%rip), %rdi     # 0x152ef
xorl %eax, %eax
callq 0x3060
movl 0x24(%r15), %esi
leaq 0x113ac(%rip), %rdi     # 0x15308
xorl %eax, %eax
callq 0x3060
movq 0x28(%r15), %rdi
callq 0x60db
mulsd 0x110cc(%rip), %xmm0    # 0x15040
leaq 0x113a6(%rip), %rdi     # 0x15321
movb $0x1, %al
callq 0x3060
movl 0x88(%r15), %esi
leaq 0x113af(%rip), %rdi     # 0x1533f
xorl %eax, %eax
callq 0x3060
movq 0x90(%r15), %rdi
callq 0x60db
leaq 0x113ae(%rip), %rdi     # 0x15358
movb $0x1, %al
callq 0x3060
leaq 0x118a7(%rip), %rdi     # 0x1585f
callq 0x3540
movl 0x30(%r15), %esi
leaq 0x113ad(%rip), %rdi     # 0x15375
xorl %eax, %eax
callq 0x3060
movq 0x38(%r15), %rdi
callq 0x60db
mulsd 0x11060(%rip), %xmm0    # 0x15040
leaq 0x113a7(%rip), %rdi     # 0x1538e
movb $0x1, %al
callq 0x3060
movl 0x40(%r15), %esi
leaq 0x113b3(%rip), %rdi     # 0x153ac
xorl %eax, %eax
callq 0x3060
movq 0x48(%r15), %rdi
callq 0x60db
mulsd 0x1102f(%rip), %xmm0    # 0x15040
leaq 0x113ad(%rip), %rdi     # 0x153c5
movb $0x1, %al
callq 0x3060
movl 0x60(%r15), %esi
leaq 0x113b9(%rip), %rdi     # 0x153e3
xorl %eax, %eax
callq 0x3060
movq 0x68(%r15), %rdi
callq 0x60db
mulsd 0x10ffe(%rip), %xmm0    # 0x15040
leaq 0x113b3(%rip), %rdi     # 0x153fc
movb $0x1, %al
callq 0x3060
cmpb $0x0, 0x29(%rsp)
jne 0x40f7
callq 0x60a6
movq %rbx, %rdi
movq %rax, %rsi
callq 0x6105
movsd 0x10fd5(%rip), %xmm1    # 0x15048
ucomisd %xmm0, %xmm1
jbe 0x4096
movl %ebp, %eax
leaq 0x192ce(%rip), %rcx     # 0x1d350
movq (%rcx,%rax,8), %rsi
leaq 0x1138d(%rip), %rdi     # 0x1541a
movb $0x1, %al
callq 0x3060
jmp 0x40f7
cvttsd2si %xmm0, %eax
cltq
imulq $-0x6e5d4c3b, %rax, %rdx # imm = 0x91A2B3C5
shrq $0x20, %rdx
addl %eax, %edx
movl %edx, %ecx
shrl $0x1f, %ecx
sarl $0xb, %edx
addl %ecx, %edx
imull $0xfffff1f0, %edx, %ecx # imm = 0xFFFFF1F0
addl %eax, %ecx
movslq %ecx, %rax
imulq $-0x77777777, %rax, %rcx # imm = 0x88888889
shrq $0x20, %rcx
addl %eax, %ecx
movl %ecx, %esi
shrl $0x1f, %esi
sarl $0x5, %ecx
addl %esi, %ecx
imull $-0x3c, %ecx, %r8d
addl %eax, %r8d
movl %ebp, %eax
leaq 0x1926b(%rip), %rsi     # 0x1d350
movq (%rsi,%rax,8), %rsi
leaq 0x11341(%rip), %rdi     # 0x15431
movb $0x1, %al
callq 0x3060
xorl %eax, %eax
testl %ebp, %ebp
setne %al
jmp 0x3cb6
leaq 0x58(%rsp), %r14
movq %r14, %rdi
callq 0xb23a
movq %r14, %rdi
movq %r15, %rsi
movl %r12d, %edx
callq 0x9d42
testb %al, %al
je 0x41c9
cmpb $0x0, 0x11b(%rsp)
jne 0x413a
cmpb $0x1, 0x11c(%rsp)
jne 0x4157
leaq 0x58(%rsp), %r14
movq %r14, %rdi
callq 0xb81b
xorl %ebp, %ebp
cmpb $0x1, 0xc4(%r14)
jne 0x3d4e
leaq 0x58(%rsp), %r14
movq %r14, %rdi
callq 0xa819
movl %eax, %ebp
movq %r14, %rdi
callq 0xabab
testb %al, %al
jne 0x4185
leaq 0x10f6a(%rip), %rsi     # 0x150e3
movl $0x1, %edi
xorl %eax, %eax
callq 0x5ef0
leaq 0x58(%rsp), %rdi
callq 0xaad6
testb %al, %al
jne 0x41a6
leaq 0x10f63(%rip), %rsi     # 0x150fd
movl $0x2, %edi
xorl %eax, %eax
callq 0x5ef0
leaq 0x58(%rsp), %rdi
callq 0xab6f
testb %al, %al
jne 0x3d4e
leaq 0x10f62(%rip), %rsi     # 0x15121
movl $0x2, %edi
jmp 0x3d47
leaq 0x10eea(%rip), %rsi     # 0x150ba
movl $0x1, %edi
jmp 0x3d47
movq 0x38(%rsp), %rsi
leaq 0x10e6a(%rip), %rdi     # 0x15050
xorl %eax, %eax
callq 0x5bdd