// File: /workspace/github_c_makefile_star2_O0/deplinenoise[P]tundra/src/Profiler.cpp
// Function: t2::ProfilerWriteOutput()
void ProfilerWriteOutput()
  {
    FILE* f = fopen(s_ProfilerState.m_FileName, "w");
    if (!f)
    {
      Log(kWarning, "profiler: failed to write profiler output file into '%s'", s_ProfilerState.m_FileName);
      return;
    }

    // See https://docs.google.com/document/d/1CvAClvFfyA5R-PhYUmn5OOQtYMH4h6I0nSsKchNAySU/edit for
    // Chrome Tracing profiler format description

    fputs("{\n", f);
    // JSON does not support comments, so emit "how to use this" as a fake string value    
    fputs("\"instructions_readme\": \"1) Open Chrome, 2) go to chrome://tracing, 3) click Load, 4) navigate to this file.\",\n", f);
    fputs("\"traceEvents\":[\n", f);
    fputs("{ \"cat\":\"\", \"pid\":1, \"tid\":0, \"ts\":0, \"ph\":\"M\", \"name\":\"process_name\", \"args\": { \"name\":\"tundra\" } }\n", f);
    for (int i = 0; i < s_ProfilerState.m_ThreadCount; ++i)
    {
      const ProfilerThread& thread = s_ProfilerState.m_Threads[i];
      for (int j = 0; j < thread.m_EventCount; ++j)
      {
        const ProfilerEvent& evt = thread.m_Events[j];
        double timeUs = TimerToSeconds(evt.m_Time)*1.0e6;
        double durUs = TimerToSeconds(evt.m_Duration)*1.0e6;
        char name[1024];
        char info[1024];
        EscapeString(evt.m_Name, name, sizeof(name));
        EscapeString(evt.m_Info, info, sizeof(info));
        fprintf(f, ",{ \"pid\":1, \"tid\":%d, \"ts\":%.0f, \"dur\":%.0f, \"ph\":\"X\", \"name\": \"%s\", \"args\": { \"durationMS\":%.0f, \"detail\":\"%s\" }}\n", i, timeUs, durUs, name, durUs*0.001, info);
      }
    }
    fputs("\n]\n", f);
    fputs("}\n", f);

    fclose(f);
  }

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x840, %rsp            # imm = 0x840
movq 0x15d2e(%rip), %rdi     # 0x2f680
leaq 0xabe2(%rip), %rsi      # 0x2453b
callq 0x33c0
movq %rax, -0x8(%rbp)
cmpq $0x0, -0x8(%rbp)
jne 0x19988
movq 0x15d10(%rip), %rdx     # 0x2f680
movl $0x2, %edi
leaq 0xb884(%rip), %rsi      # 0x25200
movb $0x0, %al
callq 0x7a60
jmp 0x19b10
movq -0x8(%rbp), %rsi
leaq 0xb8a6(%rip), %rdi      # 0x25239
callq 0x33a0
movq -0x8(%rbp), %rsi
leaq 0xb899(%rip), %rdi      # 0x2523c
callq 0x33a0
movq -0x8(%rbp), %rsi
leaq 0xb8f8(%rip), %rdi      # 0x252ab
callq 0x33a0
movq -0x8(%rbp), %rsi
leaq 0xb8f9(%rip), %rdi      # 0x252bc
callq 0x33a0
movl $0x0, -0xc(%rbp)
movl -0xc(%rbp), %eax
cmpl 0x15cb8(%rip), %eax     # 0x2f690
jge 0x19ae7
movq 0x15ca3(%rip), %rax     # 0x2f688
movslq -0xc(%rbp), %rcx
imulq $0x48, %rcx, %rcx
addq %rcx, %rax
movq %rax, -0x18(%rbp)
movl $0x0, -0x1c(%rbp)
movl -0x1c(%rbp), %eax
movq -0x18(%rbp), %rcx
cmpl 0x40(%rcx), %eax
jge 0x19ad7
movq -0x18(%rbp), %rax
movq 0x38(%rax), %rax
movslq -0x1c(%rbp), %rcx
shlq $0x5, %rcx
addq %rcx, %rax
movq %rax, -0x28(%rbp)
movq -0x28(%rbp), %rax
movq (%rax), %rdi
callq 0x7d50
movsd 0xa3ba(%rip), %xmm1     # 0x23df0
mulsd %xmm1, %xmm0
movsd %xmm0, -0x30(%rbp)
movq -0x28(%rbp), %rax
movq 0x8(%rax), %rdi
callq 0x7d50
movsd 0xa39c(%rip), %xmm1     # 0x23df0
mulsd %xmm1, %xmm0
movsd %xmm0, -0x38(%rbp)
movq -0x28(%rbp), %rax
movq 0x10(%rax), %rdi
leaq -0x440(%rbp), %rsi
movl $0x400, %edx            # imm = 0x400
callq 0x19b20
movq -0x28(%rbp), %rax
movq 0x18(%rax), %rdi
leaq -0x840(%rbp), %rsi
movl $0x400, %edx            # imm = 0x400
callq 0x19b20
movq -0x8(%rbp), %rdi
movl -0xc(%rbp), %edx
movsd -0x30(%rbp), %xmm0
movsd -0x38(%rbp), %xmm1
leaq -0x440(%rbp), %rcx
movsd 0xb731(%rip), %xmm2     # 0x251e0
mulsd -0x38(%rbp), %xmm2
leaq -0x840(%rbp), %r8
leaq 0xb860(%rip), %rsi      # 0x25322
movb $0x3, %al
callq 0x3470
movl -0x1c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x1c(%rbp)
jmp 0x199fb
jmp 0x19ad9
movl -0xc(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xc(%rbp)
jmp 0x199cf
movq -0x8(%rbp), %rsi
leaq 0xb8a4(%rip), %rdi      # 0x25396
callq 0x33a0
movq -0x8(%rbp), %rsi
leaq 0xb81d(%rip), %rdi      # 0x2531f
callq 0x33a0
movq -0x8(%rbp), %rdi
callq 0x3350
addq $0x840, %rsp            # imm = 0x840
popq %rbp
retq
nopl (%rax)