// File: /workspace/github_cpp_makefile_star2_O1/TwilioDevEd[P]twilio_cpp_demo/src/cpp_demo.cc
// Function: main
int main(int argc, char * argv[])
{
        int cmd;
        std::string account_sid;
        std::string auth_token;
        std::string message;
        std::string from_number;
        std::string to_number;
        std::string picture_url;
        bool verbose = false;

        opterr = 0;

        while ((cmd = getopt(argc, argv, "a:s:m:f:t:p:vh?")) != -1) {
                switch (cmd) {
                        case '?':
                        case 'h':
                                printf("Twilio C++ Example Help:\n");
                                printf("-a: Account\t\t"
                                       "(ex: -a \"ACXXXXX\")\n");
                                printf("-s: Auth Token\t\t"
                                       "(ex: -s \"your_token\")\n");
                                printf("-f: From Number\t\t"
                                       "(ex: -f \"+18005551212\")\n");
                                printf("-t: To Number\t\t"
                                       "(ex: -t \"+18005551212\")\n");
                                printf("-m: Message to send\t"
                                       "(ex: -m \"Hello, Twilio!\")\n");
                                printf("-p: (Opt.) URL to Image\t"
                                       "(ex: -p \"Hello, Twilio!\")\n");
                                printf("-v: Verbose Mode\n");
                                printf("-h: This help dialog\n");
                                return 0;
                        case 'a':
                                account_sid = optarg;
                                break;
                        case 's':
                                auth_token = optarg;
                                break;
                        case 'm':
                                message = optarg;
                                break;
                        case 'f':
                                from_number = optarg;
                                break;
                        case 't':
                                to_number = optarg;
                                break;
                        case 'p':
                                picture_url = optarg;
                                break;
                        case 'v':
                                verbose = true;
                                break;
                        default:
                                abort();
                }
        }

        if ( account_sid.empty() or auth_token.empty() or from_number.empty()
                or to_number.empty() or message.empty() ) {
                std::cout<< "You didn't include all necessary inputs!\n"
                        "Call using -h for help.\n" << std::endl;
                return -1;
        }

        // Instantiate a twilio object and call send_message
        std::string response;
        auto twilio = std::make_shared<twilio::Twilio>(
            account_sid, 
            auth_token
        );
        
        bool message_success = twilio->send_message(
                to_number, 
                from_number, 
                message,
                response,
                picture_url,
                verbose
        );

        // Report success or failure
        if (!message_success) {
                if (verbose) {
                        std::cout << "Message send failed." << std::endl;
                        if (!response.empty()) {
                                std::cout << "Response:" << std::endl 
                                        << response << std::endl;
                        }
                }
                return -1;
        } else if (verbose) {
                std::cout << "SMS sent successfully!" << std::endl;
                std::cout << "Response:" << std::endl << response
                        << std::endl;
        }

        return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x108, %rsp            # imm = 0x108
movq %rsi, %rbx
movl %edi, %ebp
leaq 0xd8(%rsp), %rax
movq %rax, -0x10(%rax)
xorl %edx, %edx
movq %rdx, -0x8(%rax)
movb %dl, (%rax)
leaq 0xb8(%rsp), %rax
movq %rax, -0x10(%rax)
movq %rdx, -0x8(%rax)
movb %dl, (%rax)
leaq 0x98(%rsp), %rax
movq %rax, -0x10(%rax)
movq %rdx, -0x8(%rax)
movb %dl, (%rax)
leaq 0x78(%rsp), %rax
movq %rax, -0x10(%rax)
movq %rdx, -0x8(%rax)
movb %dl, (%rax)
leaq 0x58(%rsp), %rax
movq %rax, -0x10(%rax)
movq %rdx, -0x8(%rax)
movb %dl, (%rax)
leaq 0xf8(%rsp), %rax
movq %rax, -0x10(%rax)
movq %rdx, -0x8(%rax)
movl $0x0, %ecx
movq %rcx, 0x10(%rsp)
movb %dl, (%rax)
movq 0x4a15(%rip), %rax      # 0x7fd0
movl $0x0, (%rax)
leaq 0x1a3c(%rip), %r14      # 0x5004
movl %ebp, %edi
movq %rbx, %rsi
leaq 0x1a74(%rip), %rdx      # 0x5048
callq 0x32b0
cmpl $0x65, %eax
jle 0x3602
addl $-0x66, %eax
cmpl $0x10, %eax
ja 0x39eb
movslq (%r14,%rax,4), %rax
addq %r14, %rax
leaq 0xa8(%rsp), %r15
jmpq *%rax
leaq 0x68(%rsp), %r15
jmp 0x362a
cmpl $0x61, %eax
jne 0x3664
leaq 0xc8(%rsp), %r15
jmp 0x362a
leaq 0x48(%rsp), %r15
jmp 0x362a
leaq 0xe8(%rsp), %r15
jmp 0x362a
leaq 0x88(%rsp), %r15
movq 0x4987(%rip), %rax      # 0x7fb8
movq (%rax), %r12
movq 0x8(%r15), %r13
movq %r12, %rdi
callq 0x3100
movq %r15, %rdi
xorl %esi, %esi
movq %r13, %rdx
movq %r12, %rcx
movq %rax, %r8
callq 0x3170
jmp 0x35c8
movb $0x1, %al
movq %rax, 0x10(%rsp)
jmp 0x35c8
cmpl $-0x1, %eax
je 0x37c4
cmpl $0x3f, %eax
jne 0x39eb
leaq 0x1a7d(%rip), %rdi      # 0x50fa
callq 0x3310
leaq 0x1a8a(%rip), %rdi      # 0x5113
callq 0x3310
leaq 0x1a9e(%rip), %rdi      # 0x5133
callq 0x3310
leaq 0x1ab8(%rip), %rdi      # 0x5159
callq 0x3310
leaq 0x1ad5(%rip), %rdi      # 0x5182
callq 0x3310
leaq 0x1af0(%rip), %rdi      # 0x51a9
callq 0x3310
leaq 0x1b12(%rip), %rdi      # 0x51d7
callq 0x3310
leaq 0x1b38(%rip), %rdi      # 0x5209
callq 0x3310
leaq 0x1b3d(%rip), %rdi      # 0x521a
callq 0x3310
xorl %ebx, %ebx
movq 0xe8(%rsp), %rdi
leaq 0xf8(%rsp), %rax
cmpq %rax, %rdi
je 0x3709
movq 0xf8(%rsp), %rsi
incq %rsi
callq 0x3080
movq 0x48(%rsp), %rdi
leaq 0x58(%rsp), %rax
cmpq %rax, %rdi
je 0x3725
movq 0x58(%rsp), %rsi
incq %rsi
callq 0x3080
movq 0x68(%rsp), %rdi
leaq 0x78(%rsp), %rax
cmpq %rax, %rdi
je 0x3741
movq 0x78(%rsp), %rsi
incq %rsi
callq 0x3080
movq 0x88(%rsp), %rdi
leaq 0x98(%rsp), %rax
cmpq %rax, %rdi
je 0x3766
movq 0x98(%rsp), %rsi
incq %rsi
callq 0x3080
movq 0xa8(%rsp), %rdi
leaq 0xb8(%rsp), %rax
cmpq %rax, %rdi
je 0x378b
movq 0xb8(%rsp), %rsi
incq %rsi
callq 0x3080
movq 0xc8(%rsp), %rdi
leaq 0xd8(%rsp), %rax
cmpq %rax, %rdi
je 0x37b0
movq 0xd8(%rsp), %rsi
incq %rsi
callq 0x3080
movl %ebx, %eax
addq $0x108, %rsp            # imm = 0x108
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
cmpq $0x0, 0xd0(%rsp)
je 0x38f7
cmpq $0x0, 0xb0(%rsp)
je 0x38f7
cmpq $0x0, 0x70(%rsp)
je 0x38f7
cmpq $0x0, 0x50(%rsp)
je 0x38f7
cmpq $0x0, 0x90(%rsp)
je 0x38f7
leaq 0x28(%rsp), %r14
movq %r14, -0x10(%r14)
xorl %eax, %eax
movq %rax, -0x8(%r14)
movb $0x0, (%r14)
leaq 0x40(%rsp), %rdi
movq %rax, -0x8(%rdi)
leaq 0x38(%rsp), %rsi
leaq 0xf(%rsp), %rdx
leaq 0xc8(%rsp), %rcx
leaq 0xa8(%rsp), %r8
callq 0x3b6a
movq 0x38(%rsp), %rdi
movq 0x10(%rsp), %r15
movzbl %r15b, %eax
andl $0x1, %eax
movl %eax, (%rsp)
leaq 0x48(%rsp), %rsi
leaq 0x68(%rsp), %rdx
leaq 0x88(%rsp), %rcx
leaq 0x18(%rsp), %r8
leaq 0xe8(%rsp), %r9
callq 0x3da8
testb %al, %al
je 0x3947
xorl %ebx, %ebx
testb $0x1, %r15b
je 0x39bc
movq 0x4729(%rip), %rdi      # 0x7fc0
leaq 0x181b(%rip), %rsi      # 0x50b9
movl $0x16, %edx
callq 0x32d0
movq 0x4711(%rip), %rdi      # 0x7fc0
callq 0x32f0
movq 0x4705(%rip), %rdi      # 0x7fc0
leaq 0x17ed(%rip), %rsi      # 0x50af
movl $0x9, %edx
callq 0x32d0
movq 0x46ed(%rip), %rdi      # 0x7fc0
callq 0x32f0
movq 0x18(%rsp), %rsi
movq 0x20(%rsp), %rdx
movq %rax, %rdi
callq 0x32d0
movq %rax, %rdi
callq 0x32f0
jmp 0x39bc
movq 0x46c2(%rip), %rbx      # 0x7fc0
leaq 0x1753(%rip), %rsi      # 0x5058
movl $0x41, %edx
movq %rbx, %rdi
callq 0x32d0
movq (%rbx), %rax
addq -0x18(%rax), %rbx
movq %rbx, %rdi
movl $0xa, %esi
callq 0x3320
movsbl %al, %esi
movq 0x4690(%rip), %rdi      # 0x7fc0
callq 0x31a0
movl $0xffffffff, %ebx       # imm = 0xFFFFFFFF
movq %rax, %rdi
callq 0x3160
jmp 0x36e4
movl $0xffffffff, %ebx       # imm = 0xFFFFFFFF
testb $0x1, %r15b
je 0x39bc
movq 0x4667(%rip), %rdi      # 0x7fc0
leaq 0x173a(%rip), %rsi      # 0x509a
movl $0x14, %edx
callq 0x32d0
movq 0x464f(%rip), %rdi      # 0x7fc0
callq 0x32f0
cmpq $0x0, 0x20(%rsp)
je 0x39bc
movq 0x463b(%rip), %rdi      # 0x7fc0
leaq 0x1723(%rip), %rsi      # 0x50af
movl $0x9, %edx
callq 0x32d0
movq 0x4623(%rip), %rdi      # 0x7fc0
callq 0x32f0
movq 0x18(%rsp), %rsi
movq 0x20(%rsp), %rdx
movq %rax, %rdi
callq 0x32d0
movq %rax, %rdi
callq 0x32f0
movq 0x40(%rsp), %rdi
testq %rdi, %rdi
je 0x39cb
callq 0x3afa
movq 0x18(%rsp), %rdi
cmpq %r14, %rdi
je 0x36e4
movq 0x28(%rsp), %rsi
incq %rsi
callq 0x3080
jmp 0x36e4
callq 0x3220
movq %rax, %rbx
jmp 0x3a07
movq %rax, %rbx
movq 0x40(%rsp), %rdi
testq %rdi, %rdi
je 0x3a07
callq 0x3afa
movq 0x18(%rsp), %rdi
cmpq %r14, %rdi
je 0x3a25
movq 0x28(%rsp), %rsi
incq %rsi
callq 0x3080
jmp 0x3a25
jmp 0x3a22
movq %rax, %rbx
movq 0xe8(%rsp), %rdi
leaq 0xf8(%rsp), %rax
cmpq %rax, %rdi
je 0x3a4a
movq 0xf8(%rsp), %rsi
incq %rsi
callq 0x3080
movq 0x48(%rsp), %rdi
leaq 0x58(%rsp), %rax
cmpq %rax, %rdi
je 0x3a66
movq 0x58(%rsp), %rsi
incq %rsi
callq 0x3080
movq 0x68(%rsp), %rdi
leaq 0x78(%rsp), %rax
cmpq %rax, %rdi
je 0x3a82
movq 0x78(%rsp), %rsi
incq %rsi
callq 0x3080
movq 0x88(%rsp), %rdi
leaq 0x98(%rsp), %rax
cmpq %rax, %rdi
je 0x3aa7
movq 0x98(%rsp), %rsi
incq %rsi
callq 0x3080
movq 0xa8(%rsp), %rdi
leaq 0xb8(%rsp), %rax
cmpq %rax, %rdi
je 0x3acc
movq 0xb8(%rsp), %rsi
incq %rsi
callq 0x3080
movq 0xc8(%rsp), %rdi
leaq 0xd8(%rsp), %rax
cmpq %rax, %rdi
je 0x3af1
movq 0xd8(%rsp), %rsi
incq %rsi
callq 0x3080
movq %rbx, %rdi
callq 0x31d0
nop