// File: /workspace/github_cpp_makefile_star2_O1/halfflat[P]tinyopt/test/googletest/googletest/src/gtest-port.cc
// Function: testing::internal::CapturedStream::CapturedStream(int)
explicit CapturedStream(int fd) : fd_(fd), uncaptured_fd_(dup(fd)) {
#ifdef GTEST_OS_WINDOWS
    char temp_dir_path[MAX_PATH + 1] = {'\0'};   // NOLINT
    char temp_file_path[MAX_PATH + 1] = {'\0'};  // NOLINT

    ::GetTempPathA(sizeof(temp_dir_path), temp_dir_path);
    const UINT success = ::GetTempFileNameA(temp_dir_path, "gtest_redir",
                                            0,  // Generate unique file name.
                                            temp_file_path);
    GTEST_CHECK_(success != 0)
        << "Unable to create a temporary file in " << temp_dir_path;
    const int captured_fd = creat(temp_file_path, _S_IREAD | _S_IWRITE);
    GTEST_CHECK_(captured_fd != -1)
        << "Unable to open temporary file " << temp_file_path;
    filename_ = temp_file_path;
#else
    // There's no guarantee that a test has write access to the current
    // directory, so we create the temporary file in a temporary directory.
    std::string name_template;

#ifdef GTEST_OS_LINUX_ANDROID
    // Note: Android applications are expected to call the framework's
    // Context.getExternalStorageDirectory() method through JNI to get
    // the location of the world-writable SD Card directory. However,
    // this requires a Context handle, which cannot be retrieved
    // globally from native code. Doing so also precludes running the
    // code as part of a regular standalone executable, which doesn't
    // run in a Dalvik process (e.g. when running it through 'adb shell').
    //
    // The location /data/local/tmp is directly accessible from native code.
    // '/sdcard' and other variants cannot be relied on, as they are not
    // guaranteed to be mounted, or may have a delay in mounting.
    //
    // However, prefer using the TMPDIR environment variable if set, as newer
    // devices may have /data/local/tmp read-only.
    name_template = TempDir();
    if (!EndsWithPathSeparator(name_template))
      name_template.push_back(GTEST_PATH_SEP_[0]);

#elif defined(GTEST_OS_IOS)
    char user_temp_dir[PATH_MAX + 1];

    // Documented alternative to NSTemporaryDirectory() (for obtaining creating
    // a temporary directory) at
    // https://developer.apple.com/library/archive/documentation/Security/Conceptual/SecureCodingGuide/Articles/RaceConditions.html#//apple_ref/doc/uid/TP40002585-SW10
    //
    // _CS_DARWIN_USER_TEMP_DIR (as well as _CS_DARWIN_USER_CACHE_DIR) is not
    // documented in the confstr() man page at
    // https://developer.apple.com/library/archive/documentation/System/Conceptual/ManPages_iPhoneOS/man3/confstr.3.html#//apple_ref/doc/man/3/confstr
    // but are still available, according to the WebKit patches at
    // https://trac.webkit.org/changeset/262004/webkit
    // https://trac.webkit.org/changeset/263705/webkit
    //
    // The confstr() implementation falls back to getenv("TMPDIR"). See
    // https://opensource.apple.com/source/Libc/Libc-1439.100.3/gen/confstr.c.auto.html
    ::confstr(_CS_DARWIN_USER_TEMP_DIR, user_temp_dir, sizeof(user_temp_dir));

    name_template = user_temp_dir;
    if (!EndsWithPathSeparator(name_template))
      name_template.push_back(GTEST_PATH_SEP_[0]);
#else
    name_template = "/tmp/";
#endif
    name_template.append("gtest_captured_stream.XXXXXX");

    // mkstemp() modifies the string bytes in place, and does not go beyond the
    // string's length. This results in well-defined behavior in C++17.
    //
    // The const_cast is needed below C++17. The constraints on std::string
    // implementations in C++11 and above make assumption behind the const_cast
    // fairly safe.
    const int captured_fd = ::mkstemp(const_cast<char*>(name_template.data()));
    if (captured_fd == -1) {
      GTEST_LOG_(WARNING)
          << "Failed to create tmp file " << name_template
          << " for test; does the test have access to the /tmp directory?";
    }
    filename_ = std::move(name_template);
#endif  // GTEST_OS_WINDOWS
    fflush(nullptr);
    dup2(captured_fd, fd_);
    close(captured_fd);
  }

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
subq $0x30, %rsp
movq %rdi, %r14
movl %esi, (%rdi)
movl %esi, %edi
callq 0xd930
movl %eax, 0x4(%r14)
leaq 0x8(%r14), %rbx
leaq 0x18(%r14), %r15
movq %r15, 0x8(%r14)
xorl %eax, %eax
movq %rax, 0x10(%r14)
movb %al, 0x18(%r14)
leaq 0x20(%rsp), %r12
movq %r12, -0x10(%r12)
movq %rax, -0x8(%r12)
movb %al, (%r12)
leaq 0xd3c3(%rip), %rcx      # 0x74a3d
leaq 0x10(%rsp), %rdi
movl $0x5, %r8d
xorl %esi, %esi
xorl %edx, %edx
callq 0xd960
leaq 0xd71d(%rip), %rsi      # 0x74db2
leaq 0x10(%rsp), %rdi
callq 0xdb40
movq 0x10(%rsp), %rdi
callq 0xd190
movl %eax, %ebp
cmpl $-0x1, %eax
jne 0x67717
leaq 0xbcb1(%rip), %rdx      # 0x73368
leaq 0xc(%rsp), %rdi
movl $0x1, %esi
movl $0x469, %ecx            # imm = 0x469
callq 0x48796
movq 0x2e91e(%rip), %rdi     # 0x95ff0
leaq 0xd6f6(%rip), %rsi      # 0x74dcf
movl $0x1a, %edx
callq 0xd600
movq 0x10(%rsp), %rsi
movq 0x18(%rsp), %rdx
movq 0x2e8fc(%rip), %rdi     # 0x95ff0
callq 0xd600
leaq 0xd6ea(%rip), %rsi      # 0x74dea
movl $0x3b, %edx
movq %rax, %rdi
callq 0xd600
leaq 0xc(%rsp), %rdi
callq 0x488d8
leaq 0x10(%rsp), %rsi
movq %rbx, %rdi
callq 0xd6e0
xorl %edi, %edi
callq 0xd650
movl (%r14), %esi
movl %ebp, %edi
callq 0xd4c0
movl %ebp, %edi
callq 0xdb60
movq 0x10(%rsp), %rdi
cmpq %r12, %rdi
je 0x67753
movq 0x20(%rsp), %rsi
incq %rsi
callq 0xd530
addq $0x30, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq
jmp 0x67773
movq %rax, %r14
leaq 0xc(%rsp), %rdi
callq 0x488d8
jmp 0x67776
jmp 0x67773
movq %rax, %r14
movq 0x10(%rsp), %rdi
cmpq %r12, %rdi
je 0x6778d
movq 0x20(%rsp), %rsi
incq %rsi
callq 0xd530
movq (%rbx), %rdi
cmpq %r15, %rdi
je 0x677a0
movq (%r15), %rsi
incq %rsi
callq 0xd530
movq %r14, %rdi
callq 0xda70