// File: /workspace/github_cpp_makefile_star2_O2/TwilioDevEd[P]twilio_cpp_demo/src/twilio.cc
// Function: twilio::Twilio::send_message(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>> const&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>> const&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>> const&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>> const&, bool)
bool Twilio::send_message(
        std::string const& to_number,
        std::string const& from_number,
        std::string const& message_body,
        std::string& response,
        std::string const& picture_url,
        bool verbose)
{
        std::stringstream response_stream;
        std::u16string converted_message_body;

        // Assume UTF-8 input, convert to UCS-2 to check size
        // See: https://www.twilio.com/docs/api/rest/sending-messages for
        // information on Twilio body size limits.
        try {
                converted_message_body = utf8_to_ucs2(message_body);
        } catch(const std::range_error& e) {
                response = e.what();
                return false;
        }

        if (converted_message_body.size() > 1600) {
                response_stream << "Message body must have 1600 or fewer"
                        << " characters. Cannot send message with "
                        << converted_message_body.size() << " characters.";
                response = response_stream.str();
                return false;
        }

        CURL *curl;
        curl_global_init(CURL_GLOBAL_ALL);
        curl = curl_easy_init();

        // Percent encode special characters
        char *message_body_escaped = curl_easy_escape(
                curl, 
                message_body.c_str(), 
                0
        );


        std::stringstream url;
        std::string url_string;
        url << "https://api.twilio.com/2010-04-01/Accounts/" << account_sid
                << "/Messages";
        url_string = url.str();


        std::stringstream parameters;
        std::string parameter_string;
        parameters << "To=" << to_number << "&From=" << from_number 
                << "&Body=" << message_body_escaped;
        if (!picture_url.empty()) {
                parameters << "&MediaUrl=" << picture_url;
        }
        parameter_string = parameters.str();


        curl_easy_setopt(curl, CURLOPT_POST, 1);
        curl_easy_setopt(curl, CURLOPT_URL, url_string.c_str());
        curl_easy_setopt(curl, CURLOPT_POSTFIELDS, parameter_string.c_str());
        curl_easy_setopt(curl, CURLOPT_USERNAME, account_sid.c_str());
        curl_easy_setopt(curl, CURLOPT_PASSWORD, auth_token.c_str());
        if (!verbose) {
                curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, _null_write);
        } else {
                curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, _stream_write);
                curl_easy_setopt(curl, CURLOPT_WRITEDATA, &response_stream);
        }


        CURLcode res = curl_easy_perform(curl);
        curl_free(message_body_escaped);
        curl_easy_cleanup(curl);
        long http_code = 0;
        curl_easy_getinfo (curl, CURLINFO_RESPONSE_CODE, &http_code);

        // Check for curl errors and Twilio failure status codes.
        if (res != CURLE_OK) {
                response = curl_easy_strerror(res);
                return false;
        } else if (http_code != 200 && http_code != 201) {
                response = response_stream.str();
                return false;
        } else {
                response = response_stream.str();
                return true;
        }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x538, %rsp            # imm = 0x538
