// File: /workspace/github_cpp_makefile_star2_O3/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, %rbp
movq %r8, (%rsp)
movq %rcx, %r14
movq %rdx, %rbx
movq %rsi, %r13
movq %rdi, %r12
leaq 0x3b0(%rsp), %rdi
movq %rdi, 0x10(%rsp)
callq 0x20d0
leaq 0x48(%rsp), %rax
movq %rax, -0x10(%rax)
movq $0x0, -0x8(%rax)
movw $0x0, (%rax)
leaq 0xa0(%rsp), %rdi
movq %r14, %rsi
callq 0x34a0
leaq 0x38(%rsp), %rdi
leaq 0xa0(%rsp), %r15
movq %r15, %rsi
callq 0x2360
movq (%r15), %rdi
leaq 0xb0(%rsp), %r15
cmpq %r15, %rdi
je 0x2e46
movq 0xb0(%rsp), %rax
leaq 0x2(,%rax,2), %rsi
callq 0x2080
cmpq $0x640, 0x40(%rsp)      # imm = 0x640
jbe 0x2eee
leaq 0x3c0(%rsp), %rbx
leaq 0x150c(%rip), %rsi      # 0x4370
movl $0x24, %edx
movq %rbx, %rdi
callq 0x22d0
leaq 0x151d(%rip), %rsi      # 0x4395
movl $0x26, %edx
movq %rbx, %rdi
callq 0x22d0
movq 0x40(%rsp), %rsi
movq %rbx, %rdi
callq 0x2180
leaq 0x15de(%rip), %rsi      # 0x4477
movl $0xc, %edx
movq %rax, %rdi
callq 0x22d0
leaq 0x3c8(%rsp), %rsi
leaq 0xa0(%rsp), %rdi
callq 0x20f0
leaq 0xa0(%rsp), %rbx
movq (%rsp), %rdi
movq %rbx, %rsi
callq 0x2190
movq (%rbx), %rdi
cmpq %r15, %rdi
je 0x2ee7
movq 0xb0(%rsp), %rsi
incq %rsi
callq 0x2080
xorl %ebx, %ebx
jmp 0x3311
movl $0x3, %edi
callq 0x20c0
callq 0x22e0
movq %rax, %r15
movq (%r14), %rsi
movq %rax, %rdi
xorl %edx, %edx
callq 0x2210
movq %rax, 0x8(%rsp)
leaq 0xa0(%rsp), %rdi
callq 0x20d0
leaq 0x88(%rsp), %rax
movq %rax, -0x10(%rax)
movq $0x0, -0x8(%rax)
movb $0x0, (%rax)
leaq 0xb0(%rsp), %r14
leaq 0x1477(%rip), %rsi      # 0x43bc
movl $0x2b, %edx
movq %r14, %rdi
callq 0x22d0
movq (%r12), %rsi
movq 0x8(%r12), %rdx
movq %r14, %rdi
callq 0x22d0
leaq 0x147e(%rip), %rsi      # 0x43e8
movl $0x9, %edx
movq %rax, %rdi
callq 0x22d0
leaq 0xb8(%rsp), %rsi
leaq 0x228(%rsp), %rdi
callq 0x20f0
leaq 0x78(%rsp), %rdi
leaq 0x228(%rsp), %r14
movq %r14, %rsi
callq 0x2190
movq (%r14), %rdi
leaq 0x238(%rsp), %rax
cmpq %rax, %rdi
je 0x2fc1
movq 0x238(%rsp), %rsi
incq %rsi
callq 0x2080
leaq 0x228(%rsp), %rdi
callq 0x20d0
leaq 0x68(%rsp), %rax
movq %rax, -0x10(%rax)
movq $0x0, -0x8(%rax)
movb $0x0, (%rax)
leaq 0x238(%rsp), %r14
leaq 0x1401(%rip), %rsi      # 0x43f2
movl $0x3, %edx
movq %r14, %rdi
callq 0x22d0
movq (%r13), %rsi
movq 0x8(%r13), %rdx
movq %r14, %rdi
callq 0x22d0
movq %rax, %r13
leaq 0x13de(%rip), %rsi      # 0x43f6
movl $0x6, %edx
movq %rax, %rdi
callq 0x22d0
movq (%rbx), %rsi
movq 0x8(%rbx), %rdx
movq %r13, %rdi
callq 0x22d0
movq %rax, %rbx
leaq 0x13bf(%rip), %rsi      # 0x43fd
movl $0x6, %edx
movq %rax, %rdi
callq 0x22d0
movq 0x8(%rsp), %r13
testq %r13, %r13
je 0x306d
movq %r13, %rdi
callq 0x2100
movq %rbx, %rdi
movq %r13, %rsi
movq %rax, %rdx
callq 0x22d0
jmp 0x3086
movq (%rbx), %rax
movq -0x18(%rax), %rax
movq %rbx, %rdi
addq %rax, %rdi
movl 0x20(%rbx,%rax), %esi
orl $0x1, %esi
callq 0x2330
cmpq $0x0, 0x8(%rbp)
je 0x30b1
leaq 0x1370(%rip), %rsi      # 0x4404
movl $0xa, %edx
movq %r14, %rdi
callq 0x22d0
movq (%rbp), %rsi
movq 0x8(%rbp), %rdx
movq %r14, %rdi
callq 0x22d0
leaq 0x240(%rsp), %rsi
leaq 0x18(%rsp), %rdi
callq 0x20f0
leaq 0x58(%rsp), %rdi
leaq 0x18(%rsp), %rbx
movq %rbx, %rsi
callq 0x2190
movq (%rbx), %rdi
leaq 0x28(%rsp), %r14
cmpq %r14, %rdi
je 0x30ef
movq 0x28(%rsp), %rsi
incq %rsi
callq 0x2080
movq %r15, %rdi
movl $0x2f, %esi
movl $0x1, %edx
xorl %eax, %eax
callq 0x2280
movq 0x78(%rsp), %rdx
movq %r15, %rdi
movl $0x2712, %esi           # imm = 0x2712
xorl %eax, %eax
callq 0x2280
movq 0x58(%rsp), %rdx
movq %r15, %rdi
movl $0x271f, %esi           # imm = 0x271F
xorl %eax, %eax
callq 0x2280
movq (%r12), %rdx
movq %r15, %rdi
movl $0x27bd, %esi           # imm = 0x27BD
xorl %eax, %eax
callq 0x2280
movq 0x20(%r12), %rdx
movq %r15, %rdi
movl $0x27be, %esi           # imm = 0x27BE
xorl %eax, %eax
callq 0x2280
cmpb $0x0, 0x570(%rsp)
je 0x3179
movl $0x2711, %ebx           # imm = 0x2711
leaq -0x3d8(%rip), %rdx      # 0x2d90
movq %r15, %rdi
movl $0x4e2b, %esi           # imm = 0x4E2B
xorl %eax, %eax
callq 0x2280
jmp 0x318a
leaq -0x3f8(%rip), %rax      # 0x2d88
movq %rax, 0x10(%rsp)
movl $0x4e2b, %ebx           # imm = 0x4E2B
movq %r15, %rdi
movl %ebx, %esi
movq 0x10(%rsp), %rdx
xorl %eax, %eax
callq 0x2280
movq %r15, %rdi
callq 0x21e0
movl %eax, %ebx
movq 0x8(%rsp), %rdi
callq 0x2030
movq %r15, %rdi
callq 0x2090
leaq 0x98(%rsp), %rdx
movq $0x0, (%rdx)
movq %r15, %rdi
movl $0x200002, %esi         # imm = 0x200002
xorl %eax, %eax
callq 0x22c0
testl %ebx, %ebx
je 0x320e
movl %ebx, %edi
callq 0x2120
movq %rax, %r14
movq (%rsp), %r12
movq 0x8(%r12), %r15
movq %rax, %rdi
callq 0x2100
xorl %ebx, %ebx
movq %r12, %rdi
xorl %esi, %esi
movq %r15, %rdx
movq %r14, %rcx
movq %rax, %r8
callq 0x2170
jmp 0x3291
movq $-0xca, %rax
addq 0x98(%rsp), %rax
leaq 0x3c8(%rsp), %rsi
cmpq $-0x3, %rax
ja 0x325f
leaq 0x18(%rsp), %rdi
callq 0x20f0
leaq 0x18(%rsp), %rbx
movq (%rsp), %rdi
movq %rbx, %rsi
callq 0x2190
movq (%rbx), %rdi
cmpq %r14, %rdi
je 0x325b
movq 0x28(%rsp), %rsi
incq %rsi
callq 0x2080
xorl %ebx, %ebx
jmp 0x3291
leaq 0x18(%rsp), %rdi
callq 0x20f0
leaq 0x18(%rsp), %rbx
movq (%rsp), %rdi
movq %rbx, %rsi
callq 0x2190
movq (%rbx), %rdi
cmpq %r14, %rdi
je 0x328f
movq 0x28(%rsp), %rsi
incq %rsi
callq 0x2080
movb $0x1, %bl
movq 0x58(%rsp), %rdi
leaq 0x68(%rsp), %rax
cmpq %rax, %rdi
je 0x32ad
movq 0x68(%rsp), %rsi
incq %rsi
callq 0x2080
movq 0x3d2c(%rip), %rsi      # 0x6fe0
leaq 0x228(%rsp), %rdi
callq 0x2230
leaq 0x2a8(%rsp), %rdi
callq 0x2200
movq 0x78(%rsp), %rdi
leaq 0x88(%rsp), %rax
cmpq %rax, %rdi
je 0x32f0
movq 0x88(%rsp), %rsi
incq %rsi
callq 0x2080
movq 0x3ce9(%rip), %rsi      # 0x6fe0
leaq 0xa0(%rsp), %rdi
callq 0x2230
leaq 0x120(%rsp), %rdi
callq 0x2200
movq 0x38(%rsp), %rdi
leaq 0x48(%rsp), %rax
cmpq %rax, %rdi
je 0x3332
movq 0x48(%rsp), %rax
leaq 0x2(,%rax,2), %rsi
callq 0x2080
movq 0x3ca7(%rip), %rsi      # 0x6fe0
leaq 0x3b0(%rsp), %rdi
callq 0x2230
leaq 0x430(%rsp), %rdi
callq 0x2200
movl %ebx, %eax
addq $0x538, %rsp            # imm = 0x538
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x338a
jmp 0x338a
jmp 0x338a
jmp 0x337d
jmp 0x337d
jmp 0x3382
jmp 0x3382
jmp 0x3382
jmp 0x3382
jmp 0x338a
jmp 0x338a
movq %rax, %rbx
jmp 0x33ca
movq %rax, %rbx
jmp 0x340d
movq %rax, %rbx
movq 0x58(%rsp), %rdi
leaq 0x68(%rsp), %rax
cmpq %rax, %rdi
je 0x33a9
movq 0x68(%rsp), %rsi
incq %rsi
callq 0x2080
movq 0x3c30(%rip), %rsi      # 0x6fe0
leaq 0x228(%rsp), %rdi
callq 0x2230
leaq 0x2a8(%rsp), %rdi
callq 0x2200
movq 0x78(%rsp), %rdi
leaq 0x88(%rsp), %rax
cmpq %rax, %rdi
je 0x33ec
movq 0x88(%rsp), %rsi
incq %rsi
callq 0x2080
movq 0x3bed(%rip), %rsi      # 0x6fe0
leaq 0xa0(%rsp), %rdi
callq 0x2230
leaq 0x120(%rsp), %rdi
callq 0x2200
movq 0x38(%rsp), %rdi
leaq 0x48(%rsp), %rax
cmpq %rax, %rdi
je 0x342e
movq 0x48(%rsp), %rax
leaq 0x2(,%rax,2), %rsi
callq 0x2080
movq 0x3bab(%rip), %rsi      # 0x6fe0
leaq 0x3b0(%rsp), %rdi
callq 0x2230
leaq 0x430(%rsp), %rdi
callq 0x2200
movq %rbx, %rdi
callq 0x21d0
movq %rax, %rbx
cmpl $0x1, %edx
jne 0x340d
movq %rbx, %rdi
callq 0x2050
movq (%rax), %rcx
movq %rax, %rdi
callq *0x10(%rcx)
movq (%rsp), %rdi
movq %rax, %rsi
callq 0x2110
callq 0x2240
jmp 0x2ee7
jmp 0x3382
movq %rax, %rbx
callq 0x2240
jmp 0x340d
movq %rax, %rdi
callq 0x359d