// File: halfflat[P]tinyopt/test/googletest/googletest/src/gtest.cc
// Function: testing::internal::ColoredPrintf(testing::internal::(anonymous namespace)::GTestColor, char const*, ...)
static void ColoredPrintf(GTestColor color, const char* fmt, ...) {
  va_list args;
  va_start(args, fmt);

  static const bool in_color_mode =
      // We don't condition this on GTEST_HAS_FILE_SYSTEM because we still need
      // to be able to detect terminal I/O regardless.
      ShouldUseColor(posix::IsATTY(posix::FileNo(stdout)) != 0);

  const bool use_color = in_color_mode && (color != GTestColor::kDefault);

  if (!use_color) {
    vprintf(fmt, args);
    va_end(args);
    return;
  }

#if defined(GTEST_OS_WINDOWS) && !defined(GTEST_OS_WINDOWS_MOBILE) &&    \
    !defined(GTEST_OS_WINDOWS_PHONE) && !defined(GTEST_OS_WINDOWS_RT) && \
    !defined(GTEST_OS_WINDOWS_MINGW)
  const HANDLE stdout_handle = GetStdHandle(STD_OUTPUT_HANDLE);

  // Gets the current text color.
  CONSOLE_SCREEN_BUFFER_INFO buffer_info;
  GetConsoleScreenBufferInfo(stdout_handle, &buffer_info);
  const WORD old_color_attrs = buffer_info.wAttributes;
  const WORD new_color = GetNewColor(color, old_color_attrs);

  // We need to flush the stream buffers into the console before each
  // SetConsoleTextAttribute call lest it affect the text that is already
  // printed but has not yet reached the console.
  fflush(stdout);
  SetConsoleTextAttribute(stdout_handle, new_color);

  vprintf(fmt, args);

  fflush(stdout);
  // Restores the text color.
  SetConsoleTextAttribute(stdout_handle, old_color_attrs);
#else
  printf("\033[0;3%sm", GetAnsiColorCode(color));
  vprintf(fmt, args);
  printf("\033[m");  // Resets the terminal to default.
#endif  // GTEST_OS_WINDOWS && !GTEST_OS_WINDOWS_MOBILE
  va_end(args);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x100, %rsp            # imm = 0x100
testb %al, %al
je 0x8b69b
movaps %xmm0, -0xc0(%rbp)
movaps %xmm1, -0xb0(%rbp)
movaps %xmm2, -0xa0(%rbp)
movaps %xmm3, -0x90(%rbp)
movaps %xmm4, -0x80(%rbp)
movaps %xmm5, -0x70(%rbp)
movaps %xmm6, -0x60(%rbp)
movaps %xmm7, -0x50(%rbp)
movq %r9, -0xc8(%rbp)
movq %r8, -0xd0(%rbp)
movq %rcx, -0xd8(%rbp)
movq %rdx, -0xe0(%rbp)
movl %edi, -0x4(%rbp)
movq %rsi, -0x10(%rbp)
leaq -0x30(%rbp), %rax
leaq -0xf0(%rbp), %rcx
movq %rcx, 0x10(%rax)
leaq 0x10(%rbp), %rcx
movq %rcx, 0x8(%rax)
movl $0x30, 0x4(%rax)
movl $0x10, (%rax)
cmpb $0x0, 0x8c53f(%rip)     # 0x117c28
jne 0x8b75b
leaq 0x8c536(%rip), %rdi     # 0x117c28
callq 0x10e70
cmpl $0x0, %eax
je 0x8b75b
movq 0x8b87d(%rip), %rax     # 0x116f80
movq (%rax), %rdi
callq 0xb4510
movl %eax, -0xf4(%rbp)
jmp 0x8b713
movl -0xf4(%rbp), %edi
callq 0xb44d0
movl %eax, -0xf8(%rbp)
jmp 0x8b726
movl -0xf8(%rbp), %eax
testl %eax, %eax
setne %al
movzbl %al, %edi
callq 0x8af70
movb %al, -0xf9(%rbp)
jmp 0x8b741
movb -0xf9(%rbp), %al
andb $0x1, %al
movb %al, 0x8c4d1(%rip)      # 0x117c20
leaq 0x8c4d2(%rip), %rdi     # 0x117c28
callq 0x104b0
xorl %eax, %eax
testb $0x1, 0x8c4bc(%rip)     # 0x117c20
movb %al, -0xfa(%rbp)
je 0x8b779
cmpl $0x0, -0x4(%rbp)
setne %al
movb %al, -0xfa(%rbp)
movb -0xfa(%rbp), %al
andb $0x1, %al
movb %al, -0x3d(%rbp)
testb $0x1, -0x3d(%rbp)
jne 0x8b7b7
movq -0x10(%rbp), %rdi
leaq -0x30(%rbp), %rsi
callq 0x10790
leaq -0x30(%rbp), %rax
jmp 0x8b7ef
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x38(%rbp)
movl %eax, -0x3c(%rbp)
leaq 0x8c478(%rip), %rdi     # 0x117c28
callq 0x104a0
jmp 0x8b7f8
movl -0x4(%rbp), %edi
callq 0x9ed50
movq %rax, %rsi
leaq 0x4443d(%rip), %rdi     # 0xcfc06
movb $0x0, %al
callq 0x10090
movq -0x10(%rbp), %rdi
leaq -0x30(%rbp), %rsi
callq 0x10790
leaq 0x4442b(%rip), %rdi     # 0xcfc0f
movb $0x0, %al
callq 0x10090
leaq -0x30(%rbp), %rax
addq $0x100, %rsp            # imm = 0x100
popq %rbp
retq
movq -0x38(%rbp), %rdi
callq 0x10e00
nopw %cs:(%rax,%rax)