// File: /workspace/github_cpp_makefile_star2_O2/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)
andq $0x0, -0x8(%rax)
leaq 0xb8(%rsp), %rcx
movq %rcx, -0x10(%rcx)
andq $0x0, -0x8(%rcx)
xorl %esi, %esi
movb %sil, (%rax)
leaq 0x98(%rsp), %rax
movq %rax, -0x10(%rax)
andq $0x0, -0x8(%rax)
leaq 0x78(%rsp), %rdx
movq %rdx, -0x10(%rdx)
andq $0x0, -0x8(%rdx)
movb %sil, (%rcx)
movb %sil, (%rax)
leaq 0x58(%rsp), %rax
movq %rax, -0x10(%rax)
andq $0x0, -0x8(%rax)
leaq 0xf8(%rsp), %rcx
movq %rcx, -0x10(%rcx)
andq $0x0, -0x8(%rcx)
movb %sil, (%rdx)
movb %sil, (%rax)
movl $0x0, 0x14(%rsp)
movb %sil, (%rcx)
movq 0x4b13(%rip), %rax      # 0x6fd8
andl $0x0, (%rax)
leaq 0x1b79(%rip), %r14      # 0x4048
leaq 0xa8(%rsp), %r12
movq 0x4ae2(%rip), %r15      # 0x6fc0
leaq 0x1b1f(%rip), %r13      # 0x4004
movl %ebp, %edi
movq %rbx, %rsi
movq %r14, %rdx
callq 0x2280
leal -0x66(%rax), %ecx
cmpl $0x10, %ecx
ja 0x250e
movslq (%r13,%rcx,4), %rax
addq %r13, %rax
movq %r12, %rdi
jmpq *%rax
leaq 0x68(%rsp), %rdi
jmp 0x2536
cmpl $0x61, %eax
jne 0x2548
leaq 0xc8(%rsp), %rdi
jmp 0x2536
leaq 0xe8(%rsp), %rdi
jmp 0x2536
leaq 0x48(%rsp), %rdi
jmp 0x2536
leaq 0x88(%rsp), %rdi
movq (%r15), %rsi
callq 0x22f0
jmp 0x24e5
movb $0x1, %al
movl %eax, 0x14(%rsp)
jmp 0x24e5
cmpl $-0x1, %eax
je 0x2624
cmpl $0x3f, %eax
jne 0x27c0
leaq 0x1b6f(%rip), %rdi      # 0x40d0
callq 0x22d0
leaq 0x1b7c(%rip), %rdi      # 0x40e9
callq 0x22d0
leaq 0x1b90(%rip), %rdi      # 0x4109
callq 0x22d0
leaq 0x1baa(%rip), %rdi      # 0x412f
callq 0x22d0
leaq 0x1bc7(%rip), %rdi      # 0x4158
callq 0x22d0
leaq 0x1be2(%rip), %rdi      # 0x417f
callq 0x22d0
leaq 0x1c04(%rip), %rdi      # 0x41ad
callq 0x22d0
leaq 0x1c2a(%rip), %rdi      # 0x41df
callq 0x22d0
leaq 0x1c2f(%rip), %rdi      # 0x41f0
callq 0x22d0
xorl %ebx, %ebx
leaq 0xe8(%rsp), %rdi
callq 0x21e0
leaq 0x48(%rsp), %rdi
callq 0x21e0
leaq 0x68(%rsp), %rdi
callq 0x21e0
leaq 0x88(%rsp), %rdi
callq 0x21e0
leaq 0xa8(%rsp), %rdi
callq 0x21e0
leaq 0xc8(%rsp), %rdi
callq 0x21e0
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 0x2728
cmpq $0x0, 0xb0(%rsp)
je 0x2728
cmpq $0x0, 0x70(%rsp)
je 0x2728
cmpq $0x0, 0x50(%rsp)
je 0x2728
cmpq $0x0, 0x90(%rsp)
je 0x2728
leaq 0x38(%rsp), %rax
movq %rax, -0x10(%rax)
andq $0x0, -0x8(%rax)
movb $0x0, (%rax)
leaq 0x18(%rsp), %rdi
leaq 0xc8(%rsp), %rsi
leaq 0xa8(%rsp), %rdx
callq 0x2838
movq 0x18(%rsp), %rdi
movl 0x14(%rsp), %ebp
movzbl %bpl, %eax
andl $0x1, %eax
movl %eax, (%rsp)
leaq 0x48(%rsp), %rsi
leaq 0x68(%rsp), %rdx
leaq 0x88(%rsp), %rcx
leaq 0x28(%rsp), %r8
leaq 0xe8(%rsp), %r9
callq 0x2af8
testb %al, %al
je 0x274b
xorl %ebx, %ebx
testb $0x1, %bpl
je 0x27a7
movq 0x48e6(%rip), %rdi      # 0x6fc8
leaq 0x19d0(%rip), %rsi      # 0x40b9
callq 0x2190
movq %rax, %rdi
callq 0x22b0
movq 0x48cb(%rip), %rdi      # 0x6fc8
leaq 0x19ab(%rip), %rsi      # 0x40af
callq 0x2190
movq %rax, %rdi
callq 0x22b0
leaq 0x28(%rsp), %rsi
movq %rax, %rdi
callq 0x20d0
movq %rax, %rdi
callq 0x22b0
jmp 0x27a7
movq 0x4899(%rip), %rdi      # 0x6fc8
leaq 0x1922(%rip), %rsi      # 0x4058
callq 0x2190
movq %rax, %rdi
callq 0x22b0
pushq $-0x1
popq %rbx
jmp 0x25c8
pushq $-0x1
popq %rbx
testb $0x1, %bpl
je 0x27a7
movq 0x486d(%rip), %rdi      # 0x6fc8
leaq 0x1938(%rip), %rsi      # 0x409a
callq 0x2190
movq %rax, %rdi
callq 0x22b0
cmpq $0x0, 0x30(%rsp)
je 0x27a7
movq 0x484a(%rip), %rdi      # 0x6fc8
leaq 0x192a(%rip), %rsi      # 0x40af
callq 0x2190
movq %rax, %rdi
callq 0x22b0
leaq 0x28(%rsp), %rsi
movq %rax, %rdi
callq 0x20d0
movq %rax, %rdi
callq 0x22b0
leaq 0x20(%rsp), %rdi
callq 0x285a
leaq 0x28(%rsp), %rdi
callq 0x21e0
jmp 0x25c8
callq 0x2200
movq %rax, %rbx
jmp 0x27d9
jmp 0x27e5
movq %rax, %rbx
leaq 0x20(%rsp), %rdi
callq 0x285a
leaq 0x28(%rsp), %rdi
callq 0x21e0
jmp 0x27e8
movq %rax, %rbx
leaq 0xe8(%rsp), %rdi
callq 0x21e0
leaq 0x48(%rsp), %rdi
callq 0x21e0
leaq 0x68(%rsp), %rdi
callq 0x21e0
leaq 0x88(%rsp), %rdi
callq 0x21e0
leaq 0xa8(%rsp), %rdi
callq 0x21e0
leaq 0xc8(%rsp), %rdi
callq 0x21e0
movq %rbx, %rdi
callq 0x21c0