movq %r9, %r14
movq %r8, (%rsp)
movq %rcx, %rbp
movq %rdx, 0x10(%rsp)
movq %rsi, %r12
movq %rdi, %r13
leaq 0x3b0(%rsp), %rdi
movq %rdi, 0x8(%rsp)
callq 0x20e0
leaq 0x90(%rsp), %rax
movq %rax, -0x10(%rax)
andq $0x0, -0x8(%rax)
andw $0x0, (%rax)
leaq 0xa0(%rsp), %rdi
movq %rbp, %rsi
callq 0x2fcf
leaq 0x80(%rsp), %r15
leaq 0xa0(%rsp), %rbx
movq %r15, %rdi
movq %rbx, %rsi
callq 0x307a
movq %rbx, %rdi
callq 0x3126
cmpq $0x640, 0x8(%r15)       # imm = 0x640
jbe 0x2bfc
leaq 0x3c0(%rsp), %rdi
leaq 0x1757(%rip), %rsi      # 0x42e8
callq 0x2190
leaq 0x1770(%rip), %rsi      # 0x430d
movq %rax, %rdi
callq 0x2190
movq 0x88(%rsp), %rsi
movq %rax, %rdi
callq 0x2160
leaq 0x1833(%rip), %rsi      # 0x43ef
movq %rax, %rdi
callq 0x2190
leaq 0x3c8(%rsp), %rsi
leaq 0xa0(%rsp), %rdi
callq 0x2110
leaq 0xa0(%rsp), %rbx
movq (%rsp), %rdi
movq %rbx, %rsi
callq 0x2170
movq %rbx, %rdi
callq 0x21e0
xorl %ebx, %ebx
jmp 0x2ec1
pushq $0x3
popq %rdi
callq 0x20c0
callq 0x22a0
movq %rax, %r15
movq (%rbp), %rsi
movq %rax, %rdi
xorl %edx, %edx
callq 0x21f0
movq %rax, %rbp
leaq 0xa0(%rsp), %rdi
callq 0x20e0
leaq 0x70(%rsp), %rax
movq %rax, -0x10(%rax)
andq $0x0, -0x8(%rax)
movb $0x0, (%rax)
leaq 0xb0(%rsp), %rdi
leaq 0x16ea(%rip), %rsi      # 0x4334
callq 0x2190
movq %rax, %rdi
movq %r13, %rsi
callq 0x20d0
leaq 0x16ff(%rip), %rsi      # 0x4360
movq %rax, %rdi
callq 0x2190
leaq 0xb8(%rsp), %rsi
leaq 0x228(%rsp), %rdi
callq 0x2110
leaq 0x60(%rsp), %rdi
leaq 0x228(%rsp), %rbx
movq %rbx, %rsi
callq 0x2170
movq %rbx, %rdi
callq 0x21e0
leaq 0x228(%rsp), %rdi
callq 0x20e0
leaq 0x50(%rsp), %rax
movq %rax, -0x10(%rax)
andq $0x0, -0x8(%rax)
movb $0x0, (%rax)
leaq 0x238(%rsp), %rbx
leaq 0x16a2(%rip), %rsi      # 0x436a
movq %rbx, %rdi
callq 0x2190
movq %rax, %rdi
movq %r12, %rsi
callq 0x20d0
leaq 0x168c(%rip), %rsi      # 0x436e
movq %rax, %rdi
callq 0x2190
movq %rax, %rdi
movq 0x10(%rsp), %rsi
callq 0x20d0
leaq 0x1677(%rip), %rsi      # 0x4375
movq %rax, %rdi
callq 0x2190
movq %rax, %rdi
movq %rbp, %rsi
callq 0x2190
cmpq $0x0, 0x8(%r14)
je 0x2d32
leaq 0x165d(%rip), %rsi      # 0x437c
movq %rbx, %rdi
callq 0x2190
movq %rax, %rdi
movq %r14, %rsi
callq 0x20d0
leaq 0x240(%rsp), %rsi
leaq 0x20(%rsp), %rdi
callq 0x2110
leaq 0x40(%rsp), %rdi
leaq 0x20(%rsp), %rbx
movq %rbx, %rsi
callq 0x2170
movq %rbx, %rdi
callq 0x21e0
pushq $0x2f
popq %rsi
pushq $0x1
popq %rdx
movq %r15, %rdi
xorl %eax, %eax
callq 0x2250
movq 0x60(%rsp), %rdx
movq %r15, %rdi
movl $0x2712, %esi           # imm = 0x2712
xorl %eax, %eax
callq 0x2250
movq 0x40(%rsp), %rdx
movq %r15, %rdi
movl $0x271f, %esi           # imm = 0x271F
xorl %eax, %eax
callq 0x2250
movq (%r13), %rdx
movq %r15, %rdi
movl $0x27bd, %esi           # imm = 0x27BD
xorl %eax, %eax
callq 0x2250
movq 0x20(%r13), %rdx
movq %r15, %rdi
movl $0x27be, %esi           # imm = 0x27BE
xorl %eax, %eax
callq 0x2250
cmpb $0x0, 0x570(%rsp)
je 0x2de3
movl $0x2711, %ebx           # imm = 0x2711
leaq -0x2fa(%rip), %rdx      # 0x2ad8
movq %r15, %rdi
movl $0x4e2b, %esi           # imm = 0x4E2B
xorl %eax, %eax
callq 0x2250
jmp 0x2df4
leaq -0x31a(%rip), %rax      # 0x2ad0
movq %rax, 0x8(%rsp)
movl $0x4e2b, %ebx           # imm = 0x4E2B
movq %r15, %rdi
movl %ebx, %esi
movq 0x8(%rsp), %rdx
xorl %eax, %eax
callq 0x2250
movq %r15, %rdi
callq 0x21d0
movl %eax, %ebx
movq %rbp, %rdi
callq 0x2030
movq %r15, %rdi
callq 0x2090
leaq 0x18(%rsp), %rdx
andq $0x0, (%rdx)
movq %r15, %rdi
movl $0x200002, %esi         # imm = 0x200002
xorl %eax, %eax
callq 0x2290
testl %ebx, %ebx
je 0x2e50
movl %ebx, %edi
callq 0x2120
movq (%rsp), %rdi
movq %rax, %rsi
callq 0x22f0
jmp 0x2e91
movq $-0xca, %rax
addq 0x18(%rsp), %rax
leaq 0x3c8(%rsp), %rsi
cmpq $-0x3, %rax
ja 0x2eef
leaq 0x20(%rsp), %rdi
callq 0x2110
leaq 0x20(%rsp), %rbx
movq (%rsp), %rdi
movq %rbx, %rsi
callq 0x2170
movq %rbx, %rdi
callq 0x21e0
xorl %ebx, %ebx
leaq 0x40(%rsp), %rdi
callq 0x21e0
leaq 0x228(%rsp), %rdi
callq 0x20f0
leaq 0x60(%rsp), %rdi
callq 0x21e0
leaq 0xa0(%rsp), %rdi
callq 0x20f0
leaq 0x80(%rsp), %rdi
callq 0x3126
leaq 0x3b0(%rsp), %rdi
callq 0x20f0
movl %ebx, %eax
addq $0x538, %rsp            # imm = 0x538
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x20(%rsp), %rdi
callq 0x2110
leaq 0x20(%rsp), %rbx
movq (%rsp), %rdi
movq %rbx, %rsi
callq 0x2170
movq %rbx, %rdi
callq 0x21e0
movb $0x1, %bl
jmp 0x2e93
jmp 0x2f7c
jmp 0x2f7c
jmp 0x2f7c
jmp 0x2f72
jmp 0x2f72
jmp 0x2f77
jmp 0x2f77
jmp 0x2f77
jmp 0x2f77
movq %rax, %rbx
cmpl $0x1, %edx
jne 0x2fad
movq %rbx, %rdi
callq 0x2050
movq (%rax), %rcx
movq %rax, %rdi
callq *0x10(%rcx)
movq (%rsp), %rdi
movq %rax, %rsi
callq 0x22f0
callq 0x2210
jmp 0x2bf5
jmp 0x2f77
movq %rax, %rbx
callq 0x2210
jmp 0x2fad
movq %rax, %rdi
callq 0x3136
jmp 0x2f7c
jmp 0x2f7c
movq %rax, %rbx
jmp 0x2f96
movq %rax, %rbx
jmp 0x2fad
movq %rax, %rbx
leaq 0x40(%rsp), %rdi
callq 0x21e0
leaq 0x228(%rsp), %rdi
callq 0x20f0
leaq 0x60(%rsp), %rdi
callq 0x21e0
leaq 0xa0(%rsp), %rdi
callq 0x20f0
leaq 0x80(%rsp), %rdi
callq 0x3126
leaq 0x3b0(%rsp), %rdi
callq 0x20f0
movq %rbx, %rdi
callq 0x21c0