// File: /workspace/github_cpp_makefile_star2_O1/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 0x30d0
leaq 0x48(%rsp), %rax
movq %rax, -0x10(%rax)
movq $0x0, -0x8(%rax)
movw $0x0, (%rax)
leaq 0xa0(%rsp), %rdi
movq %r14, %rsi
callq 0x4498
leaq 0x38(%rsp), %rdi
leaq 0xa0(%rsp), %r15
movq %r15, %rsi
callq 0x3362
movq (%r15), %rdi
leaq 0xb0(%rsp), %r15
cmpq %r15, %rdi
je 0x3e3e
movq 0xb0(%rsp), %rax
leaq 0x2(,%rax,2), %rsi
callq 0x3080
cmpq $0x640, 0x40(%rsp)      # imm = 0x640
jbe 0x3ee6
leaq 0x3c0(%rsp), %rbx
leaq 0x14b4(%rip), %rsi      # 0x5310
movl $0x24, %edx
movq %rbx, %rdi
callq 0x32d0
leaq 0x14c5(%rip), %rsi      # 0x5335
movl $0x26, %edx
movq %rbx, %rdi
callq 0x32d0
movq 0x40(%rsp), %rsi
movq %rbx, %rdi
callq 0x3180
leaq 0x1586(%rip), %rsi      # 0x5417
movl $0xc, %edx
movq %rax, %rdi
callq 0x32d0
leaq 0x3c8(%rsp), %rsi
leaq 0xa0(%rsp), %rdi
callq 0x30f0
leaq 0xa0(%rsp), %rbx
movq (%rsp), %rdi
movq %rbx, %rsi
callq 0x3190
movq (%rbx), %rdi
cmpq %r15, %rdi
je 0x3edf
movq 0xb0(%rsp), %rsi
incq %rsi
callq 0x3080
xorl %ebx, %ebx
jmp 0x4309
movl $0x3, %edi
callq 0x30c0
callq 0x32e0
movq %rax, %r15
movq (%r14), %rsi
movq %rax, %rdi
xorl %edx, %edx
callq 0x3210
movq %rax, 0x8(%rsp)
leaq 0xa0(%rsp), %rdi
callq 0x30d0
leaq 0x88(%rsp), %rax
movq %rax, -0x10(%rax)
movq $0x0, -0x8(%rax)
movb $0x0, (%rax)
leaq 0xb0(%rsp), %r14
leaq 0x141f(%rip), %rsi      # 0x535c
movl $0x2b, %edx
movq %r14, %rdi
callq 0x32d0
movq (%r12), %rsi
movq 0x8(%r12), %rdx
movq %r14, %rdi
callq 0x32d0
leaq 0x1426(%rip), %rsi      # 0x5388
movl $0x9, %edx
movq %rax, %rdi
callq 0x32d0
leaq 0xb8(%rsp), %rsi
leaq 0x228(%rsp), %rdi
callq 0x30f0
leaq 0x78(%rsp), %rdi
leaq 0x228(%rsp), %r14
movq %r14, %rsi
callq 0x3190
movq (%r14), %rdi
leaq 0x238(%rsp), %rax
cmpq %rax, %rdi
je 0x3fb9
movq 0x238(%rsp), %rsi
incq %rsi
callq 0x3080
leaq 0x228(%rsp), %rdi
callq 0x30d0
leaq 0x68(%rsp), %rax
movq %rax, -0x10(%rax)
movq $0x0, -0x8(%rax)
movb $0x0, (%rax)
leaq 0x238(%rsp), %r14
leaq 0x13a9(%rip), %rsi      # 0x5392
movl $0x3, %edx
movq %r14, %rdi
callq 0x32d0
movq (%r13), %rsi
movq 0x8(%r13), %rdx
movq %r14, %rdi
callq 0x32d0
movq %rax, %r13
leaq 0x1386(%rip), %rsi      # 0x5396
movl $0x6, %edx
movq %rax, %rdi
callq 0x32d0
movq (%rbx), %rsi
movq 0x8(%rbx), %rdx
movq %r13, %rdi
callq 0x32d0
movq %rax, %rbx
leaq 0x1367(%rip), %rsi      # 0x539d
movl $0x6, %edx
movq %rax, %rdi
callq 0x32d0
movq 0x8(%rsp), %r13
testq %r13, %r13
je 0x4065
movq %r13, %rdi
callq 0x3100
movq %rbx, %rdi
movq %r13, %rsi
movq %rax, %rdx
callq 0x32d0
jmp 0x407e
movq (%rbx), %rax
movq -0x18(%rax), %rax
movq %rbx, %rdi
addq %rax, %rdi
movl 0x20(%rbx,%rax), %esi
orl $0x1, %esi
callq 0x3330
cmpq $0x0, 0x8(%rbp)
je 0x40a9
leaq 0x1318(%rip), %rsi      # 0x53a4
movl $0xa, %edx
movq %r14, %rdi
callq 0x32d0
movq (%rbp), %rsi
movq 0x8(%rbp), %rdx
movq %r14, %rdi
callq 0x32d0
leaq 0x240(%rsp), %rsi
leaq 0x18(%rsp), %rdi
callq 0x30f0
leaq 0x58(%rsp), %rdi
leaq 0x18(%rsp), %rbx
movq %rbx, %rsi
callq 0x3190
movq (%rbx), %rdi
leaq 0x28(%rsp), %r14
cmpq %r14, %rdi
je 0x40e7
movq 0x28(%rsp), %rsi
incq %rsi
callq 0x3080
movq %r15, %rdi
movl $0x2f, %esi
movl $0x1, %edx
xorl %eax, %eax
callq 0x3280
movq 0x78(%rsp), %rdx
movq %r15, %rdi
movl $0x2712, %esi           # imm = 0x2712
xorl %eax, %eax
callq 0x3280
movq 0x58(%rsp), %rdx
movq %r15, %rdi
movl $0x271f, %esi           # imm = 0x271F
xorl %eax, %eax
callq 0x3280
movq (%r12), %rdx
movq %r15, %rdi
movl $0x27bd, %esi           # imm = 0x27BD
xorl %eax, %eax
callq 0x3280
movq 0x20(%r12), %rdx
movq %r15, %rdi
movl $0x27be, %esi           # imm = 0x27BE
xorl %eax, %eax
callq 0x3280
cmpb $0x0, 0x570(%rsp)
je 0x4171
movl $0x2711, %ebx           # imm = 0x2711
leaq -0x3d8(%rip), %rdx      # 0x3d88
movq %r15, %rdi
movl $0x4e2b, %esi           # imm = 0x4E2B
xorl %eax, %eax
callq 0x3280
jmp 0x4182
leaq -0x3f8(%rip), %rax      # 0x3d80
movq %rax, 0x10(%rsp)
movl $0x4e2b, %ebx           # imm = 0x4E2B
movq %r15, %rdi
movl %ebx, %esi
movq 0x10(%rsp), %rdx
xorl %eax, %eax
callq 0x3280
movq %r15, %rdi
callq 0x31e0
movl %eax, %ebx
movq 0x8(%rsp), %rdi
callq 0x3030
movq %r15, %rdi
callq 0x3090
leaq 0x98(%rsp), %rdx
movq $0x0, (%rdx)
movq %r15, %rdi
movl $0x200002, %esi         # imm = 0x200002
xorl %eax, %eax
callq 0x32c0
testl %ebx, %ebx
je 0x4206
movl %ebx, %edi
callq 0x3120
movq %rax, %r14
movq (%rsp), %r12
movq 0x8(%r12), %r15
movq %rax, %rdi
callq 0x3100
xorl %ebx, %ebx
movq %r12, %rdi
xorl %esi, %esi
movq %r15, %rdx
movq %r14, %rcx
movq %rax, %r8
callq 0x3170
jmp 0x4289
movq $-0xca, %rax
addq 0x98(%rsp), %rax
leaq 0x3c8(%rsp), %rsi
cmpq $-0x3, %rax
ja 0x4257
leaq 0x18(%rsp), %rdi
callq 0x30f0
leaq 0x18(%rsp), %rbx
movq (%rsp), %rdi
movq %rbx, %rsi
callq 0x3190
movq (%rbx), %rdi
cmpq %r14, %rdi
je 0x4253
movq 0x28(%rsp), %rsi
incq %rsi
callq 0x3080
xorl %ebx, %ebx
jmp 0x4289
leaq 0x18(%rsp), %rdi
callq 0x30f0
leaq 0x18(%rsp), %rbx
movq (%rsp), %rdi
movq %rbx, %rsi
callq 0x3190
movq (%rbx), %rdi
cmpq %r14, %rdi
je 0x4287
movq 0x28(%rsp), %rsi
incq %rsi
callq 0x3080
movb $0x1, %bl
movq 0x58(%rsp), %rdi
leaq 0x68(%rsp), %rax
cmpq %rax, %rdi
je 0x42a5
movq 0x68(%rsp), %rsi
incq %rsi
callq 0x3080
movq 0x3d34(%rip), %rsi      # 0x7fe0
leaq 0x228(%rsp), %rdi
callq 0x3230
leaq 0x2a8(%rsp), %rdi
callq 0x3200
movq 0x78(%rsp), %rdi
leaq 0x88(%rsp), %rax
cmpq %rax, %rdi
je 0x42e8
movq 0x88(%rsp), %rsi
incq %rsi
callq 0x3080
movq 0x3cf1(%rip), %rsi      # 0x7fe0
leaq 0xa0(%rsp), %rdi
callq 0x3230
leaq 0x120(%rsp), %rdi
callq 0x3200
movq 0x38(%rsp), %rdi
leaq 0x48(%rsp), %rax
cmpq %rax, %rdi
je 0x432a
movq 0x48(%rsp), %rax
leaq 0x2(,%rax,2), %rsi
callq 0x3080
movq 0x3caf(%rip), %rsi      # 0x7fe0
leaq 0x3b0(%rsp), %rdi
callq 0x3230
leaq 0x430(%rsp), %rdi
callq 0x3200
movl %ebx, %eax
addq $0x538, %rsp            # imm = 0x538
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x4382
jmp 0x4382
jmp 0x4382
jmp 0x4375
jmp 0x4375
jmp 0x437a
jmp 0x437a
jmp 0x437a
jmp 0x437a
jmp 0x4382
jmp 0x4382
movq %rax, %rbx
jmp 0x43c2
movq %rax, %rbx
jmp 0x4405
movq %rax, %rbx
movq 0x58(%rsp), %rdi
leaq 0x68(%rsp), %rax
cmpq %rax, %rdi
je 0x43a1
movq 0x68(%rsp), %rsi
incq %rsi
callq 0x3080
movq 0x3c38(%rip), %rsi      # 0x7fe0
leaq 0x228(%rsp), %rdi
callq 0x3230
leaq 0x2a8(%rsp), %rdi
callq 0x3200
movq 0x78(%rsp), %rdi
leaq 0x88(%rsp), %rax
cmpq %rax, %rdi
je 0x43e4
movq 0x88(%rsp), %rsi
incq %rsi
callq 0x3080
movq 0x3bf5(%rip), %rsi      # 0x7fe0
leaq 0xa0(%rsp), %rdi
callq 0x3230
leaq 0x120(%rsp), %rdi
callq 0x3200
movq 0x38(%rsp), %rdi
leaq 0x48(%rsp), %rax
cmpq %rax, %rdi
je 0x4426
movq 0x48(%rsp), %rax
leaq 0x2(,%rax,2), %rsi
callq 0x3080
movq 0x3bb3(%rip), %rsi      # 0x7fe0
leaq 0x3b0(%rsp), %rdi
callq 0x3230
leaq 0x430(%rsp), %rdi
callq 0x3200
movq %rbx, %rdi
callq 0x31d0
movq %rax, %rbx
cmpl $0x1, %edx
jne 0x4405
movq %rbx, %rdi
callq 0x3050
movq (%rax), %rcx
movq %rax, %rdi
callq *0x10(%rcx)
movq (%rsp), %rdi
movq %rax, %rsi
callq 0x3110
callq 0x3240
jmp 0x3edf
jmp 0x437a
movq %rax, %rbx
callq 0x3240
jmp 0x4405
movq %rax, %rdi
callq 0x4